| 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" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 list->Append(Value::CreateStringValue("unlimitedStorage")); | 115 list->Append(Value::CreateStringValue("unlimitedStorage")); |
| 116 list->Append(Value::CreateStringValue("fileSystem")); | 116 list->Append(Value::CreateStringValue("fileSystem")); |
| 117 manifest.Set(keys::kPermissions, list); | 117 manifest.Set(keys::kPermissions, list); |
| 118 std::string error; | 118 std::string error; |
| 119 scoped_refptr<Extension> handler_app = Extension::Create( | 119 scoped_refptr<Extension> handler_app = Extension::Create( |
| 120 path, Extension::INVALID, manifest, Extension::NO_FLAGS, &error); | 120 path, Extension::INVALID, manifest, Extension::NO_FLAGS, &error); |
| 121 EXPECT_TRUE(handler_app.get()) << error; | 121 EXPECT_TRUE(handler_app.get()) << error; |
| 122 return handler_app; | 122 return handler_app; |
| 123 } | 123 } |
| 124 | 124 |
| 125 scoped_refptr<Extension> CreateWebIntentViewApp() { |
| 126 #if defined(OS_WIN) |
| 127 FilePath path(FILE_PATH_LITERAL("c:\\bar")); |
| 128 #elif defined(OS_POSIX) |
| 129 FilePath path(FILE_PATH_LITERAL("/bar")); |
| 130 #endif |
| 131 DictionaryValue manifest; |
| 132 manifest.SetString(keys::kName, "WebIntent"); |
| 133 manifest.SetString(keys::kVersion, "1"); |
| 134 manifest.SetString(keys::kLaunchWebURL, "http://explicit/unlimited/start"); |
| 135 |
| 136 ListValue* view_intent_types = new ListValue; |
| 137 view_intent_types->Append(Value::CreateStringValue("text/plain")); |
| 138 |
| 139 DictionaryValue* view_intent = new DictionaryValue; |
| 140 view_intent->SetString(keys::kIntentTitle, "Test Intent"); |
| 141 view_intent->Set(keys::kIntentType, view_intent_types); |
| 142 |
| 143 ListValue* view_intent_list = new ListValue; |
| 144 view_intent_list->Append(view_intent); |
| 145 |
| 146 DictionaryValue* intents = new DictionaryValue; |
| 147 intents->SetWithoutPathExpansion("http://webintents.org/view", |
| 148 view_intent_list); |
| 149 manifest.Set(keys::kIntents, intents); |
| 150 |
| 151 std::string error; |
| 152 scoped_refptr<Extension> intent_app = Extension::Create( |
| 153 path, Extension::INVALID, manifest, Extension::NO_FLAGS, &error); |
| 154 EXPECT_TRUE(intent_app.get()) << error; |
| 155 return intent_app; |
| 156 } |
| 157 |
| 125 // Verifies that the set of extensions protecting |url| is *exactly* equal to | 158 // Verifies that the set of extensions protecting |url| is *exactly* equal to |
| 126 // |expected_extensions|. Pass in an empty set to verify that an origin is not | 159 // |expected_extensions|. Pass in an empty set to verify that an origin is not |
| 127 // protected. | 160 // protected. |
| 128 void ExpectProtectedBy(const ExtensionSet& expected_extensions, | 161 void ExpectProtectedBy(const ExtensionSet& expected_extensions, |
| 129 const GURL& url) { | 162 const GURL& url) { |
| 130 const ExtensionSet* extensions = policy_->ExtensionsProtectingOrigin(url); | 163 const ExtensionSet* extensions = policy_->ExtensionsProtectingOrigin(url); |
| 131 EXPECT_EQ(expected_extensions.size(), extensions->size()); | 164 EXPECT_EQ(expected_extensions.size(), extensions->size()); |
| 132 for (ExtensionSet::const_iterator it = expected_extensions.begin(); | 165 for (ExtensionSet::const_iterator it = expected_extensions.begin(); |
| 133 it != expected_extensions.end(); ++it) { | 166 it != expected_extensions.end(); ++it) { |
| 134 EXPECT_TRUE(extensions->Contains((*it)->id())) | 167 EXPECT_TRUE(extensions->Contains((*it)->id())) |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/")); | 269 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/")); |
| 237 ExpectProtectedBy(protecting_extensions, GURL("http://foo.wildcards/")); | 270 ExpectProtectedBy(protecting_extensions, GURL("http://foo.wildcards/")); |
| 238 ExpectProtectedBy(protecting_extensions, GURL("https://bar.wildcards/")); | 271 ExpectProtectedBy(protecting_extensions, GURL("https://bar.wildcards/")); |
| 239 | 272 |
| 240 policy_->RevokeRightsForExtension(protected_app); | 273 policy_->RevokeRightsForExtension(protected_app); |
| 241 ExpectProtectedBy(empty_set, GURL("http://explicit/")); | 274 ExpectProtectedBy(empty_set, GURL("http://explicit/")); |
| 242 ExpectProtectedBy(empty_set, GURL("http://foo.wildcards/")); | 275 ExpectProtectedBy(empty_set, GURL("http://foo.wildcards/")); |
| 243 ExpectProtectedBy(empty_set, GURL("https://bar.wildcards/")); | 276 ExpectProtectedBy(empty_set, GURL("https://bar.wildcards/")); |
| 244 } | 277 } |
| 245 | 278 |
| 279 TEST_F(ExtensionSpecialStoragePolicyTest, WebIntentViewApp) { |
| 280 scoped_refptr<Extension> intent_app(CreateWebIntentViewApp()); |
| 281 |
| 282 policy_->GrantRightsForExtension(intent_app); |
| 283 EXPECT_TRUE(policy_->IsFileHandler(intent_app->id())); |
| 284 |
| 285 policy_->RevokeRightsForExtension(intent_app); |
| 286 EXPECT_FALSE(policy_->IsFileHandler(intent_app->id())); |
| 287 } |
| 288 |
| 246 TEST_F(ExtensionSpecialStoragePolicyTest, HasSessionOnlyOrigins) { | 289 TEST_F(ExtensionSpecialStoragePolicyTest, HasSessionOnlyOrigins) { |
| 247 MessageLoop message_loop; | 290 MessageLoop message_loop; |
| 248 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 291 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 249 | 292 |
| 250 TestingProfile profile; | 293 TestingProfile profile; |
| 251 CookieSettings* cookie_settings = | 294 CookieSettings* cookie_settings = |
| 252 CookieSettings::Factory::GetForProfile(&profile); | 295 CookieSettings::Factory::GetForProfile(&profile); |
| 253 policy_ = new ExtensionSpecialStoragePolicy(cookie_settings); | 296 policy_ = new ExtensionSpecialStoragePolicy(cookie_settings); |
| 254 | 297 |
| 255 EXPECT_FALSE(policy_->HasSessionOnlyOrigins()); | 298 EXPECT_FALSE(policy_->HasSessionOnlyOrigins()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 270 CONTENT_SETTING_SESSION_ONLY); | 313 CONTENT_SETTING_SESSION_ONLY); |
| 271 | 314 |
| 272 EXPECT_TRUE(policy_->HasSessionOnlyOrigins()); | 315 EXPECT_TRUE(policy_->HasSessionOnlyOrigins()); |
| 273 | 316 |
| 274 // Clearing an origin-specific rule. | 317 // Clearing an origin-specific rule. |
| 275 cookie_settings->ResetCookieSetting(pattern, | 318 cookie_settings->ResetCookieSetting(pattern, |
| 276 ContentSettingsPattern::Wildcard()); | 319 ContentSettingsPattern::Wildcard()); |
| 277 | 320 |
| 278 EXPECT_FALSE(policy_->HasSessionOnlyOrigins()); | 321 EXPECT_FALSE(policy_->HasSessionOnlyOrigins()); |
| 279 } | 322 } |
| OLD | NEW |