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