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

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

Issue 271114: Add concept of an options page to Extensions.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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) 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); 224 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy()));
225 DictionaryValue* action = new DictionaryValue; 225 DictionaryValue* action = new DictionaryValue;
226 action->SetString(keys::kPageActionId, "MyExtensionActionId"); 226 action->SetString(keys::kPageActionId, "MyExtensionActionId");
227 action->SetString(keys::kName, "MyExtensionActionName"); 227 action->SetString(keys::kName, "MyExtensionActionName");
228 ListValue* action_list = new ListValue; 228 ListValue* action_list = new ListValue;
229 action_list->Append(action->DeepCopy()); 229 action_list->Append(action->DeepCopy());
230 input_value->Set(keys::kPageActions, action_list); 230 input_value->Set(keys::kPageActions, action_list);
231 input_value->Set(keys::kBrowserAction, action); 231 input_value->Set(keys::kBrowserAction, action);
232 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); 232 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
233 EXPECT_STREQ(error.c_str(), errors::kOneUISurfaceOnly); 233 EXPECT_STREQ(error.c_str(), errors::kOneUISurfaceOnly);
234
235 // Test invalid options page url.
236 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy()));
237 input_value->Set(keys::kOptionsPage, Value::CreateNullValue());
238 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
239 EXPECT_TRUE(MatchPattern(error, errors::kInvalidOptionsPage));
234 } 240 }
235 241
236 TEST(ExtensionTest, InitFromValueValid) { 242 TEST(ExtensionTest, InitFromValueValid) {
237 #if defined(OS_WIN) 243 #if defined(OS_WIN)
238 FilePath path(FILE_PATH_LITERAL("C:\\foo")); 244 FilePath path(FILE_PATH_LITERAL("C:\\foo"));
239 #elif defined(OS_POSIX) 245 #elif defined(OS_POSIX)
240 FilePath path(FILE_PATH_LITERAL("/foo")); 246 FilePath path(FILE_PATH_LITERAL("/foo"));
241 #endif 247 #endif
242 Extension extension(path); 248 Extension extension(path);
243 std::string error; 249 std::string error;
244 DictionaryValue input_value; 250 DictionaryValue input_value;
245 251
246 // Test minimal extension 252 // Test minimal extension
247 input_value.SetString(keys::kVersion, "1.0.0.0"); 253 input_value.SetString(keys::kVersion, "1.0.0.0");
248 input_value.SetString(keys::kName, "my extension"); 254 input_value.SetString(keys::kName, "my extension");
249 255
250 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error)); 256 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error));
251 EXPECT_EQ("", error); 257 EXPECT_EQ("", error);
252 EXPECT_TRUE(Extension::IdIsValid(extension.id())); 258 EXPECT_TRUE(Extension::IdIsValid(extension.id()));
253 EXPECT_EQ("1.0.0.0", extension.VersionString()); 259 EXPECT_EQ("1.0.0.0", extension.VersionString());
254 EXPECT_EQ("my extension", extension.name()); 260 EXPECT_EQ("my extension", extension.name());
255 EXPECT_EQ(extension.id(), extension.url().host()); 261 EXPECT_EQ(extension.id(), extension.url().host());
256 EXPECT_EQ(path.value(), extension.path().value()); 262 EXPECT_EQ(path.value(), extension.path().value());
263
264 // Test with an options page.
265 input_value.SetString(keys::kOptionsPage, "options.html");
266 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error));
267 EXPECT_EQ("", error);
268 EXPECT_EQ("chrome-extension", extension.options_url().scheme());
269 EXPECT_EQ("/options.html", extension.options_url().path());
257 } 270 }
258 271
259 TEST(ExtensionTest, GetResourceURLAndPath) { 272 TEST(ExtensionTest, GetResourceURLAndPath) {
260 #if defined(OS_WIN) 273 #if defined(OS_WIN)
261 FilePath path(FILE_PATH_LITERAL("C:\\foo")); 274 FilePath path(FILE_PATH_LITERAL("C:\\foo"));
262 #elif defined(OS_POSIX) 275 #elif defined(OS_POSIX)
263 FilePath path(FILE_PATH_LITERAL("/foo")); 276 FilePath path(FILE_PATH_LITERAL("/foo"));
264 #endif 277 #endif
265 Extension extension(path); 278 Extension extension(path);
266 DictionaryValue input_value; 279 DictionaryValue input_value;
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 scoped_ptr<Extension> new_extension( 693 scoped_ptr<Extension> new_extension(
681 LoadManifest("allow_silent_upgrade", 694 LoadManifest("allow_silent_upgrade",
682 std::string(kTests[i].base_name) + "_new.json")); 695 std::string(kTests[i].base_name) + "_new.json"));
683 696
684 EXPECT_EQ(kTests[i].expect_success, 697 EXPECT_EQ(kTests[i].expect_success,
685 Extension::IsPrivilegeIncrease(old_extension.get(), 698 Extension::IsPrivilegeIncrease(old_extension.get(),
686 new_extension.get())) 699 new_extension.get()))
687 << kTests[i].base_name; 700 << kTests[i].base_name;
688 } 701 }
689 } 702 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_constants.cc ('k') | chrome/test/data/extensions/options.crx » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698