OLD | NEW |
---|---|
(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/zoom/zoom_controller.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 "grit/theme_resources.h" | |
23 #include "testing/gtest/include/gtest/gtest.h" | |
24 | |
25 class LocationBarViewGtkZoomTest : public InProcessBrowserTest { | |
26 public: | |
27 LocationBarViewGtkZoomTest() { | |
28 } | |
29 | |
30 virtual ~LocationBarViewGtkZoomTest() { | |
31 } | |
32 | |
33 protected: | |
34 void ExpectTooltipContains(int percent) { | |
35 gchar* text = gtk_widget_get_tooltip_text(GetZoomWidget()); | |
36 std::string tooltip(text); | |
37 g_free(text); | |
38 EXPECT_TRUE(tooltip.find(base::IntToString(percent)) != std::string::npos); | |
39 } | |
40 | |
41 bool ZoomIconIsShowing() { | |
42 return gtk_widget_get_visible(GetZoomWidget()); | |
43 } | |
44 | |
45 void ExpectIconIsResource(int resource_id) { | |
46 // TODO(dbeam): actually compare the image bits with gfx::test::IsEqual? | |
47 content::WebContents* contents = chrome::GetActiveWebContents(browser()); | |
48 ZoomController* zoom_controller = ZoomController::FromWebContents(contents); | |
49 EXPECT_EQ(resource_id, zoom_controller->GetResourceForZoomLevel()); | |
50 } | |
51 | |
52 // TODO(dbeam): share below code with ZoomBubbleGtkTest. | |
53 void AssertZoomEquals(content::WebContents* contents, int percent) { | |
54 bool dummy; // Knowing whether we can zoom in or out more isn't required. | |
55 ASSERT_EQ(percent, contents->GetZoomPercent(&dummy, &dummy)); | |
56 } | |
57 | |
58 void ResetZoom() { | |
59 WaitForZoom(content::PAGE_ZOOM_RESET); | |
60 } | |
61 | |
62 content::WebContents* SetUpTest() { | |
63 content::WebContents* contents = chrome::GetActiveWebContents(browser()); | |
64 ResetZoom(); | |
65 AssertZoomEquals(contents, 100); | |
66 return contents; | |
67 } | |
68 | |
69 void ZoomIn() { | |
70 WaitForZoom(content::PAGE_ZOOM_IN); | |
71 } | |
72 | |
73 void ZoomOut() { | |
74 WaitForZoom(content::PAGE_ZOOM_OUT); | |
75 } | |
76 | |
77 private: | |
78 GtkWidget* GetZoomWidget() { | |
79 return static_cast<BrowserWindowGtk*>(browser()->window())->GetToolbar()-> | |
80 GetLocationBarView()->zoom_.get(); | |
Evan Stade
2012/10/02 08:12:00
another place to use ViewIDs
Dan Beam
2012/10/02 16:41:42
Done.
| |
81 } | |
82 | |
83 void WaitForZoom(content::PageZoom zoom_action) { | |
84 content::WindowedNotificationObserver zoom_observer( | |
85 content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | |
86 content::NotificationService::AllSources()); | |
87 chrome::Zoom(browser(), zoom_action); | |
88 zoom_observer.Wait(); | |
89 } | |
90 | |
91 DISALLOW_COPY_AND_ASSIGN(LocationBarViewGtkZoomTest); | |
92 }; | |
93 | |
94 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedIn) { | |
95 content::WebContents* contents = SetUpTest(); | |
96 | |
97 ZoomIn(); | |
98 AssertZoomEquals(contents, 110); | |
99 EXPECT_TRUE(ZoomIconIsShowing()); | |
100 ExpectIconIsResource(IDR_ZOOM_PLUS); | |
101 ExpectTooltipContains(110); | |
102 } | |
103 | |
104 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedInTwice) { | |
105 content::WebContents* contents = SetUpTest(); | |
106 | |
107 ZoomIn(); // 110%. | |
108 ZoomIn(); | |
109 AssertZoomEquals(contents, 125); | |
110 EXPECT_TRUE(ZoomIconIsShowing()); | |
111 ExpectIconIsResource(IDR_ZOOM_PLUS); | |
112 ExpectTooltipContains(125); | |
113 } | |
114 | |
115 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedInAndBack) { | |
116 content::WebContents* contents = SetUpTest(); | |
117 | |
118 ZoomIn(); | |
119 AssertZoomEquals(contents, 110); | |
120 EXPECT_TRUE(ZoomIconIsShowing()); | |
121 ExpectIconIsResource(IDR_ZOOM_PLUS); | |
122 ExpectTooltipContains(110); | |
123 | |
124 ZoomOut(); // Back to default, in theory. | |
125 AssertZoomEquals(contents, 100); | |
126 EXPECT_FALSE(ZoomIconIsShowing()); | |
127 } | |
128 | |
129 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, ZoomInTwiceAndReset) { | |
130 content::WebContents* contents = SetUpTest(); | |
131 | |
132 ZoomIn(); // 110%. | |
133 ZoomIn(); | |
134 AssertZoomEquals(contents, 125); | |
135 EXPECT_TRUE(ZoomIconIsShowing()); | |
136 ExpectIconIsResource(IDR_ZOOM_PLUS); | |
137 ExpectTooltipContains(125); | |
138 | |
139 ResetZoom(); | |
140 AssertZoomEquals(contents, 100); | |
141 EXPECT_FALSE(ZoomIconIsShowing()); | |
142 } | |
143 | |
144 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedOut) { | |
145 content::WebContents* contents = SetUpTest(); | |
146 | |
147 ZoomOut(); | |
148 AssertZoomEquals(contents, 90); | |
149 EXPECT_TRUE(ZoomIconIsShowing()); | |
150 ExpectIconIsResource(IDR_ZOOM_MINUS); | |
151 ExpectTooltipContains(90); | |
152 } | |
153 | |
154 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedOutTwice) { | |
155 content::WebContents* contents = SetUpTest(); | |
156 | |
157 ZoomOut(); // 90%. | |
158 ZoomOut(); | |
159 AssertZoomEquals(contents, 75); | |
160 EXPECT_TRUE(ZoomIconIsShowing()); | |
161 ExpectIconIsResource(IDR_ZOOM_MINUS); | |
162 ExpectTooltipContains(75); | |
163 } | |
164 | |
165 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedOutAndBack) { | |
166 content::WebContents* contents = SetUpTest(); | |
167 | |
168 ZoomOut(); | |
169 AssertZoomEquals(contents, 90); | |
170 EXPECT_TRUE(ZoomIconIsShowing()); | |
171 ExpectIconIsResource(IDR_ZOOM_MINUS); | |
172 ExpectTooltipContains(90); | |
173 | |
174 ZoomIn(); // Back to default, in theory. | |
175 AssertZoomEquals(contents, 100); | |
176 EXPECT_FALSE(ZoomIconIsShowing()); | |
177 } | |
178 | |
179 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, ZoomOutTwiceAndReset) { | |
180 content::WebContents* contents = SetUpTest(); | |
181 | |
182 ZoomOut(); // 90%. | |
183 ZoomOut(); | |
184 AssertZoomEquals(contents, 75); | |
185 EXPECT_TRUE(ZoomIconIsShowing()); | |
186 ExpectIconIsResource(IDR_ZOOM_MINUS); | |
187 ExpectTooltipContains(75); | |
188 | |
189 ResetZoom(); | |
190 AssertZoomEquals(contents, 100); | |
191 EXPECT_FALSE(ZoomIconIsShowing()); | |
192 } | |
OLD | NEW |