OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/sync/profile_signin_confirmation_helper.h" | 5 #include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/prefs/pref_notifier_impl.h" | 15 #include "base/prefs/pref_notifier_impl.h" |
16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
17 #include "base/prefs/testing_pref_service.h" | 17 #include "base/prefs/testing_pref_service.h" |
18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 22 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
23 #include "chrome/browser/extensions/extension_service.h" | |
24 #include "chrome/browser/extensions/test_extension_system.h" | |
25 #include "chrome/browser/history/history_service.h" | 23 #include "chrome/browser/history/history_service.h" |
26 #include "chrome/browser/history/history_service_factory.h" | 24 #include "chrome/browser/history/history_service_factory.h" |
27 #include "chrome/browser/prefs/browser_prefs.h" | 25 #include "chrome/browser/prefs/browser_prefs.h" |
28 #include "chrome/common/extensions/extension_constants.h" | |
29 #include "chrome/test/base/testing_pref_service_syncable.h" | 26 #include "chrome/test/base/testing_pref_service_syncable.h" |
30 #include "chrome/test/base/testing_profile.h" | 27 #include "chrome/test/base/testing_profile.h" |
31 #include "components/bookmarks/browser/bookmark_model.h" | 28 #include "components/bookmarks/browser/bookmark_model.h" |
32 #include "components/bookmarks/test/bookmark_test_helpers.h" | 29 #include "components/bookmarks/test/bookmark_test_helpers.h" |
33 #include "components/pref_registry/pref_registry_syncable.h" | 30 #include "components/pref_registry/pref_registry_syncable.h" |
34 #include "content/public/test/test_browser_thread_bundle.h" | 31 #include "content/public/test/test_browser_thread_bundle.h" |
35 #include "content/public/test/test_utils.h" | 32 #include "content/public/test/test_utils.h" |
36 #include "extensions/browser/extension_prefs.h" | |
37 #include "extensions/common/extension.h" | |
38 #include "extensions/common/manifest_constants.h" | |
39 #include "extensions/common/permissions/permission_set.h" | |
40 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
41 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
42 | 35 |
43 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
44 #include "chrome/browser/chromeos/login/users/user_manager.h" | 37 #include "chrome/browser/chromeos/login/users/user_manager.h" |
45 #include "chrome/browser/chromeos/settings/cros_settings.h" | 38 #include "chrome/browser/chromeos/settings/cros_settings.h" |
46 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 39 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
47 #endif | 40 #endif |
48 | 41 |
| 42 #if defined(ENABLE_EXTENSIONS) |
| 43 #include "chrome/browser/extensions/extension_service.h" |
| 44 #include "chrome/browser/extensions/test_extension_system.h" |
| 45 #include "chrome/common/extensions/extension_constants.h" |
| 46 #include "extensions/browser/extension_prefs.h" |
| 47 #include "extensions/common/extension.h" |
| 48 #include "extensions/common/manifest_constants.h" |
| 49 #include "extensions/common/permissions/permission_set.h" |
| 50 #endif |
| 51 |
49 namespace { | 52 namespace { |
50 | 53 |
51 template<typename T> | 54 template<typename T> |
52 void GetValueAndQuit(T* result, const base::Closure& quit, T actual) { | 55 void GetValueAndQuit(T* result, const base::Closure& quit, T actual) { |
53 *result = actual; | 56 *result = actual; |
54 quit.Run(); | 57 quit.Run(); |
55 } | 58 } |
56 | 59 |
57 template<typename T> | 60 template<typename T> |
58 T GetCallbackResult( | 61 T GetCallbackResult( |
(...skipping 20 matching lines...) Expand all Loading... |
79 return true; | 82 return true; |
80 } | 83 } |
81 void set_read_error(PrefReadError read_error) { | 84 void set_read_error(PrefReadError read_error) { |
82 read_error_ = read_error; | 85 read_error_ = read_error; |
83 } | 86 } |
84 private: | 87 private: |
85 virtual ~TestingPrefStoreWithCustomReadError() {} | 88 virtual ~TestingPrefStoreWithCustomReadError() {} |
86 PrefReadError read_error_; | 89 PrefReadError read_error_; |
87 }; | 90 }; |
88 | 91 |
| 92 #if defined(ENABLE_EXTENSIONS) |
89 #if defined(OS_WIN) | 93 #if defined(OS_WIN) |
90 const base::FilePath::CharType kExtensionFilePath[] = | 94 const base::FilePath::CharType kExtensionFilePath[] = |
91 FILE_PATH_LITERAL("c:\\foo"); | 95 FILE_PATH_LITERAL("c:\\foo"); |
92 #elif defined(OS_POSIX) | 96 #elif defined(OS_POSIX) |
93 const base::FilePath::CharType kExtensionFilePath[] = | 97 const base::FilePath::CharType kExtensionFilePath[] = |
94 FILE_PATH_LITERAL("/oo"); | 98 FILE_PATH_LITERAL("/oo"); |
95 #endif | 99 #endif |
96 | 100 |
97 static scoped_refptr<extensions::Extension> CreateExtension( | 101 static scoped_refptr<extensions::Extension> CreateExtension( |
98 const std::string& name, | 102 const std::string& name, |
99 const std::string& id) { | 103 const std::string& id) { |
100 base::DictionaryValue manifest; | 104 base::DictionaryValue manifest; |
101 manifest.SetString(extensions::manifest_keys::kVersion, "1.0.0.0"); | 105 manifest.SetString(extensions::manifest_keys::kVersion, "1.0.0.0"); |
102 manifest.SetString(extensions::manifest_keys::kName, name); | 106 manifest.SetString(extensions::manifest_keys::kName, name); |
103 std::string error; | 107 std::string error; |
104 scoped_refptr<extensions::Extension> extension = | 108 scoped_refptr<extensions::Extension> extension = |
105 extensions::Extension::Create( | 109 extensions::Extension::Create( |
106 base::FilePath(kExtensionFilePath).AppendASCII(name), | 110 base::FilePath(kExtensionFilePath).AppendASCII(name), |
107 extensions::Manifest::INTERNAL, | 111 extensions::Manifest::INTERNAL, |
108 manifest, | 112 manifest, |
109 extensions::Extension::NO_FLAGS, | 113 extensions::Extension::NO_FLAGS, |
110 id, | 114 id, |
111 &error); | 115 &error); |
112 return extension; | 116 return extension; |
113 } | 117 } |
| 118 #endif |
114 | 119 |
115 } // namespace | 120 } // namespace |
116 | 121 |
117 class ProfileSigninConfirmationHelperTest : public testing::Test { | 122 class ProfileSigninConfirmationHelperTest : public testing::Test { |
118 public: | 123 public: |
119 ProfileSigninConfirmationHelperTest() | 124 ProfileSigninConfirmationHelperTest() |
120 : user_prefs_(NULL), | 125 : user_prefs_(NULL), |
121 model_(NULL) { | 126 model_(NULL) { |
122 } | 127 } |
123 | 128 |
124 virtual void SetUp() OVERRIDE { | 129 virtual void SetUp() OVERRIDE { |
125 // Create the profile. | 130 // Create the profile. |
126 TestingProfile::Builder builder; | 131 TestingProfile::Builder builder; |
127 user_prefs_ = new TestingPrefStoreWithCustomReadError; | 132 user_prefs_ = new TestingPrefStoreWithCustomReadError; |
128 TestingPrefServiceSyncable* pref_service = new TestingPrefServiceSyncable( | 133 TestingPrefServiceSyncable* pref_service = new TestingPrefServiceSyncable( |
129 new TestingPrefStore(), | 134 new TestingPrefStore(), |
130 user_prefs_, | 135 user_prefs_, |
131 new TestingPrefStore(), | 136 new TestingPrefStore(), |
132 new user_prefs::PrefRegistrySyncable(), | 137 new user_prefs::PrefRegistrySyncable(), |
133 new PrefNotifierImpl()); | 138 new PrefNotifierImpl()); |
134 chrome::RegisterUserProfilePrefs(pref_service->registry()); | 139 chrome::RegisterUserProfilePrefs(pref_service->registry()); |
135 builder.SetPrefService(make_scoped_ptr<PrefServiceSyncable>(pref_service)); | 140 builder.SetPrefService(make_scoped_ptr<PrefServiceSyncable>(pref_service)); |
136 profile_ = builder.Build(); | 141 profile_ = builder.Build(); |
137 | 142 |
138 // Initialize the services we check. | 143 // Initialize the services we check. |
139 profile_->CreateBookmarkModel(true); | 144 profile_->CreateBookmarkModel(true); |
140 model_ = BookmarkModelFactory::GetForProfile(profile_.get()); | 145 model_ = BookmarkModelFactory::GetForProfile(profile_.get()); |
141 test::WaitForBookmarkModelToLoad(model_); | 146 test::WaitForBookmarkModelToLoad(model_); |
142 ASSERT_TRUE(profile_->CreateHistoryService(true, false)); | 147 ASSERT_TRUE(profile_->CreateHistoryService(true, false)); |
| 148 #if defined(ENABLE_EXTENSIONS) |
143 extensions::TestExtensionSystem* system = | 149 extensions::TestExtensionSystem* system = |
144 static_cast<extensions::TestExtensionSystem*>( | 150 static_cast<extensions::TestExtensionSystem*>( |
145 extensions::ExtensionSystem::Get(profile_.get())); | 151 extensions::ExtensionSystem::Get(profile_.get())); |
146 CommandLine command_line(CommandLine::NO_PROGRAM); | 152 CommandLine command_line(CommandLine::NO_PROGRAM); |
147 system->CreateExtensionService(&command_line, | 153 system->CreateExtensionService(&command_line, |
148 base::FilePath(kExtensionFilePath), | 154 base::FilePath(kExtensionFilePath), |
149 false); | 155 false); |
| 156 #endif |
150 } | 157 } |
151 | 158 |
152 virtual void TearDown() OVERRIDE { | 159 virtual void TearDown() OVERRIDE { |
153 // TestExtensionSystem uses DeleteSoon, so we need to delete the profile | 160 // TestExtensionSystem uses DeleteSoon, so we need to delete the profile |
154 // and then run the message queue to clean up. | 161 // and then run the message queue to clean up. |
155 profile_.reset(); | 162 profile_.reset(); |
156 base::RunLoop().RunUntilIdle(); | 163 base::RunLoop().RunUntilIdle(); |
157 } | 164 } |
158 | 165 |
159 protected: | 166 protected: |
(...skipping 26 matching lines...) Expand all Loading... |
186 model_->AddURL(model_->bookmark_bar_node(), 0, | 193 model_->AddURL(model_->bookmark_bar_node(), 0, |
187 base::string16(base::ASCIIToUTF16("foo")), | 194 base::string16(base::ASCIIToUTF16("foo")), |
188 GURL("http://foo.com")); | 195 GURL("http://foo.com")); |
189 EXPECT_TRUE( | 196 EXPECT_TRUE( |
190 GetCallbackResult( | 197 GetCallbackResult( |
191 base::Bind( | 198 base::Bind( |
192 &ui::CheckShouldPromptForNewProfile, | 199 &ui::CheckShouldPromptForNewProfile, |
193 profile_.get()))); | 200 profile_.get()))); |
194 } | 201 } |
195 | 202 |
| 203 #if defined(ENABLE_EXTENSIONS) |
196 TEST_F(ProfileSigninConfirmationHelperTest, PromptForNewProfile_Extensions) { | 204 TEST_F(ProfileSigninConfirmationHelperTest, PromptForNewProfile_Extensions) { |
197 ExtensionService* extensions = | 205 ExtensionService* extensions = |
198 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); | 206 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); |
199 ASSERT_TRUE(extensions); | 207 ASSERT_TRUE(extensions); |
200 | 208 |
201 // Profile is new but has synced extensions. | 209 // Profile is new but has synced extensions. |
202 | 210 |
203 // (The web store doesn't count.) | 211 // (The web store doesn't count.) |
204 scoped_refptr<extensions::Extension> webstore = | 212 scoped_refptr<extensions::Extension> webstore = |
205 CreateExtension("web store", extension_misc::kWebStoreAppId); | 213 CreateExtension("web store", extension_misc::kWebStoreAppId); |
206 extensions::ExtensionPrefs::Get(profile_.get())->AddGrantedPermissions( | 214 extensions::ExtensionPrefs::Get(profile_.get())->AddGrantedPermissions( |
207 webstore->id(), make_scoped_refptr(new extensions::PermissionSet).get()); | 215 webstore->id(), make_scoped_refptr(new extensions::PermissionSet).get()); |
208 extensions->AddExtension(webstore.get()); | 216 extensions->AddExtension(webstore.get()); |
209 EXPECT_FALSE(GetCallbackResult( | 217 EXPECT_FALSE(GetCallbackResult( |
210 base::Bind(&ui::CheckShouldPromptForNewProfile, profile_.get()))); | 218 base::Bind(&ui::CheckShouldPromptForNewProfile, profile_.get()))); |
211 | 219 |
212 scoped_refptr<extensions::Extension> extension = | 220 scoped_refptr<extensions::Extension> extension = |
213 CreateExtension("foo", std::string()); | 221 CreateExtension("foo", std::string()); |
214 extensions::ExtensionPrefs::Get(profile_.get())->AddGrantedPermissions( | 222 extensions::ExtensionPrefs::Get(profile_.get())->AddGrantedPermissions( |
215 extension->id(), make_scoped_refptr(new extensions::PermissionSet).get()); | 223 extension->id(), make_scoped_refptr(new extensions::PermissionSet).get()); |
216 extensions->AddExtension(extension.get()); | 224 extensions->AddExtension(extension.get()); |
217 EXPECT_TRUE(GetCallbackResult( | 225 EXPECT_TRUE(GetCallbackResult( |
218 base::Bind(&ui::CheckShouldPromptForNewProfile, profile_.get()))); | 226 base::Bind(&ui::CheckShouldPromptForNewProfile, profile_.get()))); |
219 } | 227 } |
| 228 #endif |
220 | 229 |
221 // http://crbug.com/393149 | 230 // http://crbug.com/393149 |
222 TEST_F(ProfileSigninConfirmationHelperTest, | 231 TEST_F(ProfileSigninConfirmationHelperTest, |
223 DISABLED_PromptForNewProfile_History) { | 232 DISABLED_PromptForNewProfile_History) { |
224 HistoryService* history = HistoryServiceFactory::GetForProfile( | 233 HistoryService* history = HistoryServiceFactory::GetForProfile( |
225 profile_.get(), | 234 profile_.get(), |
226 Profile::EXPLICIT_ACCESS); | 235 Profile::EXPLICIT_ACCESS); |
227 ASSERT_TRUE(history); | 236 ASSERT_TRUE(history); |
228 | 237 |
229 // Profile is new but has more than $(kHistoryEntriesBeforeNewProfilePrompt) | 238 // Profile is new but has more than $(kHistoryEntriesBeforeNewProfilePrompt) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 274 |
266 TEST_F(ProfileSigninConfirmationHelperTest, PromptForNewProfile_Restarted) { | 275 TEST_F(ProfileSigninConfirmationHelperTest, PromptForNewProfile_Restarted) { |
267 // Browser has been shut down since profile was created. | 276 // Browser has been shut down since profile was created. |
268 user_prefs_->set_read_error(PersistentPrefStore::PREF_READ_ERROR_NONE); | 277 user_prefs_->set_read_error(PersistentPrefStore::PREF_READ_ERROR_NONE); |
269 EXPECT_TRUE( | 278 EXPECT_TRUE( |
270 GetCallbackResult( | 279 GetCallbackResult( |
271 base::Bind( | 280 base::Bind( |
272 &ui::CheckShouldPromptForNewProfile, | 281 &ui::CheckShouldPromptForNewProfile, |
273 profile_.get()))); | 282 profile_.get()))); |
274 } | 283 } |
OLD | NEW |