| 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/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "chrome/browser/extensions/autoupdate_interceptor.h" | |
| 10 #include "chrome/browser/extensions/extension_browsertest.h" | 9 #include "chrome/browser/extensions/extension_browsertest.h" |
| 11 #include "chrome/browser/extensions/extension_host.h" | 10 #include "chrome/browser/extensions/extension_host.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_system.h" | 12 #include "chrome/browser/extensions/extension_system.h" |
| 14 #include "chrome/browser/extensions/extension_test_message_listener.h" | 13 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 15 #include "chrome/browser/extensions/external_policy_loader.h" | 14 #include "chrome/browser/extensions/external_policy_loader.h" |
| 16 #include "chrome/browser/extensions/updater/extension_downloader.h" | 15 #include "chrome/browser/extensions/updater/extension_downloader.h" |
| 17 #include "chrome/browser/extensions/updater/extension_updater.h" | 16 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 18 #include "chrome/browser/infobars/infobar_tab_helper.h" | 17 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 19 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 20 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 19 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 24 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 26 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
| 27 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 28 #include "content/public/browser/render_view_host.h" | 27 #include "content/public/browser/render_view_host.h" |
| 29 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
| 29 #include "content/test/net/url_request_prepackaged_interceptor.h" |
| 30 #include "net/url_request/url_fetcher.h" | 30 #include "net/url_request/url_fetcher.h" |
| 31 | 31 |
| 32 using extensions::Extension; | 32 using extensions::Extension; |
| 33 | 33 |
| 34 class ExtensionManagementTest : public ExtensionBrowserTest { | 34 class ExtensionManagementTest : public ExtensionBrowserTest { |
| 35 protected: | 35 protected: |
| 36 // Helper method that returns whether the extension is at the given version. | 36 // Helper method that returns whether the extension is at the given version. |
| 37 // This calls version(), which must be defined in the extension's bg page, | 37 // This calls version(), which must be defined in the extension's bg page, |
| 38 // as well as asking the extension itself. | 38 // as well as asking the extension itself. |
| 39 // | 39 // |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 #else | 243 #else |
| 244 #define MAYBE_AutoUpdate AutoUpdate | 244 #define MAYBE_AutoUpdate AutoUpdate |
| 245 #endif | 245 #endif |
| 246 #endif | 246 #endif |
| 247 | 247 |
| 248 // Tests extension autoupdate. | 248 // Tests extension autoupdate. |
| 249 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, MAYBE_AutoUpdate) { | 249 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, MAYBE_AutoUpdate) { |
| 250 NotificationListener notification_listener; | 250 NotificationListener notification_listener; |
| 251 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 251 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 252 // Note: This interceptor gets requests on the IO thread. | 252 // Note: This interceptor gets requests on the IO thread. |
| 253 scoped_refptr<extensions::AutoUpdateInterceptor> interceptor( | 253 content::URLRequestPrepackagedInterceptor interceptor; |
| 254 new extensions::AutoUpdateInterceptor()); | |
| 255 net::URLFetcher::SetEnableInterceptionForTests(true); | 254 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 256 | 255 |
| 257 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 256 interceptor.SetResponseIgnoreQuery( |
| 258 basedir.AppendASCII("manifest_v2.xml")); | 257 GURL("http://localhost/autoupdate/manifest"), |
| 259 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 258 basedir.AppendASCII("manifest_v2.xml")); |
| 260 basedir.AppendASCII("v2.crx")); | 259 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
| 260 basedir.AppendASCII("v2.crx")); |
| 261 | 261 |
| 262 // Install version 1 of the extension. | 262 // Install version 1 of the extension. |
| 263 ExtensionTestMessageListener listener1("v1 installed", false); | 263 ExtensionTestMessageListener listener1("v1 installed", false); |
| 264 ExtensionService* service = extensions::ExtensionSystem::Get( | 264 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 265 browser()->profile())->extension_service(); | 265 browser()->profile())->extension_service(); |
| 266 const size_t size_before = service->extensions()->size(); | 266 const size_t size_before = service->extensions()->size(); |
| 267 ASSERT_TRUE(service->disabled_extensions()->is_empty()); | 267 ASSERT_TRUE(service->disabled_extensions()->is_empty()); |
| 268 const Extension* extension = | 268 const Extension* extension = |
| 269 InstallExtension(basedir.AppendASCII("v1.crx"), 1); | 269 InstallExtension(basedir.AppendASCII("v1.crx"), 1); |
| 270 ASSERT_TRUE(extension); | 270 ASSERT_TRUE(extension); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 291 ASSERT_TRUE(extension); | 291 ASSERT_TRUE(extension); |
| 292 ASSERT_EQ("2.0", extension->VersionString()); | 292 ASSERT_EQ("2.0", extension->VersionString()); |
| 293 ASSERT_TRUE(notification_listener.started()); | 293 ASSERT_TRUE(notification_listener.started()); |
| 294 ASSERT_TRUE(notification_listener.finished()); | 294 ASSERT_TRUE(notification_listener.finished()); |
| 295 ASSERT_TRUE(ContainsKey(notification_listener.updates(), | 295 ASSERT_TRUE(ContainsKey(notification_listener.updates(), |
| 296 "ogjcoiohnmldgjemafoockdghcjciccf")); | 296 "ogjcoiohnmldgjemafoockdghcjciccf")); |
| 297 notification_listener.Reset(); | 297 notification_listener.Reset(); |
| 298 | 298 |
| 299 // Now try doing an update to version 3, which has been incorrectly | 299 // Now try doing an update to version 3, which has been incorrectly |
| 300 // signed. This should fail. | 300 // signed. This should fail. |
| 301 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 301 interceptor.SetResponseIgnoreQuery( |
| 302 basedir.AppendASCII("manifest_v3.xml")); | 302 GURL("http://localhost/autoupdate/manifest"), |
| 303 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v3.crx", | 303 basedir.AppendASCII("manifest_v3.xml")); |
| 304 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v3.crx"), |
| 304 basedir.AppendASCII("v3.crx")); | 305 basedir.AppendASCII("v3.crx")); |
| 305 | 306 |
| 306 service->updater()->CheckNow(params); | 307 service->updater()->CheckNow(params); |
| 307 ASSERT_TRUE(WaitForExtensionInstallError()); | 308 ASSERT_TRUE(WaitForExtensionInstallError()); |
| 308 ASSERT_TRUE(notification_listener.started()); | 309 ASSERT_TRUE(notification_listener.started()); |
| 309 ASSERT_TRUE(notification_listener.finished()); | 310 ASSERT_TRUE(notification_listener.finished()); |
| 310 ASSERT_TRUE(ContainsKey(notification_listener.updates(), | 311 ASSERT_TRUE(ContainsKey(notification_listener.updates(), |
| 311 "ogjcoiohnmldgjemafoockdghcjciccf")); | 312 "ogjcoiohnmldgjemafoockdghcjciccf")); |
| 312 | 313 |
| 313 // Make sure the extension state is the same as before. | 314 // Make sure the extension state is the same as before. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 328 #define MAYBE_AutoUpdateDisabledExtensions AutoUpdateDisabledExtensions | 329 #define MAYBE_AutoUpdateDisabledExtensions AutoUpdateDisabledExtensions |
| 329 #endif | 330 #endif |
| 330 #endif | 331 #endif |
| 331 | 332 |
| 332 // Tests extension autoupdate. | 333 // Tests extension autoupdate. |
| 333 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, | 334 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, |
| 334 MAYBE_AutoUpdateDisabledExtensions) { | 335 MAYBE_AutoUpdateDisabledExtensions) { |
| 335 NotificationListener notification_listener; | 336 NotificationListener notification_listener; |
| 336 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 337 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 337 // Note: This interceptor gets requests on the IO thread. | 338 // Note: This interceptor gets requests on the IO thread. |
| 338 scoped_refptr<extensions::AutoUpdateInterceptor> interceptor( | 339 content::URLRequestPrepackagedInterceptor interceptor; |
| 339 new extensions::AutoUpdateInterceptor()); | |
| 340 net::URLFetcher::SetEnableInterceptionForTests(true); | 340 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 341 | 341 |
| 342 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 342 interceptor.SetResponseIgnoreQuery( |
| 343 basedir.AppendASCII("manifest_v2.xml")); | 343 GURL("http://localhost/autoupdate/manifest"), |
| 344 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 344 basedir.AppendASCII("manifest_v2.xml")); |
| 345 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
| 345 basedir.AppendASCII("v2.crx")); | 346 basedir.AppendASCII("v2.crx")); |
| 346 | 347 |
| 347 // Install version 1 of the extension. | 348 // Install version 1 of the extension. |
| 348 ExtensionTestMessageListener listener1("v1 installed", false); | 349 ExtensionTestMessageListener listener1("v1 installed", false); |
| 349 ExtensionService* service = extensions::ExtensionSystem::Get( | 350 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 350 browser()->profile())->extension_service(); | 351 browser()->profile())->extension_service(); |
| 351 const size_t enabled_size_before = service->extensions()->size(); | 352 const size_t enabled_size_before = service->extensions()->size(); |
| 352 const size_t disabled_size_before = service->disabled_extensions()->size(); | 353 const size_t disabled_size_before = service->disabled_extensions()->size(); |
| 353 const Extension* extension = | 354 const Extension* extension = |
| 354 InstallExtension(basedir.AppendASCII("v1.crx"), 1); | 355 InstallExtension(basedir.AppendASCII("v1.crx"), 1); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 ExtensionService* service = extensions::ExtensionSystem::Get( | 398 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 398 browser()->profile())->extension_service(); | 399 browser()->profile())->extension_service(); |
| 399 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 400 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
| 400 // We don't want autoupdate blacklist checks. | 401 // We don't want autoupdate blacklist checks. |
| 401 extensions::ExtensionUpdater::CheckParams params; | 402 extensions::ExtensionUpdater::CheckParams params; |
| 402 params.check_blacklist = false; | 403 params.check_blacklist = false; |
| 403 | 404 |
| 404 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 405 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 405 | 406 |
| 406 // Note: This interceptor gets requests on the IO thread. | 407 // Note: This interceptor gets requests on the IO thread. |
| 407 scoped_refptr<extensions::AutoUpdateInterceptor> interceptor( | 408 content::URLRequestPrepackagedInterceptor interceptor; |
| 408 new extensions::AutoUpdateInterceptor()); | |
| 409 net::URLFetcher::SetEnableInterceptionForTests(true); | 409 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 410 | 410 |
| 411 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 411 interceptor.SetResponseIgnoreQuery( |
| 412 basedir.AppendASCII("manifest_v2.xml")); | 412 GURL("http://localhost/autoupdate/manifest"), |
| 413 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 413 basedir.AppendASCII("manifest_v2.xml")); |
| 414 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
| 414 basedir.AppendASCII("v2.crx")); | 415 basedir.AppendASCII("v2.crx")); |
| 415 | 416 |
| 416 const size_t size_before = service->extensions()->size(); | 417 const size_t size_before = service->extensions()->size(); |
| 417 ASSERT_TRUE(service->disabled_extensions()->is_empty()); | 418 ASSERT_TRUE(service->disabled_extensions()->is_empty()); |
| 418 | 419 |
| 419 extensions::PendingExtensionManager* pending_extension_manager = | 420 extensions::PendingExtensionManager* pending_extension_manager = |
| 420 service->pending_extension_manager(); | 421 service->pending_extension_manager(); |
| 421 | 422 |
| 422 // The code that reads external_extensions.json uses this method to inform | 423 // The code that reads external_extensions.json uses this method to inform |
| 423 // the ExtensionService of an extension to download. Using the real code | 424 // the ExtensionService of an extension to download. Using the real code |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 ExtensionService* service = extensions::ExtensionSystem::Get( | 484 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 484 browser()->profile())->extension_service(); | 485 browser()->profile())->extension_service(); |
| 485 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 486 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
| 486 // We don't want autoupdate blacklist checks. | 487 // We don't want autoupdate blacklist checks. |
| 487 extensions::ExtensionUpdater::CheckParams params; | 488 extensions::ExtensionUpdater::CheckParams params; |
| 488 params.check_blacklist = false; | 489 params.check_blacklist = false; |
| 489 | 490 |
| 490 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 491 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 491 | 492 |
| 492 // Note: This interceptor gets requests on the IO thread. | 493 // Note: This interceptor gets requests on the IO thread. |
| 493 scoped_refptr<extensions::AutoUpdateInterceptor> interceptor( | 494 content::URLRequestPrepackagedInterceptor interceptor; |
| 494 new extensions::AutoUpdateInterceptor()); | |
| 495 net::URLFetcher::SetEnableInterceptionForTests(true); | 495 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 496 | 496 |
| 497 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 497 interceptor.SetResponseIgnoreQuery( |
| 498 basedir.AppendASCII("manifest_v2.xml")); | 498 GURL("http://localhost/autoupdate/manifest"), |
| 499 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 499 basedir.AppendASCII("manifest_v2.xml")); |
| 500 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
| 500 basedir.AppendASCII("v2.crx")); | 501 basedir.AppendASCII("v2.crx")); |
| 501 | 502 |
| 502 const size_t size_before = service->extensions()->size(); | 503 const size_t size_before = service->extensions()->size(); |
| 503 ASSERT_TRUE(service->disabled_extensions()->is_empty()); | 504 ASSERT_TRUE(service->disabled_extensions()->is_empty()); |
| 504 | 505 |
| 505 PrefService* prefs = browser()->profile()->GetPrefs(); | 506 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 506 const DictionaryValue* forcelist = | 507 const DictionaryValue* forcelist = |
| 507 prefs->GetDictionary(prefs::kExtensionInstallForceList); | 508 prefs->GetDictionary(prefs::kExtensionInstallForceList); |
| 508 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; | 509 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; |
| 509 | 510 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 browser()->profile())->extension_service(); | 559 browser()->profile())->extension_service(); |
| 559 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 560 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
| 560 extensions::ExtensionUpdater::CheckParams params; | 561 extensions::ExtensionUpdater::CheckParams params; |
| 561 params.check_blacklist = false; | 562 params.check_blacklist = false; |
| 562 service->updater()->set_default_check_params(params); | 563 service->updater()->set_default_check_params(params); |
| 563 const size_t size_before = service->extensions()->size(); | 564 const size_t size_before = service->extensions()->size(); |
| 564 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 565 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 565 ASSERT_TRUE(service->disabled_extensions()->is_empty()); | 566 ASSERT_TRUE(service->disabled_extensions()->is_empty()); |
| 566 | 567 |
| 567 // Note: This interceptor gets requests on the IO thread. | 568 // Note: This interceptor gets requests on the IO thread. |
| 568 scoped_refptr<extensions::AutoUpdateInterceptor> interceptor( | 569 content::URLRequestPrepackagedInterceptor interceptor; |
| 569 new extensions::AutoUpdateInterceptor()); | |
| 570 net::URLFetcher::SetEnableInterceptionForTests(true); | 570 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 571 | 571 |
| 572 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 572 interceptor.SetResponseIgnoreQuery( |
| 573 basedir.AppendASCII("manifest_v2.xml")); | 573 GURL("http://localhost/autoupdate/manifest"), |
| 574 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 574 basedir.AppendASCII("manifest_v2.xml")); |
| 575 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
| 575 basedir.AppendASCII("v2.crx")); | 576 basedir.AppendASCII("v2.crx")); |
| 576 | 577 |
| 577 // Check that the policy is initially empty. | 578 // Check that the policy is initially empty. |
| 578 PrefService* prefs = browser()->profile()->GetPrefs(); | 579 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 579 const DictionaryValue* forcelist = | 580 const DictionaryValue* forcelist = |
| 580 prefs->GetDictionary(prefs::kExtensionInstallForceList); | 581 prefs->GetDictionary(prefs::kExtensionInstallForceList); |
| 581 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; | 582 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; |
| 582 | 583 |
| 583 // User install of the extension. | 584 // User install of the extension. |
| 584 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); | 585 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); | 636 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); |
| 636 } | 637 } |
| 637 ASSERT_TRUE(WaitForExtensionInstall()); | 638 ASSERT_TRUE(WaitForExtensionInstall()); |
| 638 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 639 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 639 extension = service->GetExtensionById(kExtensionId, false); | 640 extension = service->GetExtensionById(kExtensionId, false); |
| 640 ASSERT_TRUE(extension); | 641 ASSERT_TRUE(extension); |
| 641 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); | 642 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); |
| 642 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 643 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
| 643 EXPECT_TRUE(service->disabled_extensions()->is_empty()); | 644 EXPECT_TRUE(service->disabled_extensions()->is_empty()); |
| 644 } | 645 } |
| OLD | NEW |