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

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

Issue 527003: Revert 35602 - Add a "minimum_chrome_version" key to the manifest.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 | Annotate | Revision Log
« 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 TEST(ExtensionTest, InitFromValueInvalid) { 26 // TODO(mad): http://crbug.com/26214
27 TEST(ExtensionTest, DISABLED_InitFromValueInvalid) {
27 #if defined(OS_WIN) 28 #if defined(OS_WIN)
28 FilePath path(FILE_PATH_LITERAL("c:\\foo")); 29 FilePath path(FILE_PATH_LITERAL("c:\\foo"));
29 #elif defined(OS_POSIX) 30 #elif defined(OS_POSIX)
30 FilePath path(FILE_PATH_LITERAL("/foo")); 31 FilePath path(FILE_PATH_LITERAL("/foo"));
31 #endif 32 #endif
32 Extension extension(path); 33 Extension extension(path);
33 std::string error; 34 std::string error;
34 ExtensionErrorReporter::Init(false); 35 ExtensionErrorReporter::Init(false);
35 36
36 // Start with a valid extension manifest 37 // Start with a valid extension manifest
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 244
244 // Test invalid/empty default locale. 245 // Test invalid/empty default locale.
245 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); 246 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy()));
246 input_value->Set(keys::kDefaultLocale, Value::CreateIntegerValue(5)); 247 input_value->Set(keys::kDefaultLocale, Value::CreateIntegerValue(5));
247 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); 248 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
248 EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidDefaultLocale)); 249 EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidDefaultLocale));
249 250
250 input_value->Set(keys::kDefaultLocale, Value::CreateStringValue("")); 251 input_value->Set(keys::kDefaultLocale, Value::CreateStringValue(""));
251 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); 252 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
252 EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidDefaultLocale)); 253 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));
264 } 254 }
265 255
266 TEST(ExtensionTest, InitFromValueValid) { 256 TEST(ExtensionTest, InitFromValueValid) {
267 #if defined(OS_WIN) 257 #if defined(OS_WIN)
268 FilePath path(FILE_PATH_LITERAL("C:\\foo")); 258 FilePath path(FILE_PATH_LITERAL("C:\\foo"));
269 #elif defined(OS_POSIX) 259 #elif defined(OS_POSIX)
270 FilePath path(FILE_PATH_LITERAL("/foo")); 260 FilePath path(FILE_PATH_LITERAL("/foo"));
271 #endif 261 #endif
272 Extension extension(path); 262 Extension extension(path);
273 std::string error; 263 std::string error;
(...skipping 10 matching lines...) Expand all
284 EXPECT_EQ("my extension", extension.name()); 274 EXPECT_EQ("my extension", extension.name());
285 EXPECT_EQ(extension.id(), extension.url().host()); 275 EXPECT_EQ(extension.id(), extension.url().host());
286 EXPECT_EQ(path.value(), extension.path().value()); 276 EXPECT_EQ(path.value(), extension.path().value());
287 277
288 // Test with an options page. 278 // Test with an options page.
289 input_value.SetString(keys::kOptionsPage, "options.html"); 279 input_value.SetString(keys::kOptionsPage, "options.html");
290 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error)); 280 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error));
291 EXPECT_EQ("", error); 281 EXPECT_EQ("", error);
292 EXPECT_EQ("chrome-extension", extension.options_url().scheme()); 282 EXPECT_EQ("chrome-extension", extension.options_url().scheme());
293 EXPECT_EQ("/options.html", extension.options_url().path()); 283 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.
300 } 284 }
301 285
302 TEST(ExtensionTest, GetResourceURLAndPath) { 286 TEST(ExtensionTest, GetResourceURLAndPath) {
303 #if defined(OS_WIN) 287 #if defined(OS_WIN)
304 FilePath path(FILE_PATH_LITERAL("C:\\foo")); 288 FilePath path(FILE_PATH_LITERAL("C:\\foo"));
305 #elif defined(OS_POSIX) 289 #elif defined(OS_POSIX)
306 FilePath path(FILE_PATH_LITERAL("/foo")); 290 FilePath path(FILE_PATH_LITERAL("/foo"));
307 #endif 291 #endif
308 Extension extension(path); 292 Extension extension(path);
309 DictionaryValue input_value; 293 DictionaryValue input_value;
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 scoped_ptr<Extension> new_extension( 672 scoped_ptr<Extension> new_extension(
689 LoadManifest("allow_silent_upgrade", 673 LoadManifest("allow_silent_upgrade",
690 std::string(kTests[i].base_name) + "_new.json")); 674 std::string(kTests[i].base_name) + "_new.json"));
691 675
692 EXPECT_EQ(kTests[i].expect_success, 676 EXPECT_EQ(kTests[i].expect_success,
693 Extension::IsPrivilegeIncrease(old_extension.get(), 677 Extension::IsPrivilegeIncrease(old_extension.get(),
694 new_extension.get())) 678 new_extension.get()))
695 << kTests[i].base_name; 679 << kTests[i].base_name;
696 } 680 }
697 } 681 }
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