diff options
author | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-19 01:27:51 +0000 |
---|---|---|
committer | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-19 01:27:51 +0000 |
commit | 73333786fdb1f3b9fb5b4a8d2afda653b0e648c2 (patch) | |
tree | aaede316d84f6264dc705b1577031895fa065941 /chrome/browser/extensions | |
parent | 098267f02562f5636c4e7dd6fc4c52175862cf94 (diff) | |
download | chromium_src-73333786fdb1f3b9fb5b4a8d2afda653b0e648c2.zip chromium_src-73333786fdb1f3b9fb5b4a8d2afda653b0e648c2.tar.gz chromium_src-73333786fdb1f3b9fb5b4a8d2afda653b0e648c2.tar.bz2 |
[Mac] Port browser action popup test to mac.
BUG=29710
TEST=none
Review URL: http://codereview.chromium.org/506069
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35020 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
4 files changed, 107 insertions, 54 deletions
diff --git a/chrome/browser/extensions/browser_action_apitest.cc b/chrome/browser/extensions/browser_action_apitest.cc index 1713b23..0ef8f9b 100644 --- a/chrome/browser/extensions/browser_action_apitest.cc +++ b/chrome/browser/extensions/browser_action_apitest.cc @@ -8,6 +8,8 @@ #include <gtk/gtk.h> #endif +#include "base/gfx/rect.h" +#include "base/gfx/size.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/extensions/browser_action_test_util.h" @@ -20,20 +22,26 @@ #include "chrome/common/extensions/extension_action.h" #include "chrome/test/ui_test_utils.h" -#if defined(OS_WIN) || defined(TOOLKIT_VIEWS) -#include "chrome/browser/views/browser_actions_container.h" -#include "chrome/browser/views/extensions/extension_popup.h" -#include "chrome/browser/views/toolbar_view.h" -#endif - class BrowserActionApiTest : public ExtensionApiTest { public: BrowserActionApiTest() {} virtual ~BrowserActionApiTest() {} + protected: BrowserActionTestUtil GetBrowserActionsBar() { return BrowserActionTestUtil(browser()); } + +// TODO(estade): http://crbug.com/29710 port to Linux +#if !defined(TOOLKIT_GTK) + gfx::Rect OpenPopup(int index) { + ResultCatcher catcher; + GetBrowserActionsBar().Press(index); + EXPECT_TRUE(GetBrowserActionsBar().HasPopup()); + EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); + return GetBrowserActionsBar().GetPopupBounds(); + } +#endif // !defined(TOOLKIT_GTK) }; IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) { @@ -133,63 +141,36 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, TabSpecificBrowserActionState) { EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0)); } -// TODO(estade): http://crbug.com/29710 port to Mac & Linux -#if defined(OS_WIN) +// TODO(estade): http://crbug.com/29710 port to Linux +#if !defined(TOOLKIT_GTK) IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionPopup) { ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( "browser_action/popup"))); ResultCatcher catcher; - // This value is in api_test/popup/popup.html. + // The extension's popup's size grows by |growFactor| each click. const int growFactor = 500; - ASSERT_GT(ExtensionPopup::kMinHeight + growFactor * 2, - ExtensionPopup::kMaxHeight); - ASSERT_GT(ExtensionPopup::kMinWidth + growFactor * 2, - ExtensionPopup::kMaxWidth); - - // Our initial expected size. - int width = ExtensionPopup::kMinWidth; - int height = ExtensionPopup::kMinHeight; - - BrowserActionsContainer* browser_actions = - browser()->window()->GetBrowserWindowTesting()->GetToolbarView()-> - browser_actions(); - ASSERT_TRUE(browser_actions); + gfx::Size minSize = BrowserActionTestUtil::GetMinPopupSize(); + gfx::Size maxSize = BrowserActionTestUtil::GetMaxPopupSize(); + + // Ensure that two clicks will exceed the maximum allowed size. + ASSERT_GT(minSize.height() + growFactor * 2, maxSize.height()); + ASSERT_GT(minSize.width() + growFactor * 2, maxSize.width()); + // 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. - GetBrowserActionsBar().Press(0); - EXPECT_TRUE(browser_actions->TestGetPopup() != NULL); - ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); - gfx::Rect bounds = browser_actions->TestGetPopup()->view()->bounds(); - EXPECT_EQ(width, bounds.width()); - EXPECT_EQ(height, bounds.height()); - browser_actions->HidePopup(); - EXPECT_TRUE(browser_actions->TestGetPopup() == NULL); - - // Do it again, and verify the new bigger size (the popup grows each time it's - // opened). - width = growFactor; - height = growFactor; - browser_actions->TestExecuteBrowserAction(0); - EXPECT_TRUE(browser_actions->TestGetPopup() != NULL); - ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); - bounds = browser_actions->TestGetPopup()->view()->bounds(); - EXPECT_EQ(width, bounds.width()); - EXPECT_EQ(height, bounds.height()); - browser_actions->HidePopup(); - EXPECT_TRUE(browser_actions->TestGetPopup() == NULL); + gfx::Rect bounds = OpenPopup(0); + EXPECT_EQ(minSize, bounds.size()); + EXPECT_TRUE(GetBrowserActionsBar().HidePopup()); + + bounds = OpenPopup(0); + EXPECT_EQ(gfx::Size(growFactor, growFactor), bounds.size()); + EXPECT_TRUE(GetBrowserActionsBar().HidePopup()); // One more time, but this time it should be constrained by the max values. - width = ExtensionPopup::kMaxWidth; - height = ExtensionPopup::kMaxHeight; - browser_actions->TestExecuteBrowserAction(0); - EXPECT_TRUE(browser_actions->TestGetPopup() != NULL); - ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); - bounds = browser_actions->TestGetPopup()->view()->bounds(); - EXPECT_EQ(width, bounds.width()); - EXPECT_EQ(height, bounds.height()); - browser_actions->HidePopup(); - EXPECT_TRUE(browser_actions->TestGetPopup() == NULL); + bounds = OpenPopup(0); + EXPECT_EQ(maxSize, bounds.size()); + EXPECT_TRUE(GetBrowserActionsBar().HidePopup()); } -#endif // defined(OS_WIN) +#endif // !defined(TOOLKIT_GTK) diff --git a/chrome/browser/extensions/browser_action_test_util.h b/chrome/browser/extensions/browser_action_test_util.h index 2b7c725..c76930f 100644 --- a/chrome/browser/extensions/browser_action_test_util.h +++ b/chrome/browser/extensions/browser_action_test_util.h @@ -9,6 +9,11 @@ class Browser; +namespace gfx { +class Rect; +class Size; +} // namespace gfx + class BrowserActionTestUtil { public: explicit BrowserActionTestUtil(Browser* browser) : browser_(browser) {} @@ -25,6 +30,24 @@ class BrowserActionTestUtil { // Returns the current tooltip for the browser action button. std::string GetTooltip(int index); +// TODO(estade): http://crbug.com/29710 port to Linux +#if !defined(TOOLKIT_GTK) + // Returns whether a browser action popup is being shown currently. + bool HasPopup(); + + // Returns the bounds of the current browser action popup. + gfx::Rect GetPopupBounds(); + + // Hides the given popup and returns whether the hide was successful. + bool HidePopup(); + + // Returns the minimum allowed size of an extension popup. + static gfx::Size GetMinPopupSize(); + + // Returns the maximum allowed size of an extension popup. + static gfx::Size GetMaxPopupSize(); +#endif + private: Browser* browser_; // weak }; diff --git a/chrome/browser/extensions/browser_action_test_util_mac.mm b/chrome/browser/extensions/browser_action_test_util_mac.mm index de17e8e..1ce7011 100644 --- a/chrome/browser/extensions/browser_action_test_util_mac.mm +++ b/chrome/browser/extensions/browser_action_test_util_mac.mm @@ -4,11 +4,14 @@ #include "browser_action_test_util.h" +#include "base/gfx/rect.h" +#include "base/gfx/size.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/extensions/extension_popup_controller.h" #import "chrome/browser/cocoa/toolbar_controller.h" namespace { @@ -44,3 +47,25 @@ std::string BrowserActionTestUtil::GetTooltip(int index) { NSString* tooltip = [GetButton(browser_, index) toolTip]; return base::SysNSStringToUTF8(tooltip); } + +bool BrowserActionTestUtil::HasPopup() { + return [GetController(browser_) popup] != nil; +} + +gfx::Rect BrowserActionTestUtil::GetPopupBounds() { + NSRect bounds = [[[GetController(browser_) popup] view] bounds]; + return gfx::Rect(NSRectToCGRect(bounds)); +} + +bool BrowserActionTestUtil::HidePopup() { + [GetController(browser_) hidePopup]; + return !HasPopup(); +} + +gfx::Size BrowserActionTestUtil::GetMinPopupSize() { + return gfx::Size(NSSizeToCGSize([ExtensionPopupController minPopupSize])); +} + +gfx::Size BrowserActionTestUtil::GetMaxPopupSize() { + return gfx::Size(NSSizeToCGSize([ExtensionPopupController maxPopupSize])); +} diff --git a/chrome/browser/extensions/browser_action_test_util_views.cc b/chrome/browser/extensions/browser_action_test_util_views.cc index 95e8df0..9af266d 100644 --- a/chrome/browser/extensions/browser_action_test_util_views.cc +++ b/chrome/browser/extensions/browser_action_test_util_views.cc @@ -4,6 +4,8 @@ #include "chrome/browser/extensions/browser_action_test_util.h" +#include "base/gfx/rect.h" +#include "base/gfx/size.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_window.h" @@ -43,3 +45,25 @@ std::string BrowserActionTestUtil::GetTooltip(int index) { GetTooltipText(0, 0, &text); return WideToUTF8(text); } + +bool BrowserActionTestUtil::HasPopup() { + return GetContainer(browser_)->TestGetPopup() != NULL; +} + +gfx::Rect BrowserActionTestUtil::GetPopupBounds() { + return GetContainer(browser_)->TestGetPopup()->view()->bounds(); +} + +bool BrowserActionTestUtil::HidePopup() { + BrowserActionsContainer* container = GetContainer(browser_); + container->HidePopup(); + return !HasPopup(); +} + +gfx::Size BrowserActionTestUtil::GetMinPopupSize() { + return gfx::Size(ExtensionPopup::kMinWidth, ExtensionPopup::kMinHeight); +} + +gfx::Size BrowserActionTestUtil::GetMaxPopupSize() { + return gfx::Size(ExtensionPopup::kMaxWidth, ExtensionPopup::kMaxHeight); +} |