| 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" | 13 #include "chrome/browser/extensions/extension_event_router_forwarder.h" |
| 14 #include "chrome/browser/io_thread.h" | 14 #include "chrome/browser/io_thread.h" |
| 15 #include "chrome/browser/net/predictor.h" |
| 15 #include "chrome/browser/prefs/browser_prefs.h" | 16 #include "chrome/browser/prefs/browser_prefs.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
| 21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/test/base/testing_browser_process_test.h" | 24 #include "chrome/test/base/testing_browser_process_test.h" |
| 24 #include "chrome/test/base/testing_pref_service.h" | 25 #include "chrome/test/base/testing_pref_service.h" |
| 25 #include "content/browser/browser_thread.h" | 26 #include "content/browser/browser_thread.h" |
| 26 #include "content/common/notification_service.h" | 27 #include "content/common/notification_service.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 // This global variable is used to check that value returned to different | 32 // This global variable is used to check that value returned to different |
| 32 // observers is the same. | 33 // observers is the same. |
| 33 Profile* g_created_profile; | 34 Profile* g_created_profile; |
| 34 | 35 |
| 35 } // namespace | 36 } // namespace |
| 36 | 37 |
| 38 class MockPredictor : public chrome_browser_net::Predictor { |
| 39 public: |
| 40 MOCK_METHOD1(InitNetworkPredictor, void(PrefService* prefs)); |
| 41 MOCK_METHOD2(AnticipateOmniboxUrl, void(const GURL&, bool)); |
| 42 MOCK_METHOD1(PreconnectUrlAndSubresources, void(const GURL&)); |
| 43 MOCK_METHOD1(PredictFrameSubresources, void(const GURL&)); |
| 44 MOCK_METHOD1(ShutdownOnUIThread, void(PrefService* prefs)); |
| 45 MOCK_METHOD0(DiscardAllResults, void()); |
| 46 MOCK_METHOD2(ResolveList, |
| 47 void(const chrome_common_net::UrlList&, |
| 48 chrome_browser_net::UrlInfo::ResolutionMotivation)); |
| 49 MOCK_METHOD2(Resolve, |
| 50 void(const chrome_common_net::UrlList&, |
| 51 chrome_browser_net::UrlInfo::ResolutionMotivation)); |
| 52 MOCK_METHOD2(LearnFromNavigation, void(const GURL&, const GURL&)); |
| 53 MOCK_METHOD1(GetHtmlReferrerLists, void(std::string*)); |
| 54 MOCK_METHOD1(GetHtmlInfo, void(std::string*)); |
| 55 MOCK_METHOD0(TrimReferrersNow, void()); |
| 56 MOCK_METHOD1(SerializeReferrers, void(base::ListValue*)); |
| 57 MOCK_METHOD1(DeserializeReferrers, void(const base::ListValue&)); |
| 58 MOCK_METHOD1(DeserializeReferrersThenDelete, void(base::ListValue*)); |
| 59 MOCK_METHOD0(DiscardInitialNavigationHistory, void()); |
| 60 MOCK_METHOD3(FinalizeInitializationOnIOThread, |
| 61 void(const std::vector<GURL>&, base::ListValue*, IOThread*)); |
| 62 MOCK_METHOD1(LearnAboutInitialNavigation, void(const GURL&)); |
| 63 MOCK_METHOD1(DnsPrefetchList, void(const chrome_common_net::NameList&)); |
| 64 MOCK_METHOD2(DnsPrefetchMotivatedList, |
| 65 void(const chrome_common_net::UrlList&, |
| 66 chrome_browser_net::UrlInfo::ResolutionMotivation)); |
| 67 MOCK_METHOD1(SaveStateForNextStartupAndTrim, void(PrefService* prefs)); |
| 68 MOCK_METHOD3(SaveDnsPrefetchStateForNextStartupAndTrim, |
| 69 void(base::ListValue*, base::ListValue*, base::WaitableEvent*)); |
| 70 MOCK_METHOD1(EnablePredictor, void(bool enable)); |
| 71 MOCK_METHOD1(EnablePredictorOnIOThread, void(bool enable)); |
| 72 }; |
| 73 |
| 37 class ProfileManagerTest : public TestingBrowserProcessTest { | 74 class ProfileManagerTest : public TestingBrowserProcessTest { |
| 38 protected: | 75 protected: |
| 39 ProfileManagerTest() | 76 ProfileManagerTest() |
| 40 : local_state_(testing_browser_process_.get()), | 77 : local_state_(testing_browser_process_.get()), |
| 41 extension_event_router_forwarder_(new ExtensionEventRouterForwarder), | 78 extension_event_router_forwarder_(new ExtensionEventRouterForwarder), |
| 42 ui_thread_(BrowserThread::UI, &message_loop_), | 79 ui_thread_(BrowserThread::UI, &message_loop_), |
| 43 db_thread_(BrowserThread::DB, &message_loop_), | 80 db_thread_(BrowserThread::DB, &message_loop_), |
| 44 file_thread_(BrowserThread::FILE, &message_loop_), | 81 file_thread_(BrowserThread::FILE, &message_loop_), |
| 45 io_thread_(local_state_.Get(), NULL, extension_event_router_forwarder_), | 82 io_thread_(local_state_.Get(), NULL, extension_event_router_forwarder_), |
| 46 profile_manager_(new ProfileManagerWithoutInit) { | 83 profile_manager_(new ProfileManagerWithoutInit) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 75 MessageLoopForUI message_loop_; | 112 MessageLoopForUI message_loop_; |
| 76 BrowserThread ui_thread_; | 113 BrowserThread ui_thread_; |
| 77 BrowserThread db_thread_; | 114 BrowserThread db_thread_; |
| 78 BrowserThread file_thread_; | 115 BrowserThread file_thread_; |
| 79 IOThread io_thread_; | 116 IOThread io_thread_; |
| 80 | 117 |
| 81 scoped_ptr<base::SystemMonitor> system_monitor_dummy_; | 118 scoped_ptr<base::SystemMonitor> system_monitor_dummy_; |
| 82 | 119 |
| 83 // Also will test profile deletion. | 120 // Also will test profile deletion. |
| 84 scoped_ptr<ProfileManager> profile_manager_; | 121 scoped_ptr<ProfileManager> profile_manager_; |
| 122 scoped_ptr<MockPredictor> mock_predictor_; |
| 85 }; | 123 }; |
| 86 | 124 |
| 87 TEST_F(ProfileManagerTest, GetProfile) { | 125 TEST_F(ProfileManagerTest, GetProfile) { |
| 88 FilePath dest_path = temp_dir_.path(); | 126 FilePath dest_path = temp_dir_.path(); |
| 89 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); | 127 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); |
| 90 | 128 |
| 91 Profile* profile; | 129 Profile* profile; |
| 92 | 130 |
| 93 // Successfully create a profile. | 131 // Successfully create a profile. |
| 94 profile = profile_manager_->GetProfile(dest_path); | 132 profile = profile_manager_->GetProfile(dest_path); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 285 |
| 248 MockObserver mock_observer; | 286 MockObserver mock_observer; |
| 249 EXPECT_CALL(mock_observer, OnProfileCreated( | 287 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 250 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); | 288 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); |
| 251 | 289 |
| 252 profile_manager_->CreateProfileAsync(dest_path1, &mock_observer); | 290 profile_manager_->CreateProfileAsync(dest_path1, &mock_observer); |
| 253 profile_manager_->CreateProfileAsync(dest_path2, &mock_observer); | 291 profile_manager_->CreateProfileAsync(dest_path2, &mock_observer); |
| 254 | 292 |
| 255 message_loop_.RunAllPending(); | 293 message_loop_.RunAllPending(); |
| 256 } | 294 } |
| OLD | NEW |