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/memory/scoped_temp_dir.h" |
8 #include "base/path_service.h" | 9 #include "base/path_service.h" |
9 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
10 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
11 #include "base/time.h" | 12 #include "base/time.h" |
12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/defaults.h" | 14 #include "chrome/browser/defaults.h" |
14 #include "chrome/browser/sessions/session_backend.h" | 15 #include "chrome/browser/sessions/session_backend.h" |
15 #include "chrome/browser/sessions/session_service.h" | 16 #include "chrome/browser/sessions/session_service.h" |
16 #include "chrome/browser/sessions/session_service_test_helper.h" | 17 #include "chrome/browser/sessions/session_service_test_helper.h" |
17 #include "chrome/browser/sessions/session_types.h" | 18 #include "chrome/browser/sessions/session_types.h" |
(...skipping 11 matching lines...) Expand all Loading... |
29 class SessionServiceTest : public BrowserWithTestWindowTest, | 30 class SessionServiceTest : public BrowserWithTestWindowTest, |
30 public NotificationObserver { | 31 public NotificationObserver { |
31 public: | 32 public: |
32 SessionServiceTest() : window_bounds(0, 1, 2, 3), sync_save_count_(0){} | 33 SessionServiceTest() : window_bounds(0, 1, 2, 3), sync_save_count_(0){} |
33 | 34 |
34 protected: | 35 protected: |
35 virtual void SetUp() { | 36 virtual void SetUp() { |
36 BrowserWithTestWindowTest::SetUp(); | 37 BrowserWithTestWindowTest::SetUp(); |
37 std::string b = base::Int64ToString(base::Time::Now().ToInternalValue()); | 38 std::string b = base::Int64ToString(base::Time::Now().ToInternalValue()); |
38 | 39 |
39 PathService::Get(base::DIR_TEMP, &path_); | 40 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
40 path_ = path_.Append(FILE_PATH_LITERAL("SessionTestDirs")); | 41 path_ = temp_dir_.path().Append(FILE_PATH_LITERAL("SessionTestDirs")); |
41 file_util::CreateDirectory(path_); | 42 file_util::CreateDirectory(path_); |
42 path_deleter_.reset(new FileAutoDeleter(path_)); | 43 path_deleter_.reset(new FileAutoDeleter(path_)); |
43 path_ = path_.AppendASCII(b); | 44 path_ = path_.AppendASCII(b); |
44 | 45 |
45 SessionService* session_service = new SessionService(path_); | 46 SessionService* session_service = new SessionService(path_); |
46 helper_.set_service(session_service); | 47 helper_.set_service(session_service); |
47 | 48 |
48 service()->SetWindowType(window_id, Browser::TYPE_NORMAL); | 49 service()->SetWindowType(window_id, Browser::TYPE_NORMAL); |
49 service()->SetWindowBounds(window_id, window_bounds, false); | 50 service()->SetWindowBounds(window_id, window_bounds, false); |
50 } | 51 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 127 |
127 SessionBackend* backend() { return helper_.backend(); } | 128 SessionBackend* backend() { return helper_.backend(); } |
128 | 129 |
129 const gfx::Rect window_bounds; | 130 const gfx::Rect window_bounds; |
130 | 131 |
131 SessionID window_id; | 132 SessionID window_id; |
132 | 133 |
133 int sync_save_count_; | 134 int sync_save_count_; |
134 | 135 |
135 // Path used in testing. | 136 // Path used in testing. |
| 137 ScopedTempDir temp_dir_; |
136 FilePath path_; | 138 FilePath path_; |
137 scoped_ptr<FileAutoDeleter> path_deleter_; | 139 scoped_ptr<FileAutoDeleter> path_deleter_; |
138 | 140 |
139 SessionServiceTestHelper helper_; | 141 SessionServiceTestHelper helper_; |
140 }; | 142 }; |
141 | 143 |
142 TEST_F(SessionServiceTest, Basic) { | 144 TEST_F(SessionServiceTest, Basic) { |
143 SessionID tab_id; | 145 SessionID tab_id; |
144 ASSERT_NE(window_id.id(), tab_id.id()); | 146 ASSERT_NE(window_id.id(), tab_id.id()); |
145 | 147 |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 | 657 |
656 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 658 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
657 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 659 UpdateNavigation(window_id, tab_id, nav1, 0, true); |
658 service()->TabClosed(window_id, tab_id, true); | 660 service()->TabClosed(window_id, tab_id, true); |
659 | 661 |
660 ScopedVector<SessionWindow> windows; | 662 ScopedVector<SessionWindow> windows; |
661 ReadWindows(&(windows.get())); | 663 ReadWindows(&(windows.get())); |
662 | 664 |
663 ASSERT_TRUE(windows->empty()); | 665 ASSERT_TRUE(windows->empty()); |
664 } | 666 } |
OLD | NEW |