| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 } | 68 } |
| 69 | 69 |
| 70 virtual void TearDown() { | 70 virtual void TearDown() { |
| 71 helper_.set_service(NULL); | 71 helper_.set_service(NULL); |
| 72 BrowserWithTestWindowTest::TearDown(); | 72 BrowserWithTestWindowTest::TearDown(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void UpdateNavigation(const SessionID& window_id, | 75 void UpdateNavigation(const SessionID& window_id, |
| 76 const SessionID& tab_id, | 76 const SessionID& tab_id, |
| 77 const TabNavigation& navigation, | 77 const TabNavigation& navigation, |
| 78 int index, | |
| 79 bool select) { | 78 bool select) { |
| 80 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); | 79 service()->UpdateTabNavigation(window_id, tab_id, navigation); |
| 81 entry->SetURL(navigation.virtual_url()); | 80 if (select) { |
| 82 entry->SetReferrer(navigation.referrer()); | 81 service()->SetSelectedNavigationIndex( |
| 83 entry->SetTitle(navigation.title()); | 82 window_id, tab_id, navigation.index()); |
| 84 entry->SetContentState(navigation.state()); | 83 } |
| 85 entry->SetTransitionType(navigation.transition()); | |
| 86 entry->SetHasPostData( | |
| 87 navigation.type_mask() & TabNavigation::HAS_POST_DATA); | |
| 88 entry->SetOriginalRequestURL(navigation.original_request_url()); | |
| 89 entry->SetIsOverridingUserAgent(navigation.is_overriding_user_agent()); | |
| 90 service()->UpdateTabNavigation(window_id, tab_id, index, *entry.get()); | |
| 91 if (select) | |
| 92 service()->SetSelectedNavigationIndex(window_id, tab_id, index); | |
| 93 } | 84 } |
| 94 | 85 |
| 95 void ReadWindows(std::vector<SessionWindow*>* windows) { | 86 void ReadWindows(std::vector<SessionWindow*>* windows) { |
| 96 // Forces closing the file. | 87 // Forces closing the file. |
| 97 helper_.set_service(NULL); | 88 helper_.set_service(NULL); |
| 98 | 89 |
| 99 SessionService* session_service = new SessionService(path_); | 90 SessionService* session_service = new SessionService(path_); |
| 100 helper_.set_service(session_service); | 91 helper_.set_service(session_service); |
| 101 helper_.ReadWindows(windows); | 92 helper_.ReadWindows(windows); |
| 102 } | 93 } |
| 103 | 94 |
| 104 // Configures the session service with one window with one tab and a single | 95 // Configures the session service with one window with one tab and a single |
| 105 // navigation. If |pinned_state| is true or |write_always| is true, the | 96 // navigation. If |pinned_state| is true or |write_always| is true, the |
| 106 // pinned state of the tab is updated. The session service is then recreated | 97 // pinned state of the tab is updated. The session service is then recreated |
| 107 // and the pinned state of the read back tab is returned. | 98 // and the pinned state of the read back tab is returned. |
| 108 bool CreateAndWriteSessionWithOneTab(bool pinned_state, bool write_always) { | 99 bool CreateAndWriteSessionWithOneTab(bool pinned_state, bool write_always) { |
| 109 SessionID tab_id; | 100 SessionID tab_id; |
| 110 TabNavigation nav1(0, GURL("http://google.com"), | 101 TabNavigation nav1 = |
| 111 content::Referrer(GURL("http://www.referrer.com"), | 102 TabNavigation::CreateForTest("http://google.com", "abc"); |
| 112 WebKit::WebReferrerPolicyDefault), | |
| 113 ASCIIToUTF16("abc"), "def", | |
| 114 content::PAGE_TRANSITION_QUALIFIER_MASK); | |
| 115 | 103 |
| 116 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 104 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 117 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 105 UpdateNavigation(window_id, tab_id, nav1, true); |
| 118 | 106 |
| 119 if (pinned_state || write_always) | 107 if (pinned_state || write_always) |
| 120 helper_.service()->SetPinnedState(window_id, tab_id, pinned_state); | 108 helper_.service()->SetPinnedState(window_id, tab_id, pinned_state); |
| 121 | 109 |
| 122 ScopedVector<SessionWindow> windows; | 110 ScopedVector<SessionWindow> windows; |
| 123 ReadWindows(&(windows.get())); | 111 ReadWindows(&(windows.get())); |
| 124 | 112 |
| 125 EXPECT_EQ(1U, windows.size()); | 113 EXPECT_EQ(1U, windows.size()); |
| 126 if (HasFatalFailure()) | 114 if (HasFatalFailure()) |
| 127 return false; | 115 return false; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 149 ScopedTempDir temp_dir_; | 137 ScopedTempDir temp_dir_; |
| 150 FilePath path_; | 138 FilePath path_; |
| 151 | 139 |
| 152 SessionServiceTestHelper helper_; | 140 SessionServiceTestHelper helper_; |
| 153 }; | 141 }; |
| 154 | 142 |
| 155 TEST_F(SessionServiceTest, Basic) { | 143 TEST_F(SessionServiceTest, Basic) { |
| 156 SessionID tab_id; | 144 SessionID tab_id; |
| 157 ASSERT_NE(window_id.id(), tab_id.id()); | 145 ASSERT_NE(window_id.id(), tab_id.id()); |
| 158 | 146 |
| 159 TabNavigation nav1(0, GURL("http://google.com"), | 147 TabNavigation nav1 = |
| 160 content::Referrer(GURL("http://www.referrer.com"), | 148 TabNavigation::CreateForTest("http://google.com", "abc"); |
| 161 WebKit::WebReferrerPolicyDefault), | 149 nav1.SetOriginalRequestURLForTest(GURL("http://original.request.com")); |
| 162 ASCIIToUTF16("abc"), "def", | |
| 163 content::PAGE_TRANSITION_QUALIFIER_MASK); | |
| 164 nav1.set_original_request_url(GURL("http://original.request.com")); | |
| 165 | 150 |
| 166 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 151 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 167 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 152 UpdateNavigation(window_id, tab_id, nav1, true); |
| 168 | 153 |
| 169 ScopedVector<SessionWindow> windows; | 154 ScopedVector<SessionWindow> windows; |
| 170 ReadWindows(&(windows.get())); | 155 ReadWindows(&(windows.get())); |
| 171 | 156 |
| 172 ASSERT_EQ(1U, windows.size()); | 157 ASSERT_EQ(1U, windows.size()); |
| 173 ASSERT_TRUE(window_bounds == windows[0]->bounds); | 158 ASSERT_TRUE(window_bounds == windows[0]->bounds); |
| 174 ASSERT_EQ(0, windows[0]->selected_tab_index); | 159 ASSERT_EQ(0, windows[0]->selected_tab_index); |
| 175 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); | 160 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); |
| 176 ASSERT_EQ(1U, windows[0]->tabs.size()); | 161 ASSERT_EQ(1U, windows[0]->tabs.size()); |
| 177 ASSERT_EQ(Browser::TYPE_TABBED, windows[0]->type); | 162 ASSERT_EQ(Browser::TYPE_TABBED, windows[0]->type); |
| 178 | 163 |
| 179 SessionTab* tab = windows[0]->tabs[0]; | 164 SessionTab* tab = windows[0]->tabs[0]; |
| 180 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); | 165 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); |
| 181 | 166 |
| 182 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); | 167 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); |
| 183 } | 168 } |
| 184 | 169 |
| 185 // Make sure we persist post entries. | 170 // Make sure we persist post entries. |
| 186 TEST_F(SessionServiceTest, PersistPostData) { | 171 TEST_F(SessionServiceTest, PersistPostData) { |
| 187 SessionID tab_id; | 172 SessionID tab_id; |
| 188 ASSERT_NE(window_id.id(), tab_id.id()); | 173 ASSERT_NE(window_id.id(), tab_id.id()); |
| 189 | 174 |
| 190 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), | 175 TabNavigation nav1 = |
| 191 ASCIIToUTF16("abc"), std::string(), | 176 TabNavigation::CreateForTest("http://google.com", "abc"); |
| 192 content::PAGE_TRANSITION_QUALIFIER_MASK); | 177 nav1.SetHasPostDataForTest(true); |
| 193 nav1.set_type_mask(TabNavigation::HAS_POST_DATA); | |
| 194 | 178 |
| 195 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 179 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 196 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 180 UpdateNavigation(window_id, tab_id, nav1, true); |
| 197 | 181 |
| 198 ScopedVector<SessionWindow> windows; | 182 ScopedVector<SessionWindow> windows; |
| 199 ReadWindows(&(windows.get())); | 183 ReadWindows(&(windows.get())); |
| 200 | 184 |
| 201 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); | 185 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); |
| 202 } | 186 } |
| 203 | 187 |
| 204 TEST_F(SessionServiceTest, ClosingTabStaysClosed) { | 188 TEST_F(SessionServiceTest, ClosingTabStaysClosed) { |
| 205 SessionID tab_id; | 189 SessionID tab_id; |
| 206 SessionID tab2_id; | 190 SessionID tab2_id; |
| 207 ASSERT_NE(tab_id.id(), tab2_id.id()); | 191 ASSERT_NE(tab_id.id(), tab2_id.id()); |
| 208 | 192 |
| 209 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), | 193 TabNavigation nav1 = |
| 210 ASCIIToUTF16("abc"), "def", | 194 TabNavigation::CreateForTest("http://google.com", "abc"); |
| 211 content::PAGE_TRANSITION_QUALIFIER_MASK); | 195 TabNavigation nav2 = |
| 212 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), | 196 TabNavigation::CreateForTest("http://google2.com", "abcd"); |
| 213 ASCIIToUTF16("abcd"), "defg", | |
| 214 content::PAGE_TRANSITION_AUTO_BOOKMARK); | |
| 215 | 197 |
| 216 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 198 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 217 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 199 UpdateNavigation(window_id, tab_id, nav1, true); |
| 218 | 200 |
| 219 helper_.PrepareTabInWindow(window_id, tab2_id, 1, false); | 201 helper_.PrepareTabInWindow(window_id, tab2_id, 1, false); |
| 220 UpdateNavigation(window_id, tab2_id, nav2, 0, true); | 202 UpdateNavigation(window_id, tab2_id, nav2, true); |
| 221 service()->TabClosed(window_id, tab2_id, false); | 203 service()->TabClosed(window_id, tab2_id, false); |
| 222 | 204 |
| 223 ScopedVector<SessionWindow> windows; | 205 ScopedVector<SessionWindow> windows; |
| 224 ReadWindows(&(windows.get())); | 206 ReadWindows(&(windows.get())); |
| 225 | 207 |
| 226 ASSERT_EQ(1U, windows.size()); | 208 ASSERT_EQ(1U, windows.size()); |
| 227 ASSERT_EQ(0, windows[0]->selected_tab_index); | 209 ASSERT_EQ(0, windows[0]->selected_tab_index); |
| 228 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); | 210 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); |
| 229 ASSERT_EQ(1U, windows[0]->tabs.size()); | 211 ASSERT_EQ(1U, windows[0]->tabs.size()); |
| 230 | 212 |
| 231 SessionTab* tab = windows[0]->tabs[0]; | 213 SessionTab* tab = windows[0]->tabs[0]; |
| 232 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); | 214 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); |
| 233 | 215 |
| 234 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); | 216 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); |
| 235 } | 217 } |
| 236 | 218 |
| 237 TEST_F(SessionServiceTest, Pruning) { | 219 TEST_F(SessionServiceTest, Pruning) { |
| 238 SessionID tab_id; | 220 SessionID tab_id; |
| 239 | 221 |
| 240 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), | 222 TabNavigation nav1 = |
| 241 ASCIIToUTF16("abc"), "def", | 223 TabNavigation::CreateForTest("http://google.com", "abc"); |
| 242 content::PAGE_TRANSITION_QUALIFIER_MASK); | 224 TabNavigation nav2 = |
| 243 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), | 225 TabNavigation::CreateForTest("http://google2.com", "abcd"); |
| 244 ASCIIToUTF16("abcd"), "defg", | |
| 245 content::PAGE_TRANSITION_AUTO_BOOKMARK); | |
| 246 | 226 |
| 247 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 227 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 248 for (int i = 0; i < 6; ++i) { | 228 for (int i = 0; i < 6; ++i) { |
| 249 TabNavigation& nav = (i % 2) == 0 ? nav1 : nav2; | 229 TabNavigation* nav = (i % 2) == 0 ? &nav1 : &nav2; |
| 250 UpdateNavigation(window_id, tab_id, nav, i, true); | 230 nav->set_index(i); |
| 231 UpdateNavigation(window_id, tab_id, *nav, true); |
| 251 } | 232 } |
| 252 service()->TabNavigationPathPrunedFromBack(window_id, tab_id, 3); | 233 service()->TabNavigationPathPrunedFromBack(window_id, tab_id, 3); |
| 253 | 234 |
| 254 ScopedVector<SessionWindow> windows; | 235 ScopedVector<SessionWindow> windows; |
| 255 ReadWindows(&(windows.get())); | 236 ReadWindows(&(windows.get())); |
| 256 | 237 |
| 257 ASSERT_EQ(1U, windows.size()); | 238 ASSERT_EQ(1U, windows.size()); |
| 258 ASSERT_EQ(0, windows[0]->selected_tab_index); | 239 ASSERT_EQ(0, windows[0]->selected_tab_index); |
| 259 ASSERT_EQ(1U, windows[0]->tabs.size()); | 240 ASSERT_EQ(1U, windows[0]->tabs.size()); |
| 260 | 241 |
| 261 SessionTab* tab = windows[0]->tabs[0]; | 242 SessionTab* tab = windows[0]->tabs[0]; |
| 262 // We left the selected index at 5, then pruned. When rereading the | 243 // We left the selected index at 5, then pruned. When rereading the |
| 263 // index should get reset to last valid navigation, which is 2. | 244 // index should get reset to last valid navigation, which is 2. |
| 264 helper_.AssertTabEquals(window_id, tab_id, 0, 2, 3, *tab); | 245 helper_.AssertTabEquals(window_id, tab_id, 0, 2, 3, *tab); |
| 265 | 246 |
| 247 ASSERT_EQ(3u, tab->navigations.size()); |
| 266 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); | 248 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); |
| 267 helper_.AssertNavigationEquals(nav2, tab->navigations[1]); | 249 helper_.AssertNavigationEquals(nav2, tab->navigations[1]); |
| 268 helper_.AssertNavigationEquals(nav1, tab->navigations[2]); | 250 helper_.AssertNavigationEquals(nav1, tab->navigations[2]); |
| 269 } | 251 } |
| 270 | 252 |
| 271 TEST_F(SessionServiceTest, TwoWindows) { | 253 TEST_F(SessionServiceTest, TwoWindows) { |
| 272 SessionID window2_id; | 254 SessionID window2_id; |
| 273 SessionID tab1_id; | 255 SessionID tab1_id; |
| 274 SessionID tab2_id; | 256 SessionID tab2_id; |
| 275 | 257 |
| 276 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), | 258 TabNavigation nav1 = |
| 277 ASCIIToUTF16("abc"), "def", | 259 TabNavigation::CreateForTest("http://google.com", "abc"); |
| 278 content::PAGE_TRANSITION_QUALIFIER_MASK); | 260 TabNavigation nav2 = |
| 279 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), | 261 TabNavigation::CreateForTest("http://google2.com", "abcd"); |
| 280 ASCIIToUTF16("abcd"), "defg", | |
| 281 content::PAGE_TRANSITION_AUTO_BOOKMARK); | |
| 282 | 262 |
| 283 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); | 263 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); |
| 284 UpdateNavigation(window_id, tab1_id, nav1, 0, true); | 264 UpdateNavigation(window_id, tab1_id, nav1, true); |
| 285 | 265 |
| 286 const gfx::Rect window2_bounds(3, 4, 5, 6); | 266 const gfx::Rect window2_bounds(3, 4, 5, 6); |
| 287 service()->SetWindowType( | 267 service()->SetWindowType( |
| 288 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); | 268 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); |
| 289 service()->SetWindowBounds(window2_id, | 269 service()->SetWindowBounds(window2_id, |
| 290 window2_bounds, | 270 window2_bounds, |
| 291 ui::SHOW_STATE_MAXIMIZED); | 271 ui::SHOW_STATE_MAXIMIZED); |
| 292 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true); | 272 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true); |
| 293 UpdateNavigation(window2_id, tab2_id, nav2, 0, true); | 273 UpdateNavigation(window2_id, tab2_id, nav2, true); |
| 294 | 274 |
| 295 ScopedVector<SessionWindow> windows; | 275 ScopedVector<SessionWindow> windows; |
| 296 ReadWindows(&(windows.get())); | 276 ReadWindows(&(windows.get())); |
| 297 | 277 |
| 298 ASSERT_EQ(2U, windows.size()); | 278 ASSERT_EQ(2U, windows.size()); |
| 299 ASSERT_EQ(0, windows[0]->selected_tab_index); | 279 ASSERT_EQ(0, windows[0]->selected_tab_index); |
| 300 ASSERT_EQ(0, windows[1]->selected_tab_index); | 280 ASSERT_EQ(0, windows[1]->selected_tab_index); |
| 301 ASSERT_EQ(1U, windows[0]->tabs.size()); | 281 ASSERT_EQ(1U, windows[0]->tabs.size()); |
| 302 ASSERT_EQ(1U, windows[1]->tabs.size()); | 282 ASSERT_EQ(1U, windows[1]->tabs.size()); |
| 303 | 283 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 324 tab = rt2; | 304 tab = rt2; |
| 325 helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab); | 305 helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab); |
| 326 helper_.AssertNavigationEquals(nav2, tab->navigations[0]); | 306 helper_.AssertNavigationEquals(nav2, tab->navigations[0]); |
| 327 } | 307 } |
| 328 | 308 |
| 329 TEST_F(SessionServiceTest, WindowWithNoTabsGetsPruned) { | 309 TEST_F(SessionServiceTest, WindowWithNoTabsGetsPruned) { |
| 330 SessionID window2_id; | 310 SessionID window2_id; |
| 331 SessionID tab1_id; | 311 SessionID tab1_id; |
| 332 SessionID tab2_id; | 312 SessionID tab2_id; |
| 333 | 313 |
| 334 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), | 314 TabNavigation nav1 = |
| 335 ASCIIToUTF16("abc"), "def", | 315 TabNavigation::CreateForTest("http://google.com", "abc"); |
| 336 content::PAGE_TRANSITION_QUALIFIER_MASK); | |
| 337 | 316 |
| 338 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); | 317 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); |
| 339 UpdateNavigation(window_id, tab1_id, nav1, 0, true); | 318 UpdateNavigation(window_id, tab1_id, nav1, true); |
| 340 | 319 |
| 341 const gfx::Rect window2_bounds(3, 4, 5, 6); | 320 const gfx::Rect window2_bounds(3, 4, 5, 6); |
| 342 service()->SetWindowType( | 321 service()->SetWindowType( |
| 343 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); | 322 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); |
| 344 service()->SetWindowBounds(window2_id, | 323 service()->SetWindowBounds(window2_id, |
| 345 window2_bounds, | 324 window2_bounds, |
| 346 ui::SHOW_STATE_NORMAL); | 325 ui::SHOW_STATE_NORMAL); |
| 347 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true); | 326 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true); |
| 348 | 327 |
| 349 ScopedVector<SessionWindow> windows; | 328 ScopedVector<SessionWindow> windows; |
| 350 ReadWindows(&(windows.get())); | 329 ReadWindows(&(windows.get())); |
| 351 | 330 |
| 352 ASSERT_EQ(1U, windows.size()); | 331 ASSERT_EQ(1U, windows.size()); |
| 353 ASSERT_EQ(0, windows[0]->selected_tab_index); | 332 ASSERT_EQ(0, windows[0]->selected_tab_index); |
| 354 ASSERT_EQ(1U, windows[0]->tabs.size()); | 333 ASSERT_EQ(1U, windows[0]->tabs.size()); |
| 355 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); | 334 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); |
| 356 | 335 |
| 357 SessionTab* tab = windows[0]->tabs[0]; | 336 SessionTab* tab = windows[0]->tabs[0]; |
| 358 helper_.AssertTabEquals(window_id, tab1_id, 0, 0, 1, *tab); | 337 helper_.AssertTabEquals(window_id, tab1_id, 0, 0, 1, *tab); |
| 359 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); | 338 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); |
| 360 } | 339 } |
| 361 | 340 |
| 362 TEST_F(SessionServiceTest, ClosingWindowDoesntCloseTabs) { | 341 TEST_F(SessionServiceTest, ClosingWindowDoesntCloseTabs) { |
| 363 SessionID tab_id; | 342 SessionID tab_id; |
| 364 SessionID tab2_id; | 343 SessionID tab2_id; |
| 365 ASSERT_NE(tab_id.id(), tab2_id.id()); | 344 ASSERT_NE(tab_id.id(), tab2_id.id()); |
| 366 | 345 |
| 367 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), | 346 TabNavigation nav1 = |
| 368 ASCIIToUTF16("abc"), "def", | 347 TabNavigation::CreateForTest("http://google.com", "abc"); |
| 369 content::PAGE_TRANSITION_QUALIFIER_MASK); | 348 TabNavigation nav2 = |
| 370 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), | 349 TabNavigation::CreateForTest("http://google2.com", "abcd"); |
| 371 ASCIIToUTF16("abcd"), "defg", | |
| 372 content::PAGE_TRANSITION_AUTO_BOOKMARK); | |
| 373 | 350 |
| 374 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 351 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 375 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 352 UpdateNavigation(window_id, tab_id, nav1, true); |
| 376 | 353 |
| 377 helper_.PrepareTabInWindow(window_id, tab2_id, 1, false); | 354 helper_.PrepareTabInWindow(window_id, tab2_id, 1, false); |
| 378 UpdateNavigation(window_id, tab2_id, nav2, 0, true); | 355 UpdateNavigation(window_id, tab2_id, nav2, true); |
| 379 | 356 |
| 380 service()->WindowClosing(window_id); | 357 service()->WindowClosing(window_id); |
| 381 | 358 |
| 382 ScopedVector<SessionWindow> windows; | 359 ScopedVector<SessionWindow> windows; |
| 383 ReadWindows(&(windows.get())); | 360 ReadWindows(&(windows.get())); |
| 384 | 361 |
| 385 ASSERT_EQ(1U, windows.size()); | 362 ASSERT_EQ(1U, windows.size()); |
| 386 ASSERT_EQ(0, windows[0]->selected_tab_index); | 363 ASSERT_EQ(0, windows[0]->selected_tab_index); |
| 387 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); | 364 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); |
| 388 ASSERT_EQ(2U, windows[0]->tabs.size()); | 365 ASSERT_EQ(2U, windows[0]->tabs.size()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 401 SessionID tab_id; | 378 SessionID tab_id; |
| 402 SessionID tab2_id; | 379 SessionID tab2_id; |
| 403 ASSERT_NE(window2_id.id(), window_id.id()); | 380 ASSERT_NE(window2_id.id(), window_id.id()); |
| 404 | 381 |
| 405 service()->SetWindowType( | 382 service()->SetWindowType( |
| 406 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); | 383 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); |
| 407 service()->SetWindowBounds(window2_id, | 384 service()->SetWindowBounds(window2_id, |
| 408 window_bounds, | 385 window_bounds, |
| 409 ui::SHOW_STATE_NORMAL); | 386 ui::SHOW_STATE_NORMAL); |
| 410 | 387 |
| 411 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), | 388 TabNavigation nav1 = |
| 412 ASCIIToUTF16("abc"), "def", | 389 TabNavigation::CreateForTest("http://google.com", "abc"); |
| 413 content::PAGE_TRANSITION_QUALIFIER_MASK); | 390 TabNavigation nav2 = |
| 414 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), | 391 TabNavigation::CreateForTest("http://google2.com", "abcd"); |
| 415 ASCIIToUTF16("abcd"), "defg", | |
| 416 content::PAGE_TRANSITION_AUTO_BOOKMARK); | |
| 417 | 392 |
| 418 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 393 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 419 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 394 UpdateNavigation(window_id, tab_id, nav1, true); |
| 420 | 395 |
| 421 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); | 396 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); |
| 422 UpdateNavigation(window2_id, tab2_id, nav2, 0, true); | 397 UpdateNavigation(window2_id, tab2_id, nav2, true); |
| 423 | 398 |
| 424 service()->WindowClosing(window2_id); | 399 service()->WindowClosing(window2_id); |
| 425 service()->TabClosed(window2_id, tab2_id, false); | 400 service()->TabClosed(window2_id, tab2_id, false); |
| 426 service()->WindowClosed(window2_id); | 401 service()->WindowClosed(window2_id); |
| 427 | 402 |
| 428 ScopedVector<SessionWindow> windows; | 403 ScopedVector<SessionWindow> windows; |
| 429 ReadWindows(&(windows.get())); | 404 ReadWindows(&(windows.get())); |
| 430 | 405 |
| 431 ASSERT_EQ(1U, windows.size()); | 406 ASSERT_EQ(1U, windows.size()); |
| 432 ASSERT_EQ(0, windows[0]->selected_tab_index); | 407 ASSERT_EQ(0, windows[0]->selected_tab_index); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 447 SessionID tab_id; | 422 SessionID tab_id; |
| 448 SessionID tab2_id; | 423 SessionID tab2_id; |
| 449 ASSERT_NE(window2_id.id(), window_id.id()); | 424 ASSERT_NE(window2_id.id(), window_id.id()); |
| 450 | 425 |
| 451 service()->SetWindowType( | 426 service()->SetWindowType( |
| 452 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_NORMAL); | 427 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_NORMAL); |
| 453 service()->SetWindowBounds(window2_id, | 428 service()->SetWindowBounds(window2_id, |
| 454 window_bounds, | 429 window_bounds, |
| 455 ui::SHOW_STATE_NORMAL); | 430 ui::SHOW_STATE_NORMAL); |
| 456 | 431 |
| 457 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), | 432 TabNavigation nav1 = |
| 458 ASCIIToUTF16("abc"), "def", | 433 TabNavigation::CreateForTest("http://google.com", "abc"); |
| 459 content::PAGE_TRANSITION_QUALIFIER_MASK); | 434 TabNavigation nav2 = |
| 460 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), | 435 TabNavigation::CreateForTest("http://google2.com", "abcd"); |
| 461 ASCIIToUTF16("abcd"), "defg", | |
| 462 content::PAGE_TRANSITION_AUTO_BOOKMARK); | |
| 463 | 436 |
| 464 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 437 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 465 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 438 UpdateNavigation(window_id, tab_id, nav1, true); |
| 466 | 439 |
| 467 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); | 440 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); |
| 468 UpdateNavigation(window2_id, tab2_id, nav2, 0, true); | 441 UpdateNavigation(window2_id, tab2_id, nav2, true); |
| 469 | 442 |
| 470 ScopedVector<SessionWindow> windows; | 443 ScopedVector<SessionWindow> windows; |
| 471 ReadWindows(&(windows.get())); | 444 ReadWindows(&(windows.get())); |
| 472 | 445 |
| 473 ASSERT_EQ(1U, windows.size()); | 446 ASSERT_EQ(1U, windows.size()); |
| 474 ASSERT_EQ(0, windows[0]->selected_tab_index); | 447 ASSERT_EQ(0, windows[0]->selected_tab_index); |
| 475 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); | 448 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); |
| 476 ASSERT_EQ(1U, windows[0]->tabs.size()); | 449 ASSERT_EQ(1U, windows[0]->tabs.size()); |
| 477 | 450 |
| 478 SessionTab* tab = windows[0]->tabs[0]; | 451 SessionTab* tab = windows[0]->tabs[0]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 489 SessionID tab_id; | 462 SessionID tab_id; |
| 490 SessionID tab2_id; | 463 SessionID tab2_id; |
| 491 ASSERT_NE(window2_id.id(), window_id.id()); | 464 ASSERT_NE(window2_id.id(), window_id.id()); |
| 492 | 465 |
| 493 service()->SetWindowType( | 466 service()->SetWindowType( |
| 494 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_NORMAL); | 467 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_NORMAL); |
| 495 service()->SetWindowBounds(window2_id, | 468 service()->SetWindowBounds(window2_id, |
| 496 window_bounds, | 469 window_bounds, |
| 497 ui::SHOW_STATE_NORMAL); | 470 ui::SHOW_STATE_NORMAL); |
| 498 | 471 |
| 499 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), | 472 TabNavigation nav1 = |
| 500 ASCIIToUTF16("abc"), "def", | 473 TabNavigation::CreateForTest("http://google.com", "abc"); |
| 501 content::PAGE_TRANSITION_QUALIFIER_MASK); | 474 TabNavigation nav2 = |
| 502 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), | 475 TabNavigation::CreateForTest("http://google2.com", "abcd"); |
| 503 ASCIIToUTF16("abcd"), "defg", | |
| 504 content::PAGE_TRANSITION_AUTO_BOOKMARK); | |
| 505 | 476 |
| 506 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 477 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 507 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 478 UpdateNavigation(window_id, tab_id, nav1, true); |
| 508 | 479 |
| 509 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); | 480 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); |
| 510 UpdateNavigation(window2_id, tab2_id, nav2, 0, true); | 481 UpdateNavigation(window2_id, tab2_id, nav2, true); |
| 511 | 482 |
| 512 ScopedVector<SessionWindow> windows; | 483 ScopedVector<SessionWindow> windows; |
| 513 ReadWindows(&(windows.get())); | 484 ReadWindows(&(windows.get())); |
| 514 | 485 |
| 515 ASSERT_EQ(2U, windows.size()); | 486 ASSERT_EQ(2U, windows.size()); |
| 516 int tabbed_index = windows[0]->type == Browser::TYPE_TABBED ? | 487 int tabbed_index = windows[0]->type == Browser::TYPE_TABBED ? |
| 517 0 : 1; | 488 0 : 1; |
| 518 int popup_index = tabbed_index == 0 ? 1 : 0; | 489 int popup_index = tabbed_index == 0 ? 1 : 0; |
| 519 ASSERT_EQ(0, windows[tabbed_index]->selected_tab_index); | 490 ASSERT_EQ(0, windows[tabbed_index]->selected_tab_index); |
| 520 ASSERT_EQ(window_id.id(), windows[tabbed_index]->window_id.id()); | 491 ASSERT_EQ(window_id.id(), windows[tabbed_index]->window_id.id()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 541 SessionID tab2_id; | 512 SessionID tab2_id; |
| 542 ASSERT_NE(window2_id.id(), window_id.id()); | 513 ASSERT_NE(window2_id.id(), window_id.id()); |
| 543 | 514 |
| 544 service()->SetWindowType( | 515 service()->SetWindowType( |
| 545 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_APP); | 516 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_APP); |
| 546 service()->SetWindowBounds(window2_id, | 517 service()->SetWindowBounds(window2_id, |
| 547 window_bounds, | 518 window_bounds, |
| 548 ui::SHOW_STATE_NORMAL); | 519 ui::SHOW_STATE_NORMAL); |
| 549 service()->SetWindowAppName(window2_id, "TestApp"); | 520 service()->SetWindowAppName(window2_id, "TestApp"); |
| 550 | 521 |
| 551 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), | 522 TabNavigation nav1 = |
| 552 ASCIIToUTF16("abc"), "def", | 523 TabNavigation::CreateForTest("http://google.com", "abc"); |
| 553 content::PAGE_TRANSITION_QUALIFIER_MASK); | 524 TabNavigation nav2 = |
| 554 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), | 525 TabNavigation::CreateForTest("http://google2.com", "abcd"); |
| 555 ASCIIToUTF16("abcd"), "defg", | |
| 556 content::PAGE_TRANSITION_AUTO_BOOKMARK); | |
| 557 | 526 |
| 558 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 527 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 559 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 528 UpdateNavigation(window_id, tab_id, nav1, true); |
| 560 | 529 |
| 561 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); | 530 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); |
| 562 UpdateNavigation(window2_id, tab2_id, nav2, 0, true); | 531 UpdateNavigation(window2_id, tab2_id, nav2, true); |
| 563 | 532 |
| 564 ScopedVector<SessionWindow> windows; | 533 ScopedVector<SessionWindow> windows; |
| 565 ReadWindows(&(windows.get())); | 534 ReadWindows(&(windows.get())); |
| 566 | 535 |
| 567 ASSERT_EQ(2U, windows.size()); | 536 ASSERT_EQ(2U, windows.size()); |
| 568 int tabbed_index = windows[0]->type == Browser::TYPE_TABBED ? | 537 int tabbed_index = windows[0]->type == Browser::TYPE_TABBED ? |
| 569 0 : 1; | 538 0 : 1; |
| 570 int app_index = tabbed_index == 0 ? 1 : 0; | 539 int app_index = tabbed_index == 0 ? 1 : 0; |
| 571 ASSERT_EQ(0, windows[tabbed_index]->selected_tab_index); | 540 ASSERT_EQ(0, windows[tabbed_index]->selected_tab_index); |
| 572 ASSERT_EQ(window_id.id(), windows[tabbed_index]->window_id.id()); | 541 ASSERT_EQ(window_id.id(), windows[tabbed_index]->window_id.id()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 590 | 559 |
| 591 // Tests pruning from the front. | 560 // Tests pruning from the front. |
| 592 TEST_F(SessionServiceTest, PruneFromFront) { | 561 TEST_F(SessionServiceTest, PruneFromFront) { |
| 593 const std::string base_url("http://google.com/"); | 562 const std::string base_url("http://google.com/"); |
| 594 SessionID tab_id; | 563 SessionID tab_id; |
| 595 | 564 |
| 596 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 565 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 597 | 566 |
| 598 // Add 5 navigations, with the 4th selected. | 567 // Add 5 navigations, with the 4th selected. |
| 599 for (int i = 0; i < 5; ++i) { | 568 for (int i = 0; i < 5; ++i) { |
| 600 TabNavigation nav(0, GURL(base_url + base::IntToString(i)), | 569 TabNavigation nav = |
| 601 content::Referrer(), | 570 TabNavigation::CreateForTest(base_url + base::IntToString(i), "a"); |
| 602 ASCIIToUTF16("a"), "b", | 571 nav.set_index(i); |
| 603 content::PAGE_TRANSITION_QUALIFIER_MASK); | 572 UpdateNavigation(window_id, tab_id, nav, (i == 3)); |
| 604 UpdateNavigation(window_id, tab_id, nav, i, (i == 3)); | |
| 605 } | 573 } |
| 606 | 574 |
| 607 // Prune the first two navigations from the front. | 575 // Prune the first two navigations from the front. |
| 608 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 2); | 576 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 2); |
| 609 | 577 |
| 610 // Read back in. | 578 // Read back in. |
| 611 ScopedVector<SessionWindow> windows; | 579 ScopedVector<SessionWindow> windows; |
| 612 ReadWindows(&(windows.get())); | 580 ReadWindows(&(windows.get())); |
| 613 | 581 |
| 614 ASSERT_EQ(1U, windows.size()); | 582 ASSERT_EQ(1U, windows.size()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 633 | 601 |
| 634 // Prunes from front so that we have no entries. | 602 // Prunes from front so that we have no entries. |
| 635 TEST_F(SessionServiceTest, PruneToEmpty) { | 603 TEST_F(SessionServiceTest, PruneToEmpty) { |
| 636 const std::string base_url("http://google.com/"); | 604 const std::string base_url("http://google.com/"); |
| 637 SessionID tab_id; | 605 SessionID tab_id; |
| 638 | 606 |
| 639 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 607 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 640 | 608 |
| 641 // Add 5 navigations, with the 4th selected. | 609 // Add 5 navigations, with the 4th selected. |
| 642 for (int i = 0; i < 5; ++i) { | 610 for (int i = 0; i < 5; ++i) { |
| 643 TabNavigation nav(0, GURL(base_url + base::IntToString(i)), | 611 TabNavigation nav = |
| 644 content::Referrer(), | 612 TabNavigation::CreateForTest(base_url + base::IntToString(i), "a"); |
| 645 ASCIIToUTF16("a"), "b", | 613 nav.set_index(i); |
| 646 content::PAGE_TRANSITION_QUALIFIER_MASK); | 614 UpdateNavigation(window_id, tab_id, nav, (i == 3)); |
| 647 UpdateNavigation(window_id, tab_id, nav, i, (i == 3)); | |
| 648 } | 615 } |
| 649 | 616 |
| 650 // Prune the first two navigations from the front. | 617 // Prune the first two navigations from the front. |
| 651 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 5); | 618 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 5); |
| 652 | 619 |
| 653 // Read back in. | 620 // Read back in. |
| 654 ScopedVector<SessionWindow> windows; | 621 ScopedVector<SessionWindow> windows; |
| 655 ReadWindows(&(windows.get())); | 622 ReadWindows(&(windows.get())); |
| 656 | 623 |
| 657 ASSERT_EQ(0U, windows.size()); | 624 ASSERT_EQ(0U, windows.size()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 671 TEST_F(SessionServiceTest, PinnedTrue) { | 638 TEST_F(SessionServiceTest, PinnedTrue) { |
| 672 EXPECT_TRUE(CreateAndWriteSessionWithOneTab(true, true)); | 639 EXPECT_TRUE(CreateAndWriteSessionWithOneTab(true, true)); |
| 673 } | 640 } |
| 674 | 641 |
| 675 // Make sure application extension ids are persisted. | 642 // Make sure application extension ids are persisted. |
| 676 TEST_F(SessionServiceTest, PersistApplicationExtensionID) { | 643 TEST_F(SessionServiceTest, PersistApplicationExtensionID) { |
| 677 SessionID tab_id; | 644 SessionID tab_id; |
| 678 ASSERT_NE(window_id.id(), tab_id.id()); | 645 ASSERT_NE(window_id.id(), tab_id.id()); |
| 679 std::string app_id("foo"); | 646 std::string app_id("foo"); |
| 680 | 647 |
| 681 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), | 648 TabNavigation nav1 = |
| 682 ASCIIToUTF16("abc"), std::string(), | 649 TabNavigation::CreateForTest("http://google.com", "abc"); |
| 683 content::PAGE_TRANSITION_QUALIFIER_MASK); | |
| 684 | 650 |
| 685 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 651 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 686 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 652 UpdateNavigation(window_id, tab_id, nav1, true); |
| 687 helper_.SetTabExtensionAppID(window_id, tab_id, app_id); | 653 helper_.SetTabExtensionAppID(window_id, tab_id, app_id); |
| 688 | 654 |
| 689 ScopedVector<SessionWindow> windows; | 655 ScopedVector<SessionWindow> windows; |
| 690 ReadWindows(&(windows.get())); | 656 ReadWindows(&(windows.get())); |
| 691 | 657 |
| 692 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); | 658 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); |
| 693 EXPECT_TRUE(app_id == windows[0]->tabs[0]->extension_app_id); | 659 EXPECT_TRUE(app_id == windows[0]->tabs[0]->extension_app_id); |
| 694 } | 660 } |
| 695 | 661 |
| 696 // Check that user agent overrides are persisted. | 662 // Check that user agent overrides are persisted. |
| 697 TEST_F(SessionServiceTest, PersistUserAgentOverrides) { | 663 TEST_F(SessionServiceTest, PersistUserAgentOverrides) { |
| 698 SessionID tab_id; | 664 SessionID tab_id; |
| 699 ASSERT_NE(window_id.id(), tab_id.id()); | 665 ASSERT_NE(window_id.id(), tab_id.id()); |
| 700 std::string user_agent_override = "Mozilla/5.0 (X11; Linux x86_64) " | 666 std::string user_agent_override = "Mozilla/5.0 (X11; Linux x86_64) " |
| 701 "AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.45 " | 667 "AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.45 " |
| 702 "Safari/535.19"; | 668 "Safari/535.19"; |
| 703 | 669 |
| 704 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), | 670 TabNavigation nav1 = |
| 705 ASCIIToUTF16("abc"), std::string(), | 671 TabNavigation::CreateForTest("http://google.com", "abc"); |
| 706 content::PAGE_TRANSITION_QUALIFIER_MASK); | 672 nav1.SetIsOverridingUserAgentForTest(true); |
| 707 nav1.set_is_overriding_user_agent(true); | |
| 708 | 673 |
| 709 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 674 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 710 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 675 UpdateNavigation(window_id, tab_id, nav1, true); |
| 711 helper_.SetTabUserAgentOverride(window_id, tab_id, user_agent_override); | 676 helper_.SetTabUserAgentOverride(window_id, tab_id, user_agent_override); |
| 712 | 677 |
| 713 ScopedVector<SessionWindow> windows; | 678 ScopedVector<SessionWindow> windows; |
| 714 ReadWindows(&(windows.get())); | 679 ReadWindows(&(windows.get())); |
| 715 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); | 680 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); |
| 716 | 681 |
| 717 SessionTab* tab = windows[0]->tabs[0]; | 682 SessionTab* tab = windows[0]->tabs[0]; |
| 718 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); | 683 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); |
| 719 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); | 684 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); |
| 720 EXPECT_TRUE(user_agent_override == tab->user_agent_override); | 685 EXPECT_TRUE(user_agent_override == tab->user_agent_override); |
| 721 } | 686 } |
| 722 | 687 |
| 723 // Test that the notification for SESSION_SERVICE_SAVED is working properly. | 688 // Test that the notification for SESSION_SERVICE_SAVED is working properly. |
| 724 TEST_F(SessionServiceTest, SavedSessionNotification) { | 689 TEST_F(SessionServiceTest, SavedSessionNotification) { |
| 725 content::NotificationRegistrar registrar_; | 690 content::NotificationRegistrar registrar_; |
| 726 registrar_.Add(this, chrome::NOTIFICATION_SESSION_SERVICE_SAVED, | 691 registrar_.Add(this, chrome::NOTIFICATION_SESSION_SERVICE_SAVED, |
| 727 content::NotificationService::AllSources()); | 692 content::NotificationService::AllSources()); |
| 728 service()->Save(); | 693 service()->Save(); |
| 729 EXPECT_EQ(sync_save_count_, 1); | 694 EXPECT_EQ(sync_save_count_, 1); |
| 730 } | 695 } |
| 731 | 696 |
| 732 // Makes sure a tab closed by a user gesture is not restored. | 697 // Makes sure a tab closed by a user gesture is not restored. |
| 733 TEST_F(SessionServiceTest, CloseTabUserGesture) { | 698 TEST_F(SessionServiceTest, CloseTabUserGesture) { |
| 734 SessionID tab_id; | 699 SessionID tab_id; |
| 735 ASSERT_NE(window_id.id(), tab_id.id()); | 700 ASSERT_NE(window_id.id(), tab_id.id()); |
| 736 | 701 |
| 737 TabNavigation nav1(0, GURL("http://google.com"), | 702 TabNavigation nav1 = |
| 738 content::Referrer(GURL("http://www.referrer.com"), | 703 TabNavigation::CreateForTest("http://google.com", "abc"); |
| 739 WebKit::WebReferrerPolicyDefault), | |
| 740 ASCIIToUTF16("abc"), "def", | |
| 741 content::PAGE_TRANSITION_QUALIFIER_MASK); | |
| 742 | 704 |
| 743 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 705 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 744 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 706 UpdateNavigation(window_id, tab_id, nav1, true); |
| 745 service()->TabClosed(window_id, tab_id, true); | 707 service()->TabClosed(window_id, tab_id, true); |
| 746 | 708 |
| 747 ScopedVector<SessionWindow> windows; | 709 ScopedVector<SessionWindow> windows; |
| 748 ReadWindows(&(windows.get())); | 710 ReadWindows(&(windows.get())); |
| 749 | 711 |
| 750 ASSERT_TRUE(windows.empty()); | 712 ASSERT_TRUE(windows.empty()); |
| 751 } | 713 } |
| 752 | 714 |
| 753 // Verifies SetWindowBounds maps SHOW_STATE_DEFAULT to SHOW_STATE_NORMAL. | 715 // Verifies SetWindowBounds maps SHOW_STATE_DEFAULT to SHOW_STATE_NORMAL. |
| 754 TEST_F(SessionServiceTest, DontPersistDefault) { | 716 TEST_F(SessionServiceTest, DontPersistDefault) { |
| 755 SessionID tab_id; | 717 SessionID tab_id; |
| 756 ASSERT_NE(window_id.id(), tab_id.id()); | 718 ASSERT_NE(window_id.id(), tab_id.id()); |
| 757 TabNavigation nav1(0, GURL("http://google.com"), | 719 TabNavigation nav1 = |
| 758 content::Referrer(GURL("http://www.referrer.com"), | 720 TabNavigation::CreateForTest("http://google.com", "abc"); |
| 759 WebKit::WebReferrerPolicyDefault), | |
| 760 ASCIIToUTF16("abc"), "def", | |
| 761 content::PAGE_TRANSITION_QUALIFIER_MASK); | |
| 762 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 721 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 763 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 722 UpdateNavigation(window_id, tab_id, nav1, true); |
| 764 service()->SetWindowBounds(window_id, | 723 service()->SetWindowBounds(window_id, |
| 765 window_bounds, | 724 window_bounds, |
| 766 ui::SHOW_STATE_DEFAULT); | 725 ui::SHOW_STATE_DEFAULT); |
| 767 | 726 |
| 768 ScopedVector<SessionWindow> windows; | 727 ScopedVector<SessionWindow> windows; |
| 769 ReadWindows(&(windows.get())); | 728 ReadWindows(&(windows.get())); |
| 770 ASSERT_EQ(1U, windows.size()); | 729 ASSERT_EQ(1U, windows.size()); |
| 771 EXPECT_EQ(ui::SHOW_STATE_NORMAL, windows[0]->show_state); | 730 EXPECT_EQ(ui::SHOW_STATE_NORMAL, windows[0]->show_state); |
| 772 } | 731 } |
| 773 | 732 |
| 774 TEST_F(SessionServiceTest, KeepPostDataWithoutPasswords) { | 733 TEST_F(SessionServiceTest, KeepPostDataWithoutPasswords) { |
| 775 SessionID tab_id; | 734 SessionID tab_id; |
| 776 ASSERT_NE(window_id.id(), tab_id.id()); | 735 ASSERT_NE(window_id.id(), tab_id.id()); |
| 777 | 736 |
| 778 // Create a content state representing a HTTP body without posted passwords. | 737 // Create a content state representing a HTTP body without posted passwords. |
| 779 WebKit::WebHTTPBody http_body; | 738 WebKit::WebHTTPBody http_body; |
| 780 http_body.initialize(); | 739 http_body.initialize(); |
| 781 const char char_data[] = "data"; | 740 const char char_data[] = "data"; |
| 782 http_body.appendData(WebKit::WebData(char_data, sizeof(char_data)-1)); | 741 http_body.appendData(WebKit::WebData(char_data, sizeof(char_data)-1)); |
| 783 WebKit::WebHistoryItem history_item; | 742 WebKit::WebHistoryItem history_item; |
| 784 history_item.initialize(); | 743 history_item.initialize(); |
| 785 history_item.setHTTPBody(http_body); | 744 history_item.setHTTPBody(http_body); |
| 786 std::string content_state = webkit_glue::HistoryItemToString(history_item); | 745 std::string content_state = webkit_glue::HistoryItemToString(history_item); |
| 787 | 746 |
| 788 // Create a TabNavigation containing content_state and representing a POST | 747 // Create a TabNavigation containing content_state and representing a POST |
| 789 // request. | 748 // request. |
| 790 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), | 749 TabNavigation nav1 = |
| 791 ASCIIToUTF16("title"), content_state, | 750 TabNavigation::CreateForTest("http://google.com", "title"); |
| 792 content::PAGE_TRANSITION_QUALIFIER_MASK); | 751 nav1.SetContentStateForTest(content_state); |
| 793 nav1.set_type_mask(TabNavigation::HAS_POST_DATA); | 752 nav1.SetHasPostDataForTest(true); |
| 794 | 753 |
| 795 // Create a TabNavigation containing content_state and representing a normal | 754 // Create a TabNavigation containing content_state and representing a normal |
| 796 // request. | 755 // request. |
| 797 TabNavigation nav2(0, GURL("http://google.com/nopost"), content::Referrer(), | 756 TabNavigation nav2 = |
| 798 ASCIIToUTF16("title"), content_state, | 757 TabNavigation::CreateForTest("http://google.com/nopost", "title"); |
| 799 content::PAGE_TRANSITION_QUALIFIER_MASK); | 758 nav2.SetContentStateForTest(content_state); |
| 759 nav2.set_index(1); |
| 800 | 760 |
| 801 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 761 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 802 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 762 UpdateNavigation(window_id, tab_id, nav1, true); |
| 803 UpdateNavigation(window_id, tab_id, nav2, 1, true); | 763 UpdateNavigation(window_id, tab_id, nav2, true); |
| 804 | 764 |
| 805 ScopedVector<SessionWindow> windows; | 765 ScopedVector<SessionWindow> windows; |
| 806 ReadWindows(&(windows.get())); | 766 ReadWindows(&(windows.get())); |
| 807 | 767 |
| 808 helper_.AssertSingleWindowWithSingleTab(windows.get(), 2); | 768 helper_.AssertSingleWindowWithSingleTab(windows.get(), 2); |
| 809 | 769 |
| 810 // Expected: the content state of both navigations was saved and restored. | 770 // Expected: the content state of both navigations was saved and restored. |
| 771 ASSERT_EQ(2u, windows[0]->tabs[0]->navigations.size()); |
| 811 helper_.AssertNavigationEquals(nav1, windows[0]->tabs[0]->navigations[0]); | 772 helper_.AssertNavigationEquals(nav1, windows[0]->tabs[0]->navigations[0]); |
| 812 helper_.AssertNavigationEquals(nav2, windows[0]->tabs[0]->navigations[1]); | 773 helper_.AssertNavigationEquals(nav2, windows[0]->tabs[0]->navigations[1]); |
| 813 } | 774 } |
| 814 | 775 |
| 815 TEST_F(SessionServiceTest, RemovePostDataWithPasswords) { | 776 TEST_F(SessionServiceTest, RemovePostDataWithPasswords) { |
| 816 SessionID tab_id; | 777 SessionID tab_id; |
| 817 ASSERT_NE(window_id.id(), tab_id.id()); | 778 ASSERT_NE(window_id.id(), tab_id.id()); |
| 818 | 779 |
| 819 // Create a content state representing a HTTP body with posted passwords. | 780 // Create a content state representing a HTTP body with posted passwords. |
| 820 WebKit::WebHTTPBody http_body; | 781 WebKit::WebHTTPBody http_body; |
| 821 http_body.initialize(); | 782 http_body.initialize(); |
| 822 const char char_data[] = "data"; | 783 const char char_data[] = "data"; |
| 823 http_body.appendData(WebKit::WebData(char_data, sizeof(char_data)-1)); | 784 http_body.appendData(WebKit::WebData(char_data, sizeof(char_data)-1)); |
| 824 http_body.setContainsPasswordData(true); | 785 http_body.setContainsPasswordData(true); |
| 825 WebKit::WebHistoryItem history_item; | 786 WebKit::WebHistoryItem history_item; |
| 826 history_item.initialize(); | 787 history_item.initialize(); |
| 827 history_item.setHTTPBody(http_body); | 788 history_item.setHTTPBody(http_body); |
| 828 std::string content_state = webkit_glue::HistoryItemToString(history_item); | 789 std::string content_state = webkit_glue::HistoryItemToString(history_item); |
| 829 | 790 |
| 830 // Create a TabNavigation containing content_state and representing a POST | 791 // Create a TabNavigation containing content_state and representing a POST |
| 831 // request with passwords. | 792 // request with passwords. |
| 832 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), | 793 TabNavigation nav1 = |
| 833 ASCIIToUTF16("title"), content_state, | 794 TabNavigation::CreateForTest("http://google.com", "title"); |
| 834 content::PAGE_TRANSITION_QUALIFIER_MASK); | 795 nav1.SetContentStateForTest(content_state); |
| 835 nav1.set_type_mask(TabNavigation::HAS_POST_DATA); | 796 nav1.SetHasPostDataForTest(true); |
| 836 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 797 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 837 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 798 UpdateNavigation(window_id, tab_id, nav1, true); |
| 838 | 799 |
| 839 ScopedVector<SessionWindow> windows; | 800 ScopedVector<SessionWindow> windows; |
| 840 ReadWindows(&(windows.get())); | 801 ReadWindows(&(windows.get())); |
| 841 | 802 |
| 842 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); | 803 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); |
| 843 | 804 |
| 844 // Expected: the HTTP body was removed from the content state of the POST | 805 // Expected: the HTTP body was removed from the content state of the POST |
| 845 // navigation with passwords. | 806 // navigation with passwords. |
| 846 EXPECT_NE(content_state, windows[0]->tabs[0]->navigations[0].state()); | 807 EXPECT_NE(content_state, windows[0]->tabs[0]->navigations[0].content_state()); |
| 847 } | 808 } |
| 848 | 809 |
| 849 // This test is only applicable to chromeos. | 810 // This test is only applicable to chromeos. |
| 850 #if defined(OS_CHROMEOS) | 811 #if defined(OS_CHROMEOS) |
| 851 // Verifies migration of tab/window closed works. | 812 // Verifies migration of tab/window closed works. |
| 852 TEST_F(SessionServiceTest, CanOpenV1TabClosed) { | 813 TEST_F(SessionServiceTest, CanOpenV1TabClosed) { |
| 853 FilePath v1_file_path; | 814 FilePath v1_file_path; |
| 854 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &v1_file_path)); | 815 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &v1_file_path)); |
| 855 // v1_session_file contains a tab closed command with the original id. The | 816 // v1_session_file contains a tab closed command with the original id. The |
| 856 // file was generated from ClosingTabStaysClosed. If we successfully processed | 817 // file was generated from ClosingTabStaysClosed. If we successfully processed |
| 857 // the file we'll have one tab. | 818 // the file we'll have one tab. |
| 858 v1_file_path = | 819 v1_file_path = |
| 859 v1_file_path.AppendASCII("sessions").AppendASCII("v1_session_file"); | 820 v1_file_path.AppendASCII("sessions").AppendASCII("v1_session_file"); |
| 860 FilePath dest_file_path(path_); | 821 FilePath dest_file_path(path_); |
| 861 dest_file_path = dest_file_path.AppendASCII("Current Session"); | 822 dest_file_path = dest_file_path.AppendASCII("Current Session"); |
| 862 | 823 |
| 863 // Forces closing the file. | 824 // Forces closing the file. |
| 864 helper_.set_service(NULL); | 825 helper_.set_service(NULL); |
| 865 | 826 |
| 866 ASSERT_TRUE(file_util::CopyFile(v1_file_path, dest_file_path)); | 827 ASSERT_TRUE(file_util::CopyFile(v1_file_path, dest_file_path)); |
| 867 | 828 |
| 868 SessionService* session_service = new SessionService(path_); | 829 SessionService* session_service = new SessionService(path_); |
| 869 helper_.set_service(session_service); | 830 helper_.set_service(session_service); |
| 870 ScopedVector<SessionWindow> windows; | 831 ScopedVector<SessionWindow> windows; |
| 871 helper_.ReadWindows(&(windows.get())); | 832 helper_.ReadWindows(&(windows.get())); |
| 872 ASSERT_EQ(1u, windows.size()); | 833 ASSERT_EQ(1u, windows.size()); |
| 873 EXPECT_EQ(1u, windows[0]->tabs.size()); | 834 EXPECT_EQ(1u, windows[0]->tabs.size()); |
| 874 } | 835 } |
| 875 #endif | 836 #endif |
| OLD | NEW |