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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 class WebFrame; | 52 class WebFrame; |
53 class WebFrameWidget; | 53 class WebFrameWidget; |
54 class WebLocalFrame; | 54 class WebLocalFrame; |
55 class WebRemoteFrame; | 55 class WebRemoteFrame; |
56 class WebRemoteFrameImpl; | 56 class WebRemoteFrameImpl; |
57 enum class WebCachePolicy; | 57 enum class WebCachePolicy; |
58 | 58 |
59 namespace FrameTestHelpers { | 59 namespace FrameTestHelpers { |
60 | 60 |
61 class TestWebFrameClient; | 61 class TestWebFrameClient; |
62 using TestWebWidgetClient = WebWidgetClient; | 62 class TestWebWidgetClient; |
| 63 class TestWebViewClient; |
63 | 64 |
64 // Loads a url into the specified WebFrame for testing purposes. Pumps any | 65 // Loads a url into the specified WebFrame for testing purposes. Pumps any |
65 // pending resource requests, as well as waiting for the threaded parser to | 66 // pending resource requests, as well as waiting for the threaded parser to |
66 // finish, before returning. | 67 // finish, before returning. |
67 void loadFrame(WebFrame*, const std::string& url); | 68 void loadFrame(WebFrame*, const std::string& url); |
68 // Same as above, but for WebFrame::loadHTMLString(). | 69 // Same as above, but for WebFrame::loadHTMLString(). |
69 void loadHTMLString(WebFrame*, const std::string& html, const WebURL& baseURL); | 70 void loadHTMLString(WebFrame*, const std::string& html, const WebURL& baseURL); |
70 // Same as above, but for WebFrame::loadHistoryItem(). | 71 // Same as above, but for WebFrame::loadHistoryItem(). |
71 void loadHistoryItem(WebFrame*, const WebHistoryItem&, WebHistoryLoadType, WebCa
chePolicy); | 72 void loadHistoryItem(WebFrame*, const WebHistoryItem&, WebHistoryLoadType, WebCa
chePolicy); |
72 // Same as above, but for WebFrame::reload(). | 73 // Same as above, but for WebFrame::reload(). |
73 void reloadFrame(WebFrame*); | 74 void reloadFrame(WebFrame*); |
74 void reloadFrameIgnoringCache(WebFrame*); | 75 void reloadFrameIgnoringCache(WebFrame*); |
75 | 76 |
76 // Pumps pending resource requests while waiting for a frame to load. Consider | 77 // Pumps pending resource requests while waiting for a frame to load. Consider |
77 // using one of the above helper methods whenever possible. | 78 // using one of the above helper methods whenever possible. |
78 void pumpPendingRequestsForFrameToLoad(WebFrame*); | 79 void pumpPendingRequestsForFrameToLoad(WebFrame*); |
79 | 80 |
80 WebMouseEvent createMouseEvent(WebInputEvent::Type, WebMouseEvent::Button, const
IntPoint&, int modifiers); | 81 WebMouseEvent createMouseEvent(WebInputEvent::Type, WebMouseEvent::Button, const
IntPoint&, int modifiers); |
81 | 82 |
82 // Calls WebRemoteFrame::createLocalChild, but with some arguments prefilled | 83 // Calls WebRemoteFrame::createLocalChild, but with some arguments prefilled |
83 // with default test values (i.e. with a default |client| or |properties| and/or | 84 // with default test values (i.e. with a default |client| or |properties| and/or |
84 // with a precalculated |uniqueName|). | 85 // with a precalculated |uniqueName|). |
85 WebLocalFrame* createLocalChild(WebRemoteFrame* parent, const WebString& name =
WebString(), WebFrameClient* = nullptr, WebFrame* previousSibling = nullptr, con
st WebFrameOwnerProperties& = WebFrameOwnerProperties()); | 86 WebLocalFrame* createLocalChild(WebRemoteFrame* parent, const WebString& name =
WebString(), WebFrameClient* = nullptr, WebWidgetClient* = nullptr, WebFrame* pr
eviousSibling = nullptr, const WebFrameOwnerProperties& = WebFrameOwnerPropertie
s()); |
86 WebRemoteFrame* createRemoteChild(WebRemoteFrame* parent, WebRemoteFrameClient*,
const WebString& name = WebString()); | 87 WebRemoteFrame* createRemoteChild(WebRemoteFrame* parent, WebRemoteFrameClient*,
const WebString& name = WebString()); |
87 | 88 |
88 class SettingOverrider { | 89 class SettingOverrider { |
89 public: | 90 public: |
90 virtual void overrideSettings(WebSettings*) = 0; | 91 virtual void overrideSettings(WebSettings*) = 0; |
91 }; | 92 }; |
92 | 93 |
93 // Forces to use mocked overlay scrollbars instead of the default native theme s
crollbars to avoid | 94 // Forces to use mocked overlay scrollbars instead of the default native theme s
crollbars to avoid |
94 // crash in Chromium code when it tries to load UI resources that are not availa
ble when running | 95 // crash in Chromium code when it tries to load UI resources that are not availa
ble when running |
95 // blink unit tests, and to ensure consistent layout regardless of differences b
etween scrollbar themes. | 96 // blink unit tests, and to ensure consistent layout regardless of differences b
etween scrollbar themes. |
(...skipping 14 matching lines...) Expand all Loading... |
110 { | 111 { |
111 Settings::setMockScrollbarsEnabled(m_originalMockScrollbarEnabled); | 112 Settings::setMockScrollbarsEnabled(m_originalMockScrollbarEnabled); |
112 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(m_originalOverlayScr
ollbarsEnabled); | 113 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(m_originalOverlayScr
ollbarsEnabled); |
113 } | 114 } |
114 | 115 |
115 private: | 116 private: |
116 bool m_originalMockScrollbarEnabled; | 117 bool m_originalMockScrollbarEnabled; |
117 bool m_originalOverlayScrollbarsEnabled; | 118 bool m_originalOverlayScrollbarsEnabled; |
118 }; | 119 }; |
119 | 120 |
| 121 class TestWebWidgetClient : public WebWidgetClient { |
| 122 public: |
| 123 virtual ~TestWebWidgetClient() {} |
| 124 bool allowsBrokenNullLayerTreeView() const override { return true; } |
| 125 }; |
| 126 |
| 127 class TestWebViewWidgetClient : public TestWebWidgetClient { |
| 128 public: |
| 129 explicit TestWebViewWidgetClient(TestWebViewClient* testWebViewClient) |
| 130 : m_testWebViewClient(testWebViewClient) |
| 131 { |
| 132 } |
| 133 virtual ~TestWebViewWidgetClient() {} |
| 134 |
| 135 void initializeLayerTreeView() override; |
| 136 WebLayerTreeView* layerTreeView() override; |
| 137 void scheduleAnimation() override; |
| 138 |
| 139 private: |
| 140 TestWebViewClient* m_testWebViewClient; |
| 141 }; |
| 142 |
120 class TestWebViewClient : public WebViewClient { | 143 class TestWebViewClient : public WebViewClient { |
121 public: | 144 public: |
122 TestWebViewClient() : m_animationScheduled(false) { } | 145 TestWebViewClient() |
| 146 : m_testWebWidgetClient(this) |
| 147 , m_animationScheduled(false) |
| 148 { |
| 149 } |
123 virtual ~TestWebViewClient() { } | 150 virtual ~TestWebViewClient() { } |
124 void initializeLayerTreeView() override; | 151 void initializeLayerTreeView() override; |
125 WebLayerTreeView* layerTreeView() override { return m_layerTreeView.get(); } | 152 WebLayerTreeView* layerTreeView() override { return m_layerTreeView.get(); } |
126 | 153 |
127 void scheduleAnimation() override { m_animationScheduled = true; } | 154 void scheduleAnimation() override { m_animationScheduled = true; } |
128 bool animationScheduled() { return m_animationScheduled; } | 155 bool animationScheduled() { return m_animationScheduled; } |
129 void clearAnimationScheduled() { m_animationScheduled = false; } | 156 void clearAnimationScheduled() { m_animationScheduled = false; } |
130 | 157 |
131 // TODO(lfg): This is a temporary method to retrieve the WebWidgetClient, | 158 // TODO(lfg): This is a temporary method to retrieve the WebWidgetClient, |
132 // while we refactor WebView to not inherit from Webwidget. | 159 // while we refactor WebView to not inherit from Webwidget. |
133 // Returns the WebWidgetClient. | 160 // Returns the WebWidgetClient. |
134 WebWidgetClient* widgetClient() { return this; } | 161 TestWebWidgetClient* widgetClient() { return &m_testWebWidgetClient; } |
135 | 162 |
136 private: | 163 private: |
| 164 TestWebViewWidgetClient m_testWebWidgetClient; |
137 std::unique_ptr<WebLayerTreeView> m_layerTreeView; | 165 std::unique_ptr<WebLayerTreeView> m_layerTreeView; |
138 bool m_animationScheduled; | 166 bool m_animationScheduled; |
139 }; | 167 }; |
140 | 168 |
141 // Convenience class for handling the lifetime of a WebView and its associated m
ainframe in tests. | 169 // Convenience class for handling the lifetime of a WebView and its associated m
ainframe in tests. |
142 class WebViewHelper { | 170 class WebViewHelper { |
143 WTF_MAKE_NONCOPYABLE(WebViewHelper); | 171 WTF_MAKE_NONCOPYABLE(WebViewHelper); |
144 public: | 172 public: |
145 WebViewHelper(SettingOverrider* = 0); | 173 WebViewHelper(SettingOverrider* = 0); |
146 ~WebViewHelper(); | 174 ~WebViewHelper(); |
(...skipping 12 matching lines...) Expand all Loading... |
159 | 187 |
160 void resize(WebSize); | 188 void resize(WebSize); |
161 | 189 |
162 void reset(); | 190 void reset(); |
163 | 191 |
164 WebView* webView() const { return m_webView; } | 192 WebView* webView() const { return m_webView; } |
165 WebViewImpl* webViewImpl() const { return m_webView; } | 193 WebViewImpl* webViewImpl() const { return m_webView; } |
166 | 194 |
167 private: | 195 private: |
168 WebViewImpl* m_webView; | 196 WebViewImpl* m_webView; |
169 WebFrameWidget* m_webViewWidget; | |
170 SettingOverrider* m_settingOverrider; | 197 SettingOverrider* m_settingOverrider; |
171 UseMockScrollbarSettings m_mockScrollbarSettings; | 198 UseMockScrollbarSettings m_mockScrollbarSettings; |
172 TestWebViewClient* m_testWebViewClient; | 199 TestWebViewClient* m_testWebViewClient; |
173 }; | 200 }; |
174 | 201 |
175 // Minimal implementation of WebFrameClient needed for unit tests that load fram
es. Tests that load | 202 // Minimal implementation of WebFrameClient needed for unit tests that load fram
es. Tests that load |
176 // frames and need further specialization of WebFrameClient behavior should subc
lass this. | 203 // frames and need further specialization of WebFrameClient behavior should subc
lass this. |
177 class TestWebFrameClient : public WebFrameClient { | 204 class TestWebFrameClient : public WebFrameClient { |
178 public: | 205 public: |
179 TestWebFrameClient(); | 206 TestWebFrameClient(); |
180 | 207 |
181 WebFrame* createChildFrame(WebLocalFrame* parent, WebTreeScopeType, const We
bString& name, const WebString& uniqueName, WebSandboxFlags, const WebFrameOwner
Properties&) override; | 208 WebFrame* createChildFrame(WebLocalFrame* parent, WebTreeScopeType, const We
bString& name, const WebString& uniqueName, WebSandboxFlags, const WebFrameOwner
Properties&) override; |
182 void frameDetached(WebFrame*, DetachType) override; | 209 void frameDetached(WebLocalFrame*, DetachType) override; |
183 void didStartLoading(bool) override; | 210 void didStartLoading(bool) override; |
184 void didStopLoading() override; | 211 void didStopLoading() override; |
185 | 212 |
186 bool isLoading() { return m_loadsInProgress > 0; } | 213 bool isLoading() { return m_loadsInProgress > 0; } |
187 | 214 |
188 private: | 215 private: |
189 int m_loadsInProgress = 0; | 216 int m_loadsInProgress = 0; |
190 }; | 217 }; |
191 | 218 |
192 // Minimal implementation of WebRemoteFrameClient needed for unit tests that loa
d remote frames. Tests that load | 219 // Minimal implementation of WebRemoteFrameClient needed for unit tests that loa
d remote frames. Tests that load |
(...skipping 13 matching lines...) Expand all Loading... |
206 WebDOMMessageEvent) override { } | 233 WebDOMMessageEvent) override { } |
207 | 234 |
208 private: | 235 private: |
209 Persistent<WebRemoteFrameImpl> const m_frame; | 236 Persistent<WebRemoteFrameImpl> const m_frame; |
210 }; | 237 }; |
211 | 238 |
212 } // namespace FrameTestHelpers | 239 } // namespace FrameTestHelpers |
213 } // namespace blink | 240 } // namespace blink |
214 | 241 |
215 #endif // FrameTestHelpers_h | 242 #endif // FrameTestHelpers_h |
OLD | NEW |