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

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: TODO() + comment fix Created 8 years, 3 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..dea282fb2fe9e915a30e562f4251832f054d4e2c
--- /dev/null
+++ b/chrome/browser/ui/gtk/zoom_bubble_gtk_browsertest.cc
@@ -0,0 +1,198 @@
+// 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/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"
+
+class ZoomBubbleGtkTest : public InProcessBrowserTest {
+ public:
+ ZoomBubbleGtkTest() {
+ }
+
+ virtual ~ZoomBubbleGtkTest() {
+ }
+
+ protected:
+ ZoomBubbleGtk* GetZoomBubble() {
+ return ZoomBubbleGtk::g_bubble;
+ }
+
+ bool ZoomBubbleIsShowing() {
+ return ZoomBubbleGtk::IsShowing();
+ }
+
+ void ExpectLabelTextContains(int percent) {
+ const gchar* text = gtk_label_get_text(GTK_LABEL(GetZoomBubble()->label_));
+ std::string label(text);
Evan Stade 2012/10/02 08:05:58 combine L42-43
Dan Beam 2012/10/02 15:53:23 Done.
+ EXPECT_TRUE(label.find(base::IntToString(percent)) != std::string::npos);
Evan Stade 2012/10/02 08:05:58 nit: slight preference for EXPECT_FALSE ==
Dan Beam 2012/10/02 15:53:23 Done.
+ }
+
+ // TODO(dbeam): share below code with LocationBarViewGtkZoomTest if feasible.
+ void AssertZoomEquals(content::WebContents* contents, int percent) {
+ bool dummy; // Knowing whether we can zoom in or out more isn't required.
Evan Stade 2012/10/02 08:05:58 remove comment
Dan Beam 2012/10/02 15:53:23 Done.
+ ASSERT_EQ(contents->GetZoomPercent(&dummy, &dummy), percent);
+ }
+
+ void ResetZoom() {
+ WaitForZoom(content::PAGE_ZOOM_RESET);
+ }
+
+ content::WebContents* SetUpTest() {
+ content::WebContents* contents = chrome::GetActiveWebContents(browser());
+ ResetZoom();
+ AssertZoomEquals(contents, 100);
+ return contents;
+ }
+
+ void ZoomIn() {
+ WaitForZoom(content::PAGE_ZOOM_IN);
+ if (GetZoomBubble())
+ GetZoomBubble()->StopTimerIfNecessary(); // To prevent test flakiness.
+ }
+
+ void ZoomOut() {
+ WaitForZoom(content::PAGE_ZOOM_OUT);
+ if (GetZoomBubble())
+ GetZoomBubble()->StopTimerIfNecessary(); // To prevent test flakiness.
+ }
+
+ 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();
+ ZoomIn(); // There are assumptions the bubble isn't showing at default zoom.
Evan Stade 2012/10/02 08:05:58 I do not understand this comment.
Dan Beam 2012/10/02 15:53:23 Hopefully clarified.
+
+ ZoomBubbleGtk::Close();
+ DCHECK(!GetZoomBubble());
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+
+ GtkWidget* zoom_icon = static_cast<BrowserWindowGtk*>(browser()->window())->
+ GetToolbar()->GetLocationBarView()->zoom_.get();
Evan Stade 2012/10/02 08:05:58 there's a less fragile way to do this: see ViewID
Dan Beam 2012/10/02 16:41:42 Done.
+ DCHECK(zoom_icon);
+
+ TabContents* tab_contents = chrome::GetActiveTabContents(browser());
+ DCHECK(tab_contents);
+
+ ZoomBubbleGtk::Show(zoom_icon, tab_contents, true); // Force show a bubble.
Evan Stade 2012/10/02 08:05:58 you seem to love these same-line comments but the
Dan Beam 2012/10/02 15:53:23 Done.
+ DCHECK(GetZoomBubble());
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedIn) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomIn();
+ AssertZoomEquals(contents, 110);
Evan Stade 2012/10/02 08:05:58 instead of testing for an exact value, you should
Dan Beam 2012/10/02 15:53:23 Done.
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(110);
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedInTwice) {
Evan Stade 2012/10/02 08:05:58 subset of ZoomInTwiceAndReset
Dan Beam 2012/10/02 15:53:23 Done.
+ content::WebContents* contents = SetUpTest();
+
+ ZoomIn(); // 110%.
+ ZoomIn();
+ AssertZoomEquals(contents, 125);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(125);
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedInAndBack) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomIn();
+ AssertZoomEquals(contents, 110);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(110);
+
+ ZoomOut(); // Back to default, in theory.
+ AssertZoomEquals(contents, 100);
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, ZoomInTwiceAndReset) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomIn(); // 110%.
+ ZoomIn();
+ AssertZoomEquals(contents, 125);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(125);
+
+ ResetZoom();
+ AssertZoomEquals(contents, 100);
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedOut) {
Evan Stade 2012/10/02 08:05:58 this test is a subset of DefaultToZoomedOutAndBack
Dan Beam 2012/10/02 15:53:23 Done.
+ content::WebContents* contents = SetUpTest();
+
+ ZoomOut();
+ AssertZoomEquals(contents, 90);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(90);
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedOutTwice) {
Evan Stade 2012/10/02 08:05:58 this test is a subset of ZoomOutTwiceAndReset
Dan Beam 2012/10/02 15:53:23 Done.
+ content::WebContents* contents = SetUpTest();
+
+ ZoomOut(); // 90%.
+ ZoomOut();
+ AssertZoomEquals(contents, 75);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(75);
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedOutAndBack) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomOut();
+ AssertZoomEquals(contents, 90);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(90);
+
+ ZoomIn(); // Back to default, in theory.
+ AssertZoomEquals(contents, 100);
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, ZoomOutTwiceAndReset) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomOut(); // 90%.
+ ZoomOut();
+ AssertZoomEquals(contents, 75);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(75);
+
+ ResetZoom();
+ AssertZoomEquals(contents, 100);
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+}

Powered by Google App Engine
This is Rietveld 408576698