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