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

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

Issue 12225076: Delete most web intents code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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 | Annotate | Revision Log
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 "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"
16 #include "chrome/test/base/testing_profile.h" 15 #include "chrome/test/base/testing_profile.h"
17 #include "content/public/test/test_browser_thread.h" 16 #include "content/public/test/test_browser_thread.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 18
20 using content::BrowserThread; 19 using content::BrowserThread;
21 using extensions::Extension; 20 using extensions::Extension;
22 using extensions::Manifest; 21 using extensions::Manifest;
23 22
24 namespace keys = extension_manifest_keys; 23 namespace keys = extension_manifest_keys;
25 24
26 class ExtensionSpecialStoragePolicyTest : public testing::Test { 25 class ExtensionSpecialStoragePolicyTest : public testing::Test {
27 public: 26 public:
28 virtual void SetUp() { 27 virtual void SetUp() {
29 policy_ = new ExtensionSpecialStoragePolicy(NULL); 28 policy_ = new ExtensionSpecialStoragePolicy(NULL);
30 #if defined(ENABLE_WEB_INTENTS)
31 extensions::ManifestHandler::Register(
32 keys::kIntents,
33 make_linked_ptr(new extensions::WebIntentsHandler));
34 #endif
35 } 29 }
36 30
37 protected: 31 protected:
38 scoped_refptr<Extension> CreateProtectedApp() { 32 scoped_refptr<Extension> CreateProtectedApp() {
39 #if defined(OS_WIN) 33 #if defined(OS_WIN)
40 base::FilePath path(FILE_PATH_LITERAL("c:\\foo")); 34 base::FilePath path(FILE_PATH_LITERAL("c:\\foo"));
41 #elif defined(OS_POSIX) 35 #elif defined(OS_POSIX)
42 base::FilePath path(FILE_PATH_LITERAL("/foo")); 36 base::FilePath path(FILE_PATH_LITERAL("/foo"));
43 #endif 37 #endif
44 DictionaryValue manifest; 38 DictionaryValue manifest;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 list->Append(Value::CreateStringValue("fileSystem")); 121 list->Append(Value::CreateStringValue("fileSystem"));
128 manifest.Set(keys::kPermissions, list); 122 manifest.Set(keys::kPermissions, list);
129 std::string error; 123 std::string error;
130 scoped_refptr<Extension> handler_app = Extension::Create( 124 scoped_refptr<Extension> handler_app = Extension::Create(
131 path, Manifest::INVALID_LOCATION, manifest, 125 path, Manifest::INVALID_LOCATION, manifest,
132 Extension::NO_FLAGS, &error); 126 Extension::NO_FLAGS, &error);
133 EXPECT_TRUE(handler_app.get()) << error; 127 EXPECT_TRUE(handler_app.get()) << error;
134 return handler_app; 128 return handler_app;
135 } 129 }
136 130
137 #if defined(ENABLE_WEB_INTENTS)
138 scoped_refptr<Extension> CreateWebIntentViewApp() {
139 #if defined(OS_WIN)
140 base::FilePath path(FILE_PATH_LITERAL("c:\\bar"));
141 #elif defined(OS_POSIX)
142 base::FilePath path(FILE_PATH_LITERAL("/bar"));
143 #endif
144 DictionaryValue manifest;
145 manifest.SetString(keys::kName, "WebIntent");
146 manifest.SetString(keys::kVersion, "1");
147 manifest.SetString(keys::kLaunchWebURL, "http://explicit/unlimited/start");
148
149 ListValue* view_intent_types = new ListValue;
150 view_intent_types->Append(Value::CreateStringValue("text/plain"));
151
152 DictionaryValue* view_intent = new DictionaryValue;
153 view_intent->SetString(keys::kIntentTitle, "Test Intent");
154 view_intent->Set(keys::kIntentType, view_intent_types);
155
156 ListValue* view_intent_list = new ListValue;
157 view_intent_list->Append(view_intent);
158
159 DictionaryValue* intents = new DictionaryValue;
160 intents->SetWithoutPathExpansion("http://webintents.org/view",
161 view_intent_list);
162 manifest.Set(keys::kIntents, intents);
163
164 std::string error;
165 scoped_refptr<Extension> intent_app = Extension::Create(
166 path, Manifest::INVALID_LOCATION, manifest,
167 Extension::NO_FLAGS, &error);
168 EXPECT_TRUE(intent_app.get()) << error;
169 return intent_app;
170 }
171 #endif
172
173 // Verifies that the set of extensions protecting |url| is *exactly* equal to 131 // Verifies that the set of extensions protecting |url| is *exactly* equal to
174 // |expected_extensions|. Pass in an empty set to verify that an origin is not 132 // |expected_extensions|. Pass in an empty set to verify that an origin is not
175 // protected. 133 // protected.
176 void ExpectProtectedBy(const ExtensionSet& expected_extensions, 134 void ExpectProtectedBy(const ExtensionSet& expected_extensions,
177 const GURL& url) { 135 const GURL& url) {
178 const ExtensionSet* extensions = policy_->ExtensionsProtectingOrigin(url); 136 const ExtensionSet* extensions = policy_->ExtensionsProtectingOrigin(url);
179 EXPECT_EQ(expected_extensions.size(), extensions->size()); 137 EXPECT_EQ(expected_extensions.size(), extensions->size());
180 for (ExtensionSet::const_iterator it = expected_extensions.begin(); 138 for (ExtensionSet::const_iterator it = expected_extensions.begin();
181 it != expected_extensions.end(); ++it) { 139 it != expected_extensions.end(); ++it) {
182 EXPECT_TRUE(extensions->Contains((*it)->id())) 140 EXPECT_TRUE(extensions->Contains((*it)->id()))
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/")); 242 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/"));
285 ExpectProtectedBy(protecting_extensions, GURL("http://foo.wildcards/")); 243 ExpectProtectedBy(protecting_extensions, GURL("http://foo.wildcards/"));
286 ExpectProtectedBy(protecting_extensions, GURL("https://bar.wildcards/")); 244 ExpectProtectedBy(protecting_extensions, GURL("https://bar.wildcards/"));
287 245
288 policy_->RevokeRightsForExtension(protected_app); 246 policy_->RevokeRightsForExtension(protected_app);
289 ExpectProtectedBy(empty_set, GURL("http://explicit/")); 247 ExpectProtectedBy(empty_set, GURL("http://explicit/"));
290 ExpectProtectedBy(empty_set, GURL("http://foo.wildcards/")); 248 ExpectProtectedBy(empty_set, GURL("http://foo.wildcards/"));
291 ExpectProtectedBy(empty_set, GURL("https://bar.wildcards/")); 249 ExpectProtectedBy(empty_set, GURL("https://bar.wildcards/"));
292 } 250 }
293 251
294 TEST_F(ExtensionSpecialStoragePolicyTest, WebIntentViewApp) {
295 #if defined(ENABLE_WEB_INTENTS)
296 scoped_refptr<Extension> intent_app(CreateWebIntentViewApp());
297
298 policy_->GrantRightsForExtension(intent_app);
299 EXPECT_TRUE(policy_->IsFileHandler(intent_app->id()));
300
301 policy_->RevokeRightsForExtension(intent_app);
302 EXPECT_FALSE(policy_->IsFileHandler(intent_app->id()));
303 #endif
304 }
305
306 TEST_F(ExtensionSpecialStoragePolicyTest, HasSessionOnlyOrigins) { 252 TEST_F(ExtensionSpecialStoragePolicyTest, HasSessionOnlyOrigins) {
307 MessageLoop message_loop; 253 MessageLoop message_loop;
308 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 254 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
309 255
310 TestingProfile profile; 256 TestingProfile profile;
311 CookieSettings* cookie_settings = 257 CookieSettings* cookie_settings =
312 CookieSettings::Factory::GetForProfile(&profile); 258 CookieSettings::Factory::GetForProfile(&profile);
313 policy_ = new ExtensionSpecialStoragePolicy(cookie_settings); 259 policy_ = new ExtensionSpecialStoragePolicy(cookie_settings);
314 260
315 EXPECT_FALSE(policy_->HasSessionOnlyOrigins()); 261 EXPECT_FALSE(policy_->HasSessionOnlyOrigins());
(...skipping 14 matching lines...) Expand all
330 CONTENT_SETTING_SESSION_ONLY); 276 CONTENT_SETTING_SESSION_ONLY);
331 277
332 EXPECT_TRUE(policy_->HasSessionOnlyOrigins()); 278 EXPECT_TRUE(policy_->HasSessionOnlyOrigins());
333 279
334 // Clearing an origin-specific rule. 280 // Clearing an origin-specific rule.
335 cookie_settings->ResetCookieSetting(pattern, 281 cookie_settings->ResetCookieSetting(pattern,
336 ContentSettingsPattern::Wildcard()); 282 ContentSettingsPattern::Wildcard());
337 283
338 EXPECT_FALSE(policy_->HasSessionOnlyOrigins()); 284 EXPECT_FALSE(policy_->HasSessionOnlyOrigins());
339 } 285 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_special_storage_policy.cc ('k') | chrome/browser/extensions/platform_app_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698