| 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/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/values.h" | 6 #include "base/values.h" |
| 7 #include "chrome/browser/content_settings/cookie_settings.h" | 7 #include "chrome/browser/content_settings/cookie_settings.h" |
| 8 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 8 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 9 #include "chrome/common/content_settings.h" | 9 #include "chrome/common/content_settings.h" |
| 10 #include "chrome/common/content_settings_types.h" | 10 #include "chrome/common/content_settings_types.h" |
| 11 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
| 12 #include "chrome/common/extensions/extension_manifest_constants.h" | 12 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 13 #include "chrome/common/extensions/manifest.h" | 13 #include "chrome/common/extensions/manifest.h" |
| 14 #include "chrome/common/extensions/manifest_handler.h" | 14 #include "chrome/common/extensions/manifest_handler.h" |
| 15 #include "chrome/common/extensions/web_intents_handler.h" | 15 #include "chrome/common/extensions/web_intents_handler.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 17 #include "content/public/test/test_browser_thread.h" | 17 #include "content/public/test/test_browser_thread.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 using content::BrowserThread; | 20 using content::BrowserThread; |
| 21 using extensions::Extension; | 21 using extensions::Extension; |
| 22 using extensions::Manifest; | 22 using extensions::Manifest; |
| 23 | 23 |
| 24 namespace keys = extension_manifest_keys; | 24 namespace keys = extension_manifest_keys; |
| 25 | 25 |
| 26 class ExtensionSpecialStoragePolicyTest : public testing::Test { | 26 class ExtensionSpecialStoragePolicyTest : public testing::Test { |
| 27 public: | 27 public: |
| 28 virtual void SetUp() { | 28 virtual void SetUp() { |
| 29 policy_ = new ExtensionSpecialStoragePolicy(NULL); | 29 policy_ = new ExtensionSpecialStoragePolicy(NULL); |
| 30 #if defined(ENABLE_WEB_INTENTS) |
| 30 extensions::ManifestHandler::Register(keys::kIntents, | 31 extensions::ManifestHandler::Register(keys::kIntents, |
| 31 new extensions::WebIntentsHandler); | 32 new extensions::WebIntentsHandler); |
| 33 #endif |
| 32 } | 34 } |
| 33 | 35 |
| 34 protected: | 36 protected: |
| 35 scoped_refptr<Extension> CreateProtectedApp() { | 37 scoped_refptr<Extension> CreateProtectedApp() { |
| 36 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
| 37 FilePath path(FILE_PATH_LITERAL("c:\\foo")); | 39 FilePath path(FILE_PATH_LITERAL("c:\\foo")); |
| 38 #elif defined(OS_POSIX) | 40 #elif defined(OS_POSIX) |
| 39 FilePath path(FILE_PATH_LITERAL("/foo")); | 41 FilePath path(FILE_PATH_LITERAL("/foo")); |
| 40 #endif | 42 #endif |
| 41 DictionaryValue manifest; | 43 DictionaryValue manifest; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 list->Append(Value::CreateStringValue("fileSystem")); | 126 list->Append(Value::CreateStringValue("fileSystem")); |
| 125 manifest.Set(keys::kPermissions, list); | 127 manifest.Set(keys::kPermissions, list); |
| 126 std::string error; | 128 std::string error; |
| 127 scoped_refptr<Extension> handler_app = Extension::Create( | 129 scoped_refptr<Extension> handler_app = Extension::Create( |
| 128 path, Manifest::INVALID_LOCATION, manifest, | 130 path, Manifest::INVALID_LOCATION, manifest, |
| 129 Extension::NO_FLAGS, &error); | 131 Extension::NO_FLAGS, &error); |
| 130 EXPECT_TRUE(handler_app.get()) << error; | 132 EXPECT_TRUE(handler_app.get()) << error; |
| 131 return handler_app; | 133 return handler_app; |
| 132 } | 134 } |
| 133 | 135 |
| 136 #if defined(ENABLE_WEB_INTENTS) |
| 134 scoped_refptr<Extension> CreateWebIntentViewApp() { | 137 scoped_refptr<Extension> CreateWebIntentViewApp() { |
| 135 #if defined(OS_WIN) | 138 #if defined(OS_WIN) |
| 136 FilePath path(FILE_PATH_LITERAL("c:\\bar")); | 139 FilePath path(FILE_PATH_LITERAL("c:\\bar")); |
| 137 #elif defined(OS_POSIX) | 140 #elif defined(OS_POSIX) |
| 138 FilePath path(FILE_PATH_LITERAL("/bar")); | 141 FilePath path(FILE_PATH_LITERAL("/bar")); |
| 139 #endif | 142 #endif |
| 140 DictionaryValue manifest; | 143 DictionaryValue manifest; |
| 141 manifest.SetString(keys::kName, "WebIntent"); | 144 manifest.SetString(keys::kName, "WebIntent"); |
| 142 manifest.SetString(keys::kVersion, "1"); | 145 manifest.SetString(keys::kVersion, "1"); |
| 143 manifest.SetString(keys::kLaunchWebURL, "http://explicit/unlimited/start"); | 146 manifest.SetString(keys::kLaunchWebURL, "http://explicit/unlimited/start"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 157 view_intent_list); | 160 view_intent_list); |
| 158 manifest.Set(keys::kIntents, intents); | 161 manifest.Set(keys::kIntents, intents); |
| 159 | 162 |
| 160 std::string error; | 163 std::string error; |
| 161 scoped_refptr<Extension> intent_app = Extension::Create( | 164 scoped_refptr<Extension> intent_app = Extension::Create( |
| 162 path, Manifest::INVALID_LOCATION, manifest, | 165 path, Manifest::INVALID_LOCATION, manifest, |
| 163 Extension::NO_FLAGS, &error); | 166 Extension::NO_FLAGS, &error); |
| 164 EXPECT_TRUE(intent_app.get()) << error; | 167 EXPECT_TRUE(intent_app.get()) << error; |
| 165 return intent_app; | 168 return intent_app; |
| 166 } | 169 } |
| 170 #endif |
| 167 | 171 |
| 168 // Verifies that the set of extensions protecting |url| is *exactly* equal to | 172 // Verifies that the set of extensions protecting |url| is *exactly* equal to |
| 169 // |expected_extensions|. Pass in an empty set to verify that an origin is not | 173 // |expected_extensions|. Pass in an empty set to verify that an origin is not |
| 170 // protected. | 174 // protected. |
| 171 void ExpectProtectedBy(const ExtensionSet& expected_extensions, | 175 void ExpectProtectedBy(const ExtensionSet& expected_extensions, |
| 172 const GURL& url) { | 176 const GURL& url) { |
| 173 const ExtensionSet* extensions = policy_->ExtensionsProtectingOrigin(url); | 177 const ExtensionSet* extensions = policy_->ExtensionsProtectingOrigin(url); |
| 174 EXPECT_EQ(expected_extensions.size(), extensions->size()); | 178 EXPECT_EQ(expected_extensions.size(), extensions->size()); |
| 175 for (ExtensionSet::const_iterator it = expected_extensions.begin(); | 179 for (ExtensionSet::const_iterator it = expected_extensions.begin(); |
| 176 it != expected_extensions.end(); ++it) { | 180 it != expected_extensions.end(); ++it) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 ExpectProtectedBy(protecting_extensions, GURL("http://foo.wildcards/")); | 284 ExpectProtectedBy(protecting_extensions, GURL("http://foo.wildcards/")); |
| 281 ExpectProtectedBy(protecting_extensions, GURL("https://bar.wildcards/")); | 285 ExpectProtectedBy(protecting_extensions, GURL("https://bar.wildcards/")); |
| 282 | 286 |
| 283 policy_->RevokeRightsForExtension(protected_app); | 287 policy_->RevokeRightsForExtension(protected_app); |
| 284 ExpectProtectedBy(empty_set, GURL("http://explicit/")); | 288 ExpectProtectedBy(empty_set, GURL("http://explicit/")); |
| 285 ExpectProtectedBy(empty_set, GURL("http://foo.wildcards/")); | 289 ExpectProtectedBy(empty_set, GURL("http://foo.wildcards/")); |
| 286 ExpectProtectedBy(empty_set, GURL("https://bar.wildcards/")); | 290 ExpectProtectedBy(empty_set, GURL("https://bar.wildcards/")); |
| 287 } | 291 } |
| 288 | 292 |
| 289 TEST_F(ExtensionSpecialStoragePolicyTest, WebIntentViewApp) { | 293 TEST_F(ExtensionSpecialStoragePolicyTest, WebIntentViewApp) { |
| 294 #if defined(ENABLE_WEB_INTENTS) |
| 290 scoped_refptr<Extension> intent_app(CreateWebIntentViewApp()); | 295 scoped_refptr<Extension> intent_app(CreateWebIntentViewApp()); |
| 291 | 296 |
| 292 policy_->GrantRightsForExtension(intent_app); | 297 policy_->GrantRightsForExtension(intent_app); |
| 293 EXPECT_TRUE(policy_->IsFileHandler(intent_app->id())); | 298 EXPECT_TRUE(policy_->IsFileHandler(intent_app->id())); |
| 294 | 299 |
| 295 policy_->RevokeRightsForExtension(intent_app); | 300 policy_->RevokeRightsForExtension(intent_app); |
| 296 EXPECT_FALSE(policy_->IsFileHandler(intent_app->id())); | 301 EXPECT_FALSE(policy_->IsFileHandler(intent_app->id())); |
| 302 #endif |
| 297 } | 303 } |
| 298 | 304 |
| 299 TEST_F(ExtensionSpecialStoragePolicyTest, HasSessionOnlyOrigins) { | 305 TEST_F(ExtensionSpecialStoragePolicyTest, HasSessionOnlyOrigins) { |
| 300 MessageLoop message_loop; | 306 MessageLoop message_loop; |
| 301 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 307 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 302 | 308 |
| 303 TestingProfile profile; | 309 TestingProfile profile; |
| 304 CookieSettings* cookie_settings = | 310 CookieSettings* cookie_settings = |
| 305 CookieSettings::Factory::GetForProfile(&profile); | 311 CookieSettings::Factory::GetForProfile(&profile); |
| 306 policy_ = new ExtensionSpecialStoragePolicy(cookie_settings); | 312 policy_ = new ExtensionSpecialStoragePolicy(cookie_settings); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 323 CONTENT_SETTING_SESSION_ONLY); | 329 CONTENT_SETTING_SESSION_ONLY); |
| 324 | 330 |
| 325 EXPECT_TRUE(policy_->HasSessionOnlyOrigins()); | 331 EXPECT_TRUE(policy_->HasSessionOnlyOrigins()); |
| 326 | 332 |
| 327 // Clearing an origin-specific rule. | 333 // Clearing an origin-specific rule. |
| 328 cookie_settings->ResetCookieSetting(pattern, | 334 cookie_settings->ResetCookieSetting(pattern, |
| 329 ContentSettingsPattern::Wildcard()); | 335 ContentSettingsPattern::Wildcard()); |
| 330 | 336 |
| 331 EXPECT_FALSE(policy_->HasSessionOnlyOrigins()); | 337 EXPECT_FALSE(policy_->HasSessionOnlyOrigins()); |
| 332 } | 338 } |
| OLD | NEW |