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

Unified Diff: chrome/browser/extensions/page_action_apitest.cc

Issue 545068: Allow extensions to add, remove, or change their page action popup. (Closed)
Patch Set: Rebase, to run trybots with test data in place. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/page_action_apitest.cc
diff --git a/chrome/browser/extensions/page_action_apitest.cc b/chrome/browser/extensions/page_action_apitest.cc
index b5455587d6de473ad04c24f33874792230148dc4..b5ba0f3454b6aaa64cdb07c80d08e4fbc9626949 100644
--- a/chrome/browser/extensions/page_action_apitest.cc
+++ b/chrome/browser/extensions/page_action_apitest.cc
@@ -18,6 +18,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageAction) {
StartHTTPServer();
ASSERT_TRUE(RunExtensionTest("page_action/basics")) << message_;
+ // TODO(skerner): Move the next four lines into a helper method.
ExtensionsService* service = browser()->profile()->GetExtensionsService();
ASSERT_EQ(1u, service->extensions()->size());
Extension* extension = service->extensions()->at(0);
@@ -61,6 +62,86 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageAction) {
EXPECT_FALSE(action->GetIcon(tab_id).isNull());
}
+// Test that calling chrome.pageAction.setPopup() can enable a popup.
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageActionAddPopup) {
+ // Load the extension, which has no default popup.
+ ASSERT_TRUE(RunExtensionTest("page_action/add_popup")) << message_;
+
+ ExtensionsService* service = browser()->profile()->GetExtensionsService();
+ ASSERT_EQ(1u, service->extensions()->size());
+ Extension* extension = service->extensions()->at(0);
+ ASSERT_TRUE(extension);
+
+ int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents());
+
+ ExtensionAction* page_action = extension->page_action();
+ ASSERT_TRUE(page_action)
+ << "Page action test extension should have a page action.";
+
+ ASSERT_FALSE(page_action->HasPopup(tab_id));
+
+ // Simulate the page action being clicked. The resulting event should
+ // install a page action popup.
+ {
+ ResultCatcher catcher;
+ ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted(
+ browser()->profile(), extension->id(), "action", tab_id, "", 1);
+ ASSERT_TRUE(catcher.GetNextResult());
+ }
+
+ ASSERT_TRUE(page_action->HasPopup(tab_id))
+ << "Clicking on the page action should have caused a popup to be added.";
+
+ ASSERT_STREQ("/a_popup.html",
+ page_action->GetPopupUrl(tab_id).path().c_str());
+
+ // Now change the popup from a_popup.html to a_second_popup.html .
+ // Load a page which removes the popup using chrome.pageAction.setPopup().
+ {
+ ResultCatcher catcher;
+ ui_test_utils::NavigateToURL(
+ browser(),
+ GURL(extension->GetResourceURL("change_popup.html")));
+ ASSERT_TRUE(catcher.GetNextResult());
+ }
+
+ ASSERT_TRUE(page_action->HasPopup(tab_id));
+ ASSERT_STREQ("/another_popup.html",
+ page_action->GetPopupUrl(tab_id).path().c_str());
+}
+
+// Test that calling chrome.pageAction.setPopup() can remove a popup.
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageActionRemovePopup) {
+ // Load the extension, which has a page action with a default popup.
+ ASSERT_TRUE(RunExtensionTest("page_action/remove_popup")) << message_;
+
+ ExtensionsService* service = browser()->profile()->GetExtensionsService();
+ ASSERT_EQ(1u, service->extensions()->size());
+ Extension* extension = service->extensions()->at(0);
+ ASSERT_TRUE(extension);
+
+ int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents());
+
+ ExtensionAction* page_action = extension->page_action();
+ ASSERT_TRUE(page_action)
+ << "Page action test extension should have a page action.";
+
+ ASSERT_TRUE(page_action->HasPopup(tab_id))
+ << "Expect a page action popup before the test removes it.";
+
+ // Load a page which removes the popup using chrome.pageAction.setPopup().
+ {
+ ResultCatcher catcher;
+ ui_test_utils::NavigateToURL(
+ browser(),
+ GURL(extension->GetResourceURL("remove_popup.html")));
+ ASSERT_TRUE(catcher.GetNextResult());
+ }
+
+ ASSERT_FALSE(page_action->HasPopup(tab_id))
+ << "Page action popup should have been removed.";
+}
+
// Tests old-style pageActions API that is deprecated but we don't want to
// break.
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OldPageActions) {
« no previous file with comments | « chrome/browser/extensions/extension_page_actions_module.cc ('k') | chrome/common/extensions/api/extension_api.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698