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