| 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/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/defaults.h" | 16 #include "chrome/browser/defaults.h" |
| 17 #include "chrome/browser/sessions/session_backend.h" | 17 #include "chrome/browser/sessions/session_backend.h" |
| 18 #include "chrome/browser/sessions/session_service.h" | 18 #include "chrome/browser/sessions/session_service.h" |
| 19 #include "chrome/browser/sessions/session_service_test_helper.h" | 19 #include "chrome/browser/sessions/session_service_test_helper.h" |
| 20 #include "chrome/browser/sessions/session_types.h" | 20 #include "chrome/browser/sessions/session_types.h" |
| 21 #include "chrome/browser/sessions/session_types_test_helper.h" | |
| 22 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 24 #include "chrome/test/base/browser_with_test_window_test.h" | 23 #include "chrome/test/base/browser_with_test_window_test.h" |
| 25 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
| 25 #include "components/sessions/serialized_navigation_entry_test_helper.h" |
| 26 #include "content/public/browser/navigation_entry.h" | 26 #include "content/public/browser/navigation_entry.h" |
| 27 #include "content/public/browser/notification_observer.h" | 27 #include "content/public/browser/notification_observer.h" |
| 28 #include "content/public/browser/notification_registrar.h" | 28 #include "content/public/browser/notification_registrar.h" |
| 29 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" | 31 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" |
| 32 #include "third_party/WebKit/Source/Platform/chromium/public/WebHTTPBody.h" | 32 #include "third_party/WebKit/Source/Platform/chromium/public/WebHTTPBody.h" |
| 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" |
| 34 #include "webkit/glue/glue_serialize.h" | 34 #include "webkit/glue/glue_serialize.h" |
| 35 | 35 |
| 36 using content::NavigationEntry; | 36 using content::NavigationEntry; |
| 37 using components::SerializedNavigationEntry; |
| 38 using components::SerializedNavigationEntryTestHelper; |
| 37 | 39 |
| 38 class SessionServiceTest : public BrowserWithTestWindowTest, | 40 class SessionServiceTest : public BrowserWithTestWindowTest, |
| 39 public content::NotificationObserver { | 41 public content::NotificationObserver { |
| 40 public: | 42 public: |
| 41 SessionServiceTest() : window_bounds(0, 1, 2, 3), sync_save_count_(0) {} | 43 SessionServiceTest() : window_bounds(0, 1, 2, 3), sync_save_count_(0) {} |
| 42 | 44 |
| 43 protected: | 45 protected: |
| 44 virtual void SetUp() { | 46 virtual void SetUp() { |
| 45 BrowserWithTestWindowTest::SetUp(); | 47 BrowserWithTestWindowTest::SetUp(); |
| 46 std::string b = base::Int64ToString(base::Time::Now().ToInternalValue()); | 48 std::string b = base::Int64ToString(base::Time::Now().ToInternalValue()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 66 const content::NotificationDetails& details) OVERRIDE { | 68 const content::NotificationDetails& details) OVERRIDE { |
| 67 ASSERT_EQ(type, chrome::NOTIFICATION_SESSION_SERVICE_SAVED); | 69 ASSERT_EQ(type, chrome::NOTIFICATION_SESSION_SERVICE_SAVED); |
| 68 sync_save_count_++; | 70 sync_save_count_++; |
| 69 } | 71 } |
| 70 | 72 |
| 71 virtual void TearDown() { | 73 virtual void TearDown() { |
| 72 helper_.set_service(NULL); | 74 helper_.set_service(NULL); |
| 73 BrowserWithTestWindowTest::TearDown(); | 75 BrowserWithTestWindowTest::TearDown(); |
| 74 } | 76 } |
| 75 | 77 |
| 76 void UpdateNavigation(const SessionID& window_id, | 78 void UpdateNavigation( |
| 77 const SessionID& tab_id, | 79 const SessionID& window_id, |
| 78 const TabNavigation& navigation, | 80 const SessionID& tab_id, |
| 79 bool select) { | 81 const SerializedNavigationEntry& navigation, |
| 82 bool select) { |
| 80 service()->UpdateTabNavigation(window_id, tab_id, navigation); | 83 service()->UpdateTabNavigation(window_id, tab_id, navigation); |
| 81 if (select) { | 84 if (select) { |
| 82 service()->SetSelectedNavigationIndex( | 85 service()->SetSelectedNavigationIndex( |
| 83 window_id, tab_id, navigation.index()); | 86 window_id, tab_id, navigation.index()); |
| 84 } | 87 } |
| 85 } | 88 } |
| 86 | 89 |
| 87 void ReadWindows(std::vector<SessionWindow*>* windows, | 90 void ReadWindows(std::vector<SessionWindow*>* windows, |
| 88 SessionID::id_type* active_window_id) { | 91 SessionID::id_type* active_window_id) { |
| 89 // Forces closing the file. | 92 // Forces closing the file. |
| 90 helper_.set_service(NULL); | 93 helper_.set_service(NULL); |
| 91 | 94 |
| 92 SessionService* session_service = new SessionService(path_); | 95 SessionService* session_service = new SessionService(path_); |
| 93 helper_.set_service(session_service); | 96 helper_.set_service(session_service); |
| 94 | 97 |
| 95 SessionID::id_type* non_null_active_window_id = active_window_id; | 98 SessionID::id_type* non_null_active_window_id = active_window_id; |
| 96 SessionID::id_type dummy_active_window_id = 0; | 99 SessionID::id_type dummy_active_window_id = 0; |
| 97 if (!non_null_active_window_id) | 100 if (!non_null_active_window_id) |
| 98 non_null_active_window_id = &dummy_active_window_id; | 101 non_null_active_window_id = &dummy_active_window_id; |
| 99 helper_.ReadWindows(windows, non_null_active_window_id); | 102 helper_.ReadWindows(windows, non_null_active_window_id); |
| 100 } | 103 } |
| 101 | 104 |
| 102 // Configures the session service with one window with one tab and a single | 105 // Configures the session service with one window with one tab and a single |
| 103 // navigation. If |pinned_state| is true or |write_always| is true, the | 106 // navigation. If |pinned_state| is true or |write_always| is true, the |
| 104 // pinned state of the tab is updated. The session service is then recreated | 107 // pinned state of the tab is updated. The session service is then recreated |
| 105 // and the pinned state of the read back tab is returned. | 108 // and the pinned state of the read back tab is returned. |
| 106 bool CreateAndWriteSessionWithOneTab(bool pinned_state, bool write_always) { | 109 bool CreateAndWriteSessionWithOneTab(bool pinned_state, bool write_always) { |
| 107 SessionID tab_id; | 110 SessionID tab_id; |
| 108 TabNavigation nav1 = | 111 SerializedNavigationEntry nav1 = |
| 109 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc"); | 112 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 113 "http://google.com", "abc"); |
| 110 | 114 |
| 111 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 115 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 112 UpdateNavigation(window_id, tab_id, nav1, true); | 116 UpdateNavigation(window_id, tab_id, nav1, true); |
| 113 | 117 |
| 114 if (pinned_state || write_always) | 118 if (pinned_state || write_always) |
| 115 helper_.service()->SetPinnedState(window_id, tab_id, pinned_state); | 119 helper_.service()->SetPinnedState(window_id, tab_id, pinned_state); |
| 116 | 120 |
| 117 ScopedVector<SessionWindow> windows; | 121 ScopedVector<SessionWindow> windows; |
| 118 ReadWindows(&(windows.get()), NULL); | 122 ReadWindows(&(windows.get()), NULL); |
| 119 | 123 |
| 120 EXPECT_EQ(1U, windows.size()); | 124 EXPECT_EQ(1U, windows.size()); |
| 121 if (HasFatalFailure()) | 125 if (HasFatalFailure()) |
| 122 return false; | 126 return false; |
| 123 EXPECT_EQ(1U, windows[0]->tabs.size()); | 127 EXPECT_EQ(1U, windows[0]->tabs.size()); |
| 124 if (HasFatalFailure()) | 128 if (HasFatalFailure()) |
| 125 return false; | 129 return false; |
| 126 | 130 |
| 127 SessionTab* tab = windows[0]->tabs[0]; | 131 SessionTab* tab = windows[0]->tabs[0]; |
| 128 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); | 132 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); |
| 129 | 133 |
| 130 return tab->pinned; | 134 return tab->pinned; |
| 131 } | 135 } |
| 132 | 136 |
| 133 void CreateAndWriteSessionWithTwoWindows( | 137 void CreateAndWriteSessionWithTwoWindows( |
| 134 const SessionID& window2_id, | 138 const SessionID& window2_id, |
| 135 const SessionID& tab1_id, | 139 const SessionID& tab1_id, |
| 136 const SessionID& tab2_id, | 140 const SessionID& tab2_id, |
| 137 TabNavigation* nav1, | 141 SerializedNavigationEntry* nav1, |
| 138 TabNavigation* nav2) { | 142 SerializedNavigationEntry* nav2) { |
| 139 *nav1 = | 143 *nav1 = SerializedNavigationEntryTestHelper::CreateNavigation( |
| 140 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc"); | 144 "http://google.com", "abc"); |
| 141 *nav2 = | 145 *nav2 = SerializedNavigationEntryTestHelper::CreateNavigation( |
| 142 SessionTypesTestHelper::CreateNavigation("http://google2.com", "abcd"); | 146 "http://google2.com", "abcd"); |
| 143 | 147 |
| 144 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); | 148 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); |
| 145 UpdateNavigation(window_id, tab1_id, *nav1, true); | 149 UpdateNavigation(window_id, tab1_id, *nav1, true); |
| 146 | 150 |
| 147 const gfx::Rect window2_bounds(3, 4, 5, 6); | 151 const gfx::Rect window2_bounds(3, 4, 5, 6); |
| 148 service()->SetWindowType( | 152 service()->SetWindowType( |
| 149 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); | 153 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); |
| 150 service()->SetWindowBounds(window2_id, | 154 service()->SetWindowBounds(window2_id, |
| 151 window2_bounds, | 155 window2_bounds, |
| 152 ui::SHOW_STATE_MAXIMIZED); | 156 ui::SHOW_STATE_MAXIMIZED); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 168 base::ScopedTempDir temp_dir_; | 172 base::ScopedTempDir temp_dir_; |
| 169 base::FilePath path_; | 173 base::FilePath path_; |
| 170 | 174 |
| 171 SessionServiceTestHelper helper_; | 175 SessionServiceTestHelper helper_; |
| 172 }; | 176 }; |
| 173 | 177 |
| 174 TEST_F(SessionServiceTest, Basic) { | 178 TEST_F(SessionServiceTest, Basic) { |
| 175 SessionID tab_id; | 179 SessionID tab_id; |
| 176 ASSERT_NE(window_id.id(), tab_id.id()); | 180 ASSERT_NE(window_id.id(), tab_id.id()); |
| 177 | 181 |
| 178 TabNavigation nav1 = | 182 SerializedNavigationEntry nav1 = |
| 179 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc"); | 183 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 180 SessionTypesTestHelper::SetOriginalRequestURL( | 184 "http://google.com", "abc"); |
| 181 &nav1, GURL("http://original.request.com")); | 185 SerializedNavigationEntryTestHelper::SetOriginalRequestURL( |
| 186 GURL("http://original.request.com"), &nav1); |
| 182 | 187 |
| 183 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 188 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 184 UpdateNavigation(window_id, tab_id, nav1, true); | 189 UpdateNavigation(window_id, tab_id, nav1, true); |
| 185 | 190 |
| 186 ScopedVector<SessionWindow> windows; | 191 ScopedVector<SessionWindow> windows; |
| 187 ReadWindows(&(windows.get()), NULL); | 192 ReadWindows(&(windows.get()), NULL); |
| 188 | 193 |
| 189 ASSERT_EQ(1U, windows.size()); | 194 ASSERT_EQ(1U, windows.size()); |
| 190 ASSERT_TRUE(window_bounds == windows[0]->bounds); | 195 ASSERT_TRUE(window_bounds == windows[0]->bounds); |
| 191 ASSERT_EQ(0, windows[0]->selected_tab_index); | 196 ASSERT_EQ(0, windows[0]->selected_tab_index); |
| 192 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); | 197 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); |
| 193 ASSERT_EQ(1U, windows[0]->tabs.size()); | 198 ASSERT_EQ(1U, windows[0]->tabs.size()); |
| 194 ASSERT_EQ(Browser::TYPE_TABBED, windows[0]->type); | 199 ASSERT_EQ(Browser::TYPE_TABBED, windows[0]->type); |
| 195 | 200 |
| 196 SessionTab* tab = windows[0]->tabs[0]; | 201 SessionTab* tab = windows[0]->tabs[0]; |
| 197 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); | 202 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); |
| 198 | 203 |
| 199 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); | 204 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); |
| 200 } | 205 } |
| 201 | 206 |
| 202 // Make sure we persist post entries. | 207 // Make sure we persist post entries. |
| 203 TEST_F(SessionServiceTest, PersistPostData) { | 208 TEST_F(SessionServiceTest, PersistPostData) { |
| 204 SessionID tab_id; | 209 SessionID tab_id; |
| 205 ASSERT_NE(window_id.id(), tab_id.id()); | 210 ASSERT_NE(window_id.id(), tab_id.id()); |
| 206 | 211 |
| 207 TabNavigation nav1 = | 212 SerializedNavigationEntry nav1 = |
| 208 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc"); | 213 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 209 SessionTypesTestHelper::SetHasPostData(&nav1, true); | 214 "http://google.com", "abc"); |
| 215 SerializedNavigationEntryTestHelper::SetHasPostData(true, &nav1); |
| 210 | 216 |
| 211 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 217 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 212 UpdateNavigation(window_id, tab_id, nav1, true); | 218 UpdateNavigation(window_id, tab_id, nav1, true); |
| 213 | 219 |
| 214 ScopedVector<SessionWindow> windows; | 220 ScopedVector<SessionWindow> windows; |
| 215 ReadWindows(&(windows.get()), NULL); | 221 ReadWindows(&(windows.get()), NULL); |
| 216 | 222 |
| 217 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); | 223 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); |
| 218 } | 224 } |
| 219 | 225 |
| 220 TEST_F(SessionServiceTest, ClosingTabStaysClosed) { | 226 TEST_F(SessionServiceTest, ClosingTabStaysClosed) { |
| 221 SessionID tab_id; | 227 SessionID tab_id; |
| 222 SessionID tab2_id; | 228 SessionID tab2_id; |
| 223 ASSERT_NE(tab_id.id(), tab2_id.id()); | 229 ASSERT_NE(tab_id.id(), tab2_id.id()); |
| 224 | 230 |
| 225 TabNavigation nav1 = | 231 SerializedNavigationEntry nav1 = |
| 226 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc"); | 232 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 227 TabNavigation nav2 = | 233 "http://google.com", "abc"); |
| 228 SessionTypesTestHelper::CreateNavigation("http://google2.com", "abcd"); | 234 SerializedNavigationEntry nav2 = |
| 235 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 236 "http://google2.com", "abcd"); |
| 229 | 237 |
| 230 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 238 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 231 UpdateNavigation(window_id, tab_id, nav1, true); | 239 UpdateNavigation(window_id, tab_id, nav1, true); |
| 232 | 240 |
| 233 helper_.PrepareTabInWindow(window_id, tab2_id, 1, false); | 241 helper_.PrepareTabInWindow(window_id, tab2_id, 1, false); |
| 234 UpdateNavigation(window_id, tab2_id, nav2, true); | 242 UpdateNavigation(window_id, tab2_id, nav2, true); |
| 235 service()->TabClosed(window_id, tab2_id, false); | 243 service()->TabClosed(window_id, tab2_id, false); |
| 236 | 244 |
| 237 ScopedVector<SessionWindow> windows; | 245 ScopedVector<SessionWindow> windows; |
| 238 ReadWindows(&(windows.get()), NULL); | 246 ReadWindows(&(windows.get()), NULL); |
| 239 | 247 |
| 240 ASSERT_EQ(1U, windows.size()); | 248 ASSERT_EQ(1U, windows.size()); |
| 241 ASSERT_EQ(0, windows[0]->selected_tab_index); | 249 ASSERT_EQ(0, windows[0]->selected_tab_index); |
| 242 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); | 250 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); |
| 243 ASSERT_EQ(1U, windows[0]->tabs.size()); | 251 ASSERT_EQ(1U, windows[0]->tabs.size()); |
| 244 | 252 |
| 245 SessionTab* tab = windows[0]->tabs[0]; | 253 SessionTab* tab = windows[0]->tabs[0]; |
| 246 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); | 254 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); |
| 247 | 255 |
| 248 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); | 256 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); |
| 249 } | 257 } |
| 250 | 258 |
| 251 TEST_F(SessionServiceTest, Pruning) { | 259 TEST_F(SessionServiceTest, Pruning) { |
| 252 SessionID tab_id; | 260 SessionID tab_id; |
| 253 | 261 |
| 254 TabNavigation nav1 = | 262 SerializedNavigationEntry nav1 = |
| 255 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc"); | 263 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 256 TabNavigation nav2 = | 264 "http://google.com", "abc"); |
| 257 SessionTypesTestHelper::CreateNavigation("http://google2.com", "abcd"); | 265 SerializedNavigationEntry nav2 = |
| 266 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 267 "http://google2.com", "abcd"); |
| 258 | 268 |
| 259 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 269 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 260 for (int i = 0; i < 6; ++i) { | 270 for (int i = 0; i < 6; ++i) { |
| 261 TabNavigation* nav = (i % 2) == 0 ? &nav1 : &nav2; | 271 SerializedNavigationEntry* nav = (i % 2) == 0 ? &nav1 : &nav2; |
| 262 nav->set_index(i); | 272 nav->set_index(i); |
| 263 UpdateNavigation(window_id, tab_id, *nav, true); | 273 UpdateNavigation(window_id, tab_id, *nav, true); |
| 264 } | 274 } |
| 265 service()->TabNavigationPathPrunedFromBack(window_id, tab_id, 3); | 275 service()->TabNavigationPathPrunedFromBack(window_id, tab_id, 3); |
| 266 | 276 |
| 267 ScopedVector<SessionWindow> windows; | 277 ScopedVector<SessionWindow> windows; |
| 268 ReadWindows(&(windows.get()), NULL); | 278 ReadWindows(&(windows.get()), NULL); |
| 269 | 279 |
| 270 ASSERT_EQ(1U, windows.size()); | 280 ASSERT_EQ(1U, windows.size()); |
| 271 ASSERT_EQ(0, windows[0]->selected_tab_index); | 281 ASSERT_EQ(0, windows[0]->selected_tab_index); |
| 272 ASSERT_EQ(1U, windows[0]->tabs.size()); | 282 ASSERT_EQ(1U, windows[0]->tabs.size()); |
| 273 | 283 |
| 274 SessionTab* tab = windows[0]->tabs[0]; | 284 SessionTab* tab = windows[0]->tabs[0]; |
| 275 // We left the selected index at 5, then pruned. When rereading the | 285 // We left the selected index at 5, then pruned. When rereading the |
| 276 // index should get reset to last valid navigation, which is 2. | 286 // index should get reset to last valid navigation, which is 2. |
| 277 helper_.AssertTabEquals(window_id, tab_id, 0, 2, 3, *tab); | 287 helper_.AssertTabEquals(window_id, tab_id, 0, 2, 3, *tab); |
| 278 | 288 |
| 279 ASSERT_EQ(3u, tab->navigations.size()); | 289 ASSERT_EQ(3u, tab->navigations.size()); |
| 280 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); | 290 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); |
| 281 helper_.AssertNavigationEquals(nav2, tab->navigations[1]); | 291 helper_.AssertNavigationEquals(nav2, tab->navigations[1]); |
| 282 helper_.AssertNavigationEquals(nav1, tab->navigations[2]); | 292 helper_.AssertNavigationEquals(nav1, tab->navigations[2]); |
| 283 } | 293 } |
| 284 | 294 |
| 285 TEST_F(SessionServiceTest, TwoWindows) { | 295 TEST_F(SessionServiceTest, TwoWindows) { |
| 286 SessionID window2_id; | 296 SessionID window2_id; |
| 287 SessionID tab1_id; | 297 SessionID tab1_id; |
| 288 SessionID tab2_id; | 298 SessionID tab2_id; |
| 289 TabNavigation nav1; | 299 SerializedNavigationEntry nav1; |
| 290 TabNavigation nav2; | 300 SerializedNavigationEntry nav2; |
| 291 | 301 |
| 292 CreateAndWriteSessionWithTwoWindows( | 302 CreateAndWriteSessionWithTwoWindows( |
| 293 window2_id, tab1_id, tab2_id, &nav1, &nav2); | 303 window2_id, tab1_id, tab2_id, &nav1, &nav2); |
| 294 | 304 |
| 295 ScopedVector<SessionWindow> windows; | 305 ScopedVector<SessionWindow> windows; |
| 296 ReadWindows(&(windows.get()), NULL); | 306 ReadWindows(&(windows.get()), NULL); |
| 297 | 307 |
| 298 ASSERT_EQ(2U, windows.size()); | 308 ASSERT_EQ(2U, windows.size()); |
| 299 ASSERT_EQ(0, windows[0]->selected_tab_index); | 309 ASSERT_EQ(0, windows[0]->selected_tab_index); |
| 300 ASSERT_EQ(0, windows[1]->selected_tab_index); | 310 ASSERT_EQ(0, windows[1]->selected_tab_index); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 324 tab = rt2; | 334 tab = rt2; |
| 325 helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab); | 335 helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab); |
| 326 helper_.AssertNavigationEquals(nav2, tab->navigations[0]); | 336 helper_.AssertNavigationEquals(nav2, tab->navigations[0]); |
| 327 } | 337 } |
| 328 | 338 |
| 329 TEST_F(SessionServiceTest, WindowWithNoTabsGetsPruned) { | 339 TEST_F(SessionServiceTest, WindowWithNoTabsGetsPruned) { |
| 330 SessionID window2_id; | 340 SessionID window2_id; |
| 331 SessionID tab1_id; | 341 SessionID tab1_id; |
| 332 SessionID tab2_id; | 342 SessionID tab2_id; |
| 333 | 343 |
| 334 TabNavigation nav1 = | 344 SerializedNavigationEntry nav1 = |
| 335 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc"); | 345 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 346 "http://google.com", "abc"); |
| 336 | 347 |
| 337 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); | 348 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); |
| 338 UpdateNavigation(window_id, tab1_id, nav1, true); | 349 UpdateNavigation(window_id, tab1_id, nav1, true); |
| 339 | 350 |
| 340 const gfx::Rect window2_bounds(3, 4, 5, 6); | 351 const gfx::Rect window2_bounds(3, 4, 5, 6); |
| 341 service()->SetWindowType( | 352 service()->SetWindowType( |
| 342 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); | 353 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); |
| 343 service()->SetWindowBounds(window2_id, | 354 service()->SetWindowBounds(window2_id, |
| 344 window2_bounds, | 355 window2_bounds, |
| 345 ui::SHOW_STATE_NORMAL); | 356 ui::SHOW_STATE_NORMAL); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 356 SessionTab* tab = windows[0]->tabs[0]; | 367 SessionTab* tab = windows[0]->tabs[0]; |
| 357 helper_.AssertTabEquals(window_id, tab1_id, 0, 0, 1, *tab); | 368 helper_.AssertTabEquals(window_id, tab1_id, 0, 0, 1, *tab); |
| 358 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); | 369 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); |
| 359 } | 370 } |
| 360 | 371 |
| 361 TEST_F(SessionServiceTest, ClosingWindowDoesntCloseTabs) { | 372 TEST_F(SessionServiceTest, ClosingWindowDoesntCloseTabs) { |
| 362 SessionID tab_id; | 373 SessionID tab_id; |
| 363 SessionID tab2_id; | 374 SessionID tab2_id; |
| 364 ASSERT_NE(tab_id.id(), tab2_id.id()); | 375 ASSERT_NE(tab_id.id(), tab2_id.id()); |
| 365 | 376 |
| 366 TabNavigation nav1 = | 377 SerializedNavigationEntry nav1 = |
| 367 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc"); | 378 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 368 TabNavigation nav2 = | 379 "http://google.com", "abc"); |
| 369 SessionTypesTestHelper::CreateNavigation("http://google2.com", "abcd"); | 380 SerializedNavigationEntry nav2 = |
| 381 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 382 "http://google2.com", "abcd"); |
| 370 | 383 |
| 371 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 384 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 372 UpdateNavigation(window_id, tab_id, nav1, true); | 385 UpdateNavigation(window_id, tab_id, nav1, true); |
| 373 | 386 |
| 374 helper_.PrepareTabInWindow(window_id, tab2_id, 1, false); | 387 helper_.PrepareTabInWindow(window_id, tab2_id, 1, false); |
| 375 UpdateNavigation(window_id, tab2_id, nav2, true); | 388 UpdateNavigation(window_id, tab2_id, nav2, true); |
| 376 | 389 |
| 377 service()->WindowClosing(window_id); | 390 service()->WindowClosing(window_id); |
| 378 | 391 |
| 379 ScopedVector<SessionWindow> windows; | 392 ScopedVector<SessionWindow> windows; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 398 SessionID tab_id; | 411 SessionID tab_id; |
| 399 SessionID tab2_id; | 412 SessionID tab2_id; |
| 400 ASSERT_NE(window2_id.id(), window_id.id()); | 413 ASSERT_NE(window2_id.id(), window_id.id()); |
| 401 | 414 |
| 402 service()->SetWindowType( | 415 service()->SetWindowType( |
| 403 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); | 416 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); |
| 404 service()->SetWindowBounds(window2_id, | 417 service()->SetWindowBounds(window2_id, |
| 405 window_bounds, | 418 window_bounds, |
| 406 ui::SHOW_STATE_NORMAL); | 419 ui::SHOW_STATE_NORMAL); |
| 407 | 420 |
| 408 TabNavigation nav1 = | 421 SerializedNavigationEntry nav1 = |
| 409 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc"); | 422 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 410 TabNavigation nav2 = | 423 "http://google.com", "abc"); |
| 411 SessionTypesTestHelper::CreateNavigation("http://google2.com", "abcd"); | 424 SerializedNavigationEntry nav2 = |
| 425 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 426 "http://google2.com", "abcd"); |
| 412 | 427 |
| 413 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 428 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 414 UpdateNavigation(window_id, tab_id, nav1, true); | 429 UpdateNavigation(window_id, tab_id, nav1, true); |
| 415 | 430 |
| 416 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); | 431 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); |
| 417 UpdateNavigation(window2_id, tab2_id, nav2, true); | 432 UpdateNavigation(window2_id, tab2_id, nav2, true); |
| 418 | 433 |
| 419 service()->WindowClosing(window2_id); | 434 service()->WindowClosing(window2_id); |
| 420 service()->TabClosed(window2_id, tab2_id, false); | 435 service()->TabClosed(window2_id, tab2_id, false); |
| 421 service()->WindowClosed(window2_id); | 436 service()->WindowClosed(window2_id); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 442 SessionID tab_id; | 457 SessionID tab_id; |
| 443 SessionID tab2_id; | 458 SessionID tab2_id; |
| 444 ASSERT_NE(window2_id.id(), window_id.id()); | 459 ASSERT_NE(window2_id.id(), window_id.id()); |
| 445 | 460 |
| 446 service()->SetWindowType( | 461 service()->SetWindowType( |
| 447 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_NORMAL); | 462 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_NORMAL); |
| 448 service()->SetWindowBounds(window2_id, | 463 service()->SetWindowBounds(window2_id, |
| 449 window_bounds, | 464 window_bounds, |
| 450 ui::SHOW_STATE_NORMAL); | 465 ui::SHOW_STATE_NORMAL); |
| 451 | 466 |
| 452 TabNavigation nav1 = | 467 SerializedNavigationEntry nav1 = |
| 453 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc"); | 468 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 454 TabNavigation nav2 = | 469 "http://google.com", "abc"); |
| 455 SessionTypesTestHelper::CreateNavigation("http://google2.com", "abcd"); | 470 SerializedNavigationEntry nav2 = |
| 471 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 472 "http://google2.com", "abcd"); |
| 456 | 473 |
| 457 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 474 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 458 UpdateNavigation(window_id, tab_id, nav1, true); | 475 UpdateNavigation(window_id, tab_id, nav1, true); |
| 459 | 476 |
| 460 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); | 477 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); |
| 461 UpdateNavigation(window2_id, tab2_id, nav2, true); | 478 UpdateNavigation(window2_id, tab2_id, nav2, true); |
| 462 | 479 |
| 463 ScopedVector<SessionWindow> windows; | 480 ScopedVector<SessionWindow> windows; |
| 464 ReadWindows(&(windows.get()), NULL); | 481 ReadWindows(&(windows.get()), NULL); |
| 465 | 482 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 482 SessionID tab_id; | 499 SessionID tab_id; |
| 483 SessionID tab2_id; | 500 SessionID tab2_id; |
| 484 ASSERT_NE(window2_id.id(), window_id.id()); | 501 ASSERT_NE(window2_id.id(), window_id.id()); |
| 485 | 502 |
| 486 service()->SetWindowType( | 503 service()->SetWindowType( |
| 487 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_NORMAL); | 504 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_NORMAL); |
| 488 service()->SetWindowBounds(window2_id, | 505 service()->SetWindowBounds(window2_id, |
| 489 window_bounds, | 506 window_bounds, |
| 490 ui::SHOW_STATE_NORMAL); | 507 ui::SHOW_STATE_NORMAL); |
| 491 | 508 |
| 492 TabNavigation nav1 = | 509 SerializedNavigationEntry nav1 = |
| 493 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc"); | 510 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 494 TabNavigation nav2 = | 511 "http://google.com", "abc"); |
| 495 SessionTypesTestHelper::CreateNavigation("http://google2.com", "abcd"); | 512 SerializedNavigationEntry nav2 = |
| 513 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 514 "http://google2.com", "abcd"); |
| 496 | 515 |
| 497 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 516 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 498 UpdateNavigation(window_id, tab_id, nav1, true); | 517 UpdateNavigation(window_id, tab_id, nav1, true); |
| 499 | 518 |
| 500 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); | 519 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); |
| 501 UpdateNavigation(window2_id, tab2_id, nav2, true); | 520 UpdateNavigation(window2_id, tab2_id, nav2, true); |
| 502 | 521 |
| 503 ScopedVector<SessionWindow> windows; | 522 ScopedVector<SessionWindow> windows; |
| 504 ReadWindows(&(windows.get()), NULL); | 523 ReadWindows(&(windows.get()), NULL); |
| 505 | 524 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 532 SessionID tab2_id; | 551 SessionID tab2_id; |
| 533 ASSERT_NE(window2_id.id(), window_id.id()); | 552 ASSERT_NE(window2_id.id(), window_id.id()); |
| 534 | 553 |
| 535 service()->SetWindowType( | 554 service()->SetWindowType( |
| 536 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_APP); | 555 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_APP); |
| 537 service()->SetWindowBounds(window2_id, | 556 service()->SetWindowBounds(window2_id, |
| 538 window_bounds, | 557 window_bounds, |
| 539 ui::SHOW_STATE_NORMAL); | 558 ui::SHOW_STATE_NORMAL); |
| 540 service()->SetWindowAppName(window2_id, "TestApp"); | 559 service()->SetWindowAppName(window2_id, "TestApp"); |
| 541 | 560 |
| 542 TabNavigation nav1 = | 561 SerializedNavigationEntry nav1 = |
| 543 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc"); | 562 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 544 TabNavigation nav2 = | 563 "http://google.com", "abc"); |
| 545 SessionTypesTestHelper::CreateNavigation("http://google2.com", "abcd"); | 564 SerializedNavigationEntry nav2 = |
| 565 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 566 "http://google2.com", "abcd"); |
| 546 | 567 |
| 547 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 568 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 548 UpdateNavigation(window_id, tab_id, nav1, true); | 569 UpdateNavigation(window_id, tab_id, nav1, true); |
| 549 | 570 |
| 550 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); | 571 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); |
| 551 UpdateNavigation(window2_id, tab2_id, nav2, true); | 572 UpdateNavigation(window2_id, tab2_id, nav2, true); |
| 552 | 573 |
| 553 ScopedVector<SessionWindow> windows; | 574 ScopedVector<SessionWindow> windows; |
| 554 ReadWindows(&(windows.get()), NULL); | 575 ReadWindows(&(windows.get()), NULL); |
| 555 | 576 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 579 | 600 |
| 580 // Tests pruning from the front. | 601 // Tests pruning from the front. |
| 581 TEST_F(SessionServiceTest, PruneFromFront) { | 602 TEST_F(SessionServiceTest, PruneFromFront) { |
| 582 const std::string base_url("http://google.com/"); | 603 const std::string base_url("http://google.com/"); |
| 583 SessionID tab_id; | 604 SessionID tab_id; |
| 584 | 605 |
| 585 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 606 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 586 | 607 |
| 587 // Add 5 navigations, with the 4th selected. | 608 // Add 5 navigations, with the 4th selected. |
| 588 for (int i = 0; i < 5; ++i) { | 609 for (int i = 0; i < 5; ++i) { |
| 589 TabNavigation nav = | 610 SerializedNavigationEntry nav = |
| 590 SessionTypesTestHelper::CreateNavigation( | 611 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 591 base_url + base::IntToString(i), "a"); | 612 base_url + base::IntToString(i), "a"); |
| 592 nav.set_index(i); | 613 nav.set_index(i); |
| 593 UpdateNavigation(window_id, tab_id, nav, (i == 3)); | 614 UpdateNavigation(window_id, tab_id, nav, (i == 3)); |
| 594 } | 615 } |
| 595 | 616 |
| 596 // Prune the first two navigations from the front. | 617 // Prune the first two navigations from the front. |
| 597 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 2); | 618 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 2); |
| 598 | 619 |
| 599 // Read back in. | 620 // Read back in. |
| 600 ScopedVector<SessionWindow> windows; | 621 ScopedVector<SessionWindow> windows; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 622 | 643 |
| 623 // Prunes from front so that we have no entries. | 644 // Prunes from front so that we have no entries. |
| 624 TEST_F(SessionServiceTest, PruneToEmpty) { | 645 TEST_F(SessionServiceTest, PruneToEmpty) { |
| 625 const std::string base_url("http://google.com/"); | 646 const std::string base_url("http://google.com/"); |
| 626 SessionID tab_id; | 647 SessionID tab_id; |
| 627 | 648 |
| 628 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 649 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 629 | 650 |
| 630 // Add 5 navigations, with the 4th selected. | 651 // Add 5 navigations, with the 4th selected. |
| 631 for (int i = 0; i < 5; ++i) { | 652 for (int i = 0; i < 5; ++i) { |
| 632 TabNavigation nav = | 653 SerializedNavigationEntry nav = |
| 633 SessionTypesTestHelper::CreateNavigation( | 654 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 634 base_url + base::IntToString(i), "a"); | 655 base_url + base::IntToString(i), "a"); |
| 635 nav.set_index(i); | 656 nav.set_index(i); |
| 636 UpdateNavigation(window_id, tab_id, nav, (i == 3)); | 657 UpdateNavigation(window_id, tab_id, nav, (i == 3)); |
| 637 } | 658 } |
| 638 | 659 |
| 639 // Prune the first two navigations from the front. | 660 // Prune the first two navigations from the front. |
| 640 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 5); | 661 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 5); |
| 641 | 662 |
| 642 // Read back in. | 663 // Read back in. |
| 643 ScopedVector<SessionWindow> windows; | 664 ScopedVector<SessionWindow> windows; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 660 TEST_F(SessionServiceTest, PinnedTrue) { | 681 TEST_F(SessionServiceTest, PinnedTrue) { |
| 661 EXPECT_TRUE(CreateAndWriteSessionWithOneTab(true, true)); | 682 EXPECT_TRUE(CreateAndWriteSessionWithOneTab(true, true)); |
| 662 } | 683 } |
| 663 | 684 |
| 664 // Make sure application extension ids are persisted. | 685 // Make sure application extension ids are persisted. |
| 665 TEST_F(SessionServiceTest, PersistApplicationExtensionID) { | 686 TEST_F(SessionServiceTest, PersistApplicationExtensionID) { |
| 666 SessionID tab_id; | 687 SessionID tab_id; |
| 667 ASSERT_NE(window_id.id(), tab_id.id()); | 688 ASSERT_NE(window_id.id(), tab_id.id()); |
| 668 std::string app_id("foo"); | 689 std::string app_id("foo"); |
| 669 | 690 |
| 670 TabNavigation nav1 = | 691 SerializedNavigationEntry nav1 = |
| 671 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc"); | 692 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 693 "http://google.com", "abc"); |
| 672 | 694 |
| 673 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 695 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 674 UpdateNavigation(window_id, tab_id, nav1, true); | 696 UpdateNavigation(window_id, tab_id, nav1, true); |
| 675 helper_.SetTabExtensionAppID(window_id, tab_id, app_id); | 697 helper_.SetTabExtensionAppID(window_id, tab_id, app_id); |
| 676 | 698 |
| 677 ScopedVector<SessionWindow> windows; | 699 ScopedVector<SessionWindow> windows; |
| 678 ReadWindows(&(windows.get()), NULL); | 700 ReadWindows(&(windows.get()), NULL); |
| 679 | 701 |
| 680 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); | 702 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); |
| 681 EXPECT_TRUE(app_id == windows[0]->tabs[0]->extension_app_id); | 703 EXPECT_TRUE(app_id == windows[0]->tabs[0]->extension_app_id); |
| 682 } | 704 } |
| 683 | 705 |
| 684 // Check that user agent overrides are persisted. | 706 // Check that user agent overrides are persisted. |
| 685 TEST_F(SessionServiceTest, PersistUserAgentOverrides) { | 707 TEST_F(SessionServiceTest, PersistUserAgentOverrides) { |
| 686 SessionID tab_id; | 708 SessionID tab_id; |
| 687 ASSERT_NE(window_id.id(), tab_id.id()); | 709 ASSERT_NE(window_id.id(), tab_id.id()); |
| 688 std::string user_agent_override = "Mozilla/5.0 (X11; Linux x86_64) " | 710 std::string user_agent_override = "Mozilla/5.0 (X11; Linux x86_64) " |
| 689 "AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.45 " | 711 "AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.45 " |
| 690 "Safari/535.19"; | 712 "Safari/535.19"; |
| 691 | 713 |
| 692 TabNavigation nav1 = | 714 SerializedNavigationEntry nav1 = |
| 693 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc"); | 715 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 694 SessionTypesTestHelper::SetIsOverridingUserAgent(&nav1, true); | 716 "http://google.com", "abc"); |
| 717 SerializedNavigationEntryTestHelper::SetIsOverridingUserAgent(true, &nav1); |
| 695 | 718 |
| 696 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 719 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 697 UpdateNavigation(window_id, tab_id, nav1, true); | 720 UpdateNavigation(window_id, tab_id, nav1, true); |
| 698 helper_.SetTabUserAgentOverride(window_id, tab_id, user_agent_override); | 721 helper_.SetTabUserAgentOverride(window_id, tab_id, user_agent_override); |
| 699 | 722 |
| 700 ScopedVector<SessionWindow> windows; | 723 ScopedVector<SessionWindow> windows; |
| 701 ReadWindows(&(windows.get()), NULL); | 724 ReadWindows(&(windows.get()), NULL); |
| 702 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); | 725 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); |
| 703 | 726 |
| 704 SessionTab* tab = windows[0]->tabs[0]; | 727 SessionTab* tab = windows[0]->tabs[0]; |
| 705 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); | 728 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); |
| 706 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); | 729 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); |
| 707 EXPECT_TRUE(user_agent_override == tab->user_agent_override); | 730 EXPECT_TRUE(user_agent_override == tab->user_agent_override); |
| 708 } | 731 } |
| 709 | 732 |
| 710 // Test that the notification for SESSION_SERVICE_SAVED is working properly. | 733 // Test that the notification for SESSION_SERVICE_SAVED is working properly. |
| 711 TEST_F(SessionServiceTest, SavedSessionNotification) { | 734 TEST_F(SessionServiceTest, SavedSessionNotification) { |
| 712 content::NotificationRegistrar registrar_; | 735 content::NotificationRegistrar registrar_; |
| 713 registrar_.Add(this, chrome::NOTIFICATION_SESSION_SERVICE_SAVED, | 736 registrar_.Add(this, chrome::NOTIFICATION_SESSION_SERVICE_SAVED, |
| 714 content::NotificationService::AllSources()); | 737 content::NotificationService::AllSources()); |
| 715 service()->Save(); | 738 service()->Save(); |
| 716 EXPECT_EQ(sync_save_count_, 1); | 739 EXPECT_EQ(sync_save_count_, 1); |
| 717 } | 740 } |
| 718 | 741 |
| 719 // Makes sure a tab closed by a user gesture is not restored. | 742 // Makes sure a tab closed by a user gesture is not restored. |
| 720 TEST_F(SessionServiceTest, CloseTabUserGesture) { | 743 TEST_F(SessionServiceTest, CloseTabUserGesture) { |
| 721 SessionID tab_id; | 744 SessionID tab_id; |
| 722 ASSERT_NE(window_id.id(), tab_id.id()); | 745 ASSERT_NE(window_id.id(), tab_id.id()); |
| 723 | 746 |
| 724 TabNavigation nav1 = | 747 SerializedNavigationEntry nav1 = |
| 725 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc"); | 748 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 749 "http://google.com", "abc"); |
| 726 | 750 |
| 727 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 751 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 728 UpdateNavigation(window_id, tab_id, nav1, true); | 752 UpdateNavigation(window_id, tab_id, nav1, true); |
| 729 service()->TabClosed(window_id, tab_id, true); | 753 service()->TabClosed(window_id, tab_id, true); |
| 730 | 754 |
| 731 ScopedVector<SessionWindow> windows; | 755 ScopedVector<SessionWindow> windows; |
| 732 ReadWindows(&(windows.get()), NULL); | 756 ReadWindows(&(windows.get()), NULL); |
| 733 | 757 |
| 734 ASSERT_TRUE(windows.empty()); | 758 ASSERT_TRUE(windows.empty()); |
| 735 } | 759 } |
| 736 | 760 |
| 737 // Verifies SetWindowBounds maps SHOW_STATE_DEFAULT to SHOW_STATE_NORMAL. | 761 // Verifies SetWindowBounds maps SHOW_STATE_DEFAULT to SHOW_STATE_NORMAL. |
| 738 TEST_F(SessionServiceTest, DontPersistDefault) { | 762 TEST_F(SessionServiceTest, DontPersistDefault) { |
| 739 SessionID tab_id; | 763 SessionID tab_id; |
| 740 ASSERT_NE(window_id.id(), tab_id.id()); | 764 ASSERT_NE(window_id.id(), tab_id.id()); |
| 741 TabNavigation nav1 = | 765 SerializedNavigationEntry nav1 = |
| 742 SessionTypesTestHelper::CreateNavigation("http://google.com", "abc"); | 766 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 767 "http://google.com", "abc"); |
| 743 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 768 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 744 UpdateNavigation(window_id, tab_id, nav1, true); | 769 UpdateNavigation(window_id, tab_id, nav1, true); |
| 745 service()->SetWindowBounds(window_id, | 770 service()->SetWindowBounds(window_id, |
| 746 window_bounds, | 771 window_bounds, |
| 747 ui::SHOW_STATE_DEFAULT); | 772 ui::SHOW_STATE_DEFAULT); |
| 748 | 773 |
| 749 ScopedVector<SessionWindow> windows; | 774 ScopedVector<SessionWindow> windows; |
| 750 ReadWindows(&(windows.get()), NULL); | 775 ReadWindows(&(windows.get()), NULL); |
| 751 ASSERT_EQ(1U, windows.size()); | 776 ASSERT_EQ(1U, windows.size()); |
| 752 EXPECT_EQ(ui::SHOW_STATE_NORMAL, windows[0]->show_state); | 777 EXPECT_EQ(ui::SHOW_STATE_NORMAL, windows[0]->show_state); |
| 753 } | 778 } |
| 754 | 779 |
| 755 TEST_F(SessionServiceTest, KeepPostDataWithoutPasswords) { | 780 TEST_F(SessionServiceTest, KeepPostDataWithoutPasswords) { |
| 756 SessionID tab_id; | 781 SessionID tab_id; |
| 757 ASSERT_NE(window_id.id(), tab_id.id()); | 782 ASSERT_NE(window_id.id(), tab_id.id()); |
| 758 | 783 |
| 759 // Create a content state representing a HTTP body without posted passwords. | 784 // Create a content state representing a HTTP body without posted passwords. |
| 760 WebKit::WebHTTPBody http_body; | 785 WebKit::WebHTTPBody http_body; |
| 761 http_body.initialize(); | 786 http_body.initialize(); |
| 762 const char char_data[] = "data"; | 787 const char char_data[] = "data"; |
| 763 http_body.appendData(WebKit::WebData(char_data, sizeof(char_data)-1)); | 788 http_body.appendData(WebKit::WebData(char_data, sizeof(char_data)-1)); |
| 764 WebKit::WebHistoryItem history_item; | 789 WebKit::WebHistoryItem history_item; |
| 765 history_item.initialize(); | 790 history_item.initialize(); |
| 766 history_item.setHTTPBody(http_body); | 791 history_item.setHTTPBody(http_body); |
| 767 std::string content_state = webkit_glue::HistoryItemToString(history_item); | 792 std::string content_state = webkit_glue::HistoryItemToString(history_item); |
| 768 | 793 |
| 769 // Create a TabNavigation containing content_state and representing a POST | 794 // Create a TabNavigation containing content_state and representing a POST |
| 770 // request. | 795 // request. |
| 771 TabNavigation nav1 = | 796 SerializedNavigationEntry nav1 = |
| 772 SessionTypesTestHelper::CreateNavigation("http://google.com", "title"); | 797 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 773 SessionTypesTestHelper::SetContentState(&nav1, content_state); | 798 "http://google.com", "title"); |
| 774 SessionTypesTestHelper::SetHasPostData(&nav1, true); | 799 SerializedNavigationEntryTestHelper::SetContentState(content_state, &nav1); |
| 800 SerializedNavigationEntryTestHelper::SetHasPostData(true, &nav1); |
| 775 | 801 |
| 776 // Create a TabNavigation containing content_state and representing a normal | 802 // Create a TabNavigation containing content_state and representing a normal |
| 777 // request. | 803 // request. |
| 778 TabNavigation nav2 = | 804 SerializedNavigationEntry nav2 = |
| 779 SessionTypesTestHelper::CreateNavigation( | 805 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 780 "http://google.com/nopost", "title"); | 806 "http://google.com/nopost", "title"); |
| 781 SessionTypesTestHelper::SetContentState(&nav2, content_state); | 807 SerializedNavigationEntryTestHelper::SetContentState(content_state, &nav2); |
| 782 nav2.set_index(1); | 808 nav2.set_index(1); |
| 783 | 809 |
| 784 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 810 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 785 UpdateNavigation(window_id, tab_id, nav1, true); | 811 UpdateNavigation(window_id, tab_id, nav1, true); |
| 786 UpdateNavigation(window_id, tab_id, nav2, true); | 812 UpdateNavigation(window_id, tab_id, nav2, true); |
| 787 | 813 |
| 788 ScopedVector<SessionWindow> windows; | 814 ScopedVector<SessionWindow> windows; |
| 789 ReadWindows(&(windows.get()), NULL); | 815 ReadWindows(&(windows.get()), NULL); |
| 790 | 816 |
| 791 helper_.AssertSingleWindowWithSingleTab(windows.get(), 2); | 817 helper_.AssertSingleWindowWithSingleTab(windows.get(), 2); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 806 const char char_data[] = "data"; | 832 const char char_data[] = "data"; |
| 807 http_body.appendData(WebKit::WebData(char_data, sizeof(char_data)-1)); | 833 http_body.appendData(WebKit::WebData(char_data, sizeof(char_data)-1)); |
| 808 http_body.setContainsPasswordData(true); | 834 http_body.setContainsPasswordData(true); |
| 809 WebKit::WebHistoryItem history_item; | 835 WebKit::WebHistoryItem history_item; |
| 810 history_item.initialize(); | 836 history_item.initialize(); |
| 811 history_item.setHTTPBody(http_body); | 837 history_item.setHTTPBody(http_body); |
| 812 std::string content_state = webkit_glue::HistoryItemToString(history_item); | 838 std::string content_state = webkit_glue::HistoryItemToString(history_item); |
| 813 | 839 |
| 814 // Create a TabNavigation containing content_state and representing a POST | 840 // Create a TabNavigation containing content_state and representing a POST |
| 815 // request with passwords. | 841 // request with passwords. |
| 816 TabNavigation nav1 = | 842 SerializedNavigationEntry nav1 = |
| 817 SessionTypesTestHelper::CreateNavigation("http://google.com", "title"); | 843 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 818 SessionTypesTestHelper::SetContentState(&nav1, content_state); | 844 "http://google.com", "title"); |
| 819 SessionTypesTestHelper::SetHasPostData(&nav1, true); | 845 SerializedNavigationEntryTestHelper::SetContentState(content_state, &nav1); |
| 846 SerializedNavigationEntryTestHelper::SetHasPostData(true, &nav1); |
| 820 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 847 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 821 UpdateNavigation(window_id, tab_id, nav1, true); | 848 UpdateNavigation(window_id, tab_id, nav1, true); |
| 822 | 849 |
| 823 ScopedVector<SessionWindow> windows; | 850 ScopedVector<SessionWindow> windows; |
| 824 ReadWindows(&(windows.get()), NULL); | 851 ReadWindows(&(windows.get()), NULL); |
| 825 | 852 |
| 826 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); | 853 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); |
| 827 | 854 |
| 828 // Expected: the HTTP body was removed from the content state of the POST | 855 // Expected: the HTTP body was removed from the content state of the POST |
| 829 // navigation with passwords. | 856 // navigation with passwords. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 860 #endif // defined(OS_CHROMEOS) | 887 #endif // defined(OS_CHROMEOS) |
| 861 | 888 |
| 862 TEST_F(SessionServiceTest, ReplacePendingNavigation) { | 889 TEST_F(SessionServiceTest, ReplacePendingNavigation) { |
| 863 const std::string base_url("http://google.com/"); | 890 const std::string base_url("http://google.com/"); |
| 864 SessionID tab_id; | 891 SessionID tab_id; |
| 865 | 892 |
| 866 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 893 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 867 | 894 |
| 868 // Add 5 navigations, some with the same index | 895 // Add 5 navigations, some with the same index |
| 869 for (int i = 0; i < 5; ++i) { | 896 for (int i = 0; i < 5; ++i) { |
| 870 TabNavigation nav = | 897 SerializedNavigationEntry nav = |
| 871 SessionTypesTestHelper::CreateNavigation( | 898 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 872 base_url + base::IntToString(i), "a"); | 899 base_url + base::IntToString(i), "a"); |
| 873 nav.set_index(i / 2); | 900 nav.set_index(i / 2); |
| 874 UpdateNavigation(window_id, tab_id, nav, true); | 901 UpdateNavigation(window_id, tab_id, nav, true); |
| 875 } | 902 } |
| 876 | 903 |
| 877 // Read back in. | 904 // Read back in. |
| 878 ScopedVector<SessionWindow> windows; | 905 ScopedVector<SessionWindow> windows; |
| 879 ReadWindows(&(windows.get()), NULL); | 906 ReadWindows(&(windows.get()), NULL); |
| 880 | 907 |
| 881 // The ones with index 0, and 2 should have been replaced by 1 and 3. | 908 // The ones with index 0, and 2 should have been replaced by 1 and 3. |
| 882 ASSERT_EQ(1U, windows.size()); | 909 ASSERT_EQ(1U, windows.size()); |
| 883 ASSERT_EQ(1U, windows[0]->tabs.size()); | 910 ASSERT_EQ(1U, windows[0]->tabs.size()); |
| 884 EXPECT_EQ(3U, windows[0]->tabs[0]->navigations.size()); | 911 EXPECT_EQ(3U, windows[0]->tabs[0]->navigations.size()); |
| 885 EXPECT_EQ(GURL(base_url + base::IntToString(1)), | 912 EXPECT_EQ(GURL(base_url + base::IntToString(1)), |
| 886 windows[0]->tabs[0]->navigations[0].virtual_url()); | 913 windows[0]->tabs[0]->navigations[0].virtual_url()); |
| 887 EXPECT_EQ(GURL(base_url + base::IntToString(3)), | 914 EXPECT_EQ(GURL(base_url + base::IntToString(3)), |
| 888 windows[0]->tabs[0]->navigations[1].virtual_url()); | 915 windows[0]->tabs[0]->navigations[1].virtual_url()); |
| 889 EXPECT_EQ(GURL(base_url + base::IntToString(4)), | 916 EXPECT_EQ(GURL(base_url + base::IntToString(4)), |
| 890 windows[0]->tabs[0]->navigations[2].virtual_url()); | 917 windows[0]->tabs[0]->navigations[2].virtual_url()); |
| 891 } | 918 } |
| 892 | 919 |
| 893 TEST_F(SessionServiceTest, ReplacePendingNavigationAndPrune) { | 920 TEST_F(SessionServiceTest, ReplacePendingNavigationAndPrune) { |
| 894 const std::string base_url("http://google.com/"); | 921 const std::string base_url("http://google.com/"); |
| 895 SessionID tab_id; | 922 SessionID tab_id; |
| 896 | 923 |
| 897 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 924 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 898 | 925 |
| 899 for (int i = 0; i < 5; ++i) { | 926 for (int i = 0; i < 5; ++i) { |
| 900 TabNavigation nav = | 927 SerializedNavigationEntry nav = |
| 901 SessionTypesTestHelper::CreateNavigation( | 928 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 902 base_url + base::IntToString(i), "a"); | 929 base_url + base::IntToString(i), "a"); |
| 903 nav.set_index(i); | 930 nav.set_index(i); |
| 904 UpdateNavigation(window_id, tab_id, nav, true); | 931 UpdateNavigation(window_id, tab_id, nav, true); |
| 905 } | 932 } |
| 906 | 933 |
| 907 // Prune all those navigations. | 934 // Prune all those navigations. |
| 908 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 5); | 935 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 5); |
| 909 | 936 |
| 910 // Add another navigation to replace the last one. | 937 // Add another navigation to replace the last one. |
| 911 TabNavigation nav = | 938 SerializedNavigationEntry nav = |
| 912 SessionTypesTestHelper::CreateNavigation( | 939 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 913 base_url + base::IntToString(5), "a"); | 940 base_url + base::IntToString(5), "a"); |
| 914 nav.set_index(4); | 941 nav.set_index(4); |
| 915 UpdateNavigation(window_id, tab_id, nav, true); | 942 UpdateNavigation(window_id, tab_id, nav, true); |
| 916 | 943 |
| 917 // Read back in. | 944 // Read back in. |
| 918 ScopedVector<SessionWindow> windows; | 945 ScopedVector<SessionWindow> windows; |
| 919 ReadWindows(&(windows.get()), NULL); | 946 ReadWindows(&(windows.get()), NULL); |
| 920 | 947 |
| 921 // We should still have that last navigation at the end, | 948 // We should still have that last navigation at the end, |
| 922 // even though it replaced one that was set before the prune. | 949 // even though it replaced one that was set before the prune. |
| 923 ASSERT_EQ(1U, windows.size()); | 950 ASSERT_EQ(1U, windows.size()); |
| 924 ASSERT_EQ(1U, windows[0]->tabs.size()); | 951 ASSERT_EQ(1U, windows[0]->tabs.size()); |
| 925 ASSERT_EQ(1U, windows[0]->tabs[0]->navigations.size()); | 952 ASSERT_EQ(1U, windows[0]->tabs[0]->navigations.size()); |
| 926 EXPECT_EQ(GURL(base_url + base::IntToString(5)), | 953 EXPECT_EQ(GURL(base_url + base::IntToString(5)), |
| 927 windows[0]->tabs[0]->navigations[0].virtual_url()); | 954 windows[0]->tabs[0]->navigations[0].virtual_url()); |
| 928 } | 955 } |
| 929 | 956 |
| 930 TEST_F(SessionServiceTest, RestoreActivation1) { | 957 TEST_F(SessionServiceTest, RestoreActivation1) { |
| 931 SessionID window2_id; | 958 SessionID window2_id; |
| 932 SessionID tab1_id; | 959 SessionID tab1_id; |
| 933 SessionID tab2_id; | 960 SessionID tab2_id; |
| 934 TabNavigation nav1; | 961 SerializedNavigationEntry nav1; |
| 935 TabNavigation nav2; | 962 SerializedNavigationEntry nav2; |
| 936 | 963 |
| 937 CreateAndWriteSessionWithTwoWindows( | 964 CreateAndWriteSessionWithTwoWindows( |
| 938 window2_id, tab1_id, tab2_id, &nav1, &nav2); | 965 window2_id, tab1_id, tab2_id, &nav1, &nav2); |
| 939 | 966 |
| 940 service()->ScheduleCommand( | 967 service()->ScheduleCommand( |
| 941 service()->CreateSetActiveWindowCommand(window2_id)); | 968 service()->CreateSetActiveWindowCommand(window2_id)); |
| 942 service()->ScheduleCommand( | 969 service()->ScheduleCommand( |
| 943 service()->CreateSetActiveWindowCommand(window_id)); | 970 service()->CreateSetActiveWindowCommand(window_id)); |
| 944 | 971 |
| 945 ScopedVector<SessionWindow> windows; | 972 ScopedVector<SessionWindow> windows; |
| 946 SessionID::id_type active_window_id = 0; | 973 SessionID::id_type active_window_id = 0; |
| 947 ReadWindows(&(windows.get()), &active_window_id); | 974 ReadWindows(&(windows.get()), &active_window_id); |
| 948 EXPECT_EQ(window_id.id(), active_window_id); | 975 EXPECT_EQ(window_id.id(), active_window_id); |
| 949 } | 976 } |
| 950 | 977 |
| 951 // It's easier to have two separate tests with setup/teardown than to manualy | 978 // It's easier to have two separate tests with setup/teardown than to manualy |
| 952 // reset the state for the different flavors of the test. | 979 // reset the state for the different flavors of the test. |
| 953 TEST_F(SessionServiceTest, RestoreActivation2) { | 980 TEST_F(SessionServiceTest, RestoreActivation2) { |
| 954 SessionID window2_id; | 981 SessionID window2_id; |
| 955 SessionID tab1_id; | 982 SessionID tab1_id; |
| 956 SessionID tab2_id; | 983 SessionID tab2_id; |
| 957 TabNavigation nav1; | 984 SerializedNavigationEntry nav1; |
| 958 TabNavigation nav2; | 985 SerializedNavigationEntry nav2; |
| 959 | 986 |
| 960 CreateAndWriteSessionWithTwoWindows( | 987 CreateAndWriteSessionWithTwoWindows( |
| 961 window2_id, tab1_id, tab2_id, &nav1, &nav2); | 988 window2_id, tab1_id, tab2_id, &nav1, &nav2); |
| 962 | 989 |
| 963 service()->ScheduleCommand( | 990 service()->ScheduleCommand( |
| 964 service()->CreateSetActiveWindowCommand(window2_id)); | 991 service()->CreateSetActiveWindowCommand(window2_id)); |
| 965 service()->ScheduleCommand( | 992 service()->ScheduleCommand( |
| 966 service()->CreateSetActiveWindowCommand(window_id)); | 993 service()->CreateSetActiveWindowCommand(window_id)); |
| 967 service()->ScheduleCommand( | 994 service()->ScheduleCommand( |
| 968 service()->CreateSetActiveWindowCommand(window2_id)); | 995 service()->CreateSetActiveWindowCommand(window2_id)); |
| 969 | 996 |
| 970 ScopedVector<SessionWindow> windows; | 997 ScopedVector<SessionWindow> windows; |
| 971 SessionID::id_type active_window_id = 0; | 998 SessionID::id_type active_window_id = 0; |
| 972 ReadWindows(&(windows.get()), &active_window_id); | 999 ReadWindows(&(windows.get()), &active_window_id); |
| 973 EXPECT_EQ(window2_id.id(), active_window_id); | 1000 EXPECT_EQ(window2_id.id(), active_window_id); |
| 974 } | 1001 } |
| OLD | NEW |