Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: Source/web/tests/ProgrammaticScrollTest.cpp

Issue 23506013: Make the embedder responsible for creating the WebFrame (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix lifetime on frame detach Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/web/tests/PrerenderingTest.cpp ('k') | Source/web/tests/RenderLayerBackingTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "config.h" 1 #include "config.h"
2 2
3 #include <gtest/gtest.h> 3 #include <gtest/gtest.h>
4 #include "FrameTestHelpers.h" 4 #include "FrameTestHelpers.h"
5 #include "RuntimeEnabledFeatures.h" 5 #include "RuntimeEnabledFeatures.h"
6 #include "URLTestHelpers.h" 6 #include "URLTestHelpers.h"
7 #include "WebFrame.h" 7 #include "WebFrame.h"
8 #include "WebFrameClient.h" 8 #include "WebFrameClient.h"
9 #include "WebFrameImpl.h" 9 #include "WebFrameImpl.h"
10 #include "WebHistoryItem.h" 10 #include "WebHistoryItem.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 private: 76 private:
77 bool m_eventReceived; 77 bool m_eventReceived;
78 }; 78 };
79 79
80 TEST_F(ProgrammaticScrollTest, UserScroll) 80 TEST_F(ProgrammaticScrollTest, UserScroll)
81 { 81 {
82 registerMockedHttpURLLoad("short_scroll.html"); 82 registerMockedHttpURLLoad("short_scroll.html");
83 TestProgrammaticScrollClient client; 83 TestProgrammaticScrollClient client;
84 84
85 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "short _scroll.html", false, 0, &client); 85 FrameTestHelpers::WebViewHelper webViewHelper;
86 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "short_scroll .html", false, 0, &client);
86 webView->resize(WebSize(1000, 1000)); 87 webView->resize(WebSize(1000, 1000));
87 webView->layout(); 88 webView->layout();
88 89
89 EXPECT_FALSE(client.eventReceived()); 90 EXPECT_FALSE(client.eventReceived());
90 91
91 // Non zero page scale and scroll. 92 // Non zero page scale and scroll.
92 toWebViewImpl(webView)->applyScrollAndScale(WebSize(9, 13), 2.0f); 93 toWebViewImpl(webView)->applyScrollAndScale(WebSize(9, 13), 2.0f);
93 EXPECT_FALSE(client.eventReceived()); 94 EXPECT_FALSE(client.eventReceived());
94
95 webView->close();
96 } 95 }
97 96
98 TEST_F(ProgrammaticScrollTest, ProgrammaticScroll) 97 TEST_F(ProgrammaticScrollTest, ProgrammaticScroll)
99 { 98 {
100 registerMockedHttpURLLoad("long_scroll.html"); 99 registerMockedHttpURLLoad("long_scroll.html");
101 TestProgrammaticScrollClient client; 100 TestProgrammaticScrollClient client;
102 101
103 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "long_ scroll.html", true, 0, &client); 102 FrameTestHelpers::WebViewHelper webViewHelper;
103 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "long_scroll. html", true, 0, &client);
104 webView->resize(WebSize(1000, 1000)); 104 webView->resize(WebSize(1000, 1000));
105 webView->layout(); 105 webView->layout();
106 106
107 WebFrameImpl* frameImpl = toWebViewImpl(webView)->mainFrameImpl(); 107 WebFrameImpl* frameImpl = toWebViewImpl(webView)->mainFrameImpl();
108 FrameView* frameView = frameImpl->frameView(); 108 FrameView* frameView = frameImpl->frameView();
109 109
110 // Slow scroll path. 110 // Slow scroll path.
111 frameView->setCanBlitOnScroll(false); 111 frameView->setCanBlitOnScroll(false);
112 EXPECT_FALSE(client.eventReceived()); 112 EXPECT_FALSE(client.eventReceived());
113 frameImpl->executeScript(WebScriptSource("window.scrollTo(0, 20);")); 113 frameImpl->executeScript(WebScriptSource("window.scrollTo(0, 20);"));
114 EXPECT_TRUE(client.eventReceived()); 114 EXPECT_TRUE(client.eventReceived());
115 client.reset(); 115 client.reset();
116 frameImpl->executeScript(WebScriptSource("window.scrollBy(0, 0);")); 116 frameImpl->executeScript(WebScriptSource("window.scrollBy(0, 0);"));
117 EXPECT_FALSE(client.eventReceived()); 117 EXPECT_FALSE(client.eventReceived());
118 client.reset(); 118 client.reset();
119 119
120 // Fast scroll path. 120 // Fast scroll path.
121 frameImpl->frameView()->setCanBlitOnScroll(true); 121 frameImpl->frameView()->setCanBlitOnScroll(true);
122 EXPECT_FALSE(client.eventReceived()); 122 EXPECT_FALSE(client.eventReceived());
123 frameImpl->executeScript(WebScriptSource("window.scrollTo(0, 21);")); 123 frameImpl->executeScript(WebScriptSource("window.scrollTo(0, 21);"));
124 EXPECT_TRUE(client.eventReceived()); 124 EXPECT_TRUE(client.eventReceived());
125 client.reset(); 125 client.reset();
126 frameImpl->executeScript(WebScriptSource("window.scrollBy(0, 0);")); 126 frameImpl->executeScript(WebScriptSource("window.scrollBy(0, 0);"));
127 EXPECT_FALSE(client.eventReceived()); 127 EXPECT_FALSE(client.eventReceived());
128 client.reset(); 128 client.reset();
129
130 webView->close();
131 } 129 }
132 130
133 TEST_F(ProgrammaticScrollTest, UserScrollOnMainThread) 131 TEST_F(ProgrammaticScrollTest, UserScrollOnMainThread)
134 { 132 {
135 registerMockedHttpURLLoad("long_scroll.html"); 133 registerMockedHttpURLLoad("long_scroll.html");
136 TestProgrammaticScrollClient client; 134 TestProgrammaticScrollClient client;
137 135
138 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "long_ scroll.html", true, 0, &client); 136 FrameTestHelpers::WebViewHelper webViewHelper;
137 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "long_scroll. html", true, 0, &client);
139 webView->resize(WebSize(1000, 1000)); 138 webView->resize(WebSize(1000, 1000));
140 webView->layout(); 139 webView->layout();
141 140
142 WebGestureEvent gesture; 141 WebGestureEvent gesture;
143 gesture.type = WebInputEvent::GestureScrollBegin; 142 gesture.type = WebInputEvent::GestureScrollBegin;
144 webView->handleInputEvent(gesture); 143 webView->handleInputEvent(gesture);
145 FrameTestHelpers::runPendingTasks(); 144 FrameTestHelpers::runPendingTasks();
146 EXPECT_FALSE(client.eventReceived()); 145 EXPECT_FALSE(client.eventReceived());
147 146
148 gesture.type = WebInputEvent::GestureScrollUpdate; 147 gesture.type = WebInputEvent::GestureScrollUpdate;
149 gesture.data.scrollUpdate.deltaY = 40; 148 gesture.data.scrollUpdate.deltaY = 40;
150 webView->handleInputEvent(gesture); 149 webView->handleInputEvent(gesture);
151 FrameTestHelpers::runPendingTasks(); 150 FrameTestHelpers::runPendingTasks();
152 EXPECT_FALSE(client.eventReceived()); 151 EXPECT_FALSE(client.eventReceived());
153 152
154 gesture.type = WebInputEvent::GestureScrollEnd; 153 gesture.type = WebInputEvent::GestureScrollEnd;
155 gesture.data.scrollUpdate.deltaY = 0; 154 gesture.data.scrollUpdate.deltaY = 0;
156 webView->handleInputEvent(gesture); 155 webView->handleInputEvent(gesture);
157 FrameTestHelpers::runPendingTasks(); 156 FrameTestHelpers::runPendingTasks();
158 EXPECT_FALSE(client.eventReceived()); 157 EXPECT_FALSE(client.eventReceived());
159
160 webView->close();
161 } 158 }
162 159
163 TEST_F(ProgrammaticScrollTest, RestoreScrollPositionAndViewStateWithScale) 160 TEST_F(ProgrammaticScrollTest, RestoreScrollPositionAndViewStateWithScale)
164 { 161 {
165 registerMockedHttpURLLoad("long_scroll.html"); 162 registerMockedHttpURLLoad("long_scroll.html");
166 TestProgrammaticScrollClient client; 163 TestProgrammaticScrollClient client;
167 164
168 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "long_ scroll.html", true, 0, &client); 165 FrameTestHelpers::WebViewHelper webViewHelper;
166 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "long_scroll. html", true, 0, &client);
169 webView->resize(WebSize(1000, 1000)); 167 webView->resize(WebSize(1000, 1000));
170 webView->layout(); 168 webView->layout();
171 169
172 WebViewImpl* webViewImpl = toWebViewImpl(webView); 170 WebViewImpl* webViewImpl = toWebViewImpl(webView);
173 FrameView* frameView = webViewImpl->mainFrameImpl()->frameView(); 171 FrameView* frameView = webViewImpl->mainFrameImpl()->frameView();
174 HistoryController* history = webViewImpl->page()->mainFrame()->loader()->his tory(); 172 HistoryController* history = webViewImpl->page()->mainFrame()->loader()->his tory();
175 173
176 // Scale and scroll the page and save that state. Then scale and scroll agai n and restore. 174 // Scale and scroll the page and save that state. Then scale and scroll agai n and restore.
177 webViewImpl->setPageScaleFactor(2.0f, WebPoint(0, 200)); 175 webViewImpl->setPageScaleFactor(2.0f, WebPoint(0, 200));
178 history->saveDocumentAndScrollState(); 176 history->saveDocumentAndScrollState();
179 webViewImpl->setPageScaleFactor(3.0f, WebPoint(0, 300)); 177 webViewImpl->setPageScaleFactor(3.0f, WebPoint(0, 300));
180 // Flip back the wasScrolledByUser flag which was set to true by setPageScal eFactor 178 // Flip back the wasScrolledByUser flag which was set to true by setPageScal eFactor
181 // because otherwise HistoryController::restoreScrollPositionAndViewState do es nothing. 179 // because otherwise HistoryController::restoreScrollPositionAndViewState do es nothing.
182 frameView->setWasScrolledByUser(false); 180 frameView->setWasScrolledByUser(false);
183 history->restoreScrollPositionAndViewState(); 181 history->restoreScrollPositionAndViewState();
184 182
185 // Expect that both scroll and scale were restored, and that it was not a pr ogrammatic scroll. 183 // Expect that both scroll and scale were restored, and that it was not a pr ogrammatic scroll.
186 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); 184 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor());
187 EXPECT_EQ(200, webViewImpl->mainFrameImpl()->scrollOffset().height); 185 EXPECT_EQ(200, webViewImpl->mainFrameImpl()->scrollOffset().height);
188 EXPECT_TRUE(frameView->wasScrolledByUser()); 186 EXPECT_TRUE(frameView->wasScrolledByUser());
189 EXPECT_FALSE(client.eventReceived()); 187 EXPECT_FALSE(client.eventReceived());
190
191 webView->close();
192 } 188 }
193 189
194 TEST_F(ProgrammaticScrollTest, RestoreScrollPositionAndViewStateWithoutScale) 190 TEST_F(ProgrammaticScrollTest, RestoreScrollPositionAndViewStateWithoutScale)
195 { 191 {
196 registerMockedHttpURLLoad("long_scroll.html"); 192 registerMockedHttpURLLoad("long_scroll.html");
197 TestProgrammaticScrollClient client; 193 TestProgrammaticScrollClient client;
198 194
199 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "long_ scroll.html", true, 0, &client); 195 FrameTestHelpers::WebViewHelper webViewHelper;
196 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "long_scroll. html", true, 0, &client);
200 webView->resize(WebSize(1000, 1000)); 197 webView->resize(WebSize(1000, 1000));
201 webView->layout(); 198 webView->layout();
202 199
203 WebViewImpl* webViewImpl = toWebViewImpl(webView); 200 WebViewImpl* webViewImpl = toWebViewImpl(webView);
204 FrameView* frameView = webViewImpl->mainFrameImpl()->frameView(); 201 FrameView* frameView = webViewImpl->mainFrameImpl()->frameView();
205 HistoryController* history = webViewImpl->page()->mainFrame()->loader()->his tory(); 202 HistoryController* history = webViewImpl->page()->mainFrame()->loader()->his tory();
206 203
207 // Scale and scroll the page and save that state, but then set scale to zero . Then scale and 204 // Scale and scroll the page and save that state, but then set scale to zero . Then scale and
208 // scroll again and restore. 205 // scroll again and restore.
209 webViewImpl->setPageScaleFactor(2.0f, WebPoint(0, 400)); 206 webViewImpl->setPageScaleFactor(2.0f, WebPoint(0, 400));
210 history->saveDocumentAndScrollState(); 207 history->saveDocumentAndScrollState();
211 webViewImpl->setPageScaleFactor(3.0f, WebPoint(0, 500)); 208 webViewImpl->setPageScaleFactor(3.0f, WebPoint(0, 500));
212 // Flip back the wasScrolledByUser flag which was set to true by setPageScal eFactor 209 // Flip back the wasScrolledByUser flag which was set to true by setPageScal eFactor
213 // because otherwise HistoryController::restoreScrollPositionAndViewState do es nothing. 210 // because otherwise HistoryController::restoreScrollPositionAndViewState do es nothing.
214 frameView->setWasScrolledByUser(false); 211 frameView->setWasScrolledByUser(false);
215 // HistoryController::restoreScrollPositionAndViewState flows differently if scale is zero. 212 // HistoryController::restoreScrollPositionAndViewState flows differently if scale is zero.
216 history->currentItem()->setPageScaleFactor(0.0f); 213 history->currentItem()->setPageScaleFactor(0.0f);
217 history->restoreScrollPositionAndViewState(); 214 history->restoreScrollPositionAndViewState();
218 215
219 // Expect that only the scroll position was restored, and that it was not a programmatic scroll. 216 // Expect that only the scroll position was restored, and that it was not a programmatic scroll.
220 EXPECT_EQ(3.0f, webViewImpl->pageScaleFactor()); 217 EXPECT_EQ(3.0f, webViewImpl->pageScaleFactor());
221 EXPECT_EQ(400, webViewImpl->mainFrameImpl()->scrollOffset().height); 218 EXPECT_EQ(400, webViewImpl->mainFrameImpl()->scrollOffset().height);
222 EXPECT_TRUE(frameView->wasScrolledByUser()); 219 EXPECT_TRUE(frameView->wasScrolledByUser());
223 EXPECT_FALSE(client.eventReceived()); 220 EXPECT_FALSE(client.eventReceived());
224
225 webView->close();
226 } 221 }
227 222
228 } 223 }
OLDNEW
« no previous file with comments | « Source/web/tests/PrerenderingTest.cpp ('k') | Source/web/tests/RenderLayerBackingTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698