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

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

Issue 14241002: 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, 8 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 #include "chrome/browser/prefs/browser_prefs.h" 57 #include "chrome/browser/prefs/browser_prefs.h"
58 #include "chrome/browser/prefs/pref_service_mock_builder.h" 58 #include "chrome/browser/prefs/pref_service_mock_builder.h"
59 #include "chrome/browser/prefs/pref_service_syncable.h" 59 #include "chrome/browser/prefs/pref_service_syncable.h"
60 #include "chrome/browser/prefs/scoped_user_pref_update.h" 60 #include "chrome/browser/prefs/scoped_user_pref_update.h"
61 #include "chrome/common/chrome_constants.h" 61 #include "chrome/common/chrome_constants.h"
62 #include "chrome/common/chrome_notification_types.h" 62 #include "chrome/common/chrome_notification_types.h"
63 #include "chrome/common/chrome_paths.h" 63 #include "chrome/common/chrome_paths.h"
64 #include "chrome/common/chrome_switches.h" 64 #include "chrome/common/chrome_switches.h"
65 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" 65 #include "chrome/common/extensions/api/i18n/default_locale_handler.h"
66 #include "chrome/common/extensions/api/plugins/plugins_handler.h" 66 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
67 #include "chrome/common/extensions/app_launcher_info.h"
67 #include "chrome/common/extensions/background_info.h" 68 #include "chrome/common/extensions/background_info.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/manifest_handlers/content_scripts_handler.h" 72 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
72 #include "chrome/common/extensions/manifest_handlers/requirements_handler.h" 73 #include "chrome/common/extensions/manifest_handlers/requirements_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"
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 } 543 }
543 544
544 // static 545 // static
545 void ExtensionServiceTestBase::SetUpTestCase() { 546 void ExtensionServiceTestBase::SetUpTestCase() {
546 ExtensionErrorReporter::Init(false); // no noisy errors 547 ExtensionErrorReporter::Init(false); // no noisy errors
547 } 548 }
548 549
549 void ExtensionServiceTestBase::SetUp() { 550 void ExtensionServiceTestBase::SetUp() {
550 ExtensionTest::SetUp(); 551 ExtensionTest::SetUp();
551 ExtensionErrorReporter::GetInstance()->ClearErrors(); 552 ExtensionErrorReporter::GetInstance()->ClearErrors();
553 (new extensions::AppLaunchManifestHandler)->Register();
552 (new extensions::BackgroundManifestHandler)->Register(); 554 (new extensions::BackgroundManifestHandler)->Register();
553 (new extensions::ContentScriptsHandler)->Register(); 555 (new extensions::ContentScriptsHandler)->Register();
554 (new extensions::DefaultLocaleHandler)->Register(); 556 (new extensions::DefaultLocaleHandler)->Register();
555 (new extensions::PluginsHandler)->Register(); 557 (new extensions::PluginsHandler)->Register();
556 (new extensions::RequirementsHandler)->Register(); 558 (new extensions::RequirementsHandler)->Register();
557 } 559 }
558 560
559 class ExtensionServiceTest 561 class ExtensionServiceTest
560 : public ExtensionServiceTestBase, public content::NotificationObserver { 562 : public ExtensionServiceTestBase, public content::NotificationObserver {
561 public: 563 public:
(...skipping 1781 matching lines...) Expand 10 before | Expand all | Expand 10 after
2343 2345
2344 // Install app1 with unlimited storage. 2346 // Install app1 with unlimited storage.
2345 const Extension* extension = 2347 const Extension* extension =
2346 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); 2348 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW);
2347 ValidatePrefKeyCount(++pref_count); 2349 ValidatePrefKeyCount(++pref_count);
2348 ASSERT_EQ(1u, service_->extensions()->size()); 2350 ASSERT_EQ(1u, service_->extensions()->size());
2349 const std::string id1 = extension->id(); 2351 const std::string id1 = extension->id();
2350 EXPECT_TRUE(extension->HasAPIPermission( 2352 EXPECT_TRUE(extension->HasAPIPermission(
2351 APIPermission::kUnlimitedStorage)); 2353 APIPermission::kUnlimitedStorage));
2352 EXPECT_TRUE(extension->web_extent().MatchesURL( 2354 EXPECT_TRUE(extension->web_extent().MatchesURL(
2353 extension->GetFullLaunchURL())); 2355 extensions::AppLauncherInfo::GetFullLaunchURL(extension)));
2354 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); 2356 const GURL origin1(
2357 extensions::AppLauncherInfo::GetFullLaunchURL(extension).GetOrigin());
2355 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2358 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
2356 IsStorageUnlimited(origin1)); 2359 IsStorageUnlimited(origin1));
2357 2360
2358 // Install app2 from the same origin with unlimited storage. 2361 // Install app2 from the same origin with unlimited storage.
2359 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); 2362 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW);
2360 ValidatePrefKeyCount(++pref_count); 2363 ValidatePrefKeyCount(++pref_count);
2361 ASSERT_EQ(2u, service_->extensions()->size()); 2364 ASSERT_EQ(2u, service_->extensions()->size());
2362 const std::string id2 = extension->id(); 2365 const std::string id2 = extension->id();
2363 EXPECT_TRUE(extension->HasAPIPermission( 2366 EXPECT_TRUE(extension->HasAPIPermission(
2364 APIPermission::kUnlimitedStorage)); 2367 APIPermission::kUnlimitedStorage));
2365 EXPECT_TRUE(extension->web_extent().MatchesURL( 2368 EXPECT_TRUE(extension->web_extent().MatchesURL(
2366 extension->GetFullLaunchURL())); 2369 extensions::AppLauncherInfo::GetFullLaunchURL(extension)));
2367 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); 2370 const GURL origin2(
2371 extensions::AppLauncherInfo::GetFullLaunchURL(extension).GetOrigin());
2368 EXPECT_EQ(origin1, origin2); 2372 EXPECT_EQ(origin1, origin2);
2369 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2373 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
2370 IsStorageUnlimited(origin2)); 2374 IsStorageUnlimited(origin2));
2371 2375
2372 2376
2373 // Uninstall one of them, unlimited storage should still be granted 2377 // Uninstall one of them, unlimited storage should still be granted
2374 // to the origin. 2378 // to the origin.
2375 UninstallExtension(id1, false); 2379 UninstallExtension(id1, false);
2376 EXPECT_EQ(1u, service_->extensions()->size()); 2380 EXPECT_EQ(1u, service_->extensions()->size());
2377 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2381 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
(...skipping 12 matching lines...) Expand all
2390 EXPECT_TRUE(service_->extensions()->is_empty()); 2394 EXPECT_TRUE(service_->extensions()->is_empty());
2391 2395
2392 int pref_count = 0; 2396 int pref_count = 0;
2393 2397
2394 const Extension* extension = 2398 const Extension* extension =
2395 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); 2399 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW);
2396 ValidatePrefKeyCount(++pref_count); 2400 ValidatePrefKeyCount(++pref_count);
2397 ASSERT_EQ(1u, service_->extensions()->size()); 2401 ASSERT_EQ(1u, service_->extensions()->size());
2398 EXPECT_TRUE(extension->is_app()); 2402 EXPECT_TRUE(extension->is_app());
2399 const std::string id1 = extension->id(); 2403 const std::string id1 = extension->id();
2400 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); 2404 const GURL origin1(
2405 extensions::AppLauncherInfo::GetFullLaunchURL(extension).GetOrigin());
2401 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2406 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
2402 IsStorageProtected(origin1)); 2407 IsStorageProtected(origin1));
2403 2408
2404 // App 4 has a different origin (maps.google.com). 2409 // App 4 has a different origin (maps.google.com).
2405 extension = PackAndInstallCRX(data_dir_.AppendASCII("app4"), INSTALL_NEW); 2410 extension = PackAndInstallCRX(data_dir_.AppendASCII("app4"), INSTALL_NEW);
2406 ValidatePrefKeyCount(++pref_count); 2411 ValidatePrefKeyCount(++pref_count);
2407 ASSERT_EQ(2u, service_->extensions()->size()); 2412 ASSERT_EQ(2u, service_->extensions()->size());
2408 const std::string id2 = extension->id(); 2413 const std::string id2 = extension->id();
2409 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); 2414 const GURL origin2(
2415 extensions::AppLauncherInfo::GetFullLaunchURL(extension).GetOrigin());
2410 ASSERT_NE(origin1, origin2); 2416 ASSERT_NE(origin1, origin2);
2411 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2417 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
2412 IsStorageProtected(origin2)); 2418 IsStorageProtected(origin2));
2413 2419
2414 UninstallExtension(id1, false); 2420 UninstallExtension(id1, false);
2415 EXPECT_EQ(1u, service_->extensions()->size()); 2421 EXPECT_EQ(1u, service_->extensions()->size());
2416 2422
2417 UninstallExtension(id2, false); 2423 UninstallExtension(id2, false);
2418 2424
2419 EXPECT_TRUE(service_->extensions()->is_empty()); 2425 EXPECT_TRUE(service_->extensions()->is_empty());
(...skipping 1483 matching lines...) Expand 10 before | Expand all | Expand 10 after
3903 int pref_count = 0; 3909 int pref_count = 0;
3904 3910
3905 // Install app1 with unlimited storage. 3911 // Install app1 with unlimited storage.
3906 const Extension* extension = 3912 const Extension* extension =
3907 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); 3913 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW);
3908 ValidatePrefKeyCount(++pref_count); 3914 ValidatePrefKeyCount(++pref_count);
3909 ASSERT_EQ(1u, service_->extensions()->size()); 3915 ASSERT_EQ(1u, service_->extensions()->size());
3910 const std::string id1 = extension->id(); 3916 const std::string id1 = extension->id();
3911 EXPECT_TRUE(extension->HasAPIPermission( 3917 EXPECT_TRUE(extension->HasAPIPermission(
3912 APIPermission::kUnlimitedStorage)); 3918 APIPermission::kUnlimitedStorage));
3913 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); 3919 const GURL origin1(
3920 extensions::AppLauncherInfo::GetFullLaunchURL(extension).GetOrigin());
3914 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 3921 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
3915 IsStorageUnlimited(origin1)); 3922 IsStorageUnlimited(origin1));
3916 string16 origin_id = 3923 string16 origin_id =
3917 webkit_database::DatabaseUtil::GetOriginIdentifier(origin1); 3924 webkit_database::DatabaseUtil::GetOriginIdentifier(origin1);
3918 3925
3919 // Install app2 from the same origin with unlimited storage. 3926 // Install app2 from the same origin with unlimited storage.
3920 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); 3927 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW);
3921 ValidatePrefKeyCount(++pref_count); 3928 ValidatePrefKeyCount(++pref_count);
3922 ASSERT_EQ(2u, service_->extensions()->size()); 3929 ASSERT_EQ(2u, service_->extensions()->size());
3923 const std::string id2 = extension->id(); 3930 const std::string id2 = extension->id();
3924 EXPECT_TRUE(extension->HasAPIPermission( 3931 EXPECT_TRUE(extension->HasAPIPermission(
3925 APIPermission::kUnlimitedStorage)); 3932 APIPermission::kUnlimitedStorage));
3926 EXPECT_TRUE(extension->web_extent().MatchesURL( 3933 EXPECT_TRUE(extension->web_extent().MatchesURL(
3927 extension->GetFullLaunchURL())); 3934 extensions::AppLauncherInfo::GetFullLaunchURL(extension)));
3928 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); 3935 const GURL origin2(
3936 extensions::AppLauncherInfo::GetFullLaunchURL(extension).GetOrigin());
3929 EXPECT_EQ(origin1, origin2); 3937 EXPECT_EQ(origin1, origin2);
3930 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 3938 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
3931 IsStorageUnlimited(origin2)); 3939 IsStorageUnlimited(origin2));
3932 3940
3933 // Set a cookie for the extension. 3941 // Set a cookie for the extension.
3934 net::CookieMonster* cookie_monster = 3942 net::CookieMonster* cookie_monster =
3935 profile_->GetRequestContext()->GetURLRequestContext()-> 3943 profile_->GetRequestContext()->GetURLRequestContext()->
3936 cookie_store()->GetCookieMonster(); 3944 cookie_store()->GetCookieMonster();
3937 ASSERT_TRUE(cookie_monster); 3945 ASSERT_TRUE(cookie_monster);
3938 net::CookieOptions options; 3946 net::CookieOptions options;
(...skipping 1962 matching lines...) Expand 10 before | Expand all | Expand 10 after
5901 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 5909 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5902 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 5910 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
5903 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); 5911 EXPECT_TRUE(service_->IsExtensionEnabled(page_action));
5904 5912
5905 ExtensionPrefs* prefs = service_->extension_prefs(); 5913 ExtensionPrefs* prefs = service_->extension_prefs();
5906 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & 5914 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) &
5907 Extension::DISABLE_SIDELOAD_WIPEOUT); 5915 Extension::DISABLE_SIDELOAD_WIPEOUT);
5908 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & 5916 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) &
5909 Extension::DISABLE_SIDELOAD_WIPEOUT); 5917 Extension::DISABLE_SIDELOAD_WIPEOUT);
5910 } 5918 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698