diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-19 21:09:14 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-19 21:09:14 +0000 |
commit | cff386ccf5eb4de8bc409b85da0855e610824b24 (patch) | |
tree | 0a1b9d4c4abc26258d4b0f1cc9bac4bf326913de /chrome | |
parent | 76fbe717255e22a0d326b518165750e8d27a82cb (diff) | |
download | chromium_src-cff386ccf5eb4de8bc409b85da0855e610824b24.zip chromium_src-cff386ccf5eb4de8bc409b85da0855e610824b24.tar.gz chromium_src-cff386ccf5eb4de8bc409b85da0855e610824b24.tar.bz2 |
Port BrowserActionApiTest.BrowserActionPopup to linux.
Also make the test proprely wait for the EXTENSION_HOST_DID_STOP_LOADING signal.
BUG=29710
TEST=compiles
Review URL: http://codereview.chromium.org/515065
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36544 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/extensions/browser_action_apitest.cc | 26 | ||||
-rw-r--r-- | chrome/browser/extensions/browser_action_test_util.h | 3 | ||||
-rw-r--r-- | chrome/browser/extensions/browser_action_test_util_gtk.cc | 31 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_browsertest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/extension_popup_gtk.cc | 16 | ||||
-rw-r--r-- | chrome/browser/gtk/extension_popup_gtk.h | 15 | ||||
-rw-r--r-- | chrome/browser/gtk/extension_view_gtk.cc | 12 | ||||
-rw-r--r-- | chrome/browser/gtk/extension_view_gtk.h | 6 |
8 files changed, 83 insertions, 28 deletions
diff --git a/chrome/browser/extensions/browser_action_apitest.cc b/chrome/browser/extensions/browser_action_apitest.cc index 0ef8f9b..1eb1a3b 100644 --- a/chrome/browser/extensions/browser_action_apitest.cc +++ b/chrome/browser/extensions/browser_action_apitest.cc @@ -22,6 +22,8 @@ #include "chrome/common/extensions/extension_action.h" #include "chrome/test/ui_test_utils.h" +static const int kTimeoutMs = 60 * 1000; // 1 minute + class BrowserActionApiTest : public ExtensionApiTest { public: BrowserActionApiTest() {} @@ -32,16 +34,23 @@ class BrowserActionApiTest : public ExtensionApiTest { 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); + { + NotificationRegistrar registrar; + registrar.Add(this, NotificationType::EXTENSION_HOST_DID_STOP_LOADING, + NotificationService::AllSources()); + GetBrowserActionsBar().Press(index); + // If the popup is already showing then we needn't wait for the + // notification before proceeding. + if (!GetBrowserActionsBar().HasPopup()) { + MessageLoop::current()->PostDelayedTask( + FROM_HERE, new MessageLoop::QuitTask, kTimeoutMs); + } + ui_test_utils::RunMessageLoop(); + } EXPECT_TRUE(GetBrowserActionsBar().HasPopup()); - EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); return GetBrowserActionsBar().GetPopupBounds(); } -#endif // !defined(TOOLKIT_GTK) }; IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) { @@ -141,14 +150,10 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, TabSpecificBrowserActionState) { EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0)); } -// 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; - // The extension's popup's size grows by |growFactor| each click. const int growFactor = 500; gfx::Size minSize = BrowserActionTestUtil::GetMinPopupSize(); @@ -173,4 +178,3 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionPopup) { EXPECT_EQ(maxSize, bounds.size()); EXPECT_TRUE(GetBrowserActionsBar().HidePopup()); } -#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 c76930f..6af89b4 100644 --- a/chrome/browser/extensions/browser_action_test_util.h +++ b/chrome/browser/extensions/browser_action_test_util.h @@ -30,8 +30,6 @@ 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(); @@ -46,7 +44,6 @@ class BrowserActionTestUtil { // 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_gtk.cc b/chrome/browser/extensions/browser_action_test_util_gtk.cc index f58732f..55e6224 100644 --- a/chrome/browser/extensions/browser_action_test_util_gtk.cc +++ b/chrome/browser/extensions/browser_action_test_util_gtk.cc @@ -8,6 +8,8 @@ #include "chrome/browser/browser.h" #include "chrome/browser/browser_window.h" +#include "chrome/browser/gtk/extension_popup_gtk.h" +#include "chrome/browser/gtk/extension_view_gtk.h" #include "chrome/browser/gtk/view_id_util.h" namespace { @@ -57,3 +59,32 @@ std::string BrowserActionTestUtil::GetTooltip(int index) { g_free(text); return tooltip; } + +bool BrowserActionTestUtil::HasPopup() { + return ExtensionPopupGtk::get_current_extension_popup() != NULL; +} + +gfx::Rect BrowserActionTestUtil::GetPopupBounds() { + ExtensionPopupGtk* popup = ExtensionPopupGtk::get_current_extension_popup(); + if (popup) + return popup->GetViewBounds(); + return gfx::Rect(); +} + +bool BrowserActionTestUtil::HidePopup() { + ExtensionPopupGtk* popup = ExtensionPopupGtk::get_current_extension_popup(); + if (popup) + return popup->DestroyPopup(); + return false; +} + +// static +gfx::Size BrowserActionTestUtil::GetMinPopupSize() { + // On Linux we actually just limit the size of the extension view. + return gfx::Size(ExtensionViewGtk::kMinWidth, ExtensionViewGtk::kMinHeight); +} + +// static +gfx::Size BrowserActionTestUtil::GetMaxPopupSize() { + return gfx::Size(ExtensionViewGtk::kMaxWidth, ExtensionViewGtk::kMaxHeight); +} diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc index e32f8be..f41b221 100644 --- a/chrome/browser/extensions/extension_browsertest.cc +++ b/chrome/browser/extensions/extension_browsertest.cc @@ -23,12 +23,10 @@ #include "chrome/common/notification_type.h" #include "chrome/test/ui_test_utils.h" -namespace { // Amount of time to wait to load an extension. This is purposely obscenely // long because it will only get used in the case of failure and we want to // minimize false positives. static const int kTimeoutMs = 60 * 1000; // 1 minute -}; // Base class for extension browser tests. Provides utilities for loading, // unloading, and installing extensions. diff --git a/chrome/browser/gtk/extension_popup_gtk.cc b/chrome/browser/gtk/extension_popup_gtk.cc index e14ff90..75fab2df 100644 --- a/chrome/browser/gtk/extension_popup_gtk.cc +++ b/chrome/browser/gtk/extension_popup_gtk.cc @@ -16,6 +16,8 @@ #include "chrome/common/notification_service.h" #include "googleurl/src/gurl.h" +ExtensionPopupGtk* ExtensionPopupGtk::current_extension_popup_ = NULL; + ExtensionPopupGtk::ExtensionPopupGtk(Browser* browser, ExtensionHost* host, const gfx::Rect& relative_to) @@ -61,6 +63,10 @@ void ExtensionPopupGtk::ShowPopup() { return; } + // Only one instance should be showing at a time. + DCHECK(!current_extension_popup_); + current_extension_popup_ = this; + // We'll be in the upper-right corner of the window for LTR languages, so we // want to put the arrow at the upper-right corner of the bubble to match the // page and app menus. @@ -77,17 +83,19 @@ void ExtensionPopupGtk::ShowPopup() { this); } -void ExtensionPopupGtk::DestroyPopup() { +bool ExtensionPopupGtk::DestroyPopup() { if (!bubble_) { NOTREACHED(); - return; + return false; } bubble_->Close(); + return true; } void ExtensionPopupGtk::InfoBubbleClosing(InfoBubbleGtk* bubble, bool closed_by_escape) { + current_extension_popup_ = NULL; delete this; } @@ -104,3 +112,7 @@ void ExtensionPopupGtk::Show(const GURL& url, Browser* browser, // This object will delete itself when the info bubble is closed. new ExtensionPopupGtk(browser, host, relative_to); } + +gfx::Rect ExtensionPopupGtk::GetViewBounds() { + return gfx::Rect(host_->view()->native_view()->allocation); +} diff --git a/chrome/browser/gtk/extension_popup_gtk.h b/chrome/browser/gtk/extension_popup_gtk.h index 58578c8..69e8780 100644 --- a/chrome/browser/gtk/extension_popup_gtk.h +++ b/chrome/browser/gtk/extension_popup_gtk.h @@ -41,8 +41,9 @@ class ExtensionPopupGtk : public NotificationObserver, void ShowPopup(); // Destroys the popup widget. This will in turn destroy us since we delete - // ourselves when the info bubble closes. - void DestroyPopup(); + // ourselves when the info bubble closes. Returns true if we successfully + // closed the bubble. + bool DestroyPopup(); Browser* browser_; @@ -57,6 +58,16 @@ class ExtensionPopupGtk : public NotificationObserver, NotificationRegistrar registrar_; + // Used for testing. --------------------------------------------------------- + static ExtensionPopupGtk* get_current_extension_popup() { + return current_extension_popup_; + } + static ExtensionPopupGtk* current_extension_popup_; + + gfx::Rect GetViewBounds(); + + friend class BrowserActionTestUtil; + DISALLOW_COPY_AND_ASSIGN(ExtensionPopupGtk); }; diff --git a/chrome/browser/gtk/extension_view_gtk.cc b/chrome/browser/gtk/extension_view_gtk.cc index cfe0970..36cb94c 100644 --- a/chrome/browser/gtk/extension_view_gtk.cc +++ b/chrome/browser/gtk/extension_view_gtk.cc @@ -8,17 +8,13 @@ #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" -namespace { - // The minimum/maximum dimensions of the extension view. // The minimum is just a little larger than the size of a browser action button. // The maximum is an arbitrary number that should be smaller than most screens. -const int kMinWidth = 25; -const int kMinHeight = 25; -const int kMaxWidth = 800; -const int kMaxHeight = 600; - -} // namespace +const int ExtensionViewGtk::kMinWidth = 25; +const int ExtensionViewGtk::kMinHeight = 25; +const int ExtensionViewGtk::kMaxWidth = 800; +const int ExtensionViewGtk::kMaxHeight = 600; ExtensionViewGtk::ExtensionViewGtk(ExtensionHost* extension_host, Browser* browser) diff --git a/chrome/browser/gtk/extension_view_gtk.h b/chrome/browser/gtk/extension_view_gtk.h index 91d1ded..40c2196 100644 --- a/chrome/browser/gtk/extension_view_gtk.h +++ b/chrome/browser/gtk/extension_view_gtk.h @@ -37,6 +37,12 @@ class ExtensionViewGtk { RenderViewHost* render_view_host() const; + // Declared here for testing. + static const int kMinWidth; + static const int kMinHeight; + static const int kMaxWidth; + static const int kMaxHeight; + private: void CreateWidgetHostView(); |