OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_number_conversions.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "chrome/browser/defaults.h" | 12 #include "chrome/browser/defaults.h" |
13 #include "chrome/browser/sessions/session_backend.h" | 13 #include "chrome/browser/sessions/session_backend.h" |
14 #include "chrome/browser/sessions/session_service.h" | 14 #include "chrome/browser/sessions/session_service.h" |
15 #include "chrome/browser/sessions/session_service_test_helper.h" | 15 #include "chrome/browser/sessions/session_service_test_helper.h" |
16 #include "chrome/browser/sessions/session_types.h" | 16 #include "chrome/browser/sessions/session_types.h" |
17 #include "chrome/browser/tab_contents/navigation_entry.h" | 17 #include "chrome/browser/tab_contents/navigation_entry.h" |
18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
19 #include "chrome/common/notification_observer.h" | 19 #include "chrome/common/notification_observer.h" |
20 #include "chrome/common/notification_registrar.h" | 20 #include "chrome/common/notification_registrar.h" |
21 #include "chrome/common/notification_service.h" | 21 #include "chrome/common/notification_service.h" |
22 #include "chrome/common/notification_type.h" | 22 #include "chrome/common/notification_type.h" |
23 #include "chrome/test/browser_with_test_window_test.h" | 23 #include "chrome/test/browser_with_test_window_test.h" |
24 #include "chrome/test/file_test_utils.h" | 24 #include "chrome/test/file_test_utils.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 | 26 |
27 class SessionServiceTest : public BrowserWithTestWindowTest, | 27 class SessionServiceTest : public BrowserWithTestWindowTest, |
28 public NotificationObserver { | 28 public NotificationObserver { |
29 public: | 29 public: |
30 SessionServiceTest() : window_bounds(0, 1, 2, 3), sync_save_count_(0){} | 30 SessionServiceTest() : window_bounds(0, 1, 2, 3), sync_save_count_(0){} |
31 | 31 |
32 protected: | 32 protected: |
33 virtual void SetUp() { | 33 virtual void SetUp() { |
34 BrowserWithTestWindowTest::SetUp(); | 34 BrowserWithTestWindowTest::SetUp(); |
35 std::string b = Int64ToString(base::Time::Now().ToInternalValue()); | 35 std::string b = base::Int64ToString(base::Time::Now().ToInternalValue()); |
36 | 36 |
37 PathService::Get(base::DIR_TEMP, &path_); | 37 PathService::Get(base::DIR_TEMP, &path_); |
38 path_ = path_.Append(FILE_PATH_LITERAL("SessionTestDirs")); | 38 path_ = path_.Append(FILE_PATH_LITERAL("SessionTestDirs")); |
39 file_util::CreateDirectory(path_); | 39 file_util::CreateDirectory(path_); |
40 path_deleter_.reset(new FileAutoDeleter(path_)); | 40 path_deleter_.reset(new FileAutoDeleter(path_)); |
41 path_ = path_.AppendASCII(b); | 41 path_ = path_.AppendASCII(b); |
42 | 42 |
43 SessionService* session_service = new SessionService(path_); | 43 SessionService* session_service = new SessionService(path_); |
44 helper_.set_service(session_service); | 44 helper_.set_service(session_service); |
45 | 45 |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 | 503 |
504 // Tests pruning from the front. | 504 // Tests pruning from the front. |
505 TEST_F(SessionServiceTest, PruneFromFront) { | 505 TEST_F(SessionServiceTest, PruneFromFront) { |
506 const std::string base_url("http://google.com/"); | 506 const std::string base_url("http://google.com/"); |
507 SessionID tab_id; | 507 SessionID tab_id; |
508 | 508 |
509 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 509 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
510 | 510 |
511 // Add 5 navigations, with the 4th selected. | 511 // Add 5 navigations, with the 4th selected. |
512 for (int i = 0; i < 5; ++i) { | 512 for (int i = 0; i < 5; ++i) { |
513 TabNavigation nav(0, GURL(base_url + IntToString(i)), GURL(), | 513 TabNavigation nav(0, GURL(base_url + base::IntToString(i)), GURL(), |
514 ASCIIToUTF16("a"), "b", PageTransition::QUALIFIER_MASK); | 514 ASCIIToUTF16("a"), "b", PageTransition::QUALIFIER_MASK); |
515 UpdateNavigation(window_id, tab_id, nav, i, (i == 3)); | 515 UpdateNavigation(window_id, tab_id, nav, i, (i == 3)); |
516 } | 516 } |
517 | 517 |
518 // Prune the first two navigations from the front. | 518 // Prune the first two navigations from the front. |
519 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 2); | 519 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 2); |
520 | 520 |
521 // Read back in. | 521 // Read back in. |
522 ScopedVector<SessionWindow> windows; | 522 ScopedVector<SessionWindow> windows; |
523 ReadWindows(&(windows.get())); | 523 ReadWindows(&(windows.get())); |
524 | 524 |
525 ASSERT_EQ(1U, windows->size()); | 525 ASSERT_EQ(1U, windows->size()); |
526 ASSERT_EQ(0, windows[0]->selected_tab_index); | 526 ASSERT_EQ(0, windows[0]->selected_tab_index); |
527 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); | 527 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); |
528 ASSERT_EQ(1U, windows[0]->tabs.size()); | 528 ASSERT_EQ(1U, windows[0]->tabs.size()); |
529 | 529 |
530 // There shouldn't be an app id. | 530 // There shouldn't be an app id. |
531 EXPECT_TRUE(windows[0]->tabs[0]->extension_app_id.empty()); | 531 EXPECT_TRUE(windows[0]->tabs[0]->extension_app_id.empty()); |
532 | 532 |
533 // We should be left with three navigations, the 2nd selected. | 533 // We should be left with three navigations, the 2nd selected. |
534 SessionTab* tab = windows[0]->tabs[0]; | 534 SessionTab* tab = windows[0]->tabs[0]; |
535 ASSERT_EQ(1, tab->current_navigation_index); | 535 ASSERT_EQ(1, tab->current_navigation_index); |
536 EXPECT_EQ(3U, tab->navigations.size()); | 536 EXPECT_EQ(3U, tab->navigations.size()); |
537 EXPECT_TRUE(GURL(base_url + IntToString(2)) == | 537 EXPECT_TRUE(GURL(base_url + base::IntToString(2)) == |
538 tab->navigations[0].virtual_url()); | 538 tab->navigations[0].virtual_url()); |
539 EXPECT_TRUE(GURL(base_url + IntToString(3)) == | 539 EXPECT_TRUE(GURL(base_url + base::IntToString(3)) == |
540 tab->navigations[1].virtual_url()); | 540 tab->navigations[1].virtual_url()); |
541 EXPECT_TRUE(GURL(base_url + IntToString(4)) == | 541 EXPECT_TRUE(GURL(base_url + base::IntToString(4)) == |
542 tab->navigations[2].virtual_url()); | 542 tab->navigations[2].virtual_url()); |
543 } | 543 } |
544 | 544 |
545 // Prunes from front so that we have no entries. | 545 // Prunes from front so that we have no entries. |
546 TEST_F(SessionServiceTest, PruneToEmpty) { | 546 TEST_F(SessionServiceTest, PruneToEmpty) { |
547 const std::string base_url("http://google.com/"); | 547 const std::string base_url("http://google.com/"); |
548 SessionID tab_id; | 548 SessionID tab_id; |
549 | 549 |
550 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 550 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
551 | 551 |
552 // Add 5 navigations, with the 4th selected. | 552 // Add 5 navigations, with the 4th selected. |
553 for (int i = 0; i < 5; ++i) { | 553 for (int i = 0; i < 5; ++i) { |
554 TabNavigation nav(0, GURL(base_url + IntToString(i)), GURL(), | 554 TabNavigation nav(0, GURL(base_url + base::IntToString(i)), GURL(), |
555 ASCIIToUTF16("a"), "b", PageTransition::QUALIFIER_MASK); | 555 ASCIIToUTF16("a"), "b", PageTransition::QUALIFIER_MASK); |
556 UpdateNavigation(window_id, tab_id, nav, i, (i == 3)); | 556 UpdateNavigation(window_id, tab_id, nav, i, (i == 3)); |
557 } | 557 } |
558 | 558 |
559 // Prune the first two navigations from the front. | 559 // Prune the first two navigations from the front. |
560 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 5); | 560 helper_.service()->TabNavigationPathPrunedFromFront(window_id, tab_id, 5); |
561 | 561 |
562 // Read back in. | 562 // Read back in. |
563 ScopedVector<SessionWindow> windows; | 563 ScopedVector<SessionWindow> windows; |
564 ReadWindows(&(windows.get())); | 564 ReadWindows(&(windows.get())); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 | 653 |
654 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 654 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
655 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 655 UpdateNavigation(window_id, tab_id, nav1, 0, true); |
656 service()->TabClosed(window_id, tab_id, true); | 656 service()->TabClosed(window_id, tab_id, true); |
657 | 657 |
658 ScopedVector<SessionWindow> windows; | 658 ScopedVector<SessionWindow> windows; |
659 ReadWindows(&(windows.get())); | 659 ReadWindows(&(windows.get())); |
660 | 660 |
661 ASSERT_TRUE(windows->empty()); | 661 ASSERT_TRUE(windows->empty()); |
662 } | 662 } |
OLD | NEW |