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