| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| 11 #include "base/system_monitor/system_monitor.h" | 11 #include "base/system_monitor/system_monitor.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/extension_event_router_forwarder.h" |
| 14 #include "chrome/browser/io_thread.h" |
| 13 #include "chrome/browser/prefs/browser_prefs.h" | 15 #include "chrome/browser/prefs/browser_prefs.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/test/testing_browser_process_test.h" | 23 #include "chrome/test/testing_browser_process_test.h" |
| 22 #include "chrome/test/testing_pref_service.h" | 24 #include "chrome/test/testing_pref_service.h" |
| 23 #include "content/browser/browser_thread.h" | 25 #include "content/browser/browser_thread.h" |
| 24 #include "content/common/notification_service.h" | 26 #include "content/common/notification_service.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 // This global variable is used to check that value returned to different | 31 // This global variable is used to check that value returned to different |
| 30 // observers is the same. | 32 // observers is the same. |
| 31 Profile* g_created_profile; | 33 Profile* g_created_profile; |
| 32 | 34 |
| 33 } // namespace | 35 } // namespace |
| 34 | 36 |
| 35 class ProfileManagerTest : public TestingBrowserProcessTest { | 37 class ProfileManagerTest : public TestingBrowserProcessTest { |
| 36 protected: | 38 protected: |
| 37 ProfileManagerTest() | 39 ProfileManagerTest() |
| 38 : ui_thread_(BrowserThread::UI, &message_loop_), | 40 : local_state_(testing_browser_process_.get()), |
| 41 extension_event_router_forwarder_(new ExtensionEventRouterForwarder), |
| 42 ui_thread_(BrowserThread::UI, &message_loop_), |
| 43 db_thread_(BrowserThread::DB, &message_loop_), |
| 39 file_thread_(BrowserThread::FILE, &message_loop_), | 44 file_thread_(BrowserThread::FILE, &message_loop_), |
| 40 profile_manager_(new ProfileManagerWithoutInit), | 45 io_thread_(local_state_.Get(), NULL, extension_event_router_forwarder_), |
| 41 local_state_(testing_browser_process_.get()) { | 46 profile_manager_(new ProfileManagerWithoutInit) { |
| 42 #if defined(OS_MACOSX) | 47 #if defined(OS_MACOSX) |
| 43 base::SystemMonitor::AllocateSystemIOPorts(); | 48 base::SystemMonitor::AllocateSystemIOPorts(); |
| 44 #endif | 49 #endif |
| 45 system_monitor_dummy_.reset(new base::SystemMonitor); | 50 system_monitor_dummy_.reset(new base::SystemMonitor); |
| 51 testing_browser_process_.get()->SetIOThread(&io_thread_); |
| 46 } | 52 } |
| 47 | 53 |
| 48 virtual void SetUp() { | 54 virtual void SetUp() { |
| 49 // Create a new temporary directory, and store the path | 55 // Create a new temporary directory, and store the path |
| 50 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 56 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 51 } | 57 } |
| 52 | 58 |
| 53 virtual void TearDown() { | 59 virtual void TearDown() { |
| 54 profile_manager_.reset(); | 60 profile_manager_.reset(); |
| 61 message_loop_.RunAllPending(); |
| 55 } | 62 } |
| 56 | 63 |
| 57 class MockObserver : public ProfileManagerObserver { | 64 class MockObserver : public ProfileManagerObserver { |
| 58 public: | 65 public: |
| 59 MOCK_METHOD1(OnProfileCreated, void(Profile* profile)); | 66 MOCK_METHOD1(OnProfileCreated, void(Profile* profile)); |
| 60 }; | 67 }; |
| 61 | 68 |
| 62 // The path to temporary directory used to contain the test operations. | 69 // The path to temporary directory used to contain the test operations. |
| 63 ScopedTempDir temp_dir_; | 70 ScopedTempDir temp_dir_; |
| 71 ScopedTestingLocalState local_state_; |
| 72 scoped_refptr<ExtensionEventRouterForwarder> |
| 73 extension_event_router_forwarder_; |
| 64 | 74 |
| 65 MessageLoopForUI message_loop_; | 75 MessageLoopForUI message_loop_; |
| 66 BrowserThread ui_thread_; | 76 BrowserThread ui_thread_; |
| 77 BrowserThread db_thread_; |
| 67 BrowserThread file_thread_; | 78 BrowserThread file_thread_; |
| 79 IOThread io_thread_; |
| 68 | 80 |
| 69 scoped_ptr<base::SystemMonitor> system_monitor_dummy_; | 81 scoped_ptr<base::SystemMonitor> system_monitor_dummy_; |
| 70 | 82 |
| 71 // Also will test profile deletion. | 83 // Also will test profile deletion. |
| 72 scoped_ptr<ProfileManager> profile_manager_; | 84 scoped_ptr<ProfileManager> profile_manager_; |
| 73 | |
| 74 ScopedTestingLocalState local_state_; | |
| 75 }; | 85 }; |
| 76 | 86 |
| 77 TEST_F(ProfileManagerTest, GetProfile) { | 87 TEST_F(ProfileManagerTest, GetProfile) { |
| 78 FilePath dest_path = temp_dir_.path(); | 88 FilePath dest_path = temp_dir_.path(); |
| 79 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); | 89 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); |
| 80 | 90 |
| 81 Profile* profile; | 91 Profile* profile; |
| 82 | 92 |
| 83 // Successfully create a profile. | 93 // Successfully create a profile. |
| 84 profile = profile_manager_->GetProfile(dest_path); | 94 profile = profile_manager_->GetProfile(dest_path); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); | 237 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); |
| 228 | 238 |
| 229 MockObserver mock_observer; | 239 MockObserver mock_observer; |
| 230 EXPECT_CALL(mock_observer, OnProfileCreated(testing::NotNull())).Times(2); | 240 EXPECT_CALL(mock_observer, OnProfileCreated(testing::NotNull())).Times(2); |
| 231 | 241 |
| 232 profile_manager_->CreateProfileAsync(dest_path1, &mock_observer); | 242 profile_manager_->CreateProfileAsync(dest_path1, &mock_observer); |
| 233 profile_manager_->CreateProfileAsync(dest_path2, &mock_observer); | 243 profile_manager_->CreateProfileAsync(dest_path2, &mock_observer); |
| 234 | 244 |
| 235 message_loop_.RunAllPending(); | 245 message_loop_.RunAllPending(); |
| 236 } | 246 } |
| OLD | NEW |