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