Default the view background color and text color to different values when in dark...
[WebKit-https.git] / Source / WebCore / testing / Internals.h
1 /*
2  * Copyright (C) 2012 Google Inc. All rights reserved.
3  * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #pragma once
28
29 #include "CSSComputedStyleDeclaration.h"
30 #include "ContextDestructionObserver.h"
31 #include "Cookie.h"
32 #include "ExceptionOr.h"
33 #include "HEVCUtilities.h"
34 #include "JSDOMPromiseDeferred.h"
35 #include "OrientationNotifier.h"
36 #include "PageConsoleClient.h"
37 #include "RealtimeMediaSource.h"
38 #include <JavaScriptCore/Float32Array.h>
39 #include <wtf/Optional.h>
40
41 #if ENABLE(MEDIA_SESSION)
42 #include "MediaSessionInterruptionProvider.h"
43 #endif
44
45 #if ENABLE(VIDEO)
46 #include "MediaElementSession.h"
47 #endif
48
49 namespace WebCore {
50
51 class AnimationTimeline;
52 class AudioContext;
53 class CacheStorageConnection;
54 class DOMRect;
55 class DOMRectList;
56 class DOMURL;
57 class DOMWindow;
58 class Document;
59 class Element;
60 class ExtendableEvent;
61 class FetchResponse;
62 class File;
63 class Frame;
64 class GCObservation;
65 class HTMLAnchorElement;
66 class HTMLImageElement;
67 class HTMLInputElement;
68 class HTMLLinkElement;
69 class HTMLMediaElement;
70 class HTMLPictureElement;
71 class HTMLSelectElement;
72 class ImageData;
73 class InspectorStubFrontend;
74 class InternalSettings;
75 class MallocStatistics;
76 class MediaSession;
77 class MediaStream;
78 class MediaStreamTrack;
79 class MemoryInfo;
80 class MockCDMFactory;
81 class MockContentFilterSettings;
82 class MockPageOverlay;
83 class MockPaymentCoordinator;
84 class NodeList;
85 class Page;
86 class RTCPeerConnection;
87 class Range;
88 class RenderedDocumentMarker;
89 class SVGSVGElement;
90 class SerializedScriptValue;
91 class SourceBuffer;
92 class StringCallback;
93 class StyleSheet;
94 class TimeRanges;
95 class TypeConversions;
96 class VoidCallback;
97 class WebGLRenderingContext;
98 class XMLHttpRequest;
99
100 #if ENABLE(SERVICE_WORKER)
101 class ServiceWorker;
102 #endif
103
104 class Internals final : public RefCounted<Internals>, private ContextDestructionObserver
105 #if ENABLE(MEDIA_STREAM)
106     , private RealtimeMediaSource::Observer
107 #endif
108     {
109 public:
110     static Ref<Internals> create(Document&);
111     virtual ~Internals();
112
113     static void resetToConsistentState(Page&);
114
115     ExceptionOr<String> elementRenderTreeAsText(Element&);
116     bool hasPausedImageAnimations(Element&);
117
118     bool isPaintingFrequently(Element&);
119     void incrementFrequentPaintCounter(Element&);
120
121     String address(Node&);
122     bool nodeNeedsStyleRecalc(Node&);
123     String styleChangeType(Node&);
124     String description(JSC::JSValue);
125
126     bool isPreloaded(const String& url);
127     bool isLoadingFromMemoryCache(const String& url);
128     String fetchResponseSource(FetchResponse&);
129     String xhrResponseSource(XMLHttpRequest&);
130     bool isSharingStyleSheetContents(HTMLLinkElement&, HTMLLinkElement&);
131     bool isStyleSheetLoadingSubresources(HTMLLinkElement&);
132     enum class CachePolicy { UseProtocolCachePolicy, ReloadIgnoringCacheData, ReturnCacheDataElseLoad, ReturnCacheDataDontLoad };
133     void setOverrideCachePolicy(CachePolicy);
134     ExceptionOr<void> setCanShowModalDialogOverride(bool allow);
135     enum class ResourceLoadPriority { ResourceLoadPriorityVeryLow, ResourceLoadPriorityLow, ResourceLoadPriorityMedium, ResourceLoadPriorityHigh, ResourceLoadPriorityVeryHigh };
136     void setOverrideResourceLoadPriority(ResourceLoadPriority);
137     void setStrictRawResourceValidationPolicyDisabled(bool);
138
139     void clearMemoryCache();
140     void pruneMemoryCacheToSize(unsigned size);
141     void destroyDecodedDataForAllImages();
142     unsigned memoryCacheSize() const;
143
144     unsigned imageFrameIndex(HTMLImageElement&);
145     void setImageFrameDecodingDuration(HTMLImageElement&, float duration);
146     void resetImageAnimation(HTMLImageElement&);
147     bool isImageAnimating(HTMLImageElement&);
148     void setClearDecoderAfterAsyncFrameRequestForTesting(HTMLImageElement&, bool enabled);
149     unsigned imageDecodeCount(HTMLImageElement&);
150     unsigned pdfDocumentCachingCount(HTMLImageElement&);
151     void setLargeImageAsyncDecodingEnabledForTesting(HTMLImageElement&, bool enabled);
152     void setForceUpdateImageDataEnabledForTesting(HTMLImageElement&, bool enabled);
153
154     void setGridMaxTracksLimit(unsigned);
155
156     void clearPageCache();
157     unsigned pageCacheSize() const;
158
159     void disableTileSizeUpdateDelay();
160
161     void setSpeculativeTilingDelayDisabledForTesting(bool);
162
163     Ref<CSSComputedStyleDeclaration> computedStyleIncludingVisitedInfo(Element&) const;
164
165     Node* ensureUserAgentShadowRoot(Element& host);
166     Node* shadowRoot(Element& host);
167     ExceptionOr<String> shadowRootType(const Node&) const;
168     String shadowPseudoId(Element&);
169     void setShadowPseudoId(Element&, const String&);
170
171     // CSS Deferred Parsing Testing
172     unsigned deferredStyleRulesCount(StyleSheet&);
173     unsigned deferredGroupRulesCount(StyleSheet&);
174     unsigned deferredKeyframesRulesCount(StyleSheet&);
175
176     // DOMTimers throttling testing.
177     ExceptionOr<bool> isTimerThrottled(int timeoutId);
178     bool isRequestAnimationFrameThrottled() const;
179     double requestAnimationFrameInterval() const;
180     bool scriptedAnimationsAreSuspended() const;
181     bool areTimersThrottled() const;
182
183     enum EventThrottlingBehavior { Responsive, Unresponsive };
184     void setEventThrottlingBehaviorOverride(std::optional<EventThrottlingBehavior>);
185     std::optional<EventThrottlingBehavior> eventThrottlingBehaviorOverride() const;
186
187     // Spatial Navigation testing.
188     ExceptionOr<unsigned> lastSpatialNavigationCandidateCount() const;
189
190     // CSS Animation testing.
191     unsigned numberOfActiveAnimations() const;
192     ExceptionOr<bool> animationsAreSuspended() const;
193     ExceptionOr<void> suspendAnimations() const;
194     ExceptionOr<void> resumeAnimations() const;
195     ExceptionOr<bool> pauseAnimationAtTimeOnElement(const String& animationName, double pauseTime, Element&);
196     ExceptionOr<bool> pauseAnimationAtTimeOnPseudoElement(const String& animationName, double pauseTime, Element&, const String& pseudoId);
197     double animationsInterval() const;
198
199     // CSS Transition testing.
200     ExceptionOr<bool> pauseTransitionAtTimeOnElement(const String& propertyName, double pauseTime, Element&);
201     ExceptionOr<bool> pauseTransitionAtTimeOnPseudoElement(const String& property, double pauseTime, Element&, const String& pseudoId);
202
203     // Web Animations testing.
204     struct AcceleratedAnimation {
205         String property;
206         double speed;
207     };
208     Vector<AcceleratedAnimation> acceleratedAnimationsForElement(Element&);
209     unsigned numberOfAnimationTimelineInvalidations() const;
210
211     // For animations testing, we need a way to get at pseudo elements.
212     ExceptionOr<RefPtr<Element>> pseudoElement(Element&, const String&);
213
214     Node* treeScopeRootNode(Node&);
215     Node* parentTreeScope(Node&);
216
217     String visiblePlaceholder(Element&);
218     void selectColorInColorChooser(HTMLInputElement&, const String& colorValue);
219     ExceptionOr<Vector<String>> formControlStateOfPreviousHistoryItem();
220     ExceptionOr<void> setFormControlStateOfPreviousHistoryItem(const Vector<String>&);
221
222     ExceptionOr<Ref<DOMRect>> absoluteCaretBounds();
223
224     Ref<DOMRect> boundingBox(Element&);
225
226     ExceptionOr<Ref<DOMRectList>> inspectorHighlightRects();
227     ExceptionOr<String> inspectorHighlightObject();
228
229     ExceptionOr<unsigned> markerCountForNode(Node&, const String&);
230     ExceptionOr<RefPtr<Range>> markerRangeForNode(Node&, const String& markerType, unsigned index);
231     ExceptionOr<String> markerDescriptionForNode(Node&, const String& markerType, unsigned index);
232     ExceptionOr<String> dumpMarkerRects(const String& markerType);
233     void addTextMatchMarker(const Range&, bool isActive);
234     ExceptionOr<void> setMarkedTextMatchesAreHighlighted(bool);
235
236     void invalidateFontCache();
237     void setFontSmoothingEnabled(bool);
238
239     ExceptionOr<void> setLowPowerModeEnabled(bool);
240
241     ExceptionOr<void> setScrollViewPosition(int x, int y);
242     ExceptionOr<void> unconstrainedScrollTo(Element&, double x, double y);
243
244     ExceptionOr<Ref<DOMRect>> layoutViewportRect();
245     ExceptionOr<Ref<DOMRect>> visualViewportRect();
246
247     ExceptionOr<void> setViewIsTransparent(bool);
248
249     ExceptionOr<String> viewBaseBackgroundColor();
250     ExceptionOr<void> setViewBaseBackgroundColor(const String& colorValue);
251
252     ExceptionOr<void> setPagination(const String& mode, int gap, int pageLength);
253     ExceptionOr<void> setPaginationLineGridEnabled(bool);
254     ExceptionOr<String> configurationForViewport(float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight);
255
256     ExceptionOr<bool> wasLastChangeUserEdit(Element& textField);
257     bool elementShouldAutoComplete(HTMLInputElement&);
258     void setEditingValue(HTMLInputElement&, const String&);
259     void setAutofilled(HTMLInputElement&, bool enabled);
260     enum class AutoFillButtonType { None, Contacts, Credentials, StrongPassword, CreditCard };
261     void setShowAutoFillButton(HTMLInputElement&, AutoFillButtonType);
262     AutoFillButtonType autoFillButtonType(const HTMLInputElement&);
263     AutoFillButtonType lastAutoFillButtonType(const HTMLInputElement&);
264     ExceptionOr<void> scrollElementToRect(Element&, int x, int y, int w, int h);
265
266     ExceptionOr<String> autofillFieldName(Element&);
267
268     ExceptionOr<void> invalidateControlTints();
269
270     RefPtr<Range> rangeFromLocationAndLength(Element& scope, int rangeLocation, int rangeLength);
271     unsigned locationFromRange(Element& scope, const Range&);
272     unsigned lengthFromRange(Element& scope, const Range&);
273     String rangeAsText(const Range&);
274     Ref<Range> subrange(Range&, int rangeLocation, int rangeLength);
275     ExceptionOr<RefPtr<Range>> rangeForDictionaryLookupAtLocation(int x, int y);
276     RefPtr<Range> rangeOfStringNearLocation(const Range&, const String&, unsigned);
277
278     ExceptionOr<void> setDelegatesScrolling(bool enabled);
279
280     ExceptionOr<int> lastSpellCheckRequestSequence();
281     ExceptionOr<int> lastSpellCheckProcessedSequence();
282
283     Vector<String> userPreferredLanguages() const;
284     void setUserPreferredLanguages(const Vector<String>&);
285
286     Vector<String> userPreferredAudioCharacteristics() const;
287     void setUserPreferredAudioCharacteristic(const String&);
288
289     ExceptionOr<unsigned> wheelEventHandlerCount();
290     ExceptionOr<unsigned> touchEventHandlerCount();
291
292     ExceptionOr<Ref<DOMRectList>> touchEventRectsForEvent(const String&);
293     ExceptionOr<Ref<DOMRectList>> passiveTouchEventListenerRects();
294
295     ExceptionOr<RefPtr<NodeList>> nodesFromRect(Document&, int x, int y, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowUserAgentShadowContent, bool allowChildFrameContent) const;
296
297     String parserMetaData(JSC::JSValue = JSC::JSValue::JSUndefined);
298
299     void updateEditorUINowIfScheduled();
300
301     bool sentenceRetroCorrectionEnabled() const
302     {
303 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
304         return true;
305 #else
306         return false;
307 #endif
308     }
309     bool hasSpellingMarker(int from, int length);
310     bool hasGrammarMarker(int from, int length);
311     bool hasAutocorrectedMarker(int from, int length);
312     void setContinuousSpellCheckingEnabled(bool);
313     void setAutomaticQuoteSubstitutionEnabled(bool);
314     void setAutomaticLinkDetectionEnabled(bool);
315     void setAutomaticDashSubstitutionEnabled(bool);
316     void setAutomaticTextReplacementEnabled(bool);
317     void setAutomaticSpellingCorrectionEnabled(bool);
318
319     void handleAcceptedCandidate(const String& candidate, unsigned location, unsigned length);
320     void changeSelectionListType();
321
322     bool isOverwriteModeEnabled();
323     void toggleOverwriteModeEnabled();
324
325     ExceptionOr<RefPtr<Range>> rangeOfString(const String&, RefPtr<Range>&&, const Vector<String>& findOptions);
326     ExceptionOr<unsigned> countMatchesForText(const String&, const Vector<String>& findOptions, const String& markMatches);
327     ExceptionOr<unsigned> countFindMatches(const String&, const Vector<String>& findOptions);
328
329     unsigned numberOfScrollableAreas();
330
331     ExceptionOr<bool> isPageBoxVisible(int pageNumber);
332
333     static const char* internalsId;
334
335     InternalSettings* settings() const;
336     unsigned workerThreadCount() const;
337     ExceptionOr<bool> areSVGAnimationsPaused() const;
338     ExceptionOr<double> svgAnimationsInterval(SVGSVGElement&) const;
339
340     enum {
341         // Values need to be kept in sync with Internals.idl.
342         LAYER_TREE_INCLUDES_VISIBLE_RECTS = 1,
343         LAYER_TREE_INCLUDES_TILE_CACHES = 2,
344         LAYER_TREE_INCLUDES_REPAINT_RECTS = 4,
345         LAYER_TREE_INCLUDES_PAINTING_PHASES = 8,
346         LAYER_TREE_INCLUDES_CONTENT_LAYERS = 16,
347         LAYER_TREE_INCLUDES_ACCELERATES_DRAWING = 32,
348         LAYER_TREE_INCLUDES_BACKING_STORE_ATTACHED = 64,
349     };
350     ExceptionOr<String> layerTreeAsText(Document&, unsigned short flags) const;
351     ExceptionOr<uint64_t> layerIDForElement(Element&);
352     ExceptionOr<String> repaintRectsAsText() const;
353
354     ExceptionOr<String> scrollbarOverlayStyle() const;
355
356     ExceptionOr<String> scrollingStateTreeAsText() const;
357     ExceptionOr<String> mainThreadScrollingReasons() const;
358     ExceptionOr<Ref<DOMRectList>> nonFastScrollableRects() const;
359
360     ExceptionOr<void> setElementUsesDisplayListDrawing(Element&, bool usesDisplayListDrawing);
361     ExceptionOr<void> setElementTracksDisplayListReplay(Element&, bool isTrackingReplay);
362
363     enum {
364         // Values need to be kept in sync with Internals.idl.
365         DISPLAY_LIST_INCLUDES_PLATFORM_OPERATIONS = 1,
366     };
367     ExceptionOr<String> displayListForElement(Element&, unsigned short flags);
368     ExceptionOr<String> replayDisplayListForElement(Element&, unsigned short flags);
369
370     ExceptionOr<void> garbageCollectDocumentResources() const;
371
372     void beginSimulatedMemoryPressure();
373     void endSimulatedMemoryPressure();
374     bool isUnderMemoryPressure();
375
376     ExceptionOr<void> insertAuthorCSS(const String&) const;
377     ExceptionOr<void> insertUserCSS(const String&) const;
378
379     unsigned numberOfLiveNodes() const;
380     unsigned numberOfLiveDocuments() const;
381     unsigned referencingNodeCount(const Document&) const;
382
383 #if ENABLE(INTERSECTION_OBSERVER)
384     unsigned numberOfIntersectionObservers(const Document&) const;
385 #endif
386
387     uint64_t documentIdentifier(const Document&) const;
388     bool isDocumentAlive(uint64_t documentIdentifier) const;
389
390     String serviceWorkerClientIdentifier(const Document&) const;
391
392     RefPtr<WindowProxy> openDummyInspectorFrontend(const String& url);
393     void closeDummyInspectorFrontend();
394     ExceptionOr<void> setInspectorIsUnderTest(bool);
395
396     String counterValue(Element&);
397
398     int pageNumber(Element&, float pageWidth = 800, float pageHeight = 600);
399     Vector<String> shortcutIconURLs() const;
400
401     int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
402     ExceptionOr<String> pageProperty(const String& propertyName, int pageNumber) const;
403     ExceptionOr<String> pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) const;
404
405     ExceptionOr<float> pageScaleFactor() const;
406
407     ExceptionOr<void> setPageScaleFactor(float scaleFactor, int x, int y);
408     ExceptionOr<void> setPageZoomFactor(float);
409     ExceptionOr<void> setTextZoomFactor(float);
410
411     ExceptionOr<void> setUseFixedLayout(bool);
412     ExceptionOr<void> setFixedLayoutSize(int width, int height);
413     ExceptionOr<void> setViewExposedRect(float left, float top, float width, float height);
414     void setPrinting(int width, int height);
415
416     void setHeaderHeight(float);
417     void setFooterHeight(float);
418
419     void setTopContentInset(float);
420
421 #if ENABLE(FULLSCREEN_API)
422     void webkitWillEnterFullScreenForElement(Element&);
423     void webkitDidEnterFullScreenForElement(Element&);
424     void webkitWillExitFullScreenForElement(Element&);
425     void webkitDidExitFullScreenForElement(Element&);
426     bool isAnimatingFullScreen() const;
427 #endif
428
429     struct FullscreenInsets {
430         float top { 0 };
431         float left { 0 };
432         float bottom { 0 };
433         float right { 0 };
434     };
435     void setFullscreenInsets(FullscreenInsets);
436     void setFullscreenAutoHideDuration(double);
437     void setFullscreenControlsHidden(bool);
438
439     WEBCORE_TESTSUPPORT_EXPORT void setApplicationCacheOriginQuota(unsigned long long);
440
441     void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
442     void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
443
444     void registerDefaultPortForProtocol(unsigned short port, const String& protocol);
445
446     Ref<MallocStatistics> mallocStatistics() const;
447     Ref<TypeConversions> typeConversions() const;
448     Ref<MemoryInfo> memoryInfo() const;
449
450     Vector<String> getReferencedFilePaths() const;
451
452     ExceptionOr<void> startTrackingRepaints();
453     ExceptionOr<void> stopTrackingRepaints();
454
455     ExceptionOr<void> startTrackingLayerFlushes();
456     ExceptionOr<unsigned> layerFlushCount();
457
458     ExceptionOr<void> startTrackingStyleRecalcs();
459     ExceptionOr<unsigned> styleRecalcCount();
460     unsigned lastStyleUpdateSize() const;
461
462     ExceptionOr<void> startTrackingCompositingUpdates();
463     ExceptionOr<unsigned> compositingUpdateCount();
464
465     enum CompositingPolicy { Normal, Conservative };
466     ExceptionOr<void> setCompositingPolicyOverride(std::optional<CompositingPolicy>);
467     ExceptionOr<std::optional<CompositingPolicy>> compositingPolicyOverride() const;
468
469     ExceptionOr<void> updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*);
470     unsigned layoutCount() const;
471
472     Ref<ArrayBuffer> serializeObject(const RefPtr<SerializedScriptValue>&) const;
473     Ref<SerializedScriptValue> deserializeBuffer(ArrayBuffer&) const;
474
475     bool isFromCurrentWorld(JSC::JSValue) const;
476
477     void setUsesOverlayScrollbars(bool);
478     void setUsesMockScrollAnimator(bool);
479
480     ExceptionOr<String> getCurrentCursorInfo();
481
482     String markerTextForListItem(Element&);
483
484     String toolTipFromElement(Element&) const;
485
486     void forceReload(bool endToEnd);
487     void reloadExpiredOnly();
488
489     void enableAutoSizeMode(bool enabled, int minimumWidth, int minimumHeight, int maximumWidth, int maximumHeight);
490
491 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
492     void initializeMockCDM();
493 #endif
494
495 #if ENABLE(ENCRYPTED_MEDIA)
496     Ref<MockCDMFactory> registerMockCDM();
497 #endif
498
499     void enableMockMediaCapabilities();
500
501 #if ENABLE(SPEECH_SYNTHESIS)
502     void enableMockSpeechSynthesizer();
503 #endif
504
505 #if ENABLE(MEDIA_STREAM)
506     void setMockMediaCaptureDevicesEnabled(bool);
507 #endif
508
509 #if ENABLE(WEB_RTC)
510     void emulateRTCPeerConnectionPlatformEvent(RTCPeerConnection&, const String& action);
511     void useMockRTCPeerConnectionFactory(const String&);
512     void setICECandidateFiltering(bool);
513     void setEnumeratingAllNetworkInterfacesEnabled(bool);
514     void stopPeerConnection(RTCPeerConnection&);
515     void applyRotationForOutgoingVideoSources(RTCPeerConnection&);
516 #endif
517
518     String getImageSourceURL(Element&);
519
520 #if ENABLE(VIDEO)
521     Vector<String> mediaResponseSources(HTMLMediaElement&);
522     Vector<String> mediaResponseContentRanges(HTMLMediaElement&);
523     void simulateAudioInterruption(HTMLMediaElement&);
524     ExceptionOr<bool> mediaElementHasCharacteristic(HTMLMediaElement&, const String&);
525     void beginSimulatedHDCPError(HTMLMediaElement&);
526     void endSimulatedHDCPError(HTMLMediaElement&);
527
528     bool elementShouldBufferData(HTMLMediaElement&);
529 #endif
530
531     bool isSelectPopupVisible(HTMLSelectElement&);
532
533     ExceptionOr<String> captionsStyleSheetOverride();
534     ExceptionOr<void> setCaptionsStyleSheetOverride(const String&);
535     ExceptionOr<void> setPrimaryAudioTrackLanguageOverride(const String&);
536     ExceptionOr<void> setCaptionDisplayMode(const String&);
537
538 #if ENABLE(VIDEO)
539     Ref<TimeRanges> createTimeRanges(Float32Array& startTimes, Float32Array& endTimes);
540     double closestTimeToTimeRanges(double time, TimeRanges&);
541 #endif
542
543     ExceptionOr<Ref<DOMRect>> selectionBounds();
544     void setSelectionWithoutValidation(Ref<Node> baseNode, unsigned baseOffset, RefPtr<Node> extentNode, unsigned extentOffset);
545
546     ExceptionOr<bool> isPluginUnavailabilityIndicatorObscured(Element&);
547     ExceptionOr<String> unavailablePluginReplacementText(Element&);
548     bool isPluginSnapshotted(Element&);
549
550 #if ENABLE(MEDIA_SOURCE)
551     WEBCORE_TESTSUPPORT_EXPORT void initializeMockMediaSource();
552     Vector<String> bufferedSamplesForTrackID(SourceBuffer&, const AtomicString&);
553     Vector<String> enqueuedSamplesForTrackID(SourceBuffer&, const AtomicString&);
554     void setShouldGenerateTimestamps(SourceBuffer&, bool);
555 #endif
556
557 #if ENABLE(VIDEO)
558     ExceptionOr<void> beginMediaSessionInterruption(const String&);
559     void endMediaSessionInterruption(const String&);
560     void applicationWillBecomeInactive();
561     void applicationDidBecomeActive();
562     void applicationWillEnterForeground(bool suspendedUnderLock) const;
563     void applicationDidEnterBackground(bool suspendedUnderLock) const;
564     ExceptionOr<void> setMediaSessionRestrictions(const String& mediaType, StringView restrictionsString);
565     ExceptionOr<String> mediaSessionRestrictions(const String& mediaType) const;
566     void setMediaElementRestrictions(HTMLMediaElement&, StringView restrictionsString);
567     ExceptionOr<void> postRemoteControlCommand(const String&, float argument);
568     bool elementIsBlockingDisplaySleep(HTMLMediaElement&) const;
569 #endif
570
571 #if ENABLE(MEDIA_SESSION)
572     void sendMediaSessionStartOfInterruptionNotification(MediaSessionInterruptingCategory);
573     void sendMediaSessionEndOfInterruptionNotification(MediaSessionInterruptingCategory);
574     String mediaSessionCurrentState(MediaSession&) const;
575     double mediaElementPlayerVolume(HTMLMediaElement&) const;
576     enum class MediaControlEvent { PlayPause, NextTrack, PreviousTrack };
577     void sendMediaControlEvent(MediaControlEvent);
578 #endif
579
580 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
581     void setMockMediaPlaybackTargetPickerEnabled(bool);
582     ExceptionOr<void> setMockMediaPlaybackTargetPickerState(const String& deviceName, const String& deviceState);
583 #endif
584
585 #if ENABLE(WEB_AUDIO)
586     void setAudioContextRestrictions(AudioContext&, StringView restrictionsString);
587 #endif
588
589     void simulateSystemSleep() const;
590     void simulateSystemWake() const;
591
592     enum class PageOverlayType { View, Document };
593     ExceptionOr<Ref<MockPageOverlay>> installMockPageOverlay(PageOverlayType);
594     ExceptionOr<String> pageOverlayLayerTreeAsText(unsigned short flags) const;
595
596     void setPageMuted(StringView);
597     String pageMediaState();
598
599     void setPageDefersLoading(bool);
600     ExceptionOr<bool> pageDefersLoading();
601
602     RefPtr<File> createFile(const String&);
603     void queueMicroTask(int);
604     bool testPreloaderSettingViewport();
605
606 #if ENABLE(CONTENT_FILTERING)
607     MockContentFilterSettings& mockContentFilterSettings();
608 #endif
609
610 #if ENABLE(CSS_SCROLL_SNAP)
611     ExceptionOr<String> scrollSnapOffsets(Element&);
612     void setPlatformMomentumScrollingPredictionEnabled(bool);
613 #endif
614
615     ExceptionOr<String> pathStringWithShrinkWrappedRects(const Vector<double>& rectComponents, double radius);
616
617     String getCurrentMediaControlsStatusForElement(HTMLMediaElement&);
618
619     String userVisibleString(const DOMURL&);
620     void setShowAllPlugins(bool);
621
622     String resourceLoadStatisticsForOrigin(const String& origin);
623     void setResourceLoadStatisticsEnabled(bool);
624     void setUserGrantsStorageAccess(bool);
625
626 #if ENABLE(STREAMS_API)
627     bool isReadableStreamDisturbed(JSC::ExecState&, JSC::JSValue);
628     JSC::JSValue cloneArrayBuffer(JSC::ExecState&, JSC::JSValue, JSC::JSValue, JSC::JSValue);
629 #endif
630
631     String composedTreeAsText(Node&);
632
633     bool isProcessingUserGesture();
634     double lastHandledUserGestureTimestamp();
635
636     void withUserGesture(RefPtr<VoidCallback>&&);
637
638     RefPtr<GCObservation> observeGC(JSC::JSValue);
639
640     enum class UserInterfaceLayoutDirection : uint8_t { LTR, RTL };
641     void setUserInterfaceLayoutDirection(UserInterfaceLayoutDirection);
642
643     bool userPrefersReducedMotion() const;
644
645     void reportBacktrace();
646
647     enum class BaseWritingDirection { Natural, Ltr, Rtl };
648     void setBaseWritingDirection(BaseWritingDirection);
649
650 #if ENABLE(POINTER_LOCK)
651     bool pageHasPendingPointerLock() const;
652     bool pageHasPointerLock() const;
653 #endif
654
655     Vector<String> accessKeyModifiers() const;
656
657     void setQuickLookPassword(const String&);
658
659     void setAsRunningUserScripts(Document&);
660
661 #if ENABLE(WEBGL)
662     void simulateWebGLContextChanged(WebGLRenderingContext&);
663     void failNextGPUStatusCheck(WebGLRenderingContext&);
664     bool hasLowAndHighPowerGPUs();
665 #endif
666
667     void setPageVisibility(bool isVisible);
668     void setPageIsFocusedAndActive(bool);
669
670
671 #if ENABLE(WEB_RTC)
672     void setH264HardwareEncoderAllowed(bool allowed);
673 #endif
674
675 #if ENABLE(MEDIA_STREAM)
676     void setCameraMediaStreamTrackOrientation(MediaStreamTrack&, int orientation);
677     ExceptionOr<void> setMediaDeviceState(const String& id, const String& property, bool value);
678     unsigned long trackAudioSampleCount() const { return m_trackAudioSampleCount; }
679     unsigned long trackVideoSampleCount() const { return m_trackVideoSampleCount; }
680     void observeMediaStreamTrack(MediaStreamTrack&);
681     using TrackFramePromise = DOMPromiseDeferred<IDLInterface<ImageData>>;
682     void grabNextMediaStreamTrackFrame(TrackFramePromise&&);
683     void delayMediaStreamTrackSamples(MediaStreamTrack&, float);
684     void setMediaStreamTrackMuted(MediaStreamTrack&, bool);
685     void removeMediaStreamTrack(MediaStream&, MediaStreamTrack&);
686     void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack&);
687     void setMediaStreamTrackIdentifier(MediaStreamTrack&, String&& id);
688     void setMediaStreamSourceInterrupted(MediaStreamTrack&, bool);
689 #endif
690
691     String audioSessionCategory() const;
692     double preferredAudioBufferSize() const;
693
694     void clearCacheStorageMemoryRepresentation(DOMPromiseDeferred<void>&&);
695     void cacheStorageEngineRepresentation(DOMPromiseDeferred<IDLDOMString>&&);
696     void setResponseSizeWithPadding(FetchResponse&, uint64_t size);
697     uint64_t responseSizeWithPadding(FetchResponse&) const;
698
699     void setConsoleMessageListener(RefPtr<StringCallback>&&);
700
701 #if ENABLE(SERVICE_WORKER)
702     using HasRegistrationPromise = DOMPromiseDeferred<IDLBoolean>;
703     void hasServiceWorkerRegistration(const String& clientURL, HasRegistrationPromise&&);
704     void terminateServiceWorker(ServiceWorker&);
705     bool hasServiceWorkerConnection();
706 #endif
707
708 #if ENABLE(APPLE_PAY)
709     MockPaymentCoordinator& mockPaymentCoordinator(Document&);
710 #endif
711
712     bool isSystemPreviewLink(Element&) const;
713     bool isSystemPreviewImage(Element&) const;
714
715     bool usingAppleInternalSDK() const;
716
717     struct NowPlayingState {
718         String title;
719         double duration;
720         double elapsedTime;
721         uint64_t uniqueIdentifier;
722         bool hasActiveSession;
723         bool registeredAsNowPlayingApplication;
724     };
725     ExceptionOr<NowPlayingState> nowPlayingState() const;
726
727 #if ENABLE(VIDEO)
728     using PlaybackControlsPurpose = MediaElementSession::PlaybackControlsPurpose;
729     RefPtr<HTMLMediaElement> bestMediaElementForShowingPlaybackControlsManager(PlaybackControlsPurpose);
730
731     using MediaSessionState = PlatformMediaSession::State;
732     MediaSessionState mediaSessionState(HTMLMediaElement&);
733 #endif
734
735     void setCaptureExtraNetworkLoadMetricsEnabled(bool);
736     String ongoingLoadsDescriptions() const;
737
738     void reloadWithoutContentExtensions();
739
740     void setUseSystemAppearance(bool);
741
742     size_t pluginCount();
743
744     void notifyResourceLoadObserver();
745
746     unsigned primaryScreenDisplayID();
747
748     bool capsLockIsOn();
749         
750     bool supportsVCPEncoder();
751         
752     using HEVCParameterSet = WebCore::HEVCParameterSet;
753     std::optional<HEVCParameterSet> parseHEVCCodecParameters(const String& codecString);
754
755     struct CookieData {
756         String name;
757         String value;
758         String domain;
759         // Expiration dates are expressed as milliseconds since the UNIX epoch.
760         double expires { 0 };
761         bool isHttpOnly { false };
762         bool isSecure { false };
763         bool isSession { false };
764         bool isSameSiteLax { false };
765         bool isSameSiteStrict { false };
766
767         CookieData(Cookie cookie)
768             : name(cookie.name)
769             , value(cookie.value)
770             , domain(cookie.domain)
771             , expires(cookie.expires)
772             , isHttpOnly(cookie.httpOnly)
773             , isSecure(cookie.secure)
774             , isSession(cookie.session)
775             , isSameSiteLax(cookie.sameSite == Cookie::SameSitePolicy::Lax)
776             , isSameSiteStrict(cookie.sameSite == Cookie::SameSitePolicy::Strict)
777         {
778             ASSERT(!(isSameSiteLax && isSameSiteStrict));
779         }
780
781         CookieData()
782         {
783         }
784     };
785     Vector<CookieData> getCookies() const;
786
787 private:
788     explicit Internals(Document&);
789     Document* contextDocument() const;
790     Frame* frame() const;
791
792     ExceptionOr<RenderedDocumentMarker*> markerAt(Node&, const String& markerType, unsigned index);
793
794     // RealtimeMediaSource::Observer API
795 #if ENABLE(MEDIA_STREAM)
796     void videoSampleAvailable(MediaSample&) final;
797     void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final { m_trackAudioSampleCount++; }
798
799     OrientationNotifier m_orientationNotifier;
800     unsigned long m_trackVideoSampleCount { 0 };
801     unsigned long m_trackAudioSampleCount { 0 };
802     RefPtr<MediaStreamTrack> m_track;
803     std::optional<TrackFramePromise> m_nextTrackFramePromise;
804 #endif
805
806     std::unique_ptr<InspectorStubFrontend> m_inspectorFrontend;
807     RefPtr<CacheStorageConnection> m_cacheStorageConnection;
808 };
809
810 } // namespace WebCore