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