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

Side by Side Diff: Source/web/tests/WebFrameTest.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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 return m_layerTreeView.get(); 127 return m_layerTreeView.get();
128 } 128 }
129 129
130 FakeWebFrameClient m_fakeWebFrameClient; 130 FakeWebFrameClient m_fakeWebFrameClient;
131 131
132 private: 132 private:
133 OwnPtr<WebLayerTreeView> m_layerTreeView; 133 OwnPtr<WebLayerTreeView> m_layerTreeView;
134 }; 134 };
135 135
136 class WebFrameTest : public testing::Test { 136 class WebFrameTest : public testing::Test {
137 public: 137 protected:
138 WebFrameTest() 138 WebFrameTest()
139 : m_baseURL("http://www.test.com/") 139 : m_baseURL("http://www.test.com/")
140 , m_chromeURL("chrome://") 140 , m_chromeURL("chrome://")
141 , m_webView(0)
142 { 141 {
143 } 142 }
144 143
145 virtual ~WebFrameTest() 144 virtual ~WebFrameTest()
146 { 145 {
147 if (m_webView)
148 m_webView->close();
149 }
150
151 virtual void TearDown()
152 {
153 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); 146 Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
154 } 147 }
155 148
156 void registerMockedHttpURLLoad(const std::string& fileName) 149 void registerMockedHttpURLLoad(const std::string& fileName)
157 { 150 {
158 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseU RL.c_str()), WebString::fromUTF8(fileName.c_str())); 151 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseU RL.c_str()), WebString::fromUTF8(fileName.c_str()));
159 } 152 }
160 153
161 void registerMockedChromeURLLoad(const std::string& fileName) 154 void registerMockedChromeURLLoad(const std::string& fileName)
162 { 155 {
163 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_chrom eURL.c_str()), WebString::fromUTF8(fileName.c_str())); 156 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_chrom eURL.c_str()), WebString::fromUTF8(fileName.c_str()));
164 } 157 }
165 158
166 void createCompositingWebView() 159 static void configueCompositingWebView(WebSettings* settings)
167 { 160 {
168 m_fakeCompositingWebViewClient = adoptPtr(new FakeCompositingWebViewClie nt()); 161 settings->setForceCompositingMode(true);
169 m_webView = WebView::create(m_fakeCompositingWebViewClient.get()); 162 settings->setAcceleratedCompositingEnabled(true);
170 m_webView->settings()->setJavaScriptEnabled(true); 163 settings->setAcceleratedCompositingForFixedPositionEnabled(true);
171 m_webView->settings()->setForceCompositingMode(true); 164 settings->setAcceleratedCompositingForOverflowScrollEnabled(true);
172 m_webView->settings()->setAcceleratedCompositingEnabled(true); 165 settings->setAcceleratedCompositingForScrollableFramesEnabled(true);
173 m_webView->settings()->setAcceleratedCompositingForFixedPositionEnabled( true); 166 settings->setCompositedScrollingForFramesEnabled(true);
174 m_webView->settings()->setAcceleratedCompositingForOverflowScrollEnabled (true); 167 settings->setFixedPositionCreatesStackingContext(true);
175 m_webView->settings()->setAcceleratedCompositingForScrollableFramesEnabl ed(true);
176 m_webView->settings()->setCompositedScrollingForFramesEnabled(true);
177 m_webView->settings()->setFixedPositionCreatesStackingContext(true);
178 m_webView->initializeMainFrame(&m_fakeCompositingWebViewClient->m_fakeWe bFrameClient);
179 } 168 }
180 169
181 protected: 170 void initializeTextSelectionWebView(const std::string& url, FrameTestHelpers ::WebViewHelper* webViewHelper)
182 WebViewImpl* webViewImpl() const { return toWebViewImpl(m_webView); } 171 {
172 webViewHelper->initializeAndLoad(url, true);
173 webViewHelper->webView()->settings()->setDefaultFontSize(12);
174 webViewHelper->webView()->enableFixedLayoutMode(false);
175 webViewHelper->webView()->resize(WebSize(640, 480));
176 }
183 177
184 std::string m_baseURL; 178 std::string m_baseURL;
185 std::string m_chromeURL; 179 std::string m_chromeURL;
186 OwnPtr<FakeCompositingWebViewClient> m_fakeCompositingWebViewClient;
187
188 WebView* m_webView;
189 }; 180 };
190 181
191 class UseMockScrollbarSettings { 182 class UseMockScrollbarSettings {
192 public: 183 public:
193 UseMockScrollbarSettings() 184 UseMockScrollbarSettings()
194 { 185 {
195 WebCore::Settings::setMockScrollbarsEnabled(true); 186 WebCore::Settings::setMockScrollbarsEnabled(true);
196 WebCore::RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); 187 WebCore::RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true);
197 EXPECT_TRUE(WebCore::ScrollbarTheme::theme()->usesOverlayScrollbars()); 188 EXPECT_TRUE(WebCore::ScrollbarTheme::theme()->usesOverlayScrollbars());
198 } 189 }
199 190
200 ~UseMockScrollbarSettings() 191 ~UseMockScrollbarSettings()
201 { 192 {
202 WebCore::Settings::setMockScrollbarsEnabled(false); 193 WebCore::Settings::setMockScrollbarsEnabled(false);
203 WebCore::RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(false); 194 WebCore::RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(false);
204 } 195 }
205 }; 196 };
206 197
207 TEST_F(WebFrameTest, ContentText) 198 TEST_F(WebFrameTest, ContentText)
208 { 199 {
209 registerMockedHttpURLLoad("iframes_test.html"); 200 registerMockedHttpURLLoad("iframes_test.html");
210 registerMockedHttpURLLoad("visible_iframe.html"); 201 registerMockedHttpURLLoad("visible_iframe.html");
211 registerMockedHttpURLLoad("invisible_iframe.html"); 202 registerMockedHttpURLLoad("invisible_iframe.html");
212 registerMockedHttpURLLoad("zero_sized_iframe.html"); 203 registerMockedHttpURLLoad("zero_sized_iframe.html");
213 204
214 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "iframes_test .html"); 205 FrameTestHelpers::WebViewHelper webViewHelper;
206 webViewHelper.initializeAndLoad(m_baseURL + "iframes_test.html");
215 207
216 // Now retrieve the frames text and test it only includes visible elements. 208 // Now retrieve the frames text and test it only includes visible elements.
217 std::string content = std::string(m_webView->mainFrame()->contentAsText(1024 ).utf8().data()); 209 std::string content = std::string(webViewHelper.webView()->mainFrame()->cont entAsText(1024).utf8().data());
218 EXPECT_NE(std::string::npos, content.find(" visible paragraph")); 210 EXPECT_NE(std::string::npos, content.find(" visible paragraph"));
219 EXPECT_NE(std::string::npos, content.find(" visible iframe")); 211 EXPECT_NE(std::string::npos, content.find(" visible iframe"));
220 EXPECT_EQ(std::string::npos, content.find(" invisible pararaph")); 212 EXPECT_EQ(std::string::npos, content.find(" invisible pararaph"));
221 EXPECT_EQ(std::string::npos, content.find(" invisible iframe")); 213 EXPECT_EQ(std::string::npos, content.find(" invisible iframe"));
222 EXPECT_EQ(std::string::npos, content.find("iframe with zero size")); 214 EXPECT_EQ(std::string::npos, content.find("iframe with zero size"));
223 } 215 }
224 216
225 TEST_F(WebFrameTest, FrameForEnteredContext) 217 TEST_F(WebFrameTest, FrameForEnteredContext)
226 { 218 {
227 registerMockedHttpURLLoad("iframes_test.html"); 219 registerMockedHttpURLLoad("iframes_test.html");
228 registerMockedHttpURLLoad("visible_iframe.html"); 220 registerMockedHttpURLLoad("visible_iframe.html");
229 registerMockedHttpURLLoad("invisible_iframe.html"); 221 registerMockedHttpURLLoad("invisible_iframe.html");
230 registerMockedHttpURLLoad("zero_sized_iframe.html"); 222 registerMockedHttpURLLoad("zero_sized_iframe.html");
231 223
232 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "iframes_test .html", true); 224 FrameTestHelpers::WebViewHelper webViewHelper;
225 webViewHelper.initializeAndLoad(m_baseURL + "iframes_test.html", true);
233 226
234 v8::HandleScope scope(v8::Isolate::GetCurrent()); 227 v8::HandleScope scope(v8::Isolate::GetCurrent());
235 EXPECT_EQ(m_webView->mainFrame(), 228 EXPECT_EQ(webViewHelper.webView()->mainFrame(), WebFrame::frameForContext(we bViewHelper.webView()->mainFrame()->mainWorldScriptContext()));
236 WebFrame::frameForContext( 229 EXPECT_EQ(webViewHelper.webView()->mainFrame()->firstChild(), WebFrame::fram eForContext(webViewHelper.webView()->mainFrame()->firstChild()->mainWorldScriptC ontext()));
237 m_webView->mainFrame()->mainWorldScriptContext()));
238 EXPECT_EQ(m_webView->mainFrame()->firstChild(),
239 WebFrame::frameForContext(
240 m_webView->mainFrame()->firstChild()->mainWorldScriptContext() ));
241 } 230 }
242 231
243 TEST_F(WebFrameTest, FormWithNullFrame) 232 TEST_F(WebFrameTest, FormWithNullFrame)
244 { 233 {
245 registerMockedHttpURLLoad("form.html"); 234 registerMockedHttpURLLoad("form.html");
246 235
247 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "form.html"); 236 FrameTestHelpers::WebViewHelper webViewHelper;
237 webViewHelper.initializeAndLoad(m_baseURL + "form.html");
248 238
249 WebVector<WebFormElement> forms; 239 WebVector<WebFormElement> forms;
250 m_webView->mainFrame()->document().forms(forms); 240 webViewHelper.webView()->mainFrame()->document().forms(forms);
251 m_webView->close(); 241 webViewHelper.reset();
252 m_webView = 0;
253 242
254 EXPECT_EQ(forms.size(), 1U); 243 EXPECT_EQ(forms.size(), 1U);
255 244
256 // This test passes if this doesn't crash. 245 // This test passes if this doesn't crash.
257 WebSearchableFormData searchableDataForm(forms[0]); 246 WebSearchableFormData searchableDataForm(forms[0]);
258 } 247 }
259 248
260 TEST_F(WebFrameTest, ChromePageJavascript) 249 TEST_F(WebFrameTest, ChromePageJavascript)
261 { 250 {
262 registerMockedChromeURLLoad("history.html"); 251 registerMockedChromeURLLoad("history.html");
263 252
264 // Pass true to enable JavaScript. 253 // Pass true to enable JavaScript.
265 m_webView = FrameTestHelpers::createWebViewAndLoad(m_chromeURL + "history.ht ml", true); 254 FrameTestHelpers::WebViewHelper webViewHelper;
255 webViewHelper.initializeAndLoad(m_chromeURL + "history.html", true);
266 256
267 // Try to run JS against the chrome-style URL. 257 // Try to run JS against the chrome-style URL.
268 FrameTestHelpers::loadFrame(m_webView->mainFrame(), "javascript:document.bod y.appendChild(document.createTextNode('Clobbered'))"); 258 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip t:document.body.appendChild(document.createTextNode('Clobbered'))");
269 259
270 // Required to see any updates in contentAsText. 260 // Required to see any updates in contentAsText.
271 m_webView->layout(); 261 webViewHelper.webView()->layout();
272 262
273 // Now retrieve the frame's text and ensure it was modified by running javas cript. 263 // Now retrieve the frame's text and ensure it was modified by running javas cript.
274 std::string content = std::string(m_webView->mainFrame()->contentAsText(1024 ).utf8().data()); 264 std::string content = std::string(webViewHelper.webView()->mainFrame()->cont entAsText(1024).utf8().data());
275 EXPECT_NE(std::string::npos, content.find("Clobbered")); 265 EXPECT_NE(std::string::npos, content.find("Clobbered"));
276 } 266 }
277 267
278 TEST_F(WebFrameTest, ChromePageNoJavascript) 268 TEST_F(WebFrameTest, ChromePageNoJavascript)
279 { 269 {
280 registerMockedChromeURLLoad("history.html"); 270 registerMockedChromeURLLoad("history.html");
281 271
282 /// Pass true to enable JavaScript. 272 /// Pass true to enable JavaScript.
283 m_webView = FrameTestHelpers::createWebViewAndLoad(m_chromeURL + "history.ht ml", true); 273 FrameTestHelpers::WebViewHelper webViewHelper;
274 webViewHelper.initializeAndLoad(m_chromeURL + "history.html", true);
284 275
285 // Try to run JS against the chrome-style URL after prohibiting it. 276 // Try to run JS against the chrome-style URL after prohibiting it.
286 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs("chrome"); 277 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs("chrome");
287 FrameTestHelpers::loadFrame(m_webView->mainFrame(), "javascript:document.bod y.appendChild(document.createTextNode('Clobbered'))"); 278 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip t:document.body.appendChild(document.createTextNode('Clobbered'))");
288 279
289 // Required to see any updates in contentAsText. 280 // Required to see any updates in contentAsText.
290 m_webView->layout(); 281 webViewHelper.webView()->layout();
291 282
292 // Now retrieve the frame's text and ensure it wasn't modified by running ja vascript. 283 // Now retrieve the frame's text and ensure it wasn't modified by running ja vascript.
293 std::string content = std::string(m_webView->mainFrame()->contentAsText(1024 ).utf8().data()); 284 std::string content = std::string(webViewHelper.webView()->mainFrame()->cont entAsText(1024).utf8().data());
294 EXPECT_EQ(std::string::npos, content.find("Clobbered")); 285 EXPECT_EQ(std::string::npos, content.find("Clobbered"));
295 } 286 }
296 287
297 TEST_F(WebFrameTest, DispatchMessageEventWithOriginCheck) 288 TEST_F(WebFrameTest, DispatchMessageEventWithOriginCheck)
298 { 289 {
299 registerMockedHttpURLLoad("postmessage_test.html"); 290 registerMockedHttpURLLoad("postmessage_test.html");
300 291
301 // Pass true to enable JavaScript. 292 // Pass true to enable JavaScript.
302 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "postmessage_ test.html", true); 293 FrameTestHelpers::WebViewHelper webViewHelper;
294 webViewHelper.initializeAndLoad(m_baseURL + "postmessage_test.html", true);
303 295
304 // Send a message with the correct origin. 296 // Send a message with the correct origin.
305 WebSecurityOrigin correctOrigin(WebSecurityOrigin::create(toKURL(m_baseURL)) ); 297 WebSecurityOrigin correctOrigin(WebSecurityOrigin::create(toKURL(m_baseURL)) );
306 WebDOMEvent event = m_webView->mainFrame()->document().createEvent("MessageE vent"); 298 WebDOMEvent event = webViewHelper.webView()->mainFrame()->document().createE vent("MessageEvent");
307 WebDOMMessageEvent message = event.to<WebDOMMessageEvent>(); 299 WebDOMMessageEvent message = event.to<WebDOMMessageEvent>();
308 WebSerializedScriptValue data(WebSerializedScriptValue::fromString("foo")); 300 WebSerializedScriptValue data(WebSerializedScriptValue::fromString("foo"));
309 message.initMessageEvent("message", false, false, data, "http://origin.com", 0, ""); 301 message.initMessageEvent("message", false, false, data, "http://origin.com", 0, "");
310 m_webView->mainFrame()->dispatchMessageEventWithOriginCheck(correctOrigin, m essage); 302 webViewHelper.webView()->mainFrame()->dispatchMessageEventWithOriginCheck(co rrectOrigin, message);
311 303
312 // Send another message with incorrect origin. 304 // Send another message with incorrect origin.
313 WebSecurityOrigin incorrectOrigin(WebSecurityOrigin::create(toKURL(m_chromeU RL))); 305 WebSecurityOrigin incorrectOrigin(WebSecurityOrigin::create(toKURL(m_chromeU RL)));
314 m_webView->mainFrame()->dispatchMessageEventWithOriginCheck(incorrectOrigin, message); 306 webViewHelper.webView()->mainFrame()->dispatchMessageEventWithOriginCheck(in correctOrigin, message);
315 307
316 // Required to see any updates in contentAsText. 308 // Required to see any updates in contentAsText.
317 m_webView->layout(); 309 webViewHelper.webView()->layout();
318 310
319 // Verify that only the first addition is in the body of the page. 311 // Verify that only the first addition is in the body of the page.
320 std::string content = std::string(m_webView->mainFrame()->contentAsText(1024 ).utf8().data()); 312 std::string content = std::string(webViewHelper.webView()->mainFrame()->cont entAsText(1024).utf8().data());
321 EXPECT_NE(std::string::npos, content.find("Message 1.")); 313 EXPECT_NE(std::string::npos, content.find("Message 1."));
322 EXPECT_EQ(std::string::npos, content.find("Message 2.")); 314 EXPECT_EQ(std::string::npos, content.find("Message 2."));
323 } 315 }
324 316
325 class FixedLayoutTestWebViewClient : public WebViewClient { 317 class FixedLayoutTestWebViewClient : public WebViewClient {
326 public: 318 public:
327 virtual WebScreenInfo screenInfo() OVERRIDE { return m_screenInfo; } 319 virtual WebScreenInfo screenInfo() OVERRIDE { return m_screenInfo; }
328 320
329 WebScreenInfo m_screenInfo; 321 WebScreenInfo m_screenInfo;
330 }; 322 };
331 323
332 TEST_F(WebFrameTest, FrameViewNeedsLayoutOnFixedLayoutResize) 324 TEST_F(WebFrameTest, FrameViewNeedsLayoutOnFixedLayoutResize)
333 { 325 {
334 registerMockedHttpURLLoad("fixed_layout.html"); 326 registerMockedHttpURLLoad("fixed_layout.html");
335 327
336 FixedLayoutTestWebViewClient client; 328 FixedLayoutTestWebViewClient client;
337 int viewportWidth = 640; 329 int viewportWidth = 640;
338 int viewportHeight = 480; 330 int viewportHeight = 480;
339 331
340 // Make sure we initialize to minimum scale, even if the window size 332 // Make sure we initialize to minimum scale, even if the window size
341 // only becomes available after the load begins. 333 // only becomes available after the load begins.
342 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html", true, 0, &client); 334 FrameTestHelpers::WebViewHelper webViewHelper;
343 m_webView->enableFixedLayoutMode(true); 335 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c lient);
344 m_webView->settings()->setViewportEnabled(true); 336 webViewHelper.webView()->enableFixedLayoutMode(true);
345 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 337 webViewHelper.webView()->settings()->setViewportEnabled(true);
346 m_webView->layout(); 338 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
339 webViewHelper.webView()->layout();
347 340
348 webViewImpl()->mainFrameImpl()->frameView()->setFixedLayoutSize(WebCore::Int Size(100, 100)); 341 webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->setFixedLayoutSiz e(WebCore::IntSize(100, 100));
349 EXPECT_TRUE(webViewImpl()->mainFrameImpl()->frameView()->needsLayout()); 342 EXPECT_TRUE(webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->needs Layout());
350 343
351 int prevLayoutCount = webViewImpl()->mainFrameImpl()->frameView()->layoutCou nt(); 344 int prevLayoutCount = webViewHelper.webViewImpl()->mainFrameImpl()->frameVie w()->layoutCount();
352 webViewImpl()->mainFrameImpl()->frameView()->setFrameRect(WebCore::IntRect(0 , 0, 641, 481)); 345 webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->setFrameRect(WebC ore::IntRect(0, 0, 641, 481));
353 EXPECT_EQ(prevLayoutCount, webViewImpl()->mainFrameImpl()->frameView()->layo utCount()); 346 EXPECT_EQ(prevLayoutCount, webViewHelper.webViewImpl()->mainFrameImpl()->fra meView()->layoutCount());
354 347
355 webViewImpl()->layout(); 348 webViewHelper.webViewImpl()->layout();
356 } 349 }
357 350
358 TEST_F(WebFrameTest, ChangeInFixedLayoutTriggersTextAutosizingRecalculate) 351 TEST_F(WebFrameTest, ChangeInFixedLayoutTriggersTextAutosizingRecalculate)
359 { 352 {
360 registerMockedHttpURLLoad("fixed_layout.html"); 353 registerMockedHttpURLLoad("fixed_layout.html");
361 354
362 FixedLayoutTestWebViewClient client; 355 FixedLayoutTestWebViewClient client;
363 int viewportWidth = 640; 356 int viewportWidth = 640;
364 int viewportHeight = 480; 357 int viewportHeight = 480;
365 358
366 // Make sure we initialize to minimum scale, even if the window size 359 // Make sure we initialize to minimum scale, even if the window size
367 // only becomes available after the load begins. 360 // only becomes available after the load begins.
368 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html", true, 0, &client); 361 FrameTestHelpers::WebViewHelper webViewHelper;
369 m_webView->enableFixedLayoutMode(true); 362 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c lient);
370 m_webView->settings()->setViewportEnabled(true); 363 webViewHelper.webView()->enableFixedLayoutMode(true);
364 webViewHelper.webView()->settings()->setViewportEnabled(true);
371 365
372 WebCore::Document* document = webViewImpl()->page()->mainFrame()->document() ; 366 WebCore::Document* document = webViewHelper.webViewImpl()->page()->mainFrame ()->document();
373 document->settings()->setTextAutosizingEnabled(true); 367 document->settings()->setTextAutosizingEnabled(true);
374 EXPECT_TRUE(document->settings()->textAutosizingEnabled()); 368 EXPECT_TRUE(document->settings()->textAutosizingEnabled());
375 webViewImpl()->resize(WebSize(viewportWidth, viewportHeight)); 369 webViewHelper.webViewImpl()->resize(WebSize(viewportWidth, viewportHeight));
376 webViewImpl()->layout(); 370 webViewHelper.webViewImpl()->layout();
377 371
378 WebCore::RenderObject* renderer = document->renderer(); 372 WebCore::RenderObject* renderer = document->renderer();
379 bool multiplierSetAtLeastOnce = false; 373 bool multiplierSetAtLeastOnce = false;
380 while (renderer) { 374 while (renderer) {
381 if (renderer->style()) { 375 if (renderer->style()) {
382 renderer->style()->setTextAutosizingMultiplier(2); 376 renderer->style()->setTextAutosizingMultiplier(2);
383 EXPECT_EQ(2, renderer->style()->textAutosizingMultiplier()); 377 EXPECT_EQ(2, renderer->style()->textAutosizingMultiplier());
384 multiplierSetAtLeastOnce = true; 378 multiplierSetAtLeastOnce = true;
385 } 379 }
386 renderer = renderer->nextInPreOrder(); 380 renderer = renderer->nextInPreOrder();
387 } 381 }
388 EXPECT_TRUE(multiplierSetAtLeastOnce); 382 EXPECT_TRUE(multiplierSetAtLeastOnce);
389 383
390 WebCore::ViewportArguments arguments = document->viewportArguments(); 384 WebCore::ViewportArguments arguments = document->viewportArguments();
391 // Choose a width that's not going match the viewport width of the loaded do cument. 385 // Choose a width that's not going match the viewport width of the loaded do cument.
392 arguments.minWidth = WebCore::Length(100, WebCore::Fixed); 386 arguments.minWidth = WebCore::Length(100, WebCore::Fixed);
393 arguments.maxWidth = WebCore::Length(100, WebCore::Fixed); 387 arguments.maxWidth = WebCore::Length(100, WebCore::Fixed);
394 webViewImpl()->updatePageDefinedPageScaleConstraints(arguments); 388 webViewHelper.webViewImpl()->updatePageDefinedPageScaleConstraints(arguments );
395 389
396 bool multiplierCheckedAtLeastOnce = false; 390 bool multiplierCheckedAtLeastOnce = false;
397 renderer = document->renderer(); 391 renderer = document->renderer();
398 while (renderer) { 392 while (renderer) {
399 if (renderer->style()) { 393 if (renderer->style()) {
400 EXPECT_EQ(1, renderer->style()->textAutosizingMultiplier()); 394 EXPECT_EQ(1, renderer->style()->textAutosizingMultiplier());
401 multiplierCheckedAtLeastOnce = true; 395 multiplierCheckedAtLeastOnce = true;
402 } 396 }
403 renderer = renderer->nextInPreOrder(); 397 renderer = renderer->nextInPreOrder();
404 } 398 }
405 EXPECT_TRUE(multiplierCheckedAtLeastOnce); 399 EXPECT_TRUE(multiplierCheckedAtLeastOnce);
406 } 400 }
407 401
408 TEST_F(WebFrameTest, FixedLayoutSizeStopsResizeFromChangingLayoutSize) 402 TEST_F(WebFrameTest, FixedLayoutSizeStopsResizeFromChangingLayoutSize)
409 { 403 {
410 registerMockedHttpURLLoad("fixed_layout.html"); 404 registerMockedHttpURLLoad("fixed_layout.html");
411 405
412 int viewportWidth = 640; 406 int viewportWidth = 640;
413 int viewportHeight = 480; 407 int viewportHeight = 480;
414 408
415 int fixedLayoutWidth = viewportWidth / 2; 409 int fixedLayoutWidth = viewportWidth / 2;
416 int fixedLayoutHeight = viewportHeight / 2; 410 int fixedLayoutHeight = viewportHeight / 2;
417 411
418 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html"); 412 FrameTestHelpers::WebViewHelper webViewHelper;
419 m_webView->enableFixedLayoutMode(true); 413 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html");
420 m_webView->settings()->setViewportEnabled(true); 414 webViewHelper.webView()->enableFixedLayoutMode(true);
421 m_webView->setFixedLayoutSize(WebSize(fixedLayoutWidth, fixedLayoutHeight)); 415 webViewHelper.webView()->settings()->setViewportEnabled(true);
422 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 416 webViewHelper.webView()->setFixedLayoutSize(WebSize(fixedLayoutWidth, fixedL ayoutHeight));
423 m_webView->layout(); 417 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
418 webViewHelper.webView()->layout();
424 419
425 EXPECT_EQ(fixedLayoutWidth, m_webView->fixedLayoutSize().width); 420 EXPECT_EQ(fixedLayoutWidth, webViewHelper.webView()->fixedLayoutSize().width );
426 EXPECT_EQ(fixedLayoutHeight, m_webView->fixedLayoutSize().height); 421 EXPECT_EQ(fixedLayoutHeight, webViewHelper.webView()->fixedLayoutSize().heig ht);
427 } 422 }
428 423
429 TEST_F(WebFrameTest, FixedLayoutSizePreventsResizeFromChangingPageScale) 424 TEST_F(WebFrameTest, FixedLayoutSizePreventsResizeFromChangingPageScale)
430 { 425 {
431 registerMockedHttpURLLoad("fixed_layout.html"); 426 registerMockedHttpURLLoad("fixed_layout.html");
432 427
433 int viewportWidth = 640; 428 int viewportWidth = 640;
434 int viewportHeight = 480; 429 int viewportHeight = 480;
435 430
436 int fixedLayoutWidth = viewportWidth / 2; 431 int fixedLayoutWidth = viewportWidth / 2;
437 int fixedLayoutHeight = viewportHeight / 2; 432 int fixedLayoutHeight = viewportHeight / 2;
438 433
439 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html"); 434 FrameTestHelpers::WebViewHelper webViewHelper;
440 m_webView->enableFixedLayoutMode(true); 435 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html");
441 m_webView->settings()->setViewportEnabled(true); 436 webViewHelper.webView()->enableFixedLayoutMode(true);
442 m_webView->setFixedLayoutSize(WebSize(fixedLayoutWidth, fixedLayoutHeight)); 437 webViewHelper.webView()->settings()->setViewportEnabled(true);
443 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 438 webViewHelper.webView()->setFixedLayoutSize(WebSize(fixedLayoutWidth, fixedL ayoutHeight));
444 m_webView->layout(); 439 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
445 float pageScaleFactor = m_webView->pageScaleFactor(); 440 webViewHelper.webView()->layout();
441 float pageScaleFactor = webViewHelper.webView()->pageScaleFactor();
446 442
447 m_webView->resize(WebSize(viewportWidth * 2, viewportHeight * 2)); 443 webViewHelper.webView()->resize(WebSize(viewportWidth * 2, viewportHeight * 2));
448 444
449 EXPECT_EQ(pageScaleFactor, m_webView->pageScaleFactor()); 445 EXPECT_EQ(pageScaleFactor, webViewHelper.webView()->pageScaleFactor());
450 } 446 }
451 447
452 TEST_F(WebFrameTest, FixedLayoutSizePreventsLayoutFromChangingPageScale) 448 TEST_F(WebFrameTest, FixedLayoutSizePreventsLayoutFromChangingPageScale)
453 { 449 {
454 registerMockedHttpURLLoad("fixed_layout.html"); 450 registerMockedHttpURLLoad("fixed_layout.html");
455 451
456 int viewportWidth = 640; 452 int viewportWidth = 640;
457 int viewportHeight = 480; 453 int viewportHeight = 480;
458 454
459 int fixedLayoutWidth = viewportWidth * 2; 455 int fixedLayoutWidth = viewportWidth * 2;
460 int fixedLayoutHeight = viewportHeight * 2; 456 int fixedLayoutHeight = viewportHeight * 2;
461 457
462 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html"); 458 FrameTestHelpers::WebViewHelper webViewHelper;
463 m_webView->enableFixedLayoutMode(true); 459 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html");
464 m_webView->settings()->setViewportEnabled(true); 460 webViewHelper.webView()->enableFixedLayoutMode(true);
465 m_webView->setFixedLayoutSize(WebSize(viewportWidth, viewportHeight)); 461 webViewHelper.webView()->settings()->setViewportEnabled(true);
466 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 462 webViewHelper.webView()->setFixedLayoutSize(WebSize(viewportWidth, viewportH eight));
467 m_webView->layout(); 463 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
468 float pageScaleFactor = m_webView->pageScaleFactor(); 464 webViewHelper.webView()->layout();
465 float pageScaleFactor = webViewHelper.webView()->pageScaleFactor();
469 466
470 m_webView->setFixedLayoutSize(WebSize(fixedLayoutWidth, fixedLayoutHeight)); 467 webViewHelper.webView()->setFixedLayoutSize(WebSize(fixedLayoutWidth, fixedL ayoutHeight));
471 m_webView->layout(); 468 webViewHelper.webView()->layout();
472 469
473 EXPECT_EQ(pageScaleFactor, m_webView->pageScaleFactor()); 470 EXPECT_EQ(pageScaleFactor, webViewHelper.webView()->pageScaleFactor());
474 } 471 }
475 472
476 TEST_F(WebFrameTest, PreferredSizeAndContentSizeReportedCorrectlyWithZeroHeightF ixedLayout) 473 TEST_F(WebFrameTest, PreferredSizeAndContentSizeReportedCorrectlyWithZeroHeightF ixedLayout)
477 { 474 {
478 registerMockedHttpURLLoad("200-by-300.html"); 475 registerMockedHttpURLLoad("200-by-300.html");
479 476
480 int windowWidth = 100; 477 int windowWidth = 100;
481 int windowHeight = 100; 478 int windowHeight = 100;
482 int viewportWidth = 100; 479 int viewportWidth = 100;
483 int viewportHeight = 0; 480 int viewportHeight = 0;
484 int divWidth = 200; 481 int divWidth = 200;
485 int divHeight = 300; 482 int divHeight = 300;
486 483
487 FixedLayoutTestWebViewClient client; 484 FixedLayoutTestWebViewClient client;
488 client.m_screenInfo.deviceScaleFactor = 1; 485 client.m_screenInfo.deviceScaleFactor = 1;
489 486
490 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "200-by-300.h tml", true, 0, &client); 487 FrameTestHelpers::WebViewHelper webViewHelper;
491 m_webView->enableFixedLayoutMode(true); 488 webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html", true, 0, &cli ent);
492 m_webView->settings()->setViewportEnabled(true); 489 webViewHelper.webView()->enableFixedLayoutMode(true);
493 m_webView->resize(WebSize(windowWidth, windowHeight)); 490 webViewHelper.webView()->settings()->setViewportEnabled(true);
494 m_webView->setFixedLayoutSize(WebSize(viewportWidth, viewportHeight)); 491 webViewHelper.webView()->resize(WebSize(windowWidth, windowHeight));
495 m_webView->layout(); 492 webViewHelper.webView()->setFixedLayoutSize(WebSize(viewportWidth, viewportH eight));
493 webViewHelper.webView()->layout();
496 494
497 EXPECT_EQ(divWidth, m_webView->mainFrame()->contentsSize().width); 495 EXPECT_EQ(divWidth, webViewHelper.webView()->mainFrame()->contentsSize().wid th);
498 EXPECT_EQ(divHeight, m_webView->mainFrame()->contentsSize().height); 496 EXPECT_EQ(divHeight, webViewHelper.webView()->mainFrame()->contentsSize().he ight);
499 497
500 EXPECT_EQ(divWidth, m_webView->contentsPreferredMinimumSize().width); 498 EXPECT_EQ(divWidth, webViewHelper.webView()->contentsPreferredMinimumSize(). width);
501 EXPECT_EQ(divHeight, m_webView->contentsPreferredMinimumSize().height); 499 EXPECT_EQ(divHeight, webViewHelper.webView()->contentsPreferredMinimumSize() .height);
502 } 500 }
503 501
504 TEST_F(WebFrameTest, DisablingFixedLayoutSizeSetsCorrectLayoutSize) 502 TEST_F(WebFrameTest, DisablingFixedLayoutSizeSetsCorrectLayoutSize)
505 { 503 {
506 registerMockedHttpURLLoad("no_viewport_tag.html"); 504 registerMockedHttpURLLoad("no_viewport_tag.html");
507 505
508 FixedLayoutTestWebViewClient client; 506 FixedLayoutTestWebViewClient client;
509 client.m_screenInfo.deviceScaleFactor = 1; 507 client.m_screenInfo.deviceScaleFactor = 1;
510 int viewportWidth = 640; 508 int viewportWidth = 640;
511 int viewportHeight = 480; 509 int viewportHeight = 480;
512 510
513 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "no_viewport_ tag.html", true, 0, &client); 511 FrameTestHelpers::WebViewHelper webViewHelper;
514 m_webView->settings()->setSupportDeprecatedTargetDensityDPI(true); 512 webViewHelper.initializeAndLoad(m_baseURL + "no_viewport_tag.html", true, 0, &client);
515 m_webView->enableFixedLayoutMode(true); 513 webViewHelper.webView()->settings()->setSupportDeprecatedTargetDensityDPI(tr ue);
516 m_webView->settings()->setUseWideViewport(true); 514 webViewHelper.webView()->enableFixedLayoutMode(true);
517 m_webView->settings()->setViewportEnabled(true); 515 webViewHelper.webView()->settings()->setUseWideViewport(true);
518 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 516 webViewHelper.webView()->settings()->setViewportEnabled(true);
517 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
519 518
520 m_webView->setFixedLayoutSize(WebSize(viewportWidth, viewportHeight)); 519 webViewHelper.webView()->setFixedLayoutSize(WebSize(viewportWidth, viewportH eight));
521 EXPECT_TRUE(webViewImpl()->mainFrameImpl()->frameView()->needsLayout()); 520 EXPECT_TRUE(webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->needs Layout());
522 m_webView->layout(); 521 webViewHelper.webView()->layout();
523 EXPECT_EQ(viewportWidth, webViewImpl()->mainFrameImpl()->frameView()->conten tsSize().width()); 522 EXPECT_EQ(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frame View()->contentsSize().width());
524 523
525 m_webView->setFixedLayoutSize(WebSize(0, 0)); 524 webViewHelper.webView()->setFixedLayoutSize(WebSize(0, 0));
526 EXPECT_TRUE(webViewImpl()->mainFrameImpl()->frameView()->needsLayout()); 525 EXPECT_TRUE(webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->needs Layout());
527 m_webView->layout(); 526 webViewHelper.webView()->layout();
528 EXPECT_EQ(980, webViewImpl()->mainFrameImpl()->frameView()->contentsSize().w idth()); 527 EXPECT_EQ(980, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->co ntentsSize().width());
529 } 528 }
530 529
531 TEST_F(WebFrameTest, DeviceScaleFactorUsesDefaultWithoutViewportTag) 530 TEST_F(WebFrameTest, DeviceScaleFactorUsesDefaultWithoutViewportTag)
532 { 531 {
533 registerMockedHttpURLLoad("no_viewport_tag.html"); 532 registerMockedHttpURLLoad("no_viewport_tag.html");
534 533
535 int viewportWidth = 640; 534 int viewportWidth = 640;
536 int viewportHeight = 480; 535 int viewportHeight = 480;
537 536
538 FixedLayoutTestWebViewClient client; 537 FixedLayoutTestWebViewClient client;
539 client.m_screenInfo.deviceScaleFactor = 2; 538 client.m_screenInfo.deviceScaleFactor = 2;
540 539
541 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "no_viewport_ tag.html", true, 0, &client); 540 FrameTestHelpers::WebViewHelper webViewHelper;
541 webViewHelper.initializeAndLoad(m_baseURL + "no_viewport_tag.html", true, 0, &client);
542 542
543 m_webView->settings()->setViewportEnabled(true); 543 webViewHelper.webView()->settings()->setViewportEnabled(true);
544 m_webView->enableFixedLayoutMode(true); 544 webViewHelper.webView()->enableFixedLayoutMode(true);
545 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 545 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
546 m_webView->layout(); 546 webViewHelper.webView()->layout();
547 547
548 EXPECT_EQ(2, m_webView->deviceScaleFactor()); 548 EXPECT_EQ(2, webViewHelper.webView()->deviceScaleFactor());
549 549
550 // Device scale factor should be independent of page scale. 550 // Device scale factor should be independent of page scale.
551 m_webView->setPageScaleFactorLimits(1, 2); 551 webViewHelper.webView()->setPageScaleFactorLimits(1, 2);
552 m_webView->setPageScaleFactorPreservingScrollOffset(0.5); 552 webViewHelper.webView()->setPageScaleFactorPreservingScrollOffset(0.5);
553 m_webView->layout(); 553 webViewHelper.webView()->layout();
554 EXPECT_EQ(1, m_webView->pageScaleFactor()); 554 EXPECT_EQ(1, webViewHelper.webView()->pageScaleFactor());
555 555
556 // Force the layout to happen before leaving the test. 556 // Force the layout to happen before leaving the test.
557 m_webView->mainFrame()->contentAsText(1024).utf8(); 557 webViewHelper.webView()->mainFrame()->contentAsText(1024).utf8();
558 } 558 }
559 559
560 TEST_F(WebFrameTest, FixedLayoutInitializeAtMinimumScale) 560 TEST_F(WebFrameTest, FixedLayoutInitializeAtMinimumScale)
561 { 561 {
562 UseMockScrollbarSettings mockScrollbarSettings; 562 UseMockScrollbarSettings mockScrollbarSettings;
563 563
564 registerMockedHttpURLLoad("fixed_layout.html"); 564 registerMockedHttpURLLoad("fixed_layout.html");
565 565
566 FixedLayoutTestWebViewClient client; 566 FixedLayoutTestWebViewClient client;
567 client.m_screenInfo.deviceScaleFactor = 1; 567 client.m_screenInfo.deviceScaleFactor = 1;
568 int viewportWidth = 640; 568 int viewportWidth = 640;
569 int viewportHeight = 480; 569 int viewportHeight = 480;
570 570
571 // Make sure we initialize to minimum scale, even if the window size 571 // Make sure we initialize to minimum scale, even if the window size
572 // only becomes available after the load begins. 572 // only becomes available after the load begins.
573 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html", true, 0, &client); 573 FrameTestHelpers::WebViewHelper webViewHelper;
574 m_webView->enableFixedLayoutMode(true); 574 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c lient);
575 m_webView->settings()->setViewportEnabled(true); 575 webViewHelper.webView()->enableFixedLayoutMode(true);
576 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 576 webViewHelper.webView()->settings()->setViewportEnabled(true);
577 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
577 578
578 int defaultFixedLayoutWidth = 980; 579 int defaultFixedLayoutWidth = 980;
579 float minimumPageScaleFactor = viewportWidth / (float) defaultFixedLayoutWid th; 580 float minimumPageScaleFactor = viewportWidth / (float) defaultFixedLayoutWid th;
580 EXPECT_EQ(minimumPageScaleFactor, m_webView->pageScaleFactor()); 581 EXPECT_EQ(minimumPageScaleFactor, webViewHelper.webView()->pageScaleFactor() );
581 EXPECT_EQ(minimumPageScaleFactor, m_webView->minimumPageScaleFactor()); 582 EXPECT_EQ(minimumPageScaleFactor, webViewHelper.webView()->minimumPageScaleF actor());
582 583
583 // Assume the user has pinch zoomed to page scale factor 2. 584 // Assume the user has pinch zoomed to page scale factor 2.
584 float userPinchPageScaleFactor = 2; 585 float userPinchPageScaleFactor = 2;
585 m_webView->setPageScaleFactorPreservingScrollOffset(userPinchPageScaleFactor ); 586 webViewHelper.webView()->setPageScaleFactorPreservingScrollOffset(userPinchP ageScaleFactor);
586 m_webView->layout(); 587 webViewHelper.webView()->layout();
587 588
588 // Make sure we don't reset to initial scale if the page continues to load. 589 // Make sure we don't reset to initial scale if the page continues to load.
589 bool isNewNavigation; 590 bool isNewNavigation;
590 webViewImpl()->didCommitLoad(&isNewNavigation, false); 591 webViewHelper.webViewImpl()->didCommitLoad(&isNewNavigation, false);
591 webViewImpl()->didChangeContentsSize(); 592 webViewHelper.webViewImpl()->didChangeContentsSize();
592 EXPECT_EQ(userPinchPageScaleFactor, m_webView->pageScaleFactor()); 593 EXPECT_EQ(userPinchPageScaleFactor, webViewHelper.webView()->pageScaleFactor ());
593 594
594 // Make sure we don't reset to initial scale if the viewport size changes. 595 // Make sure we don't reset to initial scale if the viewport size changes.
595 m_webView->resize(WebSize(viewportWidth, viewportHeight + 100)); 596 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight + 100) );
596 EXPECT_EQ(userPinchPageScaleFactor, m_webView->pageScaleFactor()); 597 EXPECT_EQ(userPinchPageScaleFactor, webViewHelper.webView()->pageScaleFactor ());
597 } 598 }
598 599
599 TEST_F(WebFrameTest, WideDocumentInitializeAtMinimumScale) 600 TEST_F(WebFrameTest, WideDocumentInitializeAtMinimumScale)
600 { 601 {
601 UseMockScrollbarSettings mockScrollbarSettings; 602 UseMockScrollbarSettings mockScrollbarSettings;
602 603
603 registerMockedHttpURLLoad("wide_document.html"); 604 registerMockedHttpURLLoad("wide_document.html");
604 605
605 FixedLayoutTestWebViewClient client; 606 FixedLayoutTestWebViewClient client;
606 client.m_screenInfo.deviceScaleFactor = 1; 607 client.m_screenInfo.deviceScaleFactor = 1;
607 int viewportWidth = 640; 608 int viewportWidth = 640;
608 int viewportHeight = 480; 609 int viewportHeight = 480;
609 610
610 // Make sure we initialize to minimum scale, even if the window size 611 // Make sure we initialize to minimum scale, even if the window size
611 // only becomes available after the load begins. 612 // only becomes available after the load begins.
612 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "wide_documen t.html", true, 0, &client); 613 FrameTestHelpers::WebViewHelper webViewHelper;
613 m_webView->enableFixedLayoutMode(true); 614 webViewHelper.initializeAndLoad(m_baseURL + "wide_document.html", true, 0, & client);
614 m_webView->settings()->setViewportEnabled(true); 615 webViewHelper.webView()->enableFixedLayoutMode(true);
615 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 616 webViewHelper.webView()->settings()->setViewportEnabled(true);
617 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
616 618
617 int wideDocumentWidth = 1500; 619 int wideDocumentWidth = 1500;
618 float minimumPageScaleFactor = viewportWidth / (float) wideDocumentWidth; 620 float minimumPageScaleFactor = viewportWidth / (float) wideDocumentWidth;
619 EXPECT_EQ(minimumPageScaleFactor, m_webView->pageScaleFactor()); 621 EXPECT_EQ(minimumPageScaleFactor, webViewHelper.webView()->pageScaleFactor() );
620 EXPECT_EQ(minimumPageScaleFactor, m_webView->minimumPageScaleFactor()); 622 EXPECT_EQ(minimumPageScaleFactor, webViewHelper.webView()->minimumPageScaleF actor());
621 623
622 // Assume the user has pinch zoomed to page scale factor 2. 624 // Assume the user has pinch zoomed to page scale factor 2.
623 float userPinchPageScaleFactor = 2; 625 float userPinchPageScaleFactor = 2;
624 m_webView->setPageScaleFactorPreservingScrollOffset(userPinchPageScaleFactor ); 626 webViewHelper.webView()->setPageScaleFactorPreservingScrollOffset(userPinchP ageScaleFactor);
625 m_webView->layout(); 627 webViewHelper.webView()->layout();
626 628
627 // Make sure we don't reset to initial scale if the page continues to load. 629 // Make sure we don't reset to initial scale if the page continues to load.
628 bool isNewNavigation; 630 bool isNewNavigation;
629 webViewImpl()->didCommitLoad(&isNewNavigation, false); 631 webViewHelper.webViewImpl()->didCommitLoad(&isNewNavigation, false);
630 webViewImpl()->didChangeContentsSize(); 632 webViewHelper.webViewImpl()->didChangeContentsSize();
631 EXPECT_EQ(userPinchPageScaleFactor, m_webView->pageScaleFactor()); 633 EXPECT_EQ(userPinchPageScaleFactor, webViewHelper.webView()->pageScaleFactor ());
632 634
633 // Make sure we don't reset to initial scale if the viewport size changes. 635 // Make sure we don't reset to initial scale if the viewport size changes.
634 m_webView->resize(WebSize(viewportWidth, viewportHeight + 100)); 636 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight + 100) );
635 EXPECT_EQ(userPinchPageScaleFactor, m_webView->pageScaleFactor()); 637 EXPECT_EQ(userPinchPageScaleFactor, webViewHelper.webView()->pageScaleFactor ());
636 } 638 }
637 639
638 TEST_F(WebFrameTest, setLoadWithOverviewModeToFalse) 640 TEST_F(WebFrameTest, setLoadWithOverviewModeToFalse)
639 { 641 {
640 registerMockedHttpURLLoad("viewport-auto-initial-scale.html"); 642 registerMockedHttpURLLoad("viewport-auto-initial-scale.html");
641 643
642 FixedLayoutTestWebViewClient client; 644 FixedLayoutTestWebViewClient client;
643 client.m_screenInfo.deviceScaleFactor = 1; 645 client.m_screenInfo.deviceScaleFactor = 1;
644 int viewportWidth = 640; 646 int viewportWidth = 640;
645 int viewportHeight = 480; 647 int viewportHeight = 480;
646 648
647 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-aut o-initial-scale.html", true, 0, &client); 649 FrameTestHelpers::WebViewHelper webViewHelper;
648 m_webView->enableFixedLayoutMode(true); 650 webViewHelper.initializeAndLoad(m_baseURL + "viewport-auto-initial-scale.htm l", true, 0, &client);
649 m_webView->settings()->setViewportEnabled(true); 651 webViewHelper.webView()->enableFixedLayoutMode(true);
650 m_webView->settings()->setWideViewportQuirkEnabled(true); 652 webViewHelper.webView()->settings()->setViewportEnabled(true);
651 m_webView->settings()->setLoadWithOverviewMode(false); 653 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
652 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 654 webViewHelper.webView()->settings()->setLoadWithOverviewMode(false);
655 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
653 656
654 // The page must be displayed at 100% zoom. 657 // The page must be displayed at 100% zoom.
655 EXPECT_EQ(1.0f, m_webView->pageScaleFactor()); 658 EXPECT_EQ(1.0f, webViewHelper.webView()->pageScaleFactor());
656 } 659 }
657 660
658 TEST_F(WebFrameTest, SetLoadWithOverviewModeToFalseAndNoWideViewport) 661 TEST_F(WebFrameTest, SetLoadWithOverviewModeToFalseAndNoWideViewport)
659 { 662 {
660 registerMockedHttpURLLoad("large-div.html"); 663 registerMockedHttpURLLoad("large-div.html");
661 664
662 FixedLayoutTestWebViewClient client; 665 FixedLayoutTestWebViewClient client;
663 client.m_screenInfo.deviceScaleFactor = 1; 666 client.m_screenInfo.deviceScaleFactor = 1;
664 int viewportWidth = 640; 667 int viewportWidth = 640;
665 int viewportHeight = 480; 668 int viewportHeight = 480;
666 669
667 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "large-div.ht ml", true, 0, &client); 670 FrameTestHelpers::WebViewHelper webViewHelper;
668 m_webView->enableFixedLayoutMode(true); 671 webViewHelper.initializeAndLoad(m_baseURL + "large-div.html", true, 0, &clie nt);
669 m_webView->settings()->setViewportEnabled(true); 672 webViewHelper.webView()->enableFixedLayoutMode(true);
670 m_webView->settings()->setLoadWithOverviewMode(false); 673 webViewHelper.webView()->settings()->setViewportEnabled(true);
671 m_webView->settings()->setWideViewportQuirkEnabled(true); 674 webViewHelper.webView()->settings()->setLoadWithOverviewMode(false);
672 m_webView->settings()->setUseWideViewport(false); 675 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
673 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 676 webViewHelper.webView()->settings()->setUseWideViewport(false);
677 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
674 678
675 // The page must be displayed at 100% zoom, despite that it hosts a wide div element. 679 // The page must be displayed at 100% zoom, despite that it hosts a wide div element.
676 EXPECT_EQ(1.0f, m_webView->pageScaleFactor()); 680 EXPECT_EQ(1.0f, webViewHelper.webView()->pageScaleFactor());
677 } 681 }
678 682
679 TEST_F(WebFrameTest, NoWideViewportIgnoresPageViewportWidth) 683 TEST_F(WebFrameTest, NoWideViewportIgnoresPageViewportWidth)
680 { 684 {
681 registerMockedHttpURLLoad("viewport-auto-initial-scale.html"); 685 registerMockedHttpURLLoad("viewport-auto-initial-scale.html");
682 686
683 FixedLayoutTestWebViewClient client; 687 FixedLayoutTestWebViewClient client;
684 client.m_screenInfo.deviceScaleFactor = 1; 688 client.m_screenInfo.deviceScaleFactor = 1;
685 int viewportWidth = 640; 689 int viewportWidth = 640;
686 int viewportHeight = 480; 690 int viewportHeight = 480;
687 691
688 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-aut o-initial-scale.html", true, 0, &client); 692 FrameTestHelpers::WebViewHelper webViewHelper;
689 m_webView->enableFixedLayoutMode(true); 693 webViewHelper.initializeAndLoad(m_baseURL + "viewport-auto-initial-scale.htm l", true, 0, &client);
690 m_webView->settings()->setViewportEnabled(true); 694 webViewHelper.webView()->enableFixedLayoutMode(true);
691 m_webView->settings()->setWideViewportQuirkEnabled(true); 695 webViewHelper.webView()->settings()->setViewportEnabled(true);
692 m_webView->settings()->setUseWideViewport(false); 696 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
693 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 697 webViewHelper.webView()->settings()->setUseWideViewport(false);
698 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
694 699
695 // The page sets viewport width to 3000, but with UseWideViewport == false i s must be ignored. 700 // The page sets viewport width to 3000, but with UseWideViewport == false i s must be ignored.
696 EXPECT_EQ(viewportWidth, webViewImpl()->mainFrameImpl()->frameView()->conten tsSize().width()); 701 EXPECT_EQ(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frame View()->contentsSize().width());
697 EXPECT_EQ(viewportHeight, webViewImpl()->mainFrameImpl()->frameView()->conte ntsSize().height()); 702 EXPECT_EQ(viewportHeight, webViewHelper.webViewImpl()->mainFrameImpl()->fram eView()->contentsSize().height());
698 } 703 }
699 704
700 TEST_F(WebFrameTest, NoWideViewportIgnoresPageViewportWidthButAccountsScale) 705 TEST_F(WebFrameTest, NoWideViewportIgnoresPageViewportWidthButAccountsScale)
701 { 706 {
702 registerMockedHttpURLLoad("viewport-wide-2x-initial-scale.html"); 707 registerMockedHttpURLLoad("viewport-wide-2x-initial-scale.html");
703 708
704 FixedLayoutTestWebViewClient client; 709 FixedLayoutTestWebViewClient client;
705 client.m_screenInfo.deviceScaleFactor = 1; 710 client.m_screenInfo.deviceScaleFactor = 1;
706 int viewportWidth = 640; 711 int viewportWidth = 640;
707 int viewportHeight = 480; 712 int viewportHeight = 480;
708 713
709 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-wid e-2x-initial-scale.html", true, 0, &client); 714 FrameTestHelpers::WebViewHelper webViewHelper;
710 m_webView->enableFixedLayoutMode(true); 715 webViewHelper.initializeAndLoad(m_baseURL + "viewport-wide-2x-initial-scale. html", true, 0, &client);
711 m_webView->settings()->setViewportEnabled(true); 716 webViewHelper.webView()->enableFixedLayoutMode(true);
712 m_webView->settings()->setWideViewportQuirkEnabled(true); 717 webViewHelper.webView()->settings()->setViewportEnabled(true);
713 m_webView->settings()->setUseWideViewport(false); 718 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
714 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 719 webViewHelper.webView()->settings()->setUseWideViewport(false);
720 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
715 721
716 // The page sets viewport width to 3000, but with UseWideViewport == false i s must be ignored. 722 // The page sets viewport width to 3000, but with UseWideViewport == false i s must be ignored.
717 // While the initial scale specified by the page must be accounted. 723 // While the initial scale specified by the page must be accounted.
718 EXPECT_EQ(viewportWidth / 2, webViewImpl()->mainFrameImpl()->frameView()->co ntentsSize().width()); 724 EXPECT_EQ(viewportWidth / 2, webViewHelper.webViewImpl()->mainFrameImpl()->f rameView()->contentsSize().width());
719 EXPECT_EQ(viewportHeight / 2, webViewImpl()->mainFrameImpl()->frameView()->c ontentsSize().height()); 725 EXPECT_EQ(viewportHeight / 2, webViewHelper.webViewImpl()->mainFrameImpl()-> frameView()->contentsSize().height());
720 } 726 }
721 727
722 TEST_F(WebFrameTest, WideViewportSetsTo980WithoutViewportTag) 728 TEST_F(WebFrameTest, WideViewportSetsTo980WithoutViewportTag)
723 { 729 {
724 registerMockedHttpURLLoad("no_viewport_tag.html"); 730 registerMockedHttpURLLoad("no_viewport_tag.html");
725 731
726 FixedLayoutTestWebViewClient client; 732 FixedLayoutTestWebViewClient client;
727 client.m_screenInfo.deviceScaleFactor = 1; 733 client.m_screenInfo.deviceScaleFactor = 1;
728 int viewportWidth = 640; 734 int viewportWidth = 640;
729 int viewportHeight = 480; 735 int viewportHeight = 480;
730 736
731 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "no_viewport_ tag.html", true, 0, &client); 737 FrameTestHelpers::WebViewHelper webViewHelper;
732 m_webView->enableFixedLayoutMode(true); 738 webViewHelper.initializeAndLoad(m_baseURL + "no_viewport_tag.html", true, 0, &client);
733 m_webView->settings()->setWideViewportQuirkEnabled(true); 739 webViewHelper.webView()->enableFixedLayoutMode(true);
734 m_webView->settings()->setUseWideViewport(true); 740 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
735 m_webView->settings()->setViewportEnabled(true); 741 webViewHelper.webView()->settings()->setUseWideViewport(true);
736 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 742 webViewHelper.webView()->settings()->setViewportEnabled(true);
743 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
737 744
738 EXPECT_EQ(980, webViewImpl()->mainFrameImpl()->frameView()->contentsSize().w idth()); 745 EXPECT_EQ(980, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->co ntentsSize().width());
739 EXPECT_EQ(980.0 / viewportWidth * viewportHeight, webViewImpl()->mainFrameIm pl()->frameView()->contentsSize().height()); 746 EXPECT_EQ(980.0 / viewportWidth * viewportHeight, webViewHelper.webViewImpl( )->mainFrameImpl()->frameView()->contentsSize().height());
740 } 747 }
741 748
742 TEST_F(WebFrameTest, NoWideViewportAndHeightInMeta) 749 TEST_F(WebFrameTest, NoWideViewportAndHeightInMeta)
743 { 750 {
744 registerMockedHttpURLLoad("viewport-height-1000.html"); 751 registerMockedHttpURLLoad("viewport-height-1000.html");
745 752
746 FixedLayoutTestWebViewClient client; 753 FixedLayoutTestWebViewClient client;
747 client.m_screenInfo.deviceScaleFactor = 1; 754 client.m_screenInfo.deviceScaleFactor = 1;
748 int viewportWidth = 640; 755 int viewportWidth = 640;
749 int viewportHeight = 480; 756 int viewportHeight = 480;
750 757
751 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-hei ght-1000.html", true, 0, &client); 758 FrameTestHelpers::WebViewHelper webViewHelper;
752 m_webView->enableFixedLayoutMode(true); 759 webViewHelper.initializeAndLoad(m_baseURL + "viewport-height-1000.html", tru e, 0, &client);
753 m_webView->settings()->setWideViewportQuirkEnabled(true); 760 webViewHelper.webView()->enableFixedLayoutMode(true);
754 m_webView->settings()->setUseWideViewport(false); 761 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
755 m_webView->settings()->setViewportEnabled(true); 762 webViewHelper.webView()->settings()->setUseWideViewport(false);
756 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 763 webViewHelper.webView()->settings()->setViewportEnabled(true);
764 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
757 765
758 EXPECT_EQ(viewportWidth, webViewImpl()->mainFrameImpl()->frameView()->conten tsSize().width()); 766 EXPECT_EQ(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frame View()->contentsSize().width());
759 } 767 }
760 768
761 TEST_F(WebFrameTest, WideViewportSetsTo980WithAutoWidth) 769 TEST_F(WebFrameTest, WideViewportSetsTo980WithAutoWidth)
762 { 770 {
763 registerMockedHttpURLLoad("viewport-2x-initial-scale.html"); 771 registerMockedHttpURLLoad("viewport-2x-initial-scale.html");
764 772
765 FixedLayoutTestWebViewClient client; 773 FixedLayoutTestWebViewClient client;
766 client.m_screenInfo.deviceScaleFactor = 1; 774 client.m_screenInfo.deviceScaleFactor = 1;
767 int viewportWidth = 640; 775 int viewportWidth = 640;
768 int viewportHeight = 480; 776 int viewportHeight = 480;
769 777
770 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-2x- initial-scale.html", true, 0, &client); 778 FrameTestHelpers::WebViewHelper webViewHelper;
771 m_webView->enableFixedLayoutMode(true); 779 webViewHelper.initializeAndLoad(m_baseURL + "viewport-2x-initial-scale.html" , true, 0, &client);
772 m_webView->settings()->setWideViewportQuirkEnabled(true); 780 webViewHelper.webView()->enableFixedLayoutMode(true);
773 m_webView->settings()->setUseWideViewport(true); 781 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
774 m_webView->settings()->setViewportEnabled(true); 782 webViewHelper.webView()->settings()->setUseWideViewport(true);
775 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 783 webViewHelper.webView()->settings()->setViewportEnabled(true);
784 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
776 785
777 EXPECT_EQ(980, webViewImpl()->mainFrameImpl()->frameView()->contentsSize().w idth()); 786 EXPECT_EQ(980, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->co ntentsSize().width());
778 EXPECT_EQ(980.0 / viewportWidth * viewportHeight, webViewImpl()->mainFrameIm pl()->frameView()->contentsSize().height()); 787 EXPECT_EQ(980.0 / viewportWidth * viewportHeight, webViewHelper.webViewImpl( )->mainFrameImpl()->frameView()->contentsSize().height());
779 } 788 }
780 789
781 TEST_F(WebFrameTest, PageViewportInitialScaleOverridesLoadWithOverviewMode) 790 TEST_F(WebFrameTest, PageViewportInitialScaleOverridesLoadWithOverviewMode)
782 { 791 {
783 registerMockedHttpURLLoad("viewport-wide-2x-initial-scale.html"); 792 registerMockedHttpURLLoad("viewport-wide-2x-initial-scale.html");
784 793
785 FixedLayoutTestWebViewClient client; 794 FixedLayoutTestWebViewClient client;
786 client.m_screenInfo.deviceScaleFactor = 1; 795 client.m_screenInfo.deviceScaleFactor = 1;
787 int viewportWidth = 640; 796 int viewportWidth = 640;
788 int viewportHeight = 480; 797 int viewportHeight = 480;
789 798
790 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-wid e-2x-initial-scale.html", true, 0, &client); 799 FrameTestHelpers::WebViewHelper webViewHelper;
791 m_webView->enableFixedLayoutMode(true); 800 webViewHelper.initializeAndLoad(m_baseURL + "viewport-wide-2x-initial-scale. html", true, 0, &client);
792 m_webView->settings()->setViewportEnabled(true); 801 webViewHelper.webView()->enableFixedLayoutMode(true);
793 m_webView->settings()->setLoadWithOverviewMode(false); 802 webViewHelper.webView()->settings()->setViewportEnabled(true);
794 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 803 webViewHelper.webView()->settings()->setLoadWithOverviewMode(false);
804 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
795 805
796 // The page must be displayed at 200% zoom, as specified in its viewport met a tag. 806 // The page must be displayed at 200% zoom, as specified in its viewport met a tag.
797 EXPECT_EQ(2.0f, m_webView->pageScaleFactor()); 807 EXPECT_EQ(2.0f, webViewHelper.webView()->pageScaleFactor());
798 } 808 }
799 809
800 TEST_F(WebFrameTest, setInitialPageScaleFactorPermanently) 810 TEST_F(WebFrameTest, setInitialPageScaleFactorPermanently)
801 { 811 {
802 UseMockScrollbarSettings mockScrollbarSettings; 812 UseMockScrollbarSettings mockScrollbarSettings;
803 813
804 registerMockedHttpURLLoad("fixed_layout.html"); 814 registerMockedHttpURLLoad("fixed_layout.html");
805 815
806 FixedLayoutTestWebViewClient client; 816 FixedLayoutTestWebViewClient client;
807 client.m_screenInfo.deviceScaleFactor = 1; 817 client.m_screenInfo.deviceScaleFactor = 1;
808 float enforcedPageScaleFactor = 2.0f; 818 float enforcedPageScaleFactor = 2.0f;
809 819
810 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html", true, 0, &client); 820 FrameTestHelpers::WebViewHelper webViewHelper;
811 m_webView->settings()->setWideViewportQuirkEnabled(true); 821 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c lient);
812 m_webView->settings()->setLoadWithOverviewMode(false); 822 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
813 m_webView->setInitialPageScaleOverride(enforcedPageScaleFactor); 823 webViewHelper.webView()->settings()->setLoadWithOverviewMode(false);
814 m_webView->enableFixedLayoutMode(true); 824 webViewHelper.webView()->setInitialPageScaleOverride(enforcedPageScaleFactor );
815 m_webView->settings()->setViewportEnabled(true); 825 webViewHelper.webView()->enableFixedLayoutMode(true);
816 m_webView->layout(); 826 webViewHelper.webView()->settings()->setViewportEnabled(true);
827 webViewHelper.webView()->layout();
817 828
818 EXPECT_EQ(enforcedPageScaleFactor, m_webView->pageScaleFactor()); 829 EXPECT_EQ(enforcedPageScaleFactor, webViewHelper.webView()->pageScaleFactor( ));
819 830
820 int viewportWidth = 640; 831 int viewportWidth = 640;
821 int viewportHeight = 480; 832 int viewportHeight = 480;
822 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 833 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
823 m_webView->layout(); 834 webViewHelper.webView()->layout();
824 835
825 EXPECT_EQ(enforcedPageScaleFactor, m_webView->pageScaleFactor()); 836 EXPECT_EQ(enforcedPageScaleFactor, webViewHelper.webView()->pageScaleFactor( ));
826 837
827 m_webView->setInitialPageScaleOverride(-1); 838 webViewHelper.webView()->setInitialPageScaleOverride(-1);
828 m_webView->layout(); 839 webViewHelper.webView()->layout();
829 EXPECT_EQ(1.0, m_webView->pageScaleFactor()); 840 EXPECT_EQ(1.0, webViewHelper.webView()->pageScaleFactor());
830 } 841 }
831 842
832 TEST_F(WebFrameTest, PermanentInitialPageScaleFactorOverridesLoadWithOverviewMod e) 843 TEST_F(WebFrameTest, PermanentInitialPageScaleFactorOverridesLoadWithOverviewMod e)
833 { 844 {
834 registerMockedHttpURLLoad("viewport-auto-initial-scale.html"); 845 registerMockedHttpURLLoad("viewport-auto-initial-scale.html");
835 846
836 FixedLayoutTestWebViewClient client; 847 FixedLayoutTestWebViewClient client;
837 client.m_screenInfo.deviceScaleFactor = 1; 848 client.m_screenInfo.deviceScaleFactor = 1;
838 int viewportWidth = 640; 849 int viewportWidth = 640;
839 int viewportHeight = 480; 850 int viewportHeight = 480;
840 float enforcedPageScalePactor = 0.5f; 851 float enforcedPageScalePactor = 0.5f;
841 852
842 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-aut o-initial-scale.html", true, 0, &client); 853 FrameTestHelpers::WebViewHelper webViewHelper;
843 m_webView->enableFixedLayoutMode(true); 854 webViewHelper.initializeAndLoad(m_baseURL + "viewport-auto-initial-scale.htm l", true, 0, &client);
844 m_webView->settings()->setViewportEnabled(true); 855 webViewHelper.webView()->enableFixedLayoutMode(true);
845 m_webView->settings()->setLoadWithOverviewMode(false); 856 webViewHelper.webView()->settings()->setViewportEnabled(true);
846 m_webView->setInitialPageScaleOverride(enforcedPageScalePactor); 857 webViewHelper.webView()->settings()->setLoadWithOverviewMode(false);
847 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 858 webViewHelper.webView()->setInitialPageScaleOverride(enforcedPageScalePactor );
859 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
848 860
849 EXPECT_EQ(enforcedPageScalePactor, m_webView->pageScaleFactor()); 861 EXPECT_EQ(enforcedPageScalePactor, webViewHelper.webView()->pageScaleFactor( ));
850 } 862 }
851 863
852 TEST_F(WebFrameTest, PermanentInitialPageScaleFactorOverridesPageViewportInitial Scale) 864 TEST_F(WebFrameTest, PermanentInitialPageScaleFactorOverridesPageViewportInitial Scale)
853 { 865 {
854 registerMockedHttpURLLoad("viewport-wide-2x-initial-scale.html"); 866 registerMockedHttpURLLoad("viewport-wide-2x-initial-scale.html");
855 867
856 FixedLayoutTestWebViewClient client; 868 FixedLayoutTestWebViewClient client;
857 client.m_screenInfo.deviceScaleFactor = 1; 869 client.m_screenInfo.deviceScaleFactor = 1;
858 int viewportWidth = 640; 870 int viewportWidth = 640;
859 int viewportHeight = 480; 871 int viewportHeight = 480;
860 float enforcedPageScalePactor = 0.5f; 872 float enforcedPageScalePactor = 0.5f;
861 873
862 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-wid e-2x-initial-scale.html", true, 0, &client); 874 FrameTestHelpers::WebViewHelper webViewHelper;
863 m_webView->enableFixedLayoutMode(true); 875 webViewHelper.initializeAndLoad(m_baseURL + "viewport-wide-2x-initial-scale. html", true, 0, &client);
864 m_webView->settings()->setViewportEnabled(true); 876 webViewHelper.webView()->enableFixedLayoutMode(true);
865 m_webView->setInitialPageScaleOverride(enforcedPageScalePactor); 877 webViewHelper.webView()->settings()->setViewportEnabled(true);
866 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 878 webViewHelper.webView()->setInitialPageScaleOverride(enforcedPageScalePactor );
879 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
867 880
868 EXPECT_EQ(enforcedPageScalePactor, m_webView->pageScaleFactor()); 881 EXPECT_EQ(enforcedPageScalePactor, webViewHelper.webView()->pageScaleFactor( ));
869 } 882 }
870 883
871 TEST_F(WebFrameTest, WideViewportInitialScaleDoesNotExpandFixedLayoutWidth) 884 TEST_F(WebFrameTest, WideViewportInitialScaleDoesNotExpandFixedLayoutWidth)
872 { 885 {
873 registerMockedHttpURLLoad("viewport-device-0.5x-initial-scale.html"); 886 registerMockedHttpURLLoad("viewport-device-0.5x-initial-scale.html");
874 887
875 FixedLayoutTestWebViewClient client; 888 FixedLayoutTestWebViewClient client;
876 client.m_screenInfo.deviceScaleFactor = 1; 889 client.m_screenInfo.deviceScaleFactor = 1;
877 int viewportWidth = 640; 890 int viewportWidth = 640;
878 int viewportHeight = 480; 891 int viewportHeight = 480;
879 892
880 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-dev ice-0.5x-initial-scale.html", true, 0, &client); 893 FrameTestHelpers::WebViewHelper webViewHelper;
881 m_webView->enableFixedLayoutMode(true); 894 webViewHelper.initializeAndLoad(m_baseURL + "viewport-device-0.5x-initial-sc ale.html", true, 0, &client);
882 m_webView->settings()->setViewportEnabled(true); 895 webViewHelper.webView()->enableFixedLayoutMode(true);
883 m_webView->settings()->setWideViewportQuirkEnabled(true); 896 webViewHelper.webView()->settings()->setViewportEnabled(true);
884 m_webView->settings()->setUseWideViewport(true); 897 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
885 m_webView->settings()->setViewportMetaLayoutSizeQuirk(true); 898 webViewHelper.webView()->settings()->setUseWideViewport(true);
886 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 899 webViewHelper.webView()->settings()->setViewportMetaLayoutSizeQuirk(true);
900 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
887 901
888 WebViewImpl* webViewImpl = toWebViewImpl(m_webView); 902 EXPECT_EQ(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frame View()->fixedLayoutSize().width());
889 EXPECT_EQ(viewportWidth, webViewImpl->mainFrameImpl()->frameView()->fixedLay outSize().width());
890 } 903 }
891 904
892 TEST_F(WebFrameTest, ZeroValuesQuirk) 905 TEST_F(WebFrameTest, ZeroValuesQuirk)
893 { 906 {
894 registerMockedHttpURLLoad("viewport-zero-values.html"); 907 registerMockedHttpURLLoad("viewport-zero-values.html");
895 908
896 FixedLayoutTestWebViewClient client; 909 FixedLayoutTestWebViewClient client;
897 client.m_screenInfo.deviceScaleFactor = 1; 910 client.m_screenInfo.deviceScaleFactor = 1;
898 int viewportWidth = 640; 911 int viewportWidth = 640;
899 int viewportHeight = 480; 912 int viewportHeight = 480;
900 913
901 m_webView = FrameTestHelpers::createWebView(true, 0, &client); 914 FrameTestHelpers::WebViewHelper webViewHelper;
902 m_webView->enableFixedLayoutMode(true); 915 webViewHelper.initialize(true, 0, &client);
903 m_webView->settings()->setViewportEnabled(true); 916 webViewHelper.webView()->enableFixedLayoutMode(true);
904 m_webView->settings()->setViewportMetaZeroValuesQuirk(true); 917 webViewHelper.webView()->settings()->setViewportEnabled(true);
905 m_webView->settings()->setWideViewportQuirkEnabled(true); 918 webViewHelper.webView()->settings()->setViewportMetaZeroValuesQuirk(true);
906 FrameTestHelpers::loadFrame(m_webView->mainFrame(), m_baseURL + "viewport-ze ro-values.html"); 919 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
920 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL + "viewport-zero-values.html");
907 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 921 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
908 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 922 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
909 923
910 WebViewImpl* webViewImpl = toWebViewImpl(m_webView); 924 EXPECT_EQ(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frame View()->fixedLayoutSize().width());
911 EXPECT_EQ(viewportWidth, webViewImpl->mainFrameImpl()->frameView()->fixedLay outSize().width()); 925 EXPECT_EQ(1.0f, webViewHelper.webView()->pageScaleFactor());
912 EXPECT_EQ(1.0f, m_webView->pageScaleFactor());
913 926
914 m_webView->settings()->setUseWideViewport(true); 927 webViewHelper.webView()->settings()->setUseWideViewport(true);
915 m_webView->layout(); 928 webViewHelper.webView()->layout();
916 EXPECT_EQ(viewportWidth, webViewImpl->mainFrameImpl()->frameView()->fixedLay outSize().width()); 929 EXPECT_EQ(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frame View()->fixedLayoutSize().width());
917 EXPECT_EQ(1.0f, m_webView->pageScaleFactor()); 930 EXPECT_EQ(1.0f, webViewHelper.webView()->pageScaleFactor());
918 } 931 }
919 932
920 TEST_F(WebFrameTest, OverflowHiddenDisablesScrolling) 933 TEST_F(WebFrameTest, OverflowHiddenDisablesScrolling)
921 { 934 {
922 registerMockedHttpURLLoad("body-overflow-hidden.html"); 935 registerMockedHttpURLLoad("body-overflow-hidden.html");
923 936
924 FixedLayoutTestWebViewClient client; 937 FixedLayoutTestWebViewClient client;
925 client.m_screenInfo.deviceScaleFactor = 1; 938 client.m_screenInfo.deviceScaleFactor = 1;
926 int viewportWidth = 640; 939 int viewportWidth = 640;
927 int viewportHeight = 480; 940 int viewportHeight = 480;
928 941
929 m_webView = FrameTestHelpers::createWebView(true, 0, &client); 942 FrameTestHelpers::WebViewHelper webViewHelper;
930 FrameTestHelpers::loadFrame(m_webView->mainFrame(), m_baseURL + "body-overfl ow-hidden.html"); 943 webViewHelper.initialize(true, 0, &client);
944 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL + "body-overflow-hidden.html");
931 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 945 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
932 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 946 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
933 947
934 WebCore::FrameView* view = webViewImpl()->mainFrameImpl()->frameView(); 948 WebCore::FrameView* view = webViewHelper.webViewImpl()->mainFrameImpl()->fra meView();
935 EXPECT_FALSE(view->userInputScrollable(WebCore::VerticalScrollbar)); 949 EXPECT_FALSE(view->userInputScrollable(WebCore::VerticalScrollbar));
936 } 950 }
937 951
938 TEST_F(WebFrameTest, IgnoreOverflowHiddenQuirk) 952 TEST_F(WebFrameTest, IgnoreOverflowHiddenQuirk)
939 { 953 {
940 registerMockedHttpURLLoad("body-overflow-hidden.html"); 954 registerMockedHttpURLLoad("body-overflow-hidden.html");
941 955
942 FixedLayoutTestWebViewClient client; 956 FixedLayoutTestWebViewClient client;
943 client.m_screenInfo.deviceScaleFactor = 1; 957 client.m_screenInfo.deviceScaleFactor = 1;
944 int viewportWidth = 640; 958 int viewportWidth = 640;
945 int viewportHeight = 480; 959 int viewportHeight = 480;
946 960
947 m_webView = FrameTestHelpers::createWebView(true, 0, &client); 961 FrameTestHelpers::WebViewHelper webViewHelper;
948 m_webView->settings()->setIgnoreMainFrameOverflowHiddenQuirk(true); 962 webViewHelper.initialize(true, 0, &client);
949 FrameTestHelpers::loadFrame(m_webView->mainFrame(), m_baseURL + "body-overfl ow-hidden.html"); 963 webViewHelper.webView()->settings()->setIgnoreMainFrameOverflowHiddenQuirk(t rue);
964 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL + "body-overflow-hidden.html");
950 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 965 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
951 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 966 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
952 967
953 WebCore::FrameView* view = webViewImpl()->mainFrameImpl()->frameView(); 968 WebCore::FrameView* view = webViewHelper.webViewImpl()->mainFrameImpl()->fra meView();
954 EXPECT_TRUE(view->userInputScrollable(WebCore::VerticalScrollbar)); 969 EXPECT_TRUE(view->userInputScrollable(WebCore::VerticalScrollbar));
955 } 970 }
956 971
957 TEST_F(WebFrameTest, NonZeroValuesNoQuirk) 972 TEST_F(WebFrameTest, NonZeroValuesNoQuirk)
958 { 973 {
959 registerMockedHttpURLLoad("viewport-nonzero-values.html"); 974 registerMockedHttpURLLoad("viewport-nonzero-values.html");
960 975
961 FixedLayoutTestWebViewClient client; 976 FixedLayoutTestWebViewClient client;
962 client.m_screenInfo.deviceScaleFactor = 1; 977 client.m_screenInfo.deviceScaleFactor = 1;
963 int viewportWidth = 640; 978 int viewportWidth = 640;
964 int viewportHeight = 480; 979 int viewportHeight = 480;
965 float expectedPageScaleFactor = 0.5f; 980 float expectedPageScaleFactor = 0.5f;
966 981
967 m_webView = FrameTestHelpers::createWebView(true, 0, &client); 982 FrameTestHelpers::WebViewHelper webViewHelper;
968 m_webView->enableFixedLayoutMode(true); 983 webViewHelper.initialize(true, 0, &client);
969 m_webView->settings()->setViewportEnabled(true); 984 webViewHelper.webView()->enableFixedLayoutMode(true);
970 m_webView->settings()->setViewportMetaZeroValuesQuirk(true); 985 webViewHelper.webView()->settings()->setViewportEnabled(true);
971 m_webView->settings()->setWideViewportQuirkEnabled(true); 986 webViewHelper.webView()->settings()->setViewportMetaZeroValuesQuirk(true);
972 FrameTestHelpers::loadFrame(m_webView->mainFrame(), m_baseURL + "viewport-no nzero-values.html"); 987 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
988 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL + "viewport-nonzero-values.html");
973 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 989 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
974 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 990 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
975 991
976 WebViewImpl* webViewImpl = toWebViewImpl(m_webView); 992 EXPECT_EQ(viewportWidth / expectedPageScaleFactor, webViewHelper.webViewImpl ()->mainFrameImpl()->frameView()->fixedLayoutSize().width());
977 EXPECT_EQ(viewportWidth / expectedPageScaleFactor, webViewImpl->mainFrameImp l()->frameView()->fixedLayoutSize().width()); 993 EXPECT_EQ(expectedPageScaleFactor, webViewHelper.webView()->pageScaleFactor( ));
978 EXPECT_EQ(expectedPageScaleFactor, m_webView->pageScaleFactor());
979 994
980 m_webView->settings()->setUseWideViewport(true); 995 webViewHelper.webView()->settings()->setUseWideViewport(true);
981 m_webView->layout(); 996 webViewHelper.webView()->layout();
982 EXPECT_EQ(viewportWidth / expectedPageScaleFactor, webViewImpl->mainFrameImp l()->frameView()->fixedLayoutSize().width()); 997 EXPECT_EQ(viewportWidth / expectedPageScaleFactor, webViewHelper.webViewImpl ()->mainFrameImpl()->frameView()->fixedLayoutSize().width());
983 EXPECT_EQ(expectedPageScaleFactor, m_webView->pageScaleFactor()); 998 EXPECT_EQ(expectedPageScaleFactor, webViewHelper.webView()->pageScaleFactor( ));
984 } 999 }
985 1000
986 TEST_F(WebFrameTest, ScaleFactorShouldNotOscillate) 1001 TEST_F(WebFrameTest, ScaleFactorShouldNotOscillate)
987 { 1002 {
988 registerMockedHttpURLLoad("scale_oscillate.html"); 1003 registerMockedHttpURLLoad("scale_oscillate.html");
989 1004
990 FixedLayoutTestWebViewClient client; 1005 FixedLayoutTestWebViewClient client;
991 client.m_screenInfo.deviceScaleFactor = static_cast<float>(1.325); 1006 client.m_screenInfo.deviceScaleFactor = static_cast<float>(1.325);
992 int viewportWidth = 800; 1007 int viewportWidth = 800;
993 int viewportHeight = 1057; 1008 int viewportHeight = 1057;
994 1009
995 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "scale_oscill ate.html", true, 0, &client); 1010 FrameTestHelpers::WebViewHelper webViewHelper;
996 m_webView->enableFixedLayoutMode(true); 1011 webViewHelper.initializeAndLoad(m_baseURL + "scale_oscillate.html", true, 0, &client);
997 m_webView->settings()->setViewportEnabled(true); 1012 webViewHelper.webView()->enableFixedLayoutMode(true);
998 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1013 webViewHelper.webView()->settings()->setViewportEnabled(true);
999 m_webView->layout(); 1014 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1015 webViewHelper.webView()->layout();
1000 } 1016 }
1001 1017
1002 TEST_F(WebFrameTest, setPageScaleFactorDoesNotLayout) 1018 TEST_F(WebFrameTest, setPageScaleFactorDoesNotLayout)
1003 { 1019 {
1004 registerMockedHttpURLLoad("fixed_layout.html"); 1020 registerMockedHttpURLLoad("fixed_layout.html");
1005 1021
1006 FixedLayoutTestWebViewClient client; 1022 FixedLayoutTestWebViewClient client;
1007 client.m_screenInfo.deviceScaleFactor = 1; 1023 client.m_screenInfo.deviceScaleFactor = 1;
1008 // Small viewport to ensure there are always scrollbars. 1024 // Small viewport to ensure there are always scrollbars.
1009 int viewportWidth = 64; 1025 int viewportWidth = 64;
1010 int viewportHeight = 48; 1026 int viewportHeight = 48;
1011 1027
1012 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html", true, 0, &client); 1028 FrameTestHelpers::WebViewHelper webViewHelper;
1013 m_webView->enableFixedLayoutMode(true); 1029 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c lient);
1014 m_webView->settings()->setViewportEnabled(true); 1030 webViewHelper.webView()->enableFixedLayoutMode(true);
1015 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1031 webViewHelper.webView()->settings()->setViewportEnabled(true);
1016 m_webView->layout(); 1032 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1033 webViewHelper.webView()->layout();
1017 1034
1018 int prevLayoutCount = webViewImpl()->mainFrameImpl()->frameView()->layoutCou nt(); 1035 int prevLayoutCount = webViewHelper.webViewImpl()->mainFrameImpl()->frameVie w()->layoutCount();
1019 webViewImpl()->setPageScaleFactor(3, WebPoint()); 1036 webViewHelper.webViewImpl()->setPageScaleFactor(3, WebPoint());
1020 EXPECT_FALSE(webViewImpl()->mainFrameImpl()->frameView()->needsLayout()); 1037 EXPECT_FALSE(webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->need sLayout());
1021 EXPECT_EQ(prevLayoutCount, webViewImpl()->mainFrameImpl()->frameView()->layo utCount()); 1038 EXPECT_EQ(prevLayoutCount, webViewHelper.webViewImpl()->mainFrameImpl()->fra meView()->layoutCount());
1022 } 1039 }
1023 1040
1024 TEST_F(WebFrameTest, setPageScaleFactorWithOverlayScrollbarsDoesNotLayout) 1041 TEST_F(WebFrameTest, setPageScaleFactorWithOverlayScrollbarsDoesNotLayout)
1025 { 1042 {
1026 UseMockScrollbarSettings mockScrollbarSettings; 1043 UseMockScrollbarSettings mockScrollbarSettings;
1027 1044
1028 registerMockedHttpURLLoad("fixed_layout.html"); 1045 registerMockedHttpURLLoad("fixed_layout.html");
1029 1046
1030 FixedLayoutTestWebViewClient client; 1047 FixedLayoutTestWebViewClient client;
1031 client.m_screenInfo.deviceScaleFactor = 1; 1048 client.m_screenInfo.deviceScaleFactor = 1;
1032 int viewportWidth = 640; 1049 int viewportWidth = 640;
1033 int viewportHeight = 480; 1050 int viewportHeight = 480;
1034 1051
1035 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html", true, 0, &client); 1052 FrameTestHelpers::WebViewHelper webViewHelper;
1036 m_webView->enableFixedLayoutMode(true); 1053 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c lient);
1037 m_webView->settings()->setViewportEnabled(true); 1054 webViewHelper.webView()->enableFixedLayoutMode(true);
1038 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1055 webViewHelper.webView()->settings()->setViewportEnabled(true);
1039 m_webView->layout(); 1056 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1057 webViewHelper.webView()->layout();
1040 1058
1041 int prevLayoutCount = webViewImpl()->mainFrameImpl()->frameView()->layoutCou nt(); 1059 int prevLayoutCount = webViewHelper.webViewImpl()->mainFrameImpl()->frameVie w()->layoutCount();
1042 webViewImpl()->setPageScaleFactor(30, WebPoint()); 1060 webViewHelper.webViewImpl()->setPageScaleFactor(30, WebPoint());
1043 EXPECT_FALSE(webViewImpl()->mainFrameImpl()->frameView()->needsLayout()); 1061 EXPECT_FALSE(webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->need sLayout());
1044 EXPECT_EQ(prevLayoutCount, webViewImpl()->mainFrameImpl()->frameView()->layo utCount()); 1062 EXPECT_EQ(prevLayoutCount, webViewHelper.webViewImpl()->mainFrameImpl()->fra meView()->layoutCount());
1045 1063
1046 } 1064 }
1047 1065
1048 TEST_F(WebFrameTest, setPageScaleFactorBeforeFrameHasView) 1066 TEST_F(WebFrameTest, setPageScaleFactorBeforeFrameHasView)
1049 { 1067 {
1050 registerMockedHttpURLLoad("fixed_layout.html"); 1068 registerMockedHttpURLLoad("fixed_layout.html");
1051 1069
1052 float pageScaleFactor = 3; 1070 float pageScaleFactor = 3;
1053 m_webView = FrameTestHelpers::createWebViewAndLoad("about:html", true, 0, 0) ; 1071 FrameTestHelpers::WebViewHelper webViewHelper;
1054 m_webView->setPageScaleFactor(pageScaleFactor, WebPoint()); 1072 webViewHelper.initializeAndLoad("about:html", true, 0, 0);
1073 webViewHelper.webView()->setPageScaleFactor(pageScaleFactor, WebPoint());
1055 1074
1056 FrameTestHelpers::loadFrame(m_webView->mainFrame(), m_baseURL + "fixed_layou t.html"); 1075 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL + "fixed_layout.html");
1057 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 1076 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
1058 WebCore::FrameView* view = webViewImpl()->mainFrameImpl()->frameView(); 1077 WebCore::FrameView* view = webViewHelper.webViewImpl()->mainFrameImpl()->fra meView();
1059 EXPECT_EQ(pageScaleFactor, view->visibleContentScaleFactor()); 1078 EXPECT_EQ(pageScaleFactor, view->visibleContentScaleFactor());
1060 } 1079 }
1061 1080
1062 TEST_F(WebFrameTest, pageScaleFactorWrittenToHistoryItem) 1081 TEST_F(WebFrameTest, pageScaleFactorWrittenToHistoryItem)
1063 { 1082 {
1064 registerMockedHttpURLLoad("fixed_layout.html"); 1083 registerMockedHttpURLLoad("fixed_layout.html");
1065 1084
1066 FixedLayoutTestWebViewClient client; 1085 FixedLayoutTestWebViewClient client;
1067 client.m_screenInfo.deviceScaleFactor = 1; 1086 client.m_screenInfo.deviceScaleFactor = 1;
1068 int viewportWidth = 640; 1087 int viewportWidth = 640;
1069 int viewportHeight = 480; 1088 int viewportHeight = 480;
1070 1089
1071 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html", true, 0, &client); 1090 FrameTestHelpers::WebViewHelper webViewHelper;
1072 m_webView->enableFixedLayoutMode(true); 1091 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c lient);
1073 m_webView->settings()->setViewportEnabled(true); 1092 webViewHelper.webView()->enableFixedLayoutMode(true);
1074 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1093 webViewHelper.webView()->settings()->setViewportEnabled(true);
1075 m_webView->layout(); 1094 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1095 webViewHelper.webView()->layout();
1076 1096
1077 m_webView->setPageScaleFactor(3, WebPoint()); 1097 webViewHelper.webView()->setPageScaleFactor(3, WebPoint());
1078 webViewImpl()->page()->mainFrame()->loader()->history()->saveDocumentAndScro llState(); 1098 webViewHelper.webViewImpl()->page()->mainFrame()->loader()->history()->saveD ocumentAndScrollState();
1079 m_webView->setPageScaleFactor(1, WebPoint()); 1099 webViewHelper.webView()->setPageScaleFactor(1, WebPoint());
1080 webViewImpl()->page()->mainFrame()->loader()->history()->restoreScrollPositi onAndViewState(); 1100 webViewHelper.webViewImpl()->page()->mainFrame()->loader()->history()->resto reScrollPositionAndViewState();
1081 EXPECT_EQ(3, m_webView->pageScaleFactor()); 1101 EXPECT_EQ(3, webViewHelper.webView()->pageScaleFactor());
1082 } 1102 }
1083 1103
1084 TEST_F(WebFrameTest, pageScaleFactorShrinksViewport) 1104 TEST_F(WebFrameTest, pageScaleFactorShrinksViewport)
1085 { 1105 {
1086 registerMockedHttpURLLoad("large-div.html"); 1106 registerMockedHttpURLLoad("large-div.html");
1087 1107
1088 FixedLayoutTestWebViewClient client; 1108 FixedLayoutTestWebViewClient client;
1089 client.m_screenInfo.deviceScaleFactor = 1; 1109 client.m_screenInfo.deviceScaleFactor = 1;
1090 // Small viewport to ensure there are always scrollbars. 1110 // Small viewport to ensure there are always scrollbars.
1091 int viewportWidth = 64; 1111 int viewportWidth = 64;
1092 int viewportHeight = 48; 1112 int viewportHeight = 48;
1093 1113
1094 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "large-div.ht ml", true, 0, &client); 1114 FrameTestHelpers::WebViewHelper webViewHelper;
1095 m_webView->enableFixedLayoutMode(true); 1115 webViewHelper.initializeAndLoad(m_baseURL + "large-div.html", true, 0, &clie nt);
1096 m_webView->settings()->setViewportEnabled(true); 1116 webViewHelper.webView()->enableFixedLayoutMode(true);
1097 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1117 webViewHelper.webView()->settings()->setViewportEnabled(true);
1098 m_webView->layout(); 1118 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1119 webViewHelper.webView()->layout();
1099 1120
1100 WebCore::FrameView* view = webViewImpl()->mainFrameImpl()->frameView(); 1121 WebCore::FrameView* view = webViewHelper.webViewImpl()->mainFrameImpl()->fra meView();
1101 int viewportWidthMinusScrollbar = viewportWidth - (view->verticalScrollbar() ->isOverlayScrollbar() ? 0 : 15); 1122 int viewportWidthMinusScrollbar = viewportWidth - (view->verticalScrollbar() ->isOverlayScrollbar() ? 0 : 15);
1102 int viewportHeightMinusScrollbar = viewportHeight - (view->horizontalScrollb ar()->isOverlayScrollbar() ? 0 : 15); 1123 int viewportHeightMinusScrollbar = viewportHeight - (view->horizontalScrollb ar()->isOverlayScrollbar() ? 0 : 15);
1103 1124
1104 m_webView->setPageScaleFactor(2, WebPoint()); 1125 webViewHelper.webView()->setPageScaleFactor(2, WebPoint());
1105 1126
1106 WebCore::IntSize unscaledSize = view->unscaledVisibleContentSize(WebCore::Sc rollableArea::IncludeScrollbars); 1127 WebCore::IntSize unscaledSize = view->unscaledVisibleContentSize(WebCore::Sc rollableArea::IncludeScrollbars);
1107 EXPECT_EQ(viewportWidth, unscaledSize.width()); 1128 EXPECT_EQ(viewportWidth, unscaledSize.width());
1108 EXPECT_EQ(viewportHeight, unscaledSize.height()); 1129 EXPECT_EQ(viewportHeight, unscaledSize.height());
1109 1130
1110 WebCore::IntSize unscaledSizeMinusScrollbar = view->unscaledVisibleContentSi ze(WebCore::ScrollableArea::ExcludeScrollbars); 1131 WebCore::IntSize unscaledSizeMinusScrollbar = view->unscaledVisibleContentSi ze(WebCore::ScrollableArea::ExcludeScrollbars);
1111 EXPECT_EQ(viewportWidthMinusScrollbar, unscaledSizeMinusScrollbar.width()); 1132 EXPECT_EQ(viewportWidthMinusScrollbar, unscaledSizeMinusScrollbar.width());
1112 EXPECT_EQ(viewportHeightMinusScrollbar, unscaledSizeMinusScrollbar.height()) ; 1133 EXPECT_EQ(viewportHeightMinusScrollbar, unscaledSizeMinusScrollbar.height()) ;
1113 1134
1114 WebCore::IntSize scaledSize = view->visibleContentRect().size(); 1135 WebCore::IntSize scaledSize = view->visibleContentRect().size();
1115 EXPECT_EQ(ceil(viewportWidthMinusScrollbar / 2.0), scaledSize.width()); 1136 EXPECT_EQ(ceil(viewportWidthMinusScrollbar / 2.0), scaledSize.width());
1116 EXPECT_EQ(ceil(viewportHeightMinusScrollbar / 2.0), scaledSize.height()); 1137 EXPECT_EQ(ceil(viewportHeightMinusScrollbar / 2.0), scaledSize.height());
1117 } 1138 }
1118 1139
1119 TEST_F(WebFrameTest, pageScaleFactorDoesNotApplyCssTransform) 1140 TEST_F(WebFrameTest, pageScaleFactorDoesNotApplyCssTransform)
1120 { 1141 {
1121 registerMockedHttpURLLoad("fixed_layout.html"); 1142 registerMockedHttpURLLoad("fixed_layout.html");
1122 1143
1123 FixedLayoutTestWebViewClient client; 1144 FixedLayoutTestWebViewClient client;
1124 client.m_screenInfo.deviceScaleFactor = 1; 1145 client.m_screenInfo.deviceScaleFactor = 1;
1125 int viewportWidth = 640; 1146 int viewportWidth = 640;
1126 int viewportHeight = 480; 1147 int viewportHeight = 480;
1127 1148
1128 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html", true, 0, &client); 1149 FrameTestHelpers::WebViewHelper webViewHelper;
1129 m_webView->enableFixedLayoutMode(true); 1150 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c lient);
1130 m_webView->settings()->setViewportEnabled(true); 1151 webViewHelper.webView()->enableFixedLayoutMode(true);
1131 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1152 webViewHelper.webView()->settings()->setViewportEnabled(true);
1132 m_webView->layout(); 1153 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1154 webViewHelper.webView()->layout();
1133 1155
1134 m_webView->setPageScaleFactor(2, WebPoint()); 1156 webViewHelper.webView()->setPageScaleFactor(2, WebPoint());
1135 1157
1136 EXPECT_EQ(980, webViewImpl()->page()->mainFrame()->contentRenderer()->unscal edDocumentRect().width()); 1158 EXPECT_EQ(980, webViewHelper.webViewImpl()->page()->mainFrame()->contentRend erer()->unscaledDocumentRect().width());
1137 EXPECT_EQ(980, webViewImpl()->mainFrameImpl()->frameView()->contentsSize().w idth()); 1159 EXPECT_EQ(980, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->co ntentsSize().width());
1138 } 1160 }
1139 1161
1140 TEST_F(WebFrameTest, targetDensityDpiHigh) 1162 TEST_F(WebFrameTest, targetDensityDpiHigh)
1141 { 1163 {
1142 UseMockScrollbarSettings mockScrollbarSettings; 1164 UseMockScrollbarSettings mockScrollbarSettings;
1143 registerMockedHttpURLLoad("viewport-target-densitydpi-high.html"); 1165 registerMockedHttpURLLoad("viewport-target-densitydpi-high.html");
1144 1166
1145 FixedLayoutTestWebViewClient client; 1167 FixedLayoutTestWebViewClient client;
1146 // high-dpi = 240 1168 // high-dpi = 240
1147 float targetDpi = 240.0f; 1169 float targetDpi = 240.0f;
1148 float deviceScaleFactors[] = { 1.0f, 4.0f / 3.0f, 2.0f }; 1170 float deviceScaleFactors[] = { 1.0f, 4.0f / 3.0f, 2.0f };
1149 int viewportWidth = 640; 1171 int viewportWidth = 640;
1150 int viewportHeight = 480; 1172 int viewportHeight = 480;
1151 1173
1152 for (size_t i = 0; i < ARRAY_SIZE(deviceScaleFactors); ++i) { 1174 for (size_t i = 0; i < ARRAY_SIZE(deviceScaleFactors); ++i) {
1153 float deviceScaleFactor = deviceScaleFactors[i]; 1175 float deviceScaleFactor = deviceScaleFactors[i];
1154 float deviceDpi = deviceScaleFactor * 160.0f; 1176 float deviceDpi = deviceScaleFactor * 160.0f;
1155 client.m_screenInfo.deviceScaleFactor = deviceScaleFactor; 1177 client.m_screenInfo.deviceScaleFactor = deviceScaleFactor;
1156 1178
1157 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport -target-densitydpi-high.html", true, 0, &client); 1179 FrameTestHelpers::WebViewHelper webViewHelper;
1158 m_webView->enableFixedLayoutMode(true); 1180 webViewHelper.initializeAndLoad(m_baseURL + "viewport-target-densitydpi-high .html", true, 0, &client);
1159 m_webView->settings()->setViewportEnabled(true); 1181 webViewHelper.webView()->enableFixedLayoutMode(true);
1160 m_webView->settings()->setSupportDeprecatedTargetDensityDPI(true); 1182 webViewHelper.webView()->settings()->setViewportEnabled(true);
1161 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1183 webViewHelper.webView()->settings()->setSupportDeprecatedTargetDensityDP I(true);
1184 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1162 1185
1163 // We need to account for the fact that logical pixels are unconditional ly multiplied by deviceScaleFactor to produce 1186 // We need to account for the fact that logical pixels are unconditional ly multiplied by deviceScaleFactor to produce
1164 // physical pixels. 1187 // physical pixels.
1165 float densityDpiScaleRatio = deviceScaleFactor * targetDpi / deviceDpi; 1188 float densityDpiScaleRatio = deviceScaleFactor * targetDpi / deviceDpi;
1166 EXPECT_NEAR(viewportWidth * densityDpiScaleRatio, m_webView->fixedLayout Size().width, 1.0f); 1189 EXPECT_NEAR(viewportWidth * densityDpiScaleRatio, webViewHelper.webView( )->fixedLayoutSize().width, 1.0f);
1167 EXPECT_NEAR(viewportHeight * densityDpiScaleRatio, m_webView->fixedLayou tSize().height, 1.0f); 1190 EXPECT_NEAR(viewportHeight * densityDpiScaleRatio, webViewHelper.webView ()->fixedLayoutSize().height, 1.0f);
1168 EXPECT_NEAR(1.0f / densityDpiScaleRatio, m_webView->pageScaleFactor(), 0 .01f); 1191 EXPECT_NEAR(1.0f / densityDpiScaleRatio, webViewHelper.webView()->pageSc aleFactor(), 0.01f);
1169
1170 m_webView->close();
1171 m_webView = 0;
1172 } 1192 }
1173 } 1193 }
1174 1194
1175 TEST_F(WebFrameTest, targetDensityDpiDevice) 1195 TEST_F(WebFrameTest, targetDensityDpiDevice)
1176 { 1196 {
1177 UseMockScrollbarSettings mockScrollbarSettings; 1197 UseMockScrollbarSettings mockScrollbarSettings;
1178 registerMockedHttpURLLoad("viewport-target-densitydpi-device.html"); 1198 registerMockedHttpURLLoad("viewport-target-densitydpi-device.html");
1179 1199
1180 float deviceScaleFactors[] = { 1.0f, 4.0f / 3.0f, 2.0f }; 1200 float deviceScaleFactors[] = { 1.0f, 4.0f / 3.0f, 2.0f };
1181 1201
1182 FixedLayoutTestWebViewClient client; 1202 FixedLayoutTestWebViewClient client;
1183 int viewportWidth = 640; 1203 int viewportWidth = 640;
1184 int viewportHeight = 480; 1204 int viewportHeight = 480;
1185 1205
1186 for (size_t i = 0; i < ARRAY_SIZE(deviceScaleFactors); ++i) { 1206 for (size_t i = 0; i < ARRAY_SIZE(deviceScaleFactors); ++i) {
1187 client.m_screenInfo.deviceScaleFactor = deviceScaleFactors[i]; 1207 client.m_screenInfo.deviceScaleFactor = deviceScaleFactors[i];
1188 1208
1189 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport -target-densitydpi-device.html", true, 0, &client); 1209 FrameTestHelpers::WebViewHelper webViewHelper;
1190 m_webView->enableFixedLayoutMode(true); 1210 webViewHelper.initializeAndLoad(m_baseURL + "viewport-target-densitydpi-devi ce.html", true, 0, &client);
1191 m_webView->settings()->setViewportEnabled(true); 1211 webViewHelper.webView()->enableFixedLayoutMode(true);
1192 m_webView->settings()->setSupportDeprecatedTargetDensityDPI(true); 1212 webViewHelper.webView()->settings()->setViewportEnabled(true);
1193 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1213 webViewHelper.webView()->settings()->setSupportDeprecatedTargetDensityDP I(true);
1214 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1194 1215
1195 EXPECT_NEAR(viewportWidth * client.m_screenInfo.deviceScaleFactor, m_web View->fixedLayoutSize().width, 1.0f); 1216 EXPECT_NEAR(viewportWidth * client.m_screenInfo.deviceScaleFactor, webVi ewHelper.webView()->fixedLayoutSize().width, 1.0f);
1196 EXPECT_NEAR(viewportHeight * client.m_screenInfo.deviceScaleFactor, m_we bView->fixedLayoutSize().height, 1.0f); 1217 EXPECT_NEAR(viewportHeight * client.m_screenInfo.deviceScaleFactor, webV iewHelper.webView()->fixedLayoutSize().height, 1.0f);
1197 EXPECT_NEAR(1.0f / client.m_screenInfo.deviceScaleFactor, m_webView->pag eScaleFactor(), 0.01f); 1218 EXPECT_NEAR(1.0f / client.m_screenInfo.deviceScaleFactor, webViewHelper. webView()->pageScaleFactor(), 0.01f);
1198
1199 m_webView->close();
1200 m_webView = 0;
1201 } 1219 }
1202 } 1220 }
1203 1221
1204 class WebFrameResizeTest : public WebFrameTest { 1222 class WebFrameResizeTest : public WebFrameTest {
1205 protected: 1223 protected:
1206 1224
1207 static WebCore::FloatSize computeRelativeOffset(const WebCore::IntPoint& abs oluteOffset, const WebCore::LayoutRect& rect) 1225 static WebCore::FloatSize computeRelativeOffset(const WebCore::IntPoint& abs oluteOffset, const WebCore::LayoutRect& rect)
1208 { 1226 {
1209 WebCore::FloatSize relativeOffset = WebCore::FloatPoint(absoluteOffset) - rect.location(); 1227 WebCore::FloatSize relativeOffset = WebCore::FloatPoint(absoluteOffset) - rect.location();
1210 relativeOffset.scale(1.f / rect.width(), 1.f / rect.height()); 1228 relativeOffset.scale(1.f / rect.width(), 1.f / rect.height());
1211 return relativeOffset; 1229 return relativeOffset;
1212 } 1230 }
1213 1231
1214 void testResizeYieldsCorrectScrollAndScale(const char* url, 1232 void testResizeYieldsCorrectScrollAndScale(const char* url,
1215 const float initialPageScaleFacto r, 1233 const float initialPageScaleFacto r,
1216 const WebSize scrollOffset, 1234 const WebSize scrollOffset,
1217 const WebSize viewportSize, 1235 const WebSize viewportSize,
1218 const bool shouldScaleRelativeToV iewportWidth) { 1236 const bool shouldScaleRelativeToV iewportWidth) {
1219 registerMockedHttpURLLoad(url); 1237 registerMockedHttpURLLoad(url);
1220 1238
1221 const float aspectRatio = static_cast<float>(viewportSize.width) / viewp ortSize.height; 1239 const float aspectRatio = static_cast<float>(viewportSize.width) / viewp ortSize.height;
1222 1240
1223 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + url, true ); 1241 FrameTestHelpers::WebViewHelper webViewHelper;
1224 m_webView->settings()->setViewportEnabled(true); 1242 webViewHelper.initializeAndLoad(m_baseURL + url, true);
1225 m_webView->enableFixedLayoutMode(true); 1243 webViewHelper.webView()->settings()->setViewportEnabled(true);
1244 webViewHelper.webView()->enableFixedLayoutMode(true);
1226 1245
1227 // Origin scrollOffsets preserved under resize. 1246 // Origin scrollOffsets preserved under resize.
1228 { 1247 {
1229 webViewImpl()->resize(WebSize(viewportSize.width, viewportSize.heigh t)); 1248 webViewHelper.webViewImpl()->resize(WebSize(viewportSize.width, view portSize.height));
1230 webViewImpl()->setPageScaleFactor(initialPageScaleFactor, WebPoint() ); 1249 webViewHelper.webViewImpl()->setPageScaleFactor(initialPageScaleFact or, WebPoint());
1231 ASSERT_EQ(viewportSize, webViewImpl()->size()); 1250 ASSERT_EQ(viewportSize, webViewHelper.webViewImpl()->size());
1232 ASSERT_EQ(initialPageScaleFactor, webViewImpl()->pageScaleFactor()); 1251 ASSERT_EQ(initialPageScaleFactor, webViewHelper.webViewImpl()->pageS caleFactor());
1233 webViewImpl()->resize(WebSize(viewportSize.height, viewportSize.widt h)); 1252 webViewHelper.webViewImpl()->resize(WebSize(viewportSize.height, vie wportSize.width));
1234 float expectedPageScaleFactor = initialPageScaleFactor * (shouldScal eRelativeToViewportWidth ? 1 / aspectRatio : 1); 1253 float expectedPageScaleFactor = initialPageScaleFactor * (shouldScal eRelativeToViewportWidth ? 1 / aspectRatio : 1);
1235 EXPECT_NEAR(expectedPageScaleFactor, webViewImpl()->pageScaleFactor( ), 0.05f); 1254 EXPECT_NEAR(expectedPageScaleFactor, webViewHelper.webViewImpl()->pa geScaleFactor(), 0.05f);
1236 EXPECT_EQ(WebSize(), webViewImpl()->mainFrame()->scrollOffset()); 1255 EXPECT_EQ(WebSize(), webViewHelper.webViewImpl()->mainFrame()->scrol lOffset());
1237 } 1256 }
1238 1257
1239 // Resizing just the height should not affect pageScaleFactor or scrollO ffset. 1258 // Resizing just the height should not affect pageScaleFactor or scrollO ffset.
1240 { 1259 {
1241 webViewImpl()->resize(WebSize(viewportSize.width, viewportSize.heigh t)); 1260 webViewHelper.webViewImpl()->resize(WebSize(viewportSize.width, view portSize.height));
1242 webViewImpl()->setPageScaleFactor(initialPageScaleFactor, WebPoint(s crollOffset.width, scrollOffset.height)); 1261 webViewHelper.webViewImpl()->setPageScaleFactor(initialPageScaleFact or, WebPoint(scrollOffset.width, scrollOffset.height));
1243 webViewImpl()->layout(); 1262 webViewHelper.webViewImpl()->layout();
1244 const WebSize expectedScrollOffset = webViewImpl()->mainFrame()->scr ollOffset(); 1263 const WebSize expectedScrollOffset = webViewHelper.webViewImpl()->ma inFrame()->scrollOffset();
1245 webViewImpl()->resize(WebSize(viewportSize.width, viewportSize.heigh t * 0.8f)); 1264 webViewHelper.webViewImpl()->resize(WebSize(viewportSize.width, view portSize.height * 0.8f));
1246 EXPECT_EQ(initialPageScaleFactor, webViewImpl()->pageScaleFactor()); 1265 EXPECT_EQ(initialPageScaleFactor, webViewHelper.webViewImpl()->pageS caleFactor());
1247 EXPECT_EQ(expectedScrollOffset, webViewImpl()->mainFrame()->scrollOf fset()); 1266 EXPECT_EQ(expectedScrollOffset, webViewHelper.webViewImpl()->mainFra me()->scrollOffset());
1248 webViewImpl()->resize(WebSize(viewportSize.width, viewportSize.heigh t * 0.8f)); 1267 webViewHelper.webViewImpl()->resize(WebSize(viewportSize.width, view portSize.height * 0.8f));
1249 EXPECT_EQ(initialPageScaleFactor, webViewImpl()->pageScaleFactor()); 1268 EXPECT_EQ(initialPageScaleFactor, webViewHelper.webViewImpl()->pageS caleFactor());
1250 EXPECT_EQ(expectedScrollOffset, webViewImpl()->mainFrame()->scrollOf fset()); 1269 EXPECT_EQ(expectedScrollOffset, webViewHelper.webViewImpl()->mainFra me()->scrollOffset());
1251 } 1270 }
1252 1271
1253 // Generic resize preserves scrollOffset relative to anchor node located 1272 // Generic resize preserves scrollOffset relative to anchor node located
1254 // the top center of the screen. 1273 // the top center of the screen.
1255 { 1274 {
1256 webViewImpl()->resize(WebSize(viewportSize.height, viewportSize.widt h)); 1275 webViewHelper.webViewImpl()->resize(WebSize(viewportSize.height, vie wportSize.width));
1257 float pageScaleFactor = webViewImpl()->pageScaleFactor(); 1276 float pageScaleFactor = webViewHelper.webViewImpl()->pageScaleFactor ();
1258 webViewImpl()->resize(WebSize(viewportSize.width, viewportSize.heigh t)); 1277 webViewHelper.webViewImpl()->resize(WebSize(viewportSize.width, view portSize.height));
1259 float expectedPageScaleFactor = pageScaleFactor * (shouldScaleRelati veToViewportWidth ? aspectRatio : 1); 1278 float expectedPageScaleFactor = pageScaleFactor * (shouldScaleRelati veToViewportWidth ? aspectRatio : 1);
1260 EXPECT_NEAR(expectedPageScaleFactor, webViewImpl()->pageScaleFactor( ), 0.05f); 1279 EXPECT_NEAR(expectedPageScaleFactor, webViewHelper.webViewImpl()->pa geScaleFactor(), 0.05f);
1261 webViewImpl()->mainFrame()->setScrollOffset(scrollOffset); 1280 webViewHelper.webViewImpl()->mainFrame()->setScrollOffset(scrollOffs et);
1262 1281
1263 WebCore::IntPoint anchorPoint = WebCore::IntPoint(scrollOffset) + We bCore::IntPoint(viewportSize.width / 2, 0); 1282 WebCore::IntPoint anchorPoint = WebCore::IntPoint(scrollOffset) + We bCore::IntPoint(viewportSize.width / 2, 0);
1264 RefPtr<WebCore::Node> anchorNode = webViewImpl()->mainFrameImpl()->f rame()->eventHandler()->hitTestResultAtPoint(anchorPoint, HitTestRequest::ReadOn ly | HitTestRequest::Active | HitTestRequest::DisallowShadowContent).innerNode() ; 1283 RefPtr<WebCore::Node> anchorNode = webViewHelper.webViewImpl()->main FrameImpl()->frame()->eventHandler()->hitTestResultAtPoint(anchorPoint, HitTestR equest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowShadowConten t).innerNode();
1265 ASSERT(anchorNode); 1284 ASSERT(anchorNode);
1266 1285
1267 pageScaleFactor = webViewImpl()->pageScaleFactor(); 1286 pageScaleFactor = webViewHelper.webViewImpl()->pageScaleFactor();
1268 const WebCore::FloatSize preResizeRelativeOffset 1287 const WebCore::FloatSize preResizeRelativeOffset
1269 = computeRelativeOffset(anchorPoint, anchorNode->boundingBox()); 1288 = computeRelativeOffset(anchorPoint, anchorNode->boundingBox());
1270 webViewImpl()->resize(WebSize(viewportSize.height, viewportSize.widt h)); 1289 webViewHelper.webViewImpl()->resize(WebSize(viewportSize.height, vie wportSize.width));
1271 WebCore::IntPoint newAnchorPoint = WebCore::IntPoint(webViewImpl()-> mainFrame()->scrollOffset()) + WebCore::IntPoint(viewportSize.height / 2, 0); 1290 WebCore::IntPoint newAnchorPoint = WebCore::IntPoint(webViewHelper.w ebViewImpl()->mainFrame()->scrollOffset()) + WebCore::IntPoint(viewportSize.heig ht / 2, 0);
1272 const WebCore::FloatSize postResizeRelativeOffset 1291 const WebCore::FloatSize postResizeRelativeOffset
1273 = computeRelativeOffset(newAnchorPoint, anchorNode->boundingBox( )); 1292 = computeRelativeOffset(newAnchorPoint, anchorNode->boundingBox( ));
1274 EXPECT_NEAR(preResizeRelativeOffset.width(), postResizeRelativeOffse t.width(), 0.15f); 1293 EXPECT_NEAR(preResizeRelativeOffset.width(), postResizeRelativeOffse t.width(), 0.15f);
1275 expectedPageScaleFactor = pageScaleFactor * (shouldScaleRelativeToVi ewportWidth ? 1 / aspectRatio : 1); 1294 expectedPageScaleFactor = pageScaleFactor * (shouldScaleRelativeToVi ewportWidth ? 1 / aspectRatio : 1);
1276 EXPECT_NEAR(expectedPageScaleFactor, webViewImpl()->pageScaleFactor( ), 0.05f); 1295 EXPECT_NEAR(expectedPageScaleFactor, webViewHelper.webViewImpl()->pa geScaleFactor(), 0.05f);
1277 } 1296 }
1278 } 1297 }
1279 }; 1298 };
1280 1299
1281 TEST_F(WebFrameResizeTest, ResizeYieldsCorrectScrollAndScaleForWidthEqualsDevice Width) 1300 TEST_F(WebFrameResizeTest, ResizeYieldsCorrectScrollAndScaleForWidthEqualsDevice Width)
1282 { 1301 {
1283 // With width=device-width, pageScaleFactor is preserved across resizes as 1302 // With width=device-width, pageScaleFactor is preserved across resizes as
1284 // long as the content adjusts according to the device-width. 1303 // long as the content adjusts according to the device-width.
1285 const char* url = "resize_scroll_mobile.html"; 1304 const char* url = "resize_scroll_mobile.html";
1286 const float initialPageScaleFactor = 1; 1305 const float initialPageScaleFactor = 1;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 TEST_F(WebFrameTest, pageScaleFactorScalesPaintClip) 1340 TEST_F(WebFrameTest, pageScaleFactorScalesPaintClip)
1322 { 1341 {
1323 UseMockScrollbarSettings mockScrollbarSettings; 1342 UseMockScrollbarSettings mockScrollbarSettings;
1324 registerMockedHttpURLLoad("large-div.html"); 1343 registerMockedHttpURLLoad("large-div.html");
1325 1344
1326 FixedLayoutTestWebViewClient client; 1345 FixedLayoutTestWebViewClient client;
1327 client.m_screenInfo.deviceScaleFactor = 1; 1346 client.m_screenInfo.deviceScaleFactor = 1;
1328 int viewportWidth = 50; 1347 int viewportWidth = 50;
1329 int viewportHeight = 50; 1348 int viewportHeight = 50;
1330 1349
1331 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "large-div.ht ml", true, 0, &client); 1350 FrameTestHelpers::WebViewHelper webViewHelper;
1332 m_webView->enableFixedLayoutMode(true); 1351 webViewHelper.initializeAndLoad(m_baseURL + "large-div.html", true, 0, &clie nt);
1333 m_webView->settings()->setViewportEnabled(true); 1352 webViewHelper.webView()->enableFixedLayoutMode(true);
1334 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1353 webViewHelper.webView()->settings()->setViewportEnabled(true);
1335 m_webView->layout(); 1354 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1355 webViewHelper.webView()->layout();
1336 1356
1337 // Set <1 page scale so that the clip rect should be larger than 1357 // Set <1 page scale so that the clip rect should be larger than
1338 // the viewport size as passed into resize(). 1358 // the viewport size as passed into resize().
1339 m_webView->setPageScaleFactor(0.5, WebPoint()); 1359 webViewHelper.webView()->setPageScaleFactor(0.5, WebPoint());
1340 1360
1341 SkBitmap bitmap; 1361 SkBitmap bitmap;
1342 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 200, 200); 1362 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 200, 200);
1343 bitmap.allocPixels(); 1363 bitmap.allocPixels();
1344 bitmap.eraseColor(0); 1364 bitmap.eraseColor(0);
1345 SkCanvas canvas(bitmap); 1365 SkCanvas canvas(bitmap);
1346 1366
1347 WebCore::GraphicsContext context(&canvas); 1367 WebCore::GraphicsContext context(&canvas);
1348 context.setTrackOpaqueRegion(true); 1368 context.setTrackOpaqueRegion(true);
1349 1369
1350 EXPECT_EQ_RECT(WebCore::IntRect(0, 0, 0, 0), context.opaqueRegion().asRect() ); 1370 EXPECT_EQ_RECT(WebCore::IntRect(0, 0, 0, 0), context.opaqueRegion().asRect() );
1351 1371
1352 WebCore::FrameView* view = webViewImpl()->mainFrameImpl()->frameView(); 1372 WebCore::FrameView* view = webViewHelper.webViewImpl()->mainFrameImpl()->fra meView();
1353 WebCore::IntRect paintRect(0, 0, 200, 200); 1373 WebCore::IntRect paintRect(0, 0, 200, 200);
1354 view->paint(&context, paintRect); 1374 view->paint(&context, paintRect);
1355 1375
1356 int viewportWidthMinusScrollbar = 50 - (view->verticalScrollbar()->isOverlay Scrollbar() ? 0 : 15); 1376 int viewportWidthMinusScrollbar = 50 - (view->verticalScrollbar()->isOverlay Scrollbar() ? 0 : 15);
1357 int viewportHeightMinusScrollbar = 50 - (view->horizontalScrollbar()->isOver layScrollbar() ? 0 : 15); 1377 int viewportHeightMinusScrollbar = 50 - (view->horizontalScrollbar()->isOver layScrollbar() ? 0 : 15);
1358 WebCore::IntRect clippedRect(0, 0, viewportWidthMinusScrollbar * 2, viewport HeightMinusScrollbar * 2); 1378 WebCore::IntRect clippedRect(0, 0, viewportWidthMinusScrollbar * 2, viewport HeightMinusScrollbar * 2);
1359 EXPECT_EQ_RECT(clippedRect, context.opaqueRegion().asRect()); 1379 EXPECT_EQ_RECT(clippedRect, context.opaqueRegion().asRect());
1360 } 1380 }
1361 1381
1362 TEST_F(WebFrameTest, pageScaleFactorUpdatesScrollbars) 1382 TEST_F(WebFrameTest, pageScaleFactorUpdatesScrollbars)
1363 { 1383 {
1364 UseMockScrollbarSettings mockScrollbarSettings; 1384 UseMockScrollbarSettings mockScrollbarSettings;
1365 registerMockedHttpURLLoad("fixed_layout.html"); 1385 registerMockedHttpURLLoad("fixed_layout.html");
1366 1386
1367 FixedLayoutTestWebViewClient client; 1387 FixedLayoutTestWebViewClient client;
1368 client.m_screenInfo.deviceScaleFactor = 1; 1388 client.m_screenInfo.deviceScaleFactor = 1;
1369 int viewportWidth = 640; 1389 int viewportWidth = 640;
1370 int viewportHeight = 480; 1390 int viewportHeight = 480;
1371 1391
1372 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html", true, 0, &client); 1392 FrameTestHelpers::WebViewHelper webViewHelper;
1373 m_webView->enableFixedLayoutMode(true); 1393 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c lient);
1374 m_webView->settings()->setViewportEnabled(true); 1394 webViewHelper.webView()->enableFixedLayoutMode(true);
1375 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1395 webViewHelper.webView()->settings()->setViewportEnabled(true);
1376 m_webView->layout(); 1396 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1397 webViewHelper.webView()->layout();
1377 1398
1378 WebCore::FrameView* view = webViewImpl()->mainFrameImpl()->frameView(); 1399 WebCore::FrameView* view = webViewHelper.webViewImpl()->mainFrameImpl()->fra meView();
1379 EXPECT_EQ(view->scrollSize(WebCore::HorizontalScrollbar), view->contentsSize ().width() - view->visibleContentRect().width()); 1400 EXPECT_EQ(view->scrollSize(WebCore::HorizontalScrollbar), view->contentsSize ().width() - view->visibleContentRect().width());
1380 EXPECT_EQ(view->scrollSize(WebCore::VerticalScrollbar), view->contentsSize() .height() - view->visibleContentRect().height()); 1401 EXPECT_EQ(view->scrollSize(WebCore::VerticalScrollbar), view->contentsSize() .height() - view->visibleContentRect().height());
1381 1402
1382 m_webView->setPageScaleFactor(10, WebPoint()); 1403 webViewHelper.webView()->setPageScaleFactor(10, WebPoint());
1383 1404
1384 EXPECT_EQ(view->scrollSize(WebCore::HorizontalScrollbar), view->contentsSize ().width() - view->visibleContentRect().width()); 1405 EXPECT_EQ(view->scrollSize(WebCore::HorizontalScrollbar), view->contentsSize ().width() - view->visibleContentRect().width());
1385 EXPECT_EQ(view->scrollSize(WebCore::VerticalScrollbar), view->contentsSize() .height() - view->visibleContentRect().height()); 1406 EXPECT_EQ(view->scrollSize(WebCore::VerticalScrollbar), view->contentsSize() .height() - view->visibleContentRect().height());
1386 } 1407 }
1387 1408
1388 TEST_F(WebFrameTest, CanOverrideScaleLimits) 1409 TEST_F(WebFrameTest, CanOverrideScaleLimits)
1389 { 1410 {
1390 UseMockScrollbarSettings mockScrollbarSettings; 1411 UseMockScrollbarSettings mockScrollbarSettings;
1391 1412
1392 registerMockedHttpURLLoad("no_scale_for_you.html"); 1413 registerMockedHttpURLLoad("no_scale_for_you.html");
1393 1414
1394 FixedLayoutTestWebViewClient client; 1415 FixedLayoutTestWebViewClient client;
1395 client.m_screenInfo.deviceScaleFactor = 1; 1416 client.m_screenInfo.deviceScaleFactor = 1;
1396 int viewportWidth = 640; 1417 int viewportWidth = 640;
1397 int viewportHeight = 480; 1418 int viewportHeight = 480;
1398 1419
1399 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "no_scale_for _you.html", true, 0, &client); 1420 FrameTestHelpers::WebViewHelper webViewHelper;
1400 m_webView->enableFixedLayoutMode(true); 1421 webViewHelper.initializeAndLoad(m_baseURL + "no_scale_for_you.html", true, 0 , &client);
1401 m_webView->settings()->setViewportEnabled(true); 1422 webViewHelper.webView()->enableFixedLayoutMode(true);
1402 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1423 webViewHelper.webView()->settings()->setViewportEnabled(true);
1424 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1403 1425
1404 EXPECT_EQ(2.0f, m_webView->minimumPageScaleFactor()); 1426 EXPECT_EQ(2.0f, webViewHelper.webView()->minimumPageScaleFactor());
1405 EXPECT_EQ(2.0f, m_webView->maximumPageScaleFactor()); 1427 EXPECT_EQ(2.0f, webViewHelper.webView()->maximumPageScaleFactor());
1406 1428
1407 m_webView->setIgnoreViewportTagScaleLimits(true); 1429 webViewHelper.webView()->setIgnoreViewportTagScaleLimits(true);
1408 m_webView->layout(); 1430 webViewHelper.webView()->layout();
1409 1431
1410 EXPECT_EQ(1.0f, m_webView->minimumPageScaleFactor()); 1432 EXPECT_EQ(1.0f, webViewHelper.webView()->minimumPageScaleFactor());
1411 EXPECT_EQ(5.0f, m_webView->maximumPageScaleFactor()); 1433 EXPECT_EQ(5.0f, webViewHelper.webView()->maximumPageScaleFactor());
1412 1434
1413 m_webView->setIgnoreViewportTagScaleLimits(false); 1435 webViewHelper.webView()->setIgnoreViewportTagScaleLimits(false);
1414 m_webView->layout(); 1436 webViewHelper.webView()->layout();
1415 1437
1416 EXPECT_EQ(2.0f, m_webView->minimumPageScaleFactor()); 1438 EXPECT_EQ(2.0f, webViewHelper.webView()->minimumPageScaleFactor());
1417 EXPECT_EQ(2.0f, m_webView->maximumPageScaleFactor()); 1439 EXPECT_EQ(2.0f, webViewHelper.webView()->maximumPageScaleFactor());
1418 } 1440 }
1419 1441
1420 TEST_F(WebFrameTest, updateOverlayScrollbarLayers) 1442 TEST_F(WebFrameTest, updateOverlayScrollbarLayers)
1421 { 1443 {
1422 UseMockScrollbarSettings mockScrollbarSettings; 1444 UseMockScrollbarSettings mockScrollbarSettings;
1423 1445
1424 registerMockedHttpURLLoad("large-div.html"); 1446 registerMockedHttpURLLoad("large-div.html");
1425 1447
1426 int viewWidth = 500; 1448 int viewWidth = 500;
1427 int viewHeight = 500; 1449 int viewHeight = 500;
1428 1450
1429 createCompositingWebView(); 1451 OwnPtr<FakeCompositingWebViewClient> fakeCompositingWebViewClient = adoptPtr (new FakeCompositingWebViewClient());
1430 m_webView->resize(WebSize(viewWidth, viewHeight)); 1452 FrameTestHelpers::WebViewHelper webViewHelper;
1431 FrameTestHelpers::loadFrame(m_webView->mainFrame(), m_baseURL + "large-div.h tml"); 1453 webViewHelper.initialize(true, &fakeCompositingWebViewClient->m_fakeWebFrame Client, fakeCompositingWebViewClient.get(), &configueCompositingWebView);
1454
1455 webViewHelper.webView()->resize(WebSize(viewWidth, viewHeight));
1456 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL + "large-div.html");
1432 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 1457 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
1433 m_webView->layout(); 1458 webViewHelper.webView()->layout();
1434 1459
1435 WebCore::FrameView* view = webViewImpl()->mainFrameImpl()->frameView(); 1460 WebCore::FrameView* view = webViewHelper.webViewImpl()->mainFrameImpl()->fra meView();
1436 EXPECT_TRUE(view->renderView()->compositor()->layerForHorizontalScrollbar()) ; 1461 EXPECT_TRUE(view->renderView()->compositor()->layerForHorizontalScrollbar()) ;
1437 EXPECT_TRUE(view->renderView()->compositor()->layerForVerticalScrollbar()); 1462 EXPECT_TRUE(view->renderView()->compositor()->layerForVerticalScrollbar());
1438 1463
1439 m_webView->resize(WebSize(viewWidth * 10, viewHeight * 10)); 1464 webViewHelper.webView()->resize(WebSize(viewWidth * 10, viewHeight * 10));
1440 m_webView->layout(); 1465 webViewHelper.webView()->layout();
1441 EXPECT_FALSE(view->renderView()->compositor()->layerForHorizontalScrollbar() ); 1466 EXPECT_FALSE(view->renderView()->compositor()->layerForHorizontalScrollbar() );
1442 EXPECT_FALSE(view->renderView()->compositor()->layerForVerticalScrollbar()); 1467 EXPECT_FALSE(view->renderView()->compositor()->layerForVerticalScrollbar());
1443 } 1468 }
1444 1469
1445 void setScaleAndScrollAndLayout(WebKit::WebView* webView, WebPoint scroll, float scale) 1470 void setScaleAndScrollAndLayout(WebKit::WebView* webView, WebPoint scroll, float scale)
1446 { 1471 {
1447 webView->setPageScaleFactor(scale, WebPoint(scroll.x, scroll.y)); 1472 webView->setPageScaleFactor(scale, WebPoint(scroll.x, scroll.y));
1448 webView->layout(); 1473 webView->layout();
1449 } 1474 }
1450 1475
1451 TEST_F(WebFrameTest, DivAutoZoomParamsTest) 1476 TEST_F(WebFrameTest, DivAutoZoomParamsTest)
1452 { 1477 {
1453 registerMockedHttpURLLoad("get_scale_for_auto_zoom_into_div_test.html"); 1478 registerMockedHttpURLLoad("get_scale_for_auto_zoom_into_div_test.html");
1454 1479
1455 const float deviceScaleFactor = 2.0f; 1480 const float deviceScaleFactor = 2.0f;
1456 int viewportWidth = 640 / deviceScaleFactor; 1481 int viewportWidth = 640 / deviceScaleFactor;
1457 int viewportHeight = 1280 / deviceScaleFactor; 1482 int viewportHeight = 1280 / deviceScaleFactor;
1458 float doubleTapZoomAlreadyLegibleRatio = 1.2f; 1483 float doubleTapZoomAlreadyLegibleRatio = 1.2f;
1459 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_fo r_auto_zoom_into_div_test.html"); // 1484 FrameTestHelpers::WebViewHelper webViewHelper;
1460 m_webView->setDeviceScaleFactor(deviceScaleFactor); 1485 webViewHelper.initializeAndLoad(m_baseURL + "get_scale_for_auto_zoom_into_di v_test.html");
1461 m_webView->setPageScaleFactorLimits(0.01f, 4); 1486 webViewHelper.webView()->setDeviceScaleFactor(deviceScaleFactor);
1462 m_webView->setPageScaleFactor(0.5f, WebPoint(0, 0)); 1487 webViewHelper.webView()->setPageScaleFactorLimits(0.01f, 4);
1463 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1488 webViewHelper.webView()->setPageScaleFactor(0.5f, WebPoint(0, 0));
1464 m_webView->enableFixedLayoutMode(true); 1489 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1465 m_webView->layout(); 1490 webViewHelper.webView()->enableFixedLayoutMode(true);
1491 webViewHelper.webView()->layout();
1466 1492
1467 WebRect wideDiv(200, 100, 400, 150); 1493 WebRect wideDiv(200, 100, 400, 150);
1468 WebRect tallDiv(200, 300, 400, 800); 1494 WebRect tallDiv(200, 300, 400, 800);
1469 WebRect doubleTapPointWide(wideDiv.x + 50, wideDiv.y + 50, touchPointPadding , touchPointPadding); 1495 WebRect doubleTapPointWide(wideDiv.x + 50, wideDiv.y + 50, touchPointPadding , touchPointPadding);
1470 WebRect doubleTapPointTall(tallDiv.x + 50, tallDiv.y + 50, touchPointPadding , touchPointPadding); 1496 WebRect doubleTapPointTall(tallDiv.x + 50, tallDiv.y + 50, touchPointPadding , touchPointPadding);
1471 WebRect wideBlockBounds; 1497 WebRect wideBlockBounds;
1472 WebRect tallBlockBounds; 1498 WebRect tallBlockBounds;
1473 float scale; 1499 float scale;
1474 WebPoint scroll; 1500 WebPoint scroll;
1475 1501
1476 float doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFact or() * doubleTapZoomAlreadyLegibleRatio; 1502 float doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimu mPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio;
1477 1503
1478 // Test double-tap zooming into wide div. 1504 // Test double-tap zooming into wide div.
1479 wideBlockBounds = webViewImpl()->computeBlockBounds(doubleTapPointWide, fals e); 1505 wideBlockBounds = webViewHelper.webViewImpl()->computeBlockBounds(doubleTapP ointWide, false);
1480 webViewImpl()->computeScaleAndScrollForBlockRect(WebPoint(doubleTapPointWide .x, doubleTapPointWide.y), wideBlockBounds, touchPointPadding, doubleTapZoomAlre adyLegibleScale, scale, scroll); 1506 webViewHelper.webViewImpl()->computeScaleAndScrollForBlockRect(WebPoint(doub leTapPointWide.x, doubleTapPointWide.y), wideBlockBounds, touchPointPadding, dou bleTapZoomAlreadyLegibleScale, scale, scroll);
1481 // The div should horizontally fill the screen (modulo margins), and 1507 // The div should horizontally fill the screen (modulo margins), and
1482 // vertically centered (modulo integer rounding). 1508 // vertically centered (modulo integer rounding).
1483 EXPECT_NEAR(viewportWidth / (float) wideDiv.width, scale, 0.1); 1509 EXPECT_NEAR(viewportWidth / (float) wideDiv.width, scale, 0.1);
1484 EXPECT_NEAR(wideDiv.x, scroll.x, 20); 1510 EXPECT_NEAR(wideDiv.x, scroll.x, 20);
1485 EXPECT_EQ(0, scroll.y); 1511 EXPECT_EQ(0, scroll.y);
1486 1512
1487 setScaleAndScrollAndLayout(webViewImpl(), scroll, scale); 1513 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), scroll, scale);
1488 1514
1489 // Test zoom out back to minimum scale. 1515 // Test zoom out back to minimum scale.
1490 wideBlockBounds = webViewImpl()->computeBlockBounds(doubleTapPointWide, fals e); 1516 wideBlockBounds = webViewHelper.webViewImpl()->computeBlockBounds(doubleTapP ointWide, false);
1491 webViewImpl()->computeScaleAndScrollForBlockRect(WebPoint(doubleTapPointWide .x, doubleTapPointWide.y), wideBlockBounds, touchPointPadding, doubleTapZoomAlre adyLegibleScale, scale, scroll); 1517 webViewHelper.webViewImpl()->computeScaleAndScrollForBlockRect(WebPoint(doub leTapPointWide.x, doubleTapPointWide.y), wideBlockBounds, touchPointPadding, dou bleTapZoomAlreadyLegibleScale, scale, scroll);
1492 1518
1493 scale = webViewImpl()->minimumPageScaleFactor(); 1519 scale = webViewHelper.webViewImpl()->minimumPageScaleFactor();
1494 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), scale); 1520 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), scal e);
1495 1521
1496 // Test double-tap zooming into tall div. 1522 // Test double-tap zooming into tall div.
1497 tallBlockBounds = webViewImpl()->computeBlockBounds(doubleTapPointTall, fals e); 1523 tallBlockBounds = webViewHelper.webViewImpl()->computeBlockBounds(doubleTapP ointTall, false);
1498 webViewImpl()->computeScaleAndScrollForBlockRect(WebPoint(doubleTapPointTall .x, doubleTapPointTall.y), tallBlockBounds, touchPointPadding, doubleTapZoomAlre adyLegibleScale, scale, scroll); 1524 webViewHelper.webViewImpl()->computeScaleAndScrollForBlockRect(WebPoint(doub leTapPointTall.x, doubleTapPointTall.y), tallBlockBounds, touchPointPadding, dou bleTapZoomAlreadyLegibleScale, scale, scroll);
1499 // The div should start at the top left of the viewport. 1525 // The div should start at the top left of the viewport.
1500 EXPECT_NEAR(viewportWidth / (float) tallDiv.width, scale, 0.1); 1526 EXPECT_NEAR(viewportWidth / (float) tallDiv.width, scale, 0.1);
1501 EXPECT_NEAR(tallDiv.x, scroll.x, 20); 1527 EXPECT_NEAR(tallDiv.x, scroll.x, 20);
1502 EXPECT_NEAR(tallDiv.y, scroll.y, 20); 1528 EXPECT_NEAR(tallDiv.y, scroll.y, 20);
1503 1529
1504 // Test for Non-doubletap scaling 1530 // Test for Non-doubletap scaling
1505 // Test zooming into div. 1531 // Test zooming into div.
1506 webViewImpl()->computeScaleAndScrollForBlockRect(WebPoint(250, 250), webView Impl()->computeBlockBounds(WebRect(250, 250, 10, 10), true), 0, doubleTapZoomAlr eadyLegibleScale, scale, scroll); 1532 webViewHelper.webViewImpl()->computeScaleAndScrollForBlockRect(WebPoint(250, 250), webViewHelper.webViewImpl()->computeBlockBounds(WebRect(250, 250, 10, 10) , true), 0, doubleTapZoomAlreadyLegibleScale, scale, scroll);
1507 EXPECT_NEAR(viewportWidth / (float) wideDiv.width, scale, 0.1); 1533 EXPECT_NEAR(viewportWidth / (float) wideDiv.width, scale, 0.1);
1508 } 1534 }
1509 1535
1510 void simulatePageScale(WebViewImpl* webViewImpl, float& scale) 1536 void simulatePageScale(WebViewImpl* webViewImpl, float& scale)
1511 { 1537 {
1512 WebCore::IntSize scrollDelta = webViewImpl->fakePageScaleAnimationTargetPosi tionForTesting() - webViewImpl->mainFrameImpl()->frameView()->scrollPosition(); 1538 WebCore::IntSize scrollDelta = webViewImpl->fakePageScaleAnimationTargetPosi tionForTesting() - webViewImpl->mainFrameImpl()->frameView()->scrollPosition();
1513 float scaleDelta = webViewImpl->fakePageScaleAnimationPageScaleForTesting() / webViewImpl->pageScaleFactor(); 1539 float scaleDelta = webViewImpl->fakePageScaleAnimationPageScaleForTesting() / webViewImpl->pageScaleFactor();
1514 webViewImpl->applyScrollAndScale(scrollDelta, scaleDelta); 1540 webViewImpl->applyScrollAndScale(scrollDelta, scaleDelta);
1515 scale = webViewImpl->pageScaleFactor(); 1541 scale = webViewImpl->pageScaleFactor();
1516 } 1542 }
(...skipping 12 matching lines...) Expand all
1529 } 1555 }
1530 1556
1531 TEST_F(WebFrameTest, DivAutoZoomWideDivTest) 1557 TEST_F(WebFrameTest, DivAutoZoomWideDivTest)
1532 { 1558 {
1533 registerMockedHttpURLLoad("get_wide_div_for_auto_zoom_test.html"); 1559 registerMockedHttpURLLoad("get_wide_div_for_auto_zoom_test.html");
1534 1560
1535 const float deviceScaleFactor = 2.0f; 1561 const float deviceScaleFactor = 2.0f;
1536 int viewportWidth = 640 / deviceScaleFactor; 1562 int viewportWidth = 640 / deviceScaleFactor;
1537 int viewportHeight = 1280 / deviceScaleFactor; 1563 int viewportHeight = 1280 / deviceScaleFactor;
1538 float doubleTapZoomAlreadyLegibleRatio = 1.2f; 1564 float doubleTapZoomAlreadyLegibleRatio = 1.2f;
1539 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_wide_div _for_auto_zoom_test.html"); 1565 FrameTestHelpers::WebViewHelper webViewHelper;
1540 m_webView->enableFixedLayoutMode(true); 1566 webViewHelper.initializeAndLoad(m_baseURL + "get_wide_div_for_auto_zoom_test .html");
1541 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1567 webViewHelper.webView()->enableFixedLayoutMode(true);
1542 m_webView->setPageScaleFactorLimits(1.0f, 4); 1568 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1543 m_webView->setDeviceScaleFactor(deviceScaleFactor); 1569 webViewHelper.webView()->setPageScaleFactorLimits(1.0f, 4);
1544 m_webView->setPageScaleFactor(1.0f, WebPoint(0, 0)); 1570 webViewHelper.webView()->setDeviceScaleFactor(deviceScaleFactor);
1545 m_webView->layout(); 1571 webViewHelper.webView()->setPageScaleFactor(1.0f, WebPoint(0, 0));
1572 webViewHelper.webView()->layout();
1546 1573
1547 webViewImpl()->enableFakePageScaleAnimationForTesting(true); 1574 webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true);
1548 1575
1549 float doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFact or() * doubleTapZoomAlreadyLegibleRatio; 1576 float doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimu mPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio;
1550 1577
1551 WebRect div(0, 100, viewportWidth, 150); 1578 WebRect div(0, 100, viewportWidth, 150);
1552 WebPoint point(div.x + 50, div.y + 50); 1579 WebPoint point(div.x + 50, div.y + 50);
1553 float scale; 1580 float scale;
1554 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); 1581 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL egibleRatio) / 2);
1555 1582
1556 simulateDoubleTap(webViewImpl(), point, scale); 1583 simulateDoubleTap(webViewHelper.webViewImpl(), point, scale);
1557 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); 1584 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale);
1558 simulateDoubleTap(webViewImpl(), point, scale); 1585 simulateDoubleTap(webViewHelper.webViewImpl(), point, scale);
1559 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); 1586 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale );
1560 } 1587 }
1561 1588
1562 TEST_F(WebFrameTest, DivAutoZoomVeryTallTest) 1589 TEST_F(WebFrameTest, DivAutoZoomVeryTallTest)
1563 { 1590 {
1564 // When a block is taller than the viewport and a zoom targets a lower part 1591 // When a block is taller than the viewport and a zoom targets a lower part
1565 // of it, then we should keep the target point onscreen instead of snapping 1592 // of it, then we should keep the target point onscreen instead of snapping
1566 // back up the top of the block. 1593 // back up the top of the block.
1567 registerMockedHttpURLLoad("very_tall_div.html"); 1594 registerMockedHttpURLLoad("very_tall_div.html");
1568 1595
1569 const float deviceScaleFactor = 2.0f; 1596 const float deviceScaleFactor = 2.0f;
1570 int viewportWidth = 640 / deviceScaleFactor; 1597 int viewportWidth = 640 / deviceScaleFactor;
1571 int viewportHeight = 1280 / deviceScaleFactor; 1598 int viewportHeight = 1280 / deviceScaleFactor;
1572 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "very_tall_di v.html"); 1599 FrameTestHelpers::WebViewHelper webViewHelper;
1573 m_webView->enableFixedLayoutMode(true); 1600 webViewHelper.initializeAndLoad(m_baseURL + "very_tall_div.html");
1574 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1601 webViewHelper.webView()->enableFixedLayoutMode(true);
1575 m_webView->setPageScaleFactorLimits(1.0f, 4); 1602 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1576 m_webView->setDeviceScaleFactor(deviceScaleFactor); 1603 webViewHelper.webView()->setPageScaleFactorLimits(1.0f, 4);
1577 m_webView->setPageScaleFactor(1.0f, WebPoint(0, 0)); 1604 webViewHelper.webView()->setDeviceScaleFactor(deviceScaleFactor);
1578 m_webView->layout(); 1605 webViewHelper.webView()->setPageScaleFactor(1.0f, WebPoint(0, 0));
1606 webViewHelper.webView()->layout();
1579 1607
1580 WebRect div(200, 300, 400, 5000); 1608 WebRect div(200, 300, 400, 5000);
1581 WebPoint point(div.x + 50, div.y + 3000); 1609 WebPoint point(div.x + 50, div.y + 3000);
1582 float scale; 1610 float scale;
1583 WebPoint scroll; 1611 WebPoint scroll;
1584 1612
1585 WebRect blockBounds = webViewImpl()->computeBlockBounds(WebRect(point.x, poi nt.y, 0, 0), true); 1613 WebRect blockBounds = webViewHelper.webViewImpl()->computeBlockBounds(WebRec t(point.x, point.y, 0, 0), true);
1586 webViewImpl()->computeScaleAndScrollForBlockRect(point, blockBounds, 0, 1.0f , scale, scroll); 1614 webViewHelper.webViewImpl()->computeScaleAndScrollForBlockRect(point, blockB ounds, 0, 1.0f, scale, scroll);
1587 EXPECT_EQ(scale, 1.0f); 1615 EXPECT_EQ(scale, 1.0f);
1588 EXPECT_EQ(scroll.y, 2660); 1616 EXPECT_EQ(scroll.y, 2660);
1589 } 1617 }
1590 1618
1591 TEST_F(WebFrameTest, DivAutoZoomMultipleDivsTest) 1619 TEST_F(WebFrameTest, DivAutoZoomMultipleDivsTest)
1592 { 1620 {
1593 registerMockedHttpURLLoad("get_multiple_divs_for_auto_zoom_test.html"); 1621 registerMockedHttpURLLoad("get_multiple_divs_for_auto_zoom_test.html");
1594 1622
1595 const float deviceScaleFactor = 2.0f; 1623 const float deviceScaleFactor = 2.0f;
1596 int viewportWidth = 640 / deviceScaleFactor; 1624 int viewportWidth = 640 / deviceScaleFactor;
1597 int viewportHeight = 1280 / deviceScaleFactor; 1625 int viewportHeight = 1280 / deviceScaleFactor;
1598 float doubleTapZoomAlreadyLegibleRatio = 1.2f; 1626 float doubleTapZoomAlreadyLegibleRatio = 1.2f;
1599 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_multiple _divs_for_auto_zoom_test.html"); 1627 FrameTestHelpers::WebViewHelper webViewHelper;
1600 m_webView->enableFixedLayoutMode(true); 1628 webViewHelper.initializeAndLoad(m_baseURL + "get_multiple_divs_for_auto_zoom _test.html");
1601 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1629 webViewHelper.webView()->enableFixedLayoutMode(true);
1602 m_webView->setPageScaleFactorLimits(0.5f, 4); 1630 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1603 m_webView->setDeviceScaleFactor(deviceScaleFactor); 1631 webViewHelper.webView()->setPageScaleFactorLimits(0.5f, 4);
1604 m_webView->setPageScaleFactor(0.5f, WebPoint(0, 0)); 1632 webViewHelper.webView()->setDeviceScaleFactor(deviceScaleFactor);
1605 m_webView->layout(); 1633 webViewHelper.webView()->setPageScaleFactor(0.5f, WebPoint(0, 0));
1634 webViewHelper.webView()->layout();
1606 1635
1607 webViewImpl()->enableFakePageScaleAnimationForTesting(true); 1636 webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true);
1608 1637
1609 WebRect topDiv(200, 100, 200, 150); 1638 WebRect topDiv(200, 100, 200, 150);
1610 WebRect bottomDiv(200, 300, 200, 150); 1639 WebRect bottomDiv(200, 300, 200, 150);
1611 WebPoint topPoint(topDiv.x + 50, topDiv.y + 50); 1640 WebPoint topPoint(topDiv.x + 50, topDiv.y + 50);
1612 WebPoint bottomPoint(bottomDiv.x + 50, bottomDiv.y + 50); 1641 WebPoint bottomPoint(bottomDiv.x + 50, bottomDiv.y + 50);
1613 float scale; 1642 float scale;
1614 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); 1643 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL egibleRatio) / 2);
1615 1644
1616 // Test double tap on two different divs 1645 // Test double tap on two different divs
1617 // After first zoom, we should go back to minimum page scale with a second d ouble tap. 1646 // After first zoom, we should go back to minimum page scale with a second d ouble tap.
1618 simulateDoubleTap(webViewImpl(), topPoint, scale); 1647 simulateDoubleTap(webViewHelper.webViewImpl(), topPoint, scale);
1619 EXPECT_FLOAT_EQ(1, scale); 1648 EXPECT_FLOAT_EQ(1, scale);
1620 simulateDoubleTap(webViewImpl(), bottomPoint, scale); 1649 simulateDoubleTap(webViewHelper.webViewImpl(), bottomPoint, scale);
1621 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); 1650 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale );
1622 1651
1623 // If the user pinch zooms after double tap, a second double tap should zoom back to the div. 1652 // If the user pinch zooms after double tap, a second double tap should zoom back to the div.
1624 simulateDoubleTap(webViewImpl(), topPoint, scale); 1653 simulateDoubleTap(webViewHelper.webViewImpl(), topPoint, scale);
1625 EXPECT_FLOAT_EQ(1, scale); 1654 EXPECT_FLOAT_EQ(1, scale);
1626 webViewImpl()->applyScrollAndScale(WebSize(), 0.6f); 1655 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(), 0.6f);
1627 simulateDoubleTap(webViewImpl(), bottomPoint, scale); 1656 simulateDoubleTap(webViewHelper.webViewImpl(), bottomPoint, scale);
1628 EXPECT_FLOAT_EQ(1, scale); 1657 EXPECT_FLOAT_EQ(1, scale);
1629 simulateDoubleTap(webViewImpl(), bottomPoint, scale); 1658 simulateDoubleTap(webViewHelper.webViewImpl(), bottomPoint, scale);
1630 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); 1659 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale );
1631 1660
1632 // If we didn't yet get an auto-zoom update and a second double-tap arrives, should go back to minimum scale. 1661 // If we didn't yet get an auto-zoom update and a second double-tap arrives, should go back to minimum scale.
1633 webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); 1662 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(), 1.1f);
1634 webViewImpl()->animateDoubleTapZoom(topPoint); 1663 webViewHelper.webViewImpl()->animateDoubleTapZoom(topPoint);
1635 EXPECT_TRUE(webViewImpl()->fakeDoubleTapAnimationPendingForTesting()); 1664 EXPECT_TRUE(webViewHelper.webViewImpl()->fakeDoubleTapAnimationPendingForTes ting());
1636 simulateDoubleTap(webViewImpl(), bottomPoint, scale); 1665 simulateDoubleTap(webViewHelper.webViewImpl(), bottomPoint, scale);
1637 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); 1666 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale );
1638 } 1667 }
1639 1668
1640 TEST_F(WebFrameTest, DivAutoZoomScaleBoundsTest) 1669 TEST_F(WebFrameTest, DivAutoZoomScaleBoundsTest)
1641 { 1670 {
1642 registerMockedHttpURLLoad("get_scale_bounds_check_for_auto_zoom_test.html"); 1671 registerMockedHttpURLLoad("get_scale_bounds_check_for_auto_zoom_test.html");
1643 1672
1644 int viewportWidth = 320; 1673 int viewportWidth = 320;
1645 int viewportHeight = 480; 1674 int viewportHeight = 480;
1646 float doubleTapZoomAlreadyLegibleRatio = 1.2f; 1675 float doubleTapZoomAlreadyLegibleRatio = 1.2f;
1647 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_bo unds_check_for_auto_zoom_test.html"); 1676 FrameTestHelpers::WebViewHelper webViewHelper;
1648 m_webView->enableFixedLayoutMode(true); 1677 webViewHelper.initializeAndLoad(m_baseURL + "get_scale_bounds_check_for_auto _zoom_test.html");
1649 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1678 webViewHelper.webView()->enableFixedLayoutMode(true);
1650 m_webView->setDeviceScaleFactor(1.5f); 1679 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1651 m_webView->layout(); 1680 webViewHelper.webView()->setDeviceScaleFactor(1.5f);
1681 webViewHelper.webView()->layout();
1652 1682
1653 webViewImpl()->enableFakePageScaleAnimationForTesting(true); 1683 webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true);
1654 1684
1655 WebRect div(200, 100, 200, 150); 1685 WebRect div(200, 100, 200, 150);
1656 WebPoint doubleTapPoint(div.x + 50, div.y + 50); 1686 WebPoint doubleTapPoint(div.x + 50, div.y + 50);
1657 float scale; 1687 float scale;
1658 1688
1659 // Test double tap scale bounds. 1689 // Test double tap scale bounds.
1660 // minimumPageScale < doubleTapZoomAlreadyLegibleScale < 1 1690 // minimumPageScale < doubleTapZoomAlreadyLegibleScale < 1
1661 m_webView->setPageScaleFactorLimits(0.5f, 4); 1691 webViewHelper.webView()->setPageScaleFactorLimits(0.5f, 4);
1662 m_webView->layout(); 1692 webViewHelper.webView()->layout();
1663 float doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFact or() * doubleTapZoomAlreadyLegibleRatio; 1693 float doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimu mPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio;
1664 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); 1694 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL egibleRatio) / 2);
1665 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1695 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1666 EXPECT_FLOAT_EQ(1, scale); 1696 EXPECT_FLOAT_EQ(1, scale);
1667 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1697 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1668 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); 1698 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale );
1669 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1699 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1670 EXPECT_FLOAT_EQ(1, scale); 1700 EXPECT_FLOAT_EQ(1, scale);
1671 1701
1672 // Zoom in to reset double_tap_zoom_in_effect flag. 1702 // Zoom in to reset double_tap_zoom_in_effect flag.
1673 webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); 1703 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(), 1.1f);
1674 // 1 < minimumPageScale < doubleTapZoomAlreadyLegibleScale 1704 // 1 < minimumPageScale < doubleTapZoomAlreadyLegibleScale
1675 m_webView->setPageScaleFactorLimits(1.1f, 4); 1705 webViewHelper.webView()->setPageScaleFactorLimits(1.1f, 4);
1676 m_webView->layout(); 1706 webViewHelper.webView()->layout();
1677 doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio; 1707 doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimumPageS caleFactor() * doubleTapZoomAlreadyLegibleRatio;
1678 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); 1708 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL egibleRatio) / 2);
1679 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1709 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1680 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); 1710 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale);
1681 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1711 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1682 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); 1712 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale );
1683 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1713 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1684 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); 1714 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale);
1685 1715
1686 // Zoom in to reset double_tap_zoom_in_effect flag. 1716 // Zoom in to reset double_tap_zoom_in_effect flag.
1687 webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); 1717 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(), 1.1f);
1688 // minimumPageScale < 1 < doubleTapZoomAlreadyLegibleScale 1718 // minimumPageScale < 1 < doubleTapZoomAlreadyLegibleScale
1689 m_webView->setPageScaleFactorLimits(0.95f, 4); 1719 webViewHelper.webView()->setPageScaleFactorLimits(0.95f, 4);
1690 m_webView->layout(); 1720 webViewHelper.webView()->layout();
1691 doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio; 1721 doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimumPageS caleFactor() * doubleTapZoomAlreadyLegibleRatio;
1692 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); 1722 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL egibleRatio) / 2);
1693 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1723 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1694 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); 1724 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale);
1695 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1725 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1696 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); 1726 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale );
1697 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1727 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1698 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); 1728 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale);
1699 } 1729 }
1700 1730
1701 TEST_F(WebFrameTest, DivAutoZoomScaleFontScaleFactorTest) 1731 TEST_F(WebFrameTest, DivAutoZoomScaleFontScaleFactorTest)
1702 { 1732 {
1703 registerMockedHttpURLLoad("get_scale_bounds_check_for_auto_zoom_test.html"); 1733 registerMockedHttpURLLoad("get_scale_bounds_check_for_auto_zoom_test.html");
1704 1734
1705 int viewportWidth = 320; 1735 int viewportWidth = 320;
1706 int viewportHeight = 480; 1736 int viewportHeight = 480;
1707 float doubleTapZoomAlreadyLegibleRatio = 1.2f; 1737 float doubleTapZoomAlreadyLegibleRatio = 1.2f;
1708 float textAutosizingFontScaleFactor = 1.13f; 1738 float textAutosizingFontScaleFactor = 1.13f;
1709 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_bo unds_check_for_auto_zoom_test.html"); 1739 FrameTestHelpers::WebViewHelper webViewHelper;
1710 m_webView->enableFixedLayoutMode(true); 1740 webViewHelper.initializeAndLoad(m_baseURL + "get_scale_bounds_check_for_auto _zoom_test.html");
1711 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1741 webViewHelper.webView()->enableFixedLayoutMode(true);
1712 m_webView->layout(); 1742 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1743 webViewHelper.webView()->layout();
1713 1744
1714 webViewImpl()->enableFakePageScaleAnimationForTesting(true); 1745 webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true);
1715 webViewImpl()->page()->settings().setTextAutosizingEnabled(true); 1746 webViewHelper.webViewImpl()->page()->settings().setTextAutosizingEnabled(tru e);
1716 webViewImpl()->page()->settings().setTextAutosizingFontScaleFactor(textAutos izingFontScaleFactor); 1747 webViewHelper.webViewImpl()->page()->settings().setTextAutosizingFontScaleFa ctor(textAutosizingFontScaleFactor);
1717 1748
1718 WebRect div(200, 100, 200, 150); 1749 WebRect div(200, 100, 200, 150);
1719 WebPoint doubleTapPoint(div.x + 50, div.y + 50); 1750 WebPoint doubleTapPoint(div.x + 50, div.y + 50);
1720 float scale; 1751 float scale;
1721 1752
1722 // Test double tap scale bounds. 1753 // Test double tap scale bounds.
1723 // minimumPageScale < doubleTapZoomAlreadyLegibleScale < 1 < textAutosizingF ontScaleFactor 1754 // minimumPageScale < doubleTapZoomAlreadyLegibleScale < 1 < textAutosizingF ontScaleFactor
1724 float legibleScale = textAutosizingFontScaleFactor; 1755 float legibleScale = textAutosizingFontScaleFactor;
1725 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); 1756 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL egibleRatio) / 2);
1726 float doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFact or() * doubleTapZoomAlreadyLegibleRatio; 1757 float doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimu mPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio;
1727 m_webView->setPageScaleFactorLimits(0.5f, 4); 1758 webViewHelper.webView()->setPageScaleFactorLimits(0.5f, 4);
1728 m_webView->layout(); 1759 webViewHelper.webView()->layout();
1729 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1760 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1730 EXPECT_FLOAT_EQ(legibleScale, scale); 1761 EXPECT_FLOAT_EQ(legibleScale, scale);
1731 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1762 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1732 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); 1763 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale );
1733 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1764 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1734 EXPECT_FLOAT_EQ(legibleScale, scale); 1765 EXPECT_FLOAT_EQ(legibleScale, scale);
1735 1766
1736 // Zoom in to reset double_tap_zoom_in_effect flag. 1767 // Zoom in to reset double_tap_zoom_in_effect flag.
1737 webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); 1768 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(), 1.1f);
1738 // 1 < textAutosizingFontScaleFactor < minimumPageScale < doubleTapZoomAlrea dyLegibleScale 1769 // 1 < textAutosizingFontScaleFactor < minimumPageScale < doubleTapZoomAlrea dyLegibleScale
1739 m_webView->setPageScaleFactorLimits(1.0f, 4); 1770 webViewHelper.webView()->setPageScaleFactorLimits(1.0f, 4);
1740 m_webView->layout(); 1771 webViewHelper.webView()->layout();
1741 doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio; 1772 doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimumPageS caleFactor() * doubleTapZoomAlreadyLegibleRatio;
1742 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); 1773 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL egibleRatio) / 2);
1743 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1774 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1744 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); 1775 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale);
1745 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1776 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1746 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); 1777 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale );
1747 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1778 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1748 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); 1779 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale);
1749 1780
1750 // Zoom in to reset double_tap_zoom_in_effect flag. 1781 // Zoom in to reset double_tap_zoom_in_effect flag.
1751 webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); 1782 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(), 1.1f);
1752 // minimumPageScale < 1 < textAutosizingFontScaleFactor < doubleTapZoomAlrea dyLegibleScale 1783 // minimumPageScale < 1 < textAutosizingFontScaleFactor < doubleTapZoomAlrea dyLegibleScale
1753 m_webView->setPageScaleFactorLimits(0.95f, 4); 1784 webViewHelper.webView()->setPageScaleFactorLimits(0.95f, 4);
1754 m_webView->layout(); 1785 webViewHelper.webView()->layout();
1755 doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio; 1786 doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimumPageS caleFactor() * doubleTapZoomAlreadyLegibleRatio;
1756 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); 1787 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL egibleRatio) / 2);
1757 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1788 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1758 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); 1789 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale);
1759 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1790 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1760 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); 1791 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale );
1761 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1792 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1762 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); 1793 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale);
1763 1794
1764 // Zoom in to reset double_tap_zoom_in_effect flag. 1795 // Zoom in to reset double_tap_zoom_in_effect flag.
1765 webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); 1796 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(), 1.1f);
1766 // minimumPageScale < 1 < doubleTapZoomAlreadyLegibleScale < textAutosizingF ontScaleFactor 1797 // minimumPageScale < 1 < doubleTapZoomAlreadyLegibleScale < textAutosizingF ontScaleFactor
1767 m_webView->setPageScaleFactorLimits(0.9f, 4); 1798 webViewHelper.webView()->setPageScaleFactorLimits(0.9f, 4);
1768 m_webView->layout(); 1799 webViewHelper.webView()->layout();
1769 doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio; 1800 doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimumPageS caleFactor() * doubleTapZoomAlreadyLegibleRatio;
1770 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); 1801 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL egibleRatio) / 2);
1771 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1802 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1772 EXPECT_FLOAT_EQ(legibleScale, scale); 1803 EXPECT_FLOAT_EQ(legibleScale, scale);
1773 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1804 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1774 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); 1805 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale );
1775 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); 1806 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale);
1776 EXPECT_FLOAT_EQ(legibleScale, scale); 1807 EXPECT_FLOAT_EQ(legibleScale, scale);
1777 } 1808 }
1778 1809
1779 TEST_F(WebFrameTest, DivMultipleTargetZoomMultipleDivsTest) 1810 TEST_F(WebFrameTest, DivMultipleTargetZoomMultipleDivsTest)
1780 { 1811 {
1781 registerMockedHttpURLLoad("get_multiple_divs_for_auto_zoom_test.html"); 1812 registerMockedHttpURLLoad("get_multiple_divs_for_auto_zoom_test.html");
1782 1813
1783 const float deviceScaleFactor = 2.0f; 1814 const float deviceScaleFactor = 2.0f;
1784 int viewportWidth = 640 / deviceScaleFactor; 1815 int viewportWidth = 640 / deviceScaleFactor;
1785 int viewportHeight = 1280 / deviceScaleFactor; 1816 int viewportHeight = 1280 / deviceScaleFactor;
1786 float doubleTapZoomAlreadyLegibleRatio = 1.2f; 1817 float doubleTapZoomAlreadyLegibleRatio = 1.2f;
1787 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_multiple _divs_for_auto_zoom_test.html"); 1818 FrameTestHelpers::WebViewHelper webViewHelper;
1788 m_webView->enableFixedLayoutMode(true); 1819 webViewHelper.initializeAndLoad(m_baseURL + "get_multiple_divs_for_auto_zoom _test.html");
1789 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1820 webViewHelper.webView()->enableFixedLayoutMode(true);
1790 m_webView->setPageScaleFactorLimits(0.5f, 4); 1821 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1791 m_webView->setDeviceScaleFactor(deviceScaleFactor); 1822 webViewHelper.webView()->setPageScaleFactorLimits(0.5f, 4);
1792 m_webView->setPageScaleFactor(0.5f, WebPoint(0, 0)); 1823 webViewHelper.webView()->setDeviceScaleFactor(deviceScaleFactor);
1793 m_webView->layout(); 1824 webViewHelper.webView()->setPageScaleFactor(0.5f, WebPoint(0, 0));
1825 webViewHelper.webView()->layout();
1794 1826
1795 webViewImpl()->enableFakePageScaleAnimationForTesting(true); 1827 webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true);
1796 1828
1797 WebRect viewportRect(0, 0, viewportWidth, viewportHeight); 1829 WebRect viewportRect(0, 0, viewportWidth, viewportHeight);
1798 WebRect topDiv(200, 100, 200, 150); 1830 WebRect topDiv(200, 100, 200, 150);
1799 WebRect bottomDiv(200, 300, 200, 150); 1831 WebRect bottomDiv(200, 300, 200, 150);
1800 float scale; 1832 float scale;
1801 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); 1833 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL egibleRatio) / 2);
1802 1834
1803 simulateMultiTargetZoom(webViewImpl(), topDiv, scale); 1835 simulateMultiTargetZoom(webViewHelper.webViewImpl(), topDiv, scale);
1804 EXPECT_FLOAT_EQ(1, scale); 1836 EXPECT_FLOAT_EQ(1, scale);
1805 simulateMultiTargetZoom(webViewImpl(), bottomDiv, scale); 1837 simulateMultiTargetZoom(webViewHelper.webViewImpl(), bottomDiv, scale);
1806 EXPECT_FLOAT_EQ(1, scale); 1838 EXPECT_FLOAT_EQ(1, scale);
1807 simulateMultiTargetZoom(webViewImpl(), viewportRect, scale); 1839 simulateMultiTargetZoom(webViewHelper.webViewImpl(), viewportRect, scale);
1808 EXPECT_FLOAT_EQ(1, scale); 1840 EXPECT_FLOAT_EQ(1, scale);
1809 webViewImpl()->setPageScaleFactor(webViewImpl()->minimumPageScaleFactor(), W ebPoint(0, 0)); 1841 webViewHelper.webViewImpl()->setPageScaleFactor(webViewHelper.webViewImpl()- >minimumPageScaleFactor(), WebPoint(0, 0));
1810 simulateMultiTargetZoom(webViewImpl(), topDiv, scale); 1842 simulateMultiTargetZoom(webViewHelper.webViewImpl(), topDiv, scale);
1811 EXPECT_FLOAT_EQ(1, scale); 1843 EXPECT_FLOAT_EQ(1, scale);
1812 } 1844 }
1813 1845
1814 TEST_F(WebFrameTest, DivScrollIntoEditableTest) 1846 TEST_F(WebFrameTest, DivScrollIntoEditableTest)
1815 { 1847 {
1816 registerMockedHttpURLLoad("get_scale_for_zoom_into_editable_test.html"); 1848 registerMockedHttpURLLoad("get_scale_for_zoom_into_editable_test.html");
1817 1849
1818 int viewportWidth = 450; 1850 int viewportWidth = 450;
1819 int viewportHeight = 300; 1851 int viewportHeight = 300;
1820 float leftBoxRatio = 0.3f; 1852 float leftBoxRatio = 0.3f;
1821 int caretPadding = 10; 1853 int caretPadding = 10;
1822 float minReadableCaretHeight = 18.0f; 1854 float minReadableCaretHeight = 18.0f;
1823 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_fo r_zoom_into_editable_test.html"); 1855 FrameTestHelpers::WebViewHelper webViewHelper;
1824 m_webView->enableFixedLayoutMode(true); 1856 webViewHelper.initializeAndLoad(m_baseURL + "get_scale_for_zoom_into_editabl e_test.html");
1825 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1857 webViewHelper.webView()->enableFixedLayoutMode(true);
1826 m_webView->setPageScaleFactorLimits(1, 4); 1858 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1827 m_webView->layout(); 1859 webViewHelper.webView()->setPageScaleFactorLimits(1, 4);
1828 m_webView->setDeviceScaleFactor(1.5f); 1860 webViewHelper.webView()->layout();
1829 m_webView->settings()->setAutoZoomFocusedNodeToLegibleScale(true); 1861 webViewHelper.webView()->setDeviceScaleFactor(1.5f);
1862 webViewHelper.webView()->settings()->setAutoZoomFocusedNodeToLegibleScale(tr ue);
1830 1863
1831 webViewImpl()->enableFakePageScaleAnimationForTesting(true); 1864 webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true);
1832 1865
1833 WebRect editBoxWithText(200, 200, 250, 20); 1866 WebRect editBoxWithText(200, 200, 250, 20);
1834 WebRect editBoxWithNoText(200, 250, 250, 20); 1867 WebRect editBoxWithNoText(200, 250, 250, 20);
1835 1868
1836 // Test scrolling the focused node 1869 // Test scrolling the focused node
1837 // The edit box is shorter and narrower than the viewport when legible. 1870 // The edit box is shorter and narrower than the viewport when legible.
1838 m_webView->advanceFocus(false); 1871 webViewHelper.webView()->advanceFocus(false);
1839 // Set the caret to the end of the input box. 1872 // Set the caret to the end of the input box.
1840 m_webView->mainFrame()->document().getElementById("EditBoxWithText").to<WebI nputElement>().setSelectionRange(1000, 1000); 1873 webViewHelper.webView()->mainFrame()->document().getElementById("EditBoxWith Text").to<WebInputElement>().setSelectionRange(1000, 1000);
1841 setScaleAndScrollAndLayout(m_webView, WebPoint(0, 0), 1); 1874 setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), 1);
1842 WebRect rect, caret; 1875 WebRect rect, caret;
1843 webViewImpl()->selectionBounds(caret, rect); 1876 webViewHelper.webViewImpl()->selectionBounds(caret, rect);
1844 1877
1845 float scale; 1878 float scale;
1846 WebCore::IntPoint scroll; 1879 WebCore::IntPoint scroll;
1847 bool needAnimation; 1880 bool needAnimation;
1848 webViewImpl()->computeScaleAndScrollForFocusedNode(webViewImpl()->focusedEle ment(), scale, scroll, needAnimation); 1881 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp er.webViewImpl()->focusedElement(), scale, scroll, needAnimation);
1849 EXPECT_TRUE(needAnimation); 1882 EXPECT_TRUE(needAnimation);
1850 // The edit box should be left aligned with a margin for possible label. 1883 // The edit box should be left aligned with a margin for possible label.
1851 int hScroll = editBoxWithText.x - leftBoxRatio * viewportWidth / scale; 1884 int hScroll = editBoxWithText.x - leftBoxRatio * viewportWidth / scale;
1852 EXPECT_NEAR(hScroll, scroll.x(), 1); 1885 EXPECT_NEAR(hScroll, scroll.x(), 1);
1853 int vScroll = editBoxWithText.y - (viewportHeight / scale - editBoxWithText. height) / 2; 1886 int vScroll = editBoxWithText.y - (viewportHeight / scale - editBoxWithText. height) / 2;
1854 EXPECT_NEAR(vScroll, scroll.y(), 1); 1887 EXPECT_NEAR(vScroll, scroll.y(), 1);
1855 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1); 1888 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1);
1856 1889
1857 // The edit box is wider than the viewport when legible. 1890 // The edit box is wider than the viewport when legible.
1858 viewportWidth = 200; 1891 viewportWidth = 200;
1859 viewportHeight = 150; 1892 viewportHeight = 150;
1860 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1893 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1861 setScaleAndScrollAndLayout(m_webView, WebPoint(0, 0), 1); 1894 setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), 1);
1862 webViewImpl()->selectionBounds(caret, rect); 1895 webViewHelper.webViewImpl()->selectionBounds(caret, rect);
1863 webViewImpl()->computeScaleAndScrollForFocusedNode(webViewImpl()->focusedEle ment(), scale, scroll, needAnimation); 1896 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp er.webViewImpl()->focusedElement(), scale, scroll, needAnimation);
1864 EXPECT_TRUE(needAnimation); 1897 EXPECT_TRUE(needAnimation);
1865 // The caret should be right aligned since the caret would be offscreen when the edit box is left aligned. 1898 // The caret should be right aligned since the caret would be offscreen when the edit box is left aligned.
1866 hScroll = caret.x + caret.width + caretPadding - viewportWidth / scale; 1899 hScroll = caret.x + caret.width + caretPadding - viewportWidth / scale;
1867 EXPECT_NEAR(hScroll, scroll.x(), 1); 1900 EXPECT_NEAR(hScroll, scroll.x(), 1);
1868 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1); 1901 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1);
1869 1902
1870 setScaleAndScrollAndLayout(m_webView, WebPoint(0, 0), 1); 1903 setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), 1);
1871 // Move focus to edit box with text. 1904 // Move focus to edit box with text.
1872 m_webView->advanceFocus(false); 1905 webViewHelper.webView()->advanceFocus(false);
1873 webViewImpl()->selectionBounds(caret, rect); 1906 webViewHelper.webViewImpl()->selectionBounds(caret, rect);
1874 webViewImpl()->computeScaleAndScrollForFocusedNode(webViewImpl()->focusedEle ment(), scale, scroll, needAnimation); 1907 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp er.webViewImpl()->focusedElement(), scale, scroll, needAnimation);
1875 EXPECT_TRUE(needAnimation); 1908 EXPECT_TRUE(needAnimation);
1876 // The edit box should be left aligned. 1909 // The edit box should be left aligned.
1877 hScroll = editBoxWithNoText.x; 1910 hScroll = editBoxWithNoText.x;
1878 EXPECT_NEAR(hScroll, scroll.x(), 1); 1911 EXPECT_NEAR(hScroll, scroll.x(), 1);
1879 vScroll = editBoxWithNoText.y - (viewportHeight / scale - editBoxWithNoText. height) / 2; 1912 vScroll = editBoxWithNoText.y - (viewportHeight / scale - editBoxWithNoText. height) / 2;
1880 EXPECT_NEAR(vScroll, scroll.y(), 1); 1913 EXPECT_NEAR(vScroll, scroll.y(), 1);
1881 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1); 1914 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1);
1882 1915
1883 setScaleAndScrollAndLayout(webViewImpl(), scroll, scale); 1916 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), scroll, scale);
1884 1917
1885 // Move focus back to the first edit box. 1918 // Move focus back to the first edit box.
1886 m_webView->advanceFocus(true); 1919 webViewHelper.webView()->advanceFocus(true);
1887 webViewImpl()->computeScaleAndScrollForFocusedNode(webViewImpl()->focusedEle ment(), scale, scroll, needAnimation); 1920 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp er.webViewImpl()->focusedElement(), scale, scroll, needAnimation);
1888 // The position should have stayed the same since this box was already on sc reen with the right scale. 1921 // The position should have stayed the same since this box was already on sc reen with the right scale.
1889 EXPECT_FALSE(needAnimation); 1922 EXPECT_FALSE(needAnimation);
1890 } 1923 }
1891 1924
1892 class TestReloadDoesntRedirectWebFrameClient : public WebFrameClient { 1925 class TestReloadDoesntRedirectWebFrameClient : public WebFrameClient {
1893 public: 1926 public:
1894 virtual WebNavigationPolicy decidePolicyForNavigation( 1927 virtual WebNavigationPolicy decidePolicyForNavigation(
1895 WebFrame*, WebDataSource::ExtraData*, const WebURLRequest&, WebNavigatio nType, 1928 WebFrame*, WebDataSource::ExtraData*, const WebURLRequest&, WebNavigatio nType,
1896 WebNavigationPolicy defaultPolicy, bool isRedirect) OVERRIDE 1929 WebNavigationPolicy defaultPolicy, bool isRedirect) OVERRIDE
1897 { 1930 {
1898 EXPECT_FALSE(isRedirect); 1931 EXPECT_FALSE(isRedirect);
1899 return WebNavigationPolicyCurrentTab; 1932 return WebNavigationPolicyCurrentTab;
1900 } 1933 }
1901 }; 1934 };
1902 1935
1903 TEST_F(WebFrameTest, ReloadDoesntSetRedirect) 1936 TEST_F(WebFrameTest, ReloadDoesntSetRedirect)
1904 { 1937 {
1905 // Test for case in http://crbug.com/73104. Reloading a frame very quickly 1938 // Test for case in http://crbug.com/73104. Reloading a frame very quickly
1906 // would sometimes call decidePolicyForNavigation with isRedirect=true 1939 // would sometimes call decidePolicyForNavigation with isRedirect=true
1907 registerMockedHttpURLLoad("form.html"); 1940 registerMockedHttpURLLoad("form.html");
1908 1941
1909 TestReloadDoesntRedirectWebFrameClient webFrameClient; 1942 TestReloadDoesntRedirectWebFrameClient webFrameClient;
1910 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "form.html", false, &webFrameClient); 1943 FrameTestHelpers::WebViewHelper webViewHelper;
1944 webViewHelper.initializeAndLoad(m_baseURL + "form.html", false, &webFrameCli ent);
1911 1945
1912 m_webView->mainFrame()->reload(true); 1946 webViewHelper.webView()->mainFrame()->reload(true);
1913 // start reload before request is delivered. 1947 // start reload before request is delivered.
1914 m_webView->mainFrame()->reload(true); 1948 webViewHelper.webView()->mainFrame()->reload(true);
1915 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 1949 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
1916
1917 m_webView->close();
1918 m_webView = 0;
1919 } 1950 }
1920 1951
1921 TEST_F(WebFrameTest, ReloadWithOverrideURLPreservesState) 1952 TEST_F(WebFrameTest, ReloadWithOverrideURLPreservesState)
1922 { 1953 {
1923 const std::string firstURL = "find.html"; 1954 const std::string firstURL = "find.html";
1924 const std::string secondURL = "form.html"; 1955 const std::string secondURL = "form.html";
1925 const std::string thirdURL = "history.html"; 1956 const std::string thirdURL = "history.html";
1926 const float pageScaleFactor = 1.1684f; 1957 const float pageScaleFactor = 1.1684f;
1927 const int pageWidth = 640; 1958 const int pageWidth = 640;
1928 const int pageHeight = 480; 1959 const int pageHeight = 480;
1929 1960
1930 registerMockedHttpURLLoad(firstURL); 1961 registerMockedHttpURLLoad(firstURL);
1931 registerMockedHttpURLLoad(secondURL); 1962 registerMockedHttpURLLoad(secondURL);
1932 registerMockedHttpURLLoad(thirdURL); 1963 registerMockedHttpURLLoad(thirdURL);
1933 1964
1934 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + firstURL, tru e); 1965 FrameTestHelpers::WebViewHelper webViewHelper;
1935 webViewImpl()->resize(WebSize(pageWidth, pageHeight)); 1966 webViewHelper.initializeAndLoad(m_baseURL + firstURL, true);
1936 webViewImpl()->mainFrame()->setScrollOffset(WebSize(pageWidth / 4, pageHeigh t / 4)); 1967 webViewHelper.webViewImpl()->resize(WebSize(pageWidth, pageHeight));
1937 webViewImpl()->setPageScaleFactorPreservingScrollOffset(pageScaleFactor); 1968 webViewHelper.webViewImpl()->mainFrame()->setScrollOffset(WebSize(pageWidth / 4, pageHeight / 4));
1969 webViewHelper.webViewImpl()->setPageScaleFactorPreservingScrollOffset(pageSc aleFactor);
1938 1970
1939 WebSize previousOffset = webViewImpl()->mainFrame()->scrollOffset(); 1971 WebSize previousOffset = webViewHelper.webViewImpl()->mainFrame()->scrollOff set();
1940 float previousScale = webViewImpl()->pageScaleFactor(); 1972 float previousScale = webViewHelper.webViewImpl()->pageScaleFactor();
1941 1973
1942 // Reload the page using the cache. 1974 // Reload the page using the cache.
1943 webViewImpl()->mainFrame()->reloadWithOverrideURL(toKURL(m_baseURL + secondU RL), false); 1975 webViewHelper.webViewImpl()->mainFrame()->reloadWithOverrideURL(toKURL(m_bas eURL + secondURL), false);
1944 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 1976 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
1945 ASSERT_EQ(previousOffset, webViewImpl()->mainFrame()->scrollOffset()); 1977 ASSERT_EQ(previousOffset, webViewHelper.webViewImpl()->mainFrame()->scrollOf fset());
1946 ASSERT_EQ(previousScale, webViewImpl()->pageScaleFactor()); 1978 ASSERT_EQ(previousScale, webViewHelper.webViewImpl()->pageScaleFactor());
1947 1979
1948 // Reload the page while ignoring the cache. 1980 // Reload the page while ignoring the cache.
1949 webViewImpl()->mainFrame()->reloadWithOverrideURL(toKURL(m_baseURL + thirdUR L), true); 1981 webViewHelper.webViewImpl()->mainFrame()->reloadWithOverrideURL(toKURL(m_bas eURL + thirdURL), true);
1950 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 1982 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
1951 ASSERT_EQ(previousOffset, webViewImpl()->mainFrame()->scrollOffset()); 1983 ASSERT_EQ(previousOffset, webViewHelper.webViewImpl()->mainFrame()->scrollOf fset());
1952 ASSERT_EQ(previousScale, webViewImpl()->pageScaleFactor()); 1984 ASSERT_EQ(previousScale, webViewHelper.webViewImpl()->pageScaleFactor());
1953 } 1985 }
1954 1986
1955 class TestReloadWhileProvisionalFrameClient : public WebFrameClient { 1987 class TestReloadWhileProvisionalFrameClient : public WebFrameClient {
1956 }; 1988 };
1957 1989
1958 TEST_F(WebFrameTest, ReloadWhileProvisional) 1990 TEST_F(WebFrameTest, ReloadWhileProvisional)
1959 { 1991 {
1960 // Test that reloading while the previous load is still pending does not cau se the initial 1992 // Test that reloading while the previous load is still pending does not cau se the initial
1961 // request to get lost. 1993 // request to get lost.
1962 registerMockedHttpURLLoad("fixed_layout.html"); 1994 registerMockedHttpURLLoad("fixed_layout.html");
1963 1995
1964 TestReloadWhileProvisionalFrameClient webFrameClient; 1996 TestReloadWhileProvisionalFrameClient webFrameClient;
1965 m_webView = FrameTestHelpers::createWebView(false, &webFrameClient); 1997 FrameTestHelpers::WebViewHelper webViewHelper;
1966 FrameTestHelpers::loadFrame(m_webView->mainFrame(), m_baseURL + "fixed_layou t.html"); 1998 webViewHelper.initialize(false, &webFrameClient);
1999 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL + "fixed_layout.html");
1967 // start reload before first request is delivered. 2000 // start reload before first request is delivered.
1968 m_webView->mainFrame()->reload(true); 2001 webViewHelper.webView()->mainFrame()->reload(true);
1969 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 2002 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
1970 ASSERT_EQ(WebURL(toKURL(m_baseURL + "fixed_layout.html")), 2003 ASSERT_EQ(WebURL(toKURL(m_baseURL + "fixed_layout.html")),
1971 m_webView->mainFrame()->dataSource()->request().url()); 2004 webViewHelper.webView()->mainFrame()->dataSource()->request().url());
1972
1973 m_webView->close();
1974 m_webView = 0;
1975 } 2005 }
1976 2006
1977 TEST_F(WebFrameTest, IframeRedirect) 2007 TEST_F(WebFrameTest, IframeRedirect)
1978 { 2008 {
1979 registerMockedHttpURLLoad("iframe_redirect.html"); 2009 registerMockedHttpURLLoad("iframe_redirect.html");
1980 registerMockedHttpURLLoad("visible_iframe.html"); 2010 registerMockedHttpURLLoad("visible_iframe.html");
1981 2011
1982 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "iframe_redir ect.html", true); 2012 FrameTestHelpers::WebViewHelper webViewHelper;
2013 webViewHelper.initializeAndLoad(m_baseURL + "iframe_redirect.html", true);
1983 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); / / Load the iframe. 2014 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); / / Load the iframe.
1984 2015
1985 WebFrame* iframe = m_webView->findFrameByName(WebString::fromUTF8("ifr")); 2016 WebFrame* iframe = webViewHelper.webView()->findFrameByName(WebString::fromU TF8("ifr"));
1986 ASSERT_TRUE(iframe); 2017 ASSERT_TRUE(iframe);
1987 WebDataSource* iframeDataSource = iframe->dataSource(); 2018 WebDataSource* iframeDataSource = iframe->dataSource();
1988 ASSERT_TRUE(iframeDataSource); 2019 ASSERT_TRUE(iframeDataSource);
1989 WebVector<WebURL> redirects; 2020 WebVector<WebURL> redirects;
1990 iframeDataSource->redirectChain(redirects); 2021 iframeDataSource->redirectChain(redirects);
1991 ASSERT_EQ(2U, redirects.size()); 2022 ASSERT_EQ(2U, redirects.size());
1992 EXPECT_EQ(toKURL("about:blank"), toKURL(redirects[0].spec().data())); 2023 EXPECT_EQ(toKURL("about:blank"), toKURL(redirects[0].spec().data()));
1993 EXPECT_EQ(toKURL("http://www.test.com/visible_iframe.html"), toKURL(redirect s[1].spec().data())); 2024 EXPECT_EQ(toKURL("http://www.test.com/visible_iframe.html"), toKURL(redirect s[1].spec().data()));
1994 } 2025 }
1995 2026
1996 TEST_F(WebFrameTest, ClearFocusedNodeTest) 2027 TEST_F(WebFrameTest, ClearFocusedNodeTest)
1997 { 2028 {
1998 registerMockedHttpURLLoad("iframe_clear_focused_node_test.html"); 2029 registerMockedHttpURLLoad("iframe_clear_focused_node_test.html");
1999 registerMockedHttpURLLoad("autofocus_input_field_iframe.html"); 2030 registerMockedHttpURLLoad("autofocus_input_field_iframe.html");
2000 2031
2001 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "iframe_clear _focused_node_test.html", true); 2032 FrameTestHelpers::WebViewHelper webViewHelper;
2033 webViewHelper.initializeAndLoad(m_baseURL + "iframe_clear_focused_node_test. html", true);
2002 2034
2003 // Clear the focused node. 2035 // Clear the focused node.
2004 m_webView->clearFocusedNode(); 2036 webViewHelper.webView()->clearFocusedNode();
2005 2037
2006 // Now retrieve the FocusedNode and test it should be null. 2038 // Now retrieve the FocusedNode and test it should be null.
2007 EXPECT_EQ(0, webViewImpl()->focusedElement()); 2039 EXPECT_EQ(0, webViewHelper.webViewImpl()->focusedElement());
2008 } 2040 }
2009 2041
2010 // Implementation of WebFrameClient that tracks the v8 contexts that are created 2042 // Implementation of WebFrameClient that tracks the v8 contexts that are created
2011 // and destroyed for verification. 2043 // and destroyed for verification.
2012 class ContextLifetimeTestWebFrameClient : public WebFrameClient { 2044 class ContextLifetimeTestWebFrameClient : public WebFrameClient {
2013 public: 2045 public:
2014 struct Notification { 2046 struct Notification {
2015 public: 2047 public:
2016 Notification(WebFrame* frame, v8::Handle<v8::Context> context, int world Id) 2048 Notification(WebFrame* frame, v8::Handle<v8::Context> context, int world Id)
2017 : frame(frame) 2049 : frame(frame)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2070 // TODO(aa): Deflake this test. 2102 // TODO(aa): Deflake this test.
2071 TEST_F(WebFrameTest, FLAKY_ContextNotificationsLoadUnload) 2103 TEST_F(WebFrameTest, FLAKY_ContextNotificationsLoadUnload)
2072 { 2104 {
2073 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); 2105 v8::HandleScope handleScope(v8::Isolate::GetCurrent());
2074 2106
2075 registerMockedHttpURLLoad("context_notifications_test.html"); 2107 registerMockedHttpURLLoad("context_notifications_test.html");
2076 registerMockedHttpURLLoad("context_notifications_test_frame.html"); 2108 registerMockedHttpURLLoad("context_notifications_test_frame.html");
2077 2109
2078 // Load a frame with an iframe, make sure we get the right create notificati ons. 2110 // Load a frame with an iframe, make sure we get the right create notificati ons.
2079 ContextLifetimeTestWebFrameClient webFrameClient; 2111 ContextLifetimeTestWebFrameClient webFrameClient;
2080 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "context_noti fications_test.html", true, &webFrameClient); 2112 FrameTestHelpers::WebViewHelper webViewHelper;
2113 webViewHelper.initializeAndLoad(m_baseURL + "context_notifications_test.html ", true, &webFrameClient);
2081 2114
2082 WebFrame* mainFrame = m_webView->mainFrame(); 2115 WebFrame* mainFrame = webViewHelper.webView()->mainFrame();
2083 WebFrame* childFrame = mainFrame->firstChild(); 2116 WebFrame* childFrame = mainFrame->firstChild();
2084 2117
2085 ASSERT_EQ(2u, webFrameClient.createNotifications.size()); 2118 ASSERT_EQ(2u, webFrameClient.createNotifications.size());
2086 EXPECT_EQ(0u, webFrameClient.releaseNotifications.size()); 2119 EXPECT_EQ(0u, webFrameClient.releaseNotifications.size());
2087 2120
2088 ContextLifetimeTestWebFrameClient::Notification* firstCreateNotification = w ebFrameClient.createNotifications[0]; 2121 ContextLifetimeTestWebFrameClient::Notification* firstCreateNotification = w ebFrameClient.createNotifications[0];
2089 ContextLifetimeTestWebFrameClient::Notification* secondCreateNotification = webFrameClient.createNotifications[1]; 2122 ContextLifetimeTestWebFrameClient::Notification* secondCreateNotification = webFrameClient.createNotifications[1];
2090 2123
2091 EXPECT_EQ(mainFrame, firstCreateNotification->frame); 2124 EXPECT_EQ(mainFrame, firstCreateNotification->frame);
2092 EXPECT_EQ(mainFrame->mainWorldScriptContext(), firstCreateNotification->cont ext); 2125 EXPECT_EQ(mainFrame->mainWorldScriptContext(), firstCreateNotification->cont ext);
2093 EXPECT_EQ(0, firstCreateNotification->worldId); 2126 EXPECT_EQ(0, firstCreateNotification->worldId);
2094 2127
2095 EXPECT_EQ(childFrame, secondCreateNotification->frame); 2128 EXPECT_EQ(childFrame, secondCreateNotification->frame);
2096 EXPECT_EQ(childFrame->mainWorldScriptContext(), secondCreateNotification->co ntext); 2129 EXPECT_EQ(childFrame->mainWorldScriptContext(), secondCreateNotification->co ntext);
2097 EXPECT_EQ(0, secondCreateNotification->worldId); 2130 EXPECT_EQ(0, secondCreateNotification->worldId);
2098 2131
2099 // Close the view. We should get two release notifications that are exactly the same as the create ones, in reverse order. 2132 // Close the view. We should get two release notifications that are exactly the same as the create ones, in reverse order.
2100 m_webView->close(); 2133 webViewHelper.reset();
2101 m_webView = 0;
2102 2134
2103 ASSERT_EQ(2u, webFrameClient.releaseNotifications.size()); 2135 ASSERT_EQ(2u, webFrameClient.releaseNotifications.size());
2104 ContextLifetimeTestWebFrameClient::Notification* firstReleaseNotification = webFrameClient.releaseNotifications[0]; 2136 ContextLifetimeTestWebFrameClient::Notification* firstReleaseNotification = webFrameClient.releaseNotifications[0];
2105 ContextLifetimeTestWebFrameClient::Notification* secondReleaseNotification = webFrameClient.releaseNotifications[1]; 2137 ContextLifetimeTestWebFrameClient::Notification* secondReleaseNotification = webFrameClient.releaseNotifications[1];
2106 2138
2107 ASSERT_TRUE(firstCreateNotification->Equals(secondReleaseNotification)); 2139 ASSERT_TRUE(firstCreateNotification->Equals(secondReleaseNotification));
2108 ASSERT_TRUE(secondCreateNotification->Equals(firstReleaseNotification)); 2140 ASSERT_TRUE(secondCreateNotification->Equals(firstReleaseNotification));
2109 } 2141 }
2110 2142
2111 TEST_F(WebFrameTest, ContextNotificationsReload) 2143 TEST_F(WebFrameTest, ContextNotificationsReload)
2112 { 2144 {
2113 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); 2145 v8::HandleScope handleScope(v8::Isolate::GetCurrent());
2114 2146
2115 registerMockedHttpURLLoad("context_notifications_test.html"); 2147 registerMockedHttpURLLoad("context_notifications_test.html");
2116 registerMockedHttpURLLoad("context_notifications_test_frame.html"); 2148 registerMockedHttpURLLoad("context_notifications_test_frame.html");
2117 2149
2118 ContextLifetimeTestWebFrameClient webFrameClient; 2150 ContextLifetimeTestWebFrameClient webFrameClient;
2119 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "context_noti fications_test.html", true, &webFrameClient); 2151 FrameTestHelpers::WebViewHelper webViewHelper;
2152 webViewHelper.initializeAndLoad(m_baseURL + "context_notifications_test.html ", true, &webFrameClient);
2120 2153
2121 // Refresh, we should get two release notifications and two more create noti fications. 2154 // Refresh, we should get two release notifications and two more create noti fications.
2122 m_webView->mainFrame()->reload(false); 2155 webViewHelper.webView()->mainFrame()->reload(false);
2123 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 2156 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
2124 ASSERT_EQ(4u, webFrameClient.createNotifications.size()); 2157 ASSERT_EQ(4u, webFrameClient.createNotifications.size());
2125 ASSERT_EQ(2u, webFrameClient.releaseNotifications.size()); 2158 ASSERT_EQ(2u, webFrameClient.releaseNotifications.size());
2126 2159
2127 // The two release notifications we got should be exactly the same as the fi rst two create notifications. 2160 // The two release notifications we got should be exactly the same as the fi rst two create notifications.
2128 for (size_t i = 0; i < webFrameClient.releaseNotifications.size(); ++i) { 2161 for (size_t i = 0; i < webFrameClient.releaseNotifications.size(); ++i) {
2129 EXPECT_TRUE(webFrameClient.releaseNotifications[i]->Equals( 2162 EXPECT_TRUE(webFrameClient.releaseNotifications[i]->Equals(
2130 webFrameClient.createNotifications[webFrameClient.createNotifications. size() - 3 - i])); 2163 webFrameClient.createNotifications[webFrameClient.createNotifications. size() - 3 - i]));
2131 } 2164 }
2132 2165
2133 // The last two create notifications should be for the current frames and co ntext. 2166 // The last two create notifications should be for the current frames and co ntext.
2134 WebFrame* mainFrame = m_webView->mainFrame(); 2167 WebFrame* mainFrame = webViewHelper.webView()->mainFrame();
2135 WebFrame* childFrame = mainFrame->firstChild(); 2168 WebFrame* childFrame = mainFrame->firstChild();
2136 ContextLifetimeTestWebFrameClient::Notification* firstRefreshNotification = webFrameClient.createNotifications[2]; 2169 ContextLifetimeTestWebFrameClient::Notification* firstRefreshNotification = webFrameClient.createNotifications[2];
2137 ContextLifetimeTestWebFrameClient::Notification* secondRefreshNotification = webFrameClient.createNotifications[3]; 2170 ContextLifetimeTestWebFrameClient::Notification* secondRefreshNotification = webFrameClient.createNotifications[3];
2138 2171
2139 EXPECT_EQ(mainFrame, firstRefreshNotification->frame); 2172 EXPECT_EQ(mainFrame, firstRefreshNotification->frame);
2140 EXPECT_EQ(mainFrame->mainWorldScriptContext(), firstRefreshNotification->con text); 2173 EXPECT_EQ(mainFrame->mainWorldScriptContext(), firstRefreshNotification->con text);
2141 EXPECT_EQ(0, firstRefreshNotification->worldId); 2174 EXPECT_EQ(0, firstRefreshNotification->worldId);
2142 2175
2143 EXPECT_EQ(childFrame, secondRefreshNotification->frame); 2176 EXPECT_EQ(childFrame, secondRefreshNotification->frame);
2144 EXPECT_EQ(childFrame->mainWorldScriptContext(), secondRefreshNotification->c ontext); 2177 EXPECT_EQ(childFrame->mainWorldScriptContext(), secondRefreshNotification->c ontext);
2145 EXPECT_EQ(0, secondRefreshNotification->worldId); 2178 EXPECT_EQ(0, secondRefreshNotification->worldId);
2146
2147 m_webView->close();
2148 m_webView = 0;
2149 } 2179 }
2150 2180
2151 TEST_F(WebFrameTest, ContextNotificationsIsolatedWorlds) 2181 TEST_F(WebFrameTest, ContextNotificationsIsolatedWorlds)
2152 { 2182 {
2153 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 2183 v8::Isolate* isolate = v8::Isolate::GetCurrent();
2154 v8::HandleScope handleScope(isolate); 2184 v8::HandleScope handleScope(isolate);
2155 2185
2156 registerMockedHttpURLLoad("context_notifications_test.html"); 2186 registerMockedHttpURLLoad("context_notifications_test.html");
2157 registerMockedHttpURLLoad("context_notifications_test_frame.html"); 2187 registerMockedHttpURLLoad("context_notifications_test_frame.html");
2158 2188
2159 ContextLifetimeTestWebFrameClient webFrameClient; 2189 ContextLifetimeTestWebFrameClient webFrameClient;
2160 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "context_noti fications_test.html", true, &webFrameClient); 2190 FrameTestHelpers::WebViewHelper webViewHelper;
2191 webViewHelper.initializeAndLoad(m_baseURL + "context_notifications_test.html ", true, &webFrameClient);
2161 2192
2162 // Add an isolated world. 2193 // Add an isolated world.
2163 webFrameClient.reset(); 2194 webFrameClient.reset();
2164 2195
2165 int isolatedWorldId = 42; 2196 int isolatedWorldId = 42;
2166 WebScriptSource scriptSource("hi!"); 2197 WebScriptSource scriptSource("hi!");
2167 int numSources = 1; 2198 int numSources = 1;
2168 int extensionGroup = 0; 2199 int extensionGroup = 0;
2169 m_webView->mainFrame()->executeScriptInIsolatedWorld(isolatedWorldId, &scrip tSource, numSources, extensionGroup); 2200 webViewHelper.webView()->mainFrame()->executeScriptInIsolatedWorld(isolatedW orldId, &scriptSource, numSources, extensionGroup);
2170 2201
2171 // We should now have a new create notification. 2202 // We should now have a new create notification.
2172 ASSERT_EQ(1u, webFrameClient.createNotifications.size()); 2203 ASSERT_EQ(1u, webFrameClient.createNotifications.size());
2173 ContextLifetimeTestWebFrameClient::Notification* notification = webFrameClie nt.createNotifications[0]; 2204 ContextLifetimeTestWebFrameClient::Notification* notification = webFrameClie nt.createNotifications[0];
2174 ASSERT_EQ(isolatedWorldId, notification->worldId); 2205 ASSERT_EQ(isolatedWorldId, notification->worldId);
2175 ASSERT_EQ(m_webView->mainFrame(), notification->frame); 2206 ASSERT_EQ(webViewHelper.webView()->mainFrame(), notification->frame);
2176 2207
2177 // We don't have an API to enumarate isolated worlds for a frame, but we can at least assert that the context we got is *not* the main world's context. 2208 // We don't have an API to enumarate isolated worlds for a frame, but we can at least assert that the context we got is *not* the main world's context.
2178 ASSERT_NE(m_webView->mainFrame()->mainWorldScriptContext(), v8::Local<v8::Co ntext>::New(isolate, notification->context)); 2209 ASSERT_NE(webViewHelper.webView()->mainFrame()->mainWorldScriptContext(), v8 ::Local<v8::Context>::New(isolate, notification->context));
2179 2210
2180 m_webView->close(); 2211 webViewHelper.reset();
2181 m_webView = 0;
2182 2212
2183 // We should have gotten three release notifications (one for each of the fr ames, plus one for the isolated context). 2213 // We should have gotten three release notifications (one for each of the fr ames, plus one for the isolated context).
2184 ASSERT_EQ(3u, webFrameClient.releaseNotifications.size()); 2214 ASSERT_EQ(3u, webFrameClient.releaseNotifications.size());
2185 2215
2186 // And one of them should be exactly the same as the create notification for the isolated context. 2216 // And one of them should be exactly the same as the create notification for the isolated context.
2187 int matchCount = 0; 2217 int matchCount = 0;
2188 for (size_t i = 0; i < webFrameClient.releaseNotifications.size(); ++i) { 2218 for (size_t i = 0; i < webFrameClient.releaseNotifications.size(); ++i) {
2189 if (webFrameClient.releaseNotifications[i]->Equals(webFrameClient.createNo tifications[0])) 2219 if (webFrameClient.releaseNotifications[i]->Equals(webFrameClient.createNo tifications[0]))
2190 ++matchCount; 2220 ++matchCount;
2191 } 2221 }
2192 EXPECT_EQ(1, matchCount); 2222 EXPECT_EQ(1, matchCount);
2193 } 2223 }
2194 2224
2195 TEST_F(WebFrameTest, FindInPage) 2225 TEST_F(WebFrameTest, FindInPage)
2196 { 2226 {
2197 registerMockedHttpURLLoad("find.html"); 2227 registerMockedHttpURLLoad("find.html");
2198 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "find.html"); 2228 FrameTestHelpers::WebViewHelper webViewHelper;
2199 WebFrame* frame = m_webView->mainFrame(); 2229 webViewHelper.initializeAndLoad(m_baseURL + "find.html");
2230 WebFrame* frame = webViewHelper.webView()->mainFrame();
2200 const int findIdentifier = 12345; 2231 const int findIdentifier = 12345;
2201 WebFindOptions options; 2232 WebFindOptions options;
2202 2233
2203 // Find in a <div> element. 2234 // Find in a <div> element.
2204 EXPECT_TRUE(frame->find(findIdentifier, WebString::fromUTF8("bar1"), options , false, 0)); 2235 EXPECT_TRUE(frame->find(findIdentifier, WebString::fromUTF8("bar1"), options , false, 0));
2205 frame->stopFinding(false); 2236 frame->stopFinding(false);
2206 WebRange range = frame->selectionRange(); 2237 WebRange range = frame->selectionRange();
2207 EXPECT_EQ(5, range.startOffset()); 2238 EXPECT_EQ(5, range.startOffset());
2208 EXPECT_EQ(9, range.endOffset()); 2239 EXPECT_EQ(9, range.endOffset());
2209 EXPECT_TRUE(frame->document().focusedNode().isNull()); 2240 EXPECT_TRUE(frame->document().focusedNode().isNull());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2243 EXPECT_FALSE(frame->find(findIdentifier, WebString::fromUTF8("bar5"), option s, false, 0)); 2274 EXPECT_FALSE(frame->find(findIdentifier, WebString::fromUTF8("bar5"), option s, false, 0));
2244 // If there are any matches, stopFinding will set the selection on the found text. 2275 // If there are any matches, stopFinding will set the selection on the found text.
2245 // However, we do not expect any matches, so check that the selection is nul l. 2276 // However, we do not expect any matches, so check that the selection is nul l.
2246 frame->stopFinding(false); 2277 frame->stopFinding(false);
2247 range = frame->selectionRange(); 2278 range = frame->selectionRange();
2248 ASSERT_TRUE(range.isNull()); 2279 ASSERT_TRUE(range.isNull());
2249 } 2280 }
2250 2281
2251 TEST_F(WebFrameTest, GetContentAsPlainText) 2282 TEST_F(WebFrameTest, GetContentAsPlainText)
2252 { 2283 {
2253 m_webView = FrameTestHelpers::createWebViewAndLoad("about:blank", true); 2284 FrameTestHelpers::WebViewHelper webViewHelper;
2285 webViewHelper.initializeAndLoad("about:blank", true);
2254 // We set the size because it impacts line wrapping, which changes the 2286 // We set the size because it impacts line wrapping, which changes the
2255 // resulting text value. 2287 // resulting text value.
2256 m_webView->resize(WebSize(640, 480)); 2288 webViewHelper.webView()->resize(WebSize(640, 480));
2257 WebFrame* frame = m_webView->mainFrame(); 2289 WebFrame* frame = webViewHelper.webView()->mainFrame();
2258 2290
2259 // Generate a simple test case. 2291 // Generate a simple test case.
2260 const char simpleSource[] = "<div>Foo bar</div><div></div>baz"; 2292 const char simpleSource[] = "<div>Foo bar</div><div></div>baz";
2261 WebCore::KURL testURL = toKURL("about:blank"); 2293 WebCore::KURL testURL = toKURL("about:blank");
2262 frame->loadHTMLString(simpleSource, testURL); 2294 frame->loadHTMLString(simpleSource, testURL);
2263 runPendingTasks(); 2295 runPendingTasks();
2264 2296
2265 // Make sure it comes out OK. 2297 // Make sure it comes out OK.
2266 const std::string expected("Foo bar\nbaz"); 2298 const std::string expected("Foo bar\nbaz");
2267 WebString text = frame->contentAsText(std::numeric_limits<size_t>::max()); 2299 WebString text = frame->contentAsText(std::numeric_limits<size_t>::max());
(...skipping 19 matching lines...) Expand all
2287 EXPECT_EQ("Hello world\n\nsub\ntext", std::string(text.utf8().data())); 2319 EXPECT_EQ("Hello world\n\nsub\ntext", std::string(text.utf8().data()));
2288 2320
2289 // Get the frame text where the subframe separator falls on the boundary of 2321 // Get the frame text where the subframe separator falls on the boundary of
2290 // what we'll take. There used to be a crash in this case. 2322 // what we'll take. There used to be a crash in this case.
2291 text = frame->contentAsText(12); 2323 text = frame->contentAsText(12);
2292 EXPECT_EQ("Hello world", std::string(text.utf8().data())); 2324 EXPECT_EQ("Hello world", std::string(text.utf8().data()));
2293 } 2325 }
2294 2326
2295 TEST_F(WebFrameTest, GetFullHtmlOfPage) 2327 TEST_F(WebFrameTest, GetFullHtmlOfPage)
2296 { 2328 {
2297 m_webView = FrameTestHelpers::createWebViewAndLoad("about:blank", true); 2329 FrameTestHelpers::WebViewHelper webViewHelper;
2298 WebFrame* frame = m_webView->mainFrame(); 2330 webViewHelper.initializeAndLoad("about:blank", true);
2331 WebFrame* frame = webViewHelper.webView()->mainFrame();
2299 2332
2300 // Generate a simple test case. 2333 // Generate a simple test case.
2301 const char simpleSource[] = "<p>Hello</p><p>World</p>"; 2334 const char simpleSource[] = "<p>Hello</p><p>World</p>";
2302 WebCore::KURL testURL = toKURL("about:blank"); 2335 WebCore::KURL testURL = toKURL("about:blank");
2303 frame->loadHTMLString(simpleSource, testURL); 2336 frame->loadHTMLString(simpleSource, testURL);
2304 runPendingTasks(); 2337 runPendingTasks();
2305 2338
2306 WebString text = frame->contentAsText(std::numeric_limits<size_t>::max()); 2339 WebString text = frame->contentAsText(std::numeric_limits<size_t>::max());
2307 EXPECT_EQ("Hello\n\nWorld", std::string(text.utf8().data())); 2340 EXPECT_EQ("Hello\n\nWorld", std::string(text.utf8().data()));
2308 2341
(...skipping 24 matching lines...) Expand all
2333 { 2366 {
2334 frame->executeScript(WebScriptSource("window.history = 'replaced';")); 2367 frame->executeScript(WebScriptSource("window.history = 'replaced';"));
2335 } 2368 }
2336 }; 2369 };
2337 2370
2338 TEST_F(WebFrameTest, ExecuteScriptDuringDidCreateScriptContext) 2371 TEST_F(WebFrameTest, ExecuteScriptDuringDidCreateScriptContext)
2339 { 2372 {
2340 registerMockedHttpURLLoad("hello_world.html"); 2373 registerMockedHttpURLLoad("hello_world.html");
2341 2374
2342 TestExecuteScriptDuringDidCreateScriptContext webFrameClient; 2375 TestExecuteScriptDuringDidCreateScriptContext webFrameClient;
2343 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "hello_world. html", true, &webFrameClient); 2376 FrameTestHelpers::WebViewHelper webViewHelper;
2377 webViewHelper.initializeAndLoad(m_baseURL + "hello_world.html", true, &webFr ameClient);
2344 2378
2345 m_webView->mainFrame()->reload(); 2379 webViewHelper.webView()->mainFrame()->reload();
2346 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 2380 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
2347
2348 m_webView->close();
2349 m_webView = 0;
2350 } 2381 }
2351 2382
2352 class TestDidCreateFrameWebFrameClient : public WebFrameClient { 2383 class TestDidCreateFrameWebFrameClient : public WebFrameClient {
2353 public: 2384 public:
2354 TestDidCreateFrameWebFrameClient() : m_frameCount(0), m_parent(0) 2385 TestDidCreateFrameWebFrameClient() : m_frameCount(0), m_parent(0)
2355 { 2386 {
2356 } 2387 }
2357 2388
2358 virtual void didCreateFrame(WebFrame* parent, WebFrame* child) 2389 virtual void didCreateFrame(WebFrame* parent, WebFrame* child)
2359 { 2390 {
2360 m_frameCount++; 2391 m_frameCount++;
2361 if (!m_parent) 2392 if (!m_parent)
2362 m_parent = parent; 2393 m_parent = parent;
2363 } 2394 }
2364 2395
2365 int m_frameCount; 2396 int m_frameCount;
2366 WebFrame* m_parent; 2397 WebFrame* m_parent;
2367 }; 2398 };
2368 2399
2369 TEST_F(WebFrameTest, DidCreateFrame) 2400 TEST_F(WebFrameTest, DidCreateFrame)
2370 { 2401 {
2371 registerMockedHttpURLLoad("iframes_test.html"); 2402 registerMockedHttpURLLoad("iframes_test.html");
2372 registerMockedHttpURLLoad("visible_iframe.html"); 2403 registerMockedHttpURLLoad("visible_iframe.html");
2373 registerMockedHttpURLLoad("invisible_iframe.html"); 2404 registerMockedHttpURLLoad("invisible_iframe.html");
2374 registerMockedHttpURLLoad("zero_sized_iframe.html"); 2405 registerMockedHttpURLLoad("zero_sized_iframe.html");
2375 2406
2376 TestDidCreateFrameWebFrameClient webFrameClient; 2407 TestDidCreateFrameWebFrameClient webFrameClient;
2377 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "iframes_test .html", false, &webFrameClient); 2408 FrameTestHelpers::WebViewHelper webViewHelper;
2409 webViewHelper.initializeAndLoad(m_baseURL + "iframes_test.html", false, &web FrameClient);
2378 2410
2379 EXPECT_EQ(webFrameClient.m_frameCount, 3); 2411 EXPECT_EQ(webFrameClient.m_frameCount, 3);
2380 EXPECT_EQ(webFrameClient.m_parent, m_webView->mainFrame()); 2412 EXPECT_EQ(webFrameClient.m_parent, webViewHelper.webView()->mainFrame());
2381
2382 m_webView->close();
2383 m_webView = 0;
2384 } 2413 }
2385 2414
2386 class FindUpdateWebFrameClient : public WebFrameClient { 2415 class FindUpdateWebFrameClient : public WebFrameClient {
2387 public: 2416 public:
2388 FindUpdateWebFrameClient() 2417 FindUpdateWebFrameClient()
2389 : m_findResultsAreReady(false) 2418 : m_findResultsAreReady(false)
2390 , m_count(-1) 2419 , m_count(-1)
2391 { 2420 {
2392 } 2421 }
2393 2422
(...skipping 16 matching lines...) Expand all
2410 #if OS(MACOSX) 2439 #if OS(MACOSX)
2411 TEST_F(WebFrameTest, DISABLED_FindInPageMatchRects) 2440 TEST_F(WebFrameTest, DISABLED_FindInPageMatchRects)
2412 #else 2441 #else
2413 TEST_F(WebFrameTest, FindInPageMatchRects) 2442 TEST_F(WebFrameTest, FindInPageMatchRects)
2414 #endif 2443 #endif
2415 { 2444 {
2416 registerMockedHttpURLLoad("find_in_page.html"); 2445 registerMockedHttpURLLoad("find_in_page.html");
2417 registerMockedHttpURLLoad("find_in_page_frame.html"); 2446 registerMockedHttpURLLoad("find_in_page_frame.html");
2418 2447
2419 FindUpdateWebFrameClient client; 2448 FindUpdateWebFrameClient client;
2420 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "find_in_page .html", true, &client); 2449 FrameTestHelpers::WebViewHelper webViewHelper;
2421 m_webView->resize(WebSize(640, 480)); 2450 webViewHelper.initializeAndLoad(m_baseURL + "find_in_page.html", true, &clie nt);
2422 m_webView->layout(); 2451 webViewHelper.webView()->resize(WebSize(640, 480));
2452 webViewHelper.webView()->layout();
2423 runPendingTasks(); 2453 runPendingTasks();
2424 2454
2425 // Note that the 'result 19' in the <select> element is not expected to prod uce a match. 2455 // Note that the 'result 19' in the <select> element is not expected to prod uce a match.
2426 static const char* kFindString = "result"; 2456 static const char* kFindString = "result";
2427 static const int kFindIdentifier = 12345; 2457 static const int kFindIdentifier = 12345;
2428 static const int kNumResults = 19; 2458 static const int kNumResults = 19;
2429 2459
2430 WebFindOptions options; 2460 WebFindOptions options;
2431 WebString searchText = WebString::fromUTF8(kFindString); 2461 WebString searchText = WebString::fromUTF8(kFindString);
2432 WebFrameImpl* mainFrame = toWebFrameImpl(m_webView->mainFrame()); 2462 WebFrameImpl* mainFrame = toWebFrameImpl(webViewHelper.webView()->mainFrame( ));
2433 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchText, options, false, 0)) ; 2463 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchText, options, false, 0)) ;
2434 2464
2435 mainFrame->resetMatchCount(); 2465 mainFrame->resetMatchCount();
2436 2466
2437 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) 2467 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false))
2438 frame->scopeStringMatches(kFindIdentifier, searchText, options, true); 2468 frame->scopeStringMatches(kFindIdentifier, searchText, options, true);
2439 2469
2440 runPendingTasks(); 2470 runPendingTasks();
2441 EXPECT_TRUE(client.findResultsAreReady()); 2471 EXPECT_TRUE(client.findResultsAreReady());
2442 2472
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2517 EXPECT_TRUE(webMatchRects[12].y < webMatchRects[14].y); 2547 EXPECT_TRUE(webMatchRects[12].y < webMatchRects[14].y);
2518 2548
2519 // Result 16 should be below result 15. 2549 // Result 16 should be below result 15.
2520 EXPECT_TRUE(webMatchRects[15].y > webMatchRects[14].y); 2550 EXPECT_TRUE(webMatchRects[15].y > webMatchRects[14].y);
2521 2551
2522 // Result 18 should be normalized with respect to the position:relative div, and not it's 2552 // Result 18 should be normalized with respect to the position:relative div, and not it's
2523 // immediate containing div. Consequently, result 18 should be above result 17. 2553 // immediate containing div. Consequently, result 18 should be above result 17.
2524 EXPECT_TRUE(webMatchRects[17].y > webMatchRects[18].y); 2554 EXPECT_TRUE(webMatchRects[17].y > webMatchRects[18].y);
2525 2555
2526 // Resizing should update the rects version. 2556 // Resizing should update the rects version.
2527 m_webView->resize(WebSize(800, 600)); 2557 webViewHelper.webView()->resize(WebSize(800, 600));
2528 runPendingTasks(); 2558 runPendingTasks();
2529 EXPECT_TRUE(mainFrame->findMatchMarkersVersion() != rectsVersion); 2559 EXPECT_TRUE(mainFrame->findMatchMarkersVersion() != rectsVersion);
2530
2531 m_webView->close();
2532 m_webView = 0;
2533 } 2560 }
2534 2561
2535 TEST_F(WebFrameTest, FindInPageSkipsHiddenFrames) 2562 TEST_F(WebFrameTest, FindInPageSkipsHiddenFrames)
2536 { 2563 {
2537 registerMockedHttpURLLoad("find_in_hidden_frame.html"); 2564 registerMockedHttpURLLoad("find_in_hidden_frame.html");
2538 2565
2539 FindUpdateWebFrameClient client; 2566 FindUpdateWebFrameClient client;
2540 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "find_in_hidd en_frame.html", true, &client); 2567 FrameTestHelpers::WebViewHelper webViewHelper;
2541 m_webView->resize(WebSize(640, 480)); 2568 webViewHelper.initializeAndLoad(m_baseURL + "find_in_hidden_frame.html", tru e, &client);
2542 m_webView->layout(); 2569 webViewHelper.webView()->resize(WebSize(640, 480));
2570 webViewHelper.webView()->layout();
2543 runPendingTasks(); 2571 runPendingTasks();
2544 2572
2545 static const char* kFindString = "hello"; 2573 static const char* kFindString = "hello";
2546 static const int kFindIdentifier = 12345; 2574 static const int kFindIdentifier = 12345;
2547 static const int kNumResults = 1; 2575 static const int kNumResults = 1;
2548 2576
2549 WebFindOptions options; 2577 WebFindOptions options;
2550 WebString searchText = WebString::fromUTF8(kFindString); 2578 WebString searchText = WebString::fromUTF8(kFindString);
2551 WebFrameImpl* mainFrame = toWebFrameImpl(m_webView->mainFrame()); 2579 WebFrameImpl* mainFrame = toWebFrameImpl(webViewHelper.webView()->mainFrame( ));
2552 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchText, options, false, 0)) ; 2580 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchText, options, false, 0)) ;
2553 2581
2554 mainFrame->resetMatchCount(); 2582 mainFrame->resetMatchCount();
2555 2583
2556 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) 2584 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false))
2557 frame->scopeStringMatches(kFindIdentifier, searchText, options, true); 2585 frame->scopeStringMatches(kFindIdentifier, searchText, options, true);
2558 2586
2559 runPendingTasks(); 2587 runPendingTasks();
2560 EXPECT_TRUE(client.findResultsAreReady()); 2588 EXPECT_TRUE(client.findResultsAreReady());
2561 EXPECT_EQ(kNumResults, client.count()); 2589 EXPECT_EQ(kNumResults, client.count());
2562
2563 m_webView->close();
2564 m_webView = 0;
2565 } 2590 }
2566 2591
2567 TEST_F(WebFrameTest, FindOnDetachedFrame) 2592 TEST_F(WebFrameTest, FindOnDetachedFrame)
2568 { 2593 {
2569 registerMockedHttpURLLoad("find_in_page.html"); 2594 registerMockedHttpURLLoad("find_in_page.html");
2570 registerMockedHttpURLLoad("find_in_page_frame.html"); 2595 registerMockedHttpURLLoad("find_in_page_frame.html");
2571 2596
2572 FindUpdateWebFrameClient client; 2597 FindUpdateWebFrameClient client;
2573 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "find_in_page .html", true, &client); 2598 FrameTestHelpers::WebViewHelper webViewHelper;
2574 m_webView->resize(WebSize(640, 480)); 2599 webViewHelper.initializeAndLoad(m_baseURL + "find_in_page.html", true, &clie nt);
2575 m_webView->layout(); 2600 webViewHelper.webView()->resize(WebSize(640, 480));
2601 webViewHelper.webView()->layout();
2576 runPendingTasks(); 2602 runPendingTasks();
2577 2603
2578 static const char* kFindString = "result"; 2604 static const char* kFindString = "result";
2579 static const int kFindIdentifier = 12345; 2605 static const int kFindIdentifier = 12345;
2580 2606
2581 WebFindOptions options; 2607 WebFindOptions options;
2582 WebString searchText = WebString::fromUTF8(kFindString); 2608 WebString searchText = WebString::fromUTF8(kFindString);
2583 WebFrameImpl* mainFrame = toWebFrameImpl(m_webView->mainFrame()); 2609 WebFrameImpl* mainFrame = toWebFrameImpl(webViewHelper.webView()->mainFrame( ));
2584 WebFrameImpl* secondFrame = toWebFrameImpl(mainFrame->traverseNext(false)); 2610 WebFrameImpl* secondFrame = toWebFrameImpl(mainFrame->traverseNext(false));
2585 RefPtr<WebCore::Frame> holdSecondFrame = secondFrame->frame(); 2611 RefPtr<WebCore::Frame> holdSecondFrame = secondFrame->frame();
2586 2612
2587 // Detach the frame before finding. 2613 // Detach the frame before finding.
2588 EXPECT_TRUE(mainFrame->document().getElementById("frame").remove()); 2614 EXPECT_TRUE(mainFrame->document().getElementById("frame").remove());
2589 2615
2590 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchText, options, false, 0)) ; 2616 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchText, options, false, 0)) ;
2591 EXPECT_FALSE(secondFrame->find(kFindIdentifier, searchText, options, false, 0)); 2617 EXPECT_FALSE(secondFrame->find(kFindIdentifier, searchText, options, false, 0));
2592 2618
2593 runPendingTasks(); 2619 runPendingTasks();
2594 EXPECT_FALSE(client.findResultsAreReady()); 2620 EXPECT_FALSE(client.findResultsAreReady());
2595 2621
2596 mainFrame->resetMatchCount(); 2622 mainFrame->resetMatchCount();
2597 2623
2598 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) 2624 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false))
2599 frame->scopeStringMatches(kFindIdentifier, searchText, options, true); 2625 frame->scopeStringMatches(kFindIdentifier, searchText, options, true);
2600 2626
2601 runPendingTasks(); 2627 runPendingTasks();
2602 EXPECT_TRUE(client.findResultsAreReady()); 2628 EXPECT_TRUE(client.findResultsAreReady());
2603 2629
2604 holdSecondFrame.release(); 2630 holdSecondFrame.release();
2605
2606 m_webView->close();
2607 m_webView = 0;
2608 } 2631 }
2609 2632
2610 TEST_F(WebFrameTest, FindDetachFrameBeforeScopeStrings) 2633 TEST_F(WebFrameTest, FindDetachFrameBeforeScopeStrings)
2611 { 2634 {
2612 registerMockedHttpURLLoad("find_in_page.html"); 2635 registerMockedHttpURLLoad("find_in_page.html");
2613 registerMockedHttpURLLoad("find_in_page_frame.html"); 2636 registerMockedHttpURLLoad("find_in_page_frame.html");
2614 2637
2615 FindUpdateWebFrameClient client; 2638 FindUpdateWebFrameClient client;
2616 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "find_in_page .html", true, &client); 2639 FrameTestHelpers::WebViewHelper webViewHelper;
2617 m_webView->resize(WebSize(640, 480)); 2640 webViewHelper.initializeAndLoad(m_baseURL + "find_in_page.html", true, &clie nt);
2618 m_webView->layout(); 2641 webViewHelper.webView()->resize(WebSize(640, 480));
2642 webViewHelper.webView()->layout();
2619 runPendingTasks(); 2643 runPendingTasks();
2620 2644
2621 static const char* kFindString = "result"; 2645 static const char* kFindString = "result";
2622 static const int kFindIdentifier = 12345; 2646 static const int kFindIdentifier = 12345;
2623 2647
2624 WebFindOptions options; 2648 WebFindOptions options;
2625 WebString searchText = WebString::fromUTF8(kFindString); 2649 WebString searchText = WebString::fromUTF8(kFindString);
2626 WebFrameImpl* mainFrame = toWebFrameImpl(m_webView->mainFrame()); 2650 WebFrameImpl* mainFrame = toWebFrameImpl(webViewHelper.webView()->mainFrame( ));
2627 WebFrameImpl* secondFrame = toWebFrameImpl(mainFrame->traverseNext(false)); 2651 WebFrameImpl* secondFrame = toWebFrameImpl(mainFrame->traverseNext(false));
2628 RefPtr<WebCore::Frame> holdSecondFrame = secondFrame->frame(); 2652 RefPtr<WebCore::Frame> holdSecondFrame = secondFrame->frame();
2629 2653
2630 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) 2654 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false))
2631 EXPECT_TRUE(frame->find(kFindIdentifier, searchText, options, false, 0)) ; 2655 EXPECT_TRUE(frame->find(kFindIdentifier, searchText, options, false, 0)) ;
2632 2656
2633 runPendingTasks(); 2657 runPendingTasks();
2634 EXPECT_FALSE(client.findResultsAreReady()); 2658 EXPECT_FALSE(client.findResultsAreReady());
2635 2659
2636 // Detach the frame between finding and scoping. 2660 // Detach the frame between finding and scoping.
2637 EXPECT_TRUE(mainFrame->document().getElementById("frame").remove()); 2661 EXPECT_TRUE(mainFrame->document().getElementById("frame").remove());
2638 2662
2639 mainFrame->resetMatchCount(); 2663 mainFrame->resetMatchCount();
2640 2664
2641 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) 2665 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false))
2642 frame->scopeStringMatches(kFindIdentifier, searchText, options, true); 2666 frame->scopeStringMatches(kFindIdentifier, searchText, options, true);
2643 2667
2644 runPendingTasks(); 2668 runPendingTasks();
2645 EXPECT_TRUE(client.findResultsAreReady()); 2669 EXPECT_TRUE(client.findResultsAreReady());
2646 2670
2647 holdSecondFrame.release(); 2671 holdSecondFrame.release();
2648
2649 m_webView->close();
2650 m_webView = 0;
2651 } 2672 }
2652 2673
2653 TEST_F(WebFrameTest, FindDetachFrameWhileScopingStrings) 2674 TEST_F(WebFrameTest, FindDetachFrameWhileScopingStrings)
2654 { 2675 {
2655 registerMockedHttpURLLoad("find_in_page.html"); 2676 registerMockedHttpURLLoad("find_in_page.html");
2656 registerMockedHttpURLLoad("find_in_page_frame.html"); 2677 registerMockedHttpURLLoad("find_in_page_frame.html");
2657 2678
2658 FindUpdateWebFrameClient client; 2679 FindUpdateWebFrameClient client;
2659 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "find_in_page .html", true, &client); 2680 FrameTestHelpers::WebViewHelper webViewHelper;
2660 m_webView->resize(WebSize(640, 480)); 2681 webViewHelper.initializeAndLoad(m_baseURL + "find_in_page.html", true, &clie nt);
2661 m_webView->layout(); 2682 webViewHelper.webView()->resize(WebSize(640, 480));
2683 webViewHelper.webView()->layout();
2662 runPendingTasks(); 2684 runPendingTasks();
2663 2685
2664 static const char* kFindString = "result"; 2686 static const char* kFindString = "result";
2665 static const int kFindIdentifier = 12345; 2687 static const int kFindIdentifier = 12345;
2666 2688
2667 WebFindOptions options; 2689 WebFindOptions options;
2668 WebString searchText = WebString::fromUTF8(kFindString); 2690 WebString searchText = WebString::fromUTF8(kFindString);
2669 WebFrameImpl* mainFrame = toWebFrameImpl(m_webView->mainFrame()); 2691 WebFrameImpl* mainFrame = toWebFrameImpl(webViewHelper.webView()->mainFrame( ));
2670 WebFrameImpl* secondFrame = toWebFrameImpl(mainFrame->traverseNext(false)); 2692 WebFrameImpl* secondFrame = toWebFrameImpl(mainFrame->traverseNext(false));
2671 RefPtr<WebCore::Frame> holdSecondFrame = secondFrame->frame(); 2693 RefPtr<WebCore::Frame> holdSecondFrame = secondFrame->frame();
2672 2694
2673 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) 2695 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false))
2674 EXPECT_TRUE(frame->find(kFindIdentifier, searchText, options, false, 0)) ; 2696 EXPECT_TRUE(frame->find(kFindIdentifier, searchText, options, false, 0)) ;
2675 2697
2676 runPendingTasks(); 2698 runPendingTasks();
2677 EXPECT_FALSE(client.findResultsAreReady()); 2699 EXPECT_FALSE(client.findResultsAreReady());
2678 2700
2679 mainFrame->resetMatchCount(); 2701 mainFrame->resetMatchCount();
2680 2702
2681 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) 2703 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false))
2682 frame->scopeStringMatches(kFindIdentifier, searchText, options, true); 2704 frame->scopeStringMatches(kFindIdentifier, searchText, options, true);
2683 2705
2684 // The first scopeStringMatches will have reset the state. Detach before it actually scopes. 2706 // The first scopeStringMatches will have reset the state. Detach before it actually scopes.
2685 EXPECT_TRUE(mainFrame->document().getElementById("frame").remove()); 2707 EXPECT_TRUE(mainFrame->document().getElementById("frame").remove());
2686 2708
2687 runPendingTasks(); 2709 runPendingTasks();
2688 EXPECT_TRUE(client.findResultsAreReady()); 2710 EXPECT_TRUE(client.findResultsAreReady());
2689 2711
2690 holdSecondFrame.release(); 2712 holdSecondFrame.release();
2691
2692 m_webView->close();
2693 m_webView = 0;
2694 }
2695
2696 static WebView* createWebViewForTextSelection(const std::string& url)
2697 {
2698 WebView* webView = FrameTestHelpers::createWebViewAndLoad(url, true);
2699 webView->settings()->setDefaultFontSize(12);
2700 webView->enableFixedLayoutMode(false);
2701 webView->resize(WebSize(640, 480));
2702 return webView;
2703 } 2713 }
2704 2714
2705 static WebPoint topLeft(const WebRect& rect) 2715 static WebPoint topLeft(const WebRect& rect)
2706 { 2716 {
2707 return WebPoint(rect.x, rect.y); 2717 return WebPoint(rect.x, rect.y);
2708 } 2718 }
2709 2719
2710 static WebPoint bottomRightMinusOne(const WebRect& rect) 2720 static WebPoint bottomRightMinusOne(const WebRect& rect)
2711 { 2721 {
2712 // FIXME: If we don't subtract 1 from the x- and y-coordinates of the 2722 // FIXME: If we don't subtract 1 from the x- and y-coordinates of the
(...skipping 15 matching lines...) Expand all
2728 2738
2729 TEST_F(WebFrameTest, SelectRange) 2739 TEST_F(WebFrameTest, SelectRange)
2730 { 2740 {
2731 WebFrame* frame; 2741 WebFrame* frame;
2732 WebRect startWebRect; 2742 WebRect startWebRect;
2733 WebRect endWebRect; 2743 WebRect endWebRect;
2734 2744
2735 registerMockedHttpURLLoad("select_range_basic.html"); 2745 registerMockedHttpURLLoad("select_range_basic.html");
2736 registerMockedHttpURLLoad("select_range_scroll.html"); 2746 registerMockedHttpURLLoad("select_range_scroll.html");
2737 2747
2738 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_basic.ht ml"); 2748 FrameTestHelpers::WebViewHelper webViewHelper;
2739 frame = m_webView->mainFrame(); 2749 initializeTextSelectionWebView(m_baseURL + "select_range_basic.html", &webVi ewHelper);
2750 frame = webViewHelper.webView()->mainFrame();
2740 EXPECT_EQ("Some test text for testing.", selectionAsString(frame)); 2751 EXPECT_EQ("Some test text for testing.", selectionAsString(frame));
2741 m_webView->selectionBounds(startWebRect, endWebRect); 2752 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect);
2742 frame->executeCommand(WebString::fromUTF8("Unselect")); 2753 frame->executeCommand(WebString::fromUTF8("Unselect"));
2743 EXPECT_EQ("", selectionAsString(frame)); 2754 EXPECT_EQ("", selectionAsString(frame));
2744 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); 2755 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect));
2745 EXPECT_EQ("Some test text for testing.", selectionAsString(frame)); 2756 EXPECT_EQ("Some test text for testing.", selectionAsString(frame));
2746 m_webView->close();
2747 m_webView = 0;
2748 2757
2749 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_scroll.h tml"); 2758 initializeTextSelectionWebView(m_baseURL + "select_range_scroll.html", &webV iewHelper);
2750 frame = m_webView->mainFrame(); 2759 frame = webViewHelper.webView()->mainFrame();
2751 EXPECT_EQ("Some offscreen test text for testing.", selectionAsString(frame)) ; 2760 EXPECT_EQ("Some offscreen test text for testing.", selectionAsString(frame)) ;
2752 m_webView->selectionBounds(startWebRect, endWebRect); 2761 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect);
2753 frame->executeCommand(WebString::fromUTF8("Unselect")); 2762 frame->executeCommand(WebString::fromUTF8("Unselect"));
2754 EXPECT_EQ("", selectionAsString(frame)); 2763 EXPECT_EQ("", selectionAsString(frame));
2755 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); 2764 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect));
2756 EXPECT_EQ("Some offscreen test text for testing.", selectionAsString(frame)) ; 2765 EXPECT_EQ("Some offscreen test text for testing.", selectionAsString(frame)) ;
2757 m_webView->close();
2758 m_webView = 0;
2759 } 2766 }
2760 2767
2761 TEST_F(WebFrameTest, SelectRangeInIframe) 2768 TEST_F(WebFrameTest, SelectRangeInIframe)
2762 { 2769 {
2763 WebFrame* frame; 2770 WebFrame* frame;
2764 WebRect startWebRect; 2771 WebRect startWebRect;
2765 WebRect endWebRect; 2772 WebRect endWebRect;
2766 2773
2767 registerMockedHttpURLLoad("select_range_iframe.html"); 2774 registerMockedHttpURLLoad("select_range_iframe.html");
2768 registerMockedHttpURLLoad("select_range_basic.html"); 2775 registerMockedHttpURLLoad("select_range_basic.html");
2769 2776
2770 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_iframe.h tml"); 2777 FrameTestHelpers::WebViewHelper webViewHelper;
2771 frame = m_webView->mainFrame(); 2778 initializeTextSelectionWebView(m_baseURL + "select_range_iframe.html", &webV iewHelper);
2779 frame = webViewHelper.webView()->mainFrame();
2772 WebFrame* subframe = frame->findChildByExpression(WebString::fromUTF8("/html /body/iframe")); 2780 WebFrame* subframe = frame->findChildByExpression(WebString::fromUTF8("/html /body/iframe"));
2773 EXPECT_EQ("Some test text for testing.", selectionAsString(subframe)); 2781 EXPECT_EQ("Some test text for testing.", selectionAsString(subframe));
2774 m_webView->selectionBounds(startWebRect, endWebRect); 2782 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect);
2775 subframe->executeCommand(WebString::fromUTF8("Unselect")); 2783 subframe->executeCommand(WebString::fromUTF8("Unselect"));
2776 EXPECT_EQ("", selectionAsString(subframe)); 2784 EXPECT_EQ("", selectionAsString(subframe));
2777 subframe->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect) ); 2785 subframe->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect) );
2778 EXPECT_EQ("Some test text for testing.", selectionAsString(subframe)); 2786 EXPECT_EQ("Some test text for testing.", selectionAsString(subframe));
2779 m_webView->close();
2780 m_webView = 0;
2781 } 2787 }
2782 2788
2783 TEST_F(WebFrameTest, SelectRangeDivContentEditable) 2789 TEST_F(WebFrameTest, SelectRangeDivContentEditable)
2784 { 2790 {
2785 WebFrame* frame; 2791 WebFrame* frame;
2786 WebRect startWebRect; 2792 WebRect startWebRect;
2787 WebRect endWebRect; 2793 WebRect endWebRect;
2788 2794
2789 registerMockedHttpURLLoad("select_range_div_editable.html"); 2795 registerMockedHttpURLLoad("select_range_div_editable.html");
2790 2796
2791 // Select the middle of an editable element, then try to extend the selectio n to the top of the document. 2797 // Select the middle of an editable element, then try to extend the selectio n to the top of the document.
2792 // The selection range should be clipped to the bounds of the editable eleme nt. 2798 // The selection range should be clipped to the bounds of the editable eleme nt.
2793 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_div_edit able.html"); 2799 FrameTestHelpers::WebViewHelper webViewHelper;
2794 frame = m_webView->mainFrame(); 2800 initializeTextSelectionWebView(m_baseURL + "select_range_div_editable.html", &webViewHelper);
2801 frame = webViewHelper.webView()->mainFrame();
2795 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); 2802 EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
2796 m_webView->selectionBounds(startWebRect, endWebRect); 2803 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect);
2797 2804
2798 frame->selectRange(bottomRightMinusOne(endWebRect), WebPoint(0, 0)); 2805 frame->selectRange(bottomRightMinusOne(endWebRect), WebPoint(0, 0));
2799 EXPECT_EQ("16-char header. This text is initially selected.", selectionAsStr ing(frame)); 2806 EXPECT_EQ("16-char header. This text is initially selected.", selectionAsStr ing(frame));
2800 m_webView->close();
2801 m_webView = 0;
2802 2807
2803 // As above, but extending the selection to the bottom of the document. 2808 // As above, but extending the selection to the bottom of the document.
2804 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_div_edit able.html"); 2809 initializeTextSelectionWebView(m_baseURL + "select_range_div_editable.html", &webViewHelper);
2805 frame = m_webView->mainFrame(); 2810 frame = webViewHelper.webView()->mainFrame();
2806 2811
2807 m_webView->selectionBounds(startWebRect, endWebRect); 2812 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect);
2808 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); 2813 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect));
2809 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); 2814 EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
2810 m_webView->selectionBounds(startWebRect, endWebRect); 2815 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect);
2811 2816
2812 m_webView->selectionBounds(startWebRect, endWebRect); 2817 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect);
2813 frame->selectRange(topLeft(startWebRect), WebPoint(640, 480)); 2818 frame->selectRange(topLeft(startWebRect), WebPoint(640, 480));
2814 EXPECT_EQ("This text is initially selected. 16-char footer.", selectionAsStr ing(frame)); 2819 EXPECT_EQ("This text is initially selected. 16-char footer.", selectionAsStr ing(frame));
2815 m_webView->close();
2816 m_webView = 0;
2817 } 2820 }
2818 2821
2819 // positionForPoint returns the wrong values for contenteditable spans. See 2822 // positionForPoint returns the wrong values for contenteditable spans. See
2820 // http://crbug.com/238334. 2823 // http://crbug.com/238334.
2821 TEST_F(WebFrameTest, DISABLED_SelectRangeSpanContentEditable) 2824 TEST_F(WebFrameTest, DISABLED_SelectRangeSpanContentEditable)
2822 { 2825 {
2823 WebFrame* frame; 2826 WebFrame* frame;
2824 WebRect startWebRect; 2827 WebRect startWebRect;
2825 WebRect endWebRect; 2828 WebRect endWebRect;
2826 2829
2827 registerMockedHttpURLLoad("select_range_span_editable.html"); 2830 registerMockedHttpURLLoad("select_range_span_editable.html");
2828 2831
2829 // Select the middle of an editable element, then try to extend the selectio n to the top of the document. 2832 // Select the middle of an editable element, then try to extend the selectio n to the top of the document.
2830 // The selection range should be clipped to the bounds of the editable eleme nt. 2833 // The selection range should be clipped to the bounds of the editable eleme nt.
2831 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_span_edi table.html"); 2834 FrameTestHelpers::WebViewHelper webViewHelper;
2832 frame = m_webView->mainFrame(); 2835 initializeTextSelectionWebView(m_baseURL + "select_range_span_editable.html" , &webViewHelper);
2836 frame = webViewHelper.webView()->mainFrame();
2833 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); 2837 EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
2834 m_webView->selectionBounds(startWebRect, endWebRect); 2838 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect);
2835 2839
2836 frame->selectRange(bottomRightMinusOne(endWebRect), WebPoint(0, 0)); 2840 frame->selectRange(bottomRightMinusOne(endWebRect), WebPoint(0, 0));
2837 EXPECT_EQ("16-char header. This text is initially selected.", selectionAsStr ing(frame)); 2841 EXPECT_EQ("16-char header. This text is initially selected.", selectionAsStr ing(frame));
2838 m_webView->close();
2839 m_webView = 0;
2840 2842
2841 // As above, but extending the selection to the bottom of the document. 2843 // As above, but extending the selection to the bottom of the document.
2842 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_span_edi table.html"); 2844 initializeTextSelectionWebView(m_baseURL + "select_range_span_editable.html" , &webViewHelper);
2843 frame = m_webView->mainFrame(); 2845 frame = webViewHelper.webView()->mainFrame();
2844 2846
2845 m_webView->selectionBounds(startWebRect, endWebRect); 2847 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect);
2846 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); 2848 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect));
2847 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); 2849 EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
2848 m_webView->selectionBounds(startWebRect, endWebRect); 2850 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect);
2849 2851
2850 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); 2852 EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
2851 m_webView->selectionBounds(startWebRect, endWebRect); 2853 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect);
2852 frame->selectRange(topLeft(startWebRect), WebPoint(640, 480)); 2854 frame->selectRange(topLeft(startWebRect), WebPoint(640, 480));
2853 EXPECT_EQ("This text is initially selected. 16-char footer.", selectionAsStr ing(frame)); 2855 EXPECT_EQ("This text is initially selected. 16-char footer.", selectionAsStr ing(frame));
2854 m_webView->close();
2855 m_webView = 0;
2856 } 2856 }
2857 2857
2858 TEST_F(WebFrameTest, SelectRangeCanMoveSelectionStart) 2858 TEST_F(WebFrameTest, SelectRangeCanMoveSelectionStart)
2859 { 2859 {
2860 registerMockedHttpURLLoad("text_selection.html"); 2860 registerMockedHttpURLLoad("text_selection.html");
2861 m_webView = createWebViewForTextSelection(m_baseURL + "text_selection.html") ; 2861 FrameTestHelpers::WebViewHelper webViewHelper;
2862 WebFrame* frame = m_webView->mainFrame(); 2862 initializeTextSelectionWebView(m_baseURL + "text_selection.html", &webViewHe lper);
2863 WebFrame* frame = webViewHelper.webView()->mainFrame();
2863 2864
2864 // Select second span. We can move the start to include the first span. 2865 // Select second span. We can move the start to include the first span.
2865 frame->executeScript(WebScriptSource("selectElement('header_2');")); 2866 frame->executeScript(WebScriptSource("selectElement('header_2');"));
2866 EXPECT_EQ("Header 2.", selectionAsString(frame)); 2867 EXPECT_EQ("Header 2.", selectionAsString(frame));
2867 frame->selectRange(bottomRightMinusOne(elementBounds(frame, "header_2")), to pLeft(elementBounds(frame, "header_1"))); 2868 frame->selectRange(bottomRightMinusOne(elementBounds(frame, "header_2")), to pLeft(elementBounds(frame, "header_1")));
2868 EXPECT_EQ("Header 1. Header 2.", selectionAsString(frame)); 2869 EXPECT_EQ("Header 1. Header 2.", selectionAsString(frame));
2869 2870
2870 // We can move the start and end together. 2871 // We can move the start and end together.
2871 frame->executeScript(WebScriptSource("selectElement('header_1');")); 2872 frame->executeScript(WebScriptSource("selectElement('header_1');"));
2872 EXPECT_EQ("Header 1.", selectionAsString(frame)); 2873 EXPECT_EQ("Header 1.", selectionAsString(frame));
(...skipping 25 matching lines...) Expand all
2898 EXPECT_EQ("Editable 2.", selectionAsString(frame)); 2899 EXPECT_EQ("Editable 2.", selectionAsString(frame));
2899 frame->selectRange(bottomRightMinusOne(elementBounds(frame, "editable_2")), topLeft(elementBounds(frame, "header_2"))); 2900 frame->selectRange(bottomRightMinusOne(elementBounds(frame, "editable_2")), topLeft(elementBounds(frame, "header_2")));
2900 // positionForPoint returns the wrong values for contenteditable spans. See 2901 // positionForPoint returns the wrong values for contenteditable spans. See
2901 // http://crbug.com/238334. 2902 // http://crbug.com/238334.
2902 // EXPECT_EQ("[ Editable 1. Editable 2.", selectionAsString(frame)); 2903 // EXPECT_EQ("[ Editable 1. Editable 2.", selectionAsString(frame));
2903 } 2904 }
2904 2905
2905 TEST_F(WebFrameTest, SelectRangeCanMoveSelectionEnd) 2906 TEST_F(WebFrameTest, SelectRangeCanMoveSelectionEnd)
2906 { 2907 {
2907 registerMockedHttpURLLoad("text_selection.html"); 2908 registerMockedHttpURLLoad("text_selection.html");
2908 m_webView = createWebViewForTextSelection(m_baseURL + "text_selection.html") ; 2909 FrameTestHelpers::WebViewHelper webViewHelper;
2909 WebFrame* frame = m_webView->mainFrame(); 2910 initializeTextSelectionWebView(m_baseURL + "text_selection.html", &webViewHe lper);
2911 WebFrame* frame = webViewHelper.webView()->mainFrame();
2910 2912
2911 // Select first span. We can move the end to include the second span. 2913 // Select first span. We can move the end to include the second span.
2912 frame->executeScript(WebScriptSource("selectElement('header_1');")); 2914 frame->executeScript(WebScriptSource("selectElement('header_1');"));
2913 EXPECT_EQ("Header 1.", selectionAsString(frame)); 2915 EXPECT_EQ("Header 1.", selectionAsString(frame));
2914 frame->selectRange(topLeft(elementBounds(frame, "header_1")), bottomRightMin usOne(elementBounds(frame, "header_2"))); 2916 frame->selectRange(topLeft(elementBounds(frame, "header_1")), bottomRightMin usOne(elementBounds(frame, "header_2")));
2915 EXPECT_EQ("Header 1. Header 2.", selectionAsString(frame)); 2917 EXPECT_EQ("Header 1. Header 2.", selectionAsString(frame));
2916 2918
2917 // We can move the start and end together. 2919 // We can move the start and end together.
2918 frame->executeScript(WebScriptSource("selectElement('header_2');")); 2920 frame->executeScript(WebScriptSource("selectElement('header_2');"));
2919 EXPECT_EQ("Header 2.", selectionAsString(frame)); 2921 EXPECT_EQ("Header 2.", selectionAsString(frame));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2952 static int computeOffset(WebCore::RenderObject* renderer, int x, int y) 2954 static int computeOffset(WebCore::RenderObject* renderer, int x, int y)
2953 { 2955 {
2954 return WebCore::VisiblePosition(renderer->positionForPoint(WebCore::LayoutPo int(x, y))).deepEquivalent().computeOffsetInContainerNode(); 2956 return WebCore::VisiblePosition(renderer->positionForPoint(WebCore::LayoutPo int(x, y))).deepEquivalent().computeOffsetInContainerNode();
2955 } 2957 }
2956 2958
2957 // positionForPoint returns the wrong values for contenteditable spans. See 2959 // positionForPoint returns the wrong values for contenteditable spans. See
2958 // http://crbug.com/238334. 2960 // http://crbug.com/238334.
2959 TEST_F(WebFrameTest, DISABLED_PositionForPointTest) 2961 TEST_F(WebFrameTest, DISABLED_PositionForPointTest)
2960 { 2962 {
2961 registerMockedHttpURLLoad("select_range_span_editable.html"); 2963 registerMockedHttpURLLoad("select_range_span_editable.html");
2962 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_span_edi table.html"); 2964 FrameTestHelpers::WebViewHelper webViewHelper;
2963 WebFrameImpl* mainFrame = toWebFrameImpl(m_webView->mainFrame()); 2965 initializeTextSelectionWebView(m_baseURL + "select_range_span_editable.html" , &webViewHelper);
2966 WebFrameImpl* mainFrame = toWebFrameImpl(webViewHelper.webView()->mainFrame( ));
2964 WebCore::RenderObject* renderer = mainFrame->frame()->selection().rootEditab leElement()->renderer(); 2967 WebCore::RenderObject* renderer = mainFrame->frame()->selection().rootEditab leElement()->renderer();
2965 EXPECT_EQ(0, computeOffset(renderer, -1, -1)); 2968 EXPECT_EQ(0, computeOffset(renderer, -1, -1));
2966 EXPECT_EQ(64, computeOffset(renderer, 1000, 1000)); 2969 EXPECT_EQ(64, computeOffset(renderer, 1000, 1000));
2967 2970
2968 registerMockedHttpURLLoad("select_range_div_editable.html"); 2971 registerMockedHttpURLLoad("select_range_div_editable.html");
2969 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_div_edit able.html"); 2972 initializeTextSelectionWebView(m_baseURL + "select_range_div_editable.html", &webViewHelper);
2970 mainFrame = toWebFrameImpl(m_webView->mainFrame()); 2973 mainFrame = toWebFrameImpl(webViewHelper.webView()->mainFrame());
2971 renderer = mainFrame->frame()->selection().rootEditableElement()->renderer() ; 2974 renderer = mainFrame->frame()->selection().rootEditableElement()->renderer() ;
2972 EXPECT_EQ(0, computeOffset(renderer, -1, -1)); 2975 EXPECT_EQ(0, computeOffset(renderer, -1, -1));
2973 EXPECT_EQ(64, computeOffset(renderer, 1000, 1000)); 2976 EXPECT_EQ(64, computeOffset(renderer, 1000, 1000));
2974 } 2977 }
2975 2978
2976 #if !OS(MACOSX) 2979 #if !OS(MACOSX)
2977 TEST_F(WebFrameTest, SelectRangeStaysHorizontallyAlignedWhenMoved) 2980 TEST_F(WebFrameTest, SelectRangeStaysHorizontallyAlignedWhenMoved)
2978 { 2981 {
2979 WebFrameImpl* frame;
2980 registerMockedHttpURLLoad("move_caret.html"); 2982 registerMockedHttpURLLoad("move_caret.html");
2981 2983
2982 m_webView = createWebViewForTextSelection(m_baseURL + "move_caret.html"); 2984 FrameTestHelpers::WebViewHelper webViewHelper;
2983 frame = (WebFrameImpl*)m_webView->mainFrame(); 2985 initializeTextSelectionWebView(m_baseURL + "move_caret.html", &webViewHelper );
2986 WebFrameImpl* frame = toWebFrameImpl(webViewHelper.webView()->mainFrame());
2984 2987
2985 WebRect initialStartRect; 2988 WebRect initialStartRect;
2986 WebRect initialEndRect; 2989 WebRect initialEndRect;
2987 WebRect startRect; 2990 WebRect startRect;
2988 WebRect endRect; 2991 WebRect endRect;
2989 2992
2990 frame->executeScript(WebScriptSource("selectRange();")); 2993 frame->executeScript(WebScriptSource("selectRange();"));
2991 m_webView->selectionBounds(initialStartRect, initialEndRect); 2994 webViewHelper.webView()->selectionBounds(initialStartRect, initialEndRect);
2992 WebPoint movedStart(topLeft(initialStartRect)); 2995 WebPoint movedStart(topLeft(initialStartRect));
2993 2996
2994 movedStart.y += 40; 2997 movedStart.y += 40;
2995 frame->selectRange(movedStart, bottomRightMinusOne(initialEndRect)); 2998 frame->selectRange(movedStart, bottomRightMinusOne(initialEndRect));
2996 m_webView->selectionBounds(startRect, endRect); 2999 webViewHelper.webView()->selectionBounds(startRect, endRect);
2997 EXPECT_EQ(startRect, initialStartRect); 3000 EXPECT_EQ(startRect, initialStartRect);
2998 EXPECT_EQ(endRect, initialEndRect); 3001 EXPECT_EQ(endRect, initialEndRect);
2999 3002
3000 movedStart.y -= 80; 3003 movedStart.y -= 80;
3001 frame->selectRange(movedStart, bottomRightMinusOne(initialEndRect)); 3004 frame->selectRange(movedStart, bottomRightMinusOne(initialEndRect));
3002 m_webView->selectionBounds(startRect, endRect); 3005 webViewHelper.webView()->selectionBounds(startRect, endRect);
3003 EXPECT_EQ(startRect, initialStartRect); 3006 EXPECT_EQ(startRect, initialStartRect);
3004 EXPECT_EQ(endRect, initialEndRect); 3007 EXPECT_EQ(endRect, initialEndRect);
3005 3008
3006 WebPoint movedEnd(bottomRightMinusOne(initialEndRect)); 3009 WebPoint movedEnd(bottomRightMinusOne(initialEndRect));
3007 3010
3008 movedEnd.y += 40; 3011 movedEnd.y += 40;
3009 frame->selectRange(topLeft(initialStartRect), movedEnd); 3012 frame->selectRange(topLeft(initialStartRect), movedEnd);
3010 m_webView->selectionBounds(startRect, endRect); 3013 webViewHelper.webView()->selectionBounds(startRect, endRect);
3011 EXPECT_EQ(startRect, initialStartRect); 3014 EXPECT_EQ(startRect, initialStartRect);
3012 EXPECT_EQ(endRect, initialEndRect); 3015 EXPECT_EQ(endRect, initialEndRect);
3013 3016
3014 movedEnd.y -= 80; 3017 movedEnd.y -= 80;
3015 frame->selectRange(topLeft(initialStartRect), movedEnd); 3018 frame->selectRange(topLeft(initialStartRect), movedEnd);
3016 m_webView->selectionBounds(startRect, endRect); 3019 webViewHelper.webView()->selectionBounds(startRect, endRect);
3017 EXPECT_EQ(startRect, initialStartRect); 3020 EXPECT_EQ(startRect, initialStartRect);
3018 EXPECT_EQ(endRect, initialEndRect); 3021 EXPECT_EQ(endRect, initialEndRect);
3019 } 3022 }
3020 3023
3021 TEST_F(WebFrameTest, MoveCaretStaysHorizontallyAlignedWhenMoved) 3024 TEST_F(WebFrameTest, MoveCaretStaysHorizontallyAlignedWhenMoved)
3022 { 3025 {
3023 WebFrameImpl* frame; 3026 WebFrameImpl* frame;
3024 registerMockedHttpURLLoad("move_caret.html"); 3027 registerMockedHttpURLLoad("move_caret.html");
3025 3028
3026 m_webView = createWebViewForTextSelection(m_baseURL + "move_caret.html"); 3029 FrameTestHelpers::WebViewHelper webViewHelper;
3027 frame = (WebFrameImpl*)m_webView->mainFrame(); 3030 initializeTextSelectionWebView(m_baseURL + "move_caret.html", &webViewHelper );
3031 frame = (WebFrameImpl*)webViewHelper.webView()->mainFrame();
3028 3032
3029 WebRect initialStartRect; 3033 WebRect initialStartRect;
3030 WebRect initialEndRect; 3034 WebRect initialEndRect;
3031 WebRect startRect; 3035 WebRect startRect;
3032 WebRect endRect; 3036 WebRect endRect;
3033 3037
3034 frame->executeScript(WebScriptSource("selectCaret();")); 3038 frame->executeScript(WebScriptSource("selectCaret();"));
3035 m_webView->selectionBounds(initialStartRect, initialEndRect); 3039 webViewHelper.webView()->selectionBounds(initialStartRect, initialEndRect);
3036 WebPoint moveTo(topLeft(initialStartRect)); 3040 WebPoint moveTo(topLeft(initialStartRect));
3037 3041
3038 moveTo.y += 40; 3042 moveTo.y += 40;
3039 frame->moveCaretSelectionTowardsWindowPoint(moveTo); 3043 frame->moveCaretSelectionTowardsWindowPoint(moveTo);
3040 m_webView->selectionBounds(startRect, endRect); 3044 webViewHelper.webView()->selectionBounds(startRect, endRect);
3041 EXPECT_EQ(startRect, initialStartRect); 3045 EXPECT_EQ(startRect, initialStartRect);
3042 EXPECT_EQ(endRect, initialEndRect); 3046 EXPECT_EQ(endRect, initialEndRect);
3043 3047
3044 moveTo.y -= 80; 3048 moveTo.y -= 80;
3045 frame->moveCaretSelectionTowardsWindowPoint(moveTo); 3049 frame->moveCaretSelectionTowardsWindowPoint(moveTo);
3046 m_webView->selectionBounds(startRect, endRect); 3050 webViewHelper.webView()->selectionBounds(startRect, endRect);
3047 EXPECT_EQ(startRect, initialStartRect); 3051 EXPECT_EQ(startRect, initialStartRect);
3048 EXPECT_EQ(endRect, initialEndRect); 3052 EXPECT_EQ(endRect, initialEndRect);
3049 } 3053 }
3050 #endif 3054 #endif
3051 3055
3052 class DisambiguationPopupTestWebViewClient : public WebViewClient { 3056 class DisambiguationPopupTestWebViewClient : public WebViewClient {
3053 public: 3057 public:
3054 virtual bool didTapMultipleTargets(const WebGestureEvent&, const WebVector<W ebRect>& targetRects) OVERRIDE 3058 virtual bool didTapMultipleTargets(const WebGestureEvent&, const WebVector<W ebRect>& targetRects) OVERRIDE
3055 { 3059 {
3056 EXPECT_GE(targetRects.size(), 2u); 3060 EXPECT_GE(targetRects.size(), 2u);
(...skipping 19 matching lines...) Expand all
3076 3080
3077 TEST_F(WebFrameTest, DisambiguationPopup) 3081 TEST_F(WebFrameTest, DisambiguationPopup)
3078 { 3082 {
3079 const std::string htmlFile = "disambiguation_popup.html"; 3083 const std::string htmlFile = "disambiguation_popup.html";
3080 registerMockedHttpURLLoad(htmlFile); 3084 registerMockedHttpURLLoad(htmlFile);
3081 3085
3082 DisambiguationPopupTestWebViewClient client; 3086 DisambiguationPopupTestWebViewClient client;
3083 3087
3084 // Make sure we initialize to minimum scale, even if the window size 3088 // Make sure we initialize to minimum scale, even if the window size
3085 // only becomes available after the load begins. 3089 // only becomes available after the load begins.
3086 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + htmlFile, tru e, 0, &client); 3090 FrameTestHelpers::WebViewHelper webViewHelper;
3087 m_webView->resize(WebSize(1000, 1000)); 3091 webViewHelper.initializeAndLoad(m_baseURL + htmlFile, true, 0, &client);
3088 m_webView->layout(); 3092 webViewHelper.webView()->resize(WebSize(1000, 1000));
3093 webViewHelper.webView()->layout();
3089 3094
3090 client.resetTriggered(); 3095 client.resetTriggered();
3091 m_webView->handleInputEvent(fatTap(0, 0)); 3096 webViewHelper.webView()->handleInputEvent(fatTap(0, 0));
3092 EXPECT_FALSE(client.triggered()); 3097 EXPECT_FALSE(client.triggered());
3093 3098
3094 client.resetTriggered(); 3099 client.resetTriggered();
3095 m_webView->handleInputEvent(fatTap(200, 115)); 3100 webViewHelper.webView()->handleInputEvent(fatTap(200, 115));
3096 EXPECT_FALSE(client.triggered()); 3101 EXPECT_FALSE(client.triggered());
3097 3102
3098 for (int i = 0; i <= 46; i++) { 3103 for (int i = 0; i <= 46; i++) {
3099 client.resetTriggered(); 3104 client.resetTriggered();
3100 m_webView->handleInputEvent(fatTap(120, 230 + i * 5)); 3105 webViewHelper.webView()->handleInputEvent(fatTap(120, 230 + i * 5));
3101 3106
3102 int j = i % 10; 3107 int j = i % 10;
3103 if (j >= 7 && j <= 9) 3108 if (j >= 7 && j <= 9)
3104 EXPECT_TRUE(client.triggered()); 3109 EXPECT_TRUE(client.triggered());
3105 else 3110 else
3106 EXPECT_FALSE(client.triggered()); 3111 EXPECT_FALSE(client.triggered());
3107 } 3112 }
3108 3113
3109 for (int i = 0; i <= 46; i++) { 3114 for (int i = 0; i <= 46; i++) {
3110 client.resetTriggered(); 3115 client.resetTriggered();
3111 m_webView->handleInputEvent(fatTap(10 + i * 5, 590)); 3116 webViewHelper.webView()->handleInputEvent(fatTap(10 + i * 5, 590));
3112 3117
3113 int j = i % 10; 3118 int j = i % 10;
3114 if (j >= 7 && j <= 9) 3119 if (j >= 7 && j <= 9)
3115 EXPECT_TRUE(client.triggered()); 3120 EXPECT_TRUE(client.triggered());
3116 else 3121 else
3117 EXPECT_FALSE(client.triggered()); 3122 EXPECT_FALSE(client.triggered());
3118 } 3123 }
3119
3120 m_webView->close();
3121 m_webView = 0;
3122
3123 } 3124 }
3124 3125
3125 TEST_F(WebFrameTest, DisambiguationPopupNoContainer) 3126 TEST_F(WebFrameTest, DisambiguationPopupNoContainer)
3126 { 3127 {
3127 registerMockedHttpURLLoad("disambiguation_popup_no_container.html"); 3128 registerMockedHttpURLLoad("disambiguation_popup_no_container.html");
3128 3129
3129 DisambiguationPopupTestWebViewClient client; 3130 DisambiguationPopupTestWebViewClient client;
3130 3131
3131 // Make sure we initialize to minimum scale, even if the window size 3132 // Make sure we initialize to minimum scale, even if the window size
3132 // only becomes available after the load begins. 3133 // only becomes available after the load begins.
3133 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "disambiguati on_popup_no_container.html", true, 0, &client); 3134 FrameTestHelpers::WebViewHelper webViewHelper;
3134 m_webView->resize(WebSize(1000, 1000)); 3135 webViewHelper.initializeAndLoad(m_baseURL + "disambiguation_popup_no_contain er.html", true, 0, &client);
3135 m_webView->layout(); 3136 webViewHelper.webView()->resize(WebSize(1000, 1000));
3137 webViewHelper.webView()->layout();
3136 3138
3137 client.resetTriggered(); 3139 client.resetTriggered();
3138 m_webView->handleInputEvent(fatTap(50, 50)); 3140 webViewHelper.webView()->handleInputEvent(fatTap(50, 50));
3139 EXPECT_FALSE(client.triggered()); 3141 EXPECT_FALSE(client.triggered());
3140
3141 m_webView->close();
3142 m_webView = 0;
3143 } 3142 }
3144 3143
3145 TEST_F(WebFrameTest, DisambiguationPopupMobileSite) 3144 TEST_F(WebFrameTest, DisambiguationPopupMobileSite)
3146 { 3145 {
3147 const std::string htmlFile = "disambiguation_popup_mobile_site.html"; 3146 const std::string htmlFile = "disambiguation_popup_mobile_site.html";
3148 registerMockedHttpURLLoad(htmlFile); 3147 registerMockedHttpURLLoad(htmlFile);
3149 3148
3150 DisambiguationPopupTestWebViewClient client; 3149 DisambiguationPopupTestWebViewClient client;
3151 3150
3152 // Make sure we initialize to minimum scale, even if the window size 3151 // Make sure we initialize to minimum scale, even if the window size
3153 // only becomes available after the load begins. 3152 // only becomes available after the load begins.
3154 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + htmlFile, tru e, 0, &client); 3153 FrameTestHelpers::WebViewHelper webViewHelper;
3155 m_webView->enableFixedLayoutMode(true); 3154 webViewHelper.initializeAndLoad(m_baseURL + htmlFile, true, 0, &client);
3156 m_webView->settings()->setViewportEnabled(true); 3155 webViewHelper.webView()->enableFixedLayoutMode(true);
3157 m_webView->resize(WebSize(1000, 1000)); 3156 webViewHelper.webView()->settings()->setViewportEnabled(true);
3158 m_webView->layout(); 3157 webViewHelper.webView()->resize(WebSize(1000, 1000));
3158 webViewHelper.webView()->layout();
3159 3159
3160 client.resetTriggered(); 3160 client.resetTriggered();
3161 m_webView->handleInputEvent(fatTap(0, 0)); 3161 webViewHelper.webView()->handleInputEvent(fatTap(0, 0));
3162 EXPECT_FALSE(client.triggered()); 3162 EXPECT_FALSE(client.triggered());
3163 3163
3164 client.resetTriggered(); 3164 client.resetTriggered();
3165 m_webView->handleInputEvent(fatTap(200, 115)); 3165 webViewHelper.webView()->handleInputEvent(fatTap(200, 115));
3166 EXPECT_FALSE(client.triggered()); 3166 EXPECT_FALSE(client.triggered());
3167 3167
3168 for (int i = 0; i <= 46; i++) { 3168 for (int i = 0; i <= 46; i++) {
3169 client.resetTriggered(); 3169 client.resetTriggered();
3170 m_webView->handleInputEvent(fatTap(120, 230 + i * 5)); 3170 webViewHelper.webView()->handleInputEvent(fatTap(120, 230 + i * 5));
3171 EXPECT_FALSE(client.triggered()); 3171 EXPECT_FALSE(client.triggered());
3172 } 3172 }
3173 3173
3174 for (int i = 0; i <= 46; i++) { 3174 for (int i = 0; i <= 46; i++) {
3175 client.resetTriggered(); 3175 client.resetTriggered();
3176 m_webView->handleInputEvent(fatTap(10 + i * 5, 590)); 3176 webViewHelper.webView()->handleInputEvent(fatTap(10 + i * 5, 590));
3177 EXPECT_FALSE(client.triggered()); 3177 EXPECT_FALSE(client.triggered());
3178 } 3178 }
3179
3180 m_webView->close();
3181 m_webView = 0;
3182 } 3179 }
3183 3180
3184 TEST_F(WebFrameTest, DisambiguationPopupViewportSite) 3181 TEST_F(WebFrameTest, DisambiguationPopupViewportSite)
3185 { 3182 {
3186 const std::string htmlFile = "disambiguation_popup_viewport_site.html"; 3183 const std::string htmlFile = "disambiguation_popup_viewport_site.html";
3187 registerMockedHttpURLLoad(htmlFile); 3184 registerMockedHttpURLLoad(htmlFile);
3188 3185
3189 DisambiguationPopupTestWebViewClient client; 3186 DisambiguationPopupTestWebViewClient client;
3190 3187
3191 // Make sure we initialize to minimum scale, even if the window size 3188 // Make sure we initialize to minimum scale, even if the window size
3192 // only becomes available after the load begins. 3189 // only becomes available after the load begins.
3193 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + htmlFile, tru e, 0, &client); 3190 FrameTestHelpers::WebViewHelper webViewHelper;
3194 m_webView->enableFixedLayoutMode(true); 3191 webViewHelper.initializeAndLoad(m_baseURL + htmlFile, true, 0, &client);
3195 m_webView->settings()->setViewportEnabled(true); 3192 webViewHelper.webView()->enableFixedLayoutMode(true);
3196 m_webView->resize(WebSize(1000, 1000)); 3193 webViewHelper.webView()->settings()->setViewportEnabled(true);
3197 m_webView->layout(); 3194 webViewHelper.webView()->resize(WebSize(1000, 1000));
3195 webViewHelper.webView()->layout();
3198 3196
3199 client.resetTriggered(); 3197 client.resetTriggered();
3200 m_webView->handleInputEvent(fatTap(0, 0)); 3198 webViewHelper.webView()->handleInputEvent(fatTap(0, 0));
3201 EXPECT_FALSE(client.triggered()); 3199 EXPECT_FALSE(client.triggered());
3202 3200
3203 client.resetTriggered(); 3201 client.resetTriggered();
3204 m_webView->handleInputEvent(fatTap(200, 115)); 3202 webViewHelper.webView()->handleInputEvent(fatTap(200, 115));
3205 EXPECT_FALSE(client.triggered()); 3203 EXPECT_FALSE(client.triggered());
3206 3204
3207 for (int i = 0; i <= 46; i++) { 3205 for (int i = 0; i <= 46; i++) {
3208 client.resetTriggered(); 3206 client.resetTriggered();
3209 m_webView->handleInputEvent(fatTap(120, 230 + i * 5)); 3207 webViewHelper.webView()->handleInputEvent(fatTap(120, 230 + i * 5));
3210 EXPECT_FALSE(client.triggered()); 3208 EXPECT_FALSE(client.triggered());
3211 } 3209 }
3212 3210
3213 for (int i = 0; i <= 46; i++) { 3211 for (int i = 0; i <= 46; i++) {
3214 client.resetTriggered(); 3212 client.resetTriggered();
3215 m_webView->handleInputEvent(fatTap(10 + i * 5, 590)); 3213 webViewHelper.webView()->handleInputEvent(fatTap(10 + i * 5, 590));
3216 EXPECT_FALSE(client.triggered()); 3214 EXPECT_FALSE(client.triggered());
3217 } 3215 }
3218
3219 m_webView->close();
3220 m_webView = 0;
3221 } 3216 }
3222 3217
3223 TEST_F(WebFrameTest, DisambiguationPopupBlacklist) 3218 TEST_F(WebFrameTest, DisambiguationPopupBlacklist)
3224 { 3219 {
3225 const unsigned viewportWidth = 500; 3220 const unsigned viewportWidth = 500;
3226 const unsigned viewportHeight = 1000; 3221 const unsigned viewportHeight = 1000;
3227 const unsigned divHeight = 100; 3222 const unsigned divHeight = 100;
3228 const std::string htmlFile = "disambiguation_popup_blacklist.html"; 3223 const std::string htmlFile = "disambiguation_popup_blacklist.html";
3229 registerMockedHttpURLLoad(htmlFile); 3224 registerMockedHttpURLLoad(htmlFile);
3230 3225
3231 DisambiguationPopupTestWebViewClient client; 3226 DisambiguationPopupTestWebViewClient client;
3232 3227
3233 // Make sure we initialize to minimum scale, even if the window size 3228 // Make sure we initialize to minimum scale, even if the window size
3234 // only becomes available after the load begins. 3229 // only becomes available after the load begins.
3235 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + htmlFile, tru e, 0, &client); 3230 FrameTestHelpers::WebViewHelper webViewHelper;
3236 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 3231 webViewHelper.initializeAndLoad(m_baseURL + htmlFile, true, 0, &client);
3237 m_webView->layout(); 3232 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
3233 webViewHelper.webView()->layout();
3238 3234
3239 // Click somewhere where the popup shouldn't appear. 3235 // Click somewhere where the popup shouldn't appear.
3240 client.resetTriggered(); 3236 client.resetTriggered();
3241 m_webView->handleInputEvent(fatTap(viewportWidth / 2, 0)); 3237 webViewHelper.webView()->handleInputEvent(fatTap(viewportWidth / 2, 0));
3242 EXPECT_FALSE(client.triggered()); 3238 EXPECT_FALSE(client.triggered());
3243 3239
3244 // Click directly in between two container divs with click handlers, with ch ildren that don't handle clicks. 3240 // Click directly in between two container divs with click handlers, with ch ildren that don't handle clicks.
3245 client.resetTriggered(); 3241 client.resetTriggered();
3246 m_webView->handleInputEvent(fatTap(viewportWidth / 2, divHeight)); 3242 webViewHelper.webView()->handleInputEvent(fatTap(viewportWidth / 2, divHeigh t));
3247 EXPECT_TRUE(client.triggered()); 3243 EXPECT_TRUE(client.triggered());
3248 3244
3249 // The third div container should be blacklisted if you click on the link it contains. 3245 // The third div container should be blacklisted if you click on the link it contains.
3250 client.resetTriggered(); 3246 client.resetTriggered();
3251 m_webView->handleInputEvent(fatTap(viewportWidth / 2, divHeight * 3.25)); 3247 webViewHelper.webView()->handleInputEvent(fatTap(viewportWidth / 2, divHeigh t * 3.25));
3252 EXPECT_FALSE(client.triggered()); 3248 EXPECT_FALSE(client.triggered());
3253
3254 m_webView->close();
3255 m_webView = 0;
3256 } 3249 }
3257 3250
3258 TEST_F(WebFrameTest, DisambiguationPopupPageScale) 3251 TEST_F(WebFrameTest, DisambiguationPopupPageScale)
3259 { 3252 {
3260 registerMockedHttpURLLoad("disambiguation_popup_page_scale.html"); 3253 registerMockedHttpURLLoad("disambiguation_popup_page_scale.html");
3261 3254
3262 DisambiguationPopupTestWebViewClient client; 3255 DisambiguationPopupTestWebViewClient client;
3263 3256
3264 // Make sure we initialize to minimum scale, even if the window size 3257 // Make sure we initialize to minimum scale, even if the window size
3265 // only becomes available after the load begins. 3258 // only becomes available after the load begins.
3266 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "disambiguati on_popup_page_scale.html", true, 0, &client); 3259 FrameTestHelpers::WebViewHelper webViewHelper;
3267 m_webView->resize(WebSize(1000, 1000)); 3260 webViewHelper.initializeAndLoad(m_baseURL + "disambiguation_popup_page_scale .html", true, 0, &client);
3268 m_webView->layout(); 3261 webViewHelper.webView()->resize(WebSize(1000, 1000));
3262 webViewHelper.webView()->layout();
3269 3263
3270 client.resetTriggered(); 3264 client.resetTriggered();
3271 m_webView->handleInputEvent(fatTap(80, 80)); 3265 webViewHelper.webView()->handleInputEvent(fatTap(80, 80));
3272 EXPECT_TRUE(client.triggered()); 3266 EXPECT_TRUE(client.triggered());
3273 3267
3274 client.resetTriggered(); 3268 client.resetTriggered();
3275 m_webView->handleInputEvent(fatTap(230, 190)); 3269 webViewHelper.webView()->handleInputEvent(fatTap(230, 190));
3276 EXPECT_TRUE(client.triggered()); 3270 EXPECT_TRUE(client.triggered());
3277 3271
3278 m_webView->setPageScaleFactor(3.0f, WebPoint(0, 0)); 3272 webViewHelper.webView()->setPageScaleFactor(3.0f, WebPoint(0, 0));
3279 m_webView->layout(); 3273 webViewHelper.webView()->layout();
3280 3274
3281 client.resetTriggered(); 3275 client.resetTriggered();
3282 m_webView->handleInputEvent(fatTap(240, 240)); 3276 webViewHelper.webView()->handleInputEvent(fatTap(240, 240));
3283 EXPECT_TRUE(client.triggered()); 3277 EXPECT_TRUE(client.triggered());
3284 3278
3285 client.resetTriggered(); 3279 client.resetTriggered();
3286 m_webView->handleInputEvent(fatTap(690, 570)); 3280 webViewHelper.webView()->handleInputEvent(fatTap(690, 570));
3287 EXPECT_FALSE(client.triggered()); 3281 EXPECT_FALSE(client.triggered());
3288
3289 m_webView->close();
3290 m_webView = 0;
3291 } 3282 }
3292 3283
3293 class TestSubstituteDataWebFrameClient : public WebFrameClient { 3284 class TestSubstituteDataWebFrameClient : public WebFrameClient {
3294 public: 3285 public:
3295 TestSubstituteDataWebFrameClient() 3286 TestSubstituteDataWebFrameClient()
3296 : m_commitCalled(false) 3287 : m_commitCalled(false)
3297 { 3288 {
3298 } 3289 }
3299 3290
3300 virtual void didFailProvisionalLoad(WebFrame* frame, const WebURLError& erro r) 3291 virtual void didFailProvisionalLoad(WebFrame* frame, const WebURLError& erro r)
(...skipping 11 matching lines...) Expand all
3312 bool commitCalled() const { return m_commitCalled; } 3303 bool commitCalled() const { return m_commitCalled; }
3313 3304
3314 private: 3305 private:
3315 bool m_commitCalled; 3306 bool m_commitCalled;
3316 }; 3307 };
3317 3308
3318 TEST_F(WebFrameTest, ReplaceNavigationAfterHistoryNavigation) 3309 TEST_F(WebFrameTest, ReplaceNavigationAfterHistoryNavigation)
3319 { 3310 {
3320 TestSubstituteDataWebFrameClient webFrameClient; 3311 TestSubstituteDataWebFrameClient webFrameClient;
3321 3312
3322 m_webView = FrameTestHelpers::createWebViewAndLoad("about:blank", true, &web FrameClient); 3313 FrameTestHelpers::WebViewHelper webViewHelper;
3314 webViewHelper.initializeAndLoad("about:blank", true, &webFrameClient);
3323 runPendingTasks(); 3315 runPendingTasks();
3324 WebFrame* frame = m_webView->mainFrame(); 3316 WebFrame* frame = webViewHelper.webView()->mainFrame();
3325 3317
3326 // Load a url as a history navigation that will return an error. TestSubstit uteDataWebFrameClient 3318 // Load a url as a history navigation that will return an error. TestSubstit uteDataWebFrameClient
3327 // will start a SubstituteData load in response to the load failure, which s hould get fully committed. 3319 // will start a SubstituteData load in response to the load failure, which s hould get fully committed.
3328 // Due to https://bugs.webkit.org/show_bug.cgi?id=91685, FrameLoader::didRec eiveData() wasn't getting 3320 // Due to https://bugs.webkit.org/show_bug.cgi?id=91685, FrameLoader::didRec eiveData() wasn't getting
3329 // called in this case, which resulted in the SubstituteData document not ge tting displayed. 3321 // called in this case, which resulted in the SubstituteData document not ge tting displayed.
3330 WebURLError error; 3322 WebURLError error;
3331 error.reason = 1337; 3323 error.reason = 1337;
3332 error.domain = "WebFrameTest"; 3324 error.domain = "WebFrameTest";
3333 std::string errorURL = "http://0.0.0.0"; 3325 std::string errorURL = "http://0.0.0.0";
3334 WebURLResponse response; 3326 WebURLResponse response;
3335 response.initialize(); 3327 response.initialize();
3336 response.setURL(URLTestHelpers::toKURL(errorURL)); 3328 response.setURL(URLTestHelpers::toKURL(errorURL));
3337 response.setMIMEType("text/html"); 3329 response.setMIMEType("text/html");
3338 response.setHTTPStatusCode(500); 3330 response.setHTTPStatusCode(500);
3339 WebHistoryItem errorHistoryItem; 3331 WebHistoryItem errorHistoryItem;
3340 errorHistoryItem.initialize(); 3332 errorHistoryItem.initialize();
3341 errorHistoryItem.setURLString(WebString::fromUTF8(errorURL.c_str(), errorURL .length())); 3333 errorHistoryItem.setURLString(WebString::fromUTF8(errorURL.c_str(), errorURL .length()));
3342 errorHistoryItem.setOriginalURLString(WebString::fromUTF8(errorURL.c_str(), errorURL.length())); 3334 errorHistoryItem.setOriginalURLString(WebString::fromUTF8(errorURL.c_str(), errorURL.length()));
3343 Platform::current()->unitTestSupport()->registerMockedErrorURL(URLTestHelper s::toKURL(errorURL), response, error); 3335 Platform::current()->unitTestSupport()->registerMockedErrorURL(URLTestHelper s::toKURL(errorURL), response, error);
3344 frame->loadHistoryItem(errorHistoryItem); 3336 frame->loadHistoryItem(errorHistoryItem);
3345 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 3337 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
3346 3338
3347 WebString text = frame->contentAsText(std::numeric_limits<size_t>::max()); 3339 WebString text = frame->contentAsText(std::numeric_limits<size_t>::max());
3348 EXPECT_EQ("This should appear", std::string(text.utf8().data())); 3340 EXPECT_EQ("This should appear", std::string(text.utf8().data()));
3349 EXPECT_TRUE(webFrameClient.commitCalled()); 3341 EXPECT_TRUE(webFrameClient.commitCalled());
3350
3351 m_webView->close();
3352 m_webView = 0;
3353 } 3342 }
3354 3343
3355 class TestWillInsertBodyWebFrameClient : public WebFrameClient { 3344 class TestWillInsertBodyWebFrameClient : public WebFrameClient {
3356 public: 3345 public:
3357 TestWillInsertBodyWebFrameClient() : m_numBodies(0), m_didLoad(false) 3346 TestWillInsertBodyWebFrameClient() : m_numBodies(0), m_didLoad(false)
3358 { 3347 {
3359 } 3348 }
3360 3349
3361 virtual void didCommitProvisionalLoad(WebFrame*, bool) OVERRIDE 3350 virtual void didCommitProvisionalLoad(WebFrame*, bool) OVERRIDE
3362 { 3351 {
(...skipping 13 matching lines...) Expand all
3376 3365
3377 int m_numBodies; 3366 int m_numBodies;
3378 bool m_didLoad; 3367 bool m_didLoad;
3379 }; 3368 };
3380 3369
3381 TEST_F(WebFrameTest, HTMLDocument) 3370 TEST_F(WebFrameTest, HTMLDocument)
3382 { 3371 {
3383 registerMockedHttpURLLoad("clipped-body.html"); 3372 registerMockedHttpURLLoad("clipped-body.html");
3384 3373
3385 TestWillInsertBodyWebFrameClient webFrameClient; 3374 TestWillInsertBodyWebFrameClient webFrameClient;
3386 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "clipped-body .html", false, &webFrameClient); 3375 FrameTestHelpers::WebViewHelper webViewHelper;
3376 webViewHelper.initializeAndLoad(m_baseURL + "clipped-body.html", false, &web FrameClient);
3387 3377
3388 EXPECT_TRUE(webFrameClient.m_didLoad); 3378 EXPECT_TRUE(webFrameClient.m_didLoad);
3389 EXPECT_EQ(1, webFrameClient.m_numBodies); 3379 EXPECT_EQ(1, webFrameClient.m_numBodies);
3390
3391 m_webView->close();
3392 m_webView = 0;
3393 } 3380 }
3394 3381
3395 TEST_F(WebFrameTest, EmptyDocument) 3382 TEST_F(WebFrameTest, EmptyDocument)
3396 { 3383 {
3397 registerMockedHttpURLLoad("pageserializer/green_rectangle.svg"); 3384 registerMockedHttpURLLoad("pageserializer/green_rectangle.svg");
3398 3385
3399 TestWillInsertBodyWebFrameClient webFrameClient; 3386 TestWillInsertBodyWebFrameClient webFrameClient;
3400 m_webView = FrameTestHelpers::createWebView(false, &webFrameClient); 3387 FrameTestHelpers::WebViewHelper webViewHelper;
3388 webViewHelper.initialize(false, &webFrameClient);
3401 3389
3402 EXPECT_FALSE(webFrameClient.m_didLoad); 3390 EXPECT_FALSE(webFrameClient.m_didLoad);
3403 EXPECT_EQ(1, webFrameClient.m_numBodies); // The empty document that a new f rame starts with triggers this. 3391 EXPECT_EQ(1, webFrameClient.m_numBodies); // The empty document that a new f rame starts with triggers this.
3404 m_webView->close();
3405 m_webView = 0;
3406 } 3392 }
3407 3393
3408 TEST_F(WebFrameTest, MoveCaretSelectionTowardsWindowPointWithNoSelection) 3394 TEST_F(WebFrameTest, MoveCaretSelectionTowardsWindowPointWithNoSelection)
3409 { 3395 {
3410 m_webView = FrameTestHelpers::createWebViewAndLoad("about:blank", true); 3396 FrameTestHelpers::WebViewHelper webViewHelper;
3411 WebFrame* frame = m_webView->mainFrame(); 3397 webViewHelper.initializeAndLoad("about:blank", true);
3398 WebFrame* frame = webViewHelper.webView()->mainFrame();
3412 3399
3413 // This test passes if this doesn't crash. 3400 // This test passes if this doesn't crash.
3414 frame->moveCaretSelectionTowardsWindowPoint(WebPoint(0, 0)); 3401 frame->moveCaretSelectionTowardsWindowPoint(WebPoint(0, 0));
3415 } 3402 }
3416 3403
3417 class SpellCheckClient : public WebSpellCheckClient { 3404 class SpellCheckClient : public WebSpellCheckClient {
3418 public: 3405 public:
3419 explicit SpellCheckClient(uint32_t hash = 0) : m_numberOfTimesChecked(0), m_ hash(hash) { } 3406 explicit SpellCheckClient(uint32_t hash = 0) : m_numberOfTimesChecked(0), m_ hash(hash) { }
3420 virtual ~SpellCheckClient() { } 3407 virtual ~SpellCheckClient() { }
3421 virtual void requestCheckingOfText(const WebKit::WebString&, const WebKit::W ebVector<uint32_t>&, const WebKit::WebVector<unsigned>&, WebKit::WebTextChecking Completion* completion) OVERRIDE 3408 virtual void requestCheckingOfText(const WebKit::WebString&, const WebKit::W ebVector<uint32_t>&, const WebKit::WebVector<unsigned>&, WebKit::WebTextChecking Completion* completion) OVERRIDE
3422 { 3409 {
3423 ++m_numberOfTimesChecked; 3410 ++m_numberOfTimesChecked;
3424 Vector<WebTextCheckingResult> results; 3411 Vector<WebTextCheckingResult> results;
3425 const int misspellingStartOffset = 1; 3412 const int misspellingStartOffset = 1;
3426 const int misspellingLength = 8; 3413 const int misspellingLength = 8;
3427 results.append(WebTextCheckingResult(WebTextCheckingTypeSpelling, misspe llingStartOffset, misspellingLength, WebString(), m_hash)); 3414 results.append(WebTextCheckingResult(WebTextCheckingTypeSpelling, misspe llingStartOffset, misspellingLength, WebString(), m_hash));
3428 completion->didFinishCheckingText(results); 3415 completion->didFinishCheckingText(results);
3429 } 3416 }
3430 int numberOfTimesChecked() const { return m_numberOfTimesChecked; } 3417 int numberOfTimesChecked() const { return m_numberOfTimesChecked; }
3431 private: 3418 private:
3432 int m_numberOfTimesChecked; 3419 int m_numberOfTimesChecked;
3433 uint32_t m_hash; 3420 uint32_t m_hash;
3434 }; 3421 };
3435 3422
3436 TEST_F(WebFrameTest, ReplaceMisspelledRange) 3423 TEST_F(WebFrameTest, ReplaceMisspelledRange)
3437 { 3424 {
3438 registerMockedHttpURLLoad("spell.html"); 3425 registerMockedHttpURLLoad("spell.html");
3439 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "spell.html") ; 3426 FrameTestHelpers::WebViewHelper webViewHelper;
3427 webViewHelper.initializeAndLoad(m_baseURL + "spell.html");
3440 SpellCheckClient spellcheck; 3428 SpellCheckClient spellcheck;
3441 m_webView->setSpellCheckClient(&spellcheck); 3429 webViewHelper.webView()->setSpellCheckClient(&spellcheck);
3442 3430
3443 WebFrameImpl* frame = toWebFrameImpl(m_webView->mainFrame()); 3431 WebFrameImpl* frame = toWebFrameImpl(webViewHelper.webView()->mainFrame());
3444 Document* document = frame->frame()->document(); 3432 Document* document = frame->frame()->document();
3445 Element* element = document->getElementById("data"); 3433 Element* element = document->getElementById("data");
3446 3434
3447 m_webView->settings()->setAsynchronousSpellCheckingEnabled(true); 3435 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e);
3448 m_webView->settings()->setUnifiedTextCheckerEnabled(true); 3436 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
3449 m_webView->settings()->setEditingBehavior(WebSettings::EditingBehaviorWin); 3437 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
3450 3438
3451 element->focus(); 3439 element->focus();
3452 document->execCommand("InsertText", false, "_wellcome_."); 3440 document->execCommand("InsertText", false, "_wellcome_.");
3453 3441
3454 const int allTextBeginOffset = 0; 3442 const int allTextBeginOffset = 0;
3455 const int allTextLength = 11; 3443 const int allTextLength = 11;
3456 frame->selectRange(WebRange::fromDocumentRange(frame, allTextBeginOffset, al lTextLength)); 3444 frame->selectRange(WebRange::fromDocumentRange(frame, allTextBeginOffset, al lTextLength));
3457 RefPtr<Range> selectionRange = frame->frame()->selection().toNormalizedRange (); 3445 RefPtr<Range> selectionRange = frame->frame()->selection().toNormalizedRange ();
3458 3446
3459 EXPECT_EQ(1, spellcheck.numberOfTimesChecked()); 3447 EXPECT_EQ(1, spellcheck.numberOfTimesChecked());
3460 EXPECT_EQ(1U, document->markers()->markersInRange(selectionRange.get(), Docu mentMarker::Spelling).size()); 3448 EXPECT_EQ(1U, document->markers()->markersInRange(selectionRange.get(), Docu mentMarker::Spelling).size());
3461 3449
3462 frame->replaceMisspelledRange("welcome"); 3450 frame->replaceMisspelledRange("welcome");
3463 EXPECT_EQ("_welcome_.", std::string(frame->contentAsText(std::numeric_limits <size_t>::max()).utf8().data())); 3451 EXPECT_EQ("_welcome_.", std::string(frame->contentAsText(std::numeric_limits <size_t>::max()).utf8().data()));
3464
3465 m_webView->close();
3466 m_webView = 0;
3467 } 3452 }
3468 3453
3469 TEST_F(WebFrameTest, RemoveSpellingMarkers) 3454 TEST_F(WebFrameTest, RemoveSpellingMarkers)
3470 { 3455 {
3471 registerMockedHttpURLLoad("spell.html"); 3456 registerMockedHttpURLLoad("spell.html");
3472 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "spell.html") ; 3457 FrameTestHelpers::WebViewHelper webViewHelper;
3458 webViewHelper.initializeAndLoad(m_baseURL + "spell.html");
3473 SpellCheckClient spellcheck; 3459 SpellCheckClient spellcheck;
3474 m_webView->setSpellCheckClient(&spellcheck); 3460 webViewHelper.webView()->setSpellCheckClient(&spellcheck);
3475 3461
3476 WebFrameImpl* frame = toWebFrameImpl(m_webView->mainFrame()); 3462 WebFrameImpl* frame = toWebFrameImpl(webViewHelper.webView()->mainFrame());
3477 Document* document = frame->frame()->document(); 3463 Document* document = frame->frame()->document();
3478 Element* element = document->getElementById("data"); 3464 Element* element = document->getElementById("data");
3479 3465
3480 m_webView->settings()->setAsynchronousSpellCheckingEnabled(true); 3466 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e);
3481 m_webView->settings()->setUnifiedTextCheckerEnabled(true); 3467 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
3482 m_webView->settings()->setEditingBehavior(WebSettings::EditingBehaviorWin); 3468 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
3483 3469
3484 element->focus(); 3470 element->focus();
3485 document->execCommand("InsertText", false, "_wellcome_."); 3471 document->execCommand("InsertText", false, "_wellcome_.");
3486 3472
3487 frame->removeSpellingMarkers(); 3473 frame->removeSpellingMarkers();
3488 3474
3489 const int allTextBeginOffset = 0; 3475 const int allTextBeginOffset = 0;
3490 const int allTextLength = 11; 3476 const int allTextLength = 11;
3491 frame->selectRange(WebRange::fromDocumentRange(frame, allTextBeginOffset, al lTextLength)); 3477 frame->selectRange(WebRange::fromDocumentRange(frame, allTextBeginOffset, al lTextLength));
3492 RefPtr<Range> selectionRange = frame->frame()->selection().toNormalizedRange (); 3478 RefPtr<Range> selectionRange = frame->frame()->selection().toNormalizedRange ();
3493 3479
3494 EXPECT_EQ(0U, document->markers()->markersInRange(selectionRange.get(), Docu mentMarker::Spelling).size()); 3480 EXPECT_EQ(0U, document->markers()->markersInRange(selectionRange.get(), Docu mentMarker::Spelling).size());
3495
3496 m_webView->close();
3497 m_webView = 0;
3498 } 3481 }
3499 3482
3500 TEST_F(WebFrameTest, MarkerHashIdentifiers) { 3483 TEST_F(WebFrameTest, MarkerHashIdentifiers) {
3501 registerMockedHttpURLLoad("spell.html"); 3484 registerMockedHttpURLLoad("spell.html");
3502 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "spell.html") ; 3485 FrameTestHelpers::WebViewHelper webViewHelper;
3486 webViewHelper.initializeAndLoad(m_baseURL + "spell.html");
3503 3487
3504 static const uint32_t kHash = 42; 3488 static const uint32_t kHash = 42;
3505 SpellCheckClient spellcheck(kHash); 3489 SpellCheckClient spellcheck(kHash);
3506 m_webView->setSpellCheckClient(&spellcheck); 3490 webViewHelper.webView()->setSpellCheckClient(&spellcheck);
3507 3491
3508 WebFrameImpl* frame = toWebFrameImpl(m_webView->mainFrame()); 3492 WebFrameImpl* frame = toWebFrameImpl(webViewHelper.webView()->mainFrame());
3509 Document* document = frame->frame()->document(); 3493 Document* document = frame->frame()->document();
3510 Element* element = document->getElementById("data"); 3494 Element* element = document->getElementById("data");
3511 3495
3512 m_webView->settings()->setAsynchronousSpellCheckingEnabled(true); 3496 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e);
3513 m_webView->settings()->setUnifiedTextCheckerEnabled(true); 3497 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
3514 m_webView->settings()->setEditingBehavior(WebSettings::EditingBehaviorWin); 3498 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
3515 3499
3516 element->focus(); 3500 element->focus();
3517 document->execCommand("InsertText", false, "wellcome."); 3501 document->execCommand("InsertText", false, "wellcome.");
3518 3502
3519 WebVector<uint32_t> documentMarkers; 3503 WebVector<uint32_t> documentMarkers;
3520 m_webView->spellingMarkers(&documentMarkers); 3504 webViewHelper.webView()->spellingMarkers(&documentMarkers);
3521 EXPECT_EQ(1U, documentMarkers.size()); 3505 EXPECT_EQ(1U, documentMarkers.size());
3522 EXPECT_EQ(kHash, documentMarkers[0]); 3506 EXPECT_EQ(kHash, documentMarkers[0]);
3523
3524 m_webView->close();
3525 m_webView = 0;
3526 } 3507 }
3527 3508
3528 class StubbornSpellCheckClient : public WebSpellCheckClient { 3509 class StubbornSpellCheckClient : public WebSpellCheckClient {
3529 public: 3510 public:
3530 StubbornSpellCheckClient() : m_completion(0) { } 3511 StubbornSpellCheckClient() : m_completion(0) { }
3531 virtual ~StubbornSpellCheckClient() { } 3512 virtual ~StubbornSpellCheckClient() { }
3532 3513
3533 virtual void requestCheckingOfText( 3514 virtual void requestCheckingOfText(
3534 const WebKit::WebString&, 3515 const WebKit::WebString&,
3535 const WebKit::WebVector<uint32_t>&, 3516 const WebKit::WebVector<uint32_t>&,
(...skipping 15 matching lines...) Expand all
3551 m_completion = 0; 3532 m_completion = 0;
3552 } 3533 }
3553 3534
3554 private: 3535 private:
3555 WebKit::WebTextCheckingCompletion* m_completion; 3536 WebKit::WebTextCheckingCompletion* m_completion;
3556 }; 3537 };
3557 3538
3558 TEST_F(WebFrameTest, SlowSpellcheckMarkerPosition) 3539 TEST_F(WebFrameTest, SlowSpellcheckMarkerPosition)
3559 { 3540 {
3560 registerMockedHttpURLLoad("spell.html"); 3541 registerMockedHttpURLLoad("spell.html");
3561 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "spell.html") ; 3542 FrameTestHelpers::WebViewHelper webViewHelper;
3543 webViewHelper.initializeAndLoad(m_baseURL + "spell.html");
3562 3544
3563 StubbornSpellCheckClient spellcheck; 3545 StubbornSpellCheckClient spellcheck;
3564 m_webView->setSpellCheckClient(&spellcheck); 3546 webViewHelper.webView()->setSpellCheckClient(&spellcheck);
3565 3547
3566 WebFrameImpl* frame = toWebFrameImpl(m_webView->mainFrame()); 3548 WebFrameImpl* frame = toWebFrameImpl(webViewHelper.webView()->mainFrame());
3567 WebInputElement webInputElement = frame->document().getElementById("data").t o<WebInputElement>(); 3549 WebInputElement webInputElement = frame->document().getElementById("data").t o<WebInputElement>();
3568 Document* document = frame->frame()->document(); 3550 Document* document = frame->frame()->document();
3569 Element* element = document->getElementById("data"); 3551 Element* element = document->getElementById("data");
3570 3552
3571 m_webView->settings()->setAsynchronousSpellCheckingEnabled(true); 3553 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e);
3572 m_webView->settings()->setUnifiedTextCheckerEnabled(true); 3554 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
3573 m_webView->settings()->setEditingBehavior(WebSettings::EditingBehaviorWin); 3555 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
3574 3556
3575 element->focus(); 3557 element->focus();
3576 document->execCommand("InsertText", false, "wellcome "); 3558 document->execCommand("InsertText", false, "wellcome ");
3577 webInputElement.setSelectionRange(0, 0); 3559 webInputElement.setSelectionRange(0, 0);
3578 document->execCommand("InsertText", false, "he"); 3560 document->execCommand("InsertText", false, "he");
3579 3561
3580 spellcheck.kick(); 3562 spellcheck.kick();
3581 3563
3582 WebVector<uint32_t> documentMarkers; 3564 WebVector<uint32_t> documentMarkers;
3583 m_webView->spellingMarkers(&documentMarkers); 3565 webViewHelper.webView()->spellingMarkers(&documentMarkers);
3584 EXPECT_EQ(0U, documentMarkers.size()); 3566 EXPECT_EQ(0U, documentMarkers.size());
3585
3586 m_webView->close();
3587 m_webView = 0;
3588 } 3567 }
3589 3568
3590 // This test verifies that cancelling spelling request does not cause a 3569 // This test verifies that cancelling spelling request does not cause a
3591 // write-after-free when there's no spellcheck client set. 3570 // write-after-free when there's no spellcheck client set.
3592 TEST_F(WebFrameTest, CancelSpellingRequestCrash) 3571 TEST_F(WebFrameTest, CancelSpellingRequestCrash)
3593 { 3572 {
3594 registerMockedHttpURLLoad("spell.html"); 3573 registerMockedHttpURLLoad("spell.html");
3595 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "spell.html") ; 3574 FrameTestHelpers::WebViewHelper webViewHelper;
3596 m_webView->setSpellCheckClient(0); 3575 webViewHelper.initializeAndLoad(m_baseURL + "spell.html");
3576 webViewHelper.webView()->setSpellCheckClient(0);
3597 3577
3598 WebFrameImpl* frame = toWebFrameImpl(m_webView->mainFrame()); 3578 WebFrameImpl* frame = toWebFrameImpl(webViewHelper.webView()->mainFrame());
3599 Document* document = frame->frame()->document(); 3579 Document* document = frame->frame()->document();
3600 Element* element = document->getElementById("data"); 3580 Element* element = document->getElementById("data");
3601 3581
3602 m_webView->settings()->setAsynchronousSpellCheckingEnabled(true); 3582 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru e);
3603 m_webView->settings()->setUnifiedTextCheckerEnabled(true); 3583 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true);
3604 m_webView->settings()->setEditingBehavior(WebSettings::EditingBehaviorWin); 3584 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing BehaviorWin);
3605 3585
3606 element->focus(); 3586 element->focus();
3607 frame->frame()->editor().replaceSelectionWithText("A", false, false); 3587 frame->frame()->editor().replaceSelectionWithText("A", false, false);
3608 frame->frame()->editor().spellCheckRequester().cancelCheck(); 3588 frame->frame()->editor().spellCheckRequester().cancelCheck();
3609
3610 m_webView->close();
3611 m_webView = 0;
3612 } 3589 }
3613 3590
3614 class TestAccessInitialDocumentWebFrameClient : public WebFrameClient { 3591 class TestAccessInitialDocumentWebFrameClient : public WebFrameClient {
3615 public: 3592 public:
3616 TestAccessInitialDocumentWebFrameClient() : m_didAccessInitialDocument(false ) 3593 TestAccessInitialDocumentWebFrameClient() : m_didAccessInitialDocument(false )
3617 { 3594 {
3618 } 3595 }
3619 3596
3620 virtual void didAccessInitialDocument(WebFrame* frame) 3597 virtual void didAccessInitialDocument(WebFrame* frame)
3621 { 3598 {
3622 EXPECT_TRUE(!m_didAccessInitialDocument); 3599 EXPECT_TRUE(!m_didAccessInitialDocument);
3623 m_didAccessInitialDocument = true; 3600 m_didAccessInitialDocument = true;
3624 } 3601 }
3625 3602
3626 bool m_didAccessInitialDocument; 3603 bool m_didAccessInitialDocument;
3627 }; 3604 };
3628 3605
3629 TEST_F(WebFrameTest, DidAccessInitialDocumentBody) 3606 TEST_F(WebFrameTest, DidAccessInitialDocumentBody)
3630 { 3607 {
3631 TestAccessInitialDocumentWebFrameClient webFrameClient; 3608 TestAccessInitialDocumentWebFrameClient webFrameClient;
3632 m_webView = FrameTestHelpers::createWebView(true, &webFrameClient); 3609 FrameTestHelpers::WebViewHelper webViewHelper;
3610 webViewHelper.initialize(true, &webFrameClient);
3633 runPendingTasks(); 3611 runPendingTasks();
3634 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); 3612 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument);
3635 3613
3636 // Create another window that will try to access it. 3614 // Create another window that will try to access it.
3637 WebView* newView = FrameTestHelpers::createWebView(true); 3615 FrameTestHelpers::WebViewHelper newWebViewHelper;
3638 newView->mainFrame()->setOpener(m_webView->mainFrame()); 3616 WebView* newView = newWebViewHelper.initialize(true);
3617 newView->mainFrame()->setOpener(webViewHelper.webView()->mainFrame());
3639 runPendingTasks(); 3618 runPendingTasks();
3640 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); 3619 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument);
3641 3620
3642 // Access the initial document by modifying the body. 3621 // Access the initial document by modifying the body.
3643 newView->mainFrame()->executeScript( 3622 newView->mainFrame()->executeScript(
3644 WebScriptSource("window.opener.document.body.innerHTML += 'Modified';")) ; 3623 WebScriptSource("window.opener.document.body.innerHTML += 'Modified';")) ;
3645 runPendingTasks(); 3624 runPendingTasks();
3646 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); 3625 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument);
3647 3626
3648 // Access the initial document again, to ensure we don't notify twice. 3627 // Access the initial document again, to ensure we don't notify twice.
3649 newView->mainFrame()->executeScript( 3628 newView->mainFrame()->executeScript(
3650 WebScriptSource("window.opener.document.body.innerHTML += 'Modified';")) ; 3629 WebScriptSource("window.opener.document.body.innerHTML += 'Modified';")) ;
3651 runPendingTasks(); 3630 runPendingTasks();
3652 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); 3631 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument);
3653
3654 newView->close();
3655 m_webView->close();
3656 m_webView = 0;
3657 } 3632 }
3658 3633
3659 TEST_F(WebFrameTest, DidAccessInitialDocumentNavigator) 3634 TEST_F(WebFrameTest, DidAccessInitialDocumentNavigator)
3660 { 3635 {
3661 TestAccessInitialDocumentWebFrameClient webFrameClient; 3636 TestAccessInitialDocumentWebFrameClient webFrameClient;
3662 m_webView = FrameTestHelpers::createWebView(true, &webFrameClient); 3637 FrameTestHelpers::WebViewHelper webViewHelper;
3638 webViewHelper.initialize(true, &webFrameClient);
3663 runPendingTasks(); 3639 runPendingTasks();
3664 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); 3640 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument);
3665 3641
3666 // Create another window that will try to access it. 3642 // Create another window that will try to access it.
3667 WebView* newView = FrameTestHelpers::createWebView(true); 3643 FrameTestHelpers::WebViewHelper newWebViewHelper;
3668 newView->mainFrame()->setOpener(m_webView->mainFrame()); 3644 WebView* newView = newWebViewHelper.initialize(true);
3645 newView->mainFrame()->setOpener(webViewHelper.webView()->mainFrame());
3669 runPendingTasks(); 3646 runPendingTasks();
3670 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); 3647 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument);
3671 3648
3672 // Access the initial document to get to the navigator object. 3649 // Access the initial document to get to the navigator object.
3673 newView->mainFrame()->executeScript( 3650 newView->mainFrame()->executeScript(
3674 WebScriptSource("console.log(window.opener.navigator);")); 3651 WebScriptSource("console.log(window.opener.navigator);"));
3675 runPendingTasks(); 3652 runPendingTasks();
3676 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); 3653 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument);
3677
3678 newView->close();
3679 m_webView->close();
3680 m_webView = 0;
3681 } 3654 }
3682 3655
3683 TEST_F(WebFrameTest, DidAccessInitialDocumentViaJavascriptUrl) 3656 TEST_F(WebFrameTest, DidAccessInitialDocumentViaJavascriptUrl)
3684 { 3657 {
3685 TestAccessInitialDocumentWebFrameClient webFrameClient; 3658 TestAccessInitialDocumentWebFrameClient webFrameClient;
3686 m_webView = FrameTestHelpers::createWebView(true, &webFrameClient); 3659 FrameTestHelpers::WebViewHelper webViewHelper;
3660 webViewHelper.initialize(true, &webFrameClient);
3687 runPendingTasks(); 3661 runPendingTasks();
3688 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); 3662 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument);
3689 3663
3690 // Access the initial document from a javascript: URL. 3664 // Access the initial document from a javascript: URL.
3691 FrameTestHelpers::loadFrame(m_webView->mainFrame(), "javascript:document.bod y.appendChild(document.createTextNode('Modified'))"); 3665 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip t:document.body.appendChild(document.createTextNode('Modified'))");
3692 runPendingTasks(); 3666 runPendingTasks();
3693 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); 3667 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument);
3694
3695 m_webView->close();
3696 m_webView = 0;
3697 } 3668 }
3698 3669
3699 TEST_F(WebFrameTest, DidAccessInitialDocumentBodyBeforeModalDialog) 3670 TEST_F(WebFrameTest, DidAccessInitialDocumentBodyBeforeModalDialog)
3700 { 3671 {
3701 TestAccessInitialDocumentWebFrameClient webFrameClient; 3672 TestAccessInitialDocumentWebFrameClient webFrameClient;
3702 m_webView = FrameTestHelpers::createWebView(true, &webFrameClient); 3673 FrameTestHelpers::WebViewHelper webViewHelper;
3674 webViewHelper.initialize(true, &webFrameClient);
3703 runPendingTasks(); 3675 runPendingTasks();
3704 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); 3676 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument);
3705 3677
3706 // Create another window that will try to access it. 3678 // Create another window that will try to access it.
3707 WebView* newView = FrameTestHelpers::createWebView(true); 3679 FrameTestHelpers::WebViewHelper newWebViewHelper;
3708 newView->mainFrame()->setOpener(m_webView->mainFrame()); 3680 WebView* newView = newWebViewHelper.initialize(true);
3681 newView->mainFrame()->setOpener(webViewHelper.webView()->mainFrame());
3709 runPendingTasks(); 3682 runPendingTasks();
3710 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); 3683 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument);
3711 3684
3712 // Access the initial document by modifying the body. We normally set a 3685 // Access the initial document by modifying the body. We normally set a
3713 // timer to notify the client. 3686 // timer to notify the client.
3714 newView->mainFrame()->executeScript( 3687 newView->mainFrame()->executeScript(
3715 WebScriptSource("window.opener.document.body.innerHTML += 'Modified';")) ; 3688 WebScriptSource("window.opener.document.body.innerHTML += 'Modified';")) ;
3716 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); 3689 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument);
3717 3690
3718 // Make sure that a modal dialog forces us to notify right away. 3691 // Make sure that a modal dialog forces us to notify right away.
3719 newView->mainFrame()->executeScript( 3692 newView->mainFrame()->executeScript(
3720 WebScriptSource("window.opener.confirm('Modal');")); 3693 WebScriptSource("window.opener.confirm('Modal');"));
3721 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); 3694 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument);
3722 3695
3723 // Ensure that we don't notify again later. 3696 // Ensure that we don't notify again later.
3724 runPendingTasks(); 3697 runPendingTasks();
3725 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); 3698 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument);
3726
3727 newView->close();
3728 m_webView->close();
3729 m_webView = 0;
3730 } 3699 }
3731 3700
3732 class TestMainFrameUserOrProgrammaticScrollFrameClient : public WebFrameClient { 3701 class TestMainFrameUserOrProgrammaticScrollFrameClient : public WebFrameClient {
3733 public: 3702 public:
3734 TestMainFrameUserOrProgrammaticScrollFrameClient() { reset(); } 3703 TestMainFrameUserOrProgrammaticScrollFrameClient() { reset(); }
3735 void reset() 3704 void reset()
3736 { 3705 {
3737 m_didScrollMainFrame = false; 3706 m_didScrollMainFrame = false;
3738 m_wasProgrammaticScroll = false; 3707 m_wasProgrammaticScroll = false;
3739 } 3708 }
(...skipping 20 matching lines...) Expand all
3760 bool m_wasProgrammaticScroll; 3729 bool m_wasProgrammaticScroll;
3761 }; 3730 };
3762 3731
3763 TEST_F(WebFrameTest, CompositorScrollIsUserScrollLongPage) 3732 TEST_F(WebFrameTest, CompositorScrollIsUserScrollLongPage)
3764 { 3733 {
3765 registerMockedHttpURLLoad("long_scroll.html"); 3734 registerMockedHttpURLLoad("long_scroll.html");
3766 TestMainFrameUserOrProgrammaticScrollFrameClient client; 3735 TestMainFrameUserOrProgrammaticScrollFrameClient client;
3767 3736
3768 // Make sure we initialize to minimum scale, even if the window size 3737 // Make sure we initialize to minimum scale, even if the window size
3769 // only becomes available after the load begins. 3738 // only becomes available after the load begins.
3770 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "long_scroll. html", true, &client); 3739 FrameTestHelpers::WebViewHelper webViewHelper;
3771 m_webView->resize(WebSize(1000, 1000)); 3740 webViewHelper.initializeAndLoad(m_baseURL + "long_scroll.html", true, &clien t);
3772 m_webView->layout(); 3741 webViewHelper.webView()->resize(WebSize(1000, 1000));
3742 webViewHelper.webView()->layout();
3773 3743
3774 EXPECT_FALSE(client.wasUserScroll()); 3744 EXPECT_FALSE(client.wasUserScroll());
3775 EXPECT_FALSE(client.wasProgrammaticScroll()); 3745 EXPECT_FALSE(client.wasProgrammaticScroll());
3776 3746
3777 // Do a compositor scroll, verify that this is counted as a user scroll. 3747 // Do a compositor scroll, verify that this is counted as a user scroll.
3778 webViewImpl()->applyScrollAndScale(WebSize(0, 1), 1.1f); 3748 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(0, 1), 1.1f);
3779 EXPECT_TRUE(client.wasUserScroll()); 3749 EXPECT_TRUE(client.wasUserScroll());
3780 client.reset(); 3750 client.reset();
3781 3751
3782 EXPECT_FALSE(client.wasUserScroll()); 3752 EXPECT_FALSE(client.wasUserScroll());
3783 EXPECT_FALSE(client.wasProgrammaticScroll()); 3753 EXPECT_FALSE(client.wasProgrammaticScroll());
3784 3754
3785 // The page scale 1.0f and scroll. 3755 // The page scale 1.0f and scroll.
3786 webViewImpl()->applyScrollAndScale(WebSize(0, 1), 1.0f); 3756 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(0, 1), 1.0f);
3787 EXPECT_TRUE(client.wasUserScroll()); 3757 EXPECT_TRUE(client.wasUserScroll());
3788 client.reset(); 3758 client.reset();
3789 3759
3790 // No scroll event if there is no scroll delta. 3760 // No scroll event if there is no scroll delta.
3791 webViewImpl()->applyScrollAndScale(WebSize(), 1.0f); 3761 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(), 1.0f);
3792 EXPECT_FALSE(client.wasUserScroll()); 3762 EXPECT_FALSE(client.wasUserScroll());
3793 EXPECT_FALSE(client.wasProgrammaticScroll()); 3763 EXPECT_FALSE(client.wasProgrammaticScroll());
3794 client.reset(); 3764 client.reset();
3795 3765
3796 // Non zero page scale and scroll. 3766 // Non zero page scale and scroll.
3797 webViewImpl()->applyScrollAndScale(WebSize(9, 13), 0.6f); 3767 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(9, 13), 0.6f);
3798 EXPECT_TRUE(client.wasUserScroll()); 3768 EXPECT_TRUE(client.wasUserScroll());
3799 client.reset(); 3769 client.reset();
3800 3770
3801 // Programmatic scroll. 3771 // Programmatic scroll.
3802 WebFrameImpl* frameImpl = webViewImpl()->mainFrameImpl(); 3772 WebFrameImpl* frameImpl = webViewHelper.webViewImpl()->mainFrameImpl();
3803 frameImpl->executeScript(WebScriptSource("window.scrollTo(0, 20);")); 3773 frameImpl->executeScript(WebScriptSource("window.scrollTo(0, 20);"));
3804 EXPECT_FALSE(client.wasUserScroll()); 3774 EXPECT_FALSE(client.wasUserScroll());
3805 EXPECT_TRUE(client.wasProgrammaticScroll()); 3775 EXPECT_TRUE(client.wasProgrammaticScroll());
3806 client.reset(); 3776 client.reset();
3807 3777
3808 // Programmatic scroll to same offset. No scroll event should be generated. 3778 // Programmatic scroll to same offset. No scroll event should be generated.
3809 frameImpl->executeScript(WebScriptSource("window.scrollTo(0, 20);")); 3779 frameImpl->executeScript(WebScriptSource("window.scrollTo(0, 20);"));
3810 EXPECT_FALSE(client.wasProgrammaticScroll()); 3780 EXPECT_FALSE(client.wasProgrammaticScroll());
3811 EXPECT_FALSE(client.wasUserScroll()); 3781 EXPECT_FALSE(client.wasUserScroll());
3812 client.reset(); 3782 client.reset();
3813
3814 m_webView->close();
3815 m_webView = 0;
3816 } 3783 }
3817 3784
3818 TEST_F(WebFrameTest, CompositorScrollIsUserScrollShortPage) 3785 TEST_F(WebFrameTest, CompositorScrollIsUserScrollShortPage)
3819 { 3786 {
3820 registerMockedHttpURLLoad("short_scroll.html"); 3787 registerMockedHttpURLLoad("short_scroll.html");
3821 3788
3822 TestMainFrameUserOrProgrammaticScrollFrameClient client; 3789 TestMainFrameUserOrProgrammaticScrollFrameClient client;
3823 3790
3824 // Short page tests. 3791 // Short page tests.
3825 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "short_scroll .html", true, &client); 3792 FrameTestHelpers::WebViewHelper webViewHelper;
3793 webViewHelper.initializeAndLoad(m_baseURL + "short_scroll.html", true, &clie nt);
3826 3794
3827 m_webView->resize(WebSize(1000, 1000)); 3795 webViewHelper.webView()->resize(WebSize(1000, 1000));
3828 m_webView->layout(); 3796 webViewHelper.webView()->layout();
3829 3797
3830 EXPECT_FALSE(client.wasUserScroll()); 3798 EXPECT_FALSE(client.wasUserScroll());
3831 EXPECT_FALSE(client.wasProgrammaticScroll()); 3799 EXPECT_FALSE(client.wasProgrammaticScroll());
3832 3800
3833 // Non zero page scale and scroll. 3801 // Non zero page scale and scroll.
3834 webViewImpl()->applyScrollAndScale(WebSize(9, 13), 2.0f); 3802 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(9, 13), 2.0f);
3835 EXPECT_FALSE(client.wasProgrammaticScroll()); 3803 EXPECT_FALSE(client.wasProgrammaticScroll());
3836 EXPECT_TRUE(client.wasUserScroll()); 3804 EXPECT_TRUE(client.wasUserScroll());
3837 client.reset(); 3805 client.reset();
3838
3839 m_webView->close();
3840 m_webView = 0;
3841 } 3806 }
3842 3807
3843 TEST_F(WebFrameTest, FirstPartyForCookiesForRedirect) 3808 TEST_F(WebFrameTest, FirstPartyForCookiesForRedirect)
3844 { 3809 {
3845 WTF::String filePath = Platform::current()->unitTestSupport()->webKitRootDir (); 3810 WTF::String filePath = Platform::current()->unitTestSupport()->webKitRootDir ();
3846 filePath.append("/Source/web/tests/data/first_party.html"); 3811 filePath.append("/Source/web/tests/data/first_party.html");
3847 3812
3848 WebURL testURL(toKURL("http://www.test.com/first_party_redirect.html")); 3813 WebURL testURL(toKURL("http://www.test.com/first_party_redirect.html"));
3849 char redirect[] = "http://www.test.com/first_party.html"; 3814 char redirect[] = "http://www.test.com/first_party.html";
3850 WebURL redirectURL(toKURL(redirect)); 3815 WebURL redirectURL(toKURL(redirect));
3851 WebURLResponse redirectResponse; 3816 WebURLResponse redirectResponse;
3852 redirectResponse.initialize(); 3817 redirectResponse.initialize();
3853 redirectResponse.setMIMEType("text/html"); 3818 redirectResponse.setMIMEType("text/html");
3854 redirectResponse.setHTTPStatusCode(302); 3819 redirectResponse.setHTTPStatusCode(302);
3855 redirectResponse.setHTTPHeaderField("Location", redirect); 3820 redirectResponse.setHTTPHeaderField("Location", redirect);
3856 Platform::current()->unitTestSupport()->registerMockedURL(testURL, redirectR esponse, filePath); 3821 Platform::current()->unitTestSupport()->registerMockedURL(testURL, redirectR esponse, filePath);
3857 3822
3858 WebURLResponse finalResponse; 3823 WebURLResponse finalResponse;
3859 finalResponse.initialize(); 3824 finalResponse.initialize();
3860 finalResponse.setMIMEType("text/html"); 3825 finalResponse.setMIMEType("text/html");
3861 Platform::current()->unitTestSupport()->registerMockedURL(redirectURL, final Response, filePath); 3826 Platform::current()->unitTestSupport()->registerMockedURL(redirectURL, final Response, filePath);
3862 3827
3863 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "first_party_ redirect.html", true); 3828 FrameTestHelpers::WebViewHelper webViewHelper;
3864 EXPECT_TRUE(m_webView->mainFrame()->document().firstPartyForCookies() == red irectURL); 3829 webViewHelper.initializeAndLoad(m_baseURL + "first_party_redirect.html", tru e);
3865 3830 EXPECT_TRUE(webViewHelper.webView()->mainFrame()->document().firstPartyForCo okies() == redirectURL);
3866 m_webView->close();
3867 m_webView = 0;
3868 } 3831 }
3869 3832
3870 class TestNavigationPolicyWebFrameClient : public WebFrameClient { 3833 class TestNavigationPolicyWebFrameClient : public WebFrameClient {
3871 public: 3834 public:
3872 3835
3873 virtual void didNavigateWithinPage(WebFrame*, bool) 3836 virtual void didNavigateWithinPage(WebFrame*, bool)
3874 { 3837 {
3875 EXPECT_TRUE(false); 3838 EXPECT_TRUE(false);
3876 } 3839 }
3877 }; 3840 };
3878 3841
3879 TEST_F(WebFrameTest, SimulateFragmentAnchorMiddleClick) 3842 TEST_F(WebFrameTest, SimulateFragmentAnchorMiddleClick)
3880 { 3843 {
3881 registerMockedHttpURLLoad("fragment_middle_click.html"); 3844 registerMockedHttpURLLoad("fragment_middle_click.html");
3882 TestNavigationPolicyWebFrameClient client; 3845 TestNavigationPolicyWebFrameClient client;
3883 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fragment_mid dle_click.html", true, &client); 3846 FrameTestHelpers::WebViewHelper webViewHelper;
3847 webViewHelper.initializeAndLoad(m_baseURL + "fragment_middle_click.html", tr ue, &client);
3884 3848
3885 WebCore::Document* document = webViewImpl()->page()->mainFrame()->document() ; 3849 WebCore::Document* document = webViewHelper.webViewImpl()->page()->mainFrame ()->document();
3886 WebCore::KURL destination = document->url(); 3850 WebCore::KURL destination = document->url();
3887 destination.setFragmentIdentifier("test"); 3851 destination.setFragmentIdentifier("test");
3888 3852
3889 RefPtr<WebCore::Event> event = WebCore::MouseEvent::create(WebCore::eventNam es().clickEvent, false, false, 3853 RefPtr<WebCore::Event> event = WebCore::MouseEvent::create(WebCore::eventNam es().clickEvent, false, false,
3890 document->defaultView(), 0, 0, 0, 0, 0, 0, 0, false, false, false, false , 1, 0, 0); 3854 document->defaultView(), 0, 0, 0, 0, 0, 0, 0, false, false, false, false , 1, 0, 0);
3891 WebCore::FrameLoadRequest frameRequest(document->securityOrigin(), WebCore:: ResourceRequest(destination)); 3855 WebCore::FrameLoadRequest frameRequest(document->securityOrigin(), WebCore:: ResourceRequest(destination));
3892 frameRequest.setTriggeringEvent(event); 3856 frameRequest.setTriggeringEvent(event);
3893 webViewImpl()->page()->mainFrame()->loader()->load(frameRequest); 3857 webViewHelper.webViewImpl()->page()->mainFrame()->loader()->load(frameReques t);
3894
3895 m_webView->close();
3896 m_webView = 0;
3897 } 3858 }
3898 3859
3899 TEST_F(WebFrameTest, BackToReload) 3860 TEST_F(WebFrameTest, BackToReload)
3900 { 3861 {
3901 registerMockedHttpURLLoad("fragment_middle_click.html"); 3862 registerMockedHttpURLLoad("fragment_middle_click.html");
3902 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fragment_mid dle_click.html", true); 3863 FrameTestHelpers::WebViewHelper webViewHelper;
3903 WebFrame* frame = m_webView->mainFrame(); 3864 webViewHelper.initializeAndLoad(m_baseURL + "fragment_middle_click.html", tr ue);
3865 WebFrame* frame = webViewHelper.webView()->mainFrame();
3904 WebHistoryItem firstItem = frame->currentHistoryItem(); 3866 WebHistoryItem firstItem = frame->currentHistoryItem();
3905 EXPECT_FALSE(firstItem.isNull()); 3867 EXPECT_FALSE(firstItem.isNull());
3906 3868
3907 registerMockedHttpURLLoad("white-1x1.png"); 3869 registerMockedHttpURLLoad("white-1x1.png");
3908 FrameTestHelpers::loadFrame(frame, m_baseURL + "white-1x1.png"); 3870 FrameTestHelpers::loadFrame(frame, m_baseURL + "white-1x1.png");
3909 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 3871 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
3910 EXPECT_FALSE(frame->previousHistoryItem().isNull()); 3872 EXPECT_FALSE(frame->previousHistoryItem().isNull());
3911 EXPECT_EQ(firstItem.urlString(), frame->previousHistoryItem().urlString()); 3873 EXPECT_EQ(firstItem.urlString(), frame->previousHistoryItem().urlString());
3912 3874
3913 frame->loadHistoryItem(frame->previousHistoryItem()); 3875 frame->loadHistoryItem(frame->previousHistoryItem());
3914 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 3876 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
3915 EXPECT_EQ(firstItem.urlString(), frame->currentHistoryItem().urlString()); 3877 EXPECT_EQ(firstItem.urlString(), frame->currentHistoryItem().urlString());
3916 3878
3917 frame->reload(); 3879 frame->reload();
3918 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 3880 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
3919 EXPECT_EQ(WebURLRequest::ReloadIgnoringCacheData, frame->dataSource()->reque st().cachePolicy()); 3881 EXPECT_EQ(WebURLRequest::ReloadIgnoringCacheData, frame->dataSource()->reque st().cachePolicy());
3920
3921 m_webView->close();
3922 m_webView = 0;
3923 } 3882 }
3924 3883
3925 TEST_F(WebFrameTest, ReloadPost) 3884 TEST_F(WebFrameTest, ReloadPost)
3926 { 3885 {
3927 registerMockedHttpURLLoad("reload_post.html"); 3886 registerMockedHttpURLLoad("reload_post.html");
3928 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "reload_post. html", true); 3887 FrameTestHelpers::WebViewHelper webViewHelper;
3929 WebFrame* frame = m_webView->mainFrame(); 3888 webViewHelper.initializeAndLoad(m_baseURL + "reload_post.html", true);
3889 WebFrame* frame = webViewHelper.webView()->mainFrame();
3930 3890
3931 FrameTestHelpers::loadFrame(m_webView->mainFrame(), "javascript:document.for ms[0].submit()"); 3891 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip t:document.forms[0].submit()");
3932 runPendingTasks(); 3892 runPendingTasks();
3933 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 3893 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
3934 EXPECT_FALSE(frame->previousHistoryItem().isNull()); 3894 EXPECT_FALSE(frame->previousHistoryItem().isNull());
3935 EXPECT_EQ(WebString::fromUTF8("POST"), frame->dataSource()->request().httpMe thod()); 3895 EXPECT_EQ(WebString::fromUTF8("POST"), frame->dataSource()->request().httpMe thod());
3936 3896
3937 frame->reload(); 3897 frame->reload();
3938 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 3898 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
3939 EXPECT_EQ(WebURLRequest::ReloadIgnoringCacheData, frame->dataSource()->reque st().cachePolicy()); 3899 EXPECT_EQ(WebURLRequest::ReloadIgnoringCacheData, frame->dataSource()->reque st().cachePolicy());
3940 EXPECT_EQ(WebNavigationTypeFormResubmitted, frame->dataSource()->navigationT ype()); 3900 EXPECT_EQ(WebNavigationTypeFormResubmitted, frame->dataSource()->navigationT ype());
3941
3942 m_webView->close();
3943 m_webView = 0;
3944 } 3901 }
3945 3902
3946 class TestSameDocumentWebFrameClient : public WebFrameClient { 3903 class TestSameDocumentWebFrameClient : public WebFrameClient {
3947 public: 3904 public:
3948 TestSameDocumentWebFrameClient() 3905 TestSameDocumentWebFrameClient()
3949 : m_frameLoadTypeSameSeen(false) 3906 : m_frameLoadTypeSameSeen(false)
3950 { 3907 {
3951 } 3908 }
3952 3909
3953 virtual void willSendRequest(WebFrame* frame, unsigned, WebURLRequest&, cons t WebURLResponse&) 3910 virtual void willSendRequest(WebFrame* frame, unsigned, WebURLRequest&, cons t WebURLResponse&)
3954 { 3911 {
3955 if (toWebFrameImpl(frame)->frame()->loader()->loadType() == WebCore::Fra meLoadTypeSame) 3912 if (toWebFrameImpl(frame)->frame()->loader()->loadType() == WebCore::Fra meLoadTypeSame)
3956 m_frameLoadTypeSameSeen = true; 3913 m_frameLoadTypeSameSeen = true;
3957 } 3914 }
3958 3915
3959 bool frameLoadTypeSameSeen() const { return m_frameLoadTypeSameSeen; } 3916 bool frameLoadTypeSameSeen() const { return m_frameLoadTypeSameSeen; }
3960 3917
3961 private: 3918 private:
3962 bool m_frameLoadTypeSameSeen; 3919 bool m_frameLoadTypeSameSeen;
3963 }; 3920 };
3964 3921
3965 TEST_F(WebFrameTest, NavigateToSame) 3922 TEST_F(WebFrameTest, NavigateToSame)
3966 { 3923 {
3967 registerMockedHttpURLLoad("navigate_to_same.html"); 3924 registerMockedHttpURLLoad("navigate_to_same.html");
3968 TestSameDocumentWebFrameClient client; 3925 TestSameDocumentWebFrameClient client;
3969 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "navigate_to_ same.html", true, &client); 3926 FrameTestHelpers::WebViewHelper webViewHelper;
3927 webViewHelper.initializeAndLoad(m_baseURL + "navigate_to_same.html", true, & client);
3970 EXPECT_FALSE(client.frameLoadTypeSameSeen()); 3928 EXPECT_FALSE(client.frameLoadTypeSameSeen());
3971 3929
3972 WebCore::FrameLoadRequest frameRequest(0, WebCore::ResourceRequest(webViewIm pl()->page()->mainFrame()->document()->url())); 3930 WebCore::FrameLoadRequest frameRequest(0, WebCore::ResourceRequest(webViewHe lper.webViewImpl()->page()->mainFrame()->document()->url()));
3973 webViewImpl()->page()->mainFrame()->loader()->load(frameRequest); 3931 webViewHelper.webViewImpl()->page()->mainFrame()->loader()->load(frameReques t);
3974 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 3932 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
3975 3933
3976 EXPECT_TRUE(client.frameLoadTypeSameSeen()); 3934 EXPECT_TRUE(client.frameLoadTypeSameSeen());
3977 m_webView->close();
3978 m_webView = 0;
3979 } 3935 }
3980 3936
3981 TEST_F(WebFrameTest, WebNodeImageContents) 3937 TEST_F(WebFrameTest, WebNodeImageContents)
3982 { 3938 {
3983 m_webView = FrameTestHelpers::createWebViewAndLoad("about:blank", true); 3939 FrameTestHelpers::WebViewHelper webViewHelper;
3984 WebFrame* frame = m_webView->mainFrame(); 3940 webViewHelper.initializeAndLoad("about:blank", true);
3941 WebFrame* frame = webViewHelper.webView()->mainFrame();
3985 3942
3986 static const char bluePNG[] = "<img src=\"data:image/png;base64,iVBORw0KGgoA AAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYV2NkYPj/n4EIwDiqEF8oUT94AFIQE/cCn90I AAAAAElFTkSuQmCC\">"; 3943 static const char bluePNG[] = "<img src=\"data:image/png;base64,iVBORw0KGgoA AAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYV2NkYPj/n4EIwDiqEF8oUT94AFIQE/cCn90I AAAAAElFTkSuQmCC\">";
3987 3944
3988 // Load up the image and test that we can extract the contents. 3945 // Load up the image and test that we can extract the contents.
3989 WebCore::KURL testURL = toKURL("about:blank"); 3946 WebCore::KURL testURL = toKURL("about:blank");
3990 frame->loadHTMLString(bluePNG, testURL); 3947 frame->loadHTMLString(bluePNG, testURL);
3991 runPendingTasks(); 3948 runPendingTasks();
3992 3949
3993 WebNode node = frame->document().body().firstChild(); 3950 WebNode node = frame->document().body().firstChild();
3994 EXPECT_TRUE(node.isElementNode()); 3951 EXPECT_TRUE(node.isElementNode());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
4027 3984
4028 private: 3985 private:
4029 int m_startLoadingCount; 3986 int m_startLoadingCount;
4030 int m_stopLoadingCount; 3987 int m_stopLoadingCount;
4031 }; 3988 };
4032 3989
4033 TEST_F(WebFrameTest, PushStateStartsAndStops) 3990 TEST_F(WebFrameTest, PushStateStartsAndStops)
4034 { 3991 {
4035 registerMockedHttpURLLoad("push_state.html"); 3992 registerMockedHttpURLLoad("push_state.html");
4036 TestStartStopCallbackWebViewClient client; 3993 TestStartStopCallbackWebViewClient client;
4037 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "push_state.h tml", true, 0, &client); 3994 FrameTestHelpers::WebViewHelper webViewHelper;
3995 webViewHelper.initializeAndLoad(m_baseURL + "push_state.html", true, 0, &cli ent);
4038 runPendingTasks(); 3996 runPendingTasks();
4039 3997
4040 EXPECT_EQ(client.startLoadingCount(), 2); 3998 EXPECT_EQ(client.startLoadingCount(), 2);
4041 EXPECT_EQ(client.stopLoadingCount(), 2); 3999 EXPECT_EQ(client.stopLoadingCount(), 2);
4042 m_webView->close();
4043 m_webView = 0;
4044 } 4000 }
4045 4001
4046 } // namespace 4002 } // namespace
OLDNEW
« no previous file with comments | « Source/web/tests/ScrollingCoordinatorChromiumTest.cpp ('k') | Source/web/tests/WebInputEventConversionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698