OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #include "public/web/WebWidgetClient.h" | 56 #include "public/web/WebWidgetClient.h" |
57 #include "testing/gtest/include/gtest/gtest.h" | 57 #include "testing/gtest/include/gtest/gtest.h" |
58 #include "web/WebFrameImplBase.h" | 58 #include "web/WebFrameImplBase.h" |
59 #include "web/WebViewImpl.h" | 59 #include "web/WebViewImpl.h" |
60 #include "web/tests/FrameTestHelpers.h" | 60 #include "web/tests/FrameTestHelpers.h" |
61 | 61 |
62 using blink::testing::runPendingTasks; | 62 using blink::testing::runPendingTasks; |
63 | 63 |
64 namespace blink { | 64 namespace blink { |
65 | 65 |
66 class TouchActionTrackingWebViewClient | 66 class TouchActionTrackingWebWidgetClient |
67 : public FrameTestHelpers::TestWebViewClient { | 67 : public FrameTestHelpers::TestWebWidgetClient { |
68 public: | 68 public: |
69 TouchActionTrackingWebViewClient() | 69 TouchActionTrackingWebWidgetClient() |
70 : m_actionSetCount(0), m_action(WebTouchActionAuto) {} | 70 : m_actionSetCount(0), m_action(WebTouchActionAuto) {} |
71 | 71 |
72 // WebWidgetClient methods | 72 // WebWidgetClient methods |
73 void setTouchAction(WebTouchAction touchAction) override { | 73 void setTouchAction(WebTouchAction touchAction) override { |
74 m_actionSetCount++; | 74 m_actionSetCount++; |
75 m_action = touchAction; | 75 m_action = touchAction; |
76 } | 76 } |
77 | 77 |
78 // Local methods | 78 // Local methods |
79 void reset() { | 79 void reset() { |
(...skipping 26 matching lines...) Expand all Loading... |
106 void TearDown() override { | 106 void TearDown() override { |
107 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); | 107 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); |
108 WebCache::clear(); | 108 WebCache::clear(); |
109 } | 109 } |
110 | 110 |
111 protected: | 111 protected: |
112 void runTouchActionTest(std::string file); | 112 void runTouchActionTest(std::string file); |
113 void runShadowDOMTest(std::string file); | 113 void runShadowDOMTest(std::string file); |
114 void runIFrameTest(std::string file); | 114 void runIFrameTest(std::string file); |
115 void sendTouchEvent(WebView*, WebInputEvent::Type, IntPoint clientPoint); | 115 void sendTouchEvent(WebView*, WebInputEvent::Type, IntPoint clientPoint); |
116 WebView* setupTest(std::string file, TouchActionTrackingWebViewClient&); | 116 WebView* setupTest(std::string file, TouchActionTrackingWebWidgetClient&); |
117 void runTestOnTree(ContainerNode* root, | 117 void runTestOnTree(ContainerNode* root, |
118 WebView*, | 118 WebView*, |
119 TouchActionTrackingWebViewClient&); | 119 TouchActionTrackingWebWidgetClient&); |
120 | 120 |
121 std::string m_baseURL; | 121 std::string m_baseURL; |
122 FrameTestHelpers::WebViewHelper m_webViewHelper; | 122 FrameTestHelpers::WebViewHelper m_webViewHelper; |
123 }; | 123 }; |
124 | 124 |
125 void TouchActionTest::runTouchActionTest(std::string file) { | 125 void TouchActionTest::runTouchActionTest(std::string file) { |
126 TouchActionTrackingWebViewClient client; | 126 TouchActionTrackingWebWidgetClient client; |
127 | 127 |
128 // runTouchActionTest() loads a document in a frame, setting up a | 128 // runTouchActionTest() loads a document in a frame, setting up a |
129 // nested message loop. Should any Oilpan GC happen while it is in | 129 // nested message loop. Should any Oilpan GC happen while it is in |
130 // effect, the implicit assumption that we're outside any event | 130 // effect, the implicit assumption that we're outside any event |
131 // loop (=> there being no pointers on the stack needing scanning) | 131 // loop (=> there being no pointers on the stack needing scanning) |
132 // when that GC strikes will no longer hold. | 132 // when that GC strikes will no longer hold. |
133 // | 133 // |
134 // To ensure that the references on the stack are also traced, we | 134 // To ensure that the references on the stack are also traced, we |
135 // turn them into persistent, stack allocated references. This | 135 // turn them into persistent, stack allocated references. This |
136 // workaround is sufficient to handle this artificial test | 136 // workaround is sufficient to handle this artificial test |
137 // scenario. | 137 // scenario. |
138 WebView* webView = setupTest(file, client); | 138 WebView* webView = setupTest(file, client); |
139 | 139 |
140 Persistent<Document> document = | 140 Persistent<Document> document = |
141 static_cast<Document*>(webView->mainFrame()->document()); | 141 static_cast<Document*>(webView->mainFrame()->document()); |
142 runTestOnTree(document.get(), webView, client); | 142 runTestOnTree(document.get(), webView, client); |
143 | 143 |
144 // Explicitly reset to break dependency on locally scoped client. | 144 // Explicitly reset to break dependency on locally scoped client. |
145 m_webViewHelper.reset(); | 145 m_webViewHelper.reset(); |
146 } | 146 } |
147 | 147 |
148 void TouchActionTest::runShadowDOMTest(std::string file) { | 148 void TouchActionTest::runShadowDOMTest(std::string file) { |
149 TouchActionTrackingWebViewClient client; | 149 TouchActionTrackingWebWidgetClient client; |
150 | 150 |
151 WebView* webView = setupTest(file, client); | 151 WebView* webView = setupTest(file, client); |
152 | 152 |
153 DummyExceptionStateForTesting es; | 153 DummyExceptionStateForTesting es; |
154 | 154 |
155 // Oilpan: see runTouchActionTest() comment why these are persistent | 155 // Oilpan: see runTouchActionTest() comment why these are persistent |
156 // references. | 156 // references. |
157 Persistent<Document> document = | 157 Persistent<Document> document = |
158 static_cast<Document*>(webView->mainFrame()->document()); | 158 static_cast<Document*>(webView->mainFrame()->document()); |
159 Persistent<StaticElementList> hostNodes = | 159 Persistent<StaticElementList> hostNodes = |
160 document->querySelectorAll("[shadow-host]", es); | 160 document->querySelectorAll("[shadow-host]", es); |
161 ASSERT_FALSE(es.hadException()); | 161 ASSERT_FALSE(es.hadException()); |
162 ASSERT_GE(hostNodes->length(), 1u); | 162 ASSERT_GE(hostNodes->length(), 1u); |
163 | 163 |
164 for (unsigned index = 0; index < hostNodes->length(); index++) { | 164 for (unsigned index = 0; index < hostNodes->length(); index++) { |
165 ShadowRoot* shadowRoot = hostNodes->item(index)->openShadowRoot(); | 165 ShadowRoot* shadowRoot = hostNodes->item(index)->openShadowRoot(); |
166 runTestOnTree(shadowRoot, webView, client); | 166 runTestOnTree(shadowRoot, webView, client); |
167 } | 167 } |
168 | 168 |
169 // Projections show up in the main document. | 169 // Projections show up in the main document. |
170 runTestOnTree(document.get(), webView, client); | 170 runTestOnTree(document.get(), webView, client); |
171 | 171 |
172 // Explicitly reset to break dependency on locally scoped client. | 172 // Explicitly reset to break dependency on locally scoped client. |
173 m_webViewHelper.reset(); | 173 m_webViewHelper.reset(); |
174 } | 174 } |
175 | 175 |
176 void TouchActionTest::runIFrameTest(std::string file) { | 176 void TouchActionTest::runIFrameTest(std::string file) { |
177 TouchActionTrackingWebViewClient client; | 177 TouchActionTrackingWebWidgetClient client; |
178 | 178 |
179 WebView* webView = setupTest(file, client); | 179 WebView* webView = setupTest(file, client); |
180 WebFrame* curFrame = webView->mainFrame()->firstChild(); | 180 WebFrame* curFrame = webView->mainFrame()->firstChild(); |
181 ASSERT_TRUE(curFrame); | 181 ASSERT_TRUE(curFrame); |
182 | 182 |
183 for (; curFrame; curFrame = curFrame->nextSibling()) { | 183 for (; curFrame; curFrame = curFrame->nextSibling()) { |
184 // Oilpan: see runTouchActionTest() comment why these are persistent | 184 // Oilpan: see runTouchActionTest() comment why these are persistent |
185 // references. | 185 // references. |
186 Persistent<Document> contentDoc = | 186 Persistent<Document> contentDoc = |
187 static_cast<Document*>(curFrame->document()); | 187 static_cast<Document*>(curFrame->document()); |
188 runTestOnTree(contentDoc.get(), webView, client); | 188 runTestOnTree(contentDoc.get(), webView, client); |
189 } | 189 } |
190 | 190 |
191 // Explicitly reset to break dependency on locally scoped client. | 191 // Explicitly reset to break dependency on locally scoped client. |
192 m_webViewHelper.reset(); | 192 m_webViewHelper.reset(); |
193 } | 193 } |
194 | 194 |
195 WebView* TouchActionTest::setupTest(std::string file, | 195 WebView* TouchActionTest::setupTest( |
196 TouchActionTrackingWebViewClient& client) { | 196 std::string file, |
| 197 TouchActionTrackingWebWidgetClient& client) { |
197 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), | 198 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), |
198 WebString::fromUTF8(file)); | 199 WebString::fromUTF8(file)); |
199 // Note that JavaScript must be enabled for shadow DOM tests. | 200 // Note that JavaScript must be enabled for shadow DOM tests. |
200 WebView* webView = | 201 WebView* webView = |
201 m_webViewHelper.initializeAndLoad(m_baseURL + file, true, 0, &client); | 202 m_webViewHelper.initializeAndLoad(m_baseURL + file, true, 0, 0, &client); |
202 | 203 |
203 // Set size to enable hit testing, and avoid line wrapping for consistency | 204 // Set size to enable hit testing, and avoid line wrapping for consistency |
204 // with browser. | 205 // with browser. |
205 webView->resize(WebSize(800, 1200)); | 206 webView->resize(WebSize(800, 1200)); |
206 | 207 |
207 // Scroll to verify the code properly transforms windows to client co-ords. | 208 // Scroll to verify the code properly transforms windows to client co-ords. |
208 const int kScrollOffset = 100; | 209 const int kScrollOffset = 100; |
209 Document* document = static_cast<Document*>(webView->mainFrame()->document()); | 210 Document* document = static_cast<Document*>(webView->mainFrame()->document()); |
210 document->frame()->view()->layoutViewportScrollableArea()->setScrollOffset( | 211 document->frame()->view()->layoutViewportScrollableArea()->setScrollOffset( |
211 ScrollOffset(0, kScrollOffset), ProgrammaticScroll); | 212 ScrollOffset(0, kScrollOffset), ProgrammaticScroll); |
212 | 213 |
213 return webView; | 214 return webView; |
214 } | 215 } |
215 | 216 |
216 IntRect windowClipRect(const FrameView& frameView) { | 217 IntRect windowClipRect(const FrameView& frameView) { |
217 LayoutRect clipRect( | 218 LayoutRect clipRect( |
218 LayoutPoint(), | 219 LayoutPoint(), |
219 LayoutSize(frameView.visibleContentSize(ExcludeScrollbars))); | 220 LayoutSize(frameView.visibleContentSize(ExcludeScrollbars))); |
220 frameView.layoutViewItem().mapToVisualRectInAncestorSpace( | 221 frameView.layoutViewItem().mapToVisualRectInAncestorSpace( |
221 &frameView.layoutView()->containerForPaintInvalidation(), clipRect); | 222 &frameView.layoutView()->containerForPaintInvalidation(), clipRect); |
222 return enclosingIntRect(clipRect); | 223 return enclosingIntRect(clipRect); |
223 } | 224 } |
224 | 225 |
225 void TouchActionTest::runTestOnTree(ContainerNode* root, | 226 void TouchActionTest::runTestOnTree( |
226 WebView* webView, | 227 ContainerNode* root, |
227 TouchActionTrackingWebViewClient& client) { | 228 WebView* webView, |
| 229 TouchActionTrackingWebWidgetClient& client) { |
228 // Find all elements to test the touch-action of in the document. | 230 // Find all elements to test the touch-action of in the document. |
229 DummyExceptionStateForTesting es; | 231 DummyExceptionStateForTesting es; |
230 | 232 |
231 // Oilpan: see runTouchActionTest() comment why these are persistent | 233 // Oilpan: see runTouchActionTest() comment why these are persistent |
232 // references. | 234 // references. |
233 Persistent<StaticElementList> elements = | 235 Persistent<StaticElementList> elements = |
234 root->querySelectorAll("[expected-action]", es); | 236 root->querySelectorAll("[expected-action]", es); |
235 ASSERT_FALSE(es.hadException()); | 237 ASSERT_FALSE(es.hadException()); |
236 | 238 |
237 for (unsigned index = 0; index < elements->length(); index++) { | 239 for (unsigned index = 0; index < elements->length(); index++) { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 408 |
407 TEST_F(TouchActionTest, ShadowDOM) { | 409 TEST_F(TouchActionTest, ShadowDOM) { |
408 runShadowDOMTest("touch-action-shadow-dom.html"); | 410 runShadowDOMTest("touch-action-shadow-dom.html"); |
409 } | 411 } |
410 | 412 |
411 TEST_F(TouchActionTest, Pan) { | 413 TEST_F(TouchActionTest, Pan) { |
412 runTouchActionTest("touch-action-pan.html"); | 414 runTouchActionTest("touch-action-pan.html"); |
413 } | 415 } |
414 | 416 |
415 } // namespace blink | 417 } // namespace blink |
OLD | NEW |