This source file includes following definitions.
- GetPageAction
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
#include "chrome/browser/extensions/extension_action.h"
#include "chrome/browser/extensions/extension_action_icon_factory.h"
#include "chrome/browser/extensions/extension_action_manager.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
using content::WebContents;
namespace extensions {
namespace {
class PageActionApiTest : public ExtensionApiTest {
protected:
ExtensionAction* GetPageAction(const Extension& extension) {
return ExtensionActionManager::Get(browser()->profile())->
GetPageAction(extension);
}
};
IN_PROC_BROWSER_TEST_F(PageActionApiTest, Basic) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(RunExtensionTest("page_action/basics")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
{
ResultCatcher catcher;
ui_test_utils::NavigateToURL(browser(),
GURL(extension->GetResourceURL("update.html")));
ASSERT_TRUE(catcher.GetNextResult());
}
int tab_id = SessionTabHelper::FromWebContents(
browser()->tab_strip_model()->GetActiveWebContents())->session_id().id();
ExtensionAction* action = GetPageAction(*extension);
ASSERT_TRUE(action);
EXPECT_EQ("Modified", action->GetTitle(tab_id));
{
ResultCatcher catcher;
int tab_id = ExtensionTabUtil::GetTabId(
browser()->tab_strip_model()->GetActiveWebContents());
ExtensionActionAPI::PageActionExecuted(
browser()->profile(), *action, tab_id, std::string(), 0);
EXPECT_TRUE(catcher.GetNextResult());
}
{
ResultCatcher catcher;
ui_test_utils::NavigateToURL(browser(),
GURL(extension->GetResourceURL("update2.html")));
ASSERT_TRUE(catcher.GetNextResult());
}
ExtensionActionIconFactory icon_factory(profile(), extension, action, NULL);
tab_id = SessionTabHelper::FromWebContents(
browser()->tab_strip_model()->GetActiveWebContents())->session_id().id();
EXPECT_FALSE(icon_factory.GetIcon(tab_id).IsEmpty());
}
IN_PROC_BROWSER_TEST_F(PageActionApiTest, AddPopup) {
ASSERT_TRUE(RunExtensionTest("page_action/add_popup")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
int tab_id = ExtensionTabUtil::GetTabId(
browser()->tab_strip_model()->GetActiveWebContents());
ExtensionAction* page_action = GetPageAction(*extension);
ASSERT_TRUE(page_action)
<< "Page action test extension should have a page action.";
ASSERT_FALSE(page_action->HasPopup(tab_id));
{
ResultCatcher catcher;
ExtensionActionAPI::PageActionExecuted(
browser()->profile(), *page_action, tab_id, std::string(), 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());
{
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());
}
IN_PROC_BROWSER_TEST_F(PageActionApiTest, RemovePopup) {
ASSERT_TRUE(RunExtensionTest("page_action/remove_popup")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
int tab_id = ExtensionTabUtil::GetTabId(
browser()->tab_strip_model()->GetActiveWebContents());
ExtensionAction* page_action = GetPageAction(*extension);
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.";
{
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.";
}
IN_PROC_BROWSER_TEST_F(PageActionApiTest, OldPageActions) {
ASSERT_TRUE(RunExtensionTestAllowOldManifestVersion("page_action/old_api")) <<
message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
{
ResultCatcher catcher;
ui_test_utils::NavigateToURL(browser(),
GURL(extension->GetResourceURL("page.html")));
ASSERT_TRUE(catcher.GetNextResult());
}
{
ResultCatcher catcher;
int tab_id = ExtensionTabUtil::GetTabId(
browser()->tab_strip_model()->GetActiveWebContents());
ExtensionAction* page_action = GetPageAction(*extension);
ExtensionActionAPI::PageActionExecuted(
browser()->profile(), *page_action, tab_id, std::string(), 1);
EXPECT_TRUE(catcher.GetNextResult());
}
}
IN_PROC_BROWSER_TEST_F(PageActionApiTest, DISABLED_ShowPageActionPopup) {
ASSERT_TRUE(RunExtensionTest("page_action/popup")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
{
ResultCatcher catcher;
LocationBarTesting* location_bar =
browser()->window()->GetLocationBar()->GetLocationBarForTesting();
location_bar->TestPageActionPressed(0);
ASSERT_TRUE(catcher.GetNextResult());
}
}
IN_PROC_BROWSER_TEST_F(PageActionApiTest, TestCrash57333) {
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("page_action")
.AppendASCII("crash_57333")
.AppendASCII("Extension1")));
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("page_action")
.AppendASCII("crash_57333")
.AppendASCII("Extension2")));
}
IN_PROC_BROWSER_TEST_F(PageActionApiTest, Getters) {
ASSERT_TRUE(RunExtensionTest("page_action/getters")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
ResultCatcher catcher;
ui_test_utils::NavigateToURL(browser(),
GURL(extension->GetResourceURL("update.html")));
ASSERT_TRUE(catcher.GetNextResult());
}
IN_PROC_BROWSER_TEST_F(PageActionApiTest, TestTriggerPageAction) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(RunExtensionTest("trigger_actions/page_action")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/simple.html"));
chrome::NewTab(browser());
browser()->tab_strip_model()->ActivateTabAt(0, true);
ExtensionAction* page_action = GetPageAction(*extension);
ASSERT_TRUE(page_action);
{
ResultCatcher catcher;
int tab_id = ExtensionTabUtil::GetTabId(
browser()->tab_strip_model()->GetActiveWebContents());
ExtensionActionAPI::PageActionExecuted(
browser()->profile(), *page_action, tab_id, std::string(), 0);
EXPECT_TRUE(catcher.GetNextResult());
}
WebContents* tab =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_TRUE(tab != NULL);
const std::string script =
"window.domAutomationController.send(document.body.style."
"backgroundColor);";
std::string result;
EXPECT_TRUE(content::ExecuteScriptAndExtractString(tab, script, &result));
EXPECT_EQ(result, "red");
}
}
}