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