| 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 "chrome/browser/extensions/extension_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 #include "chrome/browser/prefs/browser_prefs.h" | 58 #include "chrome/browser/prefs/browser_prefs.h" |
| 59 #include "chrome/browser/prefs/pref_registry_syncable.h" | 59 #include "chrome/browser/prefs/pref_registry_syncable.h" |
| 60 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 60 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
| 61 #include "chrome/browser/prefs/pref_service_syncable.h" | 61 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 62 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 62 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 63 #include "chrome/common/chrome_constants.h" | 63 #include "chrome/common/chrome_constants.h" |
| 64 #include "chrome/common/chrome_notification_types.h" | 64 #include "chrome/common/chrome_notification_types.h" |
| 65 #include "chrome/common/chrome_paths.h" | 65 #include "chrome/common/chrome_paths.h" |
| 66 #include "chrome/common/chrome_switches.h" | 66 #include "chrome/common/chrome_switches.h" |
| 67 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" | 67 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" |
| 68 #include "chrome/common/extensions/app_launcher_info.h" |
| 68 #include "chrome/common/extensions/background_info.h" | 69 #include "chrome/common/extensions/background_info.h" |
| 69 #include "chrome/common/extensions/extension.h" | 70 #include "chrome/common/extensions/extension.h" |
| 70 #include "chrome/common/extensions/extension_l10n_util.h" | 71 #include "chrome/common/extensions/extension_l10n_util.h" |
| 71 #include "chrome/common/extensions/extension_manifest_constants.h" | 72 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 72 #include "chrome/common/extensions/extension_resource.h" | 73 #include "chrome/common/extensions/extension_resource.h" |
| 73 #include "chrome/common/extensions/manifest_handler.h" | 74 #include "chrome/common/extensions/manifest_handler.h" |
| 74 #include "chrome/common/extensions/manifest_url_handler.h" | 75 #include "chrome/common/extensions/manifest_url_handler.h" |
| 75 #include "chrome/common/extensions/permissions/permission_set.h" | 76 #include "chrome/common/extensions/permissions/permission_set.h" |
| 76 #include "chrome/common/pref_names.h" | 77 #include "chrome/common/pref_names.h" |
| 77 #include "chrome/common/url_constants.h" | 78 #include "chrome/common/url_constants.h" |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 } | 540 } |
| 540 | 541 |
| 541 // static | 542 // static |
| 542 void ExtensionServiceTestBase::SetUpTestCase() { | 543 void ExtensionServiceTestBase::SetUpTestCase() { |
| 543 ExtensionErrorReporter::Init(false); // no noisy errors | 544 ExtensionErrorReporter::Init(false); // no noisy errors |
| 544 } | 545 } |
| 545 | 546 |
| 546 void ExtensionServiceTestBase::SetUp() { | 547 void ExtensionServiceTestBase::SetUp() { |
| 547 testing::Test::SetUp(); | 548 testing::Test::SetUp(); |
| 548 ExtensionErrorReporter::GetInstance()->ClearErrors(); | 549 ExtensionErrorReporter::GetInstance()->ClearErrors(); |
| 550 (new extensions::AppLaunchManifestHandler)->Register(); |
| 549 (new extensions::BackgroundManifestHandler)->Register(); | 551 (new extensions::BackgroundManifestHandler)->Register(); |
| 550 (new extensions::DefaultLocaleHandler)->Register(); | 552 (new extensions::DefaultLocaleHandler)->Register(); |
| 551 } | 553 } |
| 552 | 554 |
| 553 void ExtensionServiceTestBase::TearDown() { | 555 void ExtensionServiceTestBase::TearDown() { |
| 554 extensions::ManifestHandler::ClearRegistryForTesting(); | 556 extensions::ManifestHandler::ClearRegistryForTesting(); |
| 555 } | 557 } |
| 556 | 558 |
| 557 class ExtensionServiceTest | 559 class ExtensionServiceTest |
| 558 : public ExtensionServiceTestBase, public content::NotificationObserver { | 560 : public ExtensionServiceTestBase, public content::NotificationObserver { |
| (...skipping 1778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2337 | 2339 |
| 2338 // Install app1 with unlimited storage. | 2340 // Install app1 with unlimited storage. |
| 2339 const Extension* extension = | 2341 const Extension* extension = |
| 2340 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); | 2342 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
| 2341 ValidatePrefKeyCount(++pref_count); | 2343 ValidatePrefKeyCount(++pref_count); |
| 2342 ASSERT_EQ(1u, service_->extensions()->size()); | 2344 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2343 const std::string id1 = extension->id(); | 2345 const std::string id1 = extension->id(); |
| 2344 EXPECT_TRUE(extension->HasAPIPermission( | 2346 EXPECT_TRUE(extension->HasAPIPermission( |
| 2345 APIPermission::kUnlimitedStorage)); | 2347 APIPermission::kUnlimitedStorage)); |
| 2346 EXPECT_TRUE(extension->web_extent().MatchesURL( | 2348 EXPECT_TRUE(extension->web_extent().MatchesURL( |
| 2347 extension->GetFullLaunchURL())); | 2349 extensions::AppLauncherInfo::GetFullLaunchURL(extension))); |
| 2348 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); | 2350 const GURL origin1( |
| 2351 extensions::AppLauncherInfo::GetFullLaunchURL(extension).GetOrigin()); |
| 2349 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 2352 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2350 IsStorageUnlimited(origin1)); | 2353 IsStorageUnlimited(origin1)); |
| 2351 | 2354 |
| 2352 // Install app2 from the same origin with unlimited storage. | 2355 // Install app2 from the same origin with unlimited storage. |
| 2353 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); | 2356 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); |
| 2354 ValidatePrefKeyCount(++pref_count); | 2357 ValidatePrefKeyCount(++pref_count); |
| 2355 ASSERT_EQ(2u, service_->extensions()->size()); | 2358 ASSERT_EQ(2u, service_->extensions()->size()); |
| 2356 const std::string id2 = extension->id(); | 2359 const std::string id2 = extension->id(); |
| 2357 EXPECT_TRUE(extension->HasAPIPermission( | 2360 EXPECT_TRUE(extension->HasAPIPermission( |
| 2358 APIPermission::kUnlimitedStorage)); | 2361 APIPermission::kUnlimitedStorage)); |
| 2359 EXPECT_TRUE(extension->web_extent().MatchesURL( | 2362 EXPECT_TRUE(extension->web_extent().MatchesURL( |
| 2360 extension->GetFullLaunchURL())); | 2363 extensions::AppLauncherInfo::GetFullLaunchURL(extension))); |
| 2361 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); | 2364 const GURL origin2( |
| 2365 extensions::AppLauncherInfo::GetFullLaunchURL(extension).GetOrigin()); |
| 2362 EXPECT_EQ(origin1, origin2); | 2366 EXPECT_EQ(origin1, origin2); |
| 2363 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 2367 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2364 IsStorageUnlimited(origin2)); | 2368 IsStorageUnlimited(origin2)); |
| 2365 | 2369 |
| 2366 | 2370 |
| 2367 // Uninstall one of them, unlimited storage should still be granted | 2371 // Uninstall one of them, unlimited storage should still be granted |
| 2368 // to the origin. | 2372 // to the origin. |
| 2369 UninstallExtension(id1, false); | 2373 UninstallExtension(id1, false); |
| 2370 EXPECT_EQ(1u, service_->extensions()->size()); | 2374 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2371 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 2375 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2384 EXPECT_TRUE(service_->extensions()->is_empty()); | 2388 EXPECT_TRUE(service_->extensions()->is_empty()); |
| 2385 | 2389 |
| 2386 int pref_count = 0; | 2390 int pref_count = 0; |
| 2387 | 2391 |
| 2388 const Extension* extension = | 2392 const Extension* extension = |
| 2389 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); | 2393 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
| 2390 ValidatePrefKeyCount(++pref_count); | 2394 ValidatePrefKeyCount(++pref_count); |
| 2391 ASSERT_EQ(1u, service_->extensions()->size()); | 2395 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2392 EXPECT_TRUE(extension->is_app()); | 2396 EXPECT_TRUE(extension->is_app()); |
| 2393 const std::string id1 = extension->id(); | 2397 const std::string id1 = extension->id(); |
| 2394 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); | 2398 const GURL origin1( |
| 2399 extensions::AppLauncherInfo::GetFullLaunchURL(extension).GetOrigin()); |
| 2395 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 2400 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2396 IsStorageProtected(origin1)); | 2401 IsStorageProtected(origin1)); |
| 2397 | 2402 |
| 2398 // App 4 has a different origin (maps.google.com). | 2403 // App 4 has a different origin (maps.google.com). |
| 2399 extension = PackAndInstallCRX(data_dir_.AppendASCII("app4"), INSTALL_NEW); | 2404 extension = PackAndInstallCRX(data_dir_.AppendASCII("app4"), INSTALL_NEW); |
| 2400 ValidatePrefKeyCount(++pref_count); | 2405 ValidatePrefKeyCount(++pref_count); |
| 2401 ASSERT_EQ(2u, service_->extensions()->size()); | 2406 ASSERT_EQ(2u, service_->extensions()->size()); |
| 2402 const std::string id2 = extension->id(); | 2407 const std::string id2 = extension->id(); |
| 2403 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); | 2408 const GURL origin2( |
| 2409 extensions::AppLauncherInfo::GetFullLaunchURL(extension).GetOrigin()); |
| 2404 ASSERT_NE(origin1, origin2); | 2410 ASSERT_NE(origin1, origin2); |
| 2405 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 2411 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2406 IsStorageProtected(origin2)); | 2412 IsStorageProtected(origin2)); |
| 2407 | 2413 |
| 2408 UninstallExtension(id1, false); | 2414 UninstallExtension(id1, false); |
| 2409 EXPECT_EQ(1u, service_->extensions()->size()); | 2415 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2410 | 2416 |
| 2411 UninstallExtension(id2, false); | 2417 UninstallExtension(id2, false); |
| 2412 | 2418 |
| 2413 EXPECT_TRUE(service_->extensions()->is_empty()); | 2419 EXPECT_TRUE(service_->extensions()->is_empty()); |
| (...skipping 1446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3860 int pref_count = 0; | 3866 int pref_count = 0; |
| 3861 | 3867 |
| 3862 // Install app1 with unlimited storage. | 3868 // Install app1 with unlimited storage. |
| 3863 const Extension* extension = | 3869 const Extension* extension = |
| 3864 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); | 3870 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
| 3865 ValidatePrefKeyCount(++pref_count); | 3871 ValidatePrefKeyCount(++pref_count); |
| 3866 ASSERT_EQ(1u, service_->extensions()->size()); | 3872 ASSERT_EQ(1u, service_->extensions()->size()); |
| 3867 const std::string id1 = extension->id(); | 3873 const std::string id1 = extension->id(); |
| 3868 EXPECT_TRUE(extension->HasAPIPermission( | 3874 EXPECT_TRUE(extension->HasAPIPermission( |
| 3869 APIPermission::kUnlimitedStorage)); | 3875 APIPermission::kUnlimitedStorage)); |
| 3870 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); | 3876 const GURL origin1( |
| 3877 extensions::AppLauncherInfo::GetFullLaunchURL(extension).GetOrigin()); |
| 3871 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 3878 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 3872 IsStorageUnlimited(origin1)); | 3879 IsStorageUnlimited(origin1)); |
| 3873 string16 origin_id = | 3880 string16 origin_id = |
| 3874 webkit_database::DatabaseUtil::GetOriginIdentifier(origin1); | 3881 webkit_database::DatabaseUtil::GetOriginIdentifier(origin1); |
| 3875 | 3882 |
| 3876 // Install app2 from the same origin with unlimited storage. | 3883 // Install app2 from the same origin with unlimited storage. |
| 3877 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); | 3884 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); |
| 3878 ValidatePrefKeyCount(++pref_count); | 3885 ValidatePrefKeyCount(++pref_count); |
| 3879 ASSERT_EQ(2u, service_->extensions()->size()); | 3886 ASSERT_EQ(2u, service_->extensions()->size()); |
| 3880 const std::string id2 = extension->id(); | 3887 const std::string id2 = extension->id(); |
| 3881 EXPECT_TRUE(extension->HasAPIPermission( | 3888 EXPECT_TRUE(extension->HasAPIPermission( |
| 3882 APIPermission::kUnlimitedStorage)); | 3889 APIPermission::kUnlimitedStorage)); |
| 3883 EXPECT_TRUE(extension->web_extent().MatchesURL( | 3890 EXPECT_TRUE(extension->web_extent().MatchesURL( |
| 3884 extension->GetFullLaunchURL())); | 3891 extensions::AppLauncherInfo::GetFullLaunchURL(extension))); |
| 3885 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); | 3892 const GURL origin2( |
| 3893 extensions::AppLauncherInfo::GetFullLaunchURL(extension).GetOrigin()); |
| 3886 EXPECT_EQ(origin1, origin2); | 3894 EXPECT_EQ(origin1, origin2); |
| 3887 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 3895 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 3888 IsStorageUnlimited(origin2)); | 3896 IsStorageUnlimited(origin2)); |
| 3889 | 3897 |
| 3890 // Set a cookie for the extension. | 3898 // Set a cookie for the extension. |
| 3891 net::CookieMonster* cookie_monster = | 3899 net::CookieMonster* cookie_monster = |
| 3892 profile_->GetRequestContext()->GetURLRequestContext()-> | 3900 profile_->GetRequestContext()->GetURLRequestContext()-> |
| 3893 cookie_store()->GetCookieMonster(); | 3901 cookie_store()->GetCookieMonster(); |
| 3894 ASSERT_TRUE(cookie_monster); | 3902 ASSERT_TRUE(cookie_monster); |
| 3895 net::CookieOptions options; | 3903 net::CookieOptions options; |
| (...skipping 1962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5858 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); | 5866 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
| 5859 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | 5867 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
| 5860 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); | 5868 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); |
| 5861 | 5869 |
| 5862 ExtensionPrefs* prefs = service_->extension_prefs(); | 5870 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 5863 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & | 5871 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & |
| 5864 Extension::DISABLE_SIDELOAD_WIPEOUT); | 5872 Extension::DISABLE_SIDELOAD_WIPEOUT); |
| 5865 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & | 5873 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & |
| 5866 Extension::DISABLE_SIDELOAD_WIPEOUT); | 5874 Extension::DISABLE_SIDELOAD_WIPEOUT); |
| 5867 } | 5875 } |
| OLD | NEW |