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

Unified Diff: chrome/browser/ui/gtk/zoom_bubble_gtk_browsertest.cc

Issue 10985069: [test fixlet] Add tests for the zoom icon in the location bar on GTK. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 2 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
Index: chrome/browser/ui/gtk/zoom_bubble_gtk_browsertest.cc
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 0000000000000000000000000000000000000000..0066c6816191cc7fd71c2334c15e7386ad1eb3e2
--- /dev/null
+++ b/chrome/browser/ui/gtk/zoom_bubble_gtk_browsertest.cc
@@ -0,0 +1,185 @@
+// 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 AssertZoomedIn(content::WebContents* contents) {
+ ASSERT_GT(GetZoomPercent(contents), 100);
+}
+
+void AssertZoomedOut(content::WebContents* contents) {
+ ASSERT_LT(GetZoomPercent(contents), 100);
+}
+
+void AssertAtDefaultZoom(content::WebContents* contents) {
+ ASSERT_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 ExpectLabelTextContains(int percent) {
+ std::string label(gtk_label_get_text(GTK_LABEL(GetZoomBubble()->label_)));
+ EXPECT_FALSE(label.find(base::IntToString(percent)) == std::string::npos);
+ }
+
+ void ResetZoom() {
+ WaitForZoom(content::PAGE_ZOOM_RESET);
+ }
+
+ content::WebContents* SetUpTest() {
+ content::WebContents* contents = chrome::GetActiveWebContents(browser());
+ ResetZoom();
+ AssertAtDefaultZoom(contents);
+ return contents;
+ }
+
+ void ZoomIn() {
+ WaitForZoom(content::PAGE_ZOOM_IN);
+ MakeTestLessFlakey();
+ }
+
+ void ZoomOut() {
+ WaitForZoom(content::PAGE_ZOOM_OUT);
+ MakeTestLessFlakey();
+ }
+
+ private:
+ void MakeTestLessFlakey() {
+ // Stopping the close timer makes this test less able to accidentally fail
+ // if a bot hangs or IPC takes forever.
+ if (GetZoomBubble())
+ GetZoomBubble()->StopTimerIfNecessary();
+ }
+
+ 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();
+ AssertZoomedIn(contents);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(110);
+
+ ZoomOut();
+ AssertAtDefaultZoom(contents);
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, ZoomInTwiceAndReset) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomIn();
+ ZoomIn();
+ AssertZoomedIn(contents);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(125);
+
+ ResetZoom();
+ AssertAtDefaultZoom(contents);
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedOutAndBack) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomOut();
+ AssertZoomedOut(contents);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(90);
Evan Stade 2012/10/02 18:35:59 I suggested you get rid of these hard-coded values
Dan Beam 2012/10/02 19:34:14 Ah, OK. Done.
+
+ ZoomIn();
+ AssertAtDefaultZoom(contents);
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, ZoomOutTwiceAndReset) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomOut();
+ ZoomOut();
+ AssertZoomedOut(contents);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(75);
+
+ ResetZoom();
+ AssertAtDefaultZoom(contents);
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+}

Powered by Google App Engine
This is Rietveld 408576698