summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-02 20:33:58 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-02 20:33:58 +0000
commitae7fe7177e80bd409a1757b7421feb59973afa08 (patch)
treed015ec0294c8389176f760eb698519a8c07959b6 /chrome
parent50a441d8fcc68babce2a7dc1fc373569c8326a2a (diff)
downloadchromium_src-ae7fe7177e80bd409a1757b7421feb59973afa08.zip
chromium_src-ae7fe7177e80bd409a1757b7421feb59973afa08.tar.gz
chromium_src-ae7fe7177e80bd409a1757b7421feb59973afa08.tar.bz2
Add a couple of more extension unit tests for page
actions. One for the helper function that parses a page action from the manifest and another that tests the page action api. BUG=None TEST=None Review URL: http://codereview.chromium.org/151181 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19840 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/common/extensions/extension.h2
-rw-r--r--chrome/common/extensions/extension_unittest.cc91
-rw-r--r--chrome/renderer/extensions/extension_api_client_unittest.cc9
3 files changed, 100 insertions, 2 deletions
diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h
index 1705e12..0b04281 100644
--- a/chrome/common/extensions/extension.h
+++ b/chrome/common/extensions/extension.h
@@ -340,6 +340,8 @@ class Extension {
// URL for fetching an update manifest
GURL update_url_;
+ FRIEND_TEST(ExtensionTest, LoadPageActionHelper);
+
DISALLOW_COPY_AND_ASSIGN(Extension);
};
diff --git a/chrome/common/extensions/extension_unittest.cc b/chrome/common/extensions/extension_unittest.cc
index 38b599e..47f8ef8 100644
--- a/chrome/common/extensions/extension_unittest.cc
+++ b/chrome/common/extensions/extension_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -243,6 +243,94 @@ TEST(ExtensionTest, GetResourceURLAndPath) {
Extension::GetResourcePath(extension.path(), "../baz.js").value());
}
+TEST(ExtensionTest, LoadPageActionHelper) {
+ Extension extension;
+ std::string error_msg;
+ scoped_ptr<PageAction> page_action;
+ DictionaryValue input;
+
+ // First try with an empty dictionary. We should get nothing back.
+ ASSERT_EQ(NULL, extension.LoadPageActionHelper(&input, 0, &error_msg));
+ 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");
+ FilePath::StringType img1 = FILE_PATH_LITERAL("image1.png");
+ FilePath::StringType img2 = FILE_PATH_LITERAL("image2.png");
+
+ // Add the page_actions dictionary.
+ input.SetString(Extension::kPageActionIdKey, id);
+ input.SetString(Extension::kNameKey, name);
+ ListValue* icons = new ListValue;
+ icons->Set(0, Value::CreateStringValue(img1));
+ icons->Set(1, Value::CreateStringValue(img2));
+ input.Set(Extension::kIconPathsKey, 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());
+ 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].value().c_str());
+ ASSERT_STREQ(img2.c_str(), page_action->icon_paths()[1].value().c_str());
+ // Type hasn't been set, but it defaults to PERMANENT.
+ ASSERT_EQ(PageAction::PERMANENT, page_action->type());
+
+ // Explicitly set the same type and parse again.
+ input.SetString(Extension::kTypeKey, Extension::kPageActionTypePermanent);
+ page_action.reset(extension.LoadPageActionHelper(&input, 0, &error_msg));
+ ASSERT_TRUE(NULL != page_action.get());
+ ASSERT_STREQ("", error_msg.c_str());
+ ASSERT_EQ(PageAction::PERMANENT, page_action->type());
+
+ // Explicitly set the TAB type and parse again.
+ input.SetString(Extension::kTypeKey, Extension::kPageActionTypeTab);
+ page_action.reset(extension.LoadPageActionHelper(&input, 0, &error_msg));
+ ASSERT_TRUE(NULL != page_action.get());
+ ASSERT_STREQ("", error_msg.c_str());
+ ASSERT_EQ(PageAction::TAB, page_action->type());
+
+ // Make a deep copy of the input and remove one key at a time and see if we
+ // get the right error.
+ scoped_ptr<DictionaryValue> copy;
+
+ // First remove id key.
+ copy.reset(static_cast<DictionaryValue*>(input.DeepCopy()));
+ copy->Remove(Extension::kPageActionIdKey, NULL);
+ page_action.reset(extension.LoadPageActionHelper(copy.get(), 0, &error_msg));
+ ASSERT_TRUE(NULL == page_action.get());
+ ASSERT_TRUE(MatchPattern(error_msg.c_str(),
+ Extension::kInvalidPageActionIdError));
+
+ // Then remove the name key.
+ copy.reset(static_cast<DictionaryValue*>(input.DeepCopy()));
+ copy->Remove(Extension::kNameKey, NULL);
+ page_action.reset(extension.LoadPageActionHelper(copy.get(), 0, &error_msg));
+ ASSERT_TRUE(NULL == page_action.get());
+ ASSERT_TRUE(MatchPattern(error_msg.c_str(),
+ Extension::kInvalidNameError));
+
+ // Then remove the icon paths key.
+ copy.reset(static_cast<DictionaryValue*>(input.DeepCopy()));
+ copy->Remove(Extension::kIconPathsKey, NULL);
+ page_action.reset(extension.LoadPageActionHelper(copy.get(), 0, &error_msg));
+ ASSERT_TRUE(NULL == page_action.get());
+ ASSERT_TRUE(MatchPattern(error_msg.c_str(),
+ Extension::kInvalidPageActionIconPathsError));
+
+ // Then set the type to something bogus.
+ copy.reset(static_cast<DictionaryValue*>(input.DeepCopy()));
+ copy->SetString(Extension::kTypeKey, "something_bogus");
+ page_action.reset(extension.LoadPageActionHelper(copy.get(), 0, &error_msg));
+ ASSERT_TRUE(NULL == page_action.get());
+ ASSERT_TRUE(MatchPattern(error_msg.c_str(),
+ Extension::kInvalidPageActionTypeValueError));
+}
+
TEST(ExtensionTest, IdIsValid) {
EXPECT_TRUE(Extension::IdIsValid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
EXPECT_TRUE(Extension::IdIsValid("pppppppppppppppppppppppppppppppp"));
@@ -321,4 +409,3 @@ TEST(ExtensionTest, UpdateUrls) {
EXPECT_TRUE(MatchPattern(error, Extension::kInvalidUpdateURLError));
}
}
-
diff --git a/chrome/renderer/extensions/extension_api_client_unittest.cc b/chrome/renderer/extensions/extension_api_client_unittest.cc
index 9638b27..6cef5750 100644
--- a/chrome/renderer/extensions/extension_api_client_unittest.cc
+++ b/chrome/renderer/extensions/extension_api_client_unittest.cc
@@ -480,11 +480,20 @@ TEST_F(ExtensionAPIClientTest, SetBookmarkTitle) {
}
TEST_F(ExtensionAPIClientTest, EnablePageAction) {
+ // Basic old-school enablePageAction call.
ExpectJsPass("chrome.pageActions.enableForTab("
"\"dummy\", {tabId: 0, url: \"http://foo/\"});",
"EnablePageAction",
"[\"dummy\",{\"tabId\":0,\"url\":\"http://foo/\"}]");
+ // Try both optional parameters (title and iconId).
+ ExpectJsPass("chrome.pageActions.enableForTab("
+ "\"dummy\", {tabId: 0, url: \"http://foo/\","
+ "title: \"a\", iconId: 0});",
+ "EnablePageAction",
+ "[\"dummy\",{\"tabId\":0,\"url\":\"http://foo/\","
+ "\"title\":\"a\",\"iconId\":0}]");
+ // Now try disablePageAction.
ExpectJsPass("chrome.pageActions.disableForTab("
"\"dummy\", {tabId: 0, url: \"http://foo/\"});",
"DisablePageAction",