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

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

Issue 7605001: Extensions installed by policy overrun previously installed extensions. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: More tests. Created 9 years, 4 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 PendingExtensionManager* pending_extension_manager = 393 PendingExtensionManager* pending_extension_manager =
394 service->pending_extension_manager(); 394 service->pending_extension_manager();
395 395
396 // The code that reads external_extensions.json uses this method to inform 396 // The code that reads external_extensions.json uses this method to inform
397 // the ExtensionService of an extension to download. Using the real code 397 // the ExtensionService of an extension to download. Using the real code
398 // is race-prone, because instantating the ExtensionService starts a read 398 // is race-prone, because instantating the ExtensionService starts a read
399 // of external_extensions.json before this test function starts. 399 // of external_extensions.json before this test function starts.
400 400
401 pending_extension_manager->AddFromExternalUpdateUrl( 401 pending_extension_manager->AddFromExternalUpdateUrl(
402 kExtensionId, GURL("http://localhost/autoupdate/manifest"), 402 kExtensionId, GURL("http://localhost/autoupdate/manifest"),
403 Extension::EXTERNAL_PREF_DOWNLOAD); 403 Extension::EXTERNAL_PREF_DOWNLOAD, false);
404 404
405 // Run autoupdate and make sure version 2 of the extension was installed. 405 // Run autoupdate and make sure version 2 of the extension was installed.
406 service->updater()->CheckNow(); 406 service->updater()->CheckNow();
407 ASSERT_TRUE(WaitForExtensionInstall()); 407 ASSERT_TRUE(WaitForExtensionInstall());
408 const ExtensionList* extensions = service->extensions(); 408 const ExtensionList* extensions = service->extensions();
409 ASSERT_EQ(size_before + 1, extensions->size()); 409 ASSERT_EQ(size_before + 1, extensions->size());
410 ASSERT_EQ(kExtensionId, extensions->at(size_before)->id()); 410 ASSERT_EQ(kExtensionId, extensions->at(size_before)->id());
411 ASSERT_EQ("2.0", extensions->at(size_before)->VersionString()); 411 ASSERT_EQ("2.0", extensions->at(size_before)->VersionString());
412 412
413 // Uninstalling the extension should set a pref that keeps the extension from 413 // Uninstalling the extension should set a pref that keeps the extension from
414 // being installed again the next time external_extensions.json is read. 414 // being installed again the next time external_extensions.json is read.
415 415
416 UninstallExtension(kExtensionId); 416 UninstallExtension(kExtensionId);
417 417
418 ExtensionPrefs* extension_prefs = service->extension_prefs(); 418 ExtensionPrefs* extension_prefs = service->extension_prefs();
419 EXPECT_TRUE(extension_prefs->IsExternalExtensionUninstalled(kExtensionId)) 419 EXPECT_TRUE(extension_prefs->IsExternalExtensionUninstalled(kExtensionId))
420 << "Uninstalling should set kill bit on externaly installed extension."; 420 << "Uninstalling should set kill bit on externaly installed extension.";
421 421
422 // Try to install the extension again from an external source. It should fail 422 // Try to install the extension again from an external source. It should fail
423 // because of the killbit. 423 // because of the killbit.
424 pending_extension_manager->AddFromExternalUpdateUrl( 424 pending_extension_manager->AddFromExternalUpdateUrl(
425 kExtensionId, GURL("http://localhost/autoupdate/manifest"), 425 kExtensionId, GURL("http://localhost/autoupdate/manifest"),
426 Extension::EXTERNAL_PREF_DOWNLOAD); 426 Extension::EXTERNAL_PREF_DOWNLOAD, false);
427 EXPECT_FALSE(pending_extension_manager->IsIdPending(kExtensionId)) 427 EXPECT_FALSE(pending_extension_manager->IsIdPending(kExtensionId))
428 << "External reinstall of a killed extension shouldn't work."; 428 << "External reinstall of a killed extension shouldn't work.";
429 EXPECT_TRUE(extension_prefs->IsExternalExtensionUninstalled(kExtensionId)) 429 EXPECT_TRUE(extension_prefs->IsExternalExtensionUninstalled(kExtensionId))
430 << "External reinstall of a killed extension should leave it killed."; 430 << "External reinstall of a killed extension should leave it killed.";
431 431
432 // Installing from non-external source. 432 // Installing from non-external source.
433 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); 433 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1));
434 434
435 EXPECT_FALSE(extension_prefs->IsExternalExtensionUninstalled(kExtensionId)) 435 EXPECT_FALSE(extension_prefs->IsExternalExtensionUninstalled(kExtensionId))
436 << "Reinstalling should clear the kill bit."; 436 << "Reinstalling should clear the kill bit.";
437 437
438 // Uninstalling from a non-external source should not set the kill bit. 438 // Uninstalling from a non-external source should not set the kill bit.
439 UninstallExtension(kExtensionId); 439 UninstallExtension(kExtensionId);
440 440
441 EXPECT_FALSE(extension_prefs->IsExternalExtensionUninstalled(kExtensionId)) 441 EXPECT_FALSE(extension_prefs->IsExternalExtensionUninstalled(kExtensionId))
442 << "Uninstalling non-external extension should not set kill bit."; 442 << "Uninstalling non-external extension should not set kill bit.";
443 } 443 }
444 444
445 namespace {
446
447 const char* kForceInstallNotEmptyHelp =
448 "A policy may already be controlling the list of force-installed "
449 "extensions. Please remove all policy settings from your computer "
450 "before running tests. E.g. from /etc/chromium/policies Linux or "
451 "from the registry on Windows, etc.";
452
453 }
454
445 // See http://crbug.com/57378 for flakiness details. 455 // See http://crbug.com/57378 for flakiness details.
446 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalPolicyRefresh) { 456 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalPolicyRefresh) {
447 ExtensionService* service = browser()->profile()->GetExtensionService(); 457 ExtensionService* service = browser()->profile()->GetExtensionService();
448 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; 458 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf";
449 // We don't want autoupdate blacklist checks. 459 // We don't want autoupdate blacklist checks.
450 service->updater()->set_blacklist_checks_enabled(false); 460 service->updater()->set_blacklist_checks_enabled(false);
451 461
452 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); 462 FilePath basedir = test_data_dir_.AppendASCII("autoupdate");
453 463
454 // Note: This interceptor gets requests on the IO thread. 464 // Note: This interceptor gets requests on the IO thread.
455 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); 465 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor());
456 URLFetcher::enable_interception_for_tests(true); 466 URLFetcher::enable_interception_for_tests(true);
457 467
458 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", 468 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest",
459 basedir.AppendASCII("manifest_v2.xml")); 469 basedir.AppendASCII("manifest_v2.xml"));
460 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", 470 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx",
461 basedir.AppendASCII("v2.crx")); 471 basedir.AppendASCII("v2.crx"));
462 472
463 const size_t size_before = service->extensions()->size(); 473 const size_t size_before = service->extensions()->size();
464 ASSERT_TRUE(service->disabled_extensions()->empty()); 474 ASSERT_TRUE(service->disabled_extensions()->empty());
465 475
466 PrefService* prefs = browser()->profile()->GetPrefs(); 476 PrefService* prefs = browser()->profile()->GetPrefs();
467 const ListValue* forcelist = 477 const ListValue* forcelist =
468 prefs->GetList(prefs::kExtensionInstallForceList); 478 prefs->GetList(prefs::kExtensionInstallForceList);
469 ASSERT_TRUE(forcelist->empty()) 479 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp;
470 << "A policy may already be controlling the list of force-installed "
471 << "extensions. Please remove all policy settings from your computer "
472 << "before running tests. E.g. from /etc/chromium/policies Linux or "
473 << "from the registry on Windows, etc.";
474 480
475 { 481 {
476 // Set the policy as a user preference and fire notification observers. 482 // Set the policy as a user preference and fire notification observers.
477 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); 483 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList);
478 ListValue* forcelist = pref_update.Get(); 484 ListValue* forcelist = pref_update.Get();
479 ASSERT_TRUE(forcelist->empty()); 485 ASSERT_TRUE(forcelist->empty());
480 forcelist->Append(Value::CreateStringValue( 486 forcelist->Append(Value::CreateStringValue(
481 std::string(kExtensionId) + 487 std::string(kExtensionId) +
482 ";http://localhost/autoupdate/manifest")); 488 ";http://localhost/autoupdate/manifest"));
483 } 489 }
(...skipping 25 matching lines...) Expand all
509 515
510 // Check that emptying the list triggers uninstall. 516 // Check that emptying the list triggers uninstall.
511 { 517 {
512 prefs->ClearPref(prefs::kExtensionInstallForceList); 518 prefs->ClearPref(prefs::kExtensionInstallForceList);
513 } 519 }
514 EXPECT_EQ(size_before + 1, extensions->size()); 520 EXPECT_EQ(size_before + 1, extensions->size());
515 ExtensionList::const_iterator i; 521 ExtensionList::const_iterator i;
516 for (i = extensions->begin(); i != extensions->end(); ++i) 522 for (i = extensions->begin(); i != extensions->end(); ++i)
517 EXPECT_NE(kExtensionId, (*i)->id()); 523 EXPECT_NE(kExtensionId, (*i)->id());
518 } 524 }
525
526 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, PolicyOverridesUserInstall) {
527 ExtensionService* service = browser()->profile()->GetExtensionService();
528 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf";
529 service->updater()->set_blacklist_checks_enabled(false);
530 const size_t size_before = service->extensions()->size();
531 FilePath basedir = test_data_dir_.AppendASCII("autoupdate");
532 ASSERT_TRUE(service->disabled_extensions()->empty());
533
534 // Note: This interceptor gets requests on the IO thread.
535 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor());
536 URLFetcher::enable_interception_for_tests(true);
537
538 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest",
539 basedir.AppendASCII("manifest_v2.xml"));
540 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx",
541 basedir.AppendASCII("v2.crx"));
542
543 // Check that the policy is initially empty.
544 PrefService* prefs = browser()->profile()->GetPrefs();
545 const ListValue* forcelist =
546 prefs->GetList(prefs::kExtensionInstallForceList);
547 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp;
548
549 // User install of the extension.
550 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1));
551 const ExtensionList* extensions = service->extensions();
552 ASSERT_EQ(size_before + 1, extensions->size());
553 const Extension* extension = extensions->at(size_before);
554 ASSERT_EQ(kExtensionId, extension->id());
555 EXPECT_EQ(Extension::INTERNAL, extension->location());
556 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId));
557
558 // Setup the force install policy. It should override the location.
559 {
560 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList);
561 ListValue* forcelist = pref_update.Get();
562 ASSERT_TRUE(forcelist->empty());
563 forcelist->Append(Value::CreateStringValue(
564 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest"));
565 }
566 ASSERT_TRUE(WaitForExtensionInstall());
567 extensions = service->extensions();
568 ASSERT_EQ(size_before + 1, extensions->size());
569 extension = extensions->at(size_before);
570 ASSERT_EQ(kExtensionId, extension->id());
571 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location());
572 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId));
573
574 // Remove the policy, and verify that the extension was uninstalled.
575 // TODO(joaodasilva): it would be nicer if the extension was kept instead,
576 // and reverted location to INTERNAL or whatever it was before the policy
577 // was applied.
578 {
579 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList);
580 ListValue* forcelist = pref_update.Get();
581 ASSERT_TRUE(!forcelist->empty());
582 forcelist->Clear();
583 }
584 extensions = service->extensions();
585 ASSERT_EQ(size_before, extensions->size());
586 extension = service->GetExtensionById(kExtensionId, true);
587 EXPECT_TRUE(extension == NULL);
588
589 // User install again, but have it disabled too before setting the policy.
590 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1));
591 extensions = service->extensions();
592 ASSERT_EQ(size_before + 1, extensions->size());
593 extension = extensions->at(size_before);
594 ASSERT_EQ(kExtensionId, extension->id());
595 EXPECT_EQ(Extension::INTERNAL, extension->location());
596 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId));
597 EXPECT_TRUE(service->disabled_extensions()->empty());
598
599 service->DisableExtension(kExtensionId);
600 EXPECT_EQ(1u, service->disabled_extensions()->size());
601 EXPECT_EQ(kExtensionId, service->disabled_extensions()->at(0)->id());
602 EXPECT_FALSE(service->IsExtensionEnabled(kExtensionId));
603
604 // Install the policy again. It should overwrite the extension's location,
605 // and force enable it too.
606 {
607 ListPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList);
608 ListValue* forcelist = pref_update.Get();
609 ASSERT_TRUE(forcelist->empty());
610 forcelist->Append(Value::CreateStringValue(
611 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest"));
612 }
613 ASSERT_TRUE(WaitForExtensionInstall());
614 extensions = service->extensions();
615 ASSERT_EQ(size_before + 1, extensions->size());
616 extension = extensions->at(size_before);
617 ASSERT_EQ(kExtensionId, extension->id());
618 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location());
619 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId));
620 EXPECT_TRUE(service->disabled_extensions()->empty());
621 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_service.cc » ('j') | chrome/browser/extensions/pending_extension_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698