This source file includes following definitions.
- AddBackgroundForViews
- ImagesAreEqualAtScale
- GetBrowserActionsBar
- OpenPopup
- GetBrowserAction
- 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
- 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 "build/build_config.h"
#if defined(TOOLKIT_GTK)
#include <gtk/gtk.h>
#endif
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/browser_action_test_util.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/extensions/extension_toolbar_model.h"
#include "chrome/browser/profiles/profile.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/tabs/tab_strip_model.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_service.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/feature_switch.h"
#include "grit/theme_resources.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
#include "ui/gfx/skia_util.h"
using content::WebContents;
namespace extensions {
namespace {
const char kEmptyImageDataError[] =
"The imageData property must contain an ImageData object or dictionary "
"of ImageData objects.";
const char kEmptyPathError[] = "The path property must not be empty.";
gfx::ImageSkia AddBackgroundForViews(const gfx::ImageSkia& icon) {
#if defined(TOOLKIT_VIEWS)
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
gfx::ImageSkia bg = *rb.GetImageSkiaNamed(IDR_BROWSER_ACTION);
return gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon);
#else
return icon;
#endif
}
bool ImagesAreEqualAtScale(const gfx::ImageSkia& i1,
const gfx::ImageSkia& i2,
float scale) {
SkBitmap bitmap1 = i1.GetRepresentation(scale).sk_bitmap();
SkBitmap bitmap2 = i2.GetRepresentation(scale).sk_bitmap();
return gfx::BitmapsAreEqual(bitmap1, bitmap2);
}
class BrowserActionApiTest : public ExtensionApiTest {
public:
BrowserActionApiTest() {}
virtual ~BrowserActionApiTest() {}
protected:
BrowserActionTestUtil GetBrowserActionsBar() {
return BrowserActionTestUtil(browser());
}
bool OpenPopup(int index) {
ResultCatcher catcher;
content::WindowedNotificationObserver popup_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
GetBrowserActionsBar().Press(index);
popup_observer.Wait();
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
return GetBrowserActionsBar().HasPopup();
}
ExtensionAction* GetBrowserAction(const Extension& extension) {
return ExtensionActionManager::Get(browser()->profile())->
GetBrowserAction(extension);
}
};
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
ResultCatcher catcher;
ui_test_utils::NavigateToURL(browser(),
GURL(extension->GetResourceURL("update.html")));
ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
ExtensionAction* action = GetBrowserAction(*extension);
ASSERT_EQ("Modified", action->GetTitle(ExtensionAction::kDefaultTabId));
ASSERT_EQ("badge", action->GetBadgeText(ExtensionAction::kDefaultTabId));
ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255),
action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId));
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/extensions/test_file.txt"));
ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get(
browser()->profile());
toolbar_model->ExecuteBrowserAction(extension, browser(), NULL, true);
ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
}
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
#if defined (OS_MACOSX)
std::vector<ui::ScaleFactor> supported_scale_factors;
supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
supported_scale_factors.push_back(ui::SCALE_FACTOR_200P);
ui::SetSupportedScaleFactors(supported_scale_factors);
#endif
ExtensionActionIconFactory icon_factory(
profile(),
extension,
GetBrowserAction(*extension),
NULL);
ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0));
gfx::Image action_icon = icon_factory.GetIcon(0);
uint32_t action_icon_last_id = action_icon.ToSkBitmap()->getGenerationID();
ASSERT_EQ(action_icon_last_id,
icon_factory.GetIcon(0).ToSkBitmap()->getGenerationID());
uint32_t action_icon_current_id = 0;
ResultCatcher catcher;
GetBrowserActionsBar().Press(0);
ASSERT_TRUE(catcher.GetNextResult());
action_icon = icon_factory.GetIcon(0);
action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
EXPECT_GT(action_icon_current_id, action_icon_last_id);
action_icon_last_id = action_icon_current_id;
EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(
ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
1.0f));
GetBrowserActionsBar().Press(0);
ASSERT_TRUE(catcher.GetNextResult());
action_icon = icon_factory.GetIcon(0);
action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
EXPECT_GT(action_icon_current_id, action_icon_last_id);
action_icon_last_id = action_icon_current_id;
EXPECT_FALSE(
action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(
ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
1.0f));
GetBrowserActionsBar().Press(0);
ASSERT_TRUE(catcher.GetNextResult());
action_icon = icon_factory.GetIcon(0);
action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
EXPECT_GT(action_icon_current_id, action_icon_last_id);
action_icon_last_id = action_icon_current_id;
EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(
ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
1.0f));
GetBrowserActionsBar().Press(0);
ASSERT_TRUE(catcher.GetNextResult());
action_icon = icon_factory.GetIcon(0);
action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
EXPECT_GT(action_icon_current_id, action_icon_last_id);
action_icon_last_id = action_icon_current_id;
EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(
ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
1.0f));
GetBrowserActionsBar().Press(0);
ASSERT_TRUE(catcher.GetNextResult());
action_icon = icon_factory.GetIcon(0);
action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
EXPECT_GT(action_icon_current_id, action_icon_last_id);
action_icon_last_id = action_icon_current_id;
EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(
ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
1.0f));
GetBrowserActionsBar().Press(0);
ASSERT_TRUE(catcher.GetNextResult());
action_icon = icon_factory.GetIcon(0);
action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
EXPECT_GT(action_icon_current_id, action_icon_last_id);
action_icon_last_id = action_icon_current_id;
EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(
ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
1.0f));
GetBrowserActionsBar().Press(0);
ASSERT_TRUE(catcher.GetNextResult());
action_icon = icon_factory.GetIcon(0);
const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia();
EXPECT_FALSE(action_icon_skia->HasRepresentation(1.0f));
EXPECT_TRUE(action_icon_skia->HasRepresentation(2.0f));
action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
EXPECT_GT(action_icon_current_id, action_icon_last_id);
action_icon_last_id = action_icon_current_id;
EXPECT_TRUE(gfx::BitmapsAreEqual(
*action_icon.ToSkBitmap(),
action_icon_skia->GetRepresentation(2.0f).sk_bitmap()));
EXPECT_TRUE(
ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon_skia),
*GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
2.0f));
GetBrowserActionsBar().Press(0);
ASSERT_FALSE(catcher.GetNextResult());
EXPECT_EQ(kEmptyImageDataError, catcher.message());
GetBrowserActionsBar().Press(0);
ASSERT_FALSE(catcher.GetNextResult());
EXPECT_EQ(kEmptyPathError, catcher.message());
}
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest,
DISABLED_TabSpecificBrowserActionState) {
ASSERT_TRUE(RunExtensionTest("browser_action/tab_specific_state")) <<
message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0));
ResultCatcher catcher;
GetBrowserActionsBar().Press(0);
ASSERT_TRUE(catcher.GetNextResult());
EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0));
chrome::NewTab(browser());
EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0));
browser()->tab_strip_model()->ActivateTabAt(0, true);
EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0));
ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0));
}
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_BrowserActionPopup) {
ASSERT_TRUE(
LoadExtension(test_data_dir_.AppendASCII("browser_action/popup")));
BrowserActionTestUtil actions_bar = GetBrowserActionsBar();
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
const int growFactor = 500;
gfx::Size minSize = BrowserActionTestUtil::GetMinPopupSize();
gfx::Size middleSize = gfx::Size(growFactor, growFactor);
gfx::Size maxSize = BrowserActionTestUtil::GetMaxPopupSize();
ASSERT_GT(minSize.height() + growFactor * 2, maxSize.height());
ASSERT_GT(minSize.width() + growFactor * 2, maxSize.width());
ASSERT_TRUE(OpenPopup(0));
EXPECT_EQ(minSize, actions_bar.GetPopupBounds().size());
EXPECT_TRUE(actions_bar.HidePopup());
ASSERT_TRUE(OpenPopup(0));
EXPECT_EQ(middleSize, actions_bar.GetPopupBounds().size());
EXPECT_TRUE(actions_bar.HidePopup());
ASSERT_TRUE(OpenPopup(0));
EXPECT_EQ(maxSize, actions_bar.GetPopupBounds().size());
EXPECT_TRUE(actions_bar.HidePopup());
}
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionAddPopup) {
ASSERT_TRUE(RunExtensionTest("browser_action/add_popup")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
int tab_id = ExtensionTabUtil::GetTabId(
browser()->tab_strip_model()->GetActiveWebContents());
ExtensionAction* browser_action = GetBrowserAction(*extension);
ASSERT_TRUE(browser_action)
<< "Browser action test extension should have a browser action.";
ASSERT_FALSE(browser_action->HasPopup(tab_id));
ASSERT_FALSE(browser_action->HasPopup(ExtensionAction::kDefaultTabId));
{
ResultCatcher catcher;
GetBrowserActionsBar().Press(0);
ASSERT_TRUE(catcher.GetNextResult());
}
ASSERT_TRUE(browser_action->HasPopup(tab_id))
<< "Clicking on the browser action should have caused a popup to "
<< "be added.";
ASSERT_FALSE(browser_action->HasPopup(ExtensionAction::kDefaultTabId))
<< "Clicking on the browser action should not have set a default "
<< "popup.";
ASSERT_STREQ("/a_popup.html",
browser_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(browser_action->HasPopup(tab_id));
ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId));
ASSERT_STREQ("/another_popup.html",
browser_action->GetPopupUrl(tab_id).path().c_str());
}
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionRemovePopup) {
ASSERT_TRUE(RunExtensionTest("browser_action/remove_popup")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
int tab_id = ExtensionTabUtil::GetTabId(
browser()->tab_strip_model()->GetActiveWebContents());
ExtensionAction* browser_action = GetBrowserAction(*extension);
ASSERT_TRUE(browser_action)
<< "Browser action test extension should have a browser action.";
ASSERT_TRUE(browser_action->HasPopup(tab_id))
<< "Expect a browser action popup before the test removes it.";
ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId))
<< "Expect a browser action popup is the default for all tabs.";
{
ResultCatcher catcher;
ui_test_utils::NavigateToURL(
browser(),
GURL(extension->GetResourceURL("remove_popup.html")));
ASSERT_TRUE(catcher.GetNextResult());
}
ASSERT_FALSE(browser_action->HasPopup(tab_id))
<< "Browser action popup should have been removed.";
ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId))
<< "Browser action popup default should not be changed by setting "
<< "a specific tab id.";
}
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoBasic) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile();
Browser* incognito_browser =
new Browser(Browser::CreateParams(incognito_profile,
browser()->host_desktop_type()));
ASSERT_EQ(0,
BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions());
extensions::ExtensionPrefs::Get(browser()->profile())
->SetIsIncognitoEnabled(extension->id(), true);
chrome::CloseWindow(incognito_browser);
incognito_browser =
new Browser(Browser::CreateParams(incognito_profile,
browser()->host_desktop_type()));
ASSERT_EQ(1,
BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions());
}
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoDragging) {
ExtensionService* service = extensions::ExtensionSystem::Get(
browser()->profile())->extension_service();
const char kTooltipA[] = "Alpha";
const char kTooltipB[] = "Beta";
const char kTooltipC[] = "Gamma";
const size_t size_before = service->extensions()->size();
base::FilePath test_dir = test_data_dir_.AppendASCII("browser_action");
const Extension* extension_a = InstallExtension(
test_dir.AppendASCII("empty_browser_action_alpha.crx"), 1);
const Extension* extension_b = InstallExtension(
test_dir.AppendASCII("empty_browser_action_beta.crx"), 1);
const Extension* extension_c = InstallExtension(
test_dir.AppendASCII("empty_browser_action_gamma.crx"), 1);
ASSERT_TRUE(extension_a);
ASSERT_TRUE(extension_b);
ASSERT_TRUE(extension_c);
ASSERT_EQ(size_before + 3, service->extensions()->size());
ASSERT_EQ(3, GetBrowserActionsBar().NumberOfBrowserActions());
extensions::ExtensionPrefs* prefs =
extensions::ExtensionPrefs::Get(browser()->profile());
prefs->SetIsIncognitoEnabled(extension_a->id(), true);
prefs->SetIsIncognitoEnabled(extension_c->id(), true);
Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile();
Browser* incognito_browser =
new Browser(Browser::CreateParams(incognito_profile,
browser()->host_desktop_type()));
BrowserActionTestUtil incognito_bar(incognito_browser);
ui_test_utils::OpenURLOffTheRecord(browser()->profile(), GURL("about:blank"));
ASSERT_EQ(2, incognito_bar.NumberOfBrowserActions());
EXPECT_EQ(kTooltipA, GetBrowserActionsBar().GetTooltip(0));
EXPECT_EQ(kTooltipB, GetBrowserActionsBar().GetTooltip(1));
EXPECT_EQ(kTooltipC, GetBrowserActionsBar().GetTooltip(2));
EXPECT_EQ(kTooltipA, incognito_bar.GetTooltip(0));
EXPECT_EQ(kTooltipC, incognito_bar.GetTooltip(1));
ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get(
browser()->profile());
toolbar_model->MoveBrowserAction(extension_c, 0);
EXPECT_EQ(kTooltipC, GetBrowserActionsBar().GetTooltip(0));
EXPECT_EQ(kTooltipA, GetBrowserActionsBar().GetTooltip(1));
EXPECT_EQ(kTooltipB, GetBrowserActionsBar().GetTooltip(2));
EXPECT_EQ(kTooltipC, incognito_bar.GetTooltip(0));
EXPECT_EQ(kTooltipA, incognito_bar.GetTooltip(1));
toolbar_model->MoveBrowserAction(extension_b, 1);
EXPECT_EQ(kTooltipC, GetBrowserActionsBar().GetTooltip(0));
EXPECT_EQ(kTooltipB, GetBrowserActionsBar().GetTooltip(1));
EXPECT_EQ(kTooltipA, GetBrowserActionsBar().GetTooltip(2));
EXPECT_EQ(kTooltipC, incognito_bar.GetTooltip(0));
EXPECT_EQ(kTooltipA, incognito_bar.GetTooltip(1));
}
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoSplit) {
ResultCatcher catcher;
const Extension* extension = LoadExtensionWithFlags(
test_data_dir_.AppendASCII("browser_action/split_mode"),
kFlagEnableIncognito);
ASSERT_TRUE(extension) << message_;
Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile();
Browser* incognito_browser =
new Browser(Browser::CreateParams(incognito_profile,
browser()->host_desktop_type()));
ui_test_utils::OpenURLOffTheRecord(browser()->profile(), GURL("about:blank"));
ASSERT_EQ(1,
BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions());
ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get(
browser()->profile());
toolbar_model->ExecuteBrowserAction(extension, browser(), NULL, true);
ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
toolbar_model->ExecuteBrowserAction(extension, incognito_browser, NULL, true);
ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
}
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_CloseBackgroundPage) {
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("browser_action/close_background")));
const Extension* extension = GetSingleLoadedExtension();
extensions::ProcessManager* manager =
extensions::ExtensionSystem::Get(browser()->profile())->process_manager();
ASSERT_TRUE(manager->GetBackgroundHostForExtension(extension->id()));
ExtensionAction* action = GetBrowserAction(*extension);
ASSERT_EQ("", action->GetBadgeText(ExtensionAction::kDefaultTabId));
content::WindowedNotificationObserver host_destroyed_observer(
chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::NotificationService::AllSources());
ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get(
browser()->profile());
toolbar_model->ExecuteBrowserAction(extension, browser(), NULL, true);
host_destroyed_observer.Wait();
ASSERT_FALSE(manager->GetBackgroundHostForExtension(extension->id()));
ASSERT_EQ("X", action->GetBadgeText(ExtensionAction::kDefaultTabId));
}
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BadgeBackgroundColor) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(RunExtensionTest("browser_action/color")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
ExtensionAction* action = GetBrowserAction(*extension);
ASSERT_EQ(SkColorSetARGB(255, 255, 0, 0),
action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId));
ResultCatcher catcher;
ui_test_utils::NavigateToURL(browser(),
GURL(extension->GetResourceURL("update.html")));
ASSERT_TRUE(catcher.GetNextResult());
ASSERT_EQ(SkColorSetARGB(255, 0, 255, 0),
action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId));
ui_test_utils::NavigateToURL(browser(),
GURL(extension->GetResourceURL("update2.html")));
ASSERT_TRUE(catcher.GetNextResult());
ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255),
action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId));
}
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Getters) {
ASSERT_TRUE(RunExtensionTest("browser_action/getters")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
ResultCatcher catcher;
ui_test_utils::NavigateToURL(browser(),
GURL(extension->GetResourceURL("update.html")));
ASSERT_TRUE(catcher.GetNextResult());
ui_test_utils::NavigateToURL(browser(),
GURL(extension->GetResourceURL("update2.html")));
ASSERT_TRUE(catcher.GetNextResult());
}
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, TestTriggerBrowserAction) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(RunExtensionTest("trigger_actions/browser_action")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
ui_test_utils::NavigateToURL(
browser(),
test_server()->GetURL("files/simple.html"));
ExtensionAction* browser_action = GetBrowserAction(*extension);
EXPECT_TRUE(browser_action != NULL);
{
ResultCatcher catcher;
GetBrowserActionsBar().Press(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");
}
}
}