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