| 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/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" |
| 11 #include "chrome/browser/extensions/extension_test_message_listener.h" | 11 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 12 #include "chrome/browser/extensions/updater/extension_updater.h" | 12 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 13 #include "chrome/browser/infobars/infobar_tab_helper.h" | 13 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 15 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.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 "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 25 #include "content/public/common/url_fetcher.h" | 25 #include "net/url_request/url_fetcher.h" |
| 26 | 26 |
| 27 using extensions::Extension; | 27 using extensions::Extension; |
| 28 | 28 |
| 29 class ExtensionManagementTest : public ExtensionBrowserTest { | 29 class ExtensionManagementTest : public ExtensionBrowserTest { |
| 30 protected: | 30 protected: |
| 31 // Helper method that returns whether the extension is at the given version. | 31 // Helper method that returns whether the extension is at the given version. |
| 32 // This calls version(), which must be defined in the extension's bg page, | 32 // This calls version(), which must be defined in the extension's bg page, |
| 33 // as well as asking the extension itself. | 33 // as well as asking the extension itself. |
| 34 // | 34 // |
| 35 // Note that 'version' here means something different than the version field | 35 // Note that 'version' here means something different than the version field |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 #define MAYBE_AutoUpdate AutoUpdate | 231 #define MAYBE_AutoUpdate AutoUpdate |
| 232 #endif | 232 #endif |
| 233 #endif | 233 #endif |
| 234 | 234 |
| 235 // Tests extension autoupdate. | 235 // Tests extension autoupdate. |
| 236 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, MAYBE_AutoUpdate) { | 236 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, MAYBE_AutoUpdate) { |
| 237 NotificationListener notification_listener; | 237 NotificationListener notification_listener; |
| 238 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 238 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 239 // Note: This interceptor gets requests on the IO thread. | 239 // Note: This interceptor gets requests on the IO thread. |
| 240 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); | 240 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); |
| 241 content::URLFetcher::SetEnableInterceptionForTests(true); | 241 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 242 | 242 |
| 243 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 243 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", |
| 244 basedir.AppendASCII("manifest_v2.xml")); | 244 basedir.AppendASCII("manifest_v2.xml")); |
| 245 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 245 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", |
| 246 basedir.AppendASCII("v2.crx")); | 246 basedir.AppendASCII("v2.crx")); |
| 247 | 247 |
| 248 // Install version 1 of the extension. | 248 // Install version 1 of the extension. |
| 249 ExtensionTestMessageListener listener1("v1 installed", false); | 249 ExtensionTestMessageListener listener1("v1 installed", false); |
| 250 ExtensionService* service = browser()->profile()->GetExtensionService(); | 250 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 251 const size_t size_before = service->extensions()->size(); | 251 const size_t size_before = service->extensions()->size(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 #endif | 310 #endif |
| 311 #endif | 311 #endif |
| 312 | 312 |
| 313 // Tests extension autoupdate. | 313 // Tests extension autoupdate. |
| 314 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, | 314 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, |
| 315 MAYBE_AutoUpdateDisabledExtensions) { | 315 MAYBE_AutoUpdateDisabledExtensions) { |
| 316 NotificationListener notification_listener; | 316 NotificationListener notification_listener; |
| 317 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 317 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 318 // Note: This interceptor gets requests on the IO thread. | 318 // Note: This interceptor gets requests on the IO thread. |
| 319 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); | 319 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); |
| 320 content::URLFetcher::SetEnableInterceptionForTests(true); | 320 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 321 | 321 |
| 322 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 322 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", |
| 323 basedir.AppendASCII("manifest_v2.xml")); | 323 basedir.AppendASCII("manifest_v2.xml")); |
| 324 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 324 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", |
| 325 basedir.AppendASCII("v2.crx")); | 325 basedir.AppendASCII("v2.crx")); |
| 326 | 326 |
| 327 // Install version 1 of the extension. | 327 // Install version 1 of the extension. |
| 328 ExtensionTestMessageListener listener1("v1 installed", false); | 328 ExtensionTestMessageListener listener1("v1 installed", false); |
| 329 ExtensionService* service = browser()->profile()->GetExtensionService(); | 329 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 330 const size_t enabled_size_before = service->extensions()->size(); | 330 const size_t enabled_size_before = service->extensions()->size(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalUrlUpdate) { | 371 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalUrlUpdate) { |
| 372 ExtensionService* service = browser()->profile()->GetExtensionService(); | 372 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 373 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 373 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
| 374 // We don't want autoupdate blacklist checks. | 374 // We don't want autoupdate blacklist checks. |
| 375 service->updater()->set_blacklist_checks_enabled(false); | 375 service->updater()->set_blacklist_checks_enabled(false); |
| 376 | 376 |
| 377 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 377 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 378 | 378 |
| 379 // Note: This interceptor gets requests on the IO thread. | 379 // Note: This interceptor gets requests on the IO thread. |
| 380 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); | 380 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); |
| 381 content::URLFetcher::SetEnableInterceptionForTests(true); | 381 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 382 | 382 |
| 383 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 383 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", |
| 384 basedir.AppendASCII("manifest_v2.xml")); | 384 basedir.AppendASCII("manifest_v2.xml")); |
| 385 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 385 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", |
| 386 basedir.AppendASCII("v2.crx")); | 386 basedir.AppendASCII("v2.crx")); |
| 387 | 387 |
| 388 const size_t size_before = service->extensions()->size(); | 388 const size_t size_before = service->extensions()->size(); |
| 389 ASSERT_TRUE(service->disabled_extensions()->is_empty()); | 389 ASSERT_TRUE(service->disabled_extensions()->is_empty()); |
| 390 | 390 |
| 391 PendingExtensionManager* pending_extension_manager = | 391 PendingExtensionManager* pending_extension_manager = |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalPolicyRefresh) { | 454 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalPolicyRefresh) { |
| 455 ExtensionService* service = browser()->profile()->GetExtensionService(); | 455 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 456 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 456 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
| 457 // We don't want autoupdate blacklist checks. | 457 // We don't want autoupdate blacklist checks. |
| 458 service->updater()->set_blacklist_checks_enabled(false); | 458 service->updater()->set_blacklist_checks_enabled(false); |
| 459 | 459 |
| 460 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 460 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 461 | 461 |
| 462 // Note: This interceptor gets requests on the IO thread. | 462 // Note: This interceptor gets requests on the IO thread. |
| 463 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); | 463 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); |
| 464 content::URLFetcher::SetEnableInterceptionForTests(true); | 464 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 465 | 465 |
| 466 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 466 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", |
| 467 basedir.AppendASCII("manifest_v2.xml")); | 467 basedir.AppendASCII("manifest_v2.xml")); |
| 468 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 468 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", |
| 469 basedir.AppendASCII("v2.crx")); | 469 basedir.AppendASCII("v2.crx")); |
| 470 | 470 |
| 471 const size_t size_before = service->extensions()->size(); | 471 const size_t size_before = service->extensions()->size(); |
| 472 ASSERT_TRUE(service->disabled_extensions()->is_empty()); | 472 ASSERT_TRUE(service->disabled_extensions()->is_empty()); |
| 473 | 473 |
| 474 PrefService* prefs = browser()->profile()->GetPrefs(); | 474 PrefService* prefs = browser()->profile()->GetPrefs(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 MAYBE_PolicyOverridesUserInstall) { | 529 MAYBE_PolicyOverridesUserInstall) { |
| 530 ExtensionService* service = browser()->profile()->GetExtensionService(); | 530 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 531 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; | 531 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; |
| 532 service->updater()->set_blacklist_checks_enabled(false); | 532 service->updater()->set_blacklist_checks_enabled(false); |
| 533 const size_t size_before = service->extensions()->size(); | 533 const size_t size_before = service->extensions()->size(); |
| 534 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); | 534 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); |
| 535 ASSERT_TRUE(service->disabled_extensions()->is_empty()); | 535 ASSERT_TRUE(service->disabled_extensions()->is_empty()); |
| 536 | 536 |
| 537 // Note: This interceptor gets requests on the IO thread. | 537 // Note: This interceptor gets requests on the IO thread. |
| 538 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); | 538 scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor()); |
| 539 content::URLFetcher::SetEnableInterceptionForTests(true); | 539 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 540 | 540 |
| 541 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", | 541 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", |
| 542 basedir.AppendASCII("manifest_v2.xml")); | 542 basedir.AppendASCII("manifest_v2.xml")); |
| 543 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", | 543 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", |
| 544 basedir.AppendASCII("v2.crx")); | 544 basedir.AppendASCII("v2.crx")); |
| 545 | 545 |
| 546 // Check that the policy is initially empty. | 546 // Check that the policy is initially empty. |
| 547 PrefService* prefs = browser()->profile()->GetPrefs(); | 547 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 548 const ListValue* forcelist = | 548 const ListValue* forcelist = |
| 549 prefs->GetList(prefs::kExtensionInstallForceList); | 549 prefs->GetList(prefs::kExtensionInstallForceList); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest")); | 611 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest")); |
| 612 } | 612 } |
| 613 ASSERT_TRUE(WaitForExtensionInstall()); | 613 ASSERT_TRUE(WaitForExtensionInstall()); |
| 614 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 614 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 615 extension = service->GetExtensionById(kExtensionId, false); | 615 extension = service->GetExtensionById(kExtensionId, false); |
| 616 ASSERT_TRUE(extension); | 616 ASSERT_TRUE(extension); |
| 617 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); | 617 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); |
| 618 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 618 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
| 619 EXPECT_TRUE(service->disabled_extensions()->is_empty()); | 619 EXPECT_TRUE(service->disabled_extensions()->is_empty()); |
| 620 } | 620 } |
| OLD | NEW |