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 | |
403 SessionID window2_id; | 400 SessionID window2_id; |
404 SessionID tab_id; | 401 SessionID tab_id; |
405 SessionID tab2_id; | 402 SessionID tab2_id; |
406 ASSERT_NE(window2_id.id(), window_id.id()); | 403 ASSERT_NE(window2_id.id(), window_id.id()); |
407 | 404 |
408 service()->SetWindowType(window2_id, Browser::TYPE_POPUP); | 405 service()->SetWindowType(window2_id, Browser::TYPE_POPUP); |
409 service()->SetWindowBounds(window2_id, window_bounds, false); | 406 service()->SetWindowBounds(window2_id, window_bounds, false); |
410 | 407 |
411 TabNavigation nav1(0, GURL("http://google.com"), GURL(), | 408 TabNavigation nav1(0, GURL("http://google.com"), GURL(), |
412 ASCIIToUTF16("abc"), "def", | 409 ASCIIToUTF16("abc"), "def", |
(...skipping 14 matching lines...) Expand all Loading... |
427 ASSERT_EQ(1U, windows->size()); | 424 ASSERT_EQ(1U, windows->size()); |
428 ASSERT_EQ(0, windows[0]->selected_tab_index); | 425 ASSERT_EQ(0, windows[0]->selected_tab_index); |
429 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); | 426 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); |
430 ASSERT_EQ(1U, windows[0]->tabs.size()); | 427 ASSERT_EQ(1U, windows[0]->tabs.size()); |
431 | 428 |
432 SessionTab* tab = windows[0]->tabs[0]; | 429 SessionTab* tab = windows[0]->tabs[0]; |
433 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); | 430 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); |
434 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); | 431 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); |
435 } | 432 } |
436 | 433 |
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 | |
487 // Tests pruning from the front. | 434 // Tests pruning from the front. |
488 TEST_F(SessionServiceTest, PruneFromFront) { | 435 TEST_F(SessionServiceTest, PruneFromFront) { |
489 const std::string base_url("http://google.com/"); | 436 const std::string base_url("http://google.com/"); |
490 SessionID tab_id; | 437 SessionID tab_id; |
491 | 438 |
492 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 439 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
493 | 440 |
494 // Add 5 navigations, with the 4th selected. | 441 // Add 5 navigations, with the 4th selected. |
495 for (int i = 0; i < 5; ++i) { | 442 for (int i = 0; i < 5; ++i) { |
496 TabNavigation nav(0, GURL(base_url + IntToString(i)), GURL(), | 443 TabNavigation nav(0, GURL(base_url + IntToString(i)), GURL(), |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 | 497 |
551 // Explicitly set the pinned state to false and make sure we get back false. | 498 // Explicitly set the pinned state to false and make sure we get back false. |
552 TEST_F(SessionServiceTest, PinnedFalseWhenSetToFalse) { | 499 TEST_F(SessionServiceTest, PinnedFalseWhenSetToFalse) { |
553 EXPECT_FALSE(CreateAndWriteSessionWithOneTab(false, true)); | 500 EXPECT_FALSE(CreateAndWriteSessionWithOneTab(false, true)); |
554 } | 501 } |
555 | 502 |
556 // Explicitly set the pinned state to false and make sure we get back true. | 503 // Explicitly set the pinned state to false and make sure we get back true. |
557 TEST_F(SessionServiceTest, PinnedTrue) { | 504 TEST_F(SessionServiceTest, PinnedTrue) { |
558 EXPECT_TRUE(CreateAndWriteSessionWithOneTab(true, true)); | 505 EXPECT_TRUE(CreateAndWriteSessionWithOneTab(true, true)); |
559 } | 506 } |
OLD | NEW |