summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-05 12:51:43 +0000
committerdbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-05 12:51:43 +0000
commit932455407a6870e79bdf04615121b6a9a1766f01 (patch)
treedbd17fc73d7e99c620690f7324fdb5c5905d5e67
parentdb43338a7e82ebf6dfcc9555d794a5990a426781 (diff)
downloadchromium_src-932455407a6870e79bdf04615121b6a9a1766f01.zip
chromium_src-932455407a6870e79bdf04615121b6a9a1766f01.tar.gz
chromium_src-932455407a6870e79bdf04615121b6a9a1766f01.tar.bz2
[test fixlet] Add tests for ZoomBubbleGTK.
TEST=ZoomBubbleGtkTest.* pass on bots. BUG=None Review URL: https://chromiumcodereview.appspot.com/11032028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160354 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/gtk/location_bar_view_gtk_browsertest.cc7
-rw-r--r--chrome/browser/ui/gtk/zoom_bubble_gtk.cc13
-rw-r--r--chrome/browser/ui/gtk/zoom_bubble_gtk.h17
-rw-r--r--chrome/browser/ui/gtk/zoom_bubble_gtk_browsertest.cc186
-rw-r--r--chrome/chrome_tests.gypi1
5 files changed, 216 insertions, 8 deletions
diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk_browsertest.cc b/chrome/browser/ui/gtk/location_bar_view_gtk_browsertest.cc
index 19226fe..53b3fe9 100644
--- a/chrome/browser/ui/gtk/location_bar_view_gtk_browsertest.cc
+++ b/chrome/browser/ui/gtk/location_bar_view_gtk_browsertest.cc
@@ -128,9 +128,9 @@ IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, ZoomInTwiceAndReset) {
ZoomIn();
int zoom_level = GetZoomPercent(contents);
ZoomIn();
- DCHECK_GT(GetZoomPercent(contents), zoom_level);
-
+ EXPECT_GT(GetZoomPercent(contents), zoom_level);
ExpectZoomedIn(contents);
+
EXPECT_TRUE(ZoomIconIsShowing());
ExpectIconIsResource(IDR_ZOOM_PLUS);
ExpectTooltipContainsZoom();
@@ -160,8 +160,9 @@ IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, ZoomOutTwiceAndReset) {
ZoomOut();
int zoom_level = GetZoomPercent(contents);
ZoomOut();
- DCHECK_LT(GetZoomPercent(contents), zoom_level);
+ EXPECT_LT(GetZoomPercent(contents), zoom_level);
ExpectZoomedOut(contents);
+
EXPECT_TRUE(ZoomIconIsShowing());
ExpectIconIsResource(IDR_ZOOM_MINUS);
ExpectTooltipContainsZoom();
diff --git a/chrome/browser/ui/gtk/zoom_bubble_gtk.cc b/chrome/browser/ui/gtk/zoom_bubble_gtk.cc
index 89bdbf5..a83338e 100644
--- a/chrome/browser/ui/gtk/zoom_bubble_gtk.cc
+++ b/chrome/browser/ui/gtk/zoom_bubble_gtk.cc
@@ -20,9 +20,6 @@
namespace {
-// Pointer to singleton object (NULL if no bubble is open).
-ZoomBubbleGtk* g_bubble = NULL;
-
// Number of milliseconds the bubble should stay open for if it will auto-close.
const int kBubbleCloseDelay = 1500;
@@ -34,6 +31,9 @@ const int kBubbleAnchorHeight = 25;
} // namespace
// static
+ZoomBubbleGtk* ZoomBubbleGtk::g_bubble = NULL;
+
+// static
void ZoomBubbleGtk::Show(GtkWidget* anchor,
TabContents* tab_contents,
bool auto_close) {
@@ -61,6 +61,11 @@ void ZoomBubbleGtk::Close() {
g_bubble->CloseBubble();
}
+// static
+bool ZoomBubbleGtk::IsShowing() {
+ return g_bubble != NULL;
+}
+
ZoomBubbleGtk::ZoomBubbleGtk(GtkWidget* anchor,
TabContents* tab_contents,
bool auto_close)
@@ -158,7 +163,7 @@ void ZoomBubbleGtk::Refresh() {
StartTimerIfNecessary();
}
-void ZoomBubbleGtk::StartTimerIfNecessary() {
+void ZoomBubbleGtk::StartTimerIfNecessaryInternal() {
if (!auto_close_ || mouse_inside_)
return;
diff --git a/chrome/browser/ui/gtk/zoom_bubble_gtk.h b/chrome/browser/ui/gtk/zoom_bubble_gtk.h
index a46c9f2..cac7fcf 100644
--- a/chrome/browser/ui/gtk/zoom_bubble_gtk.h
+++ b/chrome/browser/ui/gtk/zoom_bubble_gtk.h
@@ -23,12 +23,21 @@ class ZoomBubbleGtk {
// Closes the zoom bubble.
static void Close();
+ // Whether the zoom bubble is currently showing.
+ static bool IsShowing();
+
private:
ZoomBubbleGtk(GtkWidget* anchor, TabContents* tab_contents, bool auto_close);
virtual ~ZoomBubbleGtk();
// Convenience method to start |timer_| if |auto_close_| is true.
- void StartTimerIfNecessary();
+ void StartTimerIfNecessary() {
+#if !defined(UNIT_TEST)
+ // Don't hide the bubble on a timeout in the tests as it makes them flakey.
+ StartTimerIfNecessaryInternal();
+#endif
+ }
+ void StartTimerIfNecessaryInternal();
// Stops any close timer if |timer_| is currently running.
void StopTimerIfNecessary();
@@ -52,6 +61,12 @@ class ZoomBubbleGtk {
CHROMEGTK_CALLBACK_1(ZoomBubbleGtk, gboolean, OnMouseLeave,
GdkEventCrossing*);
+ // Friend the tests so they can access the static bubble.
+ friend class ZoomBubbleGtkTest;
+
+ // Pointer to singleton object (NULL if no bubble is open).
+ static ZoomBubbleGtk* g_bubble;
+
// Whether the currently displayed bubble will automatically close.
bool auto_close_;
diff --git a/chrome/browser/ui/gtk/zoom_bubble_gtk_browsertest.cc b/chrome/browser/ui/gtk/zoom_bubble_gtk_browsertest.cc
new file mode 100644
index 0000000..e5fad70
--- /dev/null
+++ b/chrome/browser/ui/gtk/zoom_bubble_gtk_browsertest.cc
@@ -0,0 +1,186 @@
+// Copyright (c) 2012 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 <gtk/gtk.h>
+
+#include "base/string_number_conversions.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_commands.h"
+#include "chrome/browser/ui/browser_tabstrip.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/gtk/browser_toolbar_gtk.h"
+#include "chrome/browser/ui/gtk/browser_window_gtk.h"
+#include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
+#include "chrome/browser/ui/gtk/view_id_util.h"
+#include "chrome/browser/ui/gtk/zoom_bubble_gtk.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_types.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/common/page_zoom.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+// TODO(dbeam): share some testing code with LocationBarViewGtkZoomTest.
+
+namespace {
+
+int GetZoomPercent(content::WebContents* contents) {
+ bool dummy;
+ return contents->GetZoomPercent(&dummy, &dummy);
+}
+
+void ExpectZoomedIn(content::WebContents* contents) {
+ EXPECT_GT(GetZoomPercent(contents), 100);
+}
+
+void ExpectZoomedOut(content::WebContents* contents) {
+ EXPECT_LT(GetZoomPercent(contents), 100);
+}
+
+void ExpectAtDefaultZoom(content::WebContents* contents) {
+ EXPECT_EQ(GetZoomPercent(contents), 100);
+}
+
+}
+
+class ZoomBubbleGtkTest : public InProcessBrowserTest {
+ public:
+ ZoomBubbleGtkTest() {}
+ virtual ~ZoomBubbleGtkTest() {}
+
+ protected:
+ ZoomBubbleGtk* GetZoomBubble() {
+ return ZoomBubbleGtk::g_bubble;
+ }
+
+ bool ZoomBubbleIsShowing() {
+ return ZoomBubbleGtk::IsShowing();
+ }
+
+ void ExpectLabelTextContainsZoom() {
+ std::string label(gtk_label_get_text(GTK_LABEL(GetZoomBubble()->label_)));
+ content::WebContents* contents = chrome::GetActiveWebContents(browser());
+ std::string zoom_percent = base::IntToString(GetZoomPercent(contents));
+ EXPECT_FALSE(label.find(zoom_percent) == std::string::npos);
+ }
+
+ void ResetZoom() {
+ WaitForZoom(content::PAGE_ZOOM_RESET);
+ }
+
+ content::WebContents* SetUpTest() {
+ TearDown();
+ content::WebContents* contents = chrome::GetActiveWebContents(browser());
+ ResetZoom();
+ ExpectAtDefaultZoom(contents);
+ return contents;
+ }
+
+ void TearDown() {
+ ZoomBubbleGtk::Close();
+ }
+
+ void ZoomIn() {
+ WaitForZoom(content::PAGE_ZOOM_IN);
+ }
+
+ void ZoomOut() {
+ WaitForZoom(content::PAGE_ZOOM_OUT);
+ }
+
+ private:
+ void WaitForZoom(content::PageZoom zoom_action) {
+ content::WindowedNotificationObserver zoom_observer(
+ content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
+ content::NotificationService::AllSources());
+ chrome::Zoom(browser(), zoom_action);
+ zoom_observer.Wait();
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(ZoomBubbleGtkTest);
+};
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, BubbleSanityTest) {
+ ResetZoom();
+
+ // The bubble assumes it shows only at non-default zoom levels.
+ ZoomIn();
+
+ ZoomBubbleGtk::Close();
+ DCHECK(!GetZoomBubble());
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+
+ GtkWidget* window = GTK_WIDGET(browser()->window()->GetNativeWindow());
+ GtkWidget* zoom_icon = ViewIDUtil::GetWidget(window, VIEW_ID_ZOOM_BUTTON);
+ DCHECK(zoom_icon);
+
+ TabContents* tab_contents = chrome::GetActiveTabContents(browser());
+ DCHECK(tab_contents);
+
+ // Force show a bubble.
+ ZoomBubbleGtk::Show(zoom_icon, tab_contents, true);
+ DCHECK(GetZoomBubble());
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedInAndBack) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomIn();
+ ExpectZoomedIn(contents);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContainsZoom();
+
+ ZoomOut();
+ ExpectAtDefaultZoom(contents);
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, ZoomInTwiceAndReset) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomIn();
+ int zoom_level = GetZoomPercent(contents);
+ ZoomIn();
+ EXPECT_GT(GetZoomPercent(contents), zoom_level);
+ ExpectZoomedIn(contents);
+
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContainsZoom();
+
+ ResetZoom();
+ ExpectAtDefaultZoom(contents);
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedOutAndBack) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomOut();
+ ExpectZoomedOut(contents);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContainsZoom();
+
+ ZoomIn();
+ ExpectAtDefaultZoom(contents);
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, ZoomOutTwiceAndReset) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomOut();
+ int zoom_level = GetZoomPercent(contents);
+ ZoomOut();
+ EXPECT_LT(GetZoomPercent(contents), zoom_level);
+ ExpectZoomedOut(contents);
+
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContainsZoom();
+
+ ResetZoom();
+ ExpectAtDefaultZoom(contents);
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+}
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 57d997e..c320dc2 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -512,6 +512,7 @@
'browser/task_manager/task_manager_browsertest_util.cc',
'browser/ui/fullscreen/fullscreen_controller_interactive_browsertest.cc',
'browser/ui/gtk/bookmarks/bookmark_bar_gtk_interactive_uitest.cc',
+ 'browser/ui/gtk/zoom_bubble_gtk_browsertest.cc',
'browser/ui/omnibox/action_box_browsertest.cc',
'browser/ui/omnibox/omnibox_view_browsertest.cc',
'browser/ui/panels/detached_panel_browsertest.cc',