Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(540)

Side by Side Diff: chrome/browser/extensions/extension_message_bubble_controller_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698