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

Side by Side Diff: content/browser/web_contents/web_contents_impl_browsertest.cc

Issue 1411073005: Migrating tests to use EmbeddedTestServer (/content) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 1 month 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "base/values.h" 6 #include "base/values.h"
7 #include "content/browser/frame_host/navigation_entry_impl.h" 7 #include "content/browser/frame_host/navigation_entry_impl.h"
8 #include "content/browser/renderer_host/render_widget_host_impl.h" 8 #include "content/browser/renderer_host/render_widget_host_impl.h"
9 #include "content/browser/web_contents/web_contents_impl.h" 9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/browser/web_contents/web_contents_view.h" 10 #include "content/browser/web_contents/web_contents_view.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 // See: http://crbug.com/298193 189 // See: http://crbug.com/298193
190 #if defined(OS_WIN) || defined(OS_LINUX) 190 #if defined(OS_WIN) || defined(OS_LINUX)
191 #define MAYBE_DidStopLoadingDetails DISABLED_DidStopLoadingDetails 191 #define MAYBE_DidStopLoadingDetails DISABLED_DidStopLoadingDetails
192 #else 192 #else
193 #define MAYBE_DidStopLoadingDetails DidStopLoadingDetails 193 #define MAYBE_DidStopLoadingDetails DidStopLoadingDetails
194 #endif 194 #endif
195 195
196 // Test that DidStopLoading includes the correct URL in the details. 196 // Test that DidStopLoading includes the correct URL in the details.
197 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, 197 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
198 MAYBE_DidStopLoadingDetails) { 198 MAYBE_DidStopLoadingDetails) {
199 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 199 ASSERT_TRUE(embedded_test_server()->Start());
200 200
201 LoadStopNotificationObserver load_observer( 201 LoadStopNotificationObserver load_observer(
202 &shell()->web_contents()->GetController()); 202 &shell()->web_contents()->GetController());
203 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); 203 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"));
204 load_observer.Wait(); 204 load_observer.Wait();
205 205
206 EXPECT_EQ("/title1.html", load_observer.url_.path()); 206 EXPECT_EQ("/title1.html", load_observer.url_.path());
207 EXPECT_EQ(0, load_observer.session_index_); 207 EXPECT_EQ(0, load_observer.session_index_);
208 EXPECT_EQ(&shell()->web_contents()->GetController(), 208 EXPECT_EQ(&shell()->web_contents()->GetController(),
209 load_observer.controller_); 209 load_observer.controller_);
210 } 210 }
211 211
212 // See: http://crbug.com/298193 212 // See: http://crbug.com/298193
213 #if defined(OS_WIN) || defined(OS_LINUX) 213 #if defined(OS_WIN) || defined(OS_LINUX)
214 #define MAYBE_DidStopLoadingDetailsWithPending \ 214 #define MAYBE_DidStopLoadingDetailsWithPending \
215 DISABLED_DidStopLoadingDetailsWithPending 215 DISABLED_DidStopLoadingDetailsWithPending
216 #else 216 #else
217 #define MAYBE_DidStopLoadingDetailsWithPending DidStopLoadingDetailsWithPending 217 #define MAYBE_DidStopLoadingDetailsWithPending DidStopLoadingDetailsWithPending
218 #endif 218 #endif
219 219
220 // Test that DidStopLoading includes the correct URL in the details when a 220 // Test that DidStopLoading includes the correct URL in the details when a
221 // pending entry is present. 221 // pending entry is present.
222 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, 222 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
223 MAYBE_DidStopLoadingDetailsWithPending) { 223 MAYBE_DidStopLoadingDetailsWithPending) {
224 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 224 ASSERT_TRUE(embedded_test_server()->Start());
225 GURL url("data:text/html,<div>test</div>"); 225 GURL url("data:text/html,<div>test</div>");
226 226
227 // Listen for the first load to stop. 227 // Listen for the first load to stop.
228 LoadStopNotificationObserver load_observer( 228 LoadStopNotificationObserver load_observer(
229 &shell()->web_contents()->GetController()); 229 &shell()->web_contents()->GetController());
230 // Start a new pending navigation as soon as the first load commits. 230 // Start a new pending navigation as soon as the first load commits.
231 // We will hear a DidStopLoading from the first load as the new load 231 // We will hear a DidStopLoading from the first load as the new load
232 // is started. 232 // is started.
233 NavigateOnCommitObserver commit_observer( 233 NavigateOnCommitObserver commit_observer(
234 shell(), embedded_test_server()->GetURL("/title2.html")); 234 shell(), embedded_test_server()->GetURL("/title2.html"));
235 NavigateToURL(shell(), url); 235 NavigateToURL(shell(), url);
236 load_observer.Wait(); 236 load_observer.Wait();
237 237
238 EXPECT_EQ(url, load_observer.url_); 238 EXPECT_EQ(url, load_observer.url_);
239 EXPECT_EQ(0, load_observer.session_index_); 239 EXPECT_EQ(0, load_observer.session_index_);
240 EXPECT_EQ(&shell()->web_contents()->GetController(), 240 EXPECT_EQ(&shell()->web_contents()->GetController(),
241 load_observer.controller_); 241 load_observer.controller_);
242 } 242 }
243 // Test that a renderer-initiated navigation to an invalid URL does not leave 243 // Test that a renderer-initiated navigation to an invalid URL does not leave
244 // around a pending entry that could be used in a URL spoof. We test this in 244 // around a pending entry that could be used in a URL spoof. We test this in
245 // a browser test because our unit test framework incorrectly calls 245 // a browser test because our unit test framework incorrectly calls
246 // DidStartProvisionalLoadForFrame for in-page navigations. 246 // DidStartProvisionalLoadForFrame for in-page navigations.
247 // See http://crbug.com/280512. 247 // See http://crbug.com/280512.
248 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, 248 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
249 ClearNonVisiblePendingOnFail) { 249 ClearNonVisiblePendingOnFail) {
250 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 250 ASSERT_TRUE(embedded_test_server()->Start());
251 251
252 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); 252 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"));
253 253
254 // Navigate to an invalid URL and make sure it doesn't leave a pending entry. 254 // Navigate to an invalid URL and make sure it doesn't leave a pending entry.
255 LoadStopNotificationObserver load_observer1( 255 LoadStopNotificationObserver load_observer1(
256 &shell()->web_contents()->GetController()); 256 &shell()->web_contents()->GetController());
257 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), 257 ASSERT_TRUE(ExecuteScript(shell()->web_contents(),
258 "window.location.href=\"nonexistent:12121\";")); 258 "window.location.href=\"nonexistent:12121\";"));
259 load_observer1.Wait(); 259 load_observer1.Wait();
260 EXPECT_FALSE(shell()->web_contents()->GetController().GetPendingEntry()); 260 EXPECT_FALSE(shell()->web_contents()->GetController().GetPendingEntry());
(...skipping 11 matching lines...) Expand all
272 #if defined(OS_WIN) || defined(OS_ANDROID) \ 272 #if defined(OS_WIN) || defined(OS_ANDROID) \
273 || defined(THREAD_SANITIZER) 273 || defined(THREAD_SANITIZER)
274 #define MAYBE_GetSizeForNewRenderView DISABLED_GetSizeForNewRenderView 274 #define MAYBE_GetSizeForNewRenderView DISABLED_GetSizeForNewRenderView
275 #else 275 #else
276 #define MAYBE_GetSizeForNewRenderView GetSizeForNewRenderView 276 #define MAYBE_GetSizeForNewRenderView GetSizeForNewRenderView
277 #endif 277 #endif
278 // Test that RenderViewHost is created and updated at the size specified by 278 // Test that RenderViewHost is created and updated at the size specified by
279 // WebContentsDelegate::GetSizeForNewRenderView(). 279 // WebContentsDelegate::GetSizeForNewRenderView().
280 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, 280 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
281 MAYBE_GetSizeForNewRenderView) { 281 MAYBE_GetSizeForNewRenderView) {
282 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 282 ASSERT_TRUE(embedded_test_server()->Start());
283 // Create a new server with a different site. 283 // Create a new server with a different site.
284 net::SpawnedTestServer https_server( 284 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS);
285 net::SpawnedTestServer::TYPE_HTTPS, 285 https_server.ServeFilesFromSourceDirectory("content/test/data");
286 net::SpawnedTestServer::kLocalhost,
287 base::FilePath(FILE_PATH_LITERAL("content/test/data")));
288 ASSERT_TRUE(https_server.Start()); 286 ASSERT_TRUE(https_server.Start());
289 287
290 scoped_ptr<RenderViewSizeDelegate> delegate(new RenderViewSizeDelegate()); 288 scoped_ptr<RenderViewSizeDelegate> delegate(new RenderViewSizeDelegate());
291 shell()->web_contents()->SetDelegate(delegate.get()); 289 shell()->web_contents()->SetDelegate(delegate.get());
292 ASSERT_TRUE(shell()->web_contents()->GetDelegate() == delegate.get()); 290 ASSERT_TRUE(shell()->web_contents()->GetDelegate() == delegate.get());
293 291
294 // When no size is set, RenderWidgetHostView adopts the size of 292 // When no size is set, RenderWidgetHostView adopts the size of
295 // WebContentsView. 293 // WebContentsView.
296 NavigateToURL(shell(), embedded_test_server()->GetURL("/title2.html")); 294 NavigateToURL(shell(), embedded_test_server()->GetURL("/title2.html"));
297 EXPECT_EQ(shell()->web_contents()->GetContainerBounds().size(), 295 EXPECT_EQ(shell()->web_contents()->GetContainerBounds().size(),
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 shell()->web_contents()->GetController().GetLastCommittedEntry()); 365 shell()->web_contents()->GetController().GetLastCommittedEntry());
368 SiteInstance* site_instance2 = entry2->site_instance(); 366 SiteInstance* site_instance2 = entry2->site_instance();
369 EXPECT_NE(site_instance1, site_instance2); 367 EXPECT_NE(site_instance1, site_instance2);
370 368
371 EXPECT_EQ(2, shell()->web_contents()->GetController().GetEntryCount()); 369 EXPECT_EQ(2, shell()->web_contents()->GetController().GetEntryCount());
372 EXPECT_EQ(base::ASCIIToUTF16("B"), entry1->GetTitle()); 370 EXPECT_EQ(base::ASCIIToUTF16("B"), entry1->GetTitle());
373 } 371 }
374 372
375 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, OpenURLSubframe) { 373 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, OpenURLSubframe) {
376 // Navigate to a page with frames and grab a subframe's FrameTreeNode ID. 374 // Navigate to a page with frames and grab a subframe's FrameTreeNode ID.
377 ASSERT_TRUE(test_server()->Start()); 375 ASSERT_TRUE(embedded_test_server()->Start());
378 NavigateToURL(shell(), 376 NavigateToURL(shell(),
379 test_server()->GetURL("files/frame_tree/top.html")); 377 embedded_test_server()->GetURL("/frame_tree/top.html"));
380 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); 378 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
381 FrameTreeNode* root = wc->GetFrameTree()->root(); 379 FrameTreeNode* root = wc->GetFrameTree()->root();
382 ASSERT_EQ(3UL, root->child_count()); 380 ASSERT_EQ(3UL, root->child_count());
383 int frame_tree_node_id = root->child_at(0)->frame_tree_node_id(); 381 int frame_tree_node_id = root->child_at(0)->frame_tree_node_id();
384 EXPECT_NE(-1, frame_tree_node_id); 382 EXPECT_NE(-1, frame_tree_node_id);
385 383
386 // Navigate with the subframe's FrameTreeNode ID. 384 // Navigate with the subframe's FrameTreeNode ID.
387 const GURL url(test_server()->GetURL("files/title1.html")); 385 const GURL url(embedded_test_server()->GetURL("/title1.html"));
388 OpenURLParams params(url, Referrer(), frame_tree_node_id, CURRENT_TAB, 386 OpenURLParams params(url, Referrer(), frame_tree_node_id, CURRENT_TAB,
389 ui::PAGE_TRANSITION_LINK, true); 387 ui::PAGE_TRANSITION_LINK, true);
390 shell()->web_contents()->OpenURL(params); 388 shell()->web_contents()->OpenURL(params);
391 389
392 // Make sure the NavigationEntry ends up with the FrameTreeNode ID. 390 // Make sure the NavigationEntry ends up with the FrameTreeNode ID.
393 NavigationController* controller = &shell()->web_contents()->GetController(); 391 NavigationController* controller = &shell()->web_contents()->GetController();
394 EXPECT_TRUE(controller->GetPendingEntry()); 392 EXPECT_TRUE(controller->GetPendingEntry());
395 EXPECT_EQ(frame_tree_node_id, 393 EXPECT_EQ(frame_tree_node_id,
396 NavigationEntryImpl::FromNavigationEntry( 394 NavigationEntryImpl::FromNavigationEntry(
397 controller->GetPendingEntry())->frame_tree_node_id()); 395 controller->GetPendingEntry())->frame_tree_node_id());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, 434 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
437 RenderFrameCreatedCorrectProcessForObservers) { 435 RenderFrameCreatedCorrectProcessForObservers) {
438 static const char kFooCom[] = "foo.com"; 436 static const char kFooCom[] = "foo.com";
439 GURL::Replacements replace_host; 437 GURL::Replacements replace_host;
440 net::HostPortPair foo_host_port; 438 net::HostPortPair foo_host_port;
441 GURL cross_site_url; 439 GURL cross_site_url;
442 440
443 // Setup the server to allow serving separate sites, so we can perform 441 // Setup the server to allow serving separate sites, so we can perform
444 // cross-process navigation. 442 // cross-process navigation.
445 host_resolver()->AddRule("*", "127.0.0.1"); 443 host_resolver()->AddRule("*", "127.0.0.1");
446 ASSERT_TRUE(test_server()->Start()); 444 ASSERT_TRUE(embedded_test_server()->Start());
447 445
448 foo_host_port = test_server()->host_port_pair(); 446 foo_host_port = embedded_test_server()->host_port_pair();
449 foo_host_port.set_host(kFooCom); 447 foo_host_port.set_host(kFooCom);
450 448
451 GURL initial_url(test_server()->GetURL("/title1.html")); 449 GURL initial_url(embedded_test_server()->GetURL("/title1.html"));
452 450
453 cross_site_url = test_server()->GetURL("/title2.html"); 451 cross_site_url = embedded_test_server()->GetURL("/title2.html");
454 replace_host.SetHostStr(kFooCom); 452 replace_host.SetHostStr(kFooCom);
455 cross_site_url = cross_site_url.ReplaceComponents(replace_host); 453 cross_site_url = cross_site_url.ReplaceComponents(replace_host);
456 454
457 // Navigate to the initial URL and capture the RenderFrameHost for later 455 // Navigate to the initial URL and capture the RenderFrameHost for later
458 // comparison. 456 // comparison.
459 NavigateToURL(shell(), initial_url); 457 NavigateToURL(shell(), initial_url);
460 RenderFrameHost* orig_rfh = shell()->web_contents()->GetMainFrame(); 458 RenderFrameHost* orig_rfh = shell()->web_contents()->GetMainFrame();
461 459
462 // Install the observer and navigate cross-site. 460 // Install the observer and navigate cross-site.
463 RenderFrameCreatedObserver observer(shell()); 461 RenderFrameCreatedObserver observer(shell());
464 NavigateToURL(shell(), cross_site_url); 462 NavigateToURL(shell(), cross_site_url);
465 463
466 // The observer should've seen a RenderFrameCreated call for the new frame 464 // The observer should've seen a RenderFrameCreated call for the new frame
467 // and not the old one. 465 // and not the old one.
468 EXPECT_NE(observer.last_rfh(), orig_rfh); 466 EXPECT_NE(observer.last_rfh(), orig_rfh);
469 EXPECT_EQ(observer.last_rfh(), shell()->web_contents()->GetMainFrame()); 467 EXPECT_EQ(observer.last_rfh(), shell()->web_contents()->GetMainFrame());
470 } 468 }
471 469
472 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, 470 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
473 LoadingStateChangedForSameDocumentNavigation) { 471 LoadingStateChangedForSameDocumentNavigation) {
474 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 472 ASSERT_TRUE(embedded_test_server()->Start());
475 scoped_ptr<LoadingStateChangedDelegate> delegate( 473 scoped_ptr<LoadingStateChangedDelegate> delegate(
476 new LoadingStateChangedDelegate()); 474 new LoadingStateChangedDelegate());
477 shell()->web_contents()->SetDelegate(delegate.get()); 475 shell()->web_contents()->SetDelegate(delegate.get());
478 476
479 LoadStopNotificationObserver load_observer( 477 LoadStopNotificationObserver load_observer(
480 &shell()->web_contents()->GetController()); 478 &shell()->web_contents()->GetController());
481 TitleWatcher title_watcher(shell()->web_contents(), 479 TitleWatcher title_watcher(shell()->web_contents(),
482 base::ASCIIToUTF16("pushState")); 480 base::ASCIIToUTF16("pushState"));
483 NavigateToURL(shell(), embedded_test_server()->GetURL("/push_state.html")); 481 NavigateToURL(shell(), embedded_test_server()->GetURL("/push_state.html"));
484 load_observer.Wait(); 482 load_observer.Wait();
485 base::string16 title = title_watcher.WaitAndGetTitle(); 483 base::string16 title = title_watcher.WaitAndGetTitle();
486 ASSERT_EQ(title, base::ASCIIToUTF16("pushState")); 484 ASSERT_EQ(title, base::ASCIIToUTF16("pushState"));
487 485
488 // LoadingStateChanged should be called 4 times: start and stop for the 486 // LoadingStateChanged should be called 4 times: start and stop for the
489 // initial load of push_state.html, and start and stop for the "navigation" 487 // initial load of push_state.html, and start and stop for the "navigation"
490 // triggered by history.pushState(). However, the start notification for the 488 // triggered by history.pushState(). However, the start notification for the
491 // history.pushState() navigation should set to_different_document to false. 489 // history.pushState() navigation should set to_different_document to false.
492 EXPECT_EQ("pushState", shell()->web_contents()->GetLastCommittedURL().ref()); 490 EXPECT_EQ("pushState", shell()->web_contents()->GetLastCommittedURL().ref());
493 EXPECT_EQ(4, delegate->loadingStateChangedCount()); 491 EXPECT_EQ(4, delegate->loadingStateChangedCount());
494 EXPECT_EQ(3, delegate->loadingStateToDifferentDocumentCount()); 492 EXPECT_EQ(3, delegate->loadingStateToDifferentDocumentCount());
495 } 493 }
496 494
497 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, 495 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
498 RenderViewCreatedForChildWindow) { 496 RenderViewCreatedForChildWindow) {
499 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 497 ASSERT_TRUE(embedded_test_server()->Start());
500 498
501 NavigateToURL(shell(), 499 NavigateToURL(shell(),
502 embedded_test_server()->GetURL("/title1.html")); 500 embedded_test_server()->GetURL("/title1.html"));
503 501
504 WebContentsAddedObserver new_web_contents_observer; 502 WebContentsAddedObserver new_web_contents_observer;
505 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), 503 ASSERT_TRUE(ExecuteScript(shell()->web_contents(),
506 "var a = document.createElement('a');" 504 "var a = document.createElement('a');"
507 "a.href='./title2.html';" 505 "a.href='./title2.html';"
508 "a.target = '_blank';" 506 "a.target = '_blank';"
509 "document.body.appendChild(a);" 507 "document.body.appendChild(a);"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 EXPECT_FALSE(did_stop_loading); 541 EXPECT_FALSE(did_stop_loading);
544 did_stop_loading = true; 542 did_stop_loading = true;
545 } 543 }
546 544
547 bool did_start_loading; 545 bool did_start_loading;
548 std::vector<double> progresses; 546 std::vector<double> progresses;
549 bool did_stop_loading; 547 bool did_stop_loading;
550 }; 548 };
551 549
552 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, LoadProgress) { 550 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, LoadProgress) {
553 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 551 ASSERT_TRUE(embedded_test_server()->Start());
554 scoped_ptr<LoadProgressDelegateAndObserver> delegate( 552 scoped_ptr<LoadProgressDelegateAndObserver> delegate(
555 new LoadProgressDelegateAndObserver(shell())); 553 new LoadProgressDelegateAndObserver(shell()));
556 554
557 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); 555 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"));
558 556
559 const std::vector<double>& progresses = delegate->progresses; 557 const std::vector<double>& progresses = delegate->progresses;
560 // All updates should be in order ... 558 // All updates should be in order ...
561 if (std::adjacent_find(progresses.begin(), 559 if (std::adjacent_find(progresses.begin(),
562 progresses.end(), 560 progresses.end(),
563 std::greater<double>()) != progresses.end()) { 561 std::greater<double>()) != progresses.end()) {
564 ADD_FAILURE() << "Progress values should be in order: " 562 ADD_FAILURE() << "Progress values should be in order: "
565 << ::testing::PrintToString(progresses); 563 << ::testing::PrintToString(progresses);
566 } 564 }
567 565
568 // ... and the last one should be 1.0, meaning complete. 566 // ... and the last one should be 1.0, meaning complete.
569 ASSERT_GE(progresses.size(), 1U) 567 ASSERT_GE(progresses.size(), 1U)
570 << "There should be at least one progress update"; 568 << "There should be at least one progress update";
571 EXPECT_EQ(1.0, *progresses.rbegin()); 569 EXPECT_EQ(1.0, *progresses.rbegin());
572 } 570 }
573 571
574 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, LoadProgressWithFrames) { 572 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, LoadProgressWithFrames) {
575 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 573 ASSERT_TRUE(embedded_test_server()->Start());
576 scoped_ptr<LoadProgressDelegateAndObserver> delegate( 574 scoped_ptr<LoadProgressDelegateAndObserver> delegate(
577 new LoadProgressDelegateAndObserver(shell())); 575 new LoadProgressDelegateAndObserver(shell()));
578 576
579 NavigateToURL(shell(), 577 NavigateToURL(shell(),
580 embedded_test_server()->GetURL("/frame_tree/top.html")); 578 embedded_test_server()->GetURL("/frame_tree/top.html"));
581 579
582 const std::vector<double>& progresses = delegate->progresses; 580 const std::vector<double>& progresses = delegate->progresses;
583 // All updates should be in order ... 581 // All updates should be in order ...
584 if (std::adjacent_find(progresses.begin(), 582 if (std::adjacent_find(progresses.begin(),
585 progresses.end(), 583 progresses.end(),
586 std::greater<double>()) != progresses.end()) { 584 std::greater<double>()) != progresses.end()) {
587 ADD_FAILURE() << "Progress values should be in order: " 585 ADD_FAILURE() << "Progress values should be in order: "
588 << ::testing::PrintToString(progresses); 586 << ::testing::PrintToString(progresses);
589 } 587 }
590 588
591 // ... and the last one should be 1.0, meaning complete. 589 // ... and the last one should be 1.0, meaning complete.
592 ASSERT_GE(progresses.size(), 1U) 590 ASSERT_GE(progresses.size(), 1U)
593 << "There should be at least one progress update"; 591 << "There should be at least one progress update";
594 EXPECT_EQ(1.0, *progresses.rbegin()); 592 EXPECT_EQ(1.0, *progresses.rbegin());
595 } 593 }
596 594
597 // Ensure that a new navigation that interrupts a pending one will still fire 595 // Ensure that a new navigation that interrupts a pending one will still fire
598 // a DidStopLoading. See http://crbug.com/429399. 596 // a DidStopLoading. See http://crbug.com/429399.
599 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, 597 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
600 LoadProgressAfterInterruptedNav) { 598 LoadProgressAfterInterruptedNav) {
601 host_resolver()->AddRule("*", "127.0.0.1"); 599 host_resolver()->AddRule("*", "127.0.0.1");
602 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 600 ASSERT_TRUE(embedded_test_server()->Start());
603 601
604 // Start at a real page. 602 // Start at a real page.
605 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); 603 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"));
606 604
607 // Simulate a navigation that has not completed. 605 // Simulate a navigation that has not completed.
608 scoped_ptr<LoadProgressDelegateAndObserver> delegate( 606 scoped_ptr<LoadProgressDelegateAndObserver> delegate(
609 new LoadProgressDelegateAndObserver(shell())); 607 new LoadProgressDelegateAndObserver(shell()));
610 RenderFrameHost* main_frame = shell()->web_contents()->GetMainFrame(); 608 RenderFrameHost* main_frame = shell()->web_contents()->GetMainFrame();
611 FrameHostMsg_DidStartLoading start_msg(main_frame->GetRoutingID(), true); 609 FrameHostMsg_DidStartLoading start_msg(main_frame->GetRoutingID(), true);
612 static_cast<RenderFrameHostImpl*>(main_frame)->OnMessageReceived(start_msg); 610 static_cast<RenderFrameHostImpl*>(main_frame)->OnMessageReceived(start_msg);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 654
657 // See: http://crbug.com/395664 655 // See: http://crbug.com/395664
658 #if defined(OS_ANDROID) 656 #if defined(OS_ANDROID)
659 #define MAYBE_FirstVisuallyNonEmptyPaint DISABLED_FirstVisuallyNonEmptyPaint 657 #define MAYBE_FirstVisuallyNonEmptyPaint DISABLED_FirstVisuallyNonEmptyPaint
660 #else 658 #else
661 // http://crbug.com/398471 659 // http://crbug.com/398471
662 #define MAYBE_FirstVisuallyNonEmptyPaint DISABLED_FirstVisuallyNonEmptyPaint 660 #define MAYBE_FirstVisuallyNonEmptyPaint DISABLED_FirstVisuallyNonEmptyPaint
663 #endif 661 #endif
664 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, 662 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
665 MAYBE_FirstVisuallyNonEmptyPaint) { 663 MAYBE_FirstVisuallyNonEmptyPaint) {
666 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 664 ASSERT_TRUE(embedded_test_server()->Start());
667 scoped_ptr<FirstVisuallyNonEmptyPaintObserver> observer( 665 scoped_ptr<FirstVisuallyNonEmptyPaintObserver> observer(
668 new FirstVisuallyNonEmptyPaintObserver(shell())); 666 new FirstVisuallyNonEmptyPaintObserver(shell()));
669 667
670 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); 668 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"));
671 669
672 observer->WaitForDidFirstVisuallyNonEmptyPaint(); 670 observer->WaitForDidFirstVisuallyNonEmptyPaint();
673 ASSERT_TRUE(observer->did_fist_visually_non_empty_paint_); 671 ASSERT_TRUE(observer->did_fist_visually_non_empty_paint_);
674 } 672 }
675 673
676 namespace { 674 namespace {
677 675
678 class WebDisplayModeDelegate : public WebContentsDelegate { 676 class WebDisplayModeDelegate : public WebContentsDelegate {
679 public: 677 public:
680 explicit WebDisplayModeDelegate(blink::WebDisplayMode mode) : mode_(mode) { } 678 explicit WebDisplayModeDelegate(blink::WebDisplayMode mode) : mode_(mode) { }
681 ~WebDisplayModeDelegate() override { } 679 ~WebDisplayModeDelegate() override { }
682 680
683 blink::WebDisplayMode GetDisplayMode( 681 blink::WebDisplayMode GetDisplayMode(
684 const WebContents* source) const override { return mode_; } 682 const WebContents* source) const override { return mode_; }
685 void set_mode(blink::WebDisplayMode mode) { mode_ = mode; } 683 void set_mode(blink::WebDisplayMode mode) { mode_ = mode; }
686 private: 684 private:
687 blink::WebDisplayMode mode_; 685 blink::WebDisplayMode mode_;
688 686
689 DISALLOW_COPY_AND_ASSIGN(WebDisplayModeDelegate); 687 DISALLOW_COPY_AND_ASSIGN(WebDisplayModeDelegate);
690 }; 688 };
691 689
692 } 690 }
693 691
694 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ChangeDisplayMode) { 692 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ChangeDisplayMode) {
695 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 693 ASSERT_TRUE(embedded_test_server()->Start());
696 WebDisplayModeDelegate delegate(blink::WebDisplayModeMinimalUi); 694 WebDisplayModeDelegate delegate(blink::WebDisplayModeMinimalUi);
697 shell()->web_contents()->SetDelegate(&delegate); 695 shell()->web_contents()->SetDelegate(&delegate);
698 696
699 NavigateToURL(shell(), GURL("about://blank")); 697 NavigateToURL(shell(), GURL("about://blank"));
700 698
701 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), 699 ASSERT_TRUE(ExecuteScript(shell()->web_contents(),
702 "document.title = " 700 "document.title = "
703 " window.matchMedia('(display-mode:" 701 " window.matchMedia('(display-mode:"
704 " minimal-ui)').matches")); 702 " minimal-ui)').matches"));
705 EXPECT_EQ(base::ASCIIToUTF16("true"), shell()->web_contents()->GetTitle()); 703 EXPECT_EQ(base::ASCIIToUTF16("true"), shell()->web_contents()->GetTitle());
706 704
707 delegate.set_mode(blink::WebDisplayModeFullscreen); 705 delegate.set_mode(blink::WebDisplayModeFullscreen);
708 // Simulate widget is entering fullscreen (changing size is enough). 706 // Simulate widget is entering fullscreen (changing size is enough).
709 shell()->web_contents()->GetRenderViewHost()->GetWidget()->WasResized(); 707 shell()->web_contents()->GetRenderViewHost()->GetWidget()->WasResized();
710 708
711 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), 709 ASSERT_TRUE(ExecuteScript(shell()->web_contents(),
712 "document.title = " 710 "document.title = "
713 " window.matchMedia('(display-mode:" 711 " window.matchMedia('(display-mode:"
714 " fullscreen)').matches")); 712 " fullscreen)').matches"));
715 EXPECT_EQ(base::ASCIIToUTF16("true"), shell()->web_contents()->GetTitle()); 713 EXPECT_EQ(base::ASCIIToUTF16("true"), shell()->web_contents()->GetTitle());
716 } 714 }
717 715
718 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NewNamedWindow) { 716 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NewNamedWindow) {
719 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 717 ASSERT_TRUE(embedded_test_server()->Start());
720 718
721 GURL url = embedded_test_server()->GetURL("/click-noreferrer-links.html"); 719 GURL url = embedded_test_server()->GetURL("/click-noreferrer-links.html");
722 EXPECT_TRUE(NavigateToURL(shell(), url)); 720 EXPECT_TRUE(NavigateToURL(shell(), url));
723 721
724 { 722 {
725 ShellAddedObserver new_shell_observer; 723 ShellAddedObserver new_shell_observer;
726 724
727 // Open a new, named window. 725 // Open a new, named window.
728 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), 726 EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
729 "window.open('about:blank','new_window');")); 727 "window.open('about:blank','new_window');"));
(...skipping 27 matching lines...) Expand all
757 Shell* new_shell = new_shell_observer.GetShell(); 755 Shell* new_shell = new_shell_observer.GetShell();
758 WaitForLoadStop(new_shell->web_contents()); 756 WaitForLoadStop(new_shell->web_contents());
759 757
760 EXPECT_EQ("foo", 758 EXPECT_EQ("foo",
761 static_cast<WebContentsImpl*>(new_shell->web_contents()) 759 static_cast<WebContentsImpl*>(new_shell->web_contents())
762 ->GetFrameTree()->root()->frame_name()); 760 ->GetFrameTree()->root()->frame_name());
763 } 761 }
764 } 762 }
765 763
766 } // namespace content 764 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698