Preventively expect UTF8 strings from libwebrtc SDP and error messages
[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     void setFullscreenInsetTop(double);
387     void setFullscreenAutoHideDelay(double);
388
389     WEBCORE_TESTSUPPORT_EXPORT void setApplicationCacheOriginQuota(unsigned long long);
390
391     void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
392     void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
393
394     void registerDefaultPortForProtocol(unsigned short port, const String& protocol);
395
396     Ref<MallocStatistics> mallocStatistics() const;
397     Ref<TypeConversions> typeConversions() const;
398     Ref<MemoryInfo> memoryInfo() const;
399
400     Vector<String> getReferencedFilePaths() const;
401
402     ExceptionOr<void> startTrackingRepaints();
403     ExceptionOr<void> stopTrackingRepaints();
404
405     ExceptionOr<void> startTrackingLayerFlushes();
406     ExceptionOr<unsigned> layerFlushCount();
407
408     ExceptionOr<void> startTrackingStyleRecalcs();
409     ExceptionOr<unsigned> styleRecalcCount();
410     unsigned lastStyleUpdateSize() const;
411
412     ExceptionOr<void> startTrackingCompositingUpdates();
413     ExceptionOr<unsigned> compositingUpdateCount();
414
415     ExceptionOr<void> updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*);
416     unsigned layoutCount() const;
417
418     Ref<ArrayBuffer> serializeObject(const RefPtr<SerializedScriptValue>&) const;
419     Ref<SerializedScriptValue> deserializeBuffer(ArrayBuffer&) const;
420
421     bool isFromCurrentWorld(JSC::JSValue) const;
422
423     void setUsesOverlayScrollbars(bool);
424     void setUsesMockScrollAnimator(bool);
425
426     ExceptionOr<String> getCurrentCursorInfo();
427
428     String markerTextForListItem(Element&);
429
430     String toolTipFromElement(Element&) const;
431
432     void forceReload(bool endToEnd);
433     void reloadExpiredOnly();
434
435     void enableAutoSizeMode(bool enabled, int minimumWidth, int minimumHeight, int maximumWidth, int maximumHeight);
436
437 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
438     void initializeMockCDM();
439 #endif
440
441 #if ENABLE(ENCRYPTED_MEDIA)
442     Ref<MockCDMFactory> registerMockCDM();
443 #endif
444
445 #if ENABLE(SPEECH_SYNTHESIS)
446     void enableMockSpeechSynthesizer();
447 #endif
448
449 #if ENABLE(MEDIA_STREAM)
450     void setMockMediaCaptureDevicesEnabled(bool);
451 #endif
452
453 #if ENABLE(WEB_RTC)
454     void emulateRTCPeerConnectionPlatformEvent(RTCPeerConnection&, const String& action);
455     void useMockRTCPeerConnectionFactory(const String&);
456     void setICECandidateFiltering(bool);
457     void setEnumeratingAllNetworkInterfacesEnabled(bool);
458     void stopPeerConnection(RTCPeerConnection&);
459     void applyRotationForOutgoingVideoSources(RTCPeerConnection&);
460 #endif
461
462     String getImageSourceURL(Element&);
463
464 #if ENABLE(VIDEO)
465     Vector<String> mediaResponseSources(HTMLMediaElement&);
466     Vector<String> mediaResponseContentRanges(HTMLMediaElement&);
467     void simulateAudioInterruption(HTMLMediaElement&);
468     ExceptionOr<bool> mediaElementHasCharacteristic(HTMLMediaElement&, const String&);
469     void beginSimulatedHDCPError(HTMLMediaElement&);
470     void endSimulatedHDCPError(HTMLMediaElement&);
471 #endif
472
473     bool isSelectPopupVisible(HTMLSelectElement&);
474
475     ExceptionOr<String> captionsStyleSheetOverride();
476     ExceptionOr<void> setCaptionsStyleSheetOverride(const String&);
477     ExceptionOr<void> setPrimaryAudioTrackLanguageOverride(const String&);
478     ExceptionOr<void> setCaptionDisplayMode(const String&);
479
480 #if ENABLE(VIDEO)
481     Ref<TimeRanges> createTimeRanges(Float32Array& startTimes, Float32Array& endTimes);
482     double closestTimeToTimeRanges(double time, TimeRanges&);
483 #endif
484
485     ExceptionOr<Ref<DOMRect>> selectionBounds();
486
487     ExceptionOr<bool> isPluginUnavailabilityIndicatorObscured(Element&);
488     ExceptionOr<String> unavailablePluginReplacementText(Element&);
489     bool isPluginSnapshotted(Element&);
490
491 #if ENABLE(MEDIA_SOURCE)
492     WEBCORE_TESTSUPPORT_EXPORT void initializeMockMediaSource();
493     Vector<String> bufferedSamplesForTrackID(SourceBuffer&, const AtomicString&);
494     Vector<String> enqueuedSamplesForTrackID(SourceBuffer&, const AtomicString&);
495     void setShouldGenerateTimestamps(SourceBuffer&, bool);
496 #endif
497
498 #if ENABLE(VIDEO)
499     ExceptionOr<void> beginMediaSessionInterruption(const String&);
500     void endMediaSessionInterruption(const String&);
501     void applicationWillBecomeInactive();
502     void applicationDidBecomeActive();
503     void applicationWillEnterForeground(bool suspendedUnderLock) const;
504     void applicationDidEnterBackground(bool suspendedUnderLock) const;
505     ExceptionOr<void> setMediaSessionRestrictions(const String& mediaType, StringView restrictionsString);
506     ExceptionOr<String> mediaSessionRestrictions(const String& mediaType) const;
507     void setMediaElementRestrictions(HTMLMediaElement&, StringView restrictionsString);
508     ExceptionOr<void> postRemoteControlCommand(const String&, float argument);
509     bool elementIsBlockingDisplaySleep(HTMLMediaElement&) const;
510 #endif
511
512 #if ENABLE(MEDIA_SESSION)
513     void sendMediaSessionStartOfInterruptionNotification(MediaSessionInterruptingCategory);
514     void sendMediaSessionEndOfInterruptionNotification(MediaSessionInterruptingCategory);
515     String mediaSessionCurrentState(MediaSession&) const;
516     double mediaElementPlayerVolume(HTMLMediaElement&) const;
517     enum class MediaControlEvent { PlayPause, NextTrack, PreviousTrack };
518     void sendMediaControlEvent(MediaControlEvent);
519 #endif
520
521 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
522     void setMockMediaPlaybackTargetPickerEnabled(bool);
523     ExceptionOr<void> setMockMediaPlaybackTargetPickerState(const String& deviceName, const String& deviceState);
524 #endif
525
526 #if ENABLE(WEB_AUDIO)
527     void setAudioContextRestrictions(AudioContext&, StringView restrictionsString);
528 #endif
529
530     void simulateSystemSleep() const;
531     void simulateSystemWake() const;
532
533     enum class PageOverlayType { View, Document };
534     ExceptionOr<Ref<MockPageOverlay>> installMockPageOverlay(PageOverlayType);
535     ExceptionOr<String> pageOverlayLayerTreeAsText(unsigned short flags) const;
536
537     void setPageMuted(StringView);
538     String pageMediaState();
539
540     void setPageDefersLoading(bool);
541     ExceptionOr<bool> pageDefersLoading();
542
543     RefPtr<File> createFile(const String&);
544     void queueMicroTask(int);
545     bool testPreloaderSettingViewport();
546
547 #if ENABLE(CONTENT_FILTERING)
548     MockContentFilterSettings& mockContentFilterSettings();
549 #endif
550
551 #if ENABLE(CSS_SCROLL_SNAP)
552     ExceptionOr<String> scrollSnapOffsets(Element&);
553     void setPlatformMomentumScrollingPredictionEnabled(bool);
554 #endif
555
556     ExceptionOr<String> pathStringWithShrinkWrappedRects(const Vector<double>& rectComponents, double radius);
557
558     String getCurrentMediaControlsStatusForElement(HTMLMediaElement&);
559
560     String userVisibleString(const DOMURL&);
561     void setShowAllPlugins(bool);
562
563     String resourceLoadStatisticsForOrigin(const String& origin);
564     void setResourceLoadStatisticsEnabled(bool);
565     void setUserGrantsStorageAccess(bool);
566
567 #if ENABLE(STREAMS_API)
568     bool isReadableStreamDisturbed(JSC::ExecState&, JSC::JSValue);
569     JSC::JSValue cloneArrayBuffer(JSC::ExecState&, JSC::JSValue, JSC::JSValue, JSC::JSValue);
570 #endif
571
572     String composedTreeAsText(Node&);
573
574     bool isProcessingUserGesture();
575     double lastHandledUserGestureTimestamp();
576
577     void withUserGesture(RefPtr<VoidCallback>&&);
578
579     RefPtr<GCObservation> observeGC(JSC::JSValue);
580
581     enum class UserInterfaceLayoutDirection { LTR, RTL };
582     void setUserInterfaceLayoutDirection(UserInterfaceLayoutDirection);
583
584     bool userPrefersReducedMotion() const;
585
586     void reportBacktrace();
587
588     enum class BaseWritingDirection { Natural, Ltr, Rtl };
589     void setBaseWritingDirection(BaseWritingDirection);
590
591 #if ENABLE(POINTER_LOCK)
592     bool pageHasPendingPointerLock() const;
593     bool pageHasPointerLock() const;
594 #endif
595
596     Vector<String> accessKeyModifiers() const;
597
598     void setQuickLookPassword(const String&);
599
600     void setAsRunningUserScripts(Document&);
601
602 #if ENABLE(WEBGL)
603     void simulateWebGLContextChanged(WebGLRenderingContext&);
604     void failNextGPUStatusCheck(WebGLRenderingContext&);
605 #endif
606
607     void setPageVisibility(bool isVisible);
608
609 #if ENABLE(WEB_RTC)
610     void setH264HardwareEncoderAllowed(bool allowed);
611 #endif
612
613 #if ENABLE(MEDIA_STREAM)
614     void setCameraMediaStreamTrackOrientation(MediaStreamTrack&, int orientation);
615     ExceptionOr<void> setMediaDeviceState(const String& id, const String& property, bool value);
616     unsigned long trackAudioSampleCount() const { return m_trackAudioSampleCount; }
617     unsigned long trackVideoSampleCount() const { return m_trackVideoSampleCount; }
618     void observeMediaStreamTrack(MediaStreamTrack&);
619     using TrackFramePromise = DOMPromiseDeferred<IDLInterface<ImageData>>;
620     void grabNextMediaStreamTrackFrame(TrackFramePromise&&);
621     void delayMediaStreamTrackSamples(MediaStreamTrack&, float);
622     void setMediaStreamTrackMuted(MediaStreamTrack&, bool);
623     void removeMediaStreamTrack(MediaStream&, MediaStreamTrack&);
624     void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack&);
625     void setMediaStreamTrackIdentifier(MediaStreamTrack&, String&& id);
626 #endif
627
628     String audioSessionCategory() const;
629
630     void clearCacheStorageMemoryRepresentation(DOMPromiseDeferred<void>&&);
631     void cacheStorageEngineRepresentation(DOMPromiseDeferred<IDLDOMString>&&);
632     void setResponseSizeWithPadding(FetchResponse&, uint64_t size);
633     uint64_t responseSizeWithPadding(FetchResponse&) const;
634
635     void setConsoleMessageListener(RefPtr<StringCallback>&&);
636
637 #if ENABLE(SERVICE_WORKER)
638     using HasRegistrationPromise = DOMPromiseDeferred<IDLBoolean>;
639     void hasServiceWorkerRegistration(const String& clientURL, HasRegistrationPromise&&);
640     void terminateServiceWorker(ServiceWorker&);
641     bool hasServiceWorkerConnection();
642 #endif
643
644 #if ENABLE(APPLE_PAY)
645     MockPaymentCoordinator& mockPaymentCoordinator() const;
646 #endif
647
648     String timelineDescription(AnimationTimeline&);
649     void pauseTimeline(AnimationTimeline&);
650     void setTimelineCurrentTime(AnimationTimeline&, double);
651
652     void testIncomingSyncIPCMessageWhileWaitingForSyncReply();
653
654 #if ENABLE(WEB_AUTHN)
655     MockCredentialsMessenger& mockCredentialsMessenger() const;
656 #endif
657
658 private:
659     explicit Internals(Document&);
660     Document* contextDocument() const;
661     Frame* frame() const;
662
663     ExceptionOr<RenderedDocumentMarker*> markerAt(Node&, const String& markerType, unsigned index);
664
665     // RealtimeMediaSource::Observer API
666 #if ENABLE(MEDIA_STREAM)
667     void videoSampleAvailable(MediaSample&) final;
668     void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final { m_trackAudioSampleCount++; }
669
670     OrientationNotifier m_orientationNotifier;
671     unsigned long m_trackVideoSampleCount { 0 };
672     unsigned long m_trackAudioSampleCount { 0 };
673     RefPtr<MediaStreamTrack> m_track;
674     std::optional<TrackFramePromise> m_nextTrackFramePromise;
675 #endif
676
677     std::unique_ptr<InspectorStubFrontend> m_inspectorFrontend;
678     RefPtr<CacheStorageConnection> m_cacheStorageConnection;
679
680 #if ENABLE(APPLE_PAY)
681     MockPaymentCoordinator* m_mockPaymentCoordinator { nullptr };
682 #endif
683
684 #if ENABLE(WEB_AUTHN)
685     std::unique_ptr<MockCredentialsMessenger> m_mockCredentialsMessenger;
686 #endif
687 };
688
689 } // namespace WebCore