1/*
2 * Copyright (C) 2015-2018 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include <wtf/HashMap.h>
29#include <wtf/Vector.h>
30#include <wtf/text/StringHash.h>
31#include <wtf/text/WTFString.h>
32
33namespace WTR {
34
35struct TestOptions {
36 struct ContextOptions {
37 Vector<String> overrideLanguages;
38 bool ignoreSynchronousMessagingTimeouts { false };
39 bool enableProcessSwapOnNavigation { true };
40 bool enableProcessSwapOnWindowOpen { false };
41
42 bool hasSameInitializationOptions(const ContextOptions& options) const
43 {
44 if (ignoreSynchronousMessagingTimeouts != options.ignoreSynchronousMessagingTimeouts
45 || overrideLanguages != options.overrideLanguages
46 || enableProcessSwapOnNavigation != options.enableProcessSwapOnNavigation
47 || enableProcessSwapOnWindowOpen != options.enableProcessSwapOnWindowOpen)
48 return false;
49 return true;
50 }
51
52 bool shouldEnableProcessSwapOnNavigation() const
53 {
54 return enableProcessSwapOnNavigation || enableProcessSwapOnWindowOpen;
55 }
56 };
57
58 bool useThreadedScrolling { false };
59 bool useAcceleratedDrawing { false };
60 bool useRemoteLayerTree { false };
61 bool shouldShowWebView { false };
62 bool useFlexibleViewport { false };
63 bool useFixedLayout { false };
64 bool isSVGTest { false };
65 bool useDataDetection { false };
66 bool useMockScrollbars { true };
67 bool needsSiteSpecificQuirks { false };
68 bool ignoresViewportScaleLimits { false };
69 bool useCharacterSelectionGranularity { false };
70 bool enableAttachmentElement { false };
71 bool enableIntersectionObserver { false };
72 bool enableMenuItemElement { false };
73 bool enableModernMediaControls { true };
74 bool enablePointerLock { false };
75 bool enableWebAuthentication { true };
76 bool enableWebAuthenticationLocalAuthenticator { true };
77 bool enableIsSecureContextAttribute { true };
78 bool enableInspectorAdditions { false };
79 bool shouldShowTouches { false };
80 bool dumpJSConsoleLogInStdErr { false };
81 bool allowCrossOriginSubresourcesToAskForCredentials { false };
82 bool domPasteAllowed { true };
83 bool enableColorFilter { false };
84 bool punchOutWhiteBackgroundsInDarkMode { false };
85 bool runSingly { false };
86 bool checkForWorldLeaks { false };
87 bool shouldIgnoreMetaViewport { false };
88 bool shouldShowSpellCheckingDots { false };
89 bool enableEditableImages { false };
90 bool editable { false };
91 bool enableUndoManagerAPI { false };
92 bool shouldHandleRunOpenPanel { true };
93 bool shouldPresentPopovers { true };
94 bool shouldUseModernCompatibilityMode { false };
95 bool enableAppNap { false };
96
97 double contentInsetTop { 0 };
98
99 float deviceScaleFactor { 1 };
100 std::string applicationManifest;
101 std::string jscOptions;
102 std::string additionalSupportedImageTypes;
103 HashMap<String, bool> experimentalFeatures;
104 HashMap<String, bool> internalDebugFeatures;
105
106 ContextOptions contextOptions;
107
108 TestOptions(const std::string& pathOrURL);
109
110 // Add here options that can only be set upon PlatformWebView
111 // initialization and make sure it's up to date when adding new
112 // options to this struct. Otherwise, tests using those options
113 // might fail if WTR is reusing an existing PlatformWebView.
114 bool hasSameInitializationOptions(const TestOptions& options) const
115 {
116 if (useThreadedScrolling != options.useThreadedScrolling
117 || useAcceleratedDrawing != options.useAcceleratedDrawing
118 || useMockScrollbars != options.useMockScrollbars
119 || needsSiteSpecificQuirks != options.needsSiteSpecificQuirks
120 || useCharacterSelectionGranularity != options.useCharacterSelectionGranularity
121 || enableAttachmentElement != options.enableAttachmentElement
122 || enableIntersectionObserver != options.enableIntersectionObserver
123 || enableMenuItemElement != options.enableMenuItemElement
124 || enableModernMediaControls != options.enableModernMediaControls
125 || enablePointerLock != options.enablePointerLock
126 || enableWebAuthentication != options.enableWebAuthentication
127 || enableWebAuthenticationLocalAuthenticator != options.enableWebAuthenticationLocalAuthenticator
128 || enableIsSecureContextAttribute != options.enableIsSecureContextAttribute
129 || enableInspectorAdditions != options.enableInspectorAdditions
130 || dumpJSConsoleLogInStdErr != options.dumpJSConsoleLogInStdErr
131 || applicationManifest != options.applicationManifest
132 || allowCrossOriginSubresourcesToAskForCredentials != options.allowCrossOriginSubresourcesToAskForCredentials
133 || domPasteAllowed != options.domPasteAllowed
134 || enableColorFilter != options.enableColorFilter
135 || punchOutWhiteBackgroundsInDarkMode != options.punchOutWhiteBackgroundsInDarkMode
136 || jscOptions != options.jscOptions
137 || additionalSupportedImageTypes != options.additionalSupportedImageTypes
138 || runSingly != options.runSingly
139 || checkForWorldLeaks != options.checkForWorldLeaks
140 || shouldShowSpellCheckingDots != options.shouldShowSpellCheckingDots
141 || shouldIgnoreMetaViewport != options.shouldIgnoreMetaViewport
142 || enableEditableImages != options.enableEditableImages
143 || editable != options.editable
144 || enableUndoManagerAPI != options.enableUndoManagerAPI
145 || shouldHandleRunOpenPanel != options.shouldHandleRunOpenPanel
146 || shouldPresentPopovers != options.shouldPresentPopovers
147 || contentInsetTop != options.contentInsetTop
148 || shouldUseModernCompatibilityMode != options.shouldUseModernCompatibilityMode
149 || enableAppNap != options.enableAppNap)
150 return false;
151
152 if (!contextOptions.hasSameInitializationOptions(options.contextOptions))
153 return false;
154
155 if (experimentalFeatures != options.experimentalFeatures)
156 return false;
157
158 if (internalDebugFeatures != options.internalDebugFeatures)
159 return false;
160
161 return true;
162 }
163};
164
165}
166