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