Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Side by Side Diff: chrome/browser/sessions/session_service_unittest.cc

Issue 7056011: Replace all usage of FileAutoDeleter with ScopedTempDir. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_paths.h" 19 #include "chrome/common/chrome_paths.h"
20 #include "chrome/test/browser_with_test_window_test.h" 20 #include "chrome/test/browser_with_test_window_test.h"
21 #include "chrome/test/file_test_utils.h"
22 #include "chrome/test/testing_profile.h" 21 #include "chrome/test/testing_profile.h"
23 #include "content/browser/tab_contents/navigation_entry.h" 22 #include "content/browser/tab_contents/navigation_entry.h"
24 #include "content/common/notification_observer.h" 23 #include "content/common/notification_observer.h"
25 #include "content/common/notification_registrar.h" 24 #include "content/common/notification_registrar.h"
26 #include "content/common/notification_service.h" 25 #include "content/common/notification_service.h"
27 #include "content/common/notification_type.h" 26 #include "content/common/notification_type.h"
28 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
29 28
30 class SessionServiceTest : public BrowserWithTestWindowTest, 29 class SessionServiceTest : public BrowserWithTestWindowTest,
31 public NotificationObserver { 30 public NotificationObserver {
32 public: 31 public:
33 SessionServiceTest() : window_bounds(0, 1, 2, 3), sync_save_count_(0){} 32 SessionServiceTest() : window_bounds(0, 1, 2, 3), sync_save_count_(0){}
34 33
35 protected: 34 protected:
36 virtual void SetUp() { 35 virtual void SetUp() {
37 BrowserWithTestWindowTest::SetUp(); 36 BrowserWithTestWindowTest::SetUp();
38 std::string b = base::Int64ToString(base::Time::Now().ToInternalValue()); 37 std::string b = base::Int64ToString(base::Time::Now().ToInternalValue());
39 38
40 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 39 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
41 path_ = temp_dir_.path().Append(FILE_PATH_LITERAL("SessionTestDirs")); 40 path_ = temp_dir_.path().Append(FILE_PATH_LITERAL("SessionTestDirs"));
42 file_util::CreateDirectory(path_); 41 file_util::CreateDirectory(path_);
Paweł Hajdan Jr. 2011/05/20 13:48:58 nit: Check return value.
lain Merrick 2011/05/20 14:23:32 Done.
43 path_deleter_.reset(new FileAutoDeleter(path_));
44 path_ = path_.AppendASCII(b); 42 path_ = path_.AppendASCII(b);
45 43
46 SessionService* session_service = new SessionService(path_); 44 SessionService* session_service = new SessionService(path_);
47 helper_.set_service(session_service); 45 helper_.set_service(session_service);
48 46
49 service()->SetWindowType(window_id, Browser::TYPE_TABBED); 47 service()->SetWindowType(window_id, Browser::TYPE_TABBED);
50 service()->SetWindowBounds(window_id, window_bounds, false); 48 service()->SetWindowBounds(window_id, window_bounds, false);
51 } 49 }
52 50
53 // Upon notification, increment the sync_save_count variable 51 // Upon notification, increment the sync_save_count variable
54 void Observe(NotificationType type, 52 void Observe(NotificationType type,
55 const NotificationSource& source, 53 const NotificationSource& source,
56 const NotificationDetails& details) { 54 const NotificationDetails& details) {
57 ASSERT_EQ(type.value, NotificationType::SESSION_SERVICE_SAVED); 55 ASSERT_EQ(type.value, NotificationType::SESSION_SERVICE_SAVED);
58 sync_save_count_++; 56 sync_save_count_++;
59 } 57 }
60 58
61 virtual void TearDown() { 59 virtual void TearDown() {
62 helper_.set_service(NULL); 60 helper_.set_service(NULL);
63 path_deleter_.reset();
64 } 61 }
65 62
66 void UpdateNavigation(const SessionID& window_id, 63 void UpdateNavigation(const SessionID& window_id,
67 const SessionID& tab_id, 64 const SessionID& tab_id,
68 const TabNavigation& navigation, 65 const TabNavigation& navigation,
69 int index, 66 int index,
70 bool select) { 67 bool select) {
71 NavigationEntry entry; 68 NavigationEntry entry;
72 entry.set_url(navigation.virtual_url()); 69 entry.set_url(navigation.virtual_url());
73 entry.set_referrer(navigation.referrer()); 70 entry.set_referrer(navigation.referrer());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 126
130 const gfx::Rect window_bounds; 127 const gfx::Rect window_bounds;
131 128
132 SessionID window_id; 129 SessionID window_id;
133 130
134 int sync_save_count_; 131 int sync_save_count_;
135 132
136 // Path used in testing. 133 // Path used in testing.
137 ScopedTempDir temp_dir_; 134 ScopedTempDir temp_dir_;
138 FilePath path_; 135 FilePath path_;
139 scoped_ptr<FileAutoDeleter> path_deleter_;
140 136
141 SessionServiceTestHelper helper_; 137 SessionServiceTestHelper helper_;
142 }; 138 };
143 139
144 TEST_F(SessionServiceTest, Basic) { 140 TEST_F(SessionServiceTest, Basic) {
145 SessionID tab_id; 141 SessionID tab_id;
146 ASSERT_NE(window_id.id(), tab_id.id()); 142 ASSERT_NE(window_id.id(), tab_id.id());
147 143
148 TabNavigation nav1(0, GURL("http://google.com"), 144 TabNavigation nav1(0, GURL("http://google.com"),
149 GURL("http://www.referrer.com"), 145 GURL("http://www.referrer.com"),
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 653
658 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 654 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
659 UpdateNavigation(window_id, tab_id, nav1, 0, true); 655 UpdateNavigation(window_id, tab_id, nav1, 0, true);
660 service()->TabClosed(window_id, tab_id, true); 656 service()->TabClosed(window_id, tab_id, true);
661 657
662 ScopedVector<SessionWindow> windows; 658 ScopedVector<SessionWindow> windows;
663 ReadWindows(&(windows.get())); 659 ReadWindows(&(windows.get()));
664 660
665 ASSERT_TRUE(windows->empty()); 661 ASSERT_TRUE(windows->empty());
666 } 662 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698