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" |
11 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
12 #include "base/system_monitor/system_monitor.h" | 12 #include "base/system_monitor/system_monitor.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 16 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/extensions/event_router_forwarder.h" | 18 #include "chrome/browser/extensions/event_router_forwarder.h" |
19 #include "chrome/browser/history/history.h" | 19 #include "chrome/browser/history/history.h" |
20 #include "chrome/browser/history/history_service_factory.h" | 20 #include "chrome/browser/history/history_service_factory.h" |
21 #include "chrome/browser/io_thread.h" | 21 #include "chrome/browser/io_thread.h" |
22 #include "chrome/browser/prefs/browser_prefs.h" | 22 #include "chrome/browser/prefs/browser_prefs.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/profiles/profile_info_cache.h" | 24 #include "chrome/browser/profiles/profile_info_cache.h" |
25 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
26 #include "chrome/browser/profiles/profile_shortcut_manager.h" | |
26 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/common/chrome_constants.h" | 28 #include "chrome/common/chrome_constants.h" |
28 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
30 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
31 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
33 #include "chrome/installer/util/browser_distribution.h" | |
34 #include "chrome/installer/util/shell_util.h" | |
32 #include "chrome/test/base/test_browser_window.h" | 35 #include "chrome/test/base/test_browser_window.h" |
33 #include "chrome/test/base/testing_browser_process.h" | 36 #include "chrome/test/base/testing_browser_process.h" |
34 #include "chrome/test/base/testing_pref_service.h" | 37 #include "chrome/test/base/testing_pref_service.h" |
35 #include "chrome/test/base/testing_profile.h" | 38 #include "chrome/test/base/testing_profile.h" |
36 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
37 #include "content/public/test/test_browser_thread.h" | 40 #include "content/public/test/test_browser_thread.h" |
38 #include "testing/gmock/include/gmock/gmock.h" | 41 #include "testing/gmock/include/gmock/gmock.h" |
39 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
43 #include "ui/base/resource/resource_bundle.h" | |
40 | 44 |
41 #if defined(OS_CHROMEOS) | 45 #if defined(OS_CHROMEOS) |
42 #include "chrome/browser/chromeos/cros/cros_library.h" | 46 #include "chrome/browser/chromeos/cros/cros_library.h" |
43 #endif | 47 #endif |
44 | 48 |
45 using content::BrowserThread; | 49 using content::BrowserThread; |
46 | 50 |
47 namespace { | 51 namespace { |
48 | 52 |
49 // This global variable is used to check that value returned to different | 53 // This global variable is used to check that value returned to different |
(...skipping 20 matching lines...) Expand all Loading... | |
70 | 74 |
71 virtual Profile* CreateProfileAsyncHelper(const FilePath& path, | 75 virtual Profile* CreateProfileAsyncHelper(const FilePath& path, |
72 Delegate* delegate) OVERRIDE { | 76 Delegate* delegate) OVERRIDE { |
73 // This is safe while all file operations are done on the FILE thread. | 77 // This is safe while all file operations are done on the FILE thread. |
74 BrowserThread::PostTask( | 78 BrowserThread::PostTask( |
75 BrowserThread::FILE, FROM_HERE, | 79 BrowserThread::FILE, FROM_HERE, |
76 base::Bind(base::IgnoreResult(&file_util::CreateDirectory), path)); | 80 base::Bind(base::IgnoreResult(&file_util::CreateDirectory), path)); |
77 | 81 |
78 return new TestingProfile(path, this); | 82 return new TestingProfile(path, this); |
79 } | 83 } |
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 }; | 84 }; |
88 | 85 |
89 } // namespace testing | 86 } // namespace testing |
90 | 87 |
91 class ProfileManagerTest : public testing::Test { | 88 class ProfileManagerTest : public testing::Test { |
92 protected: | 89 protected: |
93 class MockObserver { | 90 class MockObserver { |
94 public: | 91 public: |
95 MOCK_METHOD2(OnProfileCreated, | 92 MOCK_METHOD2(OnProfileCreated, |
96 void(Profile* profile, Profile::CreateStatus status)); | 93 void(Profile* profile, Profile::CreateStatus status)); |
(...skipping 13 matching lines...) Expand all Loading... | |
110 system_monitor_dummy_.reset(new base::SystemMonitor); | 107 system_monitor_dummy_.reset(new base::SystemMonitor); |
111 static_cast<TestingBrowserProcess*>(g_browser_process)->SetIOThread( | 108 static_cast<TestingBrowserProcess*>(g_browser_process)->SetIOThread( |
112 &io_thread_); | 109 &io_thread_); |
113 } | 110 } |
114 | 111 |
115 virtual void SetUp() { | 112 virtual void SetUp() { |
116 // Create a new temporary directory, and store the path | 113 // Create a new temporary directory, and store the path |
117 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 114 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
118 static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager( | 115 static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager( |
119 new testing::ProfileManager(temp_dir_.path())); | 116 new testing::ProfileManager(temp_dir_.path())); |
117 | |
120 #if defined(OS_CHROMEOS) | 118 #if defined(OS_CHROMEOS) |
121 CommandLine *cl = CommandLine::ForCurrentProcess(); | 119 CommandLine* cl = CommandLine::ForCurrentProcess(); |
SteveT
2012/08/15 18:29:41
Thank you :)
Halli
2012/08/15 19:29:59
(:
On 2012/08/15 18:29:41, SteveT wrote:
| |
122 cl->AppendSwitch(switches::kTestType); | 120 cl->AppendSwitch(switches::kTestType); |
123 #endif | 121 #endif |
124 } | 122 } |
125 | 123 |
126 virtual void TearDown() { | 124 virtual void TearDown() { |
127 static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager( | 125 static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager( |
128 NULL); | 126 NULL); |
129 message_loop_.RunAllPending(); | 127 message_loop_.RunAllPending(); |
130 } | 128 } |
131 | 129 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 EXPECT_CALL(mock_observer2, OnProfileCreated( | 278 EXPECT_CALL(mock_observer2, OnProfileCreated( |
281 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 279 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
282 MockObserver mock_observer3; | 280 MockObserver mock_observer3; |
283 EXPECT_CALL(mock_observer3, OnProfileCreated( | 281 EXPECT_CALL(mock_observer3, OnProfileCreated( |
284 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 282 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
285 | 283 |
286 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 284 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
287 | 285 |
288 profile_manager->CreateProfileAsync(dest_path, | 286 profile_manager->CreateProfileAsync(dest_path, |
289 base::Bind(&MockObserver::OnProfileCreated, | 287 base::Bind(&MockObserver::OnProfileCreated, |
290 base::Unretained(&mock_observer1)), string16(), string16()); | 288 base::Unretained(&mock_observer1)), |
289 string16(), string16()); | |
291 profile_manager->CreateProfileAsync(dest_path, | 290 profile_manager->CreateProfileAsync(dest_path, |
292 base::Bind(&MockObserver::OnProfileCreated, | 291 base::Bind(&MockObserver::OnProfileCreated, |
293 base::Unretained(&mock_observer2)), string16(), string16()); | 292 base::Unretained(&mock_observer2)), |
293 string16(), string16()); | |
294 profile_manager->CreateProfileAsync(dest_path, | 294 profile_manager->CreateProfileAsync(dest_path, |
295 base::Bind(&MockObserver::OnProfileCreated, | 295 base::Bind(&MockObserver::OnProfileCreated, |
296 base::Unretained(&mock_observer3)), string16(), string16()); | 296 base::Unretained(&mock_observer3)), |
297 string16(), string16()); | |
297 | 298 |
298 message_loop_.RunAllPending(); | 299 message_loop_.RunAllPending(); |
299 } | 300 } |
300 | 301 |
301 TEST_F(ProfileManagerTest, CreateProfilesAsync) { | 302 TEST_F(ProfileManagerTest, CreateProfilesAsync) { |
302 FilePath dest_path1 = | 303 FilePath dest_path1 = |
303 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 1")); | 304 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 1")); |
304 FilePath dest_path2 = | 305 FilePath dest_path2 = |
305 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); | 306 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); |
306 | 307 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 browser2b.reset(); | 563 browser2b.reset(); |
563 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 564 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
564 ASSERT_EQ(1U, last_opened_profiles.size()); | 565 ASSERT_EQ(1U, last_opened_profiles.size()); |
565 EXPECT_EQ(profile1, last_opened_profiles[0]); | 566 EXPECT_EQ(profile1, last_opened_profiles[0]); |
566 | 567 |
567 browser1.reset(); | 568 browser1.reset(); |
568 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 569 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
569 ASSERT_EQ(0U, last_opened_profiles.size()); | 570 ASSERT_EQ(0U, last_opened_profiles.size()); |
570 } | 571 } |
571 #endif // !defined(OS_ANDROID) | 572 #endif // !defined(OS_ANDROID) |
OLD | NEW |