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

Side by Side Diff: chrome/browser/ui/gtk/location_bar_view_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/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/ui_test_utils.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "content/public/browser/notification_types.h"
19 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/web_contents.h"
21 #include "content/public/test/browser_test_utils.h"
22 #include "content/public/test/test_utils.h"
23
24 #define ASSERT_ZOOM_EQ(contents, percent) \
Lei Zhang 2012/10/01 23:35:54 Any particular reason you prefer this over CheckZo
Dan Beam 2012/10/02 00:03:06 Not really, just seemed to be more familiar to the
Lei Zhang 2012/10/02 00:09:52 The C++ style guide prefers not to use them. http:
Dan Beam 2012/10/02 01:42:49 Done.
25 do { \
26 bool dummy; \
27 ASSERT_EQ(contents->GetZoomPercent(&dummy, &dummy), percent); \
28 } while (0)
29
30 class LocationBarViewGtkZoomTest : public InProcessBrowserTest,
31 public BrowserWindowTesting {
32 public:
33 LocationBarViewGtkZoomTest() {
34 }
35
36 virtual ~LocationBarViewGtkZoomTest() {
37 }
38
39 content::WebContents* SetUpTest() {
40 content::WebContents* contents = chrome::GetActiveWebContents(browser());
41 ResetZoom();
42 return contents;
43 }
44
45 void ResetZoom() {
46 content::WindowedNotificationObserver zoom_observer(
47 content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
48 content::NotificationService::AllSources());
49 chrome::Zoom(browser(), content::PAGE_ZOOM_RESET);
50 zoom_observer.Wait();
51 }
52
53 void ZoomIn() {
54 content::WindowedNotificationObserver zoom_observer(
55 content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
56 content::NotificationService::AllSources());
57 chrome::Zoom(browser(), content::PAGE_ZOOM_IN);
58 zoom_observer.Wait();
59 }
60
61 void ZoomOut() {
62 content::WindowedNotificationObserver zoom_observer(
63 content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
64 content::NotificationService::AllSources());
65 chrome::Zoom(browser(), content::PAGE_ZOOM_OUT);
66 zoom_observer.Wait();
67 }
68
69 void ExpectTooltipContains(int percent) {
70 gchar* text = gtk_widget_get_tooltip_text(GetZoomWidget());
71 std::string tooltip(text);
72 g_free(text);
73 EXPECT_TRUE(tooltip.find(base::IntToString(percent)) != std::string::npos);
74 }
75
76 BrowserWindowGtk* GetNativeBrowser() {
77 return static_cast<BrowserWindowGtk*>(browser()->window());
78 }
79
80 GtkWidget* GetZoomWidget() {
81 return GetNativeBrowser()->GetToolbar()->GetLocationBarView()->zoom_.get();
82 }
83
84 bool ZoomIconIsShowing() {
85 return gtk_widget_get_visible(GetZoomWidget());
86 }
87 };
88
89 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedIn) {
90 content::WebContents* contents = SetUpTest();
91
92 ZoomIn();
93 ASSERT_ZOOM_EQ(contents, 110);
94 EXPECT_TRUE(ZoomIconIsShowing());
95 ExpectTooltipContains(110);
96 }
97
98 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedInTwice) {
99 content::WebContents* contents = SetUpTest();
100
101 ZoomIn(); // 110%.
102 ZoomIn();
103 ASSERT_ZOOM_EQ(contents, 125);
104 EXPECT_TRUE(ZoomIconIsShowing());
105 ExpectTooltipContains(125);
106 }
107
108 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedInAndBack) {
109 content::WebContents* contents = SetUpTest();
110
111 ZoomIn();
112 ASSERT_ZOOM_EQ(contents, 110);
113 EXPECT_TRUE(ZoomIconIsShowing());
114 ExpectTooltipContains(110);
115
116 ZoomOut(); // Back to default, in theory.
117 ASSERT_ZOOM_EQ(contents, 100);
118 EXPECT_FALSE(ZoomIconIsShowing());
119 }
120
121 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, ZoomInTwiceAndReset) {
122 content::WebContents* contents = SetUpTest();
123
124 ZoomIn(); // 110%.
125 ZoomIn();
126 ASSERT_ZOOM_EQ(contents, 125);
127 EXPECT_TRUE(ZoomIconIsShowing());
128 ExpectTooltipContains(125);
129
130 ResetZoom();
131 ASSERT_ZOOM_EQ(contents, 100);
132 EXPECT_FALSE(ZoomIconIsShowing());
133 }
134
135 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedOut) {
136 content::WebContents* contents = SetUpTest();
137
138 ZoomOut();
139 ASSERT_ZOOM_EQ(contents, 90);
140 EXPECT_TRUE(ZoomIconIsShowing());
141 ExpectTooltipContains(90);
142 }
143
144 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedOutTwice) {
145 content::WebContents* contents = SetUpTest();
146
147 ZoomOut(); // 90%.
148 ZoomOut();
149 ASSERT_ZOOM_EQ(contents, 75);
150 EXPECT_TRUE(ZoomIconIsShowing());
151 ExpectTooltipContains(75);
152 }
153
154 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedOutAndBack) {
155 content::WebContents* contents = SetUpTest();
156
157 ZoomOut();
158 ASSERT_ZOOM_EQ(contents, 90);
159 EXPECT_TRUE(ZoomIconIsShowing());
160 ExpectTooltipContains(90);
161
162 ZoomIn(); // Back to default, in theory.
163 ASSERT_ZOOM_EQ(contents, 100);
164 EXPECT_FALSE(ZoomIconIsShowing());
165 }
166
167 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, ZoomOutTwiceAndReset) {
168 content::WebContents* contents = SetUpTest();
169
170 ZoomOut(); // 90%.
171 ZoomOut();
172 ASSERT_ZOOM_EQ(contents, 75);
173 EXPECT_TRUE(ZoomIconIsShowing());
174 ExpectTooltipContains(75);
175
176 ResetZoom();
177 ASSERT_ZOOM_EQ(contents, 100);
178 EXPECT_FALSE(ZoomIconIsShowing());
179 }
180
181 #undef ASSERT_ZOOM_EQ
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698