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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <gtk/gtk.h>
6
7 #include "base/string_number_conversions.h"
8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/browser_tabstrip.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h"
13 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
14 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
15 #include "chrome/browser/ui/gtk/zoom_bubble_gtk.h"
16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "content/public/browser/notification_types.h"
20 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/web_contents.h"
22 #include "content/public/test/browser_test_utils.h"
23 #include "content/public/test/test_utils.h"
24
25 #define ASSERT_ZOOM_EQ(web_contents, percent) \
26 do { \
27 bool dummy; \
28 ASSERT_EQ(web_contents->GetZoomPercent(&dummy, &dummy), percent); \
29 } while (0)
30
31 class ZoomBubbleGtkTest : public InProcessBrowserTest,
32 public BrowserWindowTesting {
33 public:
34 ZoomBubbleGtkTest() {
35 }
36
37 virtual ~ZoomBubbleGtkTest() {
38 }
39
40 content::WebContents* SetUpTest() {
41 content::WebContents* contents = chrome::GetActiveWebContents(browser());
42 ResetZoom();
43 return contents;
44 }
45
46 void ResetZoom() {
47 content::WindowedNotificationObserver zoom_observer(
48 content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
49 content::NotificationService::AllSources());
50 chrome::Zoom(browser(), content::PAGE_ZOOM_RESET);
51 zoom_observer.Wait();
52 }
53
54 void ZoomIn() {
55 content::WindowedNotificationObserver zoom_observer(
56 content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
57 content::NotificationService::AllSources());
58 chrome::Zoom(browser(), content::PAGE_ZOOM_IN);
59 zoom_observer.Wait();
60
61 if (GetZoomBubble())
62 GetZoomBubble()->StopTimerIfNecessary(); // To prevent test flakiness.
63 }
64
65 void ZoomOut() {
66 content::WindowedNotificationObserver zoom_observer(
67 content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
68 content::NotificationService::AllSources());
69 chrome::Zoom(browser(), content::PAGE_ZOOM_OUT);
70 zoom_observer.Wait();
71
72 if (GetZoomBubble())
73 GetZoomBubble()->StopTimerIfNecessary(); // To prevent test flakiness.
74 }
75
76 void ExpectLabelTextContains(int percent) {
77 const gchar* text = gtk_label_get_text(GTK_LABEL(GetZoomBubble()->label_));
78 std::string label(text);
79 EXPECT_TRUE(label.find(base::IntToString(percent)) != std::string::npos);
80 }
81
82 ZoomBubbleGtk* GetZoomBubble() {
83 return ZoomBubbleGtk::g_bubble;
84 }
85
86 bool ZoomBubbleIsShowing() {
87 return ZoomBubbleGtk::IsShowing();
88 }
89 };
90
91 IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, BubbleSanityTest) {
92 ResetZoom();
93 ZoomIn();
94
95 ZoomBubbleGtk::Close();
96 DCHECK(!GetZoomBubble());
97 EXPECT_FALSE(ZoomBubbleIsShowing());
98
99 GtkWidget* zoom_icon = static_cast<BrowserWindowGtk*>(browser()->window())->
100 GetToolbar()->GetLocationBarView()->zoom_.get();
101 DCHECK(zoom_icon);
102
103 TabContents* tab_contents = chrome::GetActiveTabContents(browser());
104 DCHECK(tab_contents);
105
106 ZoomBubbleGtk::Show(zoom_icon, tab_contents, true); // Force show a bubble.
107 DCHECK(GetZoomBubble());
108 EXPECT_TRUE(ZoomBubbleIsShowing());
109 }
110
111 IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedIn) {
112 content::WebContents* contents = SetUpTest();
113
114 ZoomIn();
115 ASSERT_ZOOM_EQ(contents, 110);
116 EXPECT_TRUE(ZoomBubbleIsShowing());
117 ExpectLabelTextContains(110);
118 }
119
120 IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedInTwice) {
121 content::WebContents* contents = SetUpTest();
122
123 ZoomIn(); // 110%.
124 ZoomIn();
125 ASSERT_ZOOM_EQ(contents, 125);
126 EXPECT_TRUE(ZoomBubbleIsShowing());
127 ExpectLabelTextContains(125);
128 }
129
130 IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedInAndBack) {
131 content::WebContents* contents = SetUpTest();
132
133 ZoomIn();
134 ASSERT_ZOOM_EQ(contents, 110);
135 EXPECT_TRUE(ZoomBubbleIsShowing());
136 ExpectLabelTextContains(110);
137
138 ZoomOut(); // Back to default, in theory.
139 ASSERT_ZOOM_EQ(contents, 100);
140 EXPECT_FALSE(ZoomBubbleIsShowing());
141 }
142
143 IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, ZoomInTwiceAndReset) {
144 content::WebContents* contents = SetUpTest();
145
146 ZoomIn(); // 110%.
147 ZoomIn();
148 ASSERT_ZOOM_EQ(contents, 125);
149 EXPECT_TRUE(ZoomBubbleIsShowing());
150 ExpectLabelTextContains(125);
151
152 ResetZoom();
153 ASSERT_ZOOM_EQ(contents, 100);
154 EXPECT_FALSE(ZoomBubbleIsShowing());
155 }
156
157 IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedOut) {
158 content::WebContents* contents = SetUpTest();
159
160 ZoomOut();
161 ASSERT_ZOOM_EQ(contents, 90);
162 EXPECT_TRUE(ZoomBubbleIsShowing());
163 ExpectLabelTextContains(90);
164 }
165
166 IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedOutTwice) {
167 content::WebContents* contents = SetUpTest();
168
169 ZoomOut(); // 90%.
170 ZoomOut();
171 ASSERT_ZOOM_EQ(contents, 75);
172 EXPECT_TRUE(ZoomBubbleIsShowing());
173 ExpectLabelTextContains(75);
174 }
175
176 IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedOutAndBack) {
177 content::WebContents* contents = SetUpTest();
178
179 ZoomOut();
180 ASSERT_ZOOM_EQ(contents, 90);
181 EXPECT_TRUE(ZoomBubbleIsShowing());
182 ExpectLabelTextContains(90);
183
184 ZoomIn(); // Back to default, in theory.
185 ASSERT_ZOOM_EQ(contents, 100);
186 EXPECT_FALSE(ZoomBubbleIsShowing());
187 }
188
189 IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, ZoomOutTwiceAndReset) {
190 content::WebContents* contents = SetUpTest();
191
192 ZoomOut(); // 90%.
193 ZoomOut();
194 ASSERT_ZOOM_EQ(contents, 75);
195 EXPECT_TRUE(ZoomBubbleIsShowing());
196 ExpectLabelTextContains(75);
197
198 ResetZoom();
199 ASSERT_ZOOM_EQ(contents, 100);
200 EXPECT_FALSE(ZoomBubbleIsShowing());
201 }
202
203 #undef ASSERT_ZOOM_EQ
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698