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