Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 12316077: Move the parsing of app.launch related keys out of Extension class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_launch_manifest_handler.h"
68 #include "chrome/common/extensions/extension.h" 69 #include "chrome/common/extensions/extension.h"
69 #include "chrome/common/extensions/extension_l10n_util.h" 70 #include "chrome/common/extensions/extension_l10n_util.h"
70 #include "chrome/common/extensions/extension_manifest_constants.h" 71 #include "chrome/common/extensions/extension_manifest_constants.h"
71 #include "chrome/common/extensions/extension_resource.h" 72 #include "chrome/common/extensions/extension_resource.h"
72 #include "chrome/common/extensions/manifest_handler.h" 73 #include "chrome/common/extensions/manifest_handler.h"
73 #include "chrome/common/extensions/manifest_url_handler.h" 74 #include "chrome/common/extensions/manifest_url_handler.h"
74 #include "chrome/common/extensions/permissions/permission_set.h" 75 #include "chrome/common/extensions/permissions/permission_set.h"
75 #include "chrome/common/pref_names.h" 76 #include "chrome/common/pref_names.h"
76 #include "chrome/common/url_constants.h" 77 #include "chrome/common/url_constants.h"
77 #include "chrome/test/base/testing_profile.h" 78 #include "chrome/test/base/testing_profile.h"
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 std::vector<std::string> app_launch_keys(
551 extensions::AppLaunchManifestHandler::keys());
552 linked_ptr<extensions::AppLaunchManifestHandler> app_launch_handler(
553 new extensions::AppLaunchManifestHandler);
554 for (size_t i = 0; i < app_launch_keys.size(); ++i) {
555 extensions::ManifestHandler::Register(app_launch_keys[i],
556 app_launch_handler);
557 }
549 extensions::ManifestHandler::Register( 558 extensions::ManifestHandler::Register(
550 keys::kDefaultLocale, 559 keys::kDefaultLocale,
551 make_linked_ptr(new extensions::DefaultLocaleHandler)); 560 make_linked_ptr(new extensions::DefaultLocaleHandler));
552 } 561 }
553 562
554 void ExtensionServiceTestBase::TearDown() { 563 void ExtensionServiceTestBase::TearDown() {
555 extensions::ManifestHandler::ClearRegistryForTesting(); 564 extensions::ManifestHandler::ClearRegistryForTesting();
556 } 565 }
557 566
558 class ExtensionServiceTest 567 class ExtensionServiceTest
(...skipping 1779 matching lines...) Expand 10 before | Expand all | Expand 10 after
2338 2347
2339 // Install app1 with unlimited storage. 2348 // Install app1 with unlimited storage.
2340 const Extension* extension = 2349 const Extension* extension =
2341 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); 2350 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW);
2342 ValidatePrefKeyCount(++pref_count); 2351 ValidatePrefKeyCount(++pref_count);
2343 ASSERT_EQ(1u, service_->extensions()->size()); 2352 ASSERT_EQ(1u, service_->extensions()->size());
2344 const std::string id1 = extension->id(); 2353 const std::string id1 = extension->id();
2345 EXPECT_TRUE(extension->HasAPIPermission( 2354 EXPECT_TRUE(extension->HasAPIPermission(
2346 APIPermission::kUnlimitedStorage)); 2355 APIPermission::kUnlimitedStorage));
2347 EXPECT_TRUE(extension->web_extent().MatchesURL( 2356 EXPECT_TRUE(extension->web_extent().MatchesURL(
2348 extension->GetFullLaunchURL())); 2357 extensions::AppLaunchInfo::GetFullLaunchURL(extension)));
2349 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); 2358 const GURL origin1(
2359 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
2350 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2360 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
2351 IsStorageUnlimited(origin1)); 2361 IsStorageUnlimited(origin1));
2352 2362
2353 // Install app2 from the same origin with unlimited storage. 2363 // Install app2 from the same origin with unlimited storage.
2354 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); 2364 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW);
2355 ValidatePrefKeyCount(++pref_count); 2365 ValidatePrefKeyCount(++pref_count);
2356 ASSERT_EQ(2u, service_->extensions()->size()); 2366 ASSERT_EQ(2u, service_->extensions()->size());
2357 const std::string id2 = extension->id(); 2367 const std::string id2 = extension->id();
2358 EXPECT_TRUE(extension->HasAPIPermission( 2368 EXPECT_TRUE(extension->HasAPIPermission(
2359 APIPermission::kUnlimitedStorage)); 2369 APIPermission::kUnlimitedStorage));
2360 EXPECT_TRUE(extension->web_extent().MatchesURL( 2370 EXPECT_TRUE(extension->web_extent().MatchesURL(
2361 extension->GetFullLaunchURL())); 2371 extensions::AppLaunchInfo::GetFullLaunchURL(extension)));
2362 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); 2372 const GURL origin2(
2373 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
2363 EXPECT_EQ(origin1, origin2); 2374 EXPECT_EQ(origin1, origin2);
2364 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2375 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
2365 IsStorageUnlimited(origin2)); 2376 IsStorageUnlimited(origin2));
2366 2377
2367 2378
2368 // Uninstall one of them, unlimited storage should still be granted 2379 // Uninstall one of them, unlimited storage should still be granted
2369 // to the origin. 2380 // to the origin.
2370 UninstallExtension(id1, false); 2381 UninstallExtension(id1, false);
2371 EXPECT_EQ(1u, service_->extensions()->size()); 2382 EXPECT_EQ(1u, service_->extensions()->size());
2372 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2383 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
(...skipping 12 matching lines...) Expand all
2385 EXPECT_TRUE(service_->extensions()->is_empty()); 2396 EXPECT_TRUE(service_->extensions()->is_empty());
2386 2397
2387 int pref_count = 0; 2398 int pref_count = 0;
2388 2399
2389 const Extension* extension = 2400 const Extension* extension =
2390 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); 2401 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW);
2391 ValidatePrefKeyCount(++pref_count); 2402 ValidatePrefKeyCount(++pref_count);
2392 ASSERT_EQ(1u, service_->extensions()->size()); 2403 ASSERT_EQ(1u, service_->extensions()->size());
2393 EXPECT_TRUE(extension->is_app()); 2404 EXPECT_TRUE(extension->is_app());
2394 const std::string id1 = extension->id(); 2405 const std::string id1 = extension->id();
2395 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); 2406 const GURL origin1(
2407 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
2396 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2408 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
2397 IsStorageProtected(origin1)); 2409 IsStorageProtected(origin1));
2398 2410
2399 // App 4 has a different origin (maps.google.com). 2411 // App 4 has a different origin (maps.google.com).
2400 extension = PackAndInstallCRX(data_dir_.AppendASCII("app4"), INSTALL_NEW); 2412 extension = PackAndInstallCRX(data_dir_.AppendASCII("app4"), INSTALL_NEW);
2401 ValidatePrefKeyCount(++pref_count); 2413 ValidatePrefKeyCount(++pref_count);
2402 ASSERT_EQ(2u, service_->extensions()->size()); 2414 ASSERT_EQ(2u, service_->extensions()->size());
2403 const std::string id2 = extension->id(); 2415 const std::string id2 = extension->id();
2404 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); 2416 const GURL origin2(
2417 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
2405 ASSERT_NE(origin1, origin2); 2418 ASSERT_NE(origin1, origin2);
2406 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2419 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
2407 IsStorageProtected(origin2)); 2420 IsStorageProtected(origin2));
2408 2421
2409 UninstallExtension(id1, false); 2422 UninstallExtension(id1, false);
2410 EXPECT_EQ(1u, service_->extensions()->size()); 2423 EXPECT_EQ(1u, service_->extensions()->size());
2411 2424
2412 UninstallExtension(id2, false); 2425 UninstallExtension(id2, false);
2413 2426
2414 EXPECT_TRUE(service_->extensions()->is_empty()); 2427 EXPECT_TRUE(service_->extensions()->is_empty());
(...skipping 1446 matching lines...) Expand 10 before | Expand all | Expand 10 after
3861 int pref_count = 0; 3874 int pref_count = 0;
3862 3875
3863 // Install app1 with unlimited storage. 3876 // Install app1 with unlimited storage.
3864 const Extension* extension = 3877 const Extension* extension =
3865 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); 3878 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW);
3866 ValidatePrefKeyCount(++pref_count); 3879 ValidatePrefKeyCount(++pref_count);
3867 ASSERT_EQ(1u, service_->extensions()->size()); 3880 ASSERT_EQ(1u, service_->extensions()->size());
3868 const std::string id1 = extension->id(); 3881 const std::string id1 = extension->id();
3869 EXPECT_TRUE(extension->HasAPIPermission( 3882 EXPECT_TRUE(extension->HasAPIPermission(
3870 APIPermission::kUnlimitedStorage)); 3883 APIPermission::kUnlimitedStorage));
3871 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); 3884 const GURL origin1(
3885 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
3872 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 3886 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
3873 IsStorageUnlimited(origin1)); 3887 IsStorageUnlimited(origin1));
3874 string16 origin_id = 3888 string16 origin_id =
3875 webkit_database::DatabaseUtil::GetOriginIdentifier(origin1); 3889 webkit_database::DatabaseUtil::GetOriginIdentifier(origin1);
3876 3890
3877 // Install app2 from the same origin with unlimited storage. 3891 // Install app2 from the same origin with unlimited storage.
3878 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); 3892 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW);
3879 ValidatePrefKeyCount(++pref_count); 3893 ValidatePrefKeyCount(++pref_count);
3880 ASSERT_EQ(2u, service_->extensions()->size()); 3894 ASSERT_EQ(2u, service_->extensions()->size());
3881 const std::string id2 = extension->id(); 3895 const std::string id2 = extension->id();
3882 EXPECT_TRUE(extension->HasAPIPermission( 3896 EXPECT_TRUE(extension->HasAPIPermission(
3883 APIPermission::kUnlimitedStorage)); 3897 APIPermission::kUnlimitedStorage));
3884 EXPECT_TRUE(extension->web_extent().MatchesURL( 3898 EXPECT_TRUE(extension->web_extent().MatchesURL(
3885 extension->GetFullLaunchURL())); 3899 extensions::AppLaunchInfo::GetFullLaunchURL(extension)));
3886 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); 3900 const GURL origin2(
3901 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
3887 EXPECT_EQ(origin1, origin2); 3902 EXPECT_EQ(origin1, origin2);
3888 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 3903 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
3889 IsStorageUnlimited(origin2)); 3904 IsStorageUnlimited(origin2));
3890 3905
3891 // Set a cookie for the extension. 3906 // Set a cookie for the extension.
3892 net::CookieMonster* cookie_monster = 3907 net::CookieMonster* cookie_monster =
3893 profile_->GetRequestContext()->GetURLRequestContext()-> 3908 profile_->GetRequestContext()->GetURLRequestContext()->
3894 cookie_store()->GetCookieMonster(); 3909 cookie_store()->GetCookieMonster();
3895 ASSERT_TRUE(cookie_monster); 3910 ASSERT_TRUE(cookie_monster);
3896 net::CookieOptions options; 3911 net::CookieOptions options;
(...skipping 1962 matching lines...) Expand 10 before | Expand all | Expand 10 after
5859 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 5874 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5860 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 5875 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
5861 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); 5876 EXPECT_TRUE(service_->IsExtensionEnabled(page_action));
5862 5877
5863 ExtensionPrefs* prefs = service_->extension_prefs(); 5878 ExtensionPrefs* prefs = service_->extension_prefs();
5864 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & 5879 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) &
5865 Extension::DISABLE_SIDELOAD_WIPEOUT); 5880 Extension::DISABLE_SIDELOAD_WIPEOUT);
5866 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & 5881 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) &
5867 Extension::DISABLE_SIDELOAD_WIPEOUT); 5882 Extension::DISABLE_SIDELOAD_WIPEOUT);
5868 } 5883 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698