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

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

Issue 16625012: Remove ExtensionURLInfo, make security decisions in render process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address feedback Created 7 years, 5 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/json/json_file_value_serializer.h" 5 #include "base/json/json_file_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 "chrome/common/extensions/extension_manifest_constants.h" 11 #include "chrome/common/extensions/extension_manifest_constants.h"
12 #include "content/public/test/test_browser_thread.h" 12 #include "content/public/test/test_browser_thread.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/WebKit/public/platform/WebString.h"
15 #include "third_party/WebKit/public/platform/WebURL.h"
16 14
17 using content::BrowserThread; 15 using content::BrowserThread;
18 using extensions::APIPermission; 16 using extensions::APIPermission;
19 using extensions::Extension; 17 using extensions::Extension;
20 using extensions::Manifest; 18 using extensions::Manifest;
21 using WebKit::WebSecurityOrigin;
22 using WebKit::WebString;
23 19
24 namespace keys = extension_manifest_keys; 20 namespace keys = extension_manifest_keys;
25 21
26 namespace { 22 namespace {
27 23
28 class ExtensionInfoMapTest : public testing::Test { 24 class ExtensionInfoMapTest : public testing::Test {
29 public: 25 public:
30 ExtensionInfoMapTest() 26 ExtensionInfoMapTest()
31 : ui_thread_(BrowserThread::UI, &message_loop_), 27 : ui_thread_(BrowserThread::UI, &message_loop_),
32 io_thread_(BrowserThread::IO, &message_loop_) { 28 io_thread_(BrowserThread::IO, &message_loop_) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 // Tests CheckURLAccessToExtensionPermission given both extension and app URLs. 128 // Tests CheckURLAccessToExtensionPermission given both extension and app URLs.
133 TEST_F(ExtensionInfoMapTest, CheckPermissions) { 129 TEST_F(ExtensionInfoMapTest, CheckPermissions) {
134 scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap()); 130 scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap());
135 131
136 scoped_refptr<Extension> app(LoadManifest("manifest_tests", 132 scoped_refptr<Extension> app(LoadManifest("manifest_tests",
137 "valid_app.json")); 133 "valid_app.json"));
138 scoped_refptr<Extension> extension(LoadManifest("manifest_tests", 134 scoped_refptr<Extension> extension(LoadManifest("manifest_tests",
139 "tabs_extension.json")); 135 "tabs_extension.json"));
140 136
141 GURL app_url("http://www.google.com/mail/foo.html"); 137 GURL app_url("http://www.google.com/mail/foo.html");
142 WebSecurityOrigin app_origin = WebSecurityOrigin::create(
143 GURL("http://www.google.com/mail/foo.html"));
144 ASSERT_TRUE(app->is_app()); 138 ASSERT_TRUE(app->is_app());
145 ASSERT_TRUE(app->web_extent().MatchesURL(app_url)); 139 ASSERT_TRUE(app->web_extent().MatchesURL(app_url));
146 140
147 info_map->AddExtension(app.get(), base::Time(), false); 141 info_map->AddExtension(app.get(), base::Time(), false);
148 info_map->AddExtension(extension.get(), base::Time(), false); 142 info_map->AddExtension(extension.get(), base::Time(), false);
149 143
150 // The app should have the notifications permission, either from a 144 // The app should have the notifications permission, either from a
151 // chrome-extension URL or from its web extent. 145 // chrome-extension URL or from its web extent.
152 const Extension* match = info_map->extensions().GetExtensionOrAppByURL( 146 const Extension* match = info_map->extensions().GetExtensionOrAppByURL(
153 ExtensionURLInfo(app_origin, app->GetResourceURL("a.html"))); 147 app->GetResourceURL("a.html"));
154 EXPECT_TRUE(match && 148 EXPECT_TRUE(match &&
155 match->HasAPIPermission(APIPermission::kNotification)); 149 match->HasAPIPermission(APIPermission::kNotification));
156 match = info_map->extensions().GetExtensionOrAppByURL( 150 match = info_map->extensions().GetExtensionOrAppByURL(app_url);
157 ExtensionURLInfo(app_origin, app_url));
158 EXPECT_TRUE(match && 151 EXPECT_TRUE(match &&
159 match->HasAPIPermission(APIPermission::kNotification)); 152 match->HasAPIPermission(APIPermission::kNotification));
160 EXPECT_FALSE(match && 153 EXPECT_FALSE(match &&
161 match->HasAPIPermission(APIPermission::kTab)); 154 match->HasAPIPermission(APIPermission::kTab));
162 155
163 // The extension should have the tabs permission. 156 // The extension should have the tabs permission.
164 match = info_map->extensions().GetExtensionOrAppByURL( 157 match = info_map->extensions().GetExtensionOrAppByURL(
165 ExtensionURLInfo(app_origin, extension->GetResourceURL("a.html"))); 158 extension->GetResourceURL("a.html"));
166 EXPECT_TRUE(match && 159 EXPECT_TRUE(match &&
167 match->HasAPIPermission(APIPermission::kTab)); 160 match->HasAPIPermission(APIPermission::kTab));
168 EXPECT_FALSE(match && 161 EXPECT_FALSE(match &&
169 match->HasAPIPermission(APIPermission::kNotification)); 162 match->HasAPIPermission(APIPermission::kNotification));
170 163
171 // Random URL should not have any permissions. 164 // Random URL should not have any permissions.
172 GURL evil_url("http://evil.com/a.html"); 165 GURL evil_url("http://evil.com/a.html");
173 match = info_map->extensions().GetExtensionOrAppByURL( 166 match = info_map->extensions().GetExtensionOrAppByURL(evil_url);
174 ExtensionURLInfo(WebSecurityOrigin::create(evil_url), evil_url));
175 EXPECT_FALSE(match);
176
177 // Sandboxed origins should not have any permissions.
178 match = info_map->extensions().GetExtensionOrAppByURL(ExtensionURLInfo(
179 WebSecurityOrigin::createFromString(WebString::fromUTF8("null")),
180 app_url));
181 EXPECT_FALSE(match); 167 EXPECT_FALSE(match);
182 } 168 }
183 169
184 } // namespace 170 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_function_dispatcher.cc ('k') | chrome/browser/extensions/extension_process_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698