| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "base/scoped_vector.h" | 8 #include "base/scoped_vector.h" |
| 9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); | 390 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); |
| 391 ASSERT_EQ(1U, windows[0]->tabs.size()); | 391 ASSERT_EQ(1U, windows[0]->tabs.size()); |
| 392 | 392 |
| 393 SessionTab* tab = windows[0]->tabs[0]; | 393 SessionTab* tab = windows[0]->tabs[0]; |
| 394 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); | 394 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); |
| 395 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); | 395 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); |
| 396 } | 396 } |
| 397 | 397 |
| 398 // Makes sure we don't track popups. | 398 // Makes sure we don't track popups. |
| 399 TEST_F(SessionServiceTest, IgnorePopups) { | 399 TEST_F(SessionServiceTest, IgnorePopups) { |
| 400 if (browser_defaults::kRestorePopups) |
| 401 return; // This test is only applicable if popups aren't restored. |
| 402 |
| 400 SessionID window2_id; | 403 SessionID window2_id; |
| 401 SessionID tab_id; | 404 SessionID tab_id; |
| 402 SessionID tab2_id; | 405 SessionID tab2_id; |
| 403 ASSERT_NE(window2_id.id(), window_id.id()); | 406 ASSERT_NE(window2_id.id(), window_id.id()); |
| 404 | 407 |
| 405 service()->SetWindowType(window2_id, Browser::TYPE_POPUP); | 408 service()->SetWindowType(window2_id, Browser::TYPE_POPUP); |
| 406 service()->SetWindowBounds(window2_id, window_bounds, false); | 409 service()->SetWindowBounds(window2_id, window_bounds, false); |
| 407 | 410 |
| 408 TabNavigation nav1(0, GURL("http://google.com"), GURL(), | 411 TabNavigation nav1(0, GURL("http://google.com"), GURL(), |
| 409 ASCIIToUTF16("abc"), "def", | 412 ASCIIToUTF16("abc"), "def", |
| (...skipping 14 matching lines...) Expand all Loading... |
| 424 ASSERT_EQ(1U, windows->size()); | 427 ASSERT_EQ(1U, windows->size()); |
| 425 ASSERT_EQ(0, windows[0]->selected_tab_index); | 428 ASSERT_EQ(0, windows[0]->selected_tab_index); |
| 426 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); | 429 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); |
| 427 ASSERT_EQ(1U, windows[0]->tabs.size()); | 430 ASSERT_EQ(1U, windows[0]->tabs.size()); |
| 428 | 431 |
| 429 SessionTab* tab = windows[0]->tabs[0]; | 432 SessionTab* tab = windows[0]->tabs[0]; |
| 430 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); | 433 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); |
| 431 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); | 434 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); |
| 432 } | 435 } |
| 433 | 436 |
| 437 // Makes sure we track popups. |
| 438 TEST_F(SessionServiceTest, RestorePopup) { |
| 439 if (!browser_defaults::kRestorePopups) |
| 440 return; // This test is only applicable if popups are restored. |
| 441 |
| 442 SessionID window2_id; |
| 443 SessionID tab_id; |
| 444 SessionID tab2_id; |
| 445 ASSERT_NE(window2_id.id(), window_id.id()); |
| 446 |
| 447 service()->SetWindowType(window2_id, Browser::TYPE_POPUP); |
| 448 service()->SetWindowBounds(window2_id, window_bounds, false); |
| 449 |
| 450 TabNavigation nav1(0, GURL("http://google.com"), GURL(), |
| 451 ASCIIToUTF16("abc"), "def", |
| 452 PageTransition::QUALIFIER_MASK); |
| 453 TabNavigation nav2(0, GURL("http://google2.com"), GURL(), |
| 454 ASCIIToUTF16("abcd"), "defg", |
| 455 PageTransition::AUTO_BOOKMARK); |
| 456 |
| 457 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 458 UpdateNavigation(window_id, tab_id, nav1, 0, true); |
| 459 |
| 460 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); |
| 461 UpdateNavigation(window2_id, tab2_id, nav2, 0, true); |
| 462 |
| 463 ScopedVector<SessionWindow> windows; |
| 464 ReadWindows(&(windows.get())); |
| 465 |
| 466 ASSERT_EQ(2U, windows->size()); |
| 467 int normal_index = windows[0]->type == Browser::TYPE_NORMAL ? |
| 468 0 : 1; |
| 469 int popup_index = normal_index == 0 ? 1 : 0; |
| 470 ASSERT_EQ(0, windows[normal_index]->selected_tab_index); |
| 471 ASSERT_EQ(window_id.id(), windows[normal_index]->window_id.id()); |
| 472 ASSERT_EQ(1U, windows[normal_index]->tabs.size()); |
| 473 |
| 474 SessionTab* tab = windows[normal_index]->tabs[0]; |
| 475 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); |
| 476 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); |
| 477 |
| 478 ASSERT_EQ(0, windows[popup_index]->selected_tab_index); |
| 479 ASSERT_EQ(window2_id.id(), windows[popup_index]->window_id.id()); |
| 480 ASSERT_EQ(1U, windows[popup_index]->tabs.size()); |
| 481 |
| 482 tab = windows[popup_index]->tabs[0]; |
| 483 helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab); |
| 484 helper_.AssertNavigationEquals(nav2, tab->navigations[0]); |
| 485 } |
| 486 |
| 434 // Tests pruning from the front. | 487 // Tests pruning from the front. |
| 435 TEST_F(SessionServiceTest, PruneFromFront) { | 488 TEST_F(SessionServiceTest, PruneFromFront) { |
| 436 const std::string base_url("http://google.com/"); | 489 const std::string base_url("http://google.com/"); |
| 437 SessionID tab_id; | 490 SessionID tab_id; |
| 438 | 491 |
| 439 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 492 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 440 | 493 |
| 441 // Add 5 navigations, with the 4th selected. | 494 // Add 5 navigations, with the 4th selected. |
| 442 for (int i = 0; i < 5; ++i) { | 495 for (int i = 0; i < 5; ++i) { |
| 443 TabNavigation nav(0, GURL(base_url + IntToString(i)), GURL(), | 496 TabNavigation nav(0, GURL(base_url + IntToString(i)), GURL(), |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 | 550 |
| 498 // Explicitly set the pinned state to false and make sure we get back false. | 551 // Explicitly set the pinned state to false and make sure we get back false. |
| 499 TEST_F(SessionServiceTest, PinnedFalseWhenSetToFalse) { | 552 TEST_F(SessionServiceTest, PinnedFalseWhenSetToFalse) { |
| 500 EXPECT_FALSE(CreateAndWriteSessionWithOneTab(false, true)); | 553 EXPECT_FALSE(CreateAndWriteSessionWithOneTab(false, true)); |
| 501 } | 554 } |
| 502 | 555 |
| 503 // Explicitly set the pinned state to false and make sure we get back true. | 556 // Explicitly set the pinned state to false and make sure we get back true. |
| 504 TEST_F(SessionServiceTest, PinnedTrue) { | 557 TEST_F(SessionServiceTest, PinnedTrue) { |
| 505 EXPECT_TRUE(CreateAndWriteSessionWithOneTab(true, true)); | 558 EXPECT_TRUE(CreateAndWriteSessionWithOneTab(true, true)); |
| 506 } | 559 } |
| OLD | NEW |