OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 WebRemoteFrameClient*, | 101 WebRemoteFrameClient*, |
102 const WebString& name = WebString()); | 102 const WebString& name = WebString()); |
103 | 103 |
104 // Helpers for unit tests with parameterized WebSettings overrides. | 104 // Helpers for unit tests with parameterized WebSettings overrides. |
105 typedef void (*SettingOverrideFunction)(WebSettings*); | 105 typedef void (*SettingOverrideFunction)(WebSettings*); |
106 class SettingOverrider { | 106 class SettingOverrider { |
107 public: | 107 public: |
108 virtual void overrideSettings(WebSettings*) = 0; | 108 virtual void overrideSettings(WebSettings*) = 0; |
109 }; | 109 }; |
110 | 110 |
111 // Forces to use mocked overlay scrollbars instead of the default native theme s
crollbars to avoid | 111 // Forces to use mocked overlay scrollbars instead of the default native theme |
112 // crash in Chromium code when it tries to load UI resources that are not availa
ble when running | 112 // scrollbars to avoid crash in Chromium code when it tries to load UI |
113 // blink unit tests, and to ensure consistent layout regardless of differences b
etween scrollbar themes. | 113 // resources that are not available when running blink unit tests, and to |
114 // WebViewHelper includes this, so this is only needed if a test doesn't use Web
ViewHelper or the test | 114 // ensure consistent layout regardless of differences between scrollbar themes. |
115 // needs a bigger scope of mock scrollbar settings than the scope of WebViewHelp
er. | 115 // WebViewHelper includes this, so this is only needed if a test doesn't use |
| 116 // WebViewHelper or the test needs a bigger scope of mock scrollbar settings |
| 117 // than the scope of WebViewHelper. |
116 class UseMockScrollbarSettings { | 118 class UseMockScrollbarSettings { |
117 public: | 119 public: |
118 UseMockScrollbarSettings() | 120 UseMockScrollbarSettings() |
119 : m_originalMockScrollbarEnabled(Settings::mockScrollbarsEnabled()), | 121 : m_originalMockScrollbarEnabled(Settings::mockScrollbarsEnabled()), |
120 m_originalOverlayScrollbarsEnabled( | 122 m_originalOverlayScrollbarsEnabled( |
121 RuntimeEnabledFeatures::overlayScrollbarsEnabled()) { | 123 RuntimeEnabledFeatures::overlayScrollbarsEnabled()) { |
122 Settings::setMockScrollbarsEnabled(true); | 124 Settings::setMockScrollbarsEnabled(true); |
123 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); | 125 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); |
124 EXPECT_TRUE(ScrollbarTheme::theme().usesOverlayScrollbars()); | 126 EXPECT_TRUE(ScrollbarTheme::theme().usesOverlayScrollbars()); |
125 } | 127 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 TestWebWidgetClient* widgetClient() { return &m_testWebWidgetClient; } | 176 TestWebWidgetClient* widgetClient() { return &m_testWebWidgetClient; } |
175 | 177 |
176 private: | 178 private: |
177 friend class TestWebViewWidgetClient; | 179 friend class TestWebViewWidgetClient; |
178 | 180 |
179 TestWebViewWidgetClient m_testWebWidgetClient; | 181 TestWebViewWidgetClient m_testWebWidgetClient; |
180 std::unique_ptr<WebLayerTreeView> m_layerTreeView; | 182 std::unique_ptr<WebLayerTreeView> m_layerTreeView; |
181 bool m_animationScheduled; | 183 bool m_animationScheduled; |
182 }; | 184 }; |
183 | 185 |
184 // Convenience class for handling the lifetime of a WebView and its associated m
ainframe in tests. | 186 // Convenience class for handling the lifetime of a WebView and its associated |
| 187 // mainframe in tests. |
185 class WebViewHelper { | 188 class WebViewHelper { |
186 WTF_MAKE_NONCOPYABLE(WebViewHelper); | 189 WTF_MAKE_NONCOPYABLE(WebViewHelper); |
187 | 190 |
188 public: | 191 public: |
189 WebViewHelper(SettingOverrider* = 0); | 192 WebViewHelper(SettingOverrider* = 0); |
190 ~WebViewHelper(); | 193 ~WebViewHelper(); |
191 | 194 |
192 // Creates and initializes the WebView. Implicitly calls reset() first. If | 195 // Creates and initializes the WebView. Implicitly calls reset() first. If |
193 // a WebFrameClient or a WebViewClient are passed in, they must outlive the | 196 // a WebFrameClient or a WebViewClient are passed in, they must outlive the |
194 // WebViewHelper. | 197 // WebViewHelper. |
(...skipping 27 matching lines...) Expand all Loading... |
222 | 225 |
223 WebViewImpl* webView() const { return m_webView; } | 226 WebViewImpl* webView() const { return m_webView; } |
224 | 227 |
225 private: | 228 private: |
226 WebViewImpl* m_webView; | 229 WebViewImpl* m_webView; |
227 SettingOverrider* m_settingOverrider; | 230 SettingOverrider* m_settingOverrider; |
228 UseMockScrollbarSettings m_mockScrollbarSettings; | 231 UseMockScrollbarSettings m_mockScrollbarSettings; |
229 TestWebViewClient* m_testWebViewClient; | 232 TestWebViewClient* m_testWebViewClient; |
230 }; | 233 }; |
231 | 234 |
232 // Minimal implementation of WebFrameClient needed for unit tests that load fram
es. Tests that load | 235 // Minimal implementation of WebFrameClient needed for unit tests that load |
233 // frames and need further specialization of WebFrameClient behavior should subc
lass this. | 236 // frames. Tests that load frames and need further specialization of |
| 237 // WebFrameClient behavior should subclass this. |
234 class TestWebFrameClient : public WebFrameClient { | 238 class TestWebFrameClient : public WebFrameClient { |
235 public: | 239 public: |
236 TestWebFrameClient(); | 240 TestWebFrameClient(); |
237 | 241 |
238 WebLocalFrame* createChildFrame(WebLocalFrame* parent, | 242 WebLocalFrame* createChildFrame(WebLocalFrame* parent, |
239 WebTreeScopeType, | 243 WebTreeScopeType, |
240 const WebString& name, | 244 const WebString& name, |
241 const WebString& uniqueName, | 245 const WebString& uniqueName, |
242 WebSandboxFlags, | 246 WebSandboxFlags, |
243 const WebFrameOwnerProperties&) override; | 247 const WebFrameOwnerProperties&) override; |
244 void didStartLoading(bool) override; | 248 void didStartLoading(bool) override; |
245 void didStopLoading() override; | 249 void didStopLoading() override; |
246 | 250 |
247 bool isLoading() { return m_loadsInProgress > 0; } | 251 bool isLoading() { return m_loadsInProgress > 0; } |
248 | 252 |
249 private: | 253 private: |
250 int m_loadsInProgress = 0; | 254 int m_loadsInProgress = 0; |
251 }; | 255 }; |
252 | 256 |
253 // Minimal implementation of WebRemoteFrameClient needed for unit tests that loa
d remote frames. Tests that load | 257 // Minimal implementation of WebRemoteFrameClient needed for unit tests that |
254 // frames and need further specialization of WebFrameClient behavior should subc
lass this. | 258 // load remote frames. Tests that load frames and need further specialization |
| 259 // of WebFrameClient behavior should subclass this. |
255 class TestWebRemoteFrameClient : public WebRemoteFrameClient { | 260 class TestWebRemoteFrameClient : public WebRemoteFrameClient { |
256 public: | 261 public: |
257 TestWebRemoteFrameClient(); | 262 TestWebRemoteFrameClient(); |
258 | 263 |
259 WebRemoteFrameImpl* frame() const { return m_frame; } | 264 WebRemoteFrameImpl* frame() const { return m_frame; } |
260 | 265 |
261 // WebRemoteFrameClient overrides: | 266 // WebRemoteFrameClient overrides: |
262 void frameDetached(DetachType) override; | 267 void frameDetached(DetachType) override; |
263 void forwardPostMessage(WebLocalFrame* sourceFrame, | 268 void forwardPostMessage(WebLocalFrame* sourceFrame, |
264 WebRemoteFrame* targetFrame, | 269 WebRemoteFrame* targetFrame, |
265 WebSecurityOrigin targetOrigin, | 270 WebSecurityOrigin targetOrigin, |
266 WebDOMMessageEvent) override {} | 271 WebDOMMessageEvent) override {} |
267 | 272 |
268 private: | 273 private: |
269 Persistent<WebRemoteFrameImpl> const m_frame; | 274 Persistent<WebRemoteFrameImpl> const m_frame; |
270 }; | 275 }; |
271 | 276 |
272 } // namespace FrameTestHelpers | 277 } // namespace FrameTestHelpers |
273 } // namespace blink | 278 } // namespace blink |
274 | 279 |
275 #endif // FrameTestHelpers_h | 280 #endif // FrameTestHelpers_h |
OLD | NEW |