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

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

Issue 10675007: Move each permission classes to its own files in extensions/permissions (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase again Created 8 years, 6 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
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/Source/WebKit/chromium/public/platform/WebString.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
16 16
17 using content::BrowserThread; 17 using content::BrowserThread;
18 using extensions::APIPermission;
18 using extensions::Extension; 19 using extensions::Extension;
19 using WebKit::WebSecurityOrigin; 20 using WebKit::WebSecurityOrigin;
20 using WebKit::WebString; 21 using WebKit::WebString;
21 22
22 namespace keys = extension_manifest_keys; 23 namespace keys = extension_manifest_keys;
23 24
24 namespace { 25 namespace {
25 26
26 class ExtensionInfoMapTest : public testing::Test { 27 class ExtensionInfoMapTest : public testing::Test {
27 public: 28 public:
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 ASSERT_TRUE(app->web_extent().MatchesURL(app_url)); 143 ASSERT_TRUE(app->web_extent().MatchesURL(app_url));
143 144
144 info_map->AddExtension(app, base::Time(), false); 145 info_map->AddExtension(app, base::Time(), false);
145 info_map->AddExtension(extension, base::Time(), false); 146 info_map->AddExtension(extension, base::Time(), false);
146 147
147 // The app should have the notifications permission, either from a 148 // The app should have the notifications permission, either from a
148 // chrome-extension URL or from its web extent. 149 // chrome-extension URL or from its web extent.
149 const Extension* match = info_map->extensions().GetExtensionOrAppByURL( 150 const Extension* match = info_map->extensions().GetExtensionOrAppByURL(
150 ExtensionURLInfo(app_origin, app->GetResourceURL("a.html"))); 151 ExtensionURLInfo(app_origin, app->GetResourceURL("a.html")));
151 EXPECT_TRUE(match && 152 EXPECT_TRUE(match &&
152 match->HasAPIPermission(ExtensionAPIPermission::kNotification)); 153 match->HasAPIPermission(APIPermission::kNotification));
153 match = info_map->extensions().GetExtensionOrAppByURL( 154 match = info_map->extensions().GetExtensionOrAppByURL(
154 ExtensionURLInfo(app_origin, app_url)); 155 ExtensionURLInfo(app_origin, app_url));
155 EXPECT_TRUE(match && 156 EXPECT_TRUE(match &&
156 match->HasAPIPermission(ExtensionAPIPermission::kNotification)); 157 match->HasAPIPermission(APIPermission::kNotification));
157 EXPECT_FALSE(match && 158 EXPECT_FALSE(match &&
158 match->HasAPIPermission(ExtensionAPIPermission::kTab)); 159 match->HasAPIPermission(APIPermission::kTab));
159 160
160 // The extension should have the tabs permission. 161 // The extension should have the tabs permission.
161 match = info_map->extensions().GetExtensionOrAppByURL( 162 match = info_map->extensions().GetExtensionOrAppByURL(
162 ExtensionURLInfo(app_origin, extension->GetResourceURL("a.html"))); 163 ExtensionURLInfo(app_origin, extension->GetResourceURL("a.html")));
163 EXPECT_TRUE(match && 164 EXPECT_TRUE(match &&
164 match->HasAPIPermission(ExtensionAPIPermission::kTab)); 165 match->HasAPIPermission(APIPermission::kTab));
165 EXPECT_FALSE(match && 166 EXPECT_FALSE(match &&
166 match->HasAPIPermission(ExtensionAPIPermission::kNotification)); 167 match->HasAPIPermission(APIPermission::kNotification));
167 168
168 // Random URL should not have any permissions. 169 // Random URL should not have any permissions.
169 GURL evil_url("http://evil.com/a.html"); 170 GURL evil_url("http://evil.com/a.html");
170 match = info_map->extensions().GetExtensionOrAppByURL( 171 match = info_map->extensions().GetExtensionOrAppByURL(
171 ExtensionURLInfo(WebSecurityOrigin::create(evil_url), evil_url)); 172 ExtensionURLInfo(WebSecurityOrigin::create(evil_url), evil_url));
172 EXPECT_FALSE(match); 173 EXPECT_FALSE(match);
173 174
174 // Sandboxed origins should not have any permissions. 175 // Sandboxed origins should not have any permissions.
175 match = info_map->extensions().GetExtensionOrAppByURL(ExtensionURLInfo( 176 match = info_map->extensions().GetExtensionOrAppByURL(ExtensionURLInfo(
176 WebSecurityOrigin::createFromString(WebString::fromUTF8("null")), 177 WebSecurityOrigin::createFromString(WebString::fromUTF8("null")),
177 app_url)); 178 app_url));
178 EXPECT_FALSE(match); 179 EXPECT_FALSE(match);
179 } 180 }
180 181
181 } // namespace 182 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_info_map.cc ('k') | chrome/browser/extensions/extension_install_prompt.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698