OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/strings/string_number_conversions.h" | |
6 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/values.h" | |
8 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" | 10 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" |
9 #include "chrome/browser/extensions/extension_function_test_utils.h" | 11 #include "chrome/browser/extensions/extension_function_test_utils.h" |
10 #include "chrome/browser/extensions/extension_message_bubble.h" | 12 #include "chrome/browser/extensions/extension_message_bubble.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/extensions/ntp_overridden_bubble_controller.h" | 14 #include "chrome/browser/extensions/ntp_overridden_bubble_controller.h" |
15 #include "chrome/browser/extensions/proxy_overridden_bubble_controller.h" | |
13 #include "chrome/browser/extensions/settings_api_bubble_controller.h" | 16 #include "chrome/browser/extensions/settings_api_bubble_controller.h" |
14 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" | 17 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" |
15 #include "chrome/browser/extensions/test_extension_system.h" | 18 #include "chrome/browser/extensions/test_extension_system.h" |
16 #include "chrome/common/chrome_version_info.h" | 19 #include "chrome/common/chrome_version_info.h" |
20 #include "chrome/common/pref_names.h" | |
17 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
18 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
23 #include "extensions/browser/extension_pref_value_map.h" | |
24 #include "extensions/browser/extension_pref_value_map_factory.h" | |
19 #include "extensions/browser/extension_prefs.h" | 25 #include "extensions/browser/extension_prefs.h" |
26 #include "extensions/browser/extension_registry.h" | |
20 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
21 #include "extensions/common/extension_builder.h" | 28 #include "extensions/common/extension_builder.h" |
22 #include "extensions/common/feature_switch.h" | 29 #include "extensions/common/feature_switch.h" |
30 #include "extensions/common/value_builder.h" | |
23 | 31 |
24 namespace { | 32 namespace { |
25 | 33 |
26 const char kId1[] = "iccfkkhkfiphcjdakkmcjmkfboccmndk"; | 34 const char kId1[] = "iccfkkhkfiphcjdakkmcjmkfboccmndk"; |
27 const char kId2[] = "ajjhifimiemdpmophmkkkcijegphclbl"; | 35 const char kId2[] = "ajjhifimiemdpmophmkkkcijegphclbl"; |
28 const char kId3[] = "ioibbbfddncmmabjmpokikkeiofalaek"; | 36 const char kId3[] = "ioibbbfddncmmabjmpokikkeiofalaek"; |
29 | 37 |
30 } // namespace | 38 } // namespace |
31 | 39 |
32 namespace extensions { | 40 namespace extensions { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 ++dismiss_button_callback_count_; | 160 ++dismiss_button_callback_count_; |
153 NtpOverriddenBubbleController::OnBubbleDismiss(); | 161 NtpOverriddenBubbleController::OnBubbleDismiss(); |
154 } | 162 } |
155 | 163 |
156 virtual void OnLinkClicked() OVERRIDE { | 164 virtual void OnLinkClicked() OVERRIDE { |
157 ++link_click_callback_count_; | 165 ++link_click_callback_count_; |
158 NtpOverriddenBubbleController::OnLinkClicked(); | 166 NtpOverriddenBubbleController::OnLinkClicked(); |
159 } | 167 } |
160 }; | 168 }; |
161 | 169 |
170 // A test class for the ProxyOverriddenBubbleController. | |
171 class TestProxyOverriddenBubbleController | |
172 : public ProxyOverriddenBubbleController, | |
173 public TestDelegate { | |
174 public: | |
175 explicit TestProxyOverriddenBubbleController(Profile* profile) | |
176 : ProxyOverriddenBubbleController(profile) { | |
177 } | |
178 | |
179 virtual void OnBubbleAction() OVERRIDE { | |
180 ++action_button_callback_count_; | |
181 ProxyOverriddenBubbleController::OnBubbleAction(); | |
182 } | |
183 | |
184 virtual void OnBubbleDismiss() OVERRIDE { | |
185 ++dismiss_button_callback_count_; | |
186 ProxyOverriddenBubbleController::OnBubbleDismiss(); | |
187 } | |
188 | |
189 virtual void OnLinkClicked() OVERRIDE { | |
190 ++link_click_callback_count_; | |
191 ProxyOverriddenBubbleController::OnLinkClicked(); | |
192 } | |
193 }; | |
194 | |
162 // A fake bubble used for testing the controller. Takes an action that specifies | 195 // A fake bubble used for testing the controller. Takes an action that specifies |
163 // what should happen when the bubble is "shown" (the bubble is actually not | 196 // what should happen when the bubble is "shown" (the bubble is actually not |
164 // shown, the corresponding action is taken immediately). | 197 // shown, the corresponding action is taken immediately). |
165 class FakeExtensionMessageBubble : public ExtensionMessageBubble { | 198 class FakeExtensionMessageBubble : public ExtensionMessageBubble { |
166 public: | 199 public: |
167 enum ExtensionBubbleAction { | 200 enum ExtensionBubbleAction { |
168 BUBBLE_ACTION_CLICK_ACTION_BUTTON = 0, | 201 BUBBLE_ACTION_CLICK_ACTION_BUTTON = 0, |
169 BUBBLE_ACTION_CLICK_DISMISS_BUTTON, | 202 BUBBLE_ACTION_CLICK_DISMISS_BUTTON, |
170 BUBBLE_ACTION_CLICK_LINK, | 203 BUBBLE_ACTION_CLICK_LINK, |
171 }; | 204 }; |
(...skipping 30 matching lines...) Expand all Loading... | |
202 | 235 |
203 base::Closure action_callback_; | 236 base::Closure action_callback_; |
204 base::Closure dismiss_callback_; | 237 base::Closure dismiss_callback_; |
205 base::Closure link_callback_; | 238 base::Closure link_callback_; |
206 }; | 239 }; |
207 | 240 |
208 class ExtensionMessageBubbleTest : public testing::Test { | 241 class ExtensionMessageBubbleTest : public testing::Test { |
209 public: | 242 public: |
210 ExtensionMessageBubbleTest() {} | 243 ExtensionMessageBubbleTest() {} |
211 | 244 |
212 void LoadGenericExtension(const std::string& index, | 245 testing::AssertionResult LoadGenericExtension(const std::string& index, |
213 const std::string& id, | 246 const std::string& id, |
214 Manifest::Location location) { | 247 Manifest::Location location) { |
215 extensions::ExtensionBuilder builder; | 248 ExtensionBuilder builder; |
216 builder.SetManifest(extensions::DictionaryBuilder() | 249 builder.SetManifest(DictionaryBuilder() |
217 .Set("name", std::string("Extension " + index)) | 250 .Set("name", std::string("Extension " + index)) |
218 .Set("version", "1.0") | 251 .Set("version", "1.0") |
219 .Set("manifest_version", 2)); | 252 .Set("manifest_version", 2)); |
220 builder.SetLocation(location); | 253 builder.SetLocation(location); |
221 builder.SetID(id); | 254 builder.SetID(id); |
222 service_->AddExtension(builder.Build().get()); | 255 service_->AddExtension(builder.Build().get()); |
256 | |
257 if (ExtensionRegistry::Get(profile())->enabled_extensions().GetByID(id)) | |
258 return testing::AssertionSuccess(); | |
259 return testing::AssertionFailure() << "Could not install extension: " << id; | |
223 } | 260 } |
224 | 261 |
225 void LoadExtensionWithAction(const std::string& index, | 262 testing::AssertionResult LoadExtensionWithAction( |
226 const std::string& id, | 263 const std::string& index, |
227 Manifest::Location location) { | 264 const std::string& id, |
228 extensions::ExtensionBuilder builder; | 265 Manifest::Location location) { |
229 builder.SetManifest(extensions::DictionaryBuilder() | 266 ExtensionBuilder builder; |
267 builder.SetManifest(DictionaryBuilder() | |
230 .Set("name", std::string("Extension " + index)) | 268 .Set("name", std::string("Extension " + index)) |
231 .Set("version", "1.0") | 269 .Set("version", "1.0") |
232 .Set("manifest_version", 2) | 270 .Set("manifest_version", 2) |
233 .Set("browser_action", | 271 .Set("browser_action", |
234 extensions::DictionaryBuilder().Set( | 272 DictionaryBuilder().Set( |
235 "default_title", "Default title"))); | 273 "default_title", "Default title"))); |
236 builder.SetLocation(location); | 274 builder.SetLocation(location); |
237 builder.SetID(id); | 275 builder.SetID(id); |
238 service_->AddExtension(builder.Build().get()); | 276 service_->AddExtension(builder.Build().get()); |
277 | |
278 if (ExtensionRegistry::Get(profile())->enabled_extensions().GetByID(id)) | |
279 return testing::AssertionSuccess(); | |
280 return testing::AssertionFailure() << "Could not install extension: " << id; | |
239 } | 281 } |
240 | 282 |
241 void LoadExtensionOverridingHome(const std::string& index, | 283 testing::AssertionResult LoadExtensionOverridingHome( |
242 const std::string& id, | 284 const std::string& index, |
243 Manifest::Location location) { | 285 const std::string& id, |
244 extensions::ExtensionBuilder builder; | 286 Manifest::Location location) { |
245 builder.SetManifest(extensions::DictionaryBuilder() | 287 ExtensionBuilder builder; |
288 builder.SetManifest(DictionaryBuilder() | |
246 .Set("name", std::string("Extension " + index)) | 289 .Set("name", std::string("Extension " + index)) |
247 .Set("version", "1.0") | 290 .Set("version", "1.0") |
248 .Set("manifest_version", 2) | 291 .Set("manifest_version", 2) |
249 .Set("chrome_settings_overrides", | 292 .Set("chrome_settings_overrides", |
250 extensions::DictionaryBuilder().Set( | 293 DictionaryBuilder().Set( |
251 "homepage", "http://www.google.com"))); | 294 "homepage", "http://www.google.com"))); |
252 builder.SetLocation(location); | 295 builder.SetLocation(location); |
253 builder.SetID(id); | 296 builder.SetID(id); |
254 service_->AddExtension(builder.Build().get()); | 297 service_->AddExtension(builder.Build().get()); |
298 | |
299 if (ExtensionRegistry::Get(profile())->enabled_extensions().GetByID(id)) | |
300 return testing::AssertionSuccess(); | |
301 return testing::AssertionFailure() << "Could not install extension: " << id; | |
255 } | 302 } |
256 | 303 |
257 void LoadExtensionOverridingStart(const std::string& index, | 304 testing::AssertionResult LoadExtensionOverridingStart( |
258 const std::string& id, | 305 const std::string& index, |
259 Manifest::Location location) { | 306 const std::string& id, |
260 extensions::ExtensionBuilder builder; | 307 Manifest::Location location) { |
261 builder.SetManifest(extensions::DictionaryBuilder() | 308 ExtensionBuilder builder; |
309 builder.SetManifest(DictionaryBuilder() | |
262 .Set("name", std::string("Extension " + index)) | 310 .Set("name", std::string("Extension " + index)) |
263 .Set("version", "1.0") | 311 .Set("version", "1.0") |
264 .Set("manifest_version", 2) | 312 .Set("manifest_version", 2) |
265 .Set("chrome_settings_overrides", | 313 .Set("chrome_settings_overrides", |
266 extensions::DictionaryBuilder().Set( | 314 DictionaryBuilder().Set( |
267 "startup_pages", | 315 "startup_pages", |
268 extensions::ListBuilder().Append( | 316 ListBuilder().Append( |
269 "http://www.google.com")))); | 317 "http://www.google.com")))); |
270 builder.SetLocation(location); | 318 builder.SetLocation(location); |
271 builder.SetID(id); | 319 builder.SetID(id); |
272 service_->AddExtension(builder.Build().get()); | 320 service_->AddExtension(builder.Build().get()); |
321 | |
322 if (ExtensionRegistry::Get(profile())->enabled_extensions().GetByID(id)) | |
323 return testing::AssertionSuccess(); | |
324 return testing::AssertionFailure() << "Could not install extension: " << id; | |
273 } | 325 } |
274 | 326 |
275 void LoadExtensionOverridingNtp(const std::string& index, | 327 testing::AssertionResult LoadExtensionOverridingNtp( |
276 const std::string& id, | 328 const std::string& index, |
277 Manifest::Location location) { | 329 const std::string& id, |
278 extensions::ExtensionBuilder builder; | 330 Manifest::Location location) { |
279 builder.SetManifest(extensions::DictionaryBuilder() | 331 ExtensionBuilder builder; |
332 builder.SetManifest(DictionaryBuilder() | |
280 .Set("name", std::string("Extension " + index)) | 333 .Set("name", std::string("Extension " + index)) |
281 .Set("version", "1.0") | 334 .Set("version", "1.0") |
282 .Set("manifest_version", 2) | 335 .Set("manifest_version", 2) |
283 .Set("chrome_url_overrides", | 336 .Set("chrome_url_overrides", |
284 extensions::DictionaryBuilder().Set( | 337 DictionaryBuilder().Set( |
285 "newtab", "Default.html"))); | 338 "newtab", "Default.html"))); |
286 | 339 |
287 builder.SetLocation(location); | 340 builder.SetLocation(location); |
288 builder.SetID(id); | 341 builder.SetID(id); |
289 service_->AddExtension(builder.Build().get()); | 342 service_->AddExtension(builder.Build().get()); |
343 | |
344 if (ExtensionRegistry::Get(profile())->enabled_extensions().GetByID(id)) | |
345 return testing::AssertionSuccess(); | |
346 return testing::AssertionFailure() << "Could not install extension: " << id; | |
347 } | |
348 | |
349 testing::AssertionResult LoadExtensionOverridingProxy( | |
350 const std::string& index, | |
351 const std::string& id, | |
352 Manifest::Location location) { | |
353 ExtensionBuilder builder; | |
354 builder.SetManifest(DictionaryBuilder() | |
355 .Set("name", std::string("Extension " + index)) | |
356 .Set("version", "1.0") | |
357 .Set("manifest_version", 2) | |
358 .Set("permissions", | |
359 ListBuilder().Append("proxy"))); | |
360 | |
361 builder.SetLocation(location); | |
362 builder.SetID(id); | |
363 service_->AddExtension(builder.Build().get()); | |
364 | |
365 // The proxy check relies on ExtensionPrefValueMap being up to date as to | |
366 // specifying which extension is controlling the proxy, but unfortunately | |
367 // that Map is not updated automatically for unit tests, so we simulate the | |
368 // update here to avoid test failures. | |
369 ExtensionPrefValueMap* extension_prefs_value_map = | |
370 ExtensionPrefValueMapFactory::GetForBrowserContext(profile()); | |
371 extension_prefs_value_map->RegisterExtension( | |
372 id, base::Time::Now(), true, false); | |
Devlin
2014/06/05 19:42:54
nit: please document anonymous bools.
| |
373 extension_prefs_value_map->SetExtensionPref( | |
374 id, | |
375 prefs::kProxy, | |
376 kExtensionPrefsScopeRegular, | |
377 base::Value::CreateStringValue(id)); | |
Devlin
2014/06/05 19:42:55
nit: indentation mishap.
| |
378 | |
379 if (ExtensionRegistry::Get(profile())->enabled_extensions().GetByID(id)) | |
380 return testing::AssertionSuccess(); | |
381 return testing::AssertionFailure() << "Could not install extension: " << id; | |
290 } | 382 } |
291 | 383 |
292 void Init() { | 384 void Init() { |
293 // The two lines of magical incantation required to get the extension | 385 // The two lines of magical incantation required to get the extension |
294 // service to work inside a unit test and access the extension prefs. | 386 // service to work inside a unit test and access the extension prefs. |
295 thread_bundle_.reset(new content::TestBrowserThreadBundle); | 387 thread_bundle_.reset(new content::TestBrowserThreadBundle); |
296 profile_.reset(new TestingProfile); | 388 profile_.reset(new TestingProfile); |
297 static_cast<TestExtensionSystem*>( | 389 static_cast<TestExtensionSystem*>( |
298 ExtensionSystem::Get(profile()))->CreateExtensionService( | 390 ExtensionSystem::Get(profile()))->CreateExtensionService( |
299 CommandLine::ForCurrentProcess(), | 391 CommandLine::ForCurrentProcess(), |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 #if defined(OS_WIN) | 433 #if defined(OS_WIN) |
342 #define MAYBE_WipeoutControllerTest WipeoutControllerTest | 434 #define MAYBE_WipeoutControllerTest WipeoutControllerTest |
343 #else | 435 #else |
344 #define MAYBE_WipeoutControllerTest DISABLED_WipeoutControllerTest | 436 #define MAYBE_WipeoutControllerTest DISABLED_WipeoutControllerTest |
345 #endif | 437 #endif |
346 | 438 |
347 TEST_F(ExtensionMessageBubbleTest, MAYBE_WipeoutControllerTest) { | 439 TEST_F(ExtensionMessageBubbleTest, MAYBE_WipeoutControllerTest) { |
348 Init(); | 440 Init(); |
349 // Add three extensions, and control two of them in this test (extension 1 | 441 // Add three extensions, and control two of them in this test (extension 1 |
350 // and 2). | 442 // and 2). |
351 LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE); | 443 ASSERT_TRUE(LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE)); |
352 LoadGenericExtension("2", kId2, Manifest::UNPACKED); | 444 ASSERT_TRUE(LoadGenericExtension("2", kId2, Manifest::UNPACKED)); |
353 LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY); | 445 ASSERT_TRUE(LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY)); |
354 | 446 |
355 scoped_ptr<TestSuspiciousExtensionBubbleController> controller( | 447 scoped_ptr<TestSuspiciousExtensionBubbleController> controller( |
356 new TestSuspiciousExtensionBubbleController(profile())); | 448 new TestSuspiciousExtensionBubbleController(profile())); |
357 FakeExtensionMessageBubble bubble; | 449 FakeExtensionMessageBubble bubble; |
358 bubble.set_action_on_show( | 450 bubble.set_action_on_show( |
359 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); | 451 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); |
360 | 452 |
361 // Validate that we don't have a suppress value for the extensions. | 453 // Validate that we don't have a suppress value for the extensions. |
362 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | 454 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
363 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(kId1)); | 455 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(kId1)); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 #define MAYBE_DevModeControllerTest DISABLED_DevModeControllerTest | 510 #define MAYBE_DevModeControllerTest DISABLED_DevModeControllerTest |
419 #endif | 511 #endif |
420 | 512 |
421 TEST_F(ExtensionMessageBubbleTest, MAYBE_DevModeControllerTest) { | 513 TEST_F(ExtensionMessageBubbleTest, MAYBE_DevModeControllerTest) { |
422 FeatureSwitch::ScopedOverride force_dev_mode_highlighting( | 514 FeatureSwitch::ScopedOverride force_dev_mode_highlighting( |
423 FeatureSwitch::force_dev_mode_highlighting(), true); | 515 FeatureSwitch::force_dev_mode_highlighting(), true); |
424 Init(); | 516 Init(); |
425 // Add three extensions, and control two of them in this test (extension 1 | 517 // Add three extensions, and control two of them in this test (extension 1 |
426 // and 2). Extension 1 is a regular extension, Extension 2 is UNPACKED so it | 518 // and 2). Extension 1 is a regular extension, Extension 2 is UNPACKED so it |
427 // counts as a DevMode extension. | 519 // counts as a DevMode extension. |
428 LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE); | 520 ASSERT_TRUE(LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE)); |
429 LoadGenericExtension("2", kId2, Manifest::UNPACKED); | 521 ASSERT_TRUE(LoadGenericExtension("2", kId2, Manifest::UNPACKED)); |
430 LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY); | 522 ASSERT_TRUE(LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY)); |
431 | 523 |
432 scoped_ptr<TestDevModeBubbleController> controller( | 524 scoped_ptr<TestDevModeBubbleController> controller( |
433 new TestDevModeBubbleController(profile())); | 525 new TestDevModeBubbleController(profile())); |
434 | 526 |
435 // The list will contain one enabled unpacked extension. | 527 // The list will contain one enabled unpacked extension. |
436 EXPECT_TRUE(controller->ShouldShow()); | 528 EXPECT_TRUE(controller->ShouldShow()); |
437 std::vector<base::string16> dev_mode_extensions = | 529 std::vector<base::string16> dev_mode_extensions = |
438 controller->GetExtensionList(); | 530 controller->GetExtensionList(); |
439 ASSERT_EQ(2U, dev_mode_extensions.size()); | 531 ASSERT_EQ(2U, dev_mode_extensions.size()); |
440 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == dev_mode_extensions[0]); | 532 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == dev_mode_extensions[0]); |
441 EXPECT_TRUE(base::ASCIIToUTF16("Extension 1") == dev_mode_extensions[1]); | 533 EXPECT_TRUE(base::ASCIIToUTF16("Extension 1") == dev_mode_extensions[1]); |
442 EXPECT_EQ(0U, controller->link_click_count()); | 534 EXPECT_EQ(0U, controller->link_click_count()); |
443 EXPECT_EQ(0U, controller->dismiss_click_count()); | 535 EXPECT_EQ(0U, controller->dismiss_click_count()); |
444 EXPECT_EQ(0U, controller->action_click_count()); | 536 EXPECT_EQ(0U, controller->action_click_count()); |
445 | 537 |
446 // Simulate showing the bubble. | 538 // Simulate showing the bubble. |
447 FakeExtensionMessageBubble bubble; | 539 FakeExtensionMessageBubble bubble; |
448 bubble.set_action_on_show( | 540 bubble.set_action_on_show( |
449 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); | 541 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); |
450 controller->Show(&bubble); | 542 controller->Show(&bubble); |
451 EXPECT_EQ(0U, controller->link_click_count()); | 543 EXPECT_EQ(0U, controller->link_click_count()); |
452 EXPECT_EQ(0U, controller->action_click_count()); | 544 EXPECT_EQ(0U, controller->action_click_count()); |
453 EXPECT_EQ(1U, controller->dismiss_click_count()); | 545 EXPECT_EQ(1U, controller->dismiss_click_count()); |
454 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | 546 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
455 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); | 547 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
548 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); | |
456 | 549 |
457 // Do it again, but now press different button (Disable). | 550 // Do it again, but now press different button (Disable). |
458 bubble.set_action_on_show( | 551 bubble.set_action_on_show( |
459 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); | 552 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); |
460 controller.reset(new TestDevModeBubbleController( | 553 controller.reset(new TestDevModeBubbleController( |
461 profile())); | 554 profile())); |
462 DevModeBubbleController::ClearProfileListForTesting(); | 555 DevModeBubbleController::ClearProfileListForTesting(); |
463 EXPECT_TRUE(controller->ShouldShow()); | 556 EXPECT_TRUE(controller->ShouldShow()); |
464 dev_mode_extensions = controller->GetExtensionList(); | 557 dev_mode_extensions = controller->GetExtensionList(); |
465 EXPECT_EQ(2U, dev_mode_extensions.size()); | 558 EXPECT_EQ(2U, dev_mode_extensions.size()); |
466 controller->Show(&bubble); // Simulate showing the bubble. | 559 controller->Show(&bubble); // Simulate showing the bubble. |
467 EXPECT_EQ(0U, controller->link_click_count()); | 560 EXPECT_EQ(0U, controller->link_click_count()); |
468 EXPECT_EQ(1U, controller->action_click_count()); | 561 EXPECT_EQ(1U, controller->action_click_count()); |
469 EXPECT_EQ(0U, controller->dismiss_click_count()); | 562 EXPECT_EQ(0U, controller->dismiss_click_count()); |
470 EXPECT_TRUE(service_->GetExtensionById(kId1, false) == NULL); | 563 EXPECT_TRUE(registry->disabled_extensions().GetByID(kId1) != NULL); |
471 EXPECT_TRUE(service_->GetExtensionById(kId2, false) == NULL); | 564 EXPECT_TRUE(registry->disabled_extensions().GetByID(kId2) != NULL); |
472 | 565 |
473 // Re-enable the extensions (disabled by the action button above). | 566 // Re-enable the extensions (disabled by the action button above). |
474 service_->EnableExtension(kId1); | 567 service_->EnableExtension(kId1); |
475 service_->EnableExtension(kId2); | 568 service_->EnableExtension(kId2); |
476 | 569 |
477 // Show the dialog a third time, but now press the learn more link. | 570 // Show the dialog a third time, but now press the learn more link. |
478 bubble.set_action_on_show( | 571 bubble.set_action_on_show( |
479 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); | 572 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); |
480 controller.reset(new TestDevModeBubbleController( | 573 controller.reset(new TestDevModeBubbleController( |
481 profile())); | 574 profile())); |
482 DevModeBubbleController::ClearProfileListForTesting(); | 575 DevModeBubbleController::ClearProfileListForTesting(); |
483 EXPECT_TRUE(controller->ShouldShow()); | 576 EXPECT_TRUE(controller->ShouldShow()); |
484 dev_mode_extensions = controller->GetExtensionList(); | 577 dev_mode_extensions = controller->GetExtensionList(); |
485 EXPECT_EQ(2U, dev_mode_extensions.size()); | 578 EXPECT_EQ(2U, dev_mode_extensions.size()); |
486 controller->Show(&bubble); // Simulate showing the bubble. | 579 controller->Show(&bubble); // Simulate showing the bubble. |
487 EXPECT_EQ(1U, controller->link_click_count()); | 580 EXPECT_EQ(1U, controller->link_click_count()); |
488 EXPECT_EQ(0U, controller->action_click_count()); | 581 EXPECT_EQ(0U, controller->action_click_count()); |
489 EXPECT_EQ(0U, controller->dismiss_click_count()); | 582 EXPECT_EQ(0U, controller->dismiss_click_count()); |
490 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | 583 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
491 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); | 584 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); |
492 | 585 |
493 // Now disable the unpacked extension. | 586 // Now disable the unpacked extension. |
494 service_->DisableExtension(kId1, Extension::DISABLE_USER_ACTION); | 587 service_->DisableExtension(kId1, Extension::DISABLE_USER_ACTION); |
495 service_->DisableExtension(kId2, Extension::DISABLE_USER_ACTION); | 588 service_->DisableExtension(kId2, Extension::DISABLE_USER_ACTION); |
496 | 589 |
497 controller.reset(new TestDevModeBubbleController( | 590 controller.reset(new TestDevModeBubbleController( |
498 profile())); | 591 profile())); |
499 DevModeBubbleController::ClearProfileListForTesting(); | 592 DevModeBubbleController::ClearProfileListForTesting(); |
500 EXPECT_FALSE(controller->ShouldShow()); | 593 EXPECT_FALSE(controller->ShouldShow()); |
501 dev_mode_extensions = controller->GetExtensionList(); | 594 dev_mode_extensions = controller->GetExtensionList(); |
502 EXPECT_EQ(0U, dev_mode_extensions.size()); | 595 EXPECT_EQ(0U, dev_mode_extensions.size()); |
503 } | 596 } |
504 | 597 |
505 // The feature this is meant to test is only implemented on Windows. | 598 // The feature this is meant to test is only implemented on Windows. |
506 #if defined(OS_WIN) | 599 #if defined(OS_WIN) |
507 #define MAYBE_SettingsApiControllerTest SettingsApiControllerTest | 600 #define MAYBE_SettingsApiControllerTest SettingsApiControllerTest |
508 #else | 601 #else |
509 #define MAYBE_SettingsApiControllerTest DISABLED_SettingsApiControllerTest | 602 #define MAYBE_SettingsApiControllerTest DISABLED_SettingsApiControllerTest |
510 #endif | 603 #endif |
511 | 604 |
512 TEST_F(ExtensionMessageBubbleTest, MAYBE_SettingsApiControllerTest) { | 605 TEST_F(ExtensionMessageBubbleTest, MAYBE_SettingsApiControllerTest) { |
513 Init(); | 606 Init(); |
514 extensions::ExtensionPrefs* prefs = | 607 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
515 extensions::ExtensionPrefs::Get(profile()); | |
516 | 608 |
517 for (int i = 0; i < 3; ++i) { | 609 for (int i = 0; i < 3; ++i) { |
518 switch (static_cast<SettingsApiOverrideType>(i)) { | 610 switch (static_cast<SettingsApiOverrideType>(i)) { |
519 case BUBBLE_TYPE_HOME_PAGE: | 611 case BUBBLE_TYPE_HOME_PAGE: |
520 // Load two extensions overriding home page and one overriding something | 612 // Load two extensions overriding home page and one overriding something |
521 // unrelated (to check for interference). Extension 2 should still win | 613 // unrelated (to check for interference). Extension 2 should still win |
522 // on the home page setting. | 614 // on the home page setting. |
523 LoadExtensionOverridingHome("1", kId1, Manifest::UNPACKED); | 615 ASSERT_TRUE(LoadExtensionOverridingHome("1", kId1, Manifest::UNPACKED)); |
524 LoadExtensionOverridingHome("2", kId2, Manifest::UNPACKED); | 616 ASSERT_TRUE(LoadExtensionOverridingHome("2", kId2, Manifest::UNPACKED)); |
525 LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED); | 617 ASSERT_TRUE( |
618 LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED)); | |
526 break; | 619 break; |
527 case BUBBLE_TYPE_SEARCH_ENGINE: | 620 case BUBBLE_TYPE_SEARCH_ENGINE: |
528 // We deliberately skip testing the search engine since it relies on | 621 // We deliberately skip testing the search engine since it relies on |
529 // TemplateURLServiceFactory that isn't available while unit testing. | 622 // TemplateURLServiceFactory that isn't available while unit testing. |
530 // This test is only simulating the bubble interaction with the user and | 623 // This test is only simulating the bubble interaction with the user and |
531 // that is more or less the same for the search engine as it is for the | 624 // that is more or less the same for the search engine as it is for the |
532 // others. | 625 // others. |
533 continue; | 626 continue; |
534 case BUBBLE_TYPE_STARTUP_PAGES: | 627 case BUBBLE_TYPE_STARTUP_PAGES: |
535 // Load two extensions overriding start page and one overriding | 628 // Load two extensions overriding start page and one overriding |
536 // something unrelated (to check for interference). Extension 2 should | 629 // something unrelated (to check for interference). Extension 2 should |
537 // still win on the startup page setting. | 630 // still win on the startup page setting. |
538 LoadExtensionOverridingStart("1", kId1, Manifest::UNPACKED); | 631 ASSERT_TRUE( |
539 LoadExtensionOverridingStart("2", kId2, Manifest::UNPACKED); | 632 LoadExtensionOverridingStart("1", kId1, Manifest::UNPACKED)); |
540 LoadExtensionOverridingHome("3", kId3, Manifest::UNPACKED); | 633 ASSERT_TRUE( |
634 LoadExtensionOverridingStart("2", kId2, Manifest::UNPACKED)); | |
635 ASSERT_TRUE(LoadExtensionOverridingHome("3", kId3, Manifest::UNPACKED)); | |
541 break; | 636 break; |
542 default: | 637 default: |
543 NOTREACHED(); | 638 NOTREACHED(); |
544 break; | 639 break; |
545 } | 640 } |
546 | 641 |
547 scoped_ptr<TestSettingsApiBubbleController> controller( | 642 scoped_ptr<TestSettingsApiBubbleController> controller( |
548 new TestSettingsApiBubbleController( | 643 new TestSettingsApiBubbleController( |
549 profile(), static_cast<SettingsApiOverrideType>(i))); | 644 profile(), static_cast<SettingsApiOverrideType>(i))); |
550 | 645 |
(...skipping 10 matching lines...) Expand all Loading... | |
561 | 656 |
562 // Simulate showing the bubble and dismissing it. | 657 // Simulate showing the bubble and dismissing it. |
563 FakeExtensionMessageBubble bubble; | 658 FakeExtensionMessageBubble bubble; |
564 bubble.set_action_on_show( | 659 bubble.set_action_on_show( |
565 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); | 660 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); |
566 controller->Show(&bubble); | 661 controller->Show(&bubble); |
567 EXPECT_EQ(0U, controller->link_click_count()); | 662 EXPECT_EQ(0U, controller->link_click_count()); |
568 EXPECT_EQ(0U, controller->action_click_count()); | 663 EXPECT_EQ(0U, controller->action_click_count()); |
569 EXPECT_EQ(1U, controller->dismiss_click_count()); | 664 EXPECT_EQ(1U, controller->dismiss_click_count()); |
570 // No extension should have become disabled. | 665 // No extension should have become disabled. |
571 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | 666 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
572 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); | 667 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
573 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); | 668 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); |
669 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); | |
574 // Only extension 2 should have been acknowledged. | 670 // Only extension 2 should have been acknowledged. |
575 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); | 671 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); |
576 EXPECT_TRUE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); | 672 EXPECT_TRUE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); |
577 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); | 673 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); |
578 // Clean up after ourselves. | 674 // Clean up after ourselves. |
579 prefs->SetSettingsApiBubbleBeenAcknowledged(kId2, false); | 675 prefs->SetSettingsApiBubbleBeenAcknowledged(kId2, false); |
580 | 676 |
581 // Simulate clicking the learn more link to dismiss it. | 677 // Simulate clicking the learn more link to dismiss it. |
582 bubble.set_action_on_show( | 678 bubble.set_action_on_show( |
583 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); | 679 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); |
584 controller.reset(new TestSettingsApiBubbleController( | 680 controller.reset(new TestSettingsApiBubbleController( |
585 profile(), static_cast<SettingsApiOverrideType>(i))); | 681 profile(), static_cast<SettingsApiOverrideType>(i))); |
586 controller->Show(&bubble); | 682 controller->Show(&bubble); |
587 EXPECT_EQ(1U, controller->link_click_count()); | 683 EXPECT_EQ(1U, controller->link_click_count()); |
588 EXPECT_EQ(0U, controller->action_click_count()); | 684 EXPECT_EQ(0U, controller->action_click_count()); |
589 EXPECT_EQ(0U, controller->dismiss_click_count()); | 685 EXPECT_EQ(0U, controller->dismiss_click_count()); |
590 // No extension should have become disabled. | 686 // No extension should have become disabled. |
591 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | 687 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
592 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); | 688 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); |
593 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); | 689 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); |
594 // Only extension 2 should have been acknowledged. | 690 // Only extension 2 should have been acknowledged. |
595 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); | 691 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); |
596 EXPECT_TRUE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); | 692 EXPECT_TRUE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); |
597 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); | 693 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); |
598 // Clean up after ourselves. | 694 // Clean up after ourselves. |
599 prefs->SetSettingsApiBubbleBeenAcknowledged(kId2, false); | 695 prefs->SetSettingsApiBubbleBeenAcknowledged(kId2, false); |
600 | 696 |
601 // Do it again, but now opt to disable the extension. | 697 // Do it again, but now opt to disable the extension. |
602 bubble.set_action_on_show( | 698 bubble.set_action_on_show( |
603 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); | 699 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); |
604 controller.reset(new TestSettingsApiBubbleController( | 700 controller.reset(new TestSettingsApiBubbleController( |
605 profile(), static_cast<SettingsApiOverrideType>(i))); | 701 profile(), static_cast<SettingsApiOverrideType>(i))); |
606 EXPECT_TRUE(controller->ShouldShow(kId2)); | 702 EXPECT_TRUE(controller->ShouldShow(kId2)); |
607 override_extensions = controller->GetExtensionList(); | 703 override_extensions = controller->GetExtensionList(); |
608 EXPECT_EQ(1U, override_extensions.size()); | 704 EXPECT_EQ(1U, override_extensions.size()); |
609 controller->Show(&bubble); // Simulate showing the bubble. | 705 controller->Show(&bubble); // Simulate showing the bubble. |
610 EXPECT_EQ(0U, controller->link_click_count()); | 706 EXPECT_EQ(0U, controller->link_click_count()); |
611 EXPECT_EQ(1U, controller->action_click_count()); | 707 EXPECT_EQ(1U, controller->action_click_count()); |
612 EXPECT_EQ(0U, controller->dismiss_click_count()); | 708 EXPECT_EQ(0U, controller->dismiss_click_count()); |
613 // Only extension 2 should have become disabled. | 709 // Only extension 2 should have become disabled. |
614 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | 710 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
615 EXPECT_TRUE(service_->GetExtensionById(kId2, false) == NULL); | 711 EXPECT_TRUE(registry->disabled_extensions().GetByID(kId2) != NULL); |
616 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); | 712 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); |
617 // No extension should have been acknowledged (it got disabled). | 713 // No extension should have been acknowledged (it got disabled). |
618 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); | 714 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); |
619 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); | 715 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); |
620 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); | 716 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); |
621 | 717 |
622 // Clean up after ourselves. | 718 // Clean up after ourselves. |
623 service_->UninstallExtension(kId1, false, NULL); | 719 service_->UninstallExtension(kId1, false, NULL); |
624 service_->UninstallExtension(kId2, false, NULL); | 720 service_->UninstallExtension(kId2, false, NULL); |
625 service_->UninstallExtension(kId3, false, NULL); | 721 service_->UninstallExtension(kId3, false, NULL); |
626 } | 722 } |
627 } | 723 } |
628 | 724 |
629 // The feature this is meant to test is only implemented on Windows. | 725 // The feature this is meant to test is only implemented on Windows. |
630 #if defined(OS_WIN) | 726 #if defined(OS_WIN) |
631 #define MAYBE_NtpOverriddenControllerTest NtpOverriddenControllerTest | 727 #define MAYBE_NtpOverriddenControllerTest NtpOverriddenControllerTest |
632 #else | 728 #else |
633 #define MAYBE_NtpOverriddenControllerTest DISABLED_NtpOverriddenControllerTest | 729 #define MAYBE_NtpOverriddenControllerTest DISABLED_NtpOverriddenControllerTest |
634 #endif | 730 #endif |
635 | 731 |
636 TEST_F(ExtensionMessageBubbleTest, MAYBE_NtpOverriddenControllerTest) { | 732 TEST_F(ExtensionMessageBubbleTest, MAYBE_NtpOverriddenControllerTest) { |
637 Init(); | 733 Init(); |
638 extensions::ExtensionPrefs* prefs = | 734 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
639 extensions::ExtensionPrefs::Get(profile()); | |
640 // Load two extensions overriding new tab page and one overriding something | 735 // Load two extensions overriding new tab page and one overriding something |
641 // unrelated (to check for interference). Extension 2 should still win | 736 // unrelated (to check for interference). Extension 2 should still win |
642 // on the new tab page setting. | 737 // on the new tab page setting. |
643 LoadExtensionOverridingNtp("1", kId1, Manifest::UNPACKED); | 738 ASSERT_TRUE(LoadExtensionOverridingNtp("1", kId1, Manifest::UNPACKED)); |
644 LoadExtensionOverridingNtp("2", kId2, Manifest::UNPACKED); | 739 ASSERT_TRUE(LoadExtensionOverridingNtp("2", kId2, Manifest::UNPACKED)); |
645 LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED); | 740 ASSERT_TRUE(LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED)); |
646 | 741 |
647 scoped_ptr<TestNtpOverriddenBubbleController> controller( | 742 scoped_ptr<TestNtpOverriddenBubbleController> controller( |
648 new TestNtpOverriddenBubbleController(profile())); | 743 new TestNtpOverriddenBubbleController(profile())); |
649 | 744 |
650 // The list will contain one enabled unpacked extension (ext 2). | 745 // The list will contain one enabled unpacked extension (ext 2). |
651 EXPECT_TRUE(controller->ShouldShow(kId2)); | 746 EXPECT_TRUE(controller->ShouldShow(kId2)); |
652 std::vector<base::string16> override_extensions = | 747 std::vector<base::string16> override_extensions = |
653 controller->GetExtensionList(); | 748 controller->GetExtensionList(); |
654 ASSERT_EQ(1U, override_extensions.size()); | 749 ASSERT_EQ(1U, override_extensions.size()); |
655 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == | 750 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == |
656 override_extensions[0].c_str()); | 751 override_extensions[0].c_str()); |
657 EXPECT_EQ(0U, controller->link_click_count()); | 752 EXPECT_EQ(0U, controller->link_click_count()); |
658 EXPECT_EQ(0U, controller->dismiss_click_count()); | 753 EXPECT_EQ(0U, controller->dismiss_click_count()); |
659 EXPECT_EQ(0U, controller->action_click_count()); | 754 EXPECT_EQ(0U, controller->action_click_count()); |
660 | 755 |
661 // Simulate showing the bubble and dismissing it. | 756 // Simulate showing the bubble and dismissing it. |
662 FakeExtensionMessageBubble bubble; | 757 FakeExtensionMessageBubble bubble; |
663 bubble.set_action_on_show( | 758 bubble.set_action_on_show( |
664 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); | 759 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); |
665 EXPECT_TRUE(controller->ShouldShow(kId2)); | 760 EXPECT_TRUE(controller->ShouldShow(kId2)); |
666 controller->Show(&bubble); | 761 controller->Show(&bubble); |
667 EXPECT_EQ(0U, controller->link_click_count()); | 762 EXPECT_EQ(0U, controller->link_click_count()); |
668 EXPECT_EQ(0U, controller->action_click_count()); | 763 EXPECT_EQ(0U, controller->action_click_count()); |
669 EXPECT_EQ(1U, controller->dismiss_click_count()); | 764 EXPECT_EQ(1U, controller->dismiss_click_count()); |
670 // No extension should have become disabled. | 765 // No extension should have become disabled. |
671 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | 766 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
672 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); | 767 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
673 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); | 768 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); |
769 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); | |
674 // Only extension 2 should have been acknowledged. | 770 // Only extension 2 should have been acknowledged. |
675 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1)); | 771 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1)); |
676 EXPECT_TRUE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2)); | 772 EXPECT_TRUE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2)); |
677 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3)); | 773 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3)); |
678 // Clean up after ourselves. | 774 // Clean up after ourselves. |
679 prefs->SetNtpOverriddenBubbleBeenAcknowledged(kId2, false); | 775 prefs->SetNtpOverriddenBubbleBeenAcknowledged(kId2, false); |
680 | 776 |
681 // Simulate clicking the learn more link to dismiss it. | 777 // Simulate clicking the learn more link to dismiss it. |
682 bubble.set_action_on_show( | 778 bubble.set_action_on_show( |
683 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); | 779 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); |
684 controller.reset(new TestNtpOverriddenBubbleController(profile())); | 780 controller.reset(new TestNtpOverriddenBubbleController(profile())); |
685 EXPECT_TRUE(controller->ShouldShow(kId2)); | 781 EXPECT_TRUE(controller->ShouldShow(kId2)); |
686 controller->Show(&bubble); | 782 controller->Show(&bubble); |
687 EXPECT_EQ(1U, controller->link_click_count()); | 783 EXPECT_EQ(1U, controller->link_click_count()); |
688 EXPECT_EQ(0U, controller->action_click_count()); | 784 EXPECT_EQ(0U, controller->action_click_count()); |
689 EXPECT_EQ(0U, controller->dismiss_click_count()); | 785 EXPECT_EQ(0U, controller->dismiss_click_count()); |
690 // No extension should have become disabled. | 786 // No extension should have become disabled. |
691 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | 787 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
692 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); | 788 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); |
693 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); | 789 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); |
694 // Only extension 2 should have been acknowledged. | 790 // Only extension 2 should have been acknowledged. |
695 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1)); | 791 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1)); |
696 EXPECT_TRUE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2)); | 792 EXPECT_TRUE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2)); |
697 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3)); | 793 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3)); |
698 // Clean up after ourselves. | 794 // Clean up after ourselves. |
699 prefs->SetNtpOverriddenBubbleBeenAcknowledged(kId2, false); | 795 prefs->SetNtpOverriddenBubbleBeenAcknowledged(kId2, false); |
700 | 796 |
701 // Do it again, but now opt to disable the extension. | 797 // Do it again, but now opt to disable the extension. |
702 bubble.set_action_on_show( | 798 bubble.set_action_on_show( |
703 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); | 799 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); |
704 controller.reset(new TestNtpOverriddenBubbleController(profile())); | 800 controller.reset(new TestNtpOverriddenBubbleController(profile())); |
705 EXPECT_TRUE(controller->ShouldShow(kId2)); | 801 EXPECT_TRUE(controller->ShouldShow(kId2)); |
706 override_extensions = controller->GetExtensionList(); | 802 override_extensions = controller->GetExtensionList(); |
707 EXPECT_EQ(1U, override_extensions.size()); | 803 EXPECT_EQ(1U, override_extensions.size()); |
708 controller->Show(&bubble); // Simulate showing the bubble. | 804 controller->Show(&bubble); // Simulate showing the bubble. |
709 EXPECT_EQ(0U, controller->link_click_count()); | 805 EXPECT_EQ(0U, controller->link_click_count()); |
710 EXPECT_EQ(1U, controller->action_click_count()); | 806 EXPECT_EQ(1U, controller->action_click_count()); |
711 EXPECT_EQ(0U, controller->dismiss_click_count()); | 807 EXPECT_EQ(0U, controller->dismiss_click_count()); |
712 // Only extension 2 should have become disabled. | 808 // Only extension 2 should have become disabled. |
713 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | 809 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
714 EXPECT_TRUE(service_->GetExtensionById(kId2, false) == NULL); | 810 EXPECT_TRUE(registry->disabled_extensions().GetByID(kId2) != NULL); |
715 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); | 811 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); |
716 // No extension should have been acknowledged (it got disabled). | 812 // No extension should have been acknowledged (it got disabled). |
717 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1)); | 813 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1)); |
718 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2)); | 814 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2)); |
719 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3)); | 815 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3)); |
720 | 816 |
721 // Clean up after ourselves. | 817 // Clean up after ourselves. |
722 service_->UninstallExtension(kId1, false, NULL); | 818 service_->UninstallExtension(kId1, false, NULL); |
723 service_->UninstallExtension(kId2, false, NULL); | 819 service_->UninstallExtension(kId2, false, NULL); |
724 service_->UninstallExtension(kId3, false, NULL); | 820 service_->UninstallExtension(kId3, false, NULL); |
725 } | 821 } |
726 | 822 |
823 void SetInstallTime(const std::string& extension_id, | |
824 const base::Time& time, | |
825 ExtensionPrefs* prefs) { | |
826 std::string time_str = base::Int64ToString(time.ToInternalValue()); | |
827 prefs->UpdateExtensionPref(extension_id, | |
828 "install_time", | |
829 new base::StringValue(time_str)); | |
830 } | |
831 | |
832 // The feature this is meant to test is only implemented on Windows. | |
833 #if defined(OS_WIN) | |
834 #define MAYBE_ProxyOverriddenControllerTest ProxyOverriddenControllerTest | |
835 #else | |
836 #define MAYBE_ProxyOverriddenControllerTest DISABLED_ProxyOverriddenControllerTe st | |
837 #endif | |
838 | |
839 TEST_F(ExtensionMessageBubbleTest, MAYBE_ProxyOverriddenControllerTest) { | |
840 Init(); | |
841 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | |
842 // Load two extensions overriding proxy and one overriding something | |
843 // unrelated (to check for interference). Extension 2 should still win | |
844 // on the proxy setting. | |
845 ASSERT_TRUE(LoadExtensionOverridingProxy("1", kId1, Manifest::UNPACKED)); | |
846 ASSERT_TRUE(LoadExtensionOverridingProxy("2", kId2, Manifest::UNPACKED)); | |
847 ASSERT_TRUE(LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED)); | |
848 | |
849 // The bubble will not show if the extension was installed in the last 7 days | |
850 // so we artificially set the install time to simulate an old install during | |
851 // testing. | |
852 base::Time old_enough = base::Time::Now() - base::TimeDelta::FromDays(8); | |
853 SetInstallTime(kId1, old_enough, prefs); | |
854 SetInstallTime(kId2, base::Time::Now(), prefs); | |
855 SetInstallTime(kId3, old_enough, prefs); | |
856 | |
857 scoped_ptr<TestProxyOverriddenBubbleController> controller( | |
858 new TestProxyOverriddenBubbleController(profile())); | |
859 | |
860 // The second extension is too new to warn about. | |
861 EXPECT_FALSE(controller->ShouldShow(kId1)); | |
862 EXPECT_FALSE(controller->ShouldShow(kId2)); | |
863 // Lets make it old enough. | |
864 SetInstallTime(kId2, old_enough, prefs); | |
865 | |
866 // The list will contain one enabled unpacked extension (ext 2). | |
867 EXPECT_TRUE(controller->ShouldShow(kId2)); | |
868 EXPECT_FALSE(controller->ShouldShow(kId3)); | |
869 std::vector<base::string16> override_extensions = | |
870 controller->GetExtensionList(); | |
871 ASSERT_EQ(1U, override_extensions.size()); | |
872 EXPECT_EQ(base::ASCIIToUTF16("Extension 2"), override_extensions[0]); | |
873 EXPECT_EQ(0U, controller->link_click_count()); | |
874 EXPECT_EQ(0U, controller->dismiss_click_count()); | |
875 EXPECT_EQ(0U, controller->action_click_count()); | |
876 | |
877 // Simulate showing the bubble and dismissing it. | |
878 FakeExtensionMessageBubble bubble; | |
879 bubble.set_action_on_show( | |
880 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); | |
881 controller->Show(&bubble); | |
882 EXPECT_EQ(0U, controller->link_click_count()); | |
883 EXPECT_EQ(0U, controller->action_click_count()); | |
884 EXPECT_EQ(1U, controller->dismiss_click_count()); | |
885 // No extension should have become disabled. | |
886 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); | |
887 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); | |
888 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); | |
889 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); | |
890 // Only extension 2 should have been acknowledged. | |
891 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId1)); | |
892 EXPECT_TRUE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId2)); | |
893 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId3)); | |
894 // Clean up after ourselves. | |
895 prefs->SetProxyOverriddenBubbleBeenAcknowledged(kId2, false); | |
896 | |
897 // Simulate clicking the learn more link to dismiss it. | |
898 bubble.set_action_on_show( | |
899 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); | |
900 controller.reset(new TestProxyOverriddenBubbleController(profile())); | |
901 EXPECT_TRUE(controller->ShouldShow(kId2)); | |
902 controller->Show(&bubble); | |
903 EXPECT_EQ(1U, controller->link_click_count()); | |
904 EXPECT_EQ(0U, controller->action_click_count()); | |
905 EXPECT_EQ(0U, controller->dismiss_click_count()); | |
906 // No extension should have become disabled. | |
907 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); | |
908 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); | |
909 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); | |
910 // Only extension 2 should have been acknowledged. | |
911 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId1)); | |
912 EXPECT_TRUE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId2)); | |
913 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId3)); | |
914 // Clean up after ourselves. | |
915 prefs->SetProxyOverriddenBubbleBeenAcknowledged(kId2, false); | |
916 | |
917 // Do it again, but now opt to disable the extension. | |
918 bubble.set_action_on_show( | |
919 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); | |
920 controller.reset(new TestProxyOverriddenBubbleController(profile())); | |
921 EXPECT_TRUE(controller->ShouldShow(kId2)); | |
922 override_extensions = controller->GetExtensionList(); | |
923 EXPECT_EQ(1U, override_extensions.size()); | |
924 controller->Show(&bubble); // Simulate showing the bubble. | |
925 EXPECT_EQ(0U, controller->link_click_count()); | |
926 EXPECT_EQ(1U, controller->action_click_count()); | |
927 EXPECT_EQ(0U, controller->dismiss_click_count()); | |
928 // Only extension 2 should have become disabled. | |
929 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); | |
930 EXPECT_TRUE(registry->disabled_extensions().GetByID(kId2) != NULL); | |
931 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); | |
932 // No extension should have been acknowledged (it got disabled). | |
933 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId1)); | |
934 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId2)); | |
935 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId3)); | |
936 | |
937 // Clean up after ourselves. | |
938 service_->UninstallExtension(kId1, false, NULL); | |
939 service_->UninstallExtension(kId2, false, NULL); | |
940 service_->UninstallExtension(kId3, false, NULL); | |
941 } | |
942 | |
727 } // namespace extensions | 943 } // namespace extensions |
OLD | NEW |