OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/defaults.h" | 14 #include "chrome/browser/defaults.h" |
15 #include "chrome/browser/sessions/session_backend.h" | 15 #include "chrome/browser/sessions/session_backend.h" |
16 #include "chrome/browser/sessions/session_service.h" | 16 #include "chrome/browser/sessions/session_service.h" |
17 #include "chrome/browser/sessions/session_service_test_helper.h" | 17 #include "chrome/browser/sessions/session_service_test_helper.h" |
18 #include "chrome/browser/sessions/session_types.h" | 18 #include "chrome/browser/sessions/session_types.h" |
| 19 #include "chrome/common/chrome_notification_types.h" |
19 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
20 #include "chrome/test/browser_with_test_window_test.h" | 21 #include "chrome/test/browser_with_test_window_test.h" |
21 #include "chrome/test/testing_profile.h" | 22 #include "chrome/test/testing_profile.h" |
22 #include "content/browser/tab_contents/navigation_entry.h" | 23 #include "content/browser/tab_contents/navigation_entry.h" |
23 #include "content/common/notification_observer.h" | 24 #include "content/common/notification_observer.h" |
24 #include "content/common/notification_registrar.h" | 25 #include "content/common/notification_registrar.h" |
25 #include "content/common/notification_service.h" | 26 #include "content/common/notification_service.h" |
26 #include "content/common/notification_type.h" | |
27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
28 | 28 |
29 class SessionServiceTest : public BrowserWithTestWindowTest, | 29 class SessionServiceTest : public BrowserWithTestWindowTest, |
30 public NotificationObserver { | 30 public NotificationObserver { |
31 public: | 31 public: |
32 SessionServiceTest() : window_bounds(0, 1, 2, 3), sync_save_count_(0){} | 32 SessionServiceTest() : window_bounds(0, 1, 2, 3), sync_save_count_(0){} |
33 | 33 |
34 protected: | 34 protected: |
35 virtual void SetUp() { | 35 virtual void SetUp() { |
36 BrowserWithTestWindowTest::SetUp(); | 36 BrowserWithTestWindowTest::SetUp(); |
37 std::string b = base::Int64ToString(base::Time::Now().ToInternalValue()); | 37 std::string b = base::Int64ToString(base::Time::Now().ToInternalValue()); |
38 | 38 |
39 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 39 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
40 path_ = temp_dir_.path().Append(FILE_PATH_LITERAL("SessionTestDirs")); | 40 path_ = temp_dir_.path().Append(FILE_PATH_LITERAL("SessionTestDirs")); |
41 ASSERT_TRUE(file_util::CreateDirectory(path_)); | 41 ASSERT_TRUE(file_util::CreateDirectory(path_)); |
42 path_ = path_.AppendASCII(b); | 42 path_ = path_.AppendASCII(b); |
43 | 43 |
44 SessionService* session_service = new SessionService(path_); | 44 SessionService* session_service = new SessionService(path_); |
45 helper_.set_service(session_service); | 45 helper_.set_service(session_service); |
46 | 46 |
47 service()->SetWindowType(window_id, Browser::TYPE_TABBED); | 47 service()->SetWindowType(window_id, Browser::TYPE_TABBED); |
48 service()->SetWindowBounds(window_id, window_bounds, false); | 48 service()->SetWindowBounds(window_id, window_bounds, false); |
49 } | 49 } |
50 | 50 |
51 // Upon notification, increment the sync_save_count variable | 51 // Upon notification, increment the sync_save_count variable |
52 void Observe(NotificationType type, | 52 void Observe(int type, |
53 const NotificationSource& source, | 53 const NotificationSource& source, |
54 const NotificationDetails& details) { | 54 const NotificationDetails& details) { |
55 ASSERT_EQ(type.value, NotificationType::SESSION_SERVICE_SAVED); | 55 ASSERT_EQ(type, chrome::NOTIFICATION_SESSION_SERVICE_SAVED); |
56 sync_save_count_++; | 56 sync_save_count_++; |
57 } | 57 } |
58 | 58 |
59 virtual void TearDown() { | 59 virtual void TearDown() { |
60 helper_.set_service(NULL); | 60 helper_.set_service(NULL); |
61 } | 61 } |
62 | 62 |
63 void UpdateNavigation(const SessionID& window_id, | 63 void UpdateNavigation(const SessionID& window_id, |
64 const SessionID& tab_id, | 64 const SessionID& tab_id, |
65 const TabNavigation& navigation, | 65 const TabNavigation& navigation, |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 | 628 |
629 CancelableRequestConsumer consumer; | 629 CancelableRequestConsumer consumer; |
630 GetCurrentSessionCallbackHandler handler; | 630 GetCurrentSessionCallbackHandler handler; |
631 service()->GetCurrentSession(&consumer, | 631 service()->GetCurrentSession(&consumer, |
632 NewCallback(&handler, &GetCurrentSessionCallbackHandler::OnGotSession)); | 632 NewCallback(&handler, &GetCurrentSessionCallbackHandler::OnGotSession)); |
633 } | 633 } |
634 | 634 |
635 // Test that the notification for SESSION_SERVICE_SAVED is working properly. | 635 // Test that the notification for SESSION_SERVICE_SAVED is working properly. |
636 TEST_F(SessionServiceTest, SavedSessionNotification) { | 636 TEST_F(SessionServiceTest, SavedSessionNotification) { |
637 NotificationRegistrar registrar_; | 637 NotificationRegistrar registrar_; |
638 registrar_.Add(this, NotificationType::SESSION_SERVICE_SAVED, | 638 registrar_.Add(this, chrome::NOTIFICATION_SESSION_SERVICE_SAVED, |
639 NotificationService::AllSources()); | 639 NotificationService::AllSources()); |
640 service()->Save(); | 640 service()->Save(); |
641 EXPECT_EQ(sync_save_count_, 1); | 641 EXPECT_EQ(sync_save_count_, 1); |
642 } | 642 } |
643 | 643 |
644 // Makes sure a tab closed by a user gesture is not restored. | 644 // Makes sure a tab closed by a user gesture is not restored. |
645 TEST_F(SessionServiceTest, CloseTabUserGesture) { | 645 TEST_F(SessionServiceTest, CloseTabUserGesture) { |
646 SessionID tab_id; | 646 SessionID tab_id; |
647 ASSERT_NE(window_id.id(), tab_id.id()); | 647 ASSERT_NE(window_id.id(), tab_id.id()); |
648 | 648 |
649 TabNavigation nav1(0, GURL("http://google.com"), | 649 TabNavigation nav1(0, GURL("http://google.com"), |
650 GURL("http://www.referrer.com"), | 650 GURL("http://www.referrer.com"), |
651 ASCIIToUTF16("abc"), "def", | 651 ASCIIToUTF16("abc"), "def", |
652 PageTransition::QUALIFIER_MASK); | 652 PageTransition::QUALIFIER_MASK); |
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 |