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

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

Issue 521036: Add a "minimum_chrome_version" key to the manifest. (Closed)
Patch Set: Removed extraneous change, added new test, added docs Created 10 years, 11 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
« no previous file with comments | « chrome/common/extensions/extension_constants.cc ('k') | no next file » | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "chrome/common/chrome_paths.h" 12 #include "chrome/common/chrome_paths.h"
13 #include "chrome/common/extensions/extension_constants.h" 13 #include "chrome/common/extensions/extension_constants.h"
14 #include "chrome/common/extensions/extension_error_reporter.h" 14 #include "chrome/common/extensions/extension_error_reporter.h"
15 #include "chrome/common/json_value_serializer.h" 15 #include "chrome/common/json_value_serializer.h"
16 #include "net/base/mime_sniffer.h" 16 #include "net/base/mime_sniffer.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace keys = extension_manifest_keys; 19 namespace keys = extension_manifest_keys;
20 namespace values = extension_manifest_values; 20 namespace values = extension_manifest_values;
21 namespace errors = extension_manifest_errors; 21 namespace errors = extension_manifest_errors;
22 22
23 class ExtensionTest : public testing::Test { 23 class ExtensionTest : public testing::Test {
24 }; 24 };
25 25
26 // TODO(mad): http://crbug.com/26214 26 TEST(ExtensionTest, InitFromValueInvalid) {
27 TEST(ExtensionTest, DISABLED_InitFromValueInvalid) {
28 #if defined(OS_WIN) 27 #if defined(OS_WIN)
29 FilePath path(FILE_PATH_LITERAL("c:\\foo")); 28 FilePath path(FILE_PATH_LITERAL("c:\\foo"));
30 #elif defined(OS_POSIX) 29 #elif defined(OS_POSIX)
31 FilePath path(FILE_PATH_LITERAL("/foo")); 30 FilePath path(FILE_PATH_LITERAL("/foo"));
32 #endif 31 #endif
33 Extension extension(path); 32 Extension extension(path);
34 std::string error; 33 std::string error;
35 ExtensionErrorReporter::Init(false); 34 ExtensionErrorReporter::Init(false);
36 35
37 // Start with a valid extension manifest 36 // Start with a valid extension manifest
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 243
245 // Test invalid/empty default locale. 244 // Test invalid/empty default locale.
246 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); 245 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy()));
247 input_value->Set(keys::kDefaultLocale, Value::CreateIntegerValue(5)); 246 input_value->Set(keys::kDefaultLocale, Value::CreateIntegerValue(5));
248 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); 247 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
249 EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidDefaultLocale)); 248 EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidDefaultLocale));
250 249
251 input_value->Set(keys::kDefaultLocale, Value::CreateStringValue("")); 250 input_value->Set(keys::kDefaultLocale, Value::CreateStringValue(""));
252 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); 251 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
253 EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidDefaultLocale)); 252 EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidDefaultLocale));
253
254 // Test invalid minimum_chrome_version.
255 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy()));
256 input_value->Set(keys::kMinimumChromeVersion, Value::CreateIntegerValue(42));
257 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
258 EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidMinimumChromeVersion));
259
260 input_value->Set(keys::kMinimumChromeVersion,
261 Value::CreateStringValue("88.8"));
262 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
263 EXPECT_TRUE(MatchPatternASCII(error, errors::kChromeVersionTooLow));
254 } 264 }
255 265
256 TEST(ExtensionTest, InitFromValueValid) { 266 TEST(ExtensionTest, InitFromValueValid) {
257 #if defined(OS_WIN) 267 #if defined(OS_WIN)
258 FilePath path(FILE_PATH_LITERAL("C:\\foo")); 268 FilePath path(FILE_PATH_LITERAL("C:\\foo"));
259 #elif defined(OS_POSIX) 269 #elif defined(OS_POSIX)
260 FilePath path(FILE_PATH_LITERAL("/foo")); 270 FilePath path(FILE_PATH_LITERAL("/foo"));
261 #endif 271 #endif
262 Extension extension(path); 272 Extension extension(path);
263 std::string error; 273 std::string error;
(...skipping 10 matching lines...) Expand all
274 EXPECT_EQ("my extension", extension.name()); 284 EXPECT_EQ("my extension", extension.name());
275 EXPECT_EQ(extension.id(), extension.url().host()); 285 EXPECT_EQ(extension.id(), extension.url().host());
276 EXPECT_EQ(path.value(), extension.path().value()); 286 EXPECT_EQ(path.value(), extension.path().value());
277 287
278 // Test with an options page. 288 // Test with an options page.
279 input_value.SetString(keys::kOptionsPage, "options.html"); 289 input_value.SetString(keys::kOptionsPage, "options.html");
280 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error)); 290 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error));
281 EXPECT_EQ("", error); 291 EXPECT_EQ("", error);
282 EXPECT_EQ("chrome-extension", extension.options_url().scheme()); 292 EXPECT_EQ("chrome-extension", extension.options_url().scheme());
283 EXPECT_EQ("/options.html", extension.options_url().path()); 293 EXPECT_EQ("/options.html", extension.options_url().path());
294
295 // Test with a minimum_chrome_version.
296 input_value.SetString(keys::kMinimumChromeVersion, "1.0");
297 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error));
298 EXPECT_EQ("", error);
299 // The minimum chrome version is not stored in the Extension object.
284 } 300 }
285 301
286 TEST(ExtensionTest, GetResourceURLAndPath) { 302 TEST(ExtensionTest, GetResourceURLAndPath) {
287 #if defined(OS_WIN) 303 #if defined(OS_WIN)
288 FilePath path(FILE_PATH_LITERAL("C:\\foo")); 304 FilePath path(FILE_PATH_LITERAL("C:\\foo"));
289 #elif defined(OS_POSIX) 305 #elif defined(OS_POSIX)
290 FilePath path(FILE_PATH_LITERAL("/foo")); 306 FilePath path(FILE_PATH_LITERAL("/foo"));
291 #endif 307 #endif
292 Extension extension(path); 308 Extension extension(path);
293 DictionaryValue input_value; 309 DictionaryValue input_value;
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 scoped_ptr<Extension> new_extension( 688 scoped_ptr<Extension> new_extension(
673 LoadManifest("allow_silent_upgrade", 689 LoadManifest("allow_silent_upgrade",
674 std::string(kTests[i].base_name) + "_new.json")); 690 std::string(kTests[i].base_name) + "_new.json"));
675 691
676 EXPECT_EQ(kTests[i].expect_success, 692 EXPECT_EQ(kTests[i].expect_success,
677 Extension::IsPrivilegeIncrease(old_extension.get(), 693 Extension::IsPrivilegeIncrease(old_extension.get(),
678 new_extension.get())) 694 new_extension.get()))
679 << kTests[i].base_name; 695 << kTests[i].base_name;
680 } 696 }
681 } 697 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_constants.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698