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

Unified Diff: chrome/browser/extensions/api/extension_action/browser_action_apitest.cc

Issue 170843005: Fix BrowserActionApiTest.DynamicBrowserAction interaction with dev-mode highlighting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
diff --git a/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
index 3d63e470db08e38f6a124717f046bc820a669de7..440a3580ae59cfbf4e4f45a84f1f8201153da174 100644
--- a/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
+++ b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/browser_action_test_util.h"
+#include "chrome/browser/extensions/dev_mode_bubble_controller.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"
@@ -22,6 +23,7 @@
#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/chrome_version_info.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_service.h"
@@ -46,18 +48,6 @@ const char kEmptyImageDataError[] =
"of ImageData objects.";
const char kEmptyPathError[] = "The path property must not be empty.";
-// Views implementation of browser action button will return icon whose
-// background will be set.
-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);
-#endif
-
- return icon;
-}
-
bool ImagesAreEqualAtScale(const gfx::ImageSkia& i1,
const gfx::ImageSkia& i2,
float scale) {
@@ -91,13 +81,31 @@ class BrowserActionApiTest : public ExtensionApiTest {
return ExtensionActionManager::Get(browser()->profile())->
GetBrowserAction(extension);
}
+
+ // Views implementation of browser action button will return icon whose
+ // background will be set.
+ 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);
+ // We may have a different background than the default - see
+ // BrowserActionButton::UpdateState.
+ if (extensions::DevModeBubbleController::IsDevModeExtension(extension_))
Jeffrey Yasskin 2014/02/19 01:13:34 Can we pass this extension as a function argument
+ bg = *rb.GetImageSkiaNamed(IDR_BROWSER_ACTION_HIGHLIGHT);
+ return gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon);
+#endif
+
+ return icon;
+ }
+
+ const Extension* 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_;
+ extension_ = GetSingleLoadedExtension();
+ ASSERT_TRUE(extension_) << message_;
// Test that there is a browser action in the toolbar.
ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
@@ -105,11 +113,11 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) {
// Tell the extension to update the browser action state.
ResultCatcher catcher;
ui_test_utils::NavigateToURL(browser(),
- GURL(extension->GetResourceURL("update.html")));
+ GURL(extension_->GetResourceURL("update.html")));
ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
// Test that we received the changes.
- ExtensionAction* action = GetBrowserAction(*extension);
+ 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),
@@ -121,15 +129,15 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) {
ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get(
browser()->profile());
- toolbar_model->ExecuteBrowserAction(extension, browser(), NULL, true);
+ 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_;
+ extension_ = GetSingleLoadedExtension();
+ ASSERT_TRUE(extension_) << message_;
#if defined (OS_MACOSX)
// We need this on mac so we don't loose 2x representations from browser icon
@@ -143,10 +151,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
// We should not be creating icons asynchronously, so we don't need an
// observer.
ExtensionActionIconFactory icon_factory(
- profile(),
- extension,
- GetBrowserAction(*extension),
- NULL);
+ profile(), extension_, GetBrowserAction(*extension_), NULL);
// Test that there is a browser action in the toolbar.
ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0));
@@ -309,8 +314,8 @@ 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_;
+ extension_ = GetSingleLoadedExtension();
Jeffrey Yasskin 2014/02/19 01:13:34 I don't think you have to make this change, since
+ ASSERT_TRUE(extension_) << message_;
// Test that there is a browser action in the toolbar and that it has an icon.
ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
@@ -338,11 +343,10 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest,
// http://code.google.com/p/chromium/issues/detail?id=70829
// Mac used to be ok, but then mac 10.5 started failing too. =(
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_BrowserActionPopup) {
- ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
- "browser_action/popup")));
+ extension_ =
+ LoadExtension(test_data_dir_.AppendASCII("browser_action/popup"));
+ ASSERT_TRUE(extension_) << message_;
BrowserActionTestUtil actions_bar = GetBrowserActionsBar();
- const Extension* extension = GetSingleLoadedExtension();
- ASSERT_TRUE(extension) << message_;
// The extension's popup's size grows by |growFactor| each click.
const int growFactor = 500;
@@ -374,13 +378,13 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_BrowserActionPopup) {
// a popup.
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionAddPopup) {
ASSERT_TRUE(RunExtensionTest("browser_action/add_popup")) << message_;
- const Extension* extension = GetSingleLoadedExtension();
- ASSERT_TRUE(extension) << message_;
+ extension_ = GetSingleLoadedExtension();
+ ASSERT_TRUE(extension_) << message_;
int tab_id = ExtensionTabUtil::GetTabId(
browser()->tab_strip_model()->GetActiveWebContents());
- ExtensionAction* browser_action = GetBrowserAction(*extension);
+ ExtensionAction* browser_action = GetBrowserAction(*extension_);
ASSERT_TRUE(browser_action)
<< "Browser action test extension should have a browser action.";
@@ -413,8 +417,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionAddPopup) {
{
ResultCatcher catcher;
ui_test_utils::NavigateToURL(
- browser(),
- GURL(extension->GetResourceURL("change_popup.html")));
+ browser(), GURL(extension_->GetResourceURL("change_popup.html")));
ASSERT_TRUE(catcher.GetNextResult());
}
@@ -430,13 +433,13 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionAddPopup) {
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionRemovePopup) {
// Load the extension, which has a browser action with a default popup.
ASSERT_TRUE(RunExtensionTest("browser_action/remove_popup")) << message_;
- const Extension* extension = GetSingleLoadedExtension();
- ASSERT_TRUE(extension) << message_;
+ extension_ = GetSingleLoadedExtension();
+ ASSERT_TRUE(extension_) << message_;
int tab_id = ExtensionTabUtil::GetTabId(
browser()->tab_strip_model()->GetActiveWebContents());
- ExtensionAction* browser_action = GetBrowserAction(*extension);
+ ExtensionAction* browser_action = GetBrowserAction(*extension_);
ASSERT_TRUE(browser_action)
<< "Browser action test extension should have a browser action.";
@@ -449,8 +452,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionRemovePopup) {
{
ResultCatcher catcher;
ui_test_utils::NavigateToURL(
- browser(),
- GURL(extension->GetResourceURL("remove_popup.html")));
+ browser(), GURL(extension_->GetResourceURL("remove_popup.html")));
ASSERT_TRUE(catcher.GetNextResult());
}
@@ -465,8 +467,8 @@ 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_;
+ extension_ = GetSingleLoadedExtension();
+ ASSERT_TRUE(extension_) << message_;
// Test that there is a browser action in the toolbar.
ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
@@ -484,8 +486,10 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoBasic) {
// Now enable the extension in incognito mode, and test that the browser
// action shows up. Note that we don't update the existing window at the
// moment, so we just create a new one.
- extensions::ExtensionSystem::Get(browser()->profile())->extension_service()->
- extension_prefs()->SetIsIncognitoEnabled(extension->id(), true);
+ extensions::ExtensionSystem::Get(browser()->profile())
+ ->extension_service()
+ ->extension_prefs()
+ ->SetIsIncognitoEnabled(extension_->id(), true);
chrome::CloseWindow(incognito_browser);
incognito_browser =
@@ -577,10 +581,10 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoDragging) {
// extensions.
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoSplit) {
ResultCatcher catcher;
- const Extension* extension = LoadExtensionWithFlags(
+ extension_ = LoadExtensionWithFlags(
test_data_dir_.AppendASCII("browser_action/split_mode"),
kFlagEnableIncognito);
- ASSERT_TRUE(extension) << message_;
+ ASSERT_TRUE(extension_) << message_;
// Open an incognito window.
Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile();
@@ -595,27 +599,28 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoSplit) {
// A click in the regular profile should open a tab in the regular profile.
ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get(
browser()->profile());
- toolbar_model->ExecuteBrowserAction(extension, browser(), NULL, true);
+ toolbar_model->ExecuteBrowserAction(extension_, browser(), NULL, true);
ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
// A click in the incognito profile should open a tab in the
// incognito profile.
- toolbar_model->ExecuteBrowserAction(extension, incognito_browser, NULL, true);
+ toolbar_model->ExecuteBrowserAction(
+ extension_, incognito_browser, NULL, true);
ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
}
// Disabled because of failures (crashes) on ASAN bot.
// See http://crbug.com/98861.
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_CloseBackgroundPage) {
- ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
- "browser_action/close_background")));
- const Extension* extension = GetSingleLoadedExtension();
+ extension_ = LoadExtension(
+ test_data_dir_.AppendASCII("browser_action/close_background"));
+ ASSERT_TRUE(extension_) << message_;
// There is a background page and a browser action with no badge text.
extensions::ProcessManager* manager =
extensions::ExtensionSystem::Get(browser()->profile())->process_manager();
- ASSERT_TRUE(manager->GetBackgroundHostForExtension(extension->id()));
- ExtensionAction* action = GetBrowserAction(*extension);
+ ASSERT_TRUE(manager->GetBackgroundHostForExtension(extension_->id()));
+ ExtensionAction* action = GetBrowserAction(*extension_);
ASSERT_EQ("", action->GetBadgeText(ExtensionAction::kDefaultTabId));
content::WindowedNotificationObserver host_destroyed_observer(
@@ -625,42 +630,42 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_CloseBackgroundPage) {
// Click the browser action.
ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get(
browser()->profile());
- toolbar_model->ExecuteBrowserAction(extension, browser(), NULL, true);
+ toolbar_model->ExecuteBrowserAction(extension_, browser(), NULL, true);
// It can take a moment for the background page to actually get destroyed
// so we wait for the notification before checking that it's really gone
// and the badge text has been set.
host_destroyed_observer.Wait();
- ASSERT_FALSE(manager->GetBackgroundHostForExtension(extension->id()));
+ 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_;
+ extension_ = GetSingleLoadedExtension();
+ ASSERT_TRUE(extension_) << message_;
// Test that there is a browser action in the toolbar.
ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
// Test that CSS values (#FF0000) set color correctly.
- ExtensionAction* action = GetBrowserAction(*extension);
+ ExtensionAction* action = GetBrowserAction(*extension_);
ASSERT_EQ(SkColorSetARGB(255, 255, 0, 0),
action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId));
// Tell the extension to update the browser action state.
ResultCatcher catcher;
ui_test_utils::NavigateToURL(browser(),
- GURL(extension->GetResourceURL("update.html")));
+ GURL(extension_->GetResourceURL("update.html")));
ASSERT_TRUE(catcher.GetNextResult());
// Test that CSS values (#0F0) set color correctly.
ASSERT_EQ(SkColorSetARGB(255, 0, 255, 0),
action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId));
- ui_test_utils::NavigateToURL(browser(),
- GURL(extension->GetResourceURL("update2.html")));
+ ui_test_utils::NavigateToURL(
+ browser(), GURL(extension_->GetResourceURL("update2.html")));
ASSERT_TRUE(catcher.GetNextResult());
// Test that array values set color correctly.
@@ -670,8 +675,8 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BadgeBackgroundColor) {
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Getters) {
ASSERT_TRUE(RunExtensionTest("browser_action/getters")) << message_;
- const Extension* extension = GetSingleLoadedExtension();
- ASSERT_TRUE(extension) << message_;
+ extension_ = GetSingleLoadedExtension();
+ ASSERT_TRUE(extension_) << message_;
// Test that there is a browser action in the toolbar.
ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
@@ -679,12 +684,12 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Getters) {
// Test the getters for defaults.
ResultCatcher catcher;
ui_test_utils::NavigateToURL(browser(),
- GURL(extension->GetResourceURL("update.html")));
+ GURL(extension_->GetResourceURL("update.html")));
ASSERT_TRUE(catcher.GetNextResult());
// Test the getters for a specific tab.
- ui_test_utils::NavigateToURL(browser(),
- GURL(extension->GetResourceURL("update2.html")));
+ ui_test_utils::NavigateToURL(
+ browser(), GURL(extension_->GetResourceURL("update2.html")));
ASSERT_TRUE(catcher.GetNextResult());
}
@@ -693,8 +698,8 @@ 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_;
+ extension_ = GetSingleLoadedExtension();
+ ASSERT_TRUE(extension_) << message_;
// Test that there is a browser action in the toolbar.
ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
@@ -703,7 +708,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, TestTriggerBrowserAction) {
browser(),
test_server()->GetURL("files/simple.html"));
- ExtensionAction* browser_action = GetBrowserAction(*extension);
+ ExtensionAction* browser_action = GetBrowserAction(*extension_);
EXPECT_TRUE(browser_action != NULL);
// Simulate a click on the browser action icon.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698