summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/extension_unittest.cc
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-26 03:18:46 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-26 03:18:46 +0000
commit671e6c1cecf01e46dc0267e020971aa0f98de0a2 (patch)
tree61db92254d4030103b4f4f68b7b8a7ad342f6d93 /chrome/common/extensions/extension_unittest.cc
parent37e1bb64e696f39acb8a80021af58356af8e3bf1 (diff)
downloadchromium_src-671e6c1cecf01e46dc0267e020971aa0f98de0a2.zip
chromium_src-671e6c1cecf01e46dc0267e020971aa0f98de0a2.tar.gz
chromium_src-671e6c1cecf01e46dc0267e020971aa0f98de0a2.tar.bz2
Implement Browser Actions extensions.
Browser Actions are like Page Actions, except they appear next to the Omnibox and are always visible. For details see http://code.google.com/p/chromium/wiki/BrowserActions. Added a simple browser action sample that adds a Print button to the chrome toolbar (which brings up the Print dialog for the current page). Removed |type| from PageActions, which is currently ignored and was already removed from the docs. Each extension can only have 1 browser_action. Each browser action can specify more than one icon, but only the first is used. And no API has been added yet (besides the event definition). BUG=22099 TEST=Install the sample browser action, navigate to google.com, press the print button. A print dialog should come up. Review URL: http://codereview.chromium.org/243001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27319 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/extension_unittest.cc')
-rw-r--r--chrome/common/extensions/extension_unittest.cc119
1 files changed, 84 insertions, 35 deletions
diff --git a/chrome/common/extensions/extension_unittest.cc b/chrome/common/extensions/extension_unittest.cc
index f1ee5e1..6348315 100644
--- a/chrome/common/extensions/extension_unittest.cc
+++ b/chrome/common/extensions/extension_unittest.cc
@@ -279,21 +279,28 @@ TEST(ExtensionTest, GetResourceURLAndPath) {
TEST(ExtensionTest, LoadPageActionHelper) {
Extension extension;
std::string error_msg;
- scoped_ptr<PageAction> page_action;
+ scoped_ptr<ContextualAction> action;
DictionaryValue input;
// First try with an empty dictionary. We should get nothing back.
- ASSERT_EQ(NULL, extension.LoadPageActionHelper(&input, 0, &error_msg));
+ ASSERT_EQ(NULL, extension.LoadContextualActionHelper(
+ &input, 0, &error_msg, ContextualAction::PAGE_ACTION));
+ ASSERT_STRNE("", error_msg.c_str());
+ error_msg = "";
+
+ // Now try the same, but as a browser action. Ensure same results.
+ ASSERT_EQ(NULL, extension.LoadContextualActionHelper(
+ &input, 0, &error_msg, ContextualAction::BROWSER_ACTION));
ASSERT_STRNE("", error_msg.c_str());
error_msg = "";
// Now setup some values to use in the page action.
- const std::string id("MyPageActionId");
- const std::string name("MyPageActionName");
+ const std::string id("MyContextualActionId");
+ const std::string name("MyContextualActionName");
std::string img1("image1.png");
std::string img2("image2.png");
- // Add the page_actions dictionary.
+ // Add the dictionary for the contextual action.
input.SetString(keys::kPageActionId, id);
input.SetString(keys::kName, name);
ListValue* icons = new ListValue;
@@ -301,31 +308,46 @@ TEST(ExtensionTest, LoadPageActionHelper) {
icons->Set(1, Value::CreateStringValue(img2));
input.Set(keys::kPageActionIcons, icons);
- // Parse the page action and read back the values from the object.
- page_action.reset(extension.LoadPageActionHelper(&input, 0, &error_msg));
- ASSERT_TRUE(NULL != page_action.get());
+ // Parse as page action and read back the values from the object.
+ action.reset(extension.LoadContextualActionHelper(
+ &input, 0, &error_msg, ContextualAction::PAGE_ACTION));
+ ASSERT_TRUE(NULL != action.get());
ASSERT_STREQ("", error_msg.c_str());
- ASSERT_STREQ(id.c_str(), page_action->id().c_str());
- ASSERT_STREQ(name.c_str(), page_action->name().c_str());
- ASSERT_EQ(2u, page_action->icon_paths().size());
- ASSERT_STREQ(img1.c_str(), page_action->icon_paths()[0].c_str());
- ASSERT_STREQ(img2.c_str(), page_action->icon_paths()[1].c_str());
- // Type hasn't been set, but it defaults to PERMANENT.
- ASSERT_EQ(PageAction::PERMANENT, page_action->type());
+ ASSERT_STREQ(id.c_str(), action->id().c_str());
+ ASSERT_STREQ(name.c_str(), action->name().c_str());
+ ASSERT_EQ(2u, action->icon_paths().size());
+ ASSERT_STREQ(img1.c_str(), action->icon_paths()[0].c_str());
+ ASSERT_STREQ(img2.c_str(), action->icon_paths()[1].c_str());
+ ASSERT_EQ(ContextualAction::PAGE_ACTION, action->type());
+
+ // Now try the same, but as a browser action.
+ action.reset(extension.LoadContextualActionHelper(
+ &input, 0, &error_msg, ContextualAction::BROWSER_ACTION));
+ ASSERT_TRUE(NULL != action.get());
+ ASSERT_STREQ("", error_msg.c_str());
+ // Browser actions don't have an id, page actions do.
+ ASSERT_STREQ("", action->id().c_str());
+ ASSERT_STREQ(name.c_str(), action->name().c_str());
+ ASSERT_EQ(2u, action->icon_paths().size());
+ ASSERT_STREQ(img1.c_str(), action->icon_paths()[0].c_str());
+ ASSERT_STREQ(img2.c_str(), action->icon_paths()[1].c_str());
+ ASSERT_EQ(ContextualAction::BROWSER_ACTION, action->type());
// Explicitly set the same type and parse again.
- input.SetString(keys::kType, values::kPageActionTypePermanent);
- page_action.reset(extension.LoadPageActionHelper(&input, 0, &error_msg));
- ASSERT_TRUE(NULL != page_action.get());
+ input.SetString(keys::kType, values::kPageActionTypeTab);
+ action.reset(extension.LoadContextualActionHelper(
+ &input, 0, &error_msg, ContextualAction::BROWSER_ACTION));
+ ASSERT_TRUE(NULL != action.get());
ASSERT_STREQ("", error_msg.c_str());
- ASSERT_EQ(PageAction::PERMANENT, page_action->type());
+ ASSERT_EQ(ContextualAction::BROWSER_ACTION, action->type());
- // Explicitly set the TAB type and parse again.
- input.SetString(keys::kType, values::kPageActionTypeTab);
- page_action.reset(extension.LoadPageActionHelper(&input, 0, &error_msg));
- ASSERT_TRUE(NULL != page_action.get());
+ // Explicitly set the PAGE_ACTION type and parse again.
+ input.SetString(keys::kType, values::kPageActionTypePermanent);
+ action.reset(extension.LoadContextualActionHelper(
+ &input, 0, &error_msg, ContextualAction::PAGE_ACTION));
+ ASSERT_TRUE(NULL != action.get());
ASSERT_STREQ("", error_msg.c_str());
- ASSERT_EQ(PageAction::TAB, page_action->type());
+ ASSERT_EQ(ContextualAction::PAGE_ACTION, action->type());
// Make a deep copy of the input and remove one key at a time and see if we
// get the right error.
@@ -334,34 +356,61 @@ TEST(ExtensionTest, LoadPageActionHelper) {
// First remove id key.
copy.reset(static_cast<DictionaryValue*>(input.DeepCopy()));
copy->Remove(keys::kPageActionId, NULL);
- page_action.reset(extension.LoadPageActionHelper(copy.get(), 0, &error_msg));
- ASSERT_TRUE(NULL == page_action.get());
+ action.reset(extension.LoadContextualActionHelper(
+ copy.get(), 0, &error_msg, ContextualAction::PAGE_ACTION));
+ ASSERT_TRUE(NULL == action.get());
ASSERT_TRUE(MatchPattern(error_msg.c_str(),
errors::kInvalidPageActionId));
+ error_msg = "";
+
+ // Same test (id key), but with browser action.
+ copy.reset(static_cast<DictionaryValue*>(input.DeepCopy()));
+ copy->Remove(keys::kPageActionId, NULL);
+ action.reset(extension.LoadContextualActionHelper(
+ copy.get(), 0, &error_msg, ContextualAction::BROWSER_ACTION));
+ // Having no id is valid for browser actions.
+ ASSERT_TRUE(NULL != action.get());
+ ASSERT_STREQ("", error_msg.c_str());
+ error_msg = "";
// Then remove the name key.
copy.reset(static_cast<DictionaryValue*>(input.DeepCopy()));
copy->Remove(keys::kName, NULL);
- page_action.reset(extension.LoadPageActionHelper(copy.get(), 0, &error_msg));
- ASSERT_TRUE(NULL == page_action.get());
+ action.reset(extension.LoadContextualActionHelper(
+ copy.get(), 0, &error_msg, ContextualAction::PAGE_ACTION));
+ ASSERT_TRUE(NULL == action.get());
+ ASSERT_TRUE(MatchPattern(error_msg.c_str(),
+ errors::kInvalidName));
+ error_msg = "";
+
+ // Same test (name key), but with browser action.
+ copy.reset(static_cast<DictionaryValue*>(input.DeepCopy()));
+ copy->Remove(keys::kName, NULL);
+ action.reset(extension.LoadContextualActionHelper(
+ copy.get(), 0, &error_msg, ContextualAction::BROWSER_ACTION));
+ ASSERT_TRUE(NULL == action.get());
ASSERT_TRUE(MatchPattern(error_msg.c_str(),
errors::kInvalidName));
+ error_msg = "";
// Then remove the icon paths key.
copy.reset(static_cast<DictionaryValue*>(input.DeepCopy()));
copy->Remove(keys::kPageActionIcons, NULL);
- page_action.reset(extension.LoadPageActionHelper(copy.get(), 0, &error_msg));
- ASSERT_TRUE(NULL == page_action.get());
+ action.reset(extension.LoadContextualActionHelper(
+ copy.get(), 0, &error_msg, ContextualAction::PAGE_ACTION));
+ ASSERT_TRUE(NULL == action.get());
ASSERT_TRUE(MatchPattern(error_msg.c_str(),
errors::kInvalidPageActionIconPaths));
+ error_msg = "";
- // Then set the type to something bogus.
+ // Same test (name key), but with browser action.
copy.reset(static_cast<DictionaryValue*>(input.DeepCopy()));
- copy->SetString(keys::kType, "something_bogus");
- page_action.reset(extension.LoadPageActionHelper(copy.get(), 0, &error_msg));
- ASSERT_TRUE(NULL == page_action.get());
+ copy->Remove(keys::kPageActionIcons, NULL);
+ action.reset(extension.LoadContextualActionHelper(
+ copy.get(), 0, &error_msg, ContextualAction::BROWSER_ACTION));
+ ASSERT_TRUE(NULL == action.get());
ASSERT_TRUE(MatchPattern(error_msg.c_str(),
- errors::kInvalidPageActionTypeValue));
+ errors::kInvalidPageActionIconPaths));
}
TEST(ExtensionTest, IdIsValid) {