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

Side by Side Diff: chrome/common/extensions/extension_unittest.cc

Issue 14694010: Consolidate manifest handler registration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chrome/common/extensions/extension_unittest.h"
6
7 #include "base/command_line.h" 5 #include "base/command_line.h"
8 #include "base/file_util.h" 6 #include "base/file_util.h"
9 #include "base/format_macros.h" 7 #include "base/format_macros.h"
10 #include "base/path_service.h" 8 #include "base/path_service.h"
11 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
12 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
13 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
14 #include "chrome/common/chrome_paths.h" 12 #include "chrome/common/chrome_paths.h"
15 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
17 #include "chrome/common/extensions/background_info.h"
18 #include "chrome/common/extensions/command.h" 14 #include "chrome/common/extensions/command.h"
19 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/extensions/extension_file_util.h" 16 #include "chrome/common/extensions/extension_file_util.h"
21 #include "chrome/common/extensions/extension_manifest_constants.h" 17 #include "chrome/common/extensions/extension_manifest_constants.h"
22 #include "chrome/common/extensions/extension_test_util.h" 18 #include "chrome/common/extensions/extension_test_util.h"
23 #include "chrome/common/extensions/features/feature.h" 19 #include "chrome/common/extensions/features/feature.h"
24 #include "chrome/common/extensions/incognito_handler.h"
25 #include "chrome/common/extensions/manifest.h" 20 #include "chrome/common/extensions/manifest.h"
26 #include "chrome/common/extensions/manifest_handler.h"
27 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" 21 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
28 #include "chrome/common/extensions/permissions/api_permission.h" 22 #include "chrome/common/extensions/permissions/api_permission.h"
29 #include "chrome/common/extensions/permissions/chrome_api_permissions.h"
30 #include "chrome/common/extensions/permissions/permission_set.h" 23 #include "chrome/common/extensions/permissions/permission_set.h"
31 #include "chrome/common/extensions/permissions/scoped_testing_permissions_info.h "
32 #include "chrome/common/extensions/permissions/socket_permission.h" 24 #include "chrome/common/extensions/permissions/socket_permission.h"
33 #include "chrome/common/extensions/permissions/usb_device_permission.h" 25 #include "chrome/common/extensions/permissions/usb_device_permission.h"
34 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
35 #include "extensions/common/error_utils.h" 27 #include "extensions/common/error_utils.h"
36 #include "extensions/common/extension_resource.h" 28 #include "extensions/common/extension_resource.h"
37 #include "extensions/common/id_util.h" 29 #include "extensions/common/id_util.h"
38 #include "googleurl/src/gurl.h" 30 #include "googleurl/src/gurl.h"
39 #include "net/base/mime_sniffer.h" 31 #include "net/base/mime_sniffer.h"
40 #include "net/dns/mock_host_resolver.h" 32 #include "net/dns/mock_host_resolver.h"
41 #include "skia/ext/image_operations.h" 33 #include "skia/ext/image_operations.h"
42 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
43 #include "third_party/skia/include/core/SkBitmap.h" 35 #include "third_party/skia/include/core/SkBitmap.h"
44 #include "ui/gfx/codec/png_codec.h" 36 #include "ui/gfx/codec/png_codec.h"
45 37
46 using content::SocketPermissionRequest; 38 using content::SocketPermissionRequest;
47 using extension_test_util::LoadManifest; 39 using extension_test_util::LoadManifest;
48 using extension_test_util::LoadManifestUnchecked; 40 using extension_test_util::LoadManifestUnchecked;
49 using extension_test_util::LoadManifestStrict; 41 using extension_test_util::LoadManifestStrict;
50 42
51 namespace keys = extension_manifest_keys; 43 namespace keys = extension_manifest_keys;
52 namespace values = extension_manifest_values; 44 namespace values = extension_manifest_values;
53 namespace errors = extension_manifest_errors; 45 namespace errors = extension_manifest_errors;
54 46
55 namespace extensions { 47 namespace extensions {
56 48
57 ExtensionTest::ExtensionTest() : permissions_info_(ChromeAPIPermissions()) {}
58
59 void ExtensionTest::SetUp() {
60 testing::Test::SetUp();
61 (new BackgroundManifestHandler)->Register();
62 // We need the IncognitoHandler registered for all tests, since
63 // Extension uses it in Extension::CheckPlatformAppFeatures() as part of the
64 // creation process.
65 (new IncognitoHandler)->Register();
66 }
67
68 void ExtensionTest::TearDown() {
69 ManifestHandler::ClearRegistryForTesting();
70 testing::Test::TearDown();
71 }
72
73 // We persist location values in the preferences, so this is a sanity test that 49 // We persist location values in the preferences, so this is a sanity test that
74 // someone doesn't accidentally change them. 50 // someone doesn't accidentally change them.
75 TEST_F(ExtensionTest, LocationValuesTest) { 51 TEST(ExtensionTest, LocationValuesTest) {
76 ASSERT_EQ(0, Manifest::INVALID_LOCATION); 52 ASSERT_EQ(0, Manifest::INVALID_LOCATION);
77 ASSERT_EQ(1, Manifest::INTERNAL); 53 ASSERT_EQ(1, Manifest::INTERNAL);
78 ASSERT_EQ(2, Manifest::EXTERNAL_PREF); 54 ASSERT_EQ(2, Manifest::EXTERNAL_PREF);
79 ASSERT_EQ(3, Manifest::EXTERNAL_REGISTRY); 55 ASSERT_EQ(3, Manifest::EXTERNAL_REGISTRY);
80 ASSERT_EQ(4, Manifest::UNPACKED); 56 ASSERT_EQ(4, Manifest::UNPACKED);
81 ASSERT_EQ(5, Manifest::COMPONENT); 57 ASSERT_EQ(5, Manifest::COMPONENT);
82 ASSERT_EQ(6, Manifest::EXTERNAL_PREF_DOWNLOAD); 58 ASSERT_EQ(6, Manifest::EXTERNAL_PREF_DOWNLOAD);
83 ASSERT_EQ(7, Manifest::EXTERNAL_POLICY_DOWNLOAD); 59 ASSERT_EQ(7, Manifest::EXTERNAL_POLICY_DOWNLOAD);
84 ASSERT_EQ(8, Manifest::COMMAND_LINE); 60 ASSERT_EQ(8, Manifest::COMMAND_LINE);
85 } 61 }
86 62
87 TEST_F(ExtensionTest, LocationPriorityTest) { 63 TEST(ExtensionTest, LocationPriorityTest) {
88 for (int i = 0; i < Manifest::NUM_LOCATIONS; i++) { 64 for (int i = 0; i < Manifest::NUM_LOCATIONS; i++) {
89 Manifest::Location loc = static_cast<Manifest::Location>(i); 65 Manifest::Location loc = static_cast<Manifest::Location>(i);
90 66
91 // INVALID is not a valid location. 67 // INVALID is not a valid location.
92 if (loc == Manifest::INVALID_LOCATION) 68 if (loc == Manifest::INVALID_LOCATION)
93 continue; 69 continue;
94 70
95 // Comparing a location that has no rank will hit a CHECK. Do a 71 // Comparing a location that has no rank will hit a CHECK. Do a
96 // compare with every valid location, to be sure each one is covered. 72 // compare with every valid location, to be sure each one is covered.
97 73
(...skipping 16 matching lines...) Expand all
114 Manifest::GetHigherPriorityLocation( 90 Manifest::GetHigherPriorityLocation(
115 Manifest::EXTERNAL_POLICY_DOWNLOAD, 91 Manifest::EXTERNAL_POLICY_DOWNLOAD,
116 Manifest::EXTERNAL_PREF)); 92 Manifest::EXTERNAL_PREF));
117 93
118 ASSERT_EQ(Manifest::EXTERNAL_PREF, 94 ASSERT_EQ(Manifest::EXTERNAL_PREF,
119 Manifest::GetHigherPriorityLocation( 95 Manifest::GetHigherPriorityLocation(
120 Manifest::INTERNAL, 96 Manifest::INTERNAL,
121 Manifest::EXTERNAL_PREF)); 97 Manifest::EXTERNAL_PREF));
122 } 98 }
123 99
124 TEST_F(ExtensionTest, GetResourceURLAndPath) { 100 TEST(ExtensionTest, GetResourceURLAndPath) {
125 scoped_refptr<Extension> extension = LoadManifestStrict("empty_manifest", 101 scoped_refptr<Extension> extension = LoadManifestStrict("empty_manifest",
126 "empty.json"); 102 "empty.json");
127 EXPECT_TRUE(extension.get()); 103 EXPECT_TRUE(extension.get());
128 104
129 EXPECT_EQ(extension->url().spec() + "bar/baz.js", 105 EXPECT_EQ(extension->url().spec() + "bar/baz.js",
130 Extension::GetResourceURL(extension->url(), "bar/baz.js").spec()); 106 Extension::GetResourceURL(extension->url(), "bar/baz.js").spec());
131 EXPECT_EQ(extension->url().spec() + "baz.js", 107 EXPECT_EQ(extension->url().spec() + "baz.js",
132 Extension::GetResourceURL(extension->url(), 108 Extension::GetResourceURL(extension->url(),
133 "bar/../baz.js").spec()); 109 "bar/../baz.js").spec());
134 EXPECT_EQ(extension->url().spec() + "baz.js", 110 EXPECT_EQ(extension->url().spec() + "baz.js",
135 Extension::GetResourceURL(extension->url(), "../baz.js").spec()); 111 Extension::GetResourceURL(extension->url(), "../baz.js").spec());
136 112
137 // Test that absolute-looking paths ("/"-prefixed) are pasted correctly. 113 // Test that absolute-looking paths ("/"-prefixed) are pasted correctly.
138 EXPECT_EQ(extension->url().spec() + "test.html", 114 EXPECT_EQ(extension->url().spec() + "test.html",
139 extension->GetResourceURL("/test.html").spec()); 115 extension->GetResourceURL("/test.html").spec());
140 } 116 }
141 117
142 TEST_F(ExtensionTest, GetAbsolutePathNoError) { 118 TEST(ExtensionTest, GetAbsolutePathNoError) {
143 scoped_refptr<Extension> extension = LoadManifestStrict("absolute_path", 119 scoped_refptr<Extension> extension = LoadManifestStrict("absolute_path",
144 "absolute.json"); 120 "absolute.json");
145 EXPECT_TRUE(extension.get()); 121 EXPECT_TRUE(extension.get());
146 std::string err; 122 std::string err;
147 std::vector<InstallWarning> warnings; 123 std::vector<InstallWarning> warnings;
148 EXPECT_TRUE(extension_file_util::ValidateExtension(extension.get(), 124 EXPECT_TRUE(extension_file_util::ValidateExtension(extension.get(),
149 &err, &warnings)); 125 &err, &warnings));
150 EXPECT_EQ(0U, warnings.size()); 126 EXPECT_EQ(0U, warnings.size());
151 127
152 EXPECT_EQ(extension->path().AppendASCII("test.html").value(), 128 EXPECT_EQ(extension->path().AppendASCII("test.html").value(),
153 extension->GetResource("test.html").GetFilePath().value()); 129 extension->GetResource("test.html").GetFilePath().value());
154 EXPECT_EQ(extension->path().AppendASCII("test.js").value(), 130 EXPECT_EQ(extension->path().AppendASCII("test.js").value(),
155 extension->GetResource("test.js").GetFilePath().value()); 131 extension->GetResource("test.js").GetFilePath().value());
156 } 132 }
157 133
158 134
159 TEST_F(ExtensionTest, IdIsValid) { 135 TEST(ExtensionTest, IdIsValid) {
160 EXPECT_TRUE(Extension::IdIsValid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); 136 EXPECT_TRUE(Extension::IdIsValid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
161 EXPECT_TRUE(Extension::IdIsValid("pppppppppppppppppppppppppppppppp")); 137 EXPECT_TRUE(Extension::IdIsValid("pppppppppppppppppppppppppppppppp"));
162 EXPECT_TRUE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnop")); 138 EXPECT_TRUE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnop"));
163 EXPECT_TRUE(Extension::IdIsValid("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP")); 139 EXPECT_TRUE(Extension::IdIsValid("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"));
164 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno")); 140 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno"));
165 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnopa")); 141 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnopa"));
166 EXPECT_FALSE(Extension::IdIsValid("0123456789abcdef0123456789abcdef")); 142 EXPECT_FALSE(Extension::IdIsValid("0123456789abcdef0123456789abcdef"));
167 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnoq")); 143 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnoq"));
168 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno0")); 144 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno0"));
169 } 145 }
170 146
171 147
172 // This test ensures that the mimetype sniffing code stays in sync with the 148 // This test ensures that the mimetype sniffing code stays in sync with the
173 // actual crx files that we test other parts of the system with. 149 // actual crx files that we test other parts of the system with.
174 TEST_F(ExtensionTest, MimeTypeSniffing) { 150 TEST(ExtensionTest, MimeTypeSniffing) {
175 base::FilePath path; 151 base::FilePath path;
176 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); 152 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
177 path = path.AppendASCII("extensions").AppendASCII("good.crx"); 153 path = path.AppendASCII("extensions").AppendASCII("good.crx");
178 154
179 std::string data; 155 std::string data;
180 ASSERT_TRUE(file_util::ReadFileToString(path, &data)); 156 ASSERT_TRUE(file_util::ReadFileToString(path, &data));
181 157
182 std::string result; 158 std::string result;
183 EXPECT_TRUE(net::SniffMimeType(data.c_str(), 159 EXPECT_TRUE(net::SniffMimeType(data.c_str(),
184 data.size(), 160 data.size(),
185 GURL("http://www.example.com/foo.crx"), 161 GURL("http://www.example.com/foo.crx"),
186 std::string(), 162 std::string(),
187 &result)); 163 &result));
188 EXPECT_EQ(std::string(Extension::kMimeType), result); 164 EXPECT_EQ(std::string(Extension::kMimeType), result);
189 165
190 data.clear(); 166 data.clear();
191 result.clear(); 167 result.clear();
192 path = path.DirName().AppendASCII("bad_magic.crx"); 168 path = path.DirName().AppendASCII("bad_magic.crx");
193 ASSERT_TRUE(file_util::ReadFileToString(path, &data)); 169 ASSERT_TRUE(file_util::ReadFileToString(path, &data));
194 EXPECT_TRUE(net::SniffMimeType(data.c_str(), 170 EXPECT_TRUE(net::SniffMimeType(data.c_str(),
195 data.size(), 171 data.size(),
196 GURL("http://www.example.com/foo.crx"), 172 GURL("http://www.example.com/foo.crx"),
197 std::string(), 173 std::string(),
198 &result)); 174 &result));
199 EXPECT_EQ("application/octet-stream", result); 175 EXPECT_EQ("application/octet-stream", result);
200 } 176 }
201 177
202 TEST_F(ExtensionTest, EffectiveHostPermissions) { 178 TEST(ExtensionTest, EffectiveHostPermissions) {
203 (new ContentScriptsHandler)->Register();
204 scoped_refptr<Extension> extension; 179 scoped_refptr<Extension> extension;
205 URLPatternSet hosts; 180 URLPatternSet hosts;
206 181
207 extension = LoadManifest("effective_host_permissions", "empty.json"); 182 extension = LoadManifest("effective_host_permissions", "empty.json");
208 EXPECT_EQ(0u, extension->GetEffectiveHostPermissions().patterns().size()); 183 EXPECT_EQ(0u, extension->GetEffectiveHostPermissions().patterns().size());
209 EXPECT_FALSE(hosts.MatchesURL(GURL("http://www.google.com"))); 184 EXPECT_FALSE(hosts.MatchesURL(GURL("http://www.google.com")));
210 EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts()); 185 EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts());
211 186
212 extension = LoadManifest("effective_host_permissions", "one_host.json"); 187 extension = LoadManifest("effective_host_permissions", "one_host.json");
213 hosts = extension->GetEffectiveHostPermissions(); 188 hosts = extension->GetEffectiveHostPermissions();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 245
271 static bool CheckSocketPermission(scoped_refptr<Extension> extension, 246 static bool CheckSocketPermission(scoped_refptr<Extension> extension,
272 SocketPermissionRequest::OperationType type, 247 SocketPermissionRequest::OperationType type,
273 const char* host, 248 const char* host,
274 int port) { 249 int port) {
275 SocketPermission::CheckParam param(type, host, port); 250 SocketPermission::CheckParam param(type, host, port);
276 return extension->CheckAPIPermissionWithParam( 251 return extension->CheckAPIPermissionWithParam(
277 APIPermission::kSocket, &param); 252 APIPermission::kSocket, &param);
278 } 253 }
279 254
280 TEST_F(ExtensionTest, SocketPermissions) { 255 TEST(ExtensionTest, SocketPermissions) {
281 // Set feature current channel to appropriate value. 256 // Set feature current channel to appropriate value.
282 Feature::ScopedCurrentChannel scoped_channel( 257 Feature::ScopedCurrentChannel scoped_channel(
283 chrome::VersionInfo::CHANNEL_DEV); 258 chrome::VersionInfo::CHANNEL_DEV);
284 scoped_refptr<Extension> extension; 259 scoped_refptr<Extension> extension;
285 std::string error; 260 std::string error;
286 261
287 extension = LoadManifest("socket_permissions", "empty.json"); 262 extension = LoadManifest("socket_permissions", "empty.json");
288 EXPECT_FALSE(CheckSocketPermission(extension, 263 EXPECT_FALSE(CheckSocketPermission(extension,
289 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); 264 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80));
290 265
(...skipping 16 matching lines...) Expand all
307 EXPECT_FALSE(CheckSocketPermission( 282 EXPECT_FALSE(CheckSocketPermission(
308 extension, SocketPermissionRequest::UDP_SEND_TO, "example.com", 1900)); 283 extension, SocketPermissionRequest::UDP_SEND_TO, "example.com", 1900));
309 EXPECT_TRUE(CheckSocketPermission( 284 EXPECT_TRUE(CheckSocketPermission(
310 extension, 285 extension,
311 SocketPermissionRequest::UDP_SEND_TO, 286 SocketPermissionRequest::UDP_SEND_TO,
312 "239.255.255.250", 1900)); 287 "239.255.255.250", 1900));
313 } 288 }
314 289
315 // This tests the API permissions with an empty manifest (one that just 290 // This tests the API permissions with an empty manifest (one that just
316 // specifies a name and a version and nothing else). 291 // specifies a name and a version and nothing else).
317 TEST_F(ExtensionTest, ApiPermissions) { 292 TEST(ExtensionTest, ApiPermissions) {
318 const struct { 293 const struct {
319 const char* permission_name; 294 const char* permission_name;
320 bool expect_success; 295 bool expect_success;
321 } kTests[] = { 296 } kTests[] = {
322 // Negative test. 297 // Negative test.
323 { "non_existing_permission", false }, 298 { "non_existing_permission", false },
324 // Test default module/package permission. 299 // Test default module/package permission.
325 { "browserAction", true }, 300 { "browserAction", true },
326 { "devtools", true }, 301 { "devtools", true },
327 { "extension", true }, 302 { "extension", true },
(...skipping 24 matching lines...) Expand all
352 scoped_refptr<Extension> extension; 327 scoped_refptr<Extension> extension;
353 extension = LoadManifest("empty_manifest", "empty.json"); 328 extension = LoadManifest("empty_manifest", "empty.json");
354 329
355 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { 330 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) {
356 EXPECT_EQ(kTests[i].expect_success, 331 EXPECT_EQ(kTests[i].expect_success,
357 extension->HasAPIPermission(kTests[i].permission_name)) 332 extension->HasAPIPermission(kTests[i].permission_name))
358 << "Permission being tested: " << kTests[i].permission_name; 333 << "Permission being tested: " << kTests[i].permission_name;
359 } 334 }
360 } 335 }
361 336
362 TEST_F(ExtensionTest, GetPermissionMessages_ManyApiPermissions) { 337 TEST(ExtensionTest, GetPermissionMessages_ManyApiPermissions) {
363 scoped_refptr<Extension> extension; 338 scoped_refptr<Extension> extension;
364 extension = LoadManifest("permissions", "many-apis.json"); 339 extension = LoadManifest("permissions", "many-apis.json");
365 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 340 std::vector<string16> warnings = extension->GetPermissionMessageStrings();
366 ASSERT_EQ(6u, warnings.size()); 341 ASSERT_EQ(6u, warnings.size());
367 EXPECT_EQ("Access your data on api.flickr.com", 342 EXPECT_EQ("Access your data on api.flickr.com",
368 UTF16ToUTF8(warnings[0])); 343 UTF16ToUTF8(warnings[0]));
369 EXPECT_EQ("Read and modify your bookmarks", UTF16ToUTF8(warnings[1])); 344 EXPECT_EQ("Read and modify your bookmarks", UTF16ToUTF8(warnings[1]));
370 EXPECT_EQ("Detect your physical location", UTF16ToUTF8(warnings[2])); 345 EXPECT_EQ("Detect your physical location", UTF16ToUTF8(warnings[2]));
371 EXPECT_EQ("Read and modify your browsing history", UTF16ToUTF8(warnings[3])); 346 EXPECT_EQ("Read and modify your browsing history", UTF16ToUTF8(warnings[3]));
372 EXPECT_EQ("Access your tabs and browsing activity", UTF16ToUTF8(warnings[4])); 347 EXPECT_EQ("Access your tabs and browsing activity", UTF16ToUTF8(warnings[4]));
373 EXPECT_EQ("Manage your apps, extensions, and themes", 348 EXPECT_EQ("Manage your apps, extensions, and themes",
374 UTF16ToUTF8(warnings[5])); 349 UTF16ToUTF8(warnings[5]));
375 } 350 }
376 351
377 TEST_F(ExtensionTest, GetPermissionMessages_LocationApiPermission) { 352 TEST(ExtensionTest, GetPermissionMessages_LocationApiPermission) {
378 scoped_refptr<Extension> extension; 353 scoped_refptr<Extension> extension;
379 extension = LoadManifest("permissions", 354 extension = LoadManifest("permissions",
380 "location-api.json", 355 "location-api.json",
381 Manifest::COMPONENT, 356 Manifest::COMPONENT,
382 Extension::NO_FLAGS); 357 Extension::NO_FLAGS);
383 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 358 std::vector<string16> warnings = extension->GetPermissionMessageStrings();
384 ASSERT_EQ(1u, warnings.size()); 359 ASSERT_EQ(1u, warnings.size());
385 EXPECT_EQ("Detect your physical location", UTF16ToUTF8(warnings[0])); 360 EXPECT_EQ("Detect your physical location", UTF16ToUTF8(warnings[0]));
386 } 361 }
387 362
388 TEST_F(ExtensionTest, GetPermissionMessages_ManyHosts) { 363 TEST(ExtensionTest, GetPermissionMessages_ManyHosts) {
389 (new ContentScriptsHandler)->Register();
390 scoped_refptr<Extension> extension; 364 scoped_refptr<Extension> extension;
391 extension = LoadManifest("permissions", "many-hosts.json"); 365 extension = LoadManifest("permissions", "many-hosts.json");
392 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 366 std::vector<string16> warnings = extension->GetPermissionMessageStrings();
393 ASSERT_EQ(1u, warnings.size()); 367 ASSERT_EQ(1u, warnings.size());
394 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", 368 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com",
395 UTF16ToUTF8(warnings[0])); 369 UTF16ToUTF8(warnings[0]));
396 } 370 }
397 371
398 TEST_F(ExtensionTest, GetPermissionMessages_Plugins) { 372 TEST(ExtensionTest, GetPermissionMessages_Plugins) {
399 (new PluginsHandler)->Register();
400 scoped_refptr<Extension> extension; 373 scoped_refptr<Extension> extension;
401 extension = LoadManifest("permissions", "plugins.json"); 374 extension = LoadManifest("permissions", "plugins.json");
402 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 375 std::vector<string16> warnings = extension->GetPermissionMessageStrings();
403 // We don't parse the plugins key on Chrome OS, so it should not ask for any 376 // We don't parse the plugins key on Chrome OS, so it should not ask for any
404 // permissions. 377 // permissions.
405 #if defined(OS_CHROMEOS) 378 #if defined(OS_CHROMEOS)
406 ASSERT_EQ(0u, warnings.size()); 379 ASSERT_EQ(0u, warnings.size());
407 #else 380 #else
408 ASSERT_EQ(1u, warnings.size()); 381 ASSERT_EQ(1u, warnings.size());
409 EXPECT_EQ("Access all data on your computer and the websites you visit", 382 EXPECT_EQ("Access all data on your computer and the websites you visit",
410 UTF16ToUTF8(warnings[0])); 383 UTF16ToUTF8(warnings[0]));
411 #endif 384 #endif
412 } 385 }
413 386
414 TEST_F(ExtensionTest, WantsFileAccess) { 387 TEST(ExtensionTest, WantsFileAccess) {
415 (new ContentScriptsHandler)->Register();
416 scoped_refptr<Extension> extension; 388 scoped_refptr<Extension> extension;
417 GURL file_url("file:///etc/passwd"); 389 GURL file_url("file:///etc/passwd");
418 390
419 // <all_urls> permission 391 // <all_urls> permission
420 extension = LoadManifest("permissions", "permissions_all_urls.json"); 392 extension = LoadManifest("permissions", "permissions_all_urls.json");
421 EXPECT_TRUE(extension->wants_file_access()); 393 EXPECT_TRUE(extension->wants_file_access());
422 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 394 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
423 file_url, file_url, -1, NULL, NULL)); 395 file_url, file_url, -1, NULL, NULL));
424 extension = LoadManifest( 396 extension = LoadManifest(
425 "permissions", "permissions_all_urls.json", Extension::ALLOW_FILE_ACCESS); 397 "permissions", "permissions_all_urls.json", Extension::ALLOW_FILE_ACCESS);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 Extension::ALLOW_FILE_ACCESS); 472 Extension::ALLOW_FILE_ACCESS);
501 EXPECT_FALSE(extension->wants_file_access()); 473 EXPECT_FALSE(extension->wants_file_access());
502 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 474 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
503 file_url, 475 file_url,
504 file_url, 476 file_url,
505 -1, 477 -1,
506 &ContentScriptsInfo::GetContentScripts(extension)[0], 478 &ContentScriptsInfo::GetContentScripts(extension)[0],
507 NULL)); 479 NULL));
508 } 480 }
509 481
510 TEST_F(ExtensionTest, ExtraFlags) { 482 TEST(ExtensionTest, ExtraFlags) {
511 scoped_refptr<Extension> extension; 483 scoped_refptr<Extension> extension;
512 extension = LoadManifest("app", "manifest.json", Extension::FROM_WEBSTORE); 484 extension = LoadManifest("app", "manifest.json", Extension::FROM_WEBSTORE);
513 EXPECT_TRUE(extension->from_webstore()); 485 EXPECT_TRUE(extension->from_webstore());
514 486
515 extension = LoadManifest("app", "manifest.json", Extension::FROM_BOOKMARK); 487 extension = LoadManifest("app", "manifest.json", Extension::FROM_BOOKMARK);
516 EXPECT_TRUE(extension->from_bookmark()); 488 EXPECT_TRUE(extension->from_bookmark());
517 489
518 extension = LoadManifest("app", "manifest.json", Extension::NO_FLAGS); 490 extension = LoadManifest("app", "manifest.json", Extension::NO_FLAGS);
519 EXPECT_FALSE(extension->from_bookmark()); 491 EXPECT_FALSE(extension->from_bookmark());
520 EXPECT_FALSE(extension->from_webstore()); 492 EXPECT_FALSE(extension->from_webstore());
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2)); 851 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2));
880 852
881 extension->ClearTabSpecificPermissions(1); 853 extension->ClearTabSpecificPermissions(1);
882 EXPECT_FALSE(extension->GetTabSpecificPermissions(1).get()); 854 EXPECT_FALSE(extension->GetTabSpecificPermissions(1).get());
883 855
884 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 0)); 856 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 0));
885 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 1)); 857 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 1));
886 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2)); 858 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2));
887 } 859 }
888 860
889 TEST_F(ExtensionTest, OptionalOnlyPermission) { 861 TEST(ExtensionTest, OptionalOnlyPermission) {
890 // Set feature current channel to dev because the only permission that must 862 // Set feature current channel to dev because the only permission that must
891 // be optional (usbDevices) is only available on dev channel. 863 // be optional (usbDevices) is only available on dev channel.
892 Feature::ScopedCurrentChannel scoped_channel( 864 Feature::ScopedCurrentChannel scoped_channel(
893 chrome::VersionInfo::CHANNEL_DEV); 865 chrome::VersionInfo::CHANNEL_DEV);
894 866
895 scoped_refptr<Extension> extension; 867 scoped_refptr<Extension> extension;
896 std::string error; 868 std::string error;
897 extension = LoadManifestUnchecked("optional_only_permission", 869 extension = LoadManifestUnchecked("optional_only_permission",
898 "manifest1.json", 870 "manifest1.json",
899 Manifest::INTERNAL, Extension::NO_FLAGS, 871 Manifest::INTERNAL, Extension::NO_FLAGS,
900 &error); 872 &error);
901 EXPECT_TRUE(extension == NULL); 873 EXPECT_TRUE(extension == NULL);
902 ASSERT_EQ(ErrorUtils::FormatErrorMessage( 874 ASSERT_EQ(ErrorUtils::FormatErrorMessage(
903 errors::kPermissionMustBeOptional, "usbDevices"), error); 875 errors::kPermissionMustBeOptional, "usbDevices"), error);
904 876
905 error.clear(); 877 error.clear();
906 extension = LoadManifestUnchecked("optional_only_permission", 878 extension = LoadManifestUnchecked("optional_only_permission",
907 "manifest2.json", 879 "manifest2.json",
908 Manifest::INTERNAL, Extension::NO_FLAGS, 880 Manifest::INTERNAL, Extension::NO_FLAGS,
909 &error); 881 &error);
910 EXPECT_TRUE(extension != NULL); 882 EXPECT_TRUE(extension != NULL);
911 EXPECT_TRUE(error.empty()); 883 EXPECT_TRUE(error.empty());
912 } 884 }
913 885
914 } // namespace extensions 886 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_unittest.h ('k') | chrome/common/extensions/features/base_feature_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698