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/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "chrome/browser/extensions/extension_browsertest.h" | 11 #include "chrome/browser/extensions/extension_browsertest.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/extensions/extension_test_message_listener.h" | 13 #include "chrome/browser/extensions/extension_test_message_listener.h" |
14 #include "chrome/browser/extensions/external_policy_loader.h" | 14 #include "chrome/browser/extensions/external_policy_loader.h" |
15 #include "chrome/browser/extensions/updater/extension_downloader.h" | 15 #include "chrome/browser/extensions/updater/extension_downloader.h" |
16 #include "chrome/browser/extensions/updater/extension_updater.h" | 16 #include "chrome/browser/extensions/updater/extension_updater.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
21 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
| 22 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
24 #include "content/public/test/browser_test_utils.h" | 25 #include "content/public/test/browser_test_utils.h" |
25 #include "content/test/net/url_request_prepackaged_interceptor.h" | |
26 #include "extensions/browser/extension_host.h" | 26 #include "extensions/browser/extension_host.h" |
27 #include "extensions/browser/extension_prefs.h" | 27 #include "extensions/browser/extension_prefs.h" |
28 #include "extensions/browser/extension_registry.h" | 28 #include "extensions/browser/extension_registry.h" |
29 #include "extensions/browser/extension_system.h" | 29 #include "extensions/browser/extension_system.h" |
30 #include "extensions/browser/notification_types.h" | 30 #include "extensions/browser/notification_types.h" |
31 #include "extensions/browser/pref_names.h" | 31 #include "extensions/browser/pref_names.h" |
| 32 #include "net/url_request/test_url_request_interceptor.h" |
32 #include "net/url_request/url_fetcher.h" | 33 #include "net/url_request/url_fetcher.h" |
33 | 34 |
| 35 using content::BrowserThread; |
34 using extensions::Extension; | 36 using extensions::Extension; |
35 using extensions::ExtensionRegistry; | 37 using extensions::ExtensionRegistry; |
36 using extensions::Manifest; | 38 using extensions::Manifest; |
37 | 39 |
38 class ExtensionManagementTest : public ExtensionBrowserTest { | 40 class ExtensionManagementTest : public ExtensionBrowserTest { |
39 protected: | 41 protected: |
40 // Helper method that returns whether the extension is at the given version. | 42 // Helper method that returns whether the extension is at the given version. |
41 // This calls version(), which must be defined in the extension's bg page, | 43 // This calls version(), which must be defined in the extension's bg page, |
42 // as well as asking the extension itself. | 44 // as well as asking the extension itself. |
43 // | 45 // |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 #define MAYBE_AutoUpdate DISABLED_AutoUpdate | 245 #define MAYBE_AutoUpdate DISABLED_AutoUpdate |
244 #else | 246 #else |
245 #define MAYBE_AutoUpdate AutoUpdate | 247 #define MAYBE_AutoUpdate AutoUpdate |
246 #endif | 248 #endif |
247 #endif | 249 #endif |
248 | 250 |
249 // Tests extension autoupdate. | 251 // Tests extension autoupdate. |
250 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, MAYBE_AutoUpdate) { | 252 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, MAYBE_AutoUpdate) { |
251 NotificationListener notification_listener; | 253 NotificationListener notification_listener; |
252 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 254 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 255 |
253 // Note: This interceptor gets requests on the IO thread. | 256 // Note: This interceptor gets requests on the IO thread. |
254 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 257 net::LocalHostTestURLRequestInterceptor interceptor( |
| 258 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 259 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
| 260 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
255 net::URLFetcher::SetEnableInterceptionForTests(true); | 261 net::URLFetcher::SetEnableInterceptionForTests(true); |
256 | 262 |
257 interceptor.SetResponseIgnoreQuery( | 263 interceptor.SetResponseIgnoreQuery( |
258 GURL("http://localhost/autoupdate/manifest"), | 264 GURL("http://localhost/autoupdate/manifest"), |
259 basedir.AppendASCII("manifest_v2.xml")); | 265 basedir.AppendASCII("manifest_v2.xml")); |
260 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), | 266 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
261 basedir.AppendASCII("v2.crx")); | 267 basedir.AppendASCII("v2.crx")); |
262 | 268 |
263 // Install version 1 of the extension. | 269 // Install version 1 of the extension. |
264 ExtensionTestMessageListener listener1("v1 installed", false); | 270 ExtensionTestMessageListener listener1("v1 installed", false); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 #else | 334 #else |
329 #define MAYBE_AutoUpdateDisabledExtensions AutoUpdateDisabledExtensions | 335 #define MAYBE_AutoUpdateDisabledExtensions AutoUpdateDisabledExtensions |
330 #endif | 336 #endif |
331 #endif | 337 #endif |
332 | 338 |
333 // Tests extension autoupdate. | 339 // Tests extension autoupdate. |
334 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, | 340 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, |
335 MAYBE_AutoUpdateDisabledExtensions) { | 341 MAYBE_AutoUpdateDisabledExtensions) { |
336 NotificationListener notification_listener; | 342 NotificationListener notification_listener; |
337 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 343 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 344 |
338 // Note: This interceptor gets requests on the IO thread. | 345 // Note: This interceptor gets requests on the IO thread. |
339 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 346 net::LocalHostTestURLRequestInterceptor interceptor( |
| 347 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 348 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
| 349 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
340 net::URLFetcher::SetEnableInterceptionForTests(true); | 350 net::URLFetcher::SetEnableInterceptionForTests(true); |
341 | 351 |
342 interceptor.SetResponseIgnoreQuery( | 352 interceptor.SetResponseIgnoreQuery( |
343 GURL("http://localhost/autoupdate/manifest"), | 353 GURL("http://localhost/autoupdate/manifest"), |
344 basedir.AppendASCII("manifest_v2.xml")); | 354 basedir.AppendASCII("manifest_v2.xml")); |
345 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), | 355 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
346 basedir.AppendASCII("v2.crx")); | 356 basedir.AppendASCII("v2.crx")); |
347 | 357 |
348 // Install version 1 of the extension. | 358 // Install version 1 of the extension. |
349 ExtensionTestMessageListener listener1("v1 installed", false); | 359 ExtensionTestMessageListener listener1("v1 installed", false); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 | 405 |
396 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalUrlUpdate) { | 406 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalUrlUpdate) { |
397 ExtensionService* service = extensions::ExtensionSystem::Get( | 407 ExtensionService* service = extensions::ExtensionSystem::Get( |
398 browser()->profile())->extension_service(); | 408 browser()->profile())->extension_service(); |
399 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 409 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
400 extensions::ExtensionUpdater::CheckParams params; | 410 extensions::ExtensionUpdater::CheckParams params; |
401 | 411 |
402 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 412 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
403 | 413 |
404 // Note: This interceptor gets requests on the IO thread. | 414 // Note: This interceptor gets requests on the IO thread. |
405 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 415 net::LocalHostTestURLRequestInterceptor interceptor( |
| 416 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 417 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
| 418 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
406 net::URLFetcher::SetEnableInterceptionForTests(true); | 419 net::URLFetcher::SetEnableInterceptionForTests(true); |
407 | 420 |
408 interceptor.SetResponseIgnoreQuery( | 421 interceptor.SetResponseIgnoreQuery( |
409 GURL("http://localhost/autoupdate/manifest"), | 422 GURL("http://localhost/autoupdate/manifest"), |
410 basedir.AppendASCII("manifest_v2.xml")); | 423 basedir.AppendASCII("manifest_v2.xml")); |
411 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), | 424 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
412 basedir.AppendASCII("v2.crx")); | 425 basedir.AppendASCII("v2.crx")); |
413 | 426 |
414 ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile()); | 427 ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile()); |
415 const size_t size_before = registry->enabled_extensions().size(); | 428 const size_t size_before = registry->enabled_extensions().size(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 | 501 |
489 // See http://crbug.com/57378 for flakiness details. | 502 // See http://crbug.com/57378 for flakiness details. |
490 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalPolicyRefresh) { | 503 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalPolicyRefresh) { |
491 ExtensionService* service = extensions::ExtensionSystem::Get( | 504 ExtensionService* service = extensions::ExtensionSystem::Get( |
492 browser()->profile())->extension_service(); | 505 browser()->profile())->extension_service(); |
493 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 506 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
494 | 507 |
495 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 508 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
496 | 509 |
497 // Note: This interceptor gets requests on the IO thread. | 510 // Note: This interceptor gets requests on the IO thread. |
498 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 511 net::LocalHostTestURLRequestInterceptor interceptor( |
| 512 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 513 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
| 514 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
499 net::URLFetcher::SetEnableInterceptionForTests(true); | 515 net::URLFetcher::SetEnableInterceptionForTests(true); |
500 | 516 |
501 interceptor.SetResponseIgnoreQuery( | 517 interceptor.SetResponseIgnoreQuery( |
502 GURL("http://localhost/autoupdate/manifest"), | 518 GURL("http://localhost/autoupdate/manifest"), |
503 basedir.AppendASCII("manifest_v2.xml")); | 519 basedir.AppendASCII("manifest_v2.xml")); |
504 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), | 520 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
505 basedir.AppendASCII("v2.crx")); | 521 basedir.AppendASCII("v2.crx")); |
506 | 522 |
507 ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile()); | 523 ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile()); |
508 const size_t size_before = registry->enabled_extensions().size(); | 524 const size_t size_before = registry->enabled_extensions().size(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 browser()->profile())->extension_service(); | 581 browser()->profile())->extension_service(); |
566 ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile()); | 582 ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile()); |
567 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 583 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
568 extensions::ExtensionUpdater::CheckParams params; | 584 extensions::ExtensionUpdater::CheckParams params; |
569 service->updater()->set_default_check_params(params); | 585 service->updater()->set_default_check_params(params); |
570 const size_t size_before = registry->enabled_extensions().size(); | 586 const size_t size_before = registry->enabled_extensions().size(); |
571 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 587 base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
572 ASSERT_TRUE(registry->disabled_extensions().is_empty()); | 588 ASSERT_TRUE(registry->disabled_extensions().is_empty()); |
573 | 589 |
574 // Note: This interceptor gets requests on the IO thread. | 590 // Note: This interceptor gets requests on the IO thread. |
575 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 591 net::LocalHostTestURLRequestInterceptor interceptor( |
| 592 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 593 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
| 594 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
576 net::URLFetcher::SetEnableInterceptionForTests(true); | 595 net::URLFetcher::SetEnableInterceptionForTests(true); |
577 | 596 |
578 interceptor.SetResponseIgnoreQuery( | 597 interceptor.SetResponseIgnoreQuery( |
579 GURL("http://localhost/autoupdate/manifest"), | 598 GURL("http://localhost/autoupdate/manifest"), |
580 basedir.AppendASCII("manifest_v2.xml")); | 599 basedir.AppendASCII("manifest_v2.xml")); |
581 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), | 600 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
582 basedir.AppendASCII("v2.crx")); | 601 basedir.AppendASCII("v2.crx")); |
583 | 602 |
584 // Check that the policy is initially empty. | 603 // Check that the policy is initially empty. |
585 PrefService* prefs = browser()->profile()->GetPrefs(); | 604 PrefService* prefs = browser()->profile()->GetPrefs(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); | 663 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); |
645 } | 664 } |
646 ASSERT_TRUE(WaitForExtensionInstall()); | 665 ASSERT_TRUE(WaitForExtensionInstall()); |
647 ASSERT_EQ(size_before + 1, registry->enabled_extensions().size()); | 666 ASSERT_EQ(size_before + 1, registry->enabled_extensions().size()); |
648 extension = service->GetExtensionById(kExtensionId, false); | 667 extension = service->GetExtensionById(kExtensionId, false); |
649 ASSERT_TRUE(extension); | 668 ASSERT_TRUE(extension); |
650 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, extension->location()); | 669 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, extension->location()); |
651 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 670 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
652 EXPECT_TRUE(registry->disabled_extensions().is_empty()); | 671 EXPECT_TRUE(registry->disabled_extensions().is_empty()); |
653 } | 672 } |
OLD | NEW |