| OLD | NEW |
| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/prefs/scoped_user_pref_update.h" | 8 #include "base/prefs/scoped_user_pref_update.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "chrome/browser/extensions/extension_browsertest.h" | 12 #include "chrome/browser/extensions/extension_browsertest.h" |
| 13 #include "chrome/browser/extensions/extension_management.h" | 13 #include "chrome/browser/extensions/extension_management.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/extensions/extension_test_message_listener.h" | 15 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 16 #include "chrome/browser/extensions/updater/extension_downloader.h" | 16 #include "chrome/browser/extensions/updater/extension_downloader.h" |
| 17 #include "chrome/browser/extensions/updater/extension_updater.h" | 17 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 22 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
| 23 #include "components/policy/core/browser/browser_policy_connector.h" | 23 #include "components/policy/core/browser/browser_policy_connector.h" |
| 24 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 24 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| 25 #include "components/policy/core/common/policy_map.h" | 25 #include "components/policy/core/common/policy_map.h" |
| 26 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
| 28 #include "content/public/test/browser_test_utils.h" | 29 #include "content/public/test/browser_test_utils.h" |
| 29 #include "content/test/net/url_request_prepackaged_interceptor.h" | |
| 30 #include "extensions/browser/extension_host.h" | 30 #include "extensions/browser/extension_host.h" |
| 31 #include "extensions/browser/extension_prefs.h" | 31 #include "extensions/browser/extension_prefs.h" |
| 32 #include "extensions/browser/extension_registry.h" | 32 #include "extensions/browser/extension_registry.h" |
| 33 #include "extensions/browser/extension_system.h" | 33 #include "extensions/browser/extension_system.h" |
| 34 #include "extensions/browser/notification_types.h" | 34 #include "extensions/browser/notification_types.h" |
| 35 #include "net/url_request/test_url_request_interceptor.h" |
| 35 #include "net/url_request/url_fetcher.h" | 36 #include "net/url_request/url_fetcher.h" |
| 36 #include "policy/policy_constants.h" | 37 #include "policy/policy_constants.h" |
| 37 #include "testing/gmock/include/gmock/gmock.h" | 38 #include "testing/gmock/include/gmock/gmock.h" |
| 38 | 39 |
| 40 using content::BrowserThread; |
| 39 using extensions::Extension; | 41 using extensions::Extension; |
| 40 using extensions::ExtensionRegistry; | 42 using extensions::ExtensionRegistry; |
| 41 using extensions::Manifest; | 43 using extensions::Manifest; |
| 42 using policy::PolicyMap; | 44 using policy::PolicyMap; |
| 43 using testing::Return; | 45 using testing::Return; |
| 44 using testing::_; | 46 using testing::_; |
| 45 | 47 |
| 46 namespace { | 48 namespace { |
| 47 | 49 |
| 48 std::string BuildForceInstallPolicyValue(const char* extension_id, | 50 std::string BuildForceInstallPolicyValue(const char* extension_id, |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 #define MAYBE_AutoUpdate DISABLED_AutoUpdate | 278 #define MAYBE_AutoUpdate DISABLED_AutoUpdate |
| 277 #else | 279 #else |
| 278 #define MAYBE_AutoUpdate AutoUpdate | 280 #define MAYBE_AutoUpdate AutoUpdate |
| 279 #endif | 281 #endif |
| 280 #endif | 282 #endif |
| 281 | 283 |
| 282 // Tests extension autoupdate. | 284 // Tests extension autoupdate. |
| 283 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, MAYBE_AutoUpdate) { | 285 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, MAYBE_AutoUpdate) { |
| 284 NotificationListener notification_listener; | 286 NotificationListener notification_listener; |
| 285 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 287 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 288 |
| 286 // Note: This interceptor gets requests on the IO thread. | 289 // Note: This interceptor gets requests on the IO thread. |
| 287 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 290 net::LocalHostTestURLRequestInterceptor interceptor( |
| 291 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 292 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
| 293 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 288 net::URLFetcher::SetEnableInterceptionForTests(true); | 294 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 289 | 295 |
| 290 interceptor.SetResponseIgnoreQuery( | 296 interceptor.SetResponseIgnoreQuery( |
| 291 GURL("http://localhost/autoupdate/manifest"), | 297 GURL("http://localhost/autoupdate/manifest"), |
| 292 basedir.AppendASCII("manifest_v2.xml")); | 298 basedir.AppendASCII("manifest_v2.xml")); |
| 293 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), | 299 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
| 294 basedir.AppendASCII("v2.crx")); | 300 basedir.AppendASCII("v2.crx")); |
| 295 | 301 |
| 296 // Install version 1 of the extension. | 302 // Install version 1 of the extension. |
| 297 ExtensionTestMessageListener listener1("v1 installed", false); | 303 ExtensionTestMessageListener listener1("v1 installed", false); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 #else | 367 #else |
| 362 #define MAYBE_AutoUpdateDisabledExtensions AutoUpdateDisabledExtensions | 368 #define MAYBE_AutoUpdateDisabledExtensions AutoUpdateDisabledExtensions |
| 363 #endif | 369 #endif |
| 364 #endif | 370 #endif |
| 365 | 371 |
| 366 // Tests extension autoupdate. | 372 // Tests extension autoupdate. |
| 367 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, | 373 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, |
| 368 MAYBE_AutoUpdateDisabledExtensions) { | 374 MAYBE_AutoUpdateDisabledExtensions) { |
| 369 NotificationListener notification_listener; | 375 NotificationListener notification_listener; |
| 370 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 376 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 377 |
| 371 // Note: This interceptor gets requests on the IO thread. | 378 // Note: This interceptor gets requests on the IO thread. |
| 372 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 379 net::LocalHostTestURLRequestInterceptor interceptor( |
| 380 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 381 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
| 382 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 373 net::URLFetcher::SetEnableInterceptionForTests(true); | 383 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 374 | 384 |
| 375 interceptor.SetResponseIgnoreQuery( | 385 interceptor.SetResponseIgnoreQuery( |
| 376 GURL("http://localhost/autoupdate/manifest"), | 386 GURL("http://localhost/autoupdate/manifest"), |
| 377 basedir.AppendASCII("manifest_v2.xml")); | 387 basedir.AppendASCII("manifest_v2.xml")); |
| 378 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), | 388 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
| 379 basedir.AppendASCII("v2.crx")); | 389 basedir.AppendASCII("v2.crx")); |
| 380 | 390 |
| 381 // Install version 1 of the extension. | 391 // Install version 1 of the extension. |
| 382 ExtensionTestMessageListener listener1("v1 installed", false); | 392 ExtensionTestMessageListener listener1("v1 installed", false); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 | 438 |
| 429 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalUrlUpdate) { | 439 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalUrlUpdate) { |
| 430 ExtensionService* service = extensions::ExtensionSystem::Get( | 440 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 431 browser()->profile())->extension_service(); | 441 browser()->profile())->extension_service(); |
| 432 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 442 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
| 433 extensions::ExtensionUpdater::CheckParams params; | 443 extensions::ExtensionUpdater::CheckParams params; |
| 434 | 444 |
| 435 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 445 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 436 | 446 |
| 437 // Note: This interceptor gets requests on the IO thread. | 447 // Note: This interceptor gets requests on the IO thread. |
| 438 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 448 net::LocalHostTestURLRequestInterceptor interceptor( |
| 449 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 450 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
| 451 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 439 net::URLFetcher::SetEnableInterceptionForTests(true); | 452 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 440 | 453 |
| 441 interceptor.SetResponseIgnoreQuery( | 454 interceptor.SetResponseIgnoreQuery( |
| 442 GURL("http://localhost/autoupdate/manifest"), | 455 GURL("http://localhost/autoupdate/manifest"), |
| 443 basedir.AppendASCII("manifest_v2.xml")); | 456 basedir.AppendASCII("manifest_v2.xml")); |
| 444 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), | 457 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
| 445 basedir.AppendASCII("v2.crx")); | 458 basedir.AppendASCII("v2.crx")); |
| 446 | 459 |
| 447 ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile()); | 460 ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile()); |
| 448 const size_t size_before = registry->enabled_extensions().size(); | 461 const size_t size_before = registry->enabled_extensions().size(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 | 534 |
| 522 // See http://crbug.com/57378 for flakiness details. | 535 // See http://crbug.com/57378 for flakiness details. |
| 523 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalPolicyRefresh) { | 536 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalPolicyRefresh) { |
| 524 ExtensionService* service = extensions::ExtensionSystem::Get( | 537 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 525 browser()->profile())->extension_service(); | 538 browser()->profile())->extension_service(); |
| 526 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 539 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
| 527 | 540 |
| 528 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 541 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 529 | 542 |
| 530 // Note: This interceptor gets requests on the IO thread. | 543 // Note: This interceptor gets requests on the IO thread. |
| 531 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 544 net::LocalHostTestURLRequestInterceptor interceptor( |
| 545 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 546 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
| 547 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 532 net::URLFetcher::SetEnableInterceptionForTests(true); | 548 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 533 | 549 |
| 534 interceptor.SetResponseIgnoreQuery( | 550 interceptor.SetResponseIgnoreQuery( |
| 535 GURL("http://localhost/autoupdate/manifest"), | 551 GURL("http://localhost/autoupdate/manifest"), |
| 536 basedir.AppendASCII("manifest_v2.xml")); | 552 basedir.AppendASCII("manifest_v2.xml")); |
| 537 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), | 553 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
| 538 basedir.AppendASCII("v2.crx")); | 554 basedir.AppendASCII("v2.crx")); |
| 539 | 555 |
| 540 ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile()); | 556 ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile()); |
| 541 const size_t size_before = registry->enabled_extensions().size(); | 557 const size_t size_before = registry->enabled_extensions().size(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 browser()->profile())->extension_service(); | 618 browser()->profile())->extension_service(); |
| 603 ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile()); | 619 ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile()); |
| 604 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 620 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
| 605 extensions::ExtensionUpdater::CheckParams params; | 621 extensions::ExtensionUpdater::CheckParams params; |
| 606 service->updater()->set_default_check_params(params); | 622 service->updater()->set_default_check_params(params); |
| 607 const size_t size_before = registry->enabled_extensions().size(); | 623 const size_t size_before = registry->enabled_extensions().size(); |
| 608 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 624 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 609 ASSERT_TRUE(registry->disabled_extensions().is_empty()); | 625 ASSERT_TRUE(registry->disabled_extensions().is_empty()); |
| 610 | 626 |
| 611 // Note: This interceptor gets requests on the IO thread. | 627 // Note: This interceptor gets requests on the IO thread. |
| 612 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 628 net::LocalHostTestURLRequestInterceptor interceptor( |
| 629 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 630 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
| 631 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 613 net::URLFetcher::SetEnableInterceptionForTests(true); | 632 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 614 | 633 |
| 615 interceptor.SetResponseIgnoreQuery( | 634 interceptor.SetResponseIgnoreQuery( |
| 616 GURL("http://localhost/autoupdate/manifest"), | 635 GURL("http://localhost/autoupdate/manifest"), |
| 617 basedir.AppendASCII("manifest_v2.xml")); | 636 basedir.AppendASCII("manifest_v2.xml")); |
| 618 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), | 637 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
| 619 basedir.AppendASCII("v2.crx")); | 638 basedir.AppendASCII("v2.crx")); |
| 620 | 639 |
| 621 // Check that the policy is initially empty. | 640 // Check that the policy is initially empty. |
| 622 ASSERT_TRUE(extensions::ExtensionManagementFactory::GetForBrowserContext( | 641 ASSERT_TRUE(extensions::ExtensionManagementFactory::GetForBrowserContext( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 UpdateProviderPolicy(policies); | 706 UpdateProviderPolicy(policies); |
| 688 | 707 |
| 689 ASSERT_TRUE(WaitForExtensionInstall()); | 708 ASSERT_TRUE(WaitForExtensionInstall()); |
| 690 ASSERT_EQ(size_before + 1, registry->enabled_extensions().size()); | 709 ASSERT_EQ(size_before + 1, registry->enabled_extensions().size()); |
| 691 extension = service->GetExtensionById(kExtensionId, false); | 710 extension = service->GetExtensionById(kExtensionId, false); |
| 692 ASSERT_TRUE(extension); | 711 ASSERT_TRUE(extension); |
| 693 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, extension->location()); | 712 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, extension->location()); |
| 694 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 713 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
| 695 EXPECT_TRUE(registry->disabled_extensions().is_empty()); | 714 EXPECT_TRUE(registry->disabled_extensions().is_empty()); |
| 696 } | 715 } |
| OLD | NEW |