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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 virtual Profile* CreateProfileAsyncHelper(const FilePath& path, | 71 virtual Profile* CreateProfileAsyncHelper(const FilePath& path, |
72 Delegate* delegate) OVERRIDE { | 72 Delegate* delegate) OVERRIDE { |
73 // This is safe while all file operations are done on the FILE thread. | 73 // This is safe while all file operations are done on the FILE thread. |
74 BrowserThread::PostTask( | 74 BrowserThread::PostTask( |
75 BrowserThread::FILE, FROM_HERE, | 75 BrowserThread::FILE, FROM_HERE, |
76 base::Bind(base::IgnoreResult(&file_util::CreateDirectory), path)); | 76 base::Bind(base::IgnoreResult(&file_util::CreateDirectory), path)); |
77 | 77 |
78 return new TestingProfile(path, this); | 78 return new TestingProfile(path, this); |
79 } | 79 } |
80 | |
81 #if defined(OS_WIN) | |
82 virtual ProfileShortcutManagerWin* CreateShortcutManager() OVERRIDE { | |
83 // We should avoid creating shortcuts in these tests. | |
84 return NULL; | |
85 } | |
86 #endif | |
87 }; | 80 }; |
88 | 81 |
89 } // namespace testing | 82 } // namespace testing |
90 | 83 |
91 class ProfileManagerTest : public testing::Test { | 84 class ProfileManagerTest : public testing::Test { |
92 protected: | 85 protected: |
93 class MockObserver { | 86 class MockObserver { |
94 public: | 87 public: |
95 MOCK_METHOD2(OnProfileCreated, | 88 MOCK_METHOD2(OnProfileCreated, |
96 void(Profile* profile, Profile::CreateStatus status)); | 89 void(Profile* profile, Profile::CreateStatus status)); |
(...skipping 13 matching lines...) Expand all Loading... |
110 system_monitor_dummy_.reset(new base::SystemMonitor); | 103 system_monitor_dummy_.reset(new base::SystemMonitor); |
111 static_cast<TestingBrowserProcess*>(g_browser_process)->SetIOThread( | 104 static_cast<TestingBrowserProcess*>(g_browser_process)->SetIOThread( |
112 &io_thread_); | 105 &io_thread_); |
113 } | 106 } |
114 | 107 |
115 virtual void SetUp() { | 108 virtual void SetUp() { |
116 // Create a new temporary directory, and store the path | 109 // Create a new temporary directory, and store the path |
117 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 110 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
118 static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager( | 111 static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager( |
119 new testing::ProfileManager(temp_dir_.path())); | 112 new testing::ProfileManager(temp_dir_.path())); |
| 113 |
120 #if defined(OS_CHROMEOS) | 114 #if defined(OS_CHROMEOS) |
121 CommandLine *cl = CommandLine::ForCurrentProcess(); | 115 CommandLine* cl = CommandLine::ForCurrentProcess(); |
122 cl->AppendSwitch(switches::kTestType); | 116 cl->AppendSwitch(switches::kTestType); |
123 #endif | 117 #endif |
124 } | 118 } |
125 | 119 |
126 virtual void TearDown() { | 120 virtual void TearDown() { |
127 static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager( | 121 static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager( |
128 NULL); | 122 NULL); |
129 message_loop_.RunAllPending(); | 123 message_loop_.RunAllPending(); |
130 } | 124 } |
131 | 125 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 EXPECT_CALL(mock_observer2, OnProfileCreated( | 274 EXPECT_CALL(mock_observer2, OnProfileCreated( |
281 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 275 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
282 MockObserver mock_observer3; | 276 MockObserver mock_observer3; |
283 EXPECT_CALL(mock_observer3, OnProfileCreated( | 277 EXPECT_CALL(mock_observer3, OnProfileCreated( |
284 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 278 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
285 | 279 |
286 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 280 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
287 | 281 |
288 profile_manager->CreateProfileAsync(dest_path, | 282 profile_manager->CreateProfileAsync(dest_path, |
289 base::Bind(&MockObserver::OnProfileCreated, | 283 base::Bind(&MockObserver::OnProfileCreated, |
290 base::Unretained(&mock_observer1)), string16(), string16()); | 284 base::Unretained(&mock_observer1)), |
| 285 string16(), string16()); |
291 profile_manager->CreateProfileAsync(dest_path, | 286 profile_manager->CreateProfileAsync(dest_path, |
292 base::Bind(&MockObserver::OnProfileCreated, | 287 base::Bind(&MockObserver::OnProfileCreated, |
293 base::Unretained(&mock_observer2)), string16(), string16()); | 288 base::Unretained(&mock_observer2)), |
| 289 string16(), string16()); |
294 profile_manager->CreateProfileAsync(dest_path, | 290 profile_manager->CreateProfileAsync(dest_path, |
295 base::Bind(&MockObserver::OnProfileCreated, | 291 base::Bind(&MockObserver::OnProfileCreated, |
296 base::Unretained(&mock_observer3)), string16(), string16()); | 292 base::Unretained(&mock_observer3)), |
| 293 string16(), string16()); |
297 | 294 |
298 message_loop_.RunAllPending(); | 295 message_loop_.RunAllPending(); |
299 } | 296 } |
300 | 297 |
301 TEST_F(ProfileManagerTest, CreateProfilesAsync) { | 298 TEST_F(ProfileManagerTest, CreateProfilesAsync) { |
302 FilePath dest_path1 = | 299 FilePath dest_path1 = |
303 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 1")); | 300 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 1")); |
304 FilePath dest_path2 = | 301 FilePath dest_path2 = |
305 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); | 302 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); |
306 | 303 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 browser2b.reset(); | 559 browser2b.reset(); |
563 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 560 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
564 ASSERT_EQ(1U, last_opened_profiles.size()); | 561 ASSERT_EQ(1U, last_opened_profiles.size()); |
565 EXPECT_EQ(profile1, last_opened_profiles[0]); | 562 EXPECT_EQ(profile1, last_opened_profiles[0]); |
566 | 563 |
567 browser1.reset(); | 564 browser1.reset(); |
568 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 565 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
569 ASSERT_EQ(0U, last_opened_profiles.size()); | 566 ASSERT_EQ(0U, last_opened_profiles.size()); |
570 } | 567 } |
571 #endif // !defined(OS_ANDROID) | 568 #endif // !defined(OS_ANDROID) |
OLD | NEW |