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

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

Issue 523132: Allow an empty list of page actions. (Closed)
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
« 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 216
217 // Test invalid privacy blacklists list item. 217 // Test invalid privacy blacklists list item.
218 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); 218 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy()));
219 ListValue* privacy_blacklists = NULL; 219 ListValue* privacy_blacklists = NULL;
220 input_value->GetList(keys::kPrivacyBlacklists, &privacy_blacklists); 220 input_value->GetList(keys::kPrivacyBlacklists, &privacy_blacklists);
221 ASSERT_FALSE(NULL == privacy_blacklists); 221 ASSERT_FALSE(NULL == privacy_blacklists);
222 privacy_blacklists->Set(0, Value::CreateIntegerValue(42)); 222 privacy_blacklists->Set(0, Value::CreateIntegerValue(42));
223 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); 223 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
224 EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidPrivacyBlacklistsPath)); 224 EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidPrivacyBlacklistsPath));
225 225
226 // Test invalid UI surface count (both page action and browser action). 226 // Multiple page actions are not allowed.
227 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); 227 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy()));
228 DictionaryValue* action = new DictionaryValue; 228 DictionaryValue* action = new DictionaryValue;
229 action->SetString(keys::kPageActionId, "MyExtensionActionId"); 229 action->SetString(keys::kPageActionId, "MyExtensionActionId");
230 action->SetString(keys::kName, "MyExtensionActionName"); 230 action->SetString(keys::kName, "MyExtensionActionName");
231 ListValue* action_list = new ListValue; 231 ListValue* action_list = new ListValue;
232 action_list->Append(action->DeepCopy()); 232 action_list->Append(action->DeepCopy());
233 action_list->Append(action);
234 input_value->Set(keys::kPageActions, action_list);
235 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
236 EXPECT_STREQ(errors::kInvalidPageActionsListSize, error.c_str());
237
238 // Test invalid UI surface count (both page action and browser action).
239 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy()));
240 action = new DictionaryValue;
241 action->SetString(keys::kPageActionId, "MyExtensionActionId");
242 action->SetString(keys::kName, "MyExtensionActionName");
243 action_list = new ListValue;
244 action_list->Append(action->DeepCopy());
233 input_value->Set(keys::kPageActions, action_list); 245 input_value->Set(keys::kPageActions, action_list);
234 input_value->Set(keys::kBrowserAction, action); 246 input_value->Set(keys::kBrowserAction, action);
235 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); 247 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
236 EXPECT_STREQ(error.c_str(), errors::kOneUISurfaceOnly); 248 EXPECT_STREQ(errors::kOneUISurfaceOnly, error.c_str());
237 249
238 // Test invalid options page url. 250 // Test invalid options page url.
239 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); 251 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy()));
240 input_value->Set(keys::kOptionsPage, Value::CreateNullValue()); 252 input_value->Set(keys::kOptionsPage, Value::CreateNullValue());
241 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); 253 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
242 EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidOptionsPage)); 254 EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidOptionsPage));
243 255
244 // Test invalid/empty default locale. 256 // Test invalid/empty default locale.
245 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); 257 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy()));
246 input_value->Set(keys::kDefaultLocale, Value::CreateIntegerValue(5)); 258 input_value->Set(keys::kDefaultLocale, Value::CreateIntegerValue(5));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 EXPECT_EQ(extension.id(), extension.url().host()); 300 EXPECT_EQ(extension.id(), extension.url().host());
289 EXPECT_EQ(path.value(), extension.path().value()); 301 EXPECT_EQ(path.value(), extension.path().value());
290 302
291 // Test with an options page. 303 // Test with an options page.
292 input_value.SetString(keys::kOptionsPage, "options.html"); 304 input_value.SetString(keys::kOptionsPage, "options.html");
293 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error)); 305 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error));
294 EXPECT_EQ("", error); 306 EXPECT_EQ("", error);
295 EXPECT_EQ("chrome-extension", extension.options_url().scheme()); 307 EXPECT_EQ("chrome-extension", extension.options_url().scheme());
296 EXPECT_EQ("/options.html", extension.options_url().path()); 308 EXPECT_EQ("/options.html", extension.options_url().path());
297 309
310 // Test that an empty list of page actions does not stop a browser action
311 // from being loaded.
312 ListValue* empty_list = new ListValue;
313 input_value.Set(keys::kPageActions, empty_list);
314 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error));
315 EXPECT_EQ("", error);
316
298 #if !defined(OS_MACOSX) 317 #if !defined(OS_MACOSX)
299 // TODO(aa): The version isn't stamped into the unit test binary on mac. 318 // TODO(aa): The version isn't stamped into the unit test binary on mac.
300 // Test with a minimum_chrome_version. 319 // Test with a minimum_chrome_version.
301 input_value.SetString(keys::kMinimumChromeVersion, "1.0"); 320 input_value.SetString(keys::kMinimumChromeVersion, "1.0");
302 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error)); 321 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error));
303 EXPECT_EQ("", error); 322 EXPECT_EQ("", error);
304 // The minimum chrome version is not stored in the Extension object. 323 // The minimum chrome version is not stored in the Extension object.
305 #endif 324 #endif
306 } 325 }
307 326
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 scoped_ptr<Extension> new_extension( 708 scoped_ptr<Extension> new_extension(
690 LoadManifest("allow_silent_upgrade", 709 LoadManifest("allow_silent_upgrade",
691 std::string(kTests[i].base_name) + "_new.json")); 710 std::string(kTests[i].base_name) + "_new.json"));
692 711
693 EXPECT_EQ(kTests[i].expect_success, 712 EXPECT_EQ(kTests[i].expect_success,
694 Extension::IsPrivilegeIncrease(old_extension.get(), 713 Extension::IsPrivilegeIncrease(old_extension.get(),
695 new_extension.get())) 714 new_extension.get()))
696 << kTests[i].base_name; 715 << kTests[i].base_name;
697 } 716 }
698 } 717 }
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