| 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_handler.h" | 14 #include "chrome/common/extensions/manifest_handler.h" |
| 14 #include "chrome/common/extensions/web_intents_handler.h" | 15 #include "chrome/common/extensions/web_intents_handler.h" |
| 15 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 16 #include "content/public/test/test_browser_thread.h" | 17 #include "content/public/test/test_browser_thread.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 using content::BrowserThread; | 20 using content::BrowserThread; |
| 20 using extensions::Extension; | 21 using extensions::Extension; |
| 22 using extensions::Manifest; |
| 21 | 23 |
| 22 namespace keys = extension_manifest_keys; | 24 namespace keys = extension_manifest_keys; |
| 23 | 25 |
| 24 class ExtensionSpecialStoragePolicyTest : public testing::Test { | 26 class ExtensionSpecialStoragePolicyTest : public testing::Test { |
| 25 public: | 27 public: |
| 26 virtual void SetUp() { | 28 virtual void SetUp() { |
| 27 policy_ = new ExtensionSpecialStoragePolicy(NULL); | 29 policy_ = new ExtensionSpecialStoragePolicy(NULL); |
| 28 extensions::ManifestHandler::Register(keys::kIntents, | 30 extensions::ManifestHandler::Register(keys::kIntents, |
| 29 new extensions::WebIntentsHandler); | 31 new extensions::WebIntentsHandler); |
| 30 } | 32 } |
| 31 | 33 |
| 32 protected: | 34 protected: |
| 33 scoped_refptr<Extension> CreateProtectedApp() { | 35 scoped_refptr<Extension> CreateProtectedApp() { |
| 34 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
| 35 FilePath path(FILE_PATH_LITERAL("c:\\foo")); | 37 FilePath path(FILE_PATH_LITERAL("c:\\foo")); |
| 36 #elif defined(OS_POSIX) | 38 #elif defined(OS_POSIX) |
| 37 FilePath path(FILE_PATH_LITERAL("/foo")); | 39 FilePath path(FILE_PATH_LITERAL("/foo")); |
| 38 #endif | 40 #endif |
| 39 DictionaryValue manifest; | 41 DictionaryValue manifest; |
| 40 manifest.SetString(keys::kName, "Protected"); | 42 manifest.SetString(keys::kName, "Protected"); |
| 41 manifest.SetString(keys::kVersion, "1"); | 43 manifest.SetString(keys::kVersion, "1"); |
| 42 manifest.SetString(keys::kLaunchWebURL, "http://explicit/protected/start"); | 44 manifest.SetString(keys::kLaunchWebURL, "http://explicit/protected/start"); |
| 43 ListValue* list = new ListValue(); | 45 ListValue* list = new ListValue(); |
| 44 list->Append(Value::CreateStringValue("http://explicit/protected")); | 46 list->Append(Value::CreateStringValue("http://explicit/protected")); |
| 45 list->Append(Value::CreateStringValue("*://*.wildcards/protected")); | 47 list->Append(Value::CreateStringValue("*://*.wildcards/protected")); |
| 46 manifest.Set(keys::kWebURLs, list); | 48 manifest.Set(keys::kWebURLs, list); |
| 47 std::string error; | 49 std::string error; |
| 48 scoped_refptr<Extension> protected_app = Extension::Create( | 50 scoped_refptr<Extension> protected_app = Extension::Create( |
| 49 path, Extension::INVALID, manifest, Extension::NO_FLAGS, &error); | 51 path, Manifest::INVALID_LOCATION, manifest, |
| 52 Extension::NO_FLAGS, &error); |
| 50 EXPECT_TRUE(protected_app.get()) << error; | 53 EXPECT_TRUE(protected_app.get()) << error; |
| 51 return protected_app; | 54 return protected_app; |
| 52 } | 55 } |
| 53 | 56 |
| 54 scoped_refptr<Extension> CreateUnlimitedApp() { | 57 scoped_refptr<Extension> CreateUnlimitedApp() { |
| 55 #if defined(OS_WIN) | 58 #if defined(OS_WIN) |
| 56 FilePath path(FILE_PATH_LITERAL("c:\\bar")); | 59 FilePath path(FILE_PATH_LITERAL("c:\\bar")); |
| 57 #elif defined(OS_POSIX) | 60 #elif defined(OS_POSIX) |
| 58 FilePath path(FILE_PATH_LITERAL("/bar")); | 61 FilePath path(FILE_PATH_LITERAL("/bar")); |
| 59 #endif | 62 #endif |
| 60 DictionaryValue manifest; | 63 DictionaryValue manifest; |
| 61 manifest.SetString(keys::kName, "Unlimited"); | 64 manifest.SetString(keys::kName, "Unlimited"); |
| 62 manifest.SetString(keys::kVersion, "1"); | 65 manifest.SetString(keys::kVersion, "1"); |
| 63 manifest.SetString(keys::kLaunchWebURL, "http://explicit/unlimited/start"); | 66 manifest.SetString(keys::kLaunchWebURL, "http://explicit/unlimited/start"); |
| 64 ListValue* list = new ListValue(); | 67 ListValue* list = new ListValue(); |
| 65 list->Append(Value::CreateStringValue("unlimitedStorage")); | 68 list->Append(Value::CreateStringValue("unlimitedStorage")); |
| 66 manifest.Set(keys::kPermissions, list); | 69 manifest.Set(keys::kPermissions, list); |
| 67 list = new ListValue(); | 70 list = new ListValue(); |
| 68 list->Append(Value::CreateStringValue("http://explicit/unlimited")); | 71 list->Append(Value::CreateStringValue("http://explicit/unlimited")); |
| 69 list->Append(Value::CreateStringValue("*://*.wildcards/unlimited")); | 72 list->Append(Value::CreateStringValue("*://*.wildcards/unlimited")); |
| 70 manifest.Set(keys::kWebURLs, list); | 73 manifest.Set(keys::kWebURLs, list); |
| 71 std::string error; | 74 std::string error; |
| 72 scoped_refptr<Extension> unlimited_app = Extension::Create( | 75 scoped_refptr<Extension> unlimited_app = Extension::Create( |
| 73 path, Extension::INVALID, manifest, Extension::NO_FLAGS, &error); | 76 path, Manifest::INVALID_LOCATION, manifest, |
| 77 Extension::NO_FLAGS, &error); |
| 74 EXPECT_TRUE(unlimited_app.get()) << error; | 78 EXPECT_TRUE(unlimited_app.get()) << error; |
| 75 return unlimited_app; | 79 return unlimited_app; |
| 76 } | 80 } |
| 77 | 81 |
| 78 scoped_refptr<Extension> CreateComponentApp() { | 82 scoped_refptr<Extension> CreateComponentApp() { |
| 79 #if defined(OS_WIN) | 83 #if defined(OS_WIN) |
| 80 FilePath path(FILE_PATH_LITERAL("c:\\component")); | 84 FilePath path(FILE_PATH_LITERAL("c:\\component")); |
| 81 #elif defined(OS_POSIX) | 85 #elif defined(OS_POSIX) |
| 82 FilePath path(FILE_PATH_LITERAL("/component")); | 86 FilePath path(FILE_PATH_LITERAL("/component")); |
| 83 #endif | 87 #endif |
| 84 DictionaryValue manifest; | 88 DictionaryValue manifest; |
| 85 manifest.SetString(keys::kName, "Component"); | 89 manifest.SetString(keys::kName, "Component"); |
| 86 manifest.SetString(keys::kVersion, "1"); | 90 manifest.SetString(keys::kVersion, "1"); |
| 87 manifest.SetString(keys::kPublicKey, | 91 manifest.SetString(keys::kPublicKey, |
| 88 "MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQDOuXEIuoK1kAkBe0SKiJn/N9oNn3oU" \ | 92 "MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQDOuXEIuoK1kAkBe0SKiJn/N9oNn3oU" \ |
| 89 "xGa4dwj40MnJqPn+w0aR2vuyocm0R4Drp67aYwtLjOVPF4CICRq6ICP6eU07gGwQxGdZ" \ | 93 "xGa4dwj40MnJqPn+w0aR2vuyocm0R4Drp67aYwtLjOVPF4CICRq6ICP6eU07gGwQxGdZ" \ |
| 90 "7HJASXV8hm0tab5I70oJmRLfFJyVAMCeWlFaOGq05v2i6EbifZM0qO5xALKNGQt+yjXi" \ | 94 "7HJASXV8hm0tab5I70oJmRLfFJyVAMCeWlFaOGq05v2i6EbifZM0qO5xALKNGQt+yjXi" \ |
| 91 "5INM5wIBIw=="); | 95 "5INM5wIBIw=="); |
| 92 ListValue* list = new ListValue(); | 96 ListValue* list = new ListValue(); |
| 93 list->Append(Value::CreateStringValue("unlimitedStorage")); | 97 list->Append(Value::CreateStringValue("unlimitedStorage")); |
| 94 list->Append(Value::CreateStringValue("fileSystem")); | 98 list->Append(Value::CreateStringValue("fileSystem")); |
| 95 list->Append(Value::CreateStringValue("fileBrowserPrivate")); | 99 list->Append(Value::CreateStringValue("fileBrowserPrivate")); |
| 96 manifest.Set(keys::kPermissions, list); | 100 manifest.Set(keys::kPermissions, list); |
| 97 std::string error; | 101 std::string error; |
| 98 scoped_refptr<Extension> component_app = Extension::Create( | 102 scoped_refptr<Extension> component_app = Extension::Create( |
| 99 path, Extension::COMPONENT, manifest, Extension::NO_FLAGS, &error); | 103 path, Manifest::COMPONENT, manifest, Extension::NO_FLAGS, &error); |
| 100 EXPECT_TRUE(component_app.get()) << error; | 104 EXPECT_TRUE(component_app.get()) << error; |
| 101 return component_app; | 105 return component_app; |
| 102 } | 106 } |
| 103 | 107 |
| 104 scoped_refptr<Extension> CreateHandlerApp() { | 108 scoped_refptr<Extension> CreateHandlerApp() { |
| 105 #if defined(OS_WIN) | 109 #if defined(OS_WIN) |
| 106 FilePath path(FILE_PATH_LITERAL("c:\\handler")); | 110 FilePath path(FILE_PATH_LITERAL("c:\\handler")); |
| 107 #elif defined(OS_POSIX) | 111 #elif defined(OS_POSIX) |
| 108 FilePath path(FILE_PATH_LITERAL("/handler")); | 112 FilePath path(FILE_PATH_LITERAL("/handler")); |
| 109 #endif | 113 #endif |
| 110 DictionaryValue manifest; | 114 DictionaryValue manifest; |
| 111 manifest.SetString(keys::kName, "Handler"); | 115 manifest.SetString(keys::kName, "Handler"); |
| 112 manifest.SetString(keys::kVersion, "1"); | 116 manifest.SetString(keys::kVersion, "1"); |
| 113 manifest.SetString(keys::kPublicKey, | 117 manifest.SetString(keys::kPublicKey, |
| 114 "MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQChptAQ0n4R56N03nWQ1ogR7DVRBjGo" \ | 118 "MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQChptAQ0n4R56N03nWQ1ogR7DVRBjGo" \ |
| 115 "80Vw6G9KLjzZv44D8rq5Q5IkeQrtKgWyZfXevlsCe3LaLo18rcz8iZx6lK2xhLdUR+OR" \ | 119 "80Vw6G9KLjzZv44D8rq5Q5IkeQrtKgWyZfXevlsCe3LaLo18rcz8iZx6lK2xhLdUR+OR" \ |
| 116 "jsjuBfdEL5a5cWeRTSxf75AcqndQsmpwMBdrMTCZ8jQNusUI+XlrihLNNJuI5TM4vNIN" \ | 120 "jsjuBfdEL5a5cWeRTSxf75AcqndQsmpwMBdrMTCZ8jQNusUI+XlrihLNNJuI5TM4vNIN" \ |
| 117 "I5bYFQIBIw=="); | 121 "I5bYFQIBIw=="); |
| 118 ListValue* list = new ListValue(); | 122 ListValue* list = new ListValue(); |
| 119 list->Append(Value::CreateStringValue("unlimitedStorage")); | 123 list->Append(Value::CreateStringValue("unlimitedStorage")); |
| 120 list->Append(Value::CreateStringValue("fileSystem")); | 124 list->Append(Value::CreateStringValue("fileSystem")); |
| 121 manifest.Set(keys::kPermissions, list); | 125 manifest.Set(keys::kPermissions, list); |
| 122 std::string error; | 126 std::string error; |
| 123 scoped_refptr<Extension> handler_app = Extension::Create( | 127 scoped_refptr<Extension> handler_app = Extension::Create( |
| 124 path, Extension::INVALID, manifest, Extension::NO_FLAGS, &error); | 128 path, Manifest::INVALID_LOCATION, manifest, |
| 129 Extension::NO_FLAGS, &error); |
| 125 EXPECT_TRUE(handler_app.get()) << error; | 130 EXPECT_TRUE(handler_app.get()) << error; |
| 126 return handler_app; | 131 return handler_app; |
| 127 } | 132 } |
| 128 | 133 |
| 129 scoped_refptr<Extension> CreateWebIntentViewApp() { | 134 scoped_refptr<Extension> CreateWebIntentViewApp() { |
| 130 #if defined(OS_WIN) | 135 #if defined(OS_WIN) |
| 131 FilePath path(FILE_PATH_LITERAL("c:\\bar")); | 136 FilePath path(FILE_PATH_LITERAL("c:\\bar")); |
| 132 #elif defined(OS_POSIX) | 137 #elif defined(OS_POSIX) |
| 133 FilePath path(FILE_PATH_LITERAL("/bar")); | 138 FilePath path(FILE_PATH_LITERAL("/bar")); |
| 134 #endif | 139 #endif |
| (...skipping 12 matching lines...) Expand all Loading... |
| 147 ListValue* view_intent_list = new ListValue; | 152 ListValue* view_intent_list = new ListValue; |
| 148 view_intent_list->Append(view_intent); | 153 view_intent_list->Append(view_intent); |
| 149 | 154 |
| 150 DictionaryValue* intents = new DictionaryValue; | 155 DictionaryValue* intents = new DictionaryValue; |
| 151 intents->SetWithoutPathExpansion("http://webintents.org/view", | 156 intents->SetWithoutPathExpansion("http://webintents.org/view", |
| 152 view_intent_list); | 157 view_intent_list); |
| 153 manifest.Set(keys::kIntents, intents); | 158 manifest.Set(keys::kIntents, intents); |
| 154 | 159 |
| 155 std::string error; | 160 std::string error; |
| 156 scoped_refptr<Extension> intent_app = Extension::Create( | 161 scoped_refptr<Extension> intent_app = Extension::Create( |
| 157 path, Extension::INVALID, manifest, Extension::NO_FLAGS, &error); | 162 path, Manifest::INVALID_LOCATION, manifest, |
| 163 Extension::NO_FLAGS, &error); |
| 158 EXPECT_TRUE(intent_app.get()) << error; | 164 EXPECT_TRUE(intent_app.get()) << error; |
| 159 return intent_app; | 165 return intent_app; |
| 160 } | 166 } |
| 161 | 167 |
| 162 // Verifies that the set of extensions protecting |url| is *exactly* equal to | 168 // Verifies that the set of extensions protecting |url| is *exactly* equal to |
| 163 // |expected_extensions|. Pass in an empty set to verify that an origin is not | 169 // |expected_extensions|. Pass in an empty set to verify that an origin is not |
| 164 // protected. | 170 // protected. |
| 165 void ExpectProtectedBy(const ExtensionSet& expected_extensions, | 171 void ExpectProtectedBy(const ExtensionSet& expected_extensions, |
| 166 const GURL& url) { | 172 const GURL& url) { |
| 167 const ExtensionSet* extensions = policy_->ExtensionsProtectingOrigin(url); | 173 const ExtensionSet* extensions = policy_->ExtensionsProtectingOrigin(url); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 CONTENT_SETTING_SESSION_ONLY); | 323 CONTENT_SETTING_SESSION_ONLY); |
| 318 | 324 |
| 319 EXPECT_TRUE(policy_->HasSessionOnlyOrigins()); | 325 EXPECT_TRUE(policy_->HasSessionOnlyOrigins()); |
| 320 | 326 |
| 321 // Clearing an origin-specific rule. | 327 // Clearing an origin-specific rule. |
| 322 cookie_settings->ResetCookieSetting(pattern, | 328 cookie_settings->ResetCookieSetting(pattern, |
| 323 ContentSettingsPattern::Wildcard()); | 329 ContentSettingsPattern::Wildcard()); |
| 324 | 330 |
| 325 EXPECT_FALSE(policy_->HasSessionOnlyOrigins()); | 331 EXPECT_FALSE(policy_->HasSessionOnlyOrigins()); |
| 326 } | 332 } |
| OLD | NEW |