Make it possible to test rubber-banding in overflow scroll
[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 "ExceptionOr.h"
32 #include "JSDOMPromiseDeferred.h"
33 #include "OrientationNotifier.h"
34 #include "PageConsoleClient.h"
35 #include "RealtimeMediaSource.h"
36 #include <runtime/Float32Array.h>
37 #include <wtf/Optional.h>
38
39 #if ENABLE(MEDIA_SESSION)
40 #include "MediaSessionInterruptionProvider.h"
41 #endif
42
43 namespace WebCore {
44
45 class AnimationTimeline;
46 class AudioContext;
47 class CacheStorageConnection;
48 class DOMRect;
49 class DOMRectList;
50 class DOMURL;
51 class DOMWindow;
52 class Document;
53 class Element;
54 class ExtendableEvent;
55 class FetchEvent;
56 class FetchResponse;
57 class File;
58 class Frame;
59 class GCObservation;
60 class HTMLImageElement;
61 class HTMLInputElement;
62 class HTMLLinkElement;
63 class HTMLMediaElement;
64 class HTMLSelectElement;
65 class ImageData;
66 class InspectorStubFrontend;
67 class InternalSettings;
68 class MallocStatistics;
69 class MediaSession;
70 class MediaStream;
71 class MediaStreamTrack;
72 class MemoryInfo;
73 class MockCDMFactory;
74 class MockContentFilterSettings;
75 class MockPageOverlay;
76 class MockPaymentCoordinator;
77 class NodeList;
78 class Page;
79 class Range;
80 class RenderedDocumentMarker;
81 class RTCPeerConnection;
82 class SVGSVGElement;
83 class SerializedScriptValue;
84 class SourceBuffer;
85 class StringCallback;
86 class StyleSheet;
87 class TimeRanges;
88 class TypeConversions;
89 class WebGLRenderingContext;
90 class XMLHttpRequest;
91
92 class Internals final : public RefCounted<Internals>,  private ContextDestructionObserver
93 #if ENABLE(MEDIA_STREAM)
94     , private RealtimeMediaSource::Observer
95 #endif
96     {
97 public:
98     static Ref<Internals> create(Document&);
99     virtual ~Internals();
100
101     static void resetToConsistentState(Page&);
102
103     ExceptionOr<String> elementRenderTreeAsText(Element&);
104     bool hasPausedImageAnimations(Element&);
105
106     String address(Node&);
107     bool nodeNeedsStyleRecalc(Node&);
108     String styleChangeType(Node&);
109     String description(JSC::JSValue);
110
111     bool isPreloaded(const String& url);
112     bool isLoadingFromMemoryCache(const String& url);
113     String fetchResponseSource(FetchResponse&);
114     String xhrResponseSource(XMLHttpRequest&);
115     bool isSharingStyleSheetContents(HTMLLinkElement&, HTMLLinkElement&);
116     bool isStyleSheetLoadingSubresources(HTMLLinkElement&);
117     enum class CachePolicy { UseProtocolCachePolicy, ReloadIgnoringCacheData, ReturnCacheDataElseLoad, ReturnCacheDataDontLoad };
118     void setOverrideCachePolicy(CachePolicy);
119     ExceptionOr<void> setCanShowModalDialogOverride(bool allow);
120     enum class ResourceLoadPriority { ResourceLoadPriorityVeryLow, ResourceLoadPriorityLow, ResourceLoadPriorityMedium, ResourceLoadPriorityHigh, ResourceLoadPriorityVeryHigh };
121     void setOverrideResourceLoadPriority(ResourceLoadPriority);
122     void setStrictRawResourceValidationPolicyDisabled(bool);
123
124     void clearMemoryCache();
125     void pruneMemoryCacheToSize(unsigned size);
126     void destroyDecodedDataForAllImages();
127     unsigned memoryCacheSize() const;
128
129     unsigned imageFrameIndex(HTMLImageElement&);
130     void setImageFrameDecodingDuration(HTMLImageElement&, float duration);
131     void resetImageAnimation(HTMLImageElement&);
132     bool isImageAnimating(HTMLImageElement&);
133     void setClearDecoderAfterAsyncFrameRequestForTesting(HTMLImageElement&, bool enabled);
134     unsigned imageDecodeCount(HTMLImageElement&);
135     void setLargeImageAsyncDecodingEnabledForTesting(HTMLImageElement&, bool enabled);
136
137     void setGridMaxTracksLimit(unsigned);
138
139     void clearPageCache();
140     unsigned pageCacheSize() const;
141
142     void disableTileSizeUpdateDelay();
143
144     void setSpeculativeTilingDelayDisabledForTesting(bool);
145
146     Ref<CSSComputedStyleDeclaration> computedStyleIncludingVisitedInfo(Element&) const;
147
148     Node* ensureUserAgentShadowRoot(Element& host);
149     Node* shadowRoot(Element& host);
150     ExceptionOr<String> shadowRootType(const Node&) const;
151     String shadowPseudoId(Element&);
152     void setShadowPseudoId(Element&, const String&);
153
154     // CSS Deferred Parsing Testing
155     unsigned deferredStyleRulesCount(StyleSheet&);
156     unsigned deferredGroupRulesCount(StyleSheet&);
157     unsigned deferredKeyframesRulesCount(StyleSheet&);
158
159     // DOMTimers throttling testing.
160     ExceptionOr<bool> isTimerThrottled(int timeoutId);
161     bool isRequestAnimationFrameThrottled() const;
162     double requestAnimationFrameInterval() const;
163     bool scriptedAnimationsAreSuspended() const;
164     bool areTimersThrottled() const;
165
166     enum EventThrottlingBehavior { Responsive, Unresponsive };
167     void setEventThrottlingBehaviorOverride(std::optional<EventThrottlingBehavior>);
168     std::optional<EventThrottlingBehavior> eventThrottlingBehaviorOverride() const;
169
170     // Spatial Navigation testing.
171     ExceptionOr<unsigned> lastSpatialNavigationCandidateCount() const;
172
173     // CSS Animation testing.
174     unsigned numberOfActiveAnimations() const;
175     ExceptionOr<bool> animationsAreSuspended() const;
176     ExceptionOr<void> suspendAnimations() const;
177     ExceptionOr<void> resumeAnimations() const;
178     ExceptionOr<bool> pauseAnimationAtTimeOnElement(const String& animationName, double pauseTime, Element&);
179     ExceptionOr<bool> pauseAnimationAtTimeOnPseudoElement(const String& animationName, double pauseTime, Element&, const String& pseudoId);
180     double animationsInterval() const;
181
182     // CSS Transition testing.
183     ExceptionOr<bool> pauseTransitionAtTimeOnElement(const String& propertyName, double pauseTime, Element&);
184     ExceptionOr<bool> pauseTransitionAtTimeOnPseudoElement(const String& property, double pauseTime, Element&, const String& pseudoId);
185
186     Node* treeScopeRootNode(Node&);
187     Node* parentTreeScope(Node&);
188
189     String visiblePlaceholder(Element&);
190     void selectColorInColorChooser(HTMLInputElement&, const String& colorValue);
191     ExceptionOr<Vector<String>> formControlStateOfPreviousHistoryItem();
192     ExceptionOr<void> setFormControlStateOfPreviousHistoryItem(const Vector<String>&);
193
194     ExceptionOr<Ref<DOMRect>> absoluteCaretBounds();
195
196     Ref<DOMRect> boundingBox(Element&);
197
198     ExceptionOr<Ref<DOMRectList>> inspectorHighlightRects();
199     ExceptionOr<String> inspectorHighlightObject();
200
201     ExceptionOr<unsigned> markerCountForNode(Node&, const String&);
202     ExceptionOr<RefPtr<Range>> markerRangeForNode(Node&, const String& markerType, unsigned index);
203     ExceptionOr<String> markerDescriptionForNode(Node&, const String& markerType, unsigned index);
204     ExceptionOr<String> dumpMarkerRects(const String& markerType);
205     void addTextMatchMarker(const Range&, bool isActive);
206     ExceptionOr<void> setMarkedTextMatchesAreHighlighted(bool);
207
208     void invalidateFontCache();
209     void setFontSmoothingEnabled(bool);
210
211     ExceptionOr<void> setLowPowerModeEnabled(bool);
212
213     ExceptionOr<void> setScrollViewPosition(int x, int y);
214     ExceptionOr<void> unconstrainedScrollTo(Element&, double x, double y);
215
216     ExceptionOr<Ref<DOMRect>> layoutViewportRect();
217     ExceptionOr<Ref<DOMRect>> visualViewportRect();
218
219     ExceptionOr<void> setViewBaseBackgroundColor(const String& colorValue);
220
221     ExceptionOr<void> setPagination(const String& mode, int gap, int pageLength);
222     ExceptionOr<void> setPaginationLineGridEnabled(bool);
223     ExceptionOr<String> configurationForViewport(float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight);
224
225     ExceptionOr<bool> wasLastChangeUserEdit(Element& textField);
226     bool elementShouldAutoComplete(HTMLInputElement&);
227     void setEditingValue(HTMLInputElement&, const String&);
228     void setAutofilled(HTMLInputElement&, bool enabled);
229     enum class AutoFillButtonType { AutoFillButtonTypeNone, AutoFillButtonTypeContacts, AutoFillButtonTypeCredentials };
230     void setShowAutoFillButton(HTMLInputElement&, AutoFillButtonType);
231     ExceptionOr<void> scrollElementToRect(Element&, int x, int y, int w, int h);
232
233     ExceptionOr<String> autofillFieldName(Element&);
234
235     ExceptionOr<void> paintControlTints();
236
237     RefPtr<Range> rangeFromLocationAndLength(Element& scope, int rangeLocation, int rangeLength);
238     unsigned locationFromRange(Element& scope, const Range&);
239     unsigned lengthFromRange(Element& scope, const Range&);
240     String rangeAsText(const Range&);
241     Ref<Range> subrange(Range&, int rangeLocation, int rangeLength);
242     ExceptionOr<RefPtr<Range>> rangeForDictionaryLookupAtLocation(int x, int y);
243     RefPtr<Range> rangeOfStringNearLocation(const Range&, const String&, unsigned);
244
245     ExceptionOr<void> setDelegatesScrolling(bool enabled);
246
247     ExceptionOr<int> lastSpellCheckRequestSequence();
248     ExceptionOr<int> lastSpellCheckProcessedSequence();
249
250     Vector<String> userPreferredLanguages() const;
251     void setUserPreferredLanguages(const Vector<String>&);
252
253     Vector<String> userPreferredAudioCharacteristics() const;
254     void setUserPreferredAudioCharacteristic(const String&);
255
256     ExceptionOr<unsigned> wheelEventHandlerCount();
257     ExceptionOr<unsigned> touchEventHandlerCount();
258
259     ExceptionOr<Ref<DOMRectList>> touchEventRectsForEvent(const String&);
260     ExceptionOr<Ref<DOMRectList>> passiveTouchEventListenerRects();
261
262     ExceptionOr<RefPtr<NodeList>> nodesFromRect(Document&, int x, int y, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowUserAgentShadowContent, bool allowChildFrameContent) const;
263
264     String parserMetaData(JSC::JSValue = JSC::JSValue::JSUndefined);
265
266     void updateEditorUINowIfScheduled();
267
268     bool hasSpellingMarker(int from, int length);
269     bool hasGrammarMarker(int from, int length);
270     bool hasAutocorrectedMarker(int from, int length);
271     void setContinuousSpellCheckingEnabled(bool);
272     void setAutomaticQuoteSubstitutionEnabled(bool);
273     void setAutomaticLinkDetectionEnabled(bool);
274     void setAutomaticDashSubstitutionEnabled(bool);
275     void setAutomaticTextReplacementEnabled(bool);
276     void setAutomaticSpellingCorrectionEnabled(bool);
277
278     void handleAcceptedCandidate(const String& candidate, unsigned location, unsigned length);
279
280     bool isOverwriteModeEnabled();
281     void toggleOverwriteModeEnabled();
282
283     ExceptionOr<RefPtr<Range>> rangeOfString(const String&, RefPtr<Range>&&, const Vector<String>& findOptions);
284     ExceptionOr<unsigned> countMatchesForText(const String&, const Vector<String>& findOptions, const String& markMatches);
285     ExceptionOr<unsigned> countFindMatches(const String&, const Vector<String>& findOptions);
286
287     unsigned numberOfScrollableAreas();
288
289     ExceptionOr<bool> isPageBoxVisible(int pageNumber);
290
291     static const char* internalsId;
292
293     InternalSettings* settings() const;
294     unsigned workerThreadCount() const;
295     ExceptionOr<bool> areSVGAnimationsPaused() const;
296     ExceptionOr<double> svgAnimationsInterval(SVGSVGElement&) const;
297
298     enum {
299         // Values need to be kept in sync with Internals.idl.
300         LAYER_TREE_INCLUDES_VISIBLE_RECTS = 1,
301         LAYER_TREE_INCLUDES_TILE_CACHES = 2,
302         LAYER_TREE_INCLUDES_REPAINT_RECTS = 4,
303         LAYER_TREE_INCLUDES_PAINTING_PHASES = 8,
304         LAYER_TREE_INCLUDES_CONTENT_LAYERS = 16,
305         LAYER_TREE_INCLUDES_ACCELERATES_DRAWING = 32,
306         LAYER_TREE_INCLUDES_BACKING_STORE_ATTACHED = 64,
307     };
308     ExceptionOr<String> layerTreeAsText(Document&, unsigned short flags) const;
309     ExceptionOr<uint64_t> layerIDForElement(Element&);
310     ExceptionOr<String> repaintRectsAsText() const;
311     ExceptionOr<String> scrollingStateTreeAsText() const;
312     ExceptionOr<String> mainThreadScrollingReasons() const;
313     ExceptionOr<Ref<DOMRectList>> nonFastScrollableRects() const;
314
315     ExceptionOr<void> setElementUsesDisplayListDrawing(Element&, bool usesDisplayListDrawing);
316     ExceptionOr<void> setElementTracksDisplayListReplay(Element&, bool isTrackingReplay);
317
318     enum {
319         // Values need to be kept in sync with Internals.idl.
320         DISPLAY_LIST_INCLUDES_PLATFORM_OPERATIONS = 1,
321     };
322     ExceptionOr<String> displayListForElement(Element&, unsigned short flags);
323     ExceptionOr<String> replayDisplayListForElement(Element&, unsigned short flags);
324
325     ExceptionOr<void> garbageCollectDocumentResources() const;
326
327     void beginSimulatedMemoryPressure();
328     void endSimulatedMemoryPressure();
329     bool isUnderMemoryPressure();
330
331     ExceptionOr<void> insertAuthorCSS(const String&) const;
332     ExceptionOr<void> insertUserCSS(const String&) const;
333
334     unsigned numberOfLiveNodes() const;
335     unsigned numberOfLiveDocuments() const;
336     unsigned referencingNodeCount(const Document&) const;
337
338     RefPtr<DOMWindow> openDummyInspectorFrontend(const String& url);
339     void closeDummyInspectorFrontend();
340     ExceptionOr<void> setInspectorIsUnderTest(bool);
341
342     String counterValue(Element&);
343
344     int pageNumber(Element&, float pageWidth = 800, float pageHeight = 600);
345     Vector<String> shortcutIconURLs() const;
346
347     int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
348     ExceptionOr<String> pageProperty(const String& propertyName, int pageNumber) const;
349     ExceptionOr<String> pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) const;
350
351     ExceptionOr<float> pageScaleFactor() const;
352
353     ExceptionOr<void> setPageScaleFactor(float scaleFactor, int x, int y);
354     ExceptionOr<void> setPageZoomFactor(float);
355     ExceptionOr<void> setTextZoomFactor(float);
356
357     ExceptionOr<void> setUseFixedLayout(bool);
358     ExceptionOr<void> setFixedLayoutSize(int width, int height);
359     ExceptionOr<void> setViewExposedRect(float left, float top, float width, float height);
360     void setPrinting(int width, int height);
361
362     void setHeaderHeight(float);
363     void setFooterHeight(float);
364
365     void setTopContentInset(float);
366
367 #if ENABLE(FULLSCREEN_API)
368     void webkitWillEnterFullScreenForElement(Element&);
369     void webkitDidEnterFullScreenForElement(Element&);
370     void webkitWillExitFullScreenForElement(Element&);
371     void webkitDidExitFullScreenForElement(Element&);
372 #endif
373
374     WEBCORE_TESTSUPPORT_EXPORT void setApplicationCacheOriginQuota(unsigned long long);
375
376     void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
377     void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
378
379     void registerDefaultPortForProtocol(unsigned short port, const String& protocol);
380
381     Ref<MallocStatistics> mallocStatistics() const;
382     Ref<TypeConversions> typeConversions() const;
383     Ref<MemoryInfo> memoryInfo() const;
384
385     Vector<String> getReferencedFilePaths() const;
386
387     ExceptionOr<void> startTrackingRepaints();
388     ExceptionOr<void> stopTrackingRepaints();
389
390     ExceptionOr<void> startTrackingLayerFlushes();
391     ExceptionOr<unsigned> layerFlushCount();
392
393     ExceptionOr<void> startTrackingStyleRecalcs();
394     ExceptionOr<unsigned> styleRecalcCount();
395     unsigned lastStyleUpdateSize() const;
396
397     ExceptionOr<void> startTrackingCompositingUpdates();
398     ExceptionOr<unsigned> compositingUpdateCount();
399
400     ExceptionOr<void> updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*);
401     unsigned layoutCount() const;
402
403     Ref<ArrayBuffer> serializeObject(const RefPtr<SerializedScriptValue>&) const;
404     Ref<SerializedScriptValue> deserializeBuffer(ArrayBuffer&) const;
405
406     bool isFromCurrentWorld(JSC::JSValue) const;
407
408     void setUsesOverlayScrollbars(bool);
409     void setUsesMockScrollAnimator(bool);
410
411     ExceptionOr<String> getCurrentCursorInfo();
412
413     String markerTextForListItem(Element&);
414
415     String toolTipFromElement(Element&) const;
416
417     void forceReload(bool endToEnd);
418     void reloadExpiredOnly();
419
420     void enableAutoSizeMode(bool enabled, int minimumWidth, int minimumHeight, int maximumWidth, int maximumHeight);
421
422 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
423     void initializeMockCDM();
424 #endif
425
426 #if ENABLE(ENCRYPTED_MEDIA)
427     Ref<MockCDMFactory> registerMockCDM();
428 #endif
429
430 #if ENABLE(SPEECH_SYNTHESIS)
431     void enableMockSpeechSynthesizer();
432 #endif
433
434 #if ENABLE(MEDIA_STREAM)
435     void setMockMediaCaptureDevicesEnabled(bool);
436 #endif
437
438 #if ENABLE(WEB_RTC)
439     void emulateRTCPeerConnectionPlatformEvent(RTCPeerConnection&, const String& action);
440     void useMockRTCPeerConnectionFactory(const String&);
441     void setICECandidateFiltering(bool);
442     void setEnumeratingAllNetworkInterfacesEnabled(bool);
443     void stopPeerConnection(RTCPeerConnection&);
444     void applyRotationForOutgoingVideoSources(RTCPeerConnection&);
445 #endif
446
447     String getImageSourceURL(Element&);
448
449 #if ENABLE(VIDEO)
450     Vector<String> mediaResponseSources(HTMLMediaElement&);
451     Vector<String> mediaResponseContentRanges(HTMLMediaElement&);
452     void simulateAudioInterruption(HTMLMediaElement&);
453     ExceptionOr<bool> mediaElementHasCharacteristic(HTMLMediaElement&, const String&);
454 #endif
455
456     bool isSelectPopupVisible(HTMLSelectElement&);
457
458     ExceptionOr<String> captionsStyleSheetOverride();
459     ExceptionOr<void> setCaptionsStyleSheetOverride(const String&);
460     ExceptionOr<void> setPrimaryAudioTrackLanguageOverride(const String&);
461     ExceptionOr<void> setCaptionDisplayMode(const String&);
462
463 #if ENABLE(VIDEO)
464     Ref<TimeRanges> createTimeRanges(Float32Array& startTimes, Float32Array& endTimes);
465     double closestTimeToTimeRanges(double time, TimeRanges&);
466 #endif
467
468     ExceptionOr<Ref<DOMRect>> selectionBounds();
469
470     ExceptionOr<bool> isPluginUnavailabilityIndicatorObscured(Element&);
471     bool isPluginSnapshotted(Element&);
472
473 #if ENABLE(MEDIA_SOURCE)
474     WEBCORE_TESTSUPPORT_EXPORT void initializeMockMediaSource();
475     Vector<String> bufferedSamplesForTrackID(SourceBuffer&, const AtomicString&);
476     Vector<String> enqueuedSamplesForTrackID(SourceBuffer&, const AtomicString&);
477     void setShouldGenerateTimestamps(SourceBuffer&, bool);
478 #endif
479
480 #if ENABLE(VIDEO)
481     ExceptionOr<void> beginMediaSessionInterruption(const String&);
482     void endMediaSessionInterruption(const String&);
483     void applicationWillBecomeInactive();
484     void applicationDidBecomeActive();
485     void applicationWillEnterForeground(bool suspendedUnderLock) const;
486     void applicationDidEnterBackground(bool suspendedUnderLock) const;
487     ExceptionOr<void> setMediaSessionRestrictions(const String& mediaType, StringView restrictionsString);
488     ExceptionOr<String> mediaSessionRestrictions(const String& mediaType) const;
489     void setMediaElementRestrictions(HTMLMediaElement&, StringView restrictionsString);
490     ExceptionOr<void> postRemoteControlCommand(const String&, float argument);
491     bool elementIsBlockingDisplaySleep(HTMLMediaElement&) const;
492 #endif
493
494 #if ENABLE(MEDIA_SESSION)
495     void sendMediaSessionStartOfInterruptionNotification(MediaSessionInterruptingCategory);
496     void sendMediaSessionEndOfInterruptionNotification(MediaSessionInterruptingCategory);
497     String mediaSessionCurrentState(MediaSession&) const;
498     double mediaElementPlayerVolume(HTMLMediaElement&) const;
499     enum class MediaControlEvent { PlayPause, NextTrack, PreviousTrack };
500     void sendMediaControlEvent(MediaControlEvent);
501 #endif
502
503 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
504     void setMockMediaPlaybackTargetPickerEnabled(bool);
505     ExceptionOr<void> setMockMediaPlaybackTargetPickerState(const String& deviceName, const String& deviceState);
506 #endif
507
508 #if ENABLE(WEB_AUDIO)
509     void setAudioContextRestrictions(AudioContext&, StringView restrictionsString);
510 #endif
511
512     void simulateSystemSleep() const;
513     void simulateSystemWake() const;
514
515     enum class PageOverlayType { View, Document };
516     ExceptionOr<Ref<MockPageOverlay>> installMockPageOverlay(PageOverlayType);
517     ExceptionOr<String> pageOverlayLayerTreeAsText(unsigned short flags) const;
518
519     void setPageMuted(StringView);
520     String pageMediaState();
521
522     void setPageDefersLoading(bool);
523
524     RefPtr<File> createFile(const String&);
525     void queueMicroTask(int);
526     bool testPreloaderSettingViewport();
527
528 #if ENABLE(CONTENT_FILTERING)
529     MockContentFilterSettings& mockContentFilterSettings();
530 #endif
531
532 #if ENABLE(CSS_SCROLL_SNAP)
533     ExceptionOr<String> scrollSnapOffsets(Element&);
534     void setPlatformMomentumScrollingPredictionEnabled(bool);
535 #endif
536
537     ExceptionOr<String> pathStringWithShrinkWrappedRects(const Vector<double>& rectComponents, double radius);
538
539     String getCurrentMediaControlsStatusForElement(HTMLMediaElement&);
540
541     String userVisibleString(const DOMURL&);
542     void setShowAllPlugins(bool);
543
544     String resourceLoadStatisticsForOrigin(const String& origin);
545     void setResourceLoadStatisticsEnabled(bool);
546     void setUserGrantsStorageAccess(bool);
547
548 #if ENABLE(STREAMS_API)
549     bool isReadableStreamDisturbed(JSC::ExecState&, JSC::JSValue);
550     JSC::JSValue cloneArrayBuffer(JSC::ExecState&, JSC::JSValue, JSC::JSValue, JSC::JSValue);
551 #endif
552
553     String composedTreeAsText(Node&);
554
555     bool isProcessingUserGesture();
556     double lastHandledUserGestureTimestamp();
557
558     RefPtr<GCObservation> observeGC(JSC::JSValue);
559
560     enum class UserInterfaceLayoutDirection { LTR, RTL };
561     void setUserInterfaceLayoutDirection(UserInterfaceLayoutDirection);
562
563     bool userPrefersReducedMotion() const;
564
565     void reportBacktrace();
566
567     enum class BaseWritingDirection { Natural, Ltr, Rtl };
568     void setBaseWritingDirection(BaseWritingDirection);
569
570 #if ENABLE(POINTER_LOCK)
571     bool pageHasPendingPointerLock() const;
572     bool pageHasPointerLock() const;
573 #endif
574
575     Vector<String> accessKeyModifiers() const;
576
577     void setQuickLookPassword(const String&);
578
579     void setAsRunningUserScripts(Document&);
580
581 #if ENABLE(WEBGL)
582     void simulateWebGLContextChanged(WebGLRenderingContext&);
583     void failNextGPUStatusCheck(WebGLRenderingContext&);
584 #endif
585
586     void setPageVisibility(bool isVisible);
587
588 #if ENABLE(WEB_RTC)
589     void setH264HardwareEncoderAllowed(bool allowed);
590 #endif
591
592 #if ENABLE(MEDIA_STREAM)
593     void setCameraMediaStreamTrackOrientation(MediaStreamTrack&, int orientation);
594     ExceptionOr<void> setMediaDeviceState(const String& id, const String& property, bool value);
595     unsigned long trackAudioSampleCount() const { return m_trackAudioSampleCount; }
596     unsigned long trackVideoSampleCount() const { return m_trackVideoSampleCount; }
597     void observeMediaStreamTrack(MediaStreamTrack&);
598     using TrackFramePromise = DOMPromiseDeferred<IDLInterface<ImageData>>;
599     void grabNextMediaStreamTrackFrame(TrackFramePromise&&);
600     void delayMediaStreamTrackSamples(MediaStreamTrack&, float);
601     void setMediaStreamTrackMuted(MediaStreamTrack&, bool);
602     void removeMediaStreamTrack(MediaStream&, MediaStreamTrack&);
603     void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack&);
604 #endif
605
606     String audioSessionCategory() const;
607
608     void clearCacheStorageMemoryRepresentation(DOMPromiseDeferred<void>&&);
609     void cacheStorageEngineRepresentation(DOMPromiseDeferred<IDLDOMString>&&);
610     void setResponseSizeWithPadding(FetchResponse&, uint64_t size);
611     uint64_t responseSizeWithPadding(FetchResponse&) const;
612
613     void setConsoleMessageListener(RefPtr<StringCallback>&&);
614
615 #if ENABLE(SERVICE_WORKER)
616     void waitForFetchEventToFinish(FetchEvent&, DOMPromiseDeferred<IDLInterface<FetchResponse>>&&);
617     void waitForExtendableEventToFinish(ExtendableEvent&, DOMPromiseDeferred<void>&&);
618     Ref<FetchEvent> createBeingDispatchedFetchEvent(ScriptExecutionContext&);
619     Ref<ExtendableEvent> createTrustedExtendableEvent();
620 #endif
621
622     bool hasServiceWorkerRegisteredForOrigin(const String&);
623         
624 #if ENABLE(APPLE_PAY)
625     MockPaymentCoordinator& mockPaymentCoordinator() const;
626 #endif
627
628     String timelineDescription(AnimationTimeline&);
629     void setTimelineCurrentTime(AnimationTimeline&, double);
630
631 private:
632     explicit Internals(Document&);
633     Document* contextDocument() const;
634     Frame* frame() const;
635
636     ExceptionOr<RenderedDocumentMarker*> markerAt(Node&, const String& markerType, unsigned index);
637
638     // RealtimeMediaSource::Observer API
639 #if ENABLE(MEDIA_STREAM)
640     void videoSampleAvailable(MediaSample&) final;
641     void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final { m_trackAudioSampleCount++; }
642
643     OrientationNotifier m_orientationNotifier;
644     unsigned long m_trackVideoSampleCount { 0 };
645     unsigned long m_trackAudioSampleCount { 0 };
646     RefPtr<MediaStreamTrack> m_track;
647     std::optional<TrackFramePromise> m_nextTrackFramePromise;
648 #endif
649
650     std::unique_ptr<InspectorStubFrontend> m_inspectorFrontend;
651     RefPtr<CacheStorageConnection> m_cacheStorageConnection;
652
653 #if ENABLE(APPLE_PAY)
654     MockPaymentCoordinator* m_mockPaymentCoordinator { nullptr };
655 #endif
656 };
657
658 } // namespace WebCore