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

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

Issue 8659009: Consider the origin when computing extension permissions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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
« no previous file with comments | « no previous file | chrome/common/extensions/extension_set.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/json/json_value_serializer.h" 5 #include "base/json/json_value_serializer.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "chrome/browser/extensions/extension_info_map.h" 8 #include "chrome/browser/extensions/extension_info_map.h"
9 #include "chrome/common/chrome_paths.h" 9 #include "chrome/common/chrome_paths.h"
10 #include "chrome/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
11 #include "content/test/test_browser_thread.h" 11 #include "content/test/test_browser_thread.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
13 15
14 using content::BrowserThread; 16 using content::BrowserThread;
17 using WebKit::WebSecurityOrigin;
18 using WebKit::WebString;
15 19
16 namespace keys = extension_manifest_keys; 20 namespace keys = extension_manifest_keys;
17 21
18 namespace { 22 namespace {
19 23
20 class ExtensionInfoMapTest : public testing::Test { 24 class ExtensionInfoMapTest : public testing::Test {
21 public: 25 public:
22 ExtensionInfoMapTest() 26 ExtensionInfoMapTest()
23 : ui_thread_(BrowserThread::UI, &message_loop_), 27 : ui_thread_(BrowserThread::UI, &message_loop_),
24 io_thread_(BrowserThread::IO, &message_loop_) { 28 io_thread_(BrowserThread::IO, &message_loop_) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // Tests CheckURLAccessToExtensionPermission given both extension and app URLs. 127 // Tests CheckURLAccessToExtensionPermission given both extension and app URLs.
124 TEST_F(ExtensionInfoMapTest, CheckPermissions) { 128 TEST_F(ExtensionInfoMapTest, CheckPermissions) {
125 scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap()); 129 scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap());
126 130
127 scoped_refptr<Extension> app(LoadManifest("manifest_tests", 131 scoped_refptr<Extension> app(LoadManifest("manifest_tests",
128 "valid_app.json")); 132 "valid_app.json"));
129 scoped_refptr<Extension> extension(LoadManifest("manifest_tests", 133 scoped_refptr<Extension> extension(LoadManifest("manifest_tests",
130 "tabs_extension.json")); 134 "tabs_extension.json"));
131 135
132 GURL app_url("http://www.google.com/mail/foo.html"); 136 GURL app_url("http://www.google.com/mail/foo.html");
137 WebSecurityOrigin app_origin = WebSecurityOrigin::create(
138 GURL("http://www.google.com/mail/foo.html"));
133 ASSERT_TRUE(app->is_app()); 139 ASSERT_TRUE(app->is_app());
134 ASSERT_TRUE(app->web_extent().MatchesURL(app_url)); 140 ASSERT_TRUE(app->web_extent().MatchesURL(app_url));
135 141
136 info_map->AddExtension(app, base::Time(), false); 142 info_map->AddExtension(app, base::Time(), false);
137 info_map->AddExtension(extension, base::Time(), false); 143 info_map->AddExtension(extension, base::Time(), false);
138 144
139 // The app should have the notifications permission, either from a 145 // The app should have the notifications permission, either from a
140 // chrome-extension URL or from its web extent. 146 // chrome-extension URL or from its web extent.
141 const Extension* match = info_map->extensions().GetByURL( 147 const Extension* match = info_map->extensions().GetByURL(
142 app->GetResourceURL("a.html")); 148 ExtensionURLInfo(app_origin, app->GetResourceURL("a.html")));
143 EXPECT_TRUE(match && 149 EXPECT_TRUE(match &&
144 match->HasAPIPermission(ExtensionAPIPermission::kNotification)); 150 match->HasAPIPermission(ExtensionAPIPermission::kNotification));
145 match = info_map->extensions().GetByURL(app_url); 151 match = info_map->extensions().GetByURL(
152 ExtensionURLInfo(app_origin, app_url));
146 EXPECT_TRUE(match && 153 EXPECT_TRUE(match &&
147 match->HasAPIPermission(ExtensionAPIPermission::kNotification)); 154 match->HasAPIPermission(ExtensionAPIPermission::kNotification));
148 EXPECT_FALSE(match && 155 EXPECT_FALSE(match &&
149 match->HasAPIPermission(ExtensionAPIPermission::kTab)); 156 match->HasAPIPermission(ExtensionAPIPermission::kTab));
150 157
151 // The extension should have the tabs permission. 158 // The extension should have the tabs permission.
152 match = info_map->extensions().GetByURL(extension->GetResourceURL("a.html")); 159 match = info_map->extensions().GetByURL(
160 ExtensionURLInfo(app_origin, extension->GetResourceURL("a.html")));
153 EXPECT_TRUE(match && 161 EXPECT_TRUE(match &&
154 match->HasAPIPermission(ExtensionAPIPermission::kTab)); 162 match->HasAPIPermission(ExtensionAPIPermission::kTab));
155 EXPECT_FALSE(match && 163 EXPECT_FALSE(match &&
156 match->HasAPIPermission(ExtensionAPIPermission::kNotification)); 164 match->HasAPIPermission(ExtensionAPIPermission::kNotification));
157 165
158 // Random URL should not have any permissions. 166 // Random URL should not have any permissions.
159 match = info_map->extensions().GetByURL(GURL("http://evil.com/a.html")); 167 GURL evil_url("http://evil.com/a.html");
168 match = info_map->extensions().GetByURL(
169 ExtensionURLInfo(WebSecurityOrigin::create(evil_url), evil_url));
170 EXPECT_FALSE(match);
171
172 // Sandboxed origins should not have any permissions.
173 match = info_map->extensions().GetByURL(ExtensionURLInfo(
174 WebSecurityOrigin::createFromString(WebString::fromUTF8("null")),
175 app_url));
160 EXPECT_FALSE(match); 176 EXPECT_FALSE(match);
161 } 177 }
162 178
163 } // namespace 179 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/extension_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698