summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/cocoa/browser_window_controller.h3
-rw-r--r--chrome/browser/cocoa/browser_window_controller.mm4
-rw-r--r--chrome/browser/cocoa/extensions/browser_actions_controller.h4
-rw-r--r--chrome/browser/cocoa/extensions/browser_actions_controller.mm4
-rw-r--r--chrome/browser/cocoa/toolbar_controller.h1
-rw-r--r--chrome/browser/cocoa/toolbar_controller.mm4
-rw-r--r--chrome/browser/extensions/browser_action_apitest.cc158
-rw-r--r--chrome/browser/extensions/browser_action_test_util.h32
-rw-r--r--chrome/browser/extensions/browser_action_test_util_gtk.cc59
-rw-r--r--chrome/browser/extensions/browser_action_test_util_mac.mm46
-rw-r--r--chrome/browser/extensions/browser_action_test_util_views.cc45
11 files changed, 225 insertions, 135 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h
index 988b53f..091babb 100644
--- a/chrome/browser/cocoa/browser_window_controller.h
+++ b/chrome/browser/cocoa/browser_window_controller.h
@@ -217,6 +217,9 @@ class TabStripModelObserverBridge;
// Return a point suitable for the topLeft for a bookmark bubble.
- (NSPoint)topLeftForBubble;
+// Return a weak pointer to the toolbar controller.
+- (ToolbarController*)toolbarController;
+
// Resets any saved state about window growth (due to showing the bookmark bar
// or the download shelf), so that future shrinking will occur from the bottom.
- (void)resetWindowGrowthState;
diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm
index bb615ac..43416bd 100644
--- a/chrome/browser/cocoa/browser_window_controller.mm
+++ b/chrome/browser/cocoa/browser_window_controller.mm
@@ -789,6 +789,10 @@ willPositionSheet:(NSWindow*)sheet
return enable;
}
+- (ToolbarController*)toolbarController {
+ return toolbarController_.get();
+}
+
// Called when the user picks a menu or toolbar item when this window is key.
// Calls through to the browser object to execute the command. This assumes that
// the command is supported and doesn't check, otherwise it would have been
diff --git a/chrome/browser/cocoa/extensions/browser_actions_controller.h b/chrome/browser/cocoa/extensions/browser_actions_controller.h
index cbdc28f..e1c76a9 100644
--- a/chrome/browser/cocoa/extensions/browser_actions_controller.h
+++ b/chrome/browser/cocoa/extensions/browser_actions_controller.h
@@ -84,4 +84,8 @@ extern NSString* const kBrowserActionsChangedNotification;
@end // @interface BrowserActionsController
+@interface BrowserActionsController(TestingAPI)
+- (NSButton*)buttonWithIndex:(int)index;
+@end
+
#endif // CHROME_BROWSER_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_
diff --git a/chrome/browser/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/cocoa/extensions/browser_actions_controller.mm
index 6dacbe0..2549267 100644
--- a/chrome/browser/cocoa/extensions/browser_actions_controller.mm
+++ b/chrome/browser/cocoa/extensions/browser_actions_controller.mm
@@ -460,4 +460,8 @@ class ExtensionsServiceObserverBridge : public NotificationObserver {
return selected_tab->controller().session_id().id();
}
+- (NSButton*)buttonWithIndex:(int)index {
+ return [buttonOrder_ objectAtIndex:(NSUInteger)index];
+}
+
@end
diff --git a/chrome/browser/cocoa/toolbar_controller.h b/chrome/browser/cocoa/toolbar_controller.h
index dfbe5bf..676b0a8 100644
--- a/chrome/browser/cocoa/toolbar_controller.h
+++ b/chrome/browser/cocoa/toolbar_controller.h
@@ -161,6 +161,7 @@ class ToolbarModel;
- (gfx::Rect)locationStackBounds;
// Return a hover button for the current event.
- (NSButton*)hoverButtonForEvent:(NSEvent*)theEvent;
+- (BrowserActionsController*)browserActionsController;
@end
#endif // CHROME_BROWSER_COCOA_TOOLBAR_CONTROLLER_H_
diff --git a/chrome/browser/cocoa/toolbar_controller.mm b/chrome/browser/cocoa/toolbar_controller.mm
index 8a13f25..937fe43 100644
--- a/chrome/browser/cocoa/toolbar_controller.mm
+++ b/chrome/browser/cocoa/toolbar_controller.mm
@@ -274,6 +274,10 @@ class PrefObserverBridge : public NotificationObserver {
return nil;
}
+- (BrowserActionsController*)browserActionsController {
+ return browserActionsController_.get();
+}
+
- (void)mouseMoved:(NSEvent*)theEvent {
NSButton* targetView = [self hoverButtonForEvent:theEvent];
if (hoveredButton_ != targetView) {
diff --git a/chrome/browser/extensions/browser_action_apitest.cc b/chrome/browser/extensions/browser_action_apitest.cc
index db9a9d2..30bcd50 100644
--- a/chrome/browser/extensions/browser_action_apitest.cc
+++ b/chrome/browser/extensions/browser_action_apitest.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_window.h"
+#include "chrome/browser/extensions/browser_action_test_util.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_browser_event_router.h"
#include "chrome/browser/extensions/extension_tabs_module.h"
@@ -23,137 +24,24 @@
#include "chrome/browser/views/browser_actions_container.h"
#include "chrome/browser/views/extensions/extension_popup.h"
#include "chrome/browser/views/toolbar_view.h"
-#elif defined(OS_LINUX)
-#include "chrome/browser/gtk/view_id_util.h"
#endif
-class BrowserActionTest : public ExtensionApiTest {
+class BrowserActionApiTest : public ExtensionApiTest {
public:
- BrowserActionTest() { }
- virtual ~BrowserActionTest() { }
+ BrowserActionApiTest() {}
+ virtual ~BrowserActionApiTest() {}
- int NumberOfBrowserActions() {
- int rv = -1;
-
-#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
- BrowserActionsContainer* browser_actions =
- browser()->window()->GetBrowserWindowTesting()->GetToolbarView()->
- browser_actions();
- if (browser_actions)
- rv = browser_actions->num_browser_actions();
-#elif defined(OS_LINUX)
- GtkWidget* toolbar = ViewIDUtil::GetWidget(
- GTK_WIDGET(browser()->window()->GetNativeHandle()),
- VIEW_ID_BROWSER_ACTION_TOOLBAR);
-
- if (toolbar) {
- GList* children = gtk_container_get_children(GTK_CONTAINER(toolbar));
- rv = g_list_length(children);
- g_list_free(children);
- }
-#endif
-
- EXPECT_NE(-1, rv);
- return rv;
- }
-
- bool IsIconNull(int index) {
-#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
- BrowserActionsContainer* browser_actions =
- browser()->window()->GetBrowserWindowTesting()->GetToolbarView()->
- browser_actions();
- // We can't ASSERT_TRUE in non-void functions.
- if (browser_actions) {
- return browser_actions->GetBrowserActionViewAt(index)->button()->icon().
- empty();
- } else {
- EXPECT_TRUE(false);
- }
-#elif defined(OS_LINUX)
- GtkWidget* button = GetButton(index);
- if (button)
- return gtk_button_get_image(GTK_BUTTON(button)) == NULL;
- else
- EXPECT_TRUE(false);
-#endif
-
- return false;
- }
-
- void ExecuteBrowserAction(int index) {
-#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
- BrowserActionsContainer* browser_actions =
- browser()->window()->GetBrowserWindowTesting()->GetToolbarView()->
- browser_actions();
- ASSERT_TRUE(browser_actions);
- browser_actions->TestExecuteBrowserAction(index);
-#elif defined(OS_LINUX) || defined(TOOLKIT_VIEWS)
- GtkWidget* button = GetButton(index);
- ASSERT_TRUE(button);
- gtk_button_clicked(GTK_BUTTON(button));
-#endif
- }
-
- std::string GetTooltip(int index) {
-#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
- BrowserActionsContainer* browser_actions =
- browser()->window()->GetBrowserWindowTesting()->GetToolbarView()->
- browser_actions();
- if (browser_actions) {
- std::wstring text;
- EXPECT_TRUE(browser_actions->GetBrowserActionViewAt(0)->button()->
- GetTooltipText(0, 0, &text));
- return WideToUTF8(text);
- }
-#elif defined(OS_LINUX)
- GtkWidget* button = GetButton(index);
- if (button) {
- gchar* text = gtk_widget_get_tooltip_text(button);
- std::string rv = std::string(text);
- g_free(text);
- return rv;
- }
-#endif
- EXPECT_TRUE(false);
- return std::string();
+ BrowserActionTestUtil GetBrowserActionsBar() {
+ return BrowserActionTestUtil(browser());
}
-
- private:
-#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
- GtkWidget* GetButton(int index) {
- GtkWidget* rv = NULL;
- GtkWidget* toolbar = ViewIDUtil::GetWidget(
- GTK_WIDGET(browser()->window()->GetNativeHandle()),
- VIEW_ID_BROWSER_ACTION_TOOLBAR);
-
- if (toolbar) {
- GList* children = gtk_container_get_children(GTK_CONTAINER(toolbar));
- rv = static_cast<GtkWidget*>(g_list_nth(children, index)->data);
- g_list_free(children);
- }
-
- return rv;
- }
-#endif
};
-#if defined(OS_MACOSX)
-// http://crbug.com/29709 port to Mac
-#define MAYBE_Basic DISABLED_Basic
-#define MAYBE_DynamicBrowserAction DISABLED_DynamicBrowserAction
-#define MAYBE_TabSpecificBrowserActionState DISABLED_TabSpecificBrowserActionState
-#else
-#define MAYBE_Basic Basic
-#define MAYBE_DynamicBrowserAction DynamicBrowserAction
-#define MAYBE_TabSpecificBrowserActionState TabSpecificBrowserActionState
-#endif
-
-IN_PROC_BROWSER_TEST_F(BrowserActionTest, MAYBE_Basic) {
+IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) {
StartHTTPServer();
ASSERT_TRUE(RunExtensionTest("browser_action")) << message_;
// Test that there is a browser action in the toolbar.
- ASSERT_EQ(1, NumberOfBrowserActions());
+ ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
// Tell the extension to update the browser action state.
ResultCatcher catcher;
@@ -189,12 +77,12 @@ IN_PROC_BROWSER_TEST_F(BrowserActionTest, MAYBE_Basic) {
ASSERT_TRUE(result);
}
-IN_PROC_BROWSER_TEST_F(BrowserActionTest, MAYBE_DynamicBrowserAction) {
+IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
ASSERT_TRUE(RunExtensionTest("browser_action_no_icon")) << message_;
// Test that there is a browser action in the toolbar and that it has no icon.
- EXPECT_EQ(1, NumberOfBrowserActions());
- EXPECT_TRUE(IsIconNull(0));
+ ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
+ EXPECT_FALSE(GetBrowserActionsBar().HasIcon(0));
// Tell the extension to update the icon using setIcon({imageData:...}).
ResultCatcher catcher;
@@ -205,7 +93,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionTest, MAYBE_DynamicBrowserAction) {
ASSERT_TRUE(catcher.GetNextResult());
// Test that we received the changes.
- EXPECT_FALSE(IsIconNull(0));
+ EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0));
// Tell the extension to update using setIcon({path:...});
ui_test_utils::NavigateToURL(browser(),
@@ -213,41 +101,41 @@ IN_PROC_BROWSER_TEST_F(BrowserActionTest, MAYBE_DynamicBrowserAction) {
ASSERT_TRUE(catcher.GetNextResult());
// Test that we received the changes.
- EXPECT_FALSE(IsIconNull(0));
+ EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0));
// TODO(aa): Would be nice here to actually compare that the pixels change.
}
-IN_PROC_BROWSER_TEST_F(BrowserActionTest, MAYBE_TabSpecificBrowserActionState) {
+IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, TabSpecificBrowserActionState) {
ASSERT_TRUE(RunExtensionTest("browser_action_tab_specific_state")) <<
message_;
// Test that there is a browser action in the toolbar and that it has an icon.
- ASSERT_EQ(1, NumberOfBrowserActions());
- EXPECT_FALSE(IsIconNull(0));
+ ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
+ EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0));
// Execute the action, its title should change.
ResultCatcher catcher;
- ExecuteBrowserAction(0);
+ GetBrowserActionsBar().Press(0);
ASSERT_TRUE(catcher.GetNextResult());
- EXPECT_EQ("Showing icon 2", GetTooltip(0));
+ EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0));
// Open a new tab, the title should go back.
browser()->NewTab();
- EXPECT_EQ("hi!", GetTooltip(0));
+ EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0));
// Go back to first tab, changed title should reappear.
browser()->SelectTabContentsAt(0, true);
- EXPECT_EQ("Showing icon 2", GetTooltip(0));
+ EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0));
// Reload that tab, default title should come back.
ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
- EXPECT_EQ("hi!", GetTooltip(0));
+ EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0));
}
// TODO(estade): http://crbug.com/29710 port to Mac & Linux
#if defined(OS_WIN)
-IN_PROC_BROWSER_TEST_F(BrowserActionTest, BrowserActionPopup) {
+IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionPopup) {
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("popup")));
ResultCatcher catcher;
@@ -269,7 +157,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionTest, BrowserActionPopup) {
ASSERT_TRUE(browser_actions);
// Simulate a click on the browser action and verify the size of the resulting
// popup. The first one tries to be 0x0, so it should be the min values.
- ExecuteBrowserAction(0);
+ GetBrowserActionsBar().Press(0);
EXPECT_TRUE(browser_actions->TestGetPopup() != NULL);
ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
gfx::Rect bounds = browser_actions->TestGetPopup()->view()->bounds();
diff --git a/chrome/browser/extensions/browser_action_test_util.h b/chrome/browser/extensions/browser_action_test_util.h
new file mode 100644
index 0000000..2b7c725
--- /dev/null
+++ b/chrome/browser/extensions/browser_action_test_util.h
@@ -0,0 +1,32 @@
+// 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.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_BROWSER_ACTION_TEST_UTIL_H_
+#define CHROME_BROWSER_EXTENSIONS_BROWSER_ACTION_TEST_UTIL_H_
+
+#include <string>
+
+class Browser;
+
+class BrowserActionTestUtil {
+ public:
+ explicit BrowserActionTestUtil(Browser* browser) : browser_(browser) {}
+
+ // Returns the number of browser action buttons in the window toolbar.
+ int NumberOfBrowserActions();
+
+ // Returns whether the browser action at |index| has a non-null icon.
+ bool HasIcon(int index);
+
+ // Simulates a user click on the browser action button at |index|.
+ void Press(int index);
+
+ // Returns the current tooltip for the browser action button.
+ std::string GetTooltip(int index);
+
+ private:
+ Browser* browser_; // weak
+};
+
+#endif // CHROME_BROWSER_EXTENSIONS_BROWSER_ACTION_TEST_UTIL_H_
diff --git a/chrome/browser/extensions/browser_action_test_util_gtk.cc b/chrome/browser/extensions/browser_action_test_util_gtk.cc
new file mode 100644
index 0000000..f58732f
--- /dev/null
+++ b/chrome/browser/extensions/browser_action_test_util_gtk.cc
@@ -0,0 +1,59 @@
+// 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.
+
+#include "chrome/browser/extensions/browser_action_test_util.h"
+
+#include <gtk/gtk.h>
+
+#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_window.h"
+#include "chrome/browser/gtk/view_id_util.h"
+
+namespace {
+
+GtkWidget* GetButton(Browser* browser, int index) {
+ GtkWidget* button = NULL;
+ GtkWidget* toolbar =
+ ViewIDUtil::GetWidget(GTK_WIDGET(browser->window()->GetNativeHandle()),
+ VIEW_ID_BROWSER_ACTION_TOOLBAR);
+ if (toolbar) {
+ GList* children = gtk_container_get_children(GTK_CONTAINER(toolbar));
+ button = static_cast<GtkWidget*>(g_list_nth(children, index)->data);
+ g_list_free(children);
+ }
+ return button;
+}
+
+} // namespace
+
+int BrowserActionTestUtil::NumberOfBrowserActions() {
+ int count = -1;
+ GtkWidget* toolbar =
+ ViewIDUtil::GetWidget(GTK_WIDGET(browser_->window()->GetNativeHandle()),
+ VIEW_ID_BROWSER_ACTION_TOOLBAR);
+ if (toolbar) {
+ GList* children = gtk_container_get_children(GTK_CONTAINER(toolbar));
+ count = g_list_length(children);
+ g_list_free(children);
+ }
+ return count;
+}
+
+bool BrowserActionTestUtil::HasIcon(int index) {
+ GtkWidget* button = GetButton(browser_, index);
+ return gtk_button_get_image(GTK_BUTTON(button)) != NULL;
+}
+
+void BrowserActionTestUtil::Press(int index) {
+ GtkWidget* button = GetButton(browser_, index);
+ gtk_button_clicked(GTK_BUTTON(button));
+}
+
+std::string BrowserActionTestUtil::GetTooltip(int index) {
+ GtkWidget* button = GetButton(browser_, index);
+ gchar* text = gtk_widget_get_tooltip_text(button);
+ std::string tooltip(text);
+ g_free(text);
+ return tooltip;
+}
diff --git a/chrome/browser/extensions/browser_action_test_util_mac.mm b/chrome/browser/extensions/browser_action_test_util_mac.mm
new file mode 100644
index 0000000..de17e8e
--- /dev/null
+++ b/chrome/browser/extensions/browser_action_test_util_mac.mm
@@ -0,0 +1,46 @@
+// 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.
+
+#include "browser_action_test_util.h"
+
+#include "base/sys_string_conversions.h"
+#include "chrome/browser/browser.h"
+#import "chrome/browser/cocoa/browser_window_cocoa.h"
+#import "chrome/browser/cocoa/browser_window_controller.h"
+#import "chrome/browser/cocoa/extensions/browser_actions_controller.h"
+#import "chrome/browser/cocoa/toolbar_controller.h"
+
+namespace {
+
+BrowserActionsController* GetController(Browser* browser) {
+ BrowserWindowCocoa* window =
+ static_cast<BrowserWindowCocoa*>(browser->window());
+
+ return [[window->cocoa_controller() toolbarController]
+ browserActionsController];
+}
+
+NSButton* GetButton(Browser* browser, int index) {
+ return [GetController(browser) buttonWithIndex:index];
+}
+
+} // namespace
+
+int BrowserActionTestUtil::NumberOfBrowserActions() {
+ return [GetController(browser_) buttonCount];
+}
+
+bool BrowserActionTestUtil::HasIcon(int index) {
+ return [GetButton(browser_, index) image] != nil;
+}
+
+void BrowserActionTestUtil::Press(int index) {
+ NSButton* button = GetButton(browser_, index);
+ [button performClick:nil];
+}
+
+std::string BrowserActionTestUtil::GetTooltip(int index) {
+ NSString* tooltip = [GetButton(browser_, index) toolTip];
+ return base::SysNSStringToUTF8(tooltip);
+}
diff --git a/chrome/browser/extensions/browser_action_test_util_views.cc b/chrome/browser/extensions/browser_action_test_util_views.cc
new file mode 100644
index 0000000..95e8df0
--- /dev/null
+++ b/chrome/browser/extensions/browser_action_test_util_views.cc
@@ -0,0 +1,45 @@
+// 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.
+
+#include "chrome/browser/extensions/browser_action_test_util.h"
+
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_window.h"
+#include "chrome/browser/views/browser_actions_container.h"
+#include "chrome/browser/views/extensions/extension_popup.h"
+#include "chrome/browser/views/toolbar_view.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/ui_test_utils.h"
+
+namespace {
+
+BrowserActionsContainer* GetContainer(Browser* browser) {
+ BrowserActionsContainer* container =
+ browser->window()->GetBrowserWindowTesting()->GetToolbarView()->
+ browser_actions();
+ return container;
+}
+
+} // namespace
+
+int BrowserActionTestUtil::NumberOfBrowserActions() {
+ return GetContainer(browser_)->num_browser_actions();
+}
+
+bool BrowserActionTestUtil::HasIcon(int index) {
+ return !GetContainer(browser_)->GetBrowserActionViewAt(index)->
+ button()->icon().empty();
+}
+
+void BrowserActionTestUtil::Press(int index) {
+ GetContainer(browser_)->TestExecuteBrowserAction(index);
+}
+
+std::string BrowserActionTestUtil::GetTooltip(int index) {
+ std::wstring text;
+ GetContainer(browser_)->GetBrowserActionViewAt(0)->button()->
+ GetTooltipText(0, 0, &text);
+ return WideToUTF8(text);
+}