OLD | NEW |
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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 bool select) { | 78 bool select) { |
79 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); | 79 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); |
80 entry->SetURL(navigation.virtual_url()); | 80 entry->SetURL(navigation.virtual_url()); |
81 entry->SetReferrer(navigation.referrer()); | 81 entry->SetReferrer(navigation.referrer()); |
82 entry->SetTitle(navigation.title()); | 82 entry->SetTitle(navigation.title()); |
83 entry->SetContentState(navigation.state()); | 83 entry->SetContentState(navigation.state()); |
84 entry->SetTransitionType(navigation.transition()); | 84 entry->SetTransitionType(navigation.transition()); |
85 entry->SetHasPostData( | 85 entry->SetHasPostData( |
86 navigation.type_mask() & TabNavigation::HAS_POST_DATA); | 86 navigation.type_mask() & TabNavigation::HAS_POST_DATA); |
87 entry->SetOriginalRequestURL(navigation.original_request_url()); | 87 entry->SetOriginalRequestURL(navigation.original_request_url()); |
| 88 entry->SetIsOverridingUserAgent(navigation.is_overriding_user_agent()); |
88 service()->UpdateTabNavigation(window_id, tab_id, index, *entry.get()); | 89 service()->UpdateTabNavigation(window_id, tab_id, index, *entry.get()); |
89 if (select) | 90 if (select) |
90 service()->SetSelectedNavigationIndex(window_id, tab_id, index); | 91 service()->SetSelectedNavigationIndex(window_id, tab_id, index); |
91 } | 92 } |
92 | 93 |
93 void ReadWindows(std::vector<SessionWindow*>* windows) { | 94 void ReadWindows(std::vector<SessionWindow*>* windows) { |
94 // Forces closing the file. | 95 // Forces closing the file. |
95 helper_.set_service(NULL); | 96 helper_.set_service(NULL); |
96 | 97 |
97 SessionService* session_service = new SessionService(path_); | 98 SessionService* session_service = new SessionService(path_); |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 // Don't set the pinned state and make sure the pinned value is false. | 659 // Don't set the pinned state and make sure the pinned value is false. |
659 TEST_F(SessionServiceTest, PinnedDefaultsToFalse) { | 660 TEST_F(SessionServiceTest, PinnedDefaultsToFalse) { |
660 EXPECT_FALSE(CreateAndWriteSessionWithOneTab(false, false)); | 661 EXPECT_FALSE(CreateAndWriteSessionWithOneTab(false, false)); |
661 } | 662 } |
662 | 663 |
663 // Explicitly set the pinned state to false and make sure we get back false. | 664 // Explicitly set the pinned state to false and make sure we get back false. |
664 TEST_F(SessionServiceTest, PinnedFalseWhenSetToFalse) { | 665 TEST_F(SessionServiceTest, PinnedFalseWhenSetToFalse) { |
665 EXPECT_FALSE(CreateAndWriteSessionWithOneTab(false, true)); | 666 EXPECT_FALSE(CreateAndWriteSessionWithOneTab(false, true)); |
666 } | 667 } |
667 | 668 |
| 669 // Explicitly set the pinned state to true and make sure we get back true. |
| 670 TEST_F(SessionServiceTest, PinnedTrue) { |
| 671 EXPECT_TRUE(CreateAndWriteSessionWithOneTab(true, true)); |
| 672 } |
| 673 |
668 // Make sure application extension ids are persisted. | 674 // Make sure application extension ids are persisted. |
669 TEST_F(SessionServiceTest, PersistApplicationExtensionID) { | 675 TEST_F(SessionServiceTest, PersistApplicationExtensionID) { |
670 SessionID tab_id; | 676 SessionID tab_id; |
671 ASSERT_NE(window_id.id(), tab_id.id()); | 677 ASSERT_NE(window_id.id(), tab_id.id()); |
672 std::string app_id("foo"); | 678 std::string app_id("foo"); |
673 | 679 |
674 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), | 680 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), |
675 ASCIIToUTF16("abc"), std::string(), | 681 ASCIIToUTF16("abc"), std::string(), |
676 content::PAGE_TRANSITION_QUALIFIER_MASK); | 682 content::PAGE_TRANSITION_QUALIFIER_MASK); |
677 | 683 |
678 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 684 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
679 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 685 UpdateNavigation(window_id, tab_id, nav1, 0, true); |
680 helper_.SetTabExtensionAppID(window_id, tab_id, app_id); | 686 helper_.SetTabExtensionAppID(window_id, tab_id, app_id); |
681 | 687 |
682 ScopedVector<SessionWindow> windows; | 688 ScopedVector<SessionWindow> windows; |
683 ReadWindows(&(windows.get())); | 689 ReadWindows(&(windows.get())); |
684 | 690 |
685 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); | 691 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); |
686 EXPECT_TRUE(app_id == windows[0]->tabs[0]->extension_app_id); | 692 EXPECT_TRUE(app_id == windows[0]->tabs[0]->extension_app_id); |
687 } | 693 } |
688 | 694 |
689 // Explicitly set the pinned state to true and make sure we get back true. | 695 // Check that user agent overrides are persisted. |
690 TEST_F(SessionServiceTest, PinnedTrue) { | 696 TEST_F(SessionServiceTest, PersistUserAgentOverrides) { |
691 EXPECT_TRUE(CreateAndWriteSessionWithOneTab(true, true)); | 697 SessionID tab_id; |
| 698 ASSERT_NE(window_id.id(), tab_id.id()); |
| 699 std::string user_agent_override("overridden user agent"); |
| 700 |
| 701 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), |
| 702 ASCIIToUTF16("abc"), std::string(), |
| 703 content::PAGE_TRANSITION_QUALIFIER_MASK); |
| 704 nav1.set_is_overriding_user_agent(true); |
| 705 |
| 706 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 707 UpdateNavigation(window_id, tab_id, nav1, 0, true); |
| 708 helper_.SetTabUserAgentOverride(window_id, tab_id, user_agent_override); |
| 709 |
| 710 ScopedVector<SessionWindow> windows; |
| 711 ReadWindows(&(windows.get())); |
| 712 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); |
| 713 |
| 714 SessionTab* tab = windows[0]->tabs[0]; |
| 715 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); |
| 716 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); |
| 717 EXPECT_TRUE(user_agent_override == tab->user_agent_override); |
692 } | 718 } |
693 | 719 |
694 // Test that the notification for SESSION_SERVICE_SAVED is working properly. | 720 // Test that the notification for SESSION_SERVICE_SAVED is working properly. |
695 TEST_F(SessionServiceTest, SavedSessionNotification) { | 721 TEST_F(SessionServiceTest, SavedSessionNotification) { |
696 content::NotificationRegistrar registrar_; | 722 content::NotificationRegistrar registrar_; |
697 registrar_.Add(this, chrome::NOTIFICATION_SESSION_SERVICE_SAVED, | 723 registrar_.Add(this, chrome::NOTIFICATION_SESSION_SERVICE_SAVED, |
698 content::NotificationService::AllSources()); | 724 content::NotificationService::AllSources()); |
699 service()->Save(); | 725 service()->Save(); |
700 EXPECT_EQ(sync_save_count_, 1); | 726 EXPECT_EQ(sync_save_count_, 1); |
701 } | 727 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 ASSERT_TRUE(file_util::CopyFile(v1_file_path, dest_file_path)); | 902 ASSERT_TRUE(file_util::CopyFile(v1_file_path, dest_file_path)); |
877 | 903 |
878 SessionService* session_service = new SessionService(path_); | 904 SessionService* session_service = new SessionService(path_); |
879 helper_.set_service(session_service); | 905 helper_.set_service(session_service); |
880 ScopedVector<SessionWindow> windows; | 906 ScopedVector<SessionWindow> windows; |
881 helper_.ReadWindows(&(windows.get())); | 907 helper_.ReadWindows(&(windows.get())); |
882 ASSERT_EQ(1u, windows.size()); | 908 ASSERT_EQ(1u, windows.size()); |
883 EXPECT_EQ(1u, windows[0]->tabs.size()); | 909 EXPECT_EQ(1u, windows[0]->tabs.size()); |
884 } | 910 } |
885 #endif | 911 #endif |
OLD | NEW |