| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 ExtensionService* service = extensions::ExtensionSystem::Get( | 405 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 405 browser()->profile())->extension_service(); | 406 browser()->profile())->extension_service(); |
| 406 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 407 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
| 407 // We don't want autoupdate blacklist checks. | 408 // We don't want autoupdate blacklist checks. |
| 408 extensions::ExtensionUpdater::CheckParams params; | 409 extensions::ExtensionUpdater::CheckParams params; |
| 409 params.check_blacklist = false; | 410 params.check_blacklist = false; |
| 410 | 411 |
| 411 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 412 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 412 | 413 |
| 413 // Note: This interceptor gets requests on the IO thread. | 414 // Note: This interceptor gets requests on the IO thread. |
| 414 scoped_refptr<extensions::AutoUpdateInterceptor> interceptor( | 415 content::URLRequestPrepackagedInterceptor interceptor; |
| 415 new extensions::AutoUpdateInterceptor()); | |
| 416 net::URLFetcher::SetEnableInterceptionForTests(true); | 416 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 417 | 417 |
| 418 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 418 interceptor.SetResponseIgnoreQuery( |
| 419 basedir.AppendASCII("manifest_v2.xml")); | 419 GURL("http://localhost/autoupdate/manifest"), |
| 420 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 420 basedir.AppendASCII("manifest_v2.xml")); |
| 421 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
| 421 basedir.AppendASCII("v2.crx")); | 422 basedir.AppendASCII("v2.crx")); |
| 422 | 423 |
| 423 const size_t size_before = service->extensions()->size(); | 424 const size_t size_before = service->extensions()->size(); |
| 424 ASSERT_TRUE(service->disabled_extensions()->is_empty()); | 425 ASSERT_TRUE(service->disabled_extensions()->is_empty()); |
| 425 | 426 |
| 426 extensions::PendingExtensionManager* pending_extension_manager = | 427 extensions::PendingExtensionManager* pending_extension_manager = |
| 427 service->pending_extension_manager(); | 428 service->pending_extension_manager(); |
| 428 | 429 |
| 429 // The code that reads external_extensions.json uses this method to inform | 430 // The code that reads external_extensions.json uses this method to inform |
| 430 // the ExtensionService of an extension to download. Using the real code | 431 // the ExtensionService of an extension to download. Using the real code |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 ExtensionService* service = extensions::ExtensionSystem::Get( | 491 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 491 browser()->profile())->extension_service(); | 492 browser()->profile())->extension_service(); |
| 492 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 493 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
| 493 // We don't want autoupdate blacklist checks. | 494 // We don't want autoupdate blacklist checks. |
| 494 extensions::ExtensionUpdater::CheckParams params; | 495 extensions::ExtensionUpdater::CheckParams params; |
| 495 params.check_blacklist = false; | 496 params.check_blacklist = false; |
| 496 | 497 |
| 497 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 498 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 498 | 499 |
| 499 // Note: This interceptor gets requests on the IO thread. | 500 // Note: This interceptor gets requests on the IO thread. |
| 500 scoped_refptr<extensions::AutoUpdateInterceptor> interceptor( | 501 content::URLRequestPrepackagedInterceptor interceptor; |
| 501 new extensions::AutoUpdateInterceptor()); | |
| 502 net::URLFetcher::SetEnableInterceptionForTests(true); | 502 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 503 | 503 |
| 504 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 504 interceptor.SetResponseIgnoreQuery( |
| 505 basedir.AppendASCII("manifest_v2.xml")); | 505 GURL("http://localhost/autoupdate/manifest"), |
| 506 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 506 basedir.AppendASCII("manifest_v2.xml")); |
| 507 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
| 507 basedir.AppendASCII("v2.crx")); | 508 basedir.AppendASCII("v2.crx")); |
| 508 | 509 |
| 509 const size_t size_before = service->extensions()->size(); | 510 const size_t size_before = service->extensions()->size(); |
| 510 ASSERT_TRUE(service->disabled_extensions()->is_empty()); | 511 ASSERT_TRUE(service->disabled_extensions()->is_empty()); |
| 511 | 512 |
| 512 PrefService* prefs = browser()->profile()->GetPrefs(); | 513 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 513 const DictionaryValue* forcelist = | 514 const DictionaryValue* forcelist = |
| 514 prefs->GetDictionary(prefs::kExtensionInstallForceList); | 515 prefs->GetDictionary(prefs::kExtensionInstallForceList); |
| 515 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; | 516 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; |
| 516 | 517 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 browser()->profile())->extension_service(); | 566 browser()->profile())->extension_service(); |
| 566 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 567 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
| 567 extensions::ExtensionUpdater::CheckParams params; | 568 extensions::ExtensionUpdater::CheckParams params; |
| 568 params.check_blacklist = false; | 569 params.check_blacklist = false; |
| 569 service->updater()->set_default_check_params(params); | 570 service->updater()->set_default_check_params(params); |
| 570 const size_t size_before = service->extensions()->size(); | 571 const size_t size_before = service->extensions()->size(); |
| 571 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 572 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 572 ASSERT_TRUE(service->disabled_extensions()->is_empty()); | 573 ASSERT_TRUE(service->disabled_extensions()->is_empty()); |
| 573 | 574 |
| 574 // Note: This interceptor gets requests on the IO thread. | 575 // Note: This interceptor gets requests on the IO thread. |
| 575 scoped_refptr<extensions::AutoUpdateInterceptor> interceptor( | 576 content::URLRequestPrepackagedInterceptor interceptor; |
| 576 new extensions::AutoUpdateInterceptor()); | |
| 577 net::URLFetcher::SetEnableInterceptionForTests(true); | 577 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 578 | 578 |
| 579 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 579 interceptor.SetResponseIgnoreQuery( |
| 580 basedir.AppendASCII("manifest_v2.xml")); | 580 GURL("http://localhost/autoupdate/manifest"), |
| 581 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 581 basedir.AppendASCII("manifest_v2.xml")); |
| 582 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
| 582 basedir.AppendASCII("v2.crx")); | 583 basedir.AppendASCII("v2.crx")); |
| 583 | 584 |
| 584 // Check that the policy is initially empty. | 585 // Check that the policy is initially empty. |
| 585 PrefService* prefs = browser()->profile()->GetPrefs(); | 586 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 586 const DictionaryValue* forcelist = | 587 const DictionaryValue* forcelist = |
| 587 prefs->GetDictionary(prefs::kExtensionInstallForceList); | 588 prefs->GetDictionary(prefs::kExtensionInstallForceList); |
| 588 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; | 589 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; |
| 589 | 590 |
| 590 // User install of the extension. | 591 // User install of the extension. |
| 591 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); | 592 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); | 643 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); |
| 643 } | 644 } |
| 644 ASSERT_TRUE(WaitForExtensionInstall()); | 645 ASSERT_TRUE(WaitForExtensionInstall()); |
| 645 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 646 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 646 extension = service->GetExtensionById(kExtensionId, false); | 647 extension = service->GetExtensionById(kExtensionId, false); |
| 647 ASSERT_TRUE(extension); | 648 ASSERT_TRUE(extension); |
| 648 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); | 649 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); |
| 649 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 650 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
| 650 EXPECT_TRUE(service->disabled_extensions()->is_empty()); | 651 EXPECT_TRUE(service->disabled_extensions()->is_empty()); |
| 651 } | 652 } |
| OLD | NEW |