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