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

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

Issue 390019: Parse messages.json in ExtensionUnpacker (like we do for manifest).... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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) 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 "base/file_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/path_service.h" 8 #include "base/path_service.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"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 .AppendASCII("1.0.0.0") 42 .AppendASCII("1.0.0.0")
43 .AppendASCII(Extension::kManifestFilename); 43 .AppendASCII(Extension::kManifestFilename);
44 44
45 JSONFileValueSerializer serializer(extensions_path); 45 JSONFileValueSerializer serializer(extensions_path);
46 scoped_ptr<DictionaryValue> valid_value( 46 scoped_ptr<DictionaryValue> valid_value(
47 static_cast<DictionaryValue*>(serializer.Deserialize(&error))); 47 static_cast<DictionaryValue*>(serializer.Deserialize(&error)));
48 EXPECT_EQ("", error); 48 EXPECT_EQ("", error);
49 ASSERT_TRUE(valid_value.get()); 49 ASSERT_TRUE(valid_value.get());
50 ASSERT_TRUE(extension.InitFromValue(*valid_value, true, &error)); 50 ASSERT_TRUE(extension.InitFromValue(*valid_value, true, &error));
51 ASSERT_EQ("", error); 51 ASSERT_EQ("", error);
52 EXPECT_EQ("en_US", extension.default_locale());
52 53
53 scoped_ptr<DictionaryValue> input_value; 54 scoped_ptr<DictionaryValue> input_value;
54 55
55 // Test missing and invalid versions 56 // Test missing and invalid versions
56 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); 57 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy()));
57 input_value->Remove(keys::kVersion, NULL); 58 input_value->Remove(keys::kVersion, NULL);
58 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); 59 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
59 EXPECT_EQ(errors::kInvalidVersion, error); 60 EXPECT_EQ(errors::kInvalidVersion, error);
60 61
61 input_value->SetInteger(keys::kVersion, 42); 62 input_value->SetInteger(keys::kVersion, 42);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 input_value->Set(keys::kPageActions, action_list); 232 input_value->Set(keys::kPageActions, action_list);
232 input_value->Set(keys::kBrowserAction, action); 233 input_value->Set(keys::kBrowserAction, action);
233 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); 234 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
234 EXPECT_STREQ(error.c_str(), errors::kOneUISurfaceOnly); 235 EXPECT_STREQ(error.c_str(), errors::kOneUISurfaceOnly);
235 236
236 // Test invalid options page url. 237 // Test invalid options page url.
237 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); 238 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy()));
238 input_value->Set(keys::kOptionsPage, Value::CreateNullValue()); 239 input_value->Set(keys::kOptionsPage, Value::CreateNullValue());
239 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); 240 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
240 EXPECT_TRUE(MatchPattern(error, errors::kInvalidOptionsPage)); 241 EXPECT_TRUE(MatchPattern(error, errors::kInvalidOptionsPage));
242
243 // Test invalid/empty default locale.
244 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy()));
245 input_value->Set(keys::kDefaultLocale, Value::CreateIntegerValue(5));
246 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
247 EXPECT_TRUE(MatchPattern(error, errors::kInvalidDefaultLocale));
248
249 input_value->Set(keys::kDefaultLocale, Value::CreateStringValue(""));
250 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
251 EXPECT_TRUE(MatchPattern(error, errors::kInvalidDefaultLocale));
241 } 252 }
242 253
243 TEST(ExtensionTest, InitFromValueValid) { 254 TEST(ExtensionTest, InitFromValueValid) {
244 #if defined(OS_WIN) 255 #if defined(OS_WIN)
245 FilePath path(FILE_PATH_LITERAL("C:\\foo")); 256 FilePath path(FILE_PATH_LITERAL("C:\\foo"));
246 #elif defined(OS_POSIX) 257 #elif defined(OS_POSIX)
247 FilePath path(FILE_PATH_LITERAL("/foo")); 258 FilePath path(FILE_PATH_LITERAL("/foo"));
248 #endif 259 #endif
249 Extension extension(path); 260 Extension extension(path);
250 std::string error; 261 std::string error;
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 scoped_ptr<Extension> new_extension( 666 scoped_ptr<Extension> new_extension(
656 LoadManifest("allow_silent_upgrade", 667 LoadManifest("allow_silent_upgrade",
657 std::string(kTests[i].base_name) + "_new.json")); 668 std::string(kTests[i].base_name) + "_new.json"));
658 669
659 EXPECT_EQ(kTests[i].expect_success, 670 EXPECT_EQ(kTests[i].expect_success,
660 Extension::IsPrivilegeIncrease(old_extension.get(), 671 Extension::IsPrivilegeIncrease(old_extension.get(),
661 new_extension.get())) 672 new_extension.get()))
662 << kTests[i].base_name; 673 << kTests[i].base_name;
663 } 674 }
664 } 675 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698