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

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: TODO() + comment fix 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.h"
9 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/browser_tabstrip.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 "content/public/browser/notification_service.h"
19 #include "content/public/browser/notification_types.h"
20 #include "content/public/browser/web_contents.h"
21 #include "content/public/common/page_zoom.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23
24 class ZoomBubbleGtkTest : public InProcessBrowserTest {
25 public:
26 ZoomBubbleGtkTest() {
27 }
28
29 virtual ~ZoomBubbleGtkTest() {
30 }
31
32 protected:
33 ZoomBubbleGtk* GetZoomBubble() {
34 return ZoomBubbleGtk::g_bubble;
35 }
36
37 bool ZoomBubbleIsShowing() {
38 return ZoomBubbleGtk::IsShowing();
39 }
40
41 void ExpectLabelTextContains(int percent) {
42 const gchar* text = gtk_label_get_text(GTK_LABEL(GetZoomBubble()->label_));
43 std::string label(text);
Evan Stade 2012/10/02 08:05:58 combine L42-43
Dan Beam 2012/10/02 15:53:23 Done.
44 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.
45 }
46
47 // TODO(dbeam): share below code with LocationBarViewGtkZoomTest if feasible.
48 void AssertZoomEquals(content::WebContents* contents, int percent) {
49 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.
50 ASSERT_EQ(contents->GetZoomPercent(&dummy, &dummy), percent);
51 }
52
53 void ResetZoom() {
54 WaitForZoom(content::PAGE_ZOOM_RESET);
55 }
56
57 content::WebContents* SetUpTest() {
58 content::WebContents* contents = chrome::GetActiveWebContents(browser());
59 ResetZoom();
60 AssertZoomEquals(contents, 100);
61 return contents;
62 }
63
64 void ZoomIn() {
65 WaitForZoom(content::PAGE_ZOOM_IN);
66 if (GetZoomBubble())
67 GetZoomBubble()->StopTimerIfNecessary(); // To prevent test flakiness.
68 }
69
70 void ZoomOut() {
71 WaitForZoom(content::PAGE_ZOOM_OUT);
72 if (GetZoomBubble())
73 GetZoomBubble()->StopTimerIfNecessary(); // To prevent test flakiness.
74 }
75
76 private:
77 void WaitForZoom(content::PageZoom zoom_action) {
78 content::WindowedNotificationObserver zoom_observer(
79 content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
80 content::NotificationService::AllSources());
81 chrome::Zoom(browser(), zoom_action);
82 zoom_observer.Wait();
83 }
84
85 DISALLOW_COPY_AND_ASSIGN(ZoomBubbleGtkTest);
86 };
87
88 IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, BubbleSanityTest) {
89 ResetZoom();
90 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.
91
92 ZoomBubbleGtk::Close();
93 DCHECK(!GetZoomBubble());
94 EXPECT_FALSE(ZoomBubbleIsShowing());
95
96 GtkWidget* zoom_icon = static_cast<BrowserWindowGtk*>(browser()->window())->
97 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.
98 DCHECK(zoom_icon);
99
100 TabContents* tab_contents = chrome::GetActiveTabContents(browser());
101 DCHECK(tab_contents);
102
103 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.
104 DCHECK(GetZoomBubble());
105 EXPECT_TRUE(ZoomBubbleIsShowing());
106 }
107
108 IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedIn) {
109 content::WebContents* contents = SetUpTest();
110
111 ZoomIn();
112 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.
113 EXPECT_TRUE(ZoomBubbleIsShowing());
114 ExpectLabelTextContains(110);
115 }
116
117 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.
118 content::WebContents* contents = SetUpTest();
119
120 ZoomIn(); // 110%.
121 ZoomIn();
122 AssertZoomEquals(contents, 125);
123 EXPECT_TRUE(ZoomBubbleIsShowing());
124 ExpectLabelTextContains(125);
125 }
126
127 IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedInAndBack) {
128 content::WebContents* contents = SetUpTest();
129
130 ZoomIn();
131 AssertZoomEquals(contents, 110);
132 EXPECT_TRUE(ZoomBubbleIsShowing());
133 ExpectLabelTextContains(110);
134
135 ZoomOut(); // Back to default, in theory.
136 AssertZoomEquals(contents, 100);
137 EXPECT_FALSE(ZoomBubbleIsShowing());
138 }
139
140 IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, ZoomInTwiceAndReset) {
141 content::WebContents* contents = SetUpTest();
142
143 ZoomIn(); // 110%.
144 ZoomIn();
145 AssertZoomEquals(contents, 125);
146 EXPECT_TRUE(ZoomBubbleIsShowing());
147 ExpectLabelTextContains(125);
148
149 ResetZoom();
150 AssertZoomEquals(contents, 100);
151 EXPECT_FALSE(ZoomBubbleIsShowing());
152 }
153
154 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.
155 content::WebContents* contents = SetUpTest();
156
157 ZoomOut();
158 AssertZoomEquals(contents, 90);
159 EXPECT_TRUE(ZoomBubbleIsShowing());
160 ExpectLabelTextContains(90);
161 }
162
163 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.
164 content::WebContents* contents = SetUpTest();
165
166 ZoomOut(); // 90%.
167 ZoomOut();
168 AssertZoomEquals(contents, 75);
169 EXPECT_TRUE(ZoomBubbleIsShowing());
170 ExpectLabelTextContains(75);
171 }
172
173 IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, DefaultToZoomedOutAndBack) {
174 content::WebContents* contents = SetUpTest();
175
176 ZoomOut();
177 AssertZoomEquals(contents, 90);
178 EXPECT_TRUE(ZoomBubbleIsShowing());
179 ExpectLabelTextContains(90);
180
181 ZoomIn(); // Back to default, in theory.
182 AssertZoomEquals(contents, 100);
183 EXPECT_FALSE(ZoomBubbleIsShowing());
184 }
185
186 IN_PROC_BROWSER_TEST_F(ZoomBubbleGtkTest, ZoomOutTwiceAndReset) {
187 content::WebContents* contents = SetUpTest();
188
189 ZoomOut(); // 90%.
190 ZoomOut();
191 AssertZoomEquals(contents, 75);
192 EXPECT_TRUE(ZoomBubbleIsShowing());
193 ExpectLabelTextContains(75);
194
195 ResetZoom();
196 AssertZoomEquals(contents, 100);
197 EXPECT_FALSE(ZoomBubbleIsShowing());
198 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698