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

Side by Side Diff: chrome/browser/sessions/session_restore_browsertest.cc

Issue 10827168: Fix user agent override restore pipeline (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebasing Created 8 years, 4 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/file_path.h" 6 #include "base/file_path.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/defaults.h" 9 #include "chrome/browser/defaults.h"
10 #include "chrome/browser/first_run/first_run.h" 10 #include "chrome/browser/first_run/first_run.h"
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 TabNavigation nav2(0, url2, content::Referrer(), ASCIIToUTF16("two"), 385 TabNavigation nav2(0, url2, content::Referrer(), ASCIIToUTF16("two"),
386 std::string(), content::PAGE_TRANSITION_TYPED); 386 std::string(), content::PAGE_TRANSITION_TYPED);
387 387
388 // Set up the restore data. 388 // Set up the restore data.
389 SessionTab tab; 389 SessionTab tab;
390 tab.tab_visual_index = 0; 390 tab.tab_visual_index = 0;
391 tab.current_navigation_index = 1; 391 tab.current_navigation_index = 1;
392 tab.pinned = false; 392 tab.pinned = false;
393 tab.navigations.push_back(nav1); 393 tab.navigations.push_back(nav1);
394 tab.navigations.push_back(nav2); 394 tab.navigations.push_back(nav2);
395 tab.user_agent_override = "user_agent_override";
Charlie Reis 2012/08/15 17:24:23 Can you make this a realistic value? Tests also s
gone 2012/08/15 20:15:43 Stuck in the one we're currently using to spoof a
395 396
396 ASSERT_EQ(1, browser()->tab_count()); 397 ASSERT_EQ(1, browser()->tab_count());
397 398
398 // Restore in the current tab. 399 // Restore in the current tab.
399 { 400 {
400 content::WindowedNotificationObserver observer( 401 content::WindowedNotificationObserver observer(
401 content::NOTIFICATION_LOAD_STOP, 402 content::NOTIFICATION_LOAD_STOP,
402 content::NotificationService::AllSources()); 403 content::NotificationService::AllSources());
403 SessionRestore::RestoreForeignSessionTab( 404 SessionRestore::RestoreForeignSessionTab(
404 chrome::GetActiveWebContents(browser()), tab, CURRENT_TAB); 405 chrome::GetActiveWebContents(browser()), tab, CURRENT_TAB);
405 observer.Wait(); 406 observer.Wait();
406 } 407 }
407 ASSERT_EQ(1, browser()->tab_count()); 408 ASSERT_EQ(1, browser()->tab_count());
408 VerifyNavigationEntries( 409 content::WebContents* web_contents = chrome::GetWebContentsAt(browser(), 0);
409 chrome::GetWebContentsAt(browser(), 0)->GetController(), url1, url2); 410 VerifyNavigationEntries(web_contents->GetController(), url1, url2);
411 ASSERT_EQ(tab.user_agent_override, web_contents->GetUserAgentOverride());
410 412
411 // Restore in a new tab. 413 // Restore in a new tab.
412 { 414 {
413 content::WindowedNotificationObserver observer( 415 content::WindowedNotificationObserver observer(
414 content::NOTIFICATION_LOAD_STOP, 416 content::NOTIFICATION_LOAD_STOP,
415 content::NotificationService::AllSources()); 417 content::NotificationService::AllSources());
416 SessionRestore::RestoreForeignSessionTab( 418 SessionRestore::RestoreForeignSessionTab(
417 chrome::GetActiveWebContents(browser()), tab, NEW_BACKGROUND_TAB); 419 chrome::GetActiveWebContents(browser()), tab, NEW_BACKGROUND_TAB);
418 observer.Wait(); 420 observer.Wait();
419 } 421 }
420 ASSERT_EQ(2, browser()->tab_count()); 422 ASSERT_EQ(2, browser()->tab_count());
421 ASSERT_EQ(0, browser()->active_index()); 423 ASSERT_EQ(0, browser()->active_index());
422 VerifyNavigationEntries( 424 web_contents = chrome::GetWebContentsAt(browser(), 1);
423 chrome::GetWebContentsAt(browser(), 1)->GetController(), url1, url2); 425 VerifyNavigationEntries(web_contents->GetController(), url1, url2);
426 ASSERT_EQ(tab.user_agent_override, web_contents->GetUserAgentOverride());
424 427
425 // Restore in a new window. 428 // Restore in a new window.
426 ui_test_utils::BrowserAddedObserver browser_observer; 429 ui_test_utils::BrowserAddedObserver browser_observer;
427 SessionRestore::RestoreForeignSessionTab( 430 SessionRestore::RestoreForeignSessionTab(
428 chrome::GetActiveWebContents(browser()), tab, NEW_WINDOW); 431 chrome::GetActiveWebContents(browser()), tab, NEW_WINDOW);
429 Browser* new_browser = browser_observer.WaitForSingleNewBrowser(); 432 Browser* new_browser = browser_observer.WaitForSingleNewBrowser();
430 433
431 ASSERT_EQ(1, new_browser->tab_count()); 434 ASSERT_EQ(1, new_browser->tab_count());
432 VerifyNavigationEntries( 435 web_contents = chrome::GetWebContentsAt(new_browser, 0);
433 chrome::GetWebContentsAt(new_browser, 0)->GetController(), url1, url2); 436 VerifyNavigationEntries(web_contents->GetController(), url1, url2);
437 ASSERT_EQ(tab.user_agent_override, web_contents->GetUserAgentOverride());
434 } 438 }
435 439
436 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) { 440 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) {
437 Profile* profile = browser()->profile(); 441 Profile* profile = browser()->profile();
438 442
439 GURL url1("http://google.com"); 443 GURL url1("http://google.com");
440 GURL url2("http://google2.com"); 444 GURL url2("http://google2.com");
441 TabNavigation nav1(0, url1, content::Referrer(), ASCIIToUTF16("one"), 445 TabNavigation nav1(0, url1, content::Referrer(), ASCIIToUTF16("one"),
442 std::string(), content::PAGE_TRANSITION_TYPED); 446 std::string(), content::PAGE_TRANSITION_TYPED);
443 TabNavigation nav2(0, url2, content::Referrer(), ASCIIToUTF16("two"), 447 TabNavigation nav2(0, url2, content::Referrer(), ASCIIToUTF16("two"),
444 std::string(), content::PAGE_TRANSITION_TYPED); 448 std::string(), content::PAGE_TRANSITION_TYPED);
449 nav1.set_is_overriding_user_agent(false);
450 nav2.set_is_overriding_user_agent(true);
445 451
446 // Set up the restore data -- one window with two tabs. 452 // Set up the restore data -- one window with two tabs.
447 std::vector<const SessionWindow*> session; 453 std::vector<const SessionWindow*> session;
448 SessionWindow window; 454 SessionWindow window;
449 SessionTab tab1; 455 SessionTab tab1;
450 tab1.tab_visual_index = 0; 456 tab1.tab_visual_index = 0;
451 tab1.current_navigation_index = 0; 457 tab1.current_navigation_index = 0;
452 tab1.pinned = true; 458 tab1.pinned = true;
453 tab1.navigations.push_back(nav1); 459 tab1.navigations.push_back(nav1);
460 tab1.user_agent_override = "user_agent_override";
454 window.tabs.push_back(&tab1); 461 window.tabs.push_back(&tab1);
455 462
456 SessionTab tab2; 463 SessionTab tab2;
457 tab2.tab_visual_index = 1; 464 tab2.tab_visual_index = 1;
458 tab2.current_navigation_index = 0; 465 tab2.current_navigation_index = 0;
459 tab2.pinned = false; 466 tab2.pinned = false;
460 tab2.navigations.push_back(nav2); 467 tab2.navigations.push_back(nav2);
468 tab2.user_agent_override = "user_agent_override_2";
461 window.tabs.push_back(&tab2); 469 window.tabs.push_back(&tab2);
462 470
463 session.push_back(static_cast<const SessionWindow*>(&window)); 471 session.push_back(static_cast<const SessionWindow*>(&window));
464 ui_test_utils::BrowserAddedObserver window_observer; 472 ui_test_utils::BrowserAddedObserver window_observer;
465 SessionRestore::RestoreForeignSessionWindows( 473 SessionRestore::RestoreForeignSessionWindows(
466 profile, session.begin(), session.end()); 474 profile, session.begin(), session.end());
467 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); 475 Browser* new_browser = window_observer.WaitForSingleNewBrowser();
468 ASSERT_TRUE(new_browser); 476 ASSERT_TRUE(new_browser);
469 ASSERT_EQ(2u, BrowserList::size()); 477 ASSERT_EQ(2u, BrowserList::size());
470 ASSERT_EQ(2, new_browser->tab_count()); 478 ASSERT_EQ(2, new_browser->tab_count());
471 479
472 ASSERT_EQ(url1, chrome::GetWebContentsAt(new_browser, 0)->GetURL()); 480 content::WebContents* web_contents_1 =
473 ASSERT_EQ(url2, chrome::GetWebContentsAt(new_browser, 1)->GetURL()); 481 chrome::GetWebContentsAt(new_browser, 0);
482 content::WebContents* web_contents_2 =
483 chrome::GetWebContentsAt(new_browser, 1);
484 ASSERT_EQ(url1, web_contents_1->GetURL());
485 ASSERT_EQ(url2, web_contents_2->GetURL());
486
487 // Check user agent override state.
488 ASSERT_EQ(tab1.user_agent_override, web_contents_1->GetUserAgentOverride());
489 ASSERT_EQ(tab2.user_agent_override, web_contents_2->GetUserAgentOverride());
490
491 content::NavigationEntry* entry =
492 web_contents_1->GetController().GetActiveEntry();
493 ASSERT_TRUE(entry);
494 ASSERT_EQ(nav1.is_overriding_user_agent(), entry->GetIsOverridingUserAgent());
495
496 entry = web_contents_2->GetController().GetActiveEntry();
497 ASSERT_TRUE(entry);
498 ASSERT_EQ(nav2.is_overriding_user_agent(), entry->GetIsOverridingUserAgent());
474 499
475 // The SessionWindow destructor deletes the tabs, so we have to clear them 500 // The SessionWindow destructor deletes the tabs, so we have to clear them
476 // here to avoid a crash. 501 // here to avoid a crash.
477 window.tabs.clear(); 502 window.tabs.clear();
478 } 503 }
479 504
480 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, Basic) { 505 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, Basic) {
481 ui_test_utils::NavigateToURL(browser(), url1_); 506 ui_test_utils::NavigateToURL(browser(), url1_);
482 ui_test_utils::NavigateToURL(browser(), url2_); 507 ui_test_utils::NavigateToURL(browser(), url2_);
483 508
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 int expected_process_count = RenderProcessHostCount(); 745 int expected_process_count = RenderProcessHostCount();
721 746
722 // Restart. 747 // Restart.
723 Browser* new_browser = QuitBrowserAndRestore(browser(), 3); 748 Browser* new_browser = QuitBrowserAndRestore(browser(), 3);
724 749
725 ASSERT_EQ(3, new_browser->tab_count()); 750 ASSERT_EQ(3, new_browser->tab_count());
726 751
727 ASSERT_EQ(expected_process_count, RenderProcessHostCount()); 752 ASSERT_EQ(expected_process_count, RenderProcessHostCount());
728 } 753 }
729 754
755 // Test that changing the user agent override will persist it to disk.
756 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, PersistAndRestoreUserAgentOverride) {
757 // Create a tab with an overridden user agent.
758 ui_test_utils::NavigateToURL(browser(), url1_);
759 ASSERT_EQ(0, browser()->active_index());
760 chrome::GetWebContentsAt(browser(), 0)->SetUserAgentOverride("override");
761
762 // Create a tab without an overridden user agent.
763 ui_test_utils::NavigateToURLWithDisposition(
764 browser(), url2_, NEW_FOREGROUND_TAB,
765 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
766 ASSERT_EQ(1, browser()->active_index());
767
768 // Kill the original browser then open a new one to trigger a restore.
769 Browser* new_browser = QuitBrowserAndRestore(browser(), 1);
770 ASSERT_EQ(1u, BrowserList::size());
771 ASSERT_EQ(2, new_browser->tab_count());
772 ASSERT_EQ(1, new_browser->active_index());
773
774 // Confirm that the user agent overrides are properly set.
775 EXPECT_EQ("override",
776 chrome::GetWebContentsAt(new_browser, 0)->GetUserAgentOverride());
777 EXPECT_EQ("",
778 chrome::GetWebContentsAt(new_browser, 1)->GetUserAgentOverride());
779 }
780
730 // Regression test for crbug.com/125958. When restoring a pinned selected tab in 781 // Regression test for crbug.com/125958. When restoring a pinned selected tab in
731 // a setting where there are existing tabs, the selected index computation was 782 // a setting where there are existing tabs, the selected index computation was
732 // wrong, leading to the wrong tab getting selected, DCHECKs firing, and the 783 // wrong, leading to the wrong tab getting selected, DCHECKs firing, and the
733 // pinned tab not getting loaded. 784 // pinned tab not getting loaded.
734 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestorePinnedSelectedTab) { 785 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestorePinnedSelectedTab) {
735 // Create a pinned tab. 786 // Create a pinned tab.
736 ui_test_utils::NavigateToURL(browser(), url1_); 787 ui_test_utils::NavigateToURL(browser(), url1_);
737 browser()->tab_strip_model()->SetTabPinned(0, true); 788 browser()->tab_strip_model()->SetTabPinned(0, true);
738 ASSERT_EQ(0, browser()->active_index()); 789 ASSERT_EQ(0, browser()->active_index());
739 // Create a nonpinned tab. 790 // Create a nonpinned tab.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 ASSERT_EQ(1u, BrowserList::size()); 834 ASSERT_EQ(1u, BrowserList::size());
784 ASSERT_EQ(url1_, chrome::GetActiveWebContents(new_browser)->GetURL()); 835 ASSERT_EQ(url1_, chrome::GetActiveWebContents(new_browser)->GetURL());
785 content::NavigationController* new_controller = 836 content::NavigationController* new_controller =
786 &chrome::GetActiveWebContents(new_browser)->GetController(); 837 &chrome::GetActiveWebContents(new_browser)->GetController();
787 ASSERT_TRUE(new_controller->GetDefaultSessionStorageNamespace()); 838 ASSERT_TRUE(new_controller->GetDefaultSessionStorageNamespace());
788 std::string restored_session_storage_persistent_id = 839 std::string restored_session_storage_persistent_id =
789 new_controller->GetDefaultSessionStorageNamespace()->persistent_id(); 840 new_controller->GetDefaultSessionStorageNamespace()->persistent_id();
790 EXPECT_EQ(session_storage_persistent_id, 841 EXPECT_EQ(session_storage_persistent_id,
791 restored_session_storage_persistent_id); 842 restored_session_storage_persistent_id);
792 } 843 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698