diff options
author | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-08 22:30:24 +0000 |
---|---|---|
committer | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-08 22:30:24 +0000 |
commit | 6ae592e4947c687e6c695b0a3b117dd7512d357e (patch) | |
tree | b17136f89df894ebf10dad5adc531a0e3b172e59 /chrome/common | |
parent | 1e419d42be673bd9b67e4576e8e2b8d5c8c3e0b9 (diff) | |
download | chromium_src-6ae592e4947c687e6c695b0a3b117dd7512d357e.zip chromium_src-6ae592e4947c687e6c695b0a3b117dd7512d357e.tar.gz chromium_src-6ae592e4947c687e6c695b0a3b117dd7512d357e.tar.bz2 |
Revert 35802 - Failed Valgrind - Allow an empty list of page actions.
BUG=26050
TEST=Updated existing unit tests ExtensionTest.InitFromValue*, manual testing on Linux.
Review URL: http://codereview.chromium.org/523132
TBR=skerner@chromium.org
Review URL: http://codereview.chromium.org/535003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35834 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/extensions/extension.cc | 31 | ||||
-rw-r--r-- | chrome/common/extensions/extension_constants.cc | 2 | ||||
-rw-r--r-- | chrome/common/extensions/extension_unittest.cc | 23 |
3 files changed, 17 insertions, 39 deletions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 7f9783d..1ccaeec 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -1079,8 +1079,6 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, } // Initialize page action (optional). - DictionaryValue* page_action_value = NULL; - if (source.HasKey(keys::kPageActions)) { ListValue* list_value; if (!source.GetList(keys::kPageActions, &list_value)) { @@ -1088,29 +1086,28 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, return false; } - size_t list_value_length = list_value->GetSize(); - - if (list_value_length == 0u) { - // A list with zero items is allowed, and is equivalent to not having - // a page_actions key in the manifest. Don't set |page_action_value|. - } else if (list_value_length == 1u) { - if (!list_value->GetDictionary(0, &page_action_value)) { - *error = errors::kInvalidPageAction; - return false; - } - } else { // list_value_length > 1u. + if (list_value->GetSize() != 1u) { *error = errors::kInvalidPageActionsListSize; return false; } + + DictionaryValue* page_action_value; + if (!list_value->GetDictionary(0, &page_action_value)) { + *error = errors::kInvalidPageAction; + return false; + } + + page_action_.reset( + LoadExtensionActionHelper(page_action_value, error)); + if (!page_action_.get()) + return false; // Failed to parse page action definition. } else if (source.HasKey(keys::kPageAction)) { + DictionaryValue* page_action_value; if (!source.GetDictionary(keys::kPageAction, &page_action_value)) { *error = errors::kInvalidPageAction; return false; } - } - // If page_action_value is not NULL, then there was a valid page action. - if (page_action_value) { page_action_.reset( LoadExtensionActionHelper(page_action_value, error)); if (!page_action_.get()) @@ -1120,7 +1117,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, // Initialize browser action (optional). if (source.HasKey(keys::kBrowserAction)) { // Restrict extensions to one UI surface. - if (page_action_.get()) { + if (source.HasKey(keys::kPageAction) || source.HasKey(keys::kPageActions)) { *error = errors::kOneUISurfaceOnly; return false; } diff --git a/chrome/common/extensions/extension_constants.cc b/chrome/common/extensions/extension_constants.cc index 0f59e5f..825fc2e 100644 --- a/chrome/common/extensions/extension_constants.cc +++ b/chrome/common/extensions/extension_constants.cc @@ -122,7 +122,7 @@ const char* kInvalidPageActionIconPath = const char* kInvalidPageActionsList = "Invalid value for 'page_actions'."; const char* kInvalidPageActionsListSize = - "Invalid value for 'page_actions'. There can be at most one page action."; + "Invalid value for 'page_actions'. There can be only one."; const char* kInvalidPageActionId = "Required value 'id' is missing or invalid."; const char* kInvalidPageActionDefaultTitle = diff --git a/chrome/common/extensions/extension_unittest.cc b/chrome/common/extensions/extension_unittest.cc index a2bb857..a294c23 100644 --- a/chrome/common/extensions/extension_unittest.cc +++ b/chrome/common/extensions/extension_unittest.cc @@ -223,29 +223,17 @@ TEST(ExtensionTest, InitFromValueInvalid) { EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidPrivacyBlacklistsPath)); - // Multiple page actions are not allowed. + // Test invalid UI surface count (both page action and browser action). input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); DictionaryValue* action = new DictionaryValue; action->SetString(keys::kPageActionId, "MyExtensionActionId"); action->SetString(keys::kName, "MyExtensionActionName"); ListValue* action_list = new ListValue; action_list->Append(action->DeepCopy()); - action_list->Append(action->DeepCopy()); - input_value->Set(keys::kPageActions, action_list); - EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); - EXPECT_STREQ(errors::kInvalidPageActionsListSize, error.c_str()); - - // Test invalid UI surface count (both page action and browser action). - input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); - action = new DictionaryValue; - action->SetString(keys::kPageActionId, "MyExtensionActionId"); - action->SetString(keys::kName, "MyExtensionActionName"); - action_list = new ListValue; - action_list->Append(action->DeepCopy()); input_value->Set(keys::kPageActions, action_list); input_value->Set(keys::kBrowserAction, action); EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); - EXPECT_STREQ(errors::kOneUISurfaceOnly, error.c_str()); + EXPECT_STREQ(error.c_str(), errors::kOneUISurfaceOnly); // Test invalid options page url. input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); @@ -307,13 +295,6 @@ TEST(ExtensionTest, InitFromValueValid) { EXPECT_EQ("chrome-extension", extension.options_url().scheme()); EXPECT_EQ("/options.html", extension.options_url().path()); - // Test that an empty list of page actions does not stop a browser action - // from being loaded. - ListValue* empty_list = new ListValue; - input_value.Set(keys::kPageActions, empty_list); - EXPECT_TRUE(extension.InitFromValue(input_value, false, &error)); - EXPECT_EQ("", error); - #if !defined(OS_MACOSX) // TODO(aa): The version isn't stamped into the unit test binary on mac. // Test with a minimum_chrome_version. |