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

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: making bubble tests interactive_ui_tests 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..9cca0a2b486584ea867ef653340d92bb89b0fddd
--- /dev/null
+++ b/chrome/browser/ui/gtk/zoom_bubble_gtk_browsertest.cc
@@ -0,0 +1,203 @@
+// 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_commands.h"
+#include "chrome/browser/ui/browser_tabstrip.h"
+#include "chrome/browser/ui/browser.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 "testing/gtest/include/gtest/gtest.h"
+#include "content/public/browser/notification_types.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/test/browser_test_utils.h"
+#include "content/public/test/test_utils.h"
+
+#define ASSERT_ZOOM_EQ(web_contents, percent) \
+ do { \
+ bool dummy; \
+ ASSERT_EQ(web_contents->GetZoomPercent(&dummy, &dummy), percent); \
+ } while (0)
+
+class ZoomBubbleGtkTest : public InProcessBrowserTest,
+ public BrowserWindowTesting {
+ public:
+ ZoomBubbleGtkTest() {
+ }
+
+ virtual ~ZoomBubbleGtkTest() {
+ }
+
+ content::WebContents* SetUpTest() {
+ content::WebContents* contents = chrome::GetActiveWebContents(browser());
+ ResetZoom();
+ return contents;
+ }
+
+ void ResetZoom() {
+ content::WindowedNotificationObserver zoom_observer(
+ content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
+ content::NotificationService::AllSources());
+ chrome::Zoom(browser(), content::PAGE_ZOOM_RESET);
+ zoom_observer.Wait();
+ }
+
+ void ZoomIn() {
+ content::WindowedNotificationObserver zoom_observer(
+ content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
+ content::NotificationService::AllSources());
+ chrome::Zoom(browser(), content::PAGE_ZOOM_IN);
+ zoom_observer.Wait();
+
+ if (GetZoomBubble())
+ GetZoomBubble()->StopTimerIfNecessary(); // To prevent test flakiness.
+ }
+
+ void ZoomOut() {
+ content::WindowedNotificationObserver zoom_observer(
+ content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
+ content::NotificationService::AllSources());
+ chrome::Zoom(browser(), content::PAGE_ZOOM_OUT);
+ zoom_observer.Wait();
+
+ if (GetZoomBubble())
+ GetZoomBubble()->StopTimerIfNecessary(); // To prevent test flakiness.
+ }
+
+ void ExpectLabelTextContains(int percent) {
+ const gchar* text = gtk_label_get_text(GTK_LABEL(GetZoomBubble()->label_));
+ std::string label(text);
+ EXPECT_TRUE(label.find(base::IntToString(percent)) != std::string::npos);
+ }
+
+ ZoomBubbleGtk* GetZoomBubble() {
+ return ZoomBubbleGtk::g_bubble;
+ }
+
+ bool ZoomBubbleIsShowing() {
+ return ZoomBubbleGtk::IsShowing();
+ }
+};
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, BubbleSanityTest) {
+ ResetZoom();
+ ZoomIn();
+
+ ZoomBubbleGtk::Close();
+ DCHECK(!GetZoomBubble());
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+
+ GtkWidget* zoom_icon = static_cast<BrowserWindowGtk*>(browser()->window())->
+ GetToolbar()->GetLocationBarView()->zoom_.get();
+ DCHECK(zoom_icon);
+
+ TabContents* tab_contents = chrome::GetActiveTabContents(browser());
+ DCHECK(tab_contents);
+
+ ZoomBubbleGtk::Show(zoom_icon, tab_contents, true); // Force show a bubble.
+ DCHECK(GetZoomBubble());
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedIn) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomIn();
+ ASSERT_ZOOM_EQ(contents, 110);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(110);
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedInTwice) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomIn(); // 110%.
+ ZoomIn();
+ ASSERT_ZOOM_EQ(contents, 125);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(125);
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedInAndBack) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomIn();
+ ASSERT_ZOOM_EQ(contents, 110);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(110);
+
+ ZoomOut(); // Back to default, in theory.
+ ASSERT_ZOOM_EQ(contents, 100);
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, ZoomInTwiceAndReset) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomIn(); // 110%.
+ ZoomIn();
+ ASSERT_ZOOM_EQ(contents, 125);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(125);
+
+ ResetZoom();
+ ASSERT_ZOOM_EQ(contents, 100);
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedOut) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomOut();
+ ASSERT_ZOOM_EQ(contents, 90);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(90);
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedOutTwice) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomOut(); // 90%.
+ ZoomOut();
+ ASSERT_ZOOM_EQ(contents, 75);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(75);
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedOutAndBack) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomOut();
+ ASSERT_ZOOM_EQ(contents, 90);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(90);
+
+ ZoomIn(); // Back to default, in theory.
+ ASSERT_ZOOM_EQ(contents, 100);
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+}
+
+IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, ZoomOutTwiceAndReset) {
+ content::WebContents* contents = SetUpTest();
+
+ ZoomOut(); // 90%.
+ ZoomOut();
+ ASSERT_ZOOM_EQ(contents, 75);
+ EXPECT_TRUE(ZoomBubbleIsShowing());
+ ExpectLabelTextContains(75);
+
+ ResetZoom();
+ ASSERT_ZOOM_EQ(contents, 100);
+ EXPECT_FALSE(ZoomBubbleIsShowing());
+}
+
+#undef ASSERT_ZOOM_EQ

Powered by Google App Engine
This is Rietveld 408576698