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

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

Issue 9960087: Revert 13676 - Revert 131665 - Add a preference for why an extension is disabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/ref_counted.h" 5 #include "base/memory/ref_counted.h"
6 #include "base/stl_util.h" 6 #include "base/stl_util.h"
7 #include "chrome/browser/extensions/autoupdate_interceptor.h" 7 #include "chrome/browser/extensions/autoupdate_interceptor.h"
8 #include "chrome/browser/extensions/extension_browsertest.h" 8 #include "chrome/browser/extensions/extension_browsertest.h"
9 #include "chrome/browser/extensions/extension_host.h" 9 #include "chrome/browser/extensions/extension_host.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 std::string extension_id = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; 132 std::string extension_id = "bjafgdebaacbbbecmhlhpofkepfkgcpa";
133 ASSERT_TRUE(LoadExtension( 133 ASSERT_TRUE(LoadExtension(
134 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") 134 test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
135 .AppendASCII(extension_id) 135 .AppendASCII(extension_id)
136 .AppendASCII("1.0"))); 136 .AppendASCII("1.0")));
137 ASSERT_EQ(size_before + 1, service->extensions()->size()); 137 ASSERT_EQ(size_before + 1, service->extensions()->size());
138 EXPECT_EQ(0u, service->disabled_extensions()->size()); 138 EXPECT_EQ(0u, service->disabled_extensions()->size());
139 EXPECT_TRUE(manager->GetBackgroundHostForExtension(extension_id)); 139 EXPECT_TRUE(manager->GetBackgroundHostForExtension(extension_id));
140 140
141 // After disabling, the background page should go away. 141 // After disabling, the background page should go away.
142 service->DisableExtension(extension_id); 142 DisableExtension(extension_id);
143 EXPECT_EQ(size_before, service->extensions()->size()); 143 EXPECT_EQ(size_before, service->extensions()->size());
144 EXPECT_EQ(1u, service->disabled_extensions()->size()); 144 EXPECT_EQ(1u, service->disabled_extensions()->size());
145 EXPECT_FALSE(manager->GetBackgroundHostForExtension(extension_id)); 145 EXPECT_FALSE(manager->GetBackgroundHostForExtension(extension_id));
146 146
147 // And bring it back. 147 // And bring it back.
148 service->EnableExtension(extension_id); 148 EnableExtension(extension_id);
149 EXPECT_EQ(size_before + 1, service->extensions()->size()); 149 EXPECT_EQ(size_before + 1, service->extensions()->size());
150 EXPECT_EQ(0u, service->disabled_extensions()->size()); 150 EXPECT_EQ(0u, service->disabled_extensions()->size());
151 EXPECT_TRUE(manager->GetBackgroundHostForExtension(extension_id)); 151 EXPECT_TRUE(manager->GetBackgroundHostForExtension(extension_id));
152 } 152 }
153 153
154 // Used for testing notifications sent during extension updates. 154 // Used for testing notifications sent during extension updates.
155 class NotificationListener : public content::NotificationObserver { 155 class NotificationListener : public content::NotificationObserver {
156 public: 156 public:
157 NotificationListener() : started_(false), finished_(false) { 157 NotificationListener() : started_(false), finished_(false) {
158 int types[] = { 158 int types[] = {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 315
316 // Install version 1 of the extension. 316 // Install version 1 of the extension.
317 ExtensionTestMessageListener listener1("v1 installed", false); 317 ExtensionTestMessageListener listener1("v1 installed", false);
318 ExtensionService* service = browser()->profile()->GetExtensionService(); 318 ExtensionService* service = browser()->profile()->GetExtensionService();
319 const size_t enabled_size_before = service->extensions()->size(); 319 const size_t enabled_size_before = service->extensions()->size();
320 const size_t disabled_size_before = service->disabled_extensions()->size(); 320 const size_t disabled_size_before = service->disabled_extensions()->size();
321 const Extension* extension = 321 const Extension* extension =
322 InstallExtension(basedir.AppendASCII("v1.crx"), 1); 322 InstallExtension(basedir.AppendASCII("v1.crx"), 1);
323 ASSERT_TRUE(extension); 323 ASSERT_TRUE(extension);
324 listener1.WaitUntilSatisfied(); 324 listener1.WaitUntilSatisfied();
325 service->DisableExtension(extension->id()); 325 DisableExtension(extension->id());
326 ASSERT_EQ(disabled_size_before + 1, service->disabled_extensions()->size()); 326 ASSERT_EQ(disabled_size_before + 1, service->disabled_extensions()->size());
327 ASSERT_EQ(enabled_size_before, service->extensions()->size()); 327 ASSERT_EQ(enabled_size_before, service->extensions()->size());
328 ASSERT_EQ("ogjcoiohnmldgjemafoockdghcjciccf", extension->id()); 328 ASSERT_EQ("ogjcoiohnmldgjemafoockdghcjciccf", extension->id());
329 ASSERT_EQ("1.0", extension->VersionString()); 329 ASSERT_EQ("1.0", extension->VersionString());
330 330
331 // We don't want autoupdate blacklist checks. 331 // We don't want autoupdate blacklist checks.
332 service->updater()->set_blacklist_checks_enabled(false); 332 service->updater()->set_blacklist_checks_enabled(false);
333 333
334 ExtensionTestMessageListener listener2("v2 installed", false); 334 ExtensionTestMessageListener listener2("v2 installed", false);
335 // Run autoupdate and make sure version 2 of the extension was installed but 335 // Run autoupdate and make sure version 2 of the extension was installed but
336 // is still disabled. 336 // is still disabled.
337 service->updater()->CheckNow(); 337 service->updater()->CheckNow();
338 ASSERT_TRUE(WaitForExtensionInstall()); 338 ASSERT_TRUE(WaitForExtensionInstall());
339 ASSERT_EQ(disabled_size_before + 1, service->disabled_extensions()->size()); 339 ASSERT_EQ(disabled_size_before + 1, service->disabled_extensions()->size());
340 ASSERT_EQ(enabled_size_before, service->extensions()->size()); 340 ASSERT_EQ(enabled_size_before, service->extensions()->size());
341 extension = service->GetExtensionById( 341 extension = service->GetExtensionById(
342 "ogjcoiohnmldgjemafoockdghcjciccf", true); 342 "ogjcoiohnmldgjemafoockdghcjciccf", true);
343 ASSERT_TRUE(extension); 343 ASSERT_TRUE(extension);
344 ASSERT_FALSE(service->GetExtensionById( 344 ASSERT_FALSE(service->GetExtensionById(
345 "ogjcoiohnmldgjemafoockdghcjciccf", false)); 345 "ogjcoiohnmldgjemafoockdghcjciccf", false));
346 ASSERT_EQ("2.0", extension->VersionString()); 346 ASSERT_EQ("2.0", extension->VersionString());
347 347
348 // The extension should have not made the callback because it is disabled. 348 // The extension should have not made the callback because it is disabled.
349 // When we enabled it, it should then make the callback. 349 // When we enabled it, it should then make the callback.
350 ASSERT_FALSE(listener2.was_satisfied()); 350 ASSERT_FALSE(listener2.was_satisfied());
351 service->EnableExtension(extension->id()); 351 EnableExtension(extension->id());
352 listener2.WaitUntilSatisfied(); 352 listener2.WaitUntilSatisfied();
353 ASSERT_TRUE(notification_listener.started()); 353 ASSERT_TRUE(notification_listener.started());
354 ASSERT_TRUE(notification_listener.finished()); 354 ASSERT_TRUE(notification_listener.finished());
355 ASSERT_TRUE(ContainsKey(notification_listener.updates(), 355 ASSERT_TRUE(ContainsKey(notification_listener.updates(),
356 "ogjcoiohnmldgjemafoockdghcjciccf")); 356 "ogjcoiohnmldgjemafoockdghcjciccf"));
357 notification_listener.Reset(); 357 notification_listener.Reset();
358 } 358 }
359 359
360 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalUrlUpdate) { 360 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalUrlUpdate) {
361 ExtensionService* service = browser()->profile()->GetExtensionService(); 361 ExtensionService* service = browser()->profile()->GetExtensionService();
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 477
478 // Check if the extension got installed. 478 // Check if the extension got installed.
479 ASSERT_TRUE(WaitForExtensionInstall()); 479 ASSERT_TRUE(WaitForExtensionInstall());
480 ASSERT_EQ(size_before + 1, service->extensions()->size()); 480 ASSERT_EQ(size_before + 1, service->extensions()->size());
481 const Extension* extension = service->GetExtensionById(kExtensionId, false); 481 const Extension* extension = service->GetExtensionById(kExtensionId, false);
482 ASSERT_TRUE(extension); 482 ASSERT_TRUE(extension);
483 ASSERT_EQ("2.0", extension->VersionString()); 483 ASSERT_EQ("2.0", extension->VersionString());
484 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); 484 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location());
485 485
486 // Try to disable and uninstall the extension which should fail. 486 // Try to disable and uninstall the extension which should fail.
487 service->DisableExtension(kExtensionId); 487 DisableExtension(kExtensionId);
488 EXPECT_EQ(size_before + 1, service->extensions()->size()); 488 EXPECT_EQ(size_before + 1, service->extensions()->size());
489 EXPECT_EQ(0u, service->disabled_extensions()->size()); 489 EXPECT_EQ(0u, service->disabled_extensions()->size());
490 UninstallExtension(kExtensionId); 490 UninstallExtension(kExtensionId);
491 EXPECT_EQ(size_before + 1, service->extensions()->size()); 491 EXPECT_EQ(size_before + 1, service->extensions()->size());
492 EXPECT_EQ(0u, service->disabled_extensions()->size()); 492 EXPECT_EQ(0u, service->disabled_extensions()->size());
493 493
494 // Now try to disable it through the management api, again failing. 494 // Now try to disable it through the management api, again failing.
495 ExtensionTestMessageListener listener1("ready", false); 495 ExtensionTestMessageListener listener1("ready", false);
496 ASSERT_TRUE(LoadExtension( 496 ASSERT_TRUE(LoadExtension(
497 test_data_dir_.AppendASCII("management/uninstall_extension"))); 497 test_data_dir_.AppendASCII("management/uninstall_extension")));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 569
570 // User install again, but have it disabled too before setting the policy. 570 // User install again, but have it disabled too before setting the policy.
571 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); 571 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1));
572 ASSERT_EQ(size_before + 1, service->extensions()->size()); 572 ASSERT_EQ(size_before + 1, service->extensions()->size());
573 extension = service->GetExtensionById(kExtensionId, false); 573 extension = service->GetExtensionById(kExtensionId, false);
574 ASSERT_TRUE(extension); 574 ASSERT_TRUE(extension);
575 EXPECT_EQ(Extension::INTERNAL, extension->location()); 575 EXPECT_EQ(Extension::INTERNAL, extension->location());
576 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); 576 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId));
577 EXPECT_TRUE(service->disabled_extensions()->is_empty()); 577 EXPECT_TRUE(service->disabled_extensions()->is_empty());
578 578
579 service->DisableExtension(kExtensionId); 579 DisableExtension(kExtensionId);
580 EXPECT_EQ(1u, service->disabled_extensions()->size()); 580 EXPECT_EQ(1u, service->disabled_extensions()->size());
581 extension = service->GetExtensionById(kExtensionId, true); 581 extension = service->GetExtensionById(kExtensionId, true);
582 EXPECT_TRUE(extension); 582 EXPECT_TRUE(extension);
583 EXPECT_FALSE(service->IsExtensionEnabled(kExtensionId)); 583 EXPECT_FALSE(service->IsExtensionEnabled(kExtensionId));
584 584
585 // Install the policy again. It should overwrite the extension's location, 585 // Install the policy again. It should overwrite the extension's location,
586 // and force enable it too. 586 // and force enable it too.
587 { 587 {
588 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); 588 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList);
589 ListValue* forcelist = pref_update.Get(); 589 ListValue* forcelist = pref_update.Get();
590 ASSERT_TRUE(forcelist->empty()); 590 ASSERT_TRUE(forcelist->empty());
591 forcelist->Append(Value::CreateStringValue( 591 forcelist->Append(Value::CreateStringValue(
592 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest")); 592 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest"));
593 } 593 }
594 ASSERT_TRUE(WaitForExtensionInstall()); 594 ASSERT_TRUE(WaitForExtensionInstall());
595 ASSERT_EQ(size_before + 1, service->extensions()->size()); 595 ASSERT_EQ(size_before + 1, service->extensions()->size());
596 extension = service->GetExtensionById(kExtensionId, false); 596 extension = service->GetExtensionById(kExtensionId, false);
597 ASSERT_TRUE(extension); 597 ASSERT_TRUE(extension);
598 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); 598 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location());
599 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); 599 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId));
600 EXPECT_TRUE(service->disabled_extensions()->is_empty()); 600 EXPECT_TRUE(service->disabled_extensions()->is_empty());
601 } 601 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_management_apitest.cc ('k') | chrome/browser/extensions/extension_prefs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698