| 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/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 virtual void SetUp() { | 43 virtual void SetUp() { |
| 44 BrowserWithTestWindowTest::SetUp(); | 44 BrowserWithTestWindowTest::SetUp(); |
| 45 std::string b = base::Int64ToString(base::Time::Now().ToInternalValue()); | 45 std::string b = base::Int64ToString(base::Time::Now().ToInternalValue()); |
| 46 | 46 |
| 47 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 47 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 48 path_ = temp_dir_.path().Append(FILE_PATH_LITERAL("SessionTestDirs")); | 48 path_ = temp_dir_.path().Append(FILE_PATH_LITERAL("SessionTestDirs")); |
| 49 ASSERT_TRUE(file_util::CreateDirectory(path_)); | 49 ASSERT_TRUE(file_util::CreateDirectory(path_)); |
| 50 path_ = path_.AppendASCII(b); | 50 path_ = path_.AppendASCII(b); |
| 51 | 51 |
| 52 SessionService* session_service = new SessionService(path_); | 52 SessionService* session_service = new SessionService(path_); |
| 53 helper_.set_service(session_service); | 53 helper_.SetService(session_service); |
| 54 | 54 |
| 55 service()->SetWindowType( | 55 service()->SetWindowType( |
| 56 window_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); | 56 window_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); |
| 57 service()->SetWindowBounds(window_id, | 57 service()->SetWindowBounds(window_id, |
| 58 window_bounds, | 58 window_bounds, |
| 59 ui::SHOW_STATE_NORMAL); | 59 ui::SHOW_STATE_NORMAL); |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Upon notification, increment the sync_save_count variable | 62 // Upon notification, increment the sync_save_count variable |
| 63 virtual void Observe(int type, | 63 virtual void Observe(int type, |
| 64 const content::NotificationSource& source, | 64 const content::NotificationSource& source, |
| 65 const content::NotificationDetails& details) OVERRIDE { | 65 const content::NotificationDetails& details) OVERRIDE { |
| 66 ASSERT_EQ(type, chrome::NOTIFICATION_SESSION_SERVICE_SAVED); | 66 ASSERT_EQ(type, chrome::NOTIFICATION_SESSION_SERVICE_SAVED); |
| 67 sync_save_count_++; | 67 sync_save_count_++; |
| 68 } | 68 } |
| 69 | 69 |
| 70 virtual void TearDown() { | 70 virtual void TearDown() { |
| 71 helper_.set_service(NULL); | 71 helper_.SetService(NULL); |
| 72 BrowserWithTestWindowTest::TearDown(); | 72 BrowserWithTestWindowTest::TearDown(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void UpdateNavigation( | 75 void UpdateNavigation( |
| 76 const SessionID& window_id, | 76 const SessionID& window_id, |
| 77 const SessionID& tab_id, | 77 const SessionID& tab_id, |
| 78 const SerializedNavigationEntry& navigation, | 78 const SerializedNavigationEntry& navigation, |
| 79 bool select) { | 79 bool select) { |
| 80 service()->UpdateTabNavigation(window_id, tab_id, navigation); | 80 service()->UpdateTabNavigation(window_id, tab_id, navigation); |
| 81 if (select) { | 81 if (select) { |
| 82 service()->SetSelectedNavigationIndex( | 82 service()->SetSelectedNavigationIndex( |
| 83 window_id, tab_id, navigation.index()); | 83 window_id, tab_id, navigation.index()); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 void ReadWindows(std::vector<SessionWindow*>* windows, | 87 void ReadWindows(std::vector<SessionWindow*>* windows, |
| 88 SessionID::id_type* active_window_id) { | 88 SessionID::id_type* active_window_id) { |
| 89 // Forces closing the file. | 89 // Forces closing the file. |
| 90 helper_.set_service(NULL); | 90 helper_.SetService(NULL); |
| 91 | 91 |
| 92 SessionService* session_service = new SessionService(path_); | 92 SessionService* session_service = new SessionService(path_); |
| 93 helper_.set_service(session_service); | 93 helper_.SetService(session_service); |
| 94 | 94 |
| 95 SessionID::id_type* non_null_active_window_id = active_window_id; | 95 SessionID::id_type* non_null_active_window_id = active_window_id; |
| 96 SessionID::id_type dummy_active_window_id = 0; | 96 SessionID::id_type dummy_active_window_id = 0; |
| 97 if (!non_null_active_window_id) | 97 if (!non_null_active_window_id) |
| 98 non_null_active_window_id = &dummy_active_window_id; | 98 non_null_active_window_id = &dummy_active_window_id; |
| 99 helper_.ReadWindows(windows, non_null_active_window_id); | 99 helper_.ReadWindows(windows, non_null_active_window_id); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Configures the session service with one window with one tab and a single | 102 // Configures the session service with one window with one tab and a single |
| 103 // navigation. If |pinned_state| is true or |write_always| is true, the | 103 // navigation. If |pinned_state| is true or |write_always| is true, the |
| (...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &v1_file_path)); | 849 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &v1_file_path)); |
| 850 // v1_session_file contains a tab closed command with the original id. The | 850 // v1_session_file contains a tab closed command with the original id. The |
| 851 // file was generated from ClosingTabStaysClosed. If we successfully processed | 851 // file was generated from ClosingTabStaysClosed. If we successfully processed |
| 852 // the file we'll have one tab. | 852 // the file we'll have one tab. |
| 853 v1_file_path = | 853 v1_file_path = |
| 854 v1_file_path.AppendASCII("sessions").AppendASCII("v1_session_file"); | 854 v1_file_path.AppendASCII("sessions").AppendASCII("v1_session_file"); |
| 855 base::FilePath dest_file_path(path_); | 855 base::FilePath dest_file_path(path_); |
| 856 dest_file_path = dest_file_path.AppendASCII("Current Session"); | 856 dest_file_path = dest_file_path.AppendASCII("Current Session"); |
| 857 | 857 |
| 858 // Forces closing the file. | 858 // Forces closing the file. |
| 859 helper_.set_service(NULL); | 859 helper_.SetService(NULL); |
| 860 | 860 |
| 861 ASSERT_TRUE(base::CopyFile(v1_file_path, dest_file_path)); | 861 ASSERT_TRUE(base::CopyFile(v1_file_path, dest_file_path)); |
| 862 | 862 |
| 863 SessionService* session_service = new SessionService(path_); | 863 SessionService* session_service = new SessionService(path_); |
| 864 helper_.set_service(session_service); | 864 helper_.SetService(session_service); |
| 865 ScopedVector<SessionWindow> windows; | 865 ScopedVector<SessionWindow> windows; |
| 866 SessionID::id_type active_window_id = 0; | 866 SessionID::id_type active_window_id = 0; |
| 867 helper_.ReadWindows(&(windows.get()), &active_window_id); | 867 helper_.ReadWindows(&(windows.get()), &active_window_id); |
| 868 ASSERT_EQ(1u, windows.size()); | 868 ASSERT_EQ(1u, windows.size()); |
| 869 EXPECT_EQ(1u, windows[0]->tabs.size()); | 869 EXPECT_EQ(1u, windows[0]->tabs.size()); |
| 870 } | 870 } |
| 871 #endif // defined(OS_CHROMEOS) | 871 #endif // defined(OS_CHROMEOS) |
| 872 | 872 |
| 873 TEST_F(SessionServiceTest, ReplacePendingNavigation) { | 873 TEST_F(SessionServiceTest, ReplacePendingNavigation) { |
| 874 const std::string base_url("http://google.com/"); | 874 const std::string base_url("http://google.com/"); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 service()->ScheduleCommand( | 976 service()->ScheduleCommand( |
| 977 service()->CreateSetActiveWindowCommand(window_id)); | 977 service()->CreateSetActiveWindowCommand(window_id)); |
| 978 service()->ScheduleCommand( | 978 service()->ScheduleCommand( |
| 979 service()->CreateSetActiveWindowCommand(window2_id)); | 979 service()->CreateSetActiveWindowCommand(window2_id)); |
| 980 | 980 |
| 981 ScopedVector<SessionWindow> windows; | 981 ScopedVector<SessionWindow> windows; |
| 982 SessionID::id_type active_window_id = 0; | 982 SessionID::id_type active_window_id = 0; |
| 983 ReadWindows(&(windows.get()), &active_window_id); | 983 ReadWindows(&(windows.get()), &active_window_id); |
| 984 EXPECT_EQ(window2_id.id(), active_window_id); | 984 EXPECT_EQ(window2_id.id(), active_window_id); |
| 985 } | 985 } |
| OLD | NEW |