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

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: Nit addressing 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 = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19"
396 " (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19";
395 397
396 ASSERT_EQ(1, browser()->tab_count()); 398 ASSERT_EQ(1, browser()->tab_count());
397 399
398 // Restore in the current tab. 400 // Restore in the current tab.
399 { 401 {
400 content::WindowedNotificationObserver observer( 402 content::WindowedNotificationObserver observer(
401 content::NOTIFICATION_LOAD_STOP, 403 content::NOTIFICATION_LOAD_STOP,
402 content::NotificationService::AllSources()); 404 content::NotificationService::AllSources());
403 SessionRestore::RestoreForeignSessionTab( 405 SessionRestore::RestoreForeignSessionTab(
404 chrome::GetActiveWebContents(browser()), tab, CURRENT_TAB); 406 chrome::GetActiveWebContents(browser()), tab, CURRENT_TAB);
405 observer.Wait(); 407 observer.Wait();
406 } 408 }
407 ASSERT_EQ(1, browser()->tab_count()); 409 ASSERT_EQ(1, browser()->tab_count());
408 VerifyNavigationEntries( 410 content::WebContents* web_contents = chrome::GetWebContentsAt(browser(), 0);
409 chrome::GetWebContentsAt(browser(), 0)->GetController(), url1, url2); 411 VerifyNavigationEntries(web_contents->GetController(), url1, url2);
412 ASSERT_EQ(tab.user_agent_override, web_contents->GetUserAgentOverride());
410 413
411 // Restore in a new tab. 414 // Restore in a new tab.
412 { 415 {
413 content::WindowedNotificationObserver observer( 416 content::WindowedNotificationObserver observer(
414 content::NOTIFICATION_LOAD_STOP, 417 content::NOTIFICATION_LOAD_STOP,
415 content::NotificationService::AllSources()); 418 content::NotificationService::AllSources());
416 SessionRestore::RestoreForeignSessionTab( 419 SessionRestore::RestoreForeignSessionTab(
417 chrome::GetActiveWebContents(browser()), tab, NEW_BACKGROUND_TAB); 420 chrome::GetActiveWebContents(browser()), tab, NEW_BACKGROUND_TAB);
418 observer.Wait(); 421 observer.Wait();
419 } 422 }
420 ASSERT_EQ(2, browser()->tab_count()); 423 ASSERT_EQ(2, browser()->tab_count());
421 ASSERT_EQ(0, browser()->active_index()); 424 ASSERT_EQ(0, browser()->active_index());
422 VerifyNavigationEntries( 425 web_contents = chrome::GetWebContentsAt(browser(), 1);
423 chrome::GetWebContentsAt(browser(), 1)->GetController(), url1, url2); 426 VerifyNavigationEntries(web_contents->GetController(), url1, url2);
427 ASSERT_EQ(tab.user_agent_override, web_contents->GetUserAgentOverride());
424 428
425 // Restore in a new window. 429 // Restore in a new window.
426 ui_test_utils::BrowserAddedObserver browser_observer; 430 ui_test_utils::BrowserAddedObserver browser_observer;
427 SessionRestore::RestoreForeignSessionTab( 431 SessionRestore::RestoreForeignSessionTab(
428 chrome::GetActiveWebContents(browser()), tab, NEW_WINDOW); 432 chrome::GetActiveWebContents(browser()), tab, NEW_WINDOW);
429 Browser* new_browser = browser_observer.WaitForSingleNewBrowser(); 433 Browser* new_browser = browser_observer.WaitForSingleNewBrowser();
430 434
431 ASSERT_EQ(1, new_browser->tab_count()); 435 ASSERT_EQ(1, new_browser->tab_count());
432 VerifyNavigationEntries( 436 web_contents = chrome::GetWebContentsAt(new_browser, 0);
433 chrome::GetWebContentsAt(new_browser, 0)->GetController(), url1, url2); 437 VerifyNavigationEntries(web_contents->GetController(), url1, url2);
438 ASSERT_EQ(tab.user_agent_override, web_contents->GetUserAgentOverride());
434 } 439 }
435 440
436 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) { 441 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) {
437 Profile* profile = browser()->profile(); 442 Profile* profile = browser()->profile();
438 443
439 GURL url1("http://google.com"); 444 GURL url1("http://google.com");
440 GURL url2("http://google2.com"); 445 GURL url2("http://google2.com");
441 TabNavigation nav1(0, url1, content::Referrer(), ASCIIToUTF16("one"), 446 TabNavigation nav1(0, url1, content::Referrer(), ASCIIToUTF16("one"),
442 std::string(), content::PAGE_TRANSITION_TYPED); 447 std::string(), content::PAGE_TRANSITION_TYPED);
443 TabNavigation nav2(0, url2, content::Referrer(), ASCIIToUTF16("two"), 448 TabNavigation nav2(0, url2, content::Referrer(), ASCIIToUTF16("two"),
444 std::string(), content::PAGE_TRANSITION_TYPED); 449 std::string(), content::PAGE_TRANSITION_TYPED);
450 nav1.set_is_overriding_user_agent(false);
451 nav2.set_is_overriding_user_agent(true);
445 452
446 // Set up the restore data -- one window with two tabs. 453 // Set up the restore data -- one window with two tabs.
447 std::vector<const SessionWindow*> session; 454 std::vector<const SessionWindow*> session;
448 SessionWindow window; 455 SessionWindow window;
449 SessionTab tab1; 456 SessionTab tab1;
450 tab1.tab_visual_index = 0; 457 tab1.tab_visual_index = 0;
451 tab1.current_navigation_index = 0; 458 tab1.current_navigation_index = 0;
452 tab1.pinned = true; 459 tab1.pinned = true;
453 tab1.navigations.push_back(nav1); 460 tab1.navigations.push_back(nav1);
461 tab1.user_agent_override = "user_agent_override";
454 window.tabs.push_back(&tab1); 462 window.tabs.push_back(&tab1);
455 463
456 SessionTab tab2; 464 SessionTab tab2;
457 tab2.tab_visual_index = 1; 465 tab2.tab_visual_index = 1;
458 tab2.current_navigation_index = 0; 466 tab2.current_navigation_index = 0;
459 tab2.pinned = false; 467 tab2.pinned = false;
460 tab2.navigations.push_back(nav2); 468 tab2.navigations.push_back(nav2);
469 tab2.user_agent_override = "user_agent_override_2";
461 window.tabs.push_back(&tab2); 470 window.tabs.push_back(&tab2);
462 471
463 session.push_back(static_cast<const SessionWindow*>(&window)); 472 session.push_back(static_cast<const SessionWindow*>(&window));
464 ui_test_utils::BrowserAddedObserver window_observer; 473 ui_test_utils::BrowserAddedObserver window_observer;
465 SessionRestore::RestoreForeignSessionWindows( 474 SessionRestore::RestoreForeignSessionWindows(
466 profile, session.begin(), session.end()); 475 profile, session.begin(), session.end());
467 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); 476 Browser* new_browser = window_observer.WaitForSingleNewBrowser();
468 ASSERT_TRUE(new_browser); 477 ASSERT_TRUE(new_browser);
469 ASSERT_EQ(2u, BrowserList::size()); 478 ASSERT_EQ(2u, BrowserList::size());
470 ASSERT_EQ(2, new_browser->tab_count()); 479 ASSERT_EQ(2, new_browser->tab_count());
471 480
472 ASSERT_EQ(url1, chrome::GetWebContentsAt(new_browser, 0)->GetURL()); 481 content::WebContents* web_contents_1 =
473 ASSERT_EQ(url2, chrome::GetWebContentsAt(new_browser, 1)->GetURL()); 482 chrome::GetWebContentsAt(new_browser, 0);
483 content::WebContents* web_contents_2 =
484 chrome::GetWebContentsAt(new_browser, 1);
485 ASSERT_EQ(url1, web_contents_1->GetURL());
486 ASSERT_EQ(url2, web_contents_2->GetURL());
487
488 // Check user agent override state.
489 ASSERT_EQ(tab1.user_agent_override, web_contents_1->GetUserAgentOverride());
490 ASSERT_EQ(tab2.user_agent_override, web_contents_2->GetUserAgentOverride());
491
492 content::NavigationEntry* entry =
493 web_contents_1->GetController().GetActiveEntry();
494 ASSERT_TRUE(entry);
495 ASSERT_EQ(nav1.is_overriding_user_agent(), entry->GetIsOverridingUserAgent());
496
497 entry = web_contents_2->GetController().GetActiveEntry();
498 ASSERT_TRUE(entry);
499 ASSERT_EQ(nav2.is_overriding_user_agent(), entry->GetIsOverridingUserAgent());
474 500
475 // The SessionWindow destructor deletes the tabs, so we have to clear them 501 // The SessionWindow destructor deletes the tabs, so we have to clear them
476 // here to avoid a crash. 502 // here to avoid a crash.
477 window.tabs.clear(); 503 window.tabs.clear();
478 } 504 }
479 505
480 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, Basic) { 506 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, Basic) {
481 ui_test_utils::NavigateToURL(browser(), url1_); 507 ui_test_utils::NavigateToURL(browser(), url1_);
482 ui_test_utils::NavigateToURL(browser(), url2_); 508 ui_test_utils::NavigateToURL(browser(), url2_);
483 509
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 int expected_process_count = RenderProcessHostCount(); 746 int expected_process_count = RenderProcessHostCount();
721 747
722 // Restart. 748 // Restart.
723 Browser* new_browser = QuitBrowserAndRestore(browser(), 3); 749 Browser* new_browser = QuitBrowserAndRestore(browser(), 3);
724 750
725 ASSERT_EQ(3, new_browser->tab_count()); 751 ASSERT_EQ(3, new_browser->tab_count());
726 752
727 ASSERT_EQ(expected_process_count, RenderProcessHostCount()); 753 ASSERT_EQ(expected_process_count, RenderProcessHostCount());
728 } 754 }
729 755
756 // Test that changing the user agent override will persist it to disk.
757 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, PersistAndRestoreUserAgentOverride) {
758 // Create a tab with an overridden user agent.
759 ui_test_utils::NavigateToURL(browser(), url1_);
760 ASSERT_EQ(0, browser()->active_index());
761 chrome::GetWebContentsAt(browser(), 0)->SetUserAgentOverride("override");
762
763 // Create a tab without an overridden user agent.
764 ui_test_utils::NavigateToURLWithDisposition(
765 browser(), url2_, NEW_FOREGROUND_TAB,
766 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
767 ASSERT_EQ(1, browser()->active_index());
768
769 // Kill the original browser then open a new one to trigger a restore.
770 Browser* new_browser = QuitBrowserAndRestore(browser(), 1);
771 ASSERT_EQ(1u, BrowserList::size());
772 ASSERT_EQ(2, new_browser->tab_count());
773 ASSERT_EQ(1, new_browser->active_index());
774
775 // Confirm that the user agent overrides are properly set.
776 EXPECT_EQ("override",
777 chrome::GetWebContentsAt(new_browser, 0)->GetUserAgentOverride());
778 EXPECT_EQ("",
779 chrome::GetWebContentsAt(new_browser, 1)->GetUserAgentOverride());
780 }
781
730 // Regression test for crbug.com/125958. When restoring a pinned selected tab in 782 // 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 783 // 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 784 // wrong, leading to the wrong tab getting selected, DCHECKs firing, and the
733 // pinned tab not getting loaded. 785 // pinned tab not getting loaded.
734 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestorePinnedSelectedTab) { 786 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestorePinnedSelectedTab) {
735 // Create a pinned tab. 787 // Create a pinned tab.
736 ui_test_utils::NavigateToURL(browser(), url1_); 788 ui_test_utils::NavigateToURL(browser(), url1_);
737 browser()->tab_strip_model()->SetTabPinned(0, true); 789 browser()->tab_strip_model()->SetTabPinned(0, true);
738 ASSERT_EQ(0, browser()->active_index()); 790 ASSERT_EQ(0, browser()->active_index());
739 // Create a nonpinned tab. 791 // Create a nonpinned tab.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 ASSERT_EQ(1u, BrowserList::size()); 835 ASSERT_EQ(1u, BrowserList::size());
784 ASSERT_EQ(url1_, chrome::GetActiveWebContents(new_browser)->GetURL()); 836 ASSERT_EQ(url1_, chrome::GetActiveWebContents(new_browser)->GetURL());
785 content::NavigationController* new_controller = 837 content::NavigationController* new_controller =
786 &chrome::GetActiveWebContents(new_browser)->GetController(); 838 &chrome::GetActiveWebContents(new_browser)->GetController();
787 ASSERT_TRUE(new_controller->GetDefaultSessionStorageNamespace()); 839 ASSERT_TRUE(new_controller->GetDefaultSessionStorageNamespace());
788 std::string restored_session_storage_persistent_id = 840 std::string restored_session_storage_persistent_id =
789 new_controller->GetDefaultSessionStorageNamespace()->persistent_id(); 841 new_controller->GetDefaultSessionStorageNamespace()->persistent_id();
790 EXPECT_EQ(session_storage_persistent_id, 842 EXPECT_EQ(session_storage_persistent_id,
791 restored_session_storage_persistent_id); 843 restored_session_storage_persistent_id);
792 } 844 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698