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/gtk/view_id_util.h" | |
16 #include "chrome/browser/ui/zoom/zoom_controller.h" | |
17 #include "chrome/test/base/in_process_browser_test.h" | |
18 #include "chrome/test/base/ui_test_utils.h" | |
19 #include "content/public/browser/notification_service.h" | |
20 #include "content/public/browser/notification_types.h" | |
21 #include "content/public/browser/web_contents.h" | |
22 #include "content/public/common/page_zoom.h" | |
23 #include "grit/theme_resources.h" | |
24 #include "testing/gtest/include/gtest/gtest.h" | |
25 | |
26 // TODO(dbeam): share some testing code with ZoomBubbleGtkTest. | |
27 | |
28 namespace { | |
29 | |
30 int GetZoomPercent(content::WebContents* contents) { | |
31 bool dummy; | |
32 return contents->GetZoomPercent(&dummy, &dummy); | |
33 } | |
34 | |
35 void AssertZoomedIn(content::WebContents* contents) { | |
36 ASSERT_GT(GetZoomPercent(contents), 100); | |
37 } | |
38 | |
39 void AssertZoomedOut(content::WebContents* contents) { | |
40 ASSERT_LT(GetZoomPercent(contents), 100); | |
41 } | |
42 | |
43 void AssertAtDefaultZoom(content::WebContents* contents) { | |
44 ASSERT_EQ(GetZoomPercent(contents), 100); | |
45 } | |
46 | |
47 } | |
48 | |
49 class LocationBarViewGtkZoomTest : public InProcessBrowserTest { | |
50 public: | |
51 LocationBarViewGtkZoomTest() {} | |
52 virtual ~LocationBarViewGtkZoomTest() {} | |
53 | |
54 protected: | |
55 void ExpectTooltipContainsZoom() { | |
56 gchar* text = gtk_widget_get_tooltip_text(GetZoomWidget()); | |
57 std::string tooltip(text); | |
58 g_free(text); | |
59 content::WebContents* contents = chrome::GetActiveWebContents(browser()); | |
60 std::string zoom_percent = base::IntToString(GetZoomPercent(contents)); | |
61 EXPECT_FALSE(tooltip.find(zoom_percent) == std::string::npos); | |
62 } | |
63 | |
64 bool ZoomIconIsShowing() { | |
65 return gtk_widget_get_visible(GetZoomWidget()); | |
66 } | |
67 | |
68 void ExpectIconIsResource(int resource_id) { | |
69 // TODO(dbeam): actually compare the image bits with gfx::test::IsEqual? | |
70 content::WebContents* contents = chrome::GetActiveWebContents(browser()); | |
71 ZoomController* zoom_controller = ZoomController::FromWebContents(contents); | |
72 EXPECT_EQ(resource_id, zoom_controller->GetResourceForZoomLevel()); | |
73 } | |
74 | |
75 void ResetZoom() { | |
76 WaitForZoom(content::PAGE_ZOOM_RESET); | |
77 } | |
78 | |
79 content::WebContents* SetUpTest() { | |
80 content::WebContents* contents = chrome::GetActiveWebContents(browser()); | |
81 ResetZoom(); | |
82 AssertAtDefaultZoom(contents); | |
83 return contents; | |
84 } | |
85 | |
86 void ZoomIn() { | |
87 WaitForZoom(content::PAGE_ZOOM_IN); | |
88 } | |
89 | |
90 void ZoomOut() { | |
91 WaitForZoom(content::PAGE_ZOOM_OUT); | |
92 } | |
93 | |
94 private: | |
95 GtkWidget* GetZoomWidget() { | |
96 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | |
97 return ViewIDUtil::GetWidget(GTK_WIDGET(window), VIEW_ID_ZOOM_BUTTON); | |
98 } | |
99 | |
100 void WaitForZoom(content::PageZoom zoom_action) { | |
101 content::WindowedNotificationObserver zoom_observer( | |
102 content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | |
103 content::NotificationService::AllSources()); | |
104 chrome::Zoom(browser(), zoom_action); | |
105 zoom_observer.Wait(); | |
106 } | |
107 | |
108 DISALLOW_COPY_AND_ASSIGN(LocationBarViewGtkZoomTest); | |
109 }; | |
110 | |
111 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedInAndBack) { | |
112 content::WebContents* contents = SetUpTest(); | |
113 | |
114 ZoomIn(); | |
115 AssertZoomedIn(contents); | |
116 EXPECT_TRUE(ZoomIconIsShowing()); | |
117 ExpectIconIsResource(IDR_ZOOM_PLUS); | |
118 ExpectTooltipContainsZoom(); | |
Evan Stade
2012/10/04 11:51:22
...
you didn't check the percent was >100
Dan Beam
2012/10/04 18:14:41
AssertZoomedIn(contents); does this
Evan Stade
2012/10/04 19:07:43
oh, so it does.
| |
119 | |
120 ZoomOut(); // Back to default, in theory. | |
121 AssertAtDefaultZoom(contents); | |
122 EXPECT_FALSE(ZoomIconIsShowing()); | |
123 } | |
124 | |
125 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, ZoomInTwiceAndReset) { | |
126 content::WebContents* contents = SetUpTest(); | |
127 | |
128 ZoomIn(); | |
129 ZoomIn(); | |
Evan Stade
2012/10/04 11:51:22
and here you should be checking that zoom after tw
Dan Beam
2012/10/04 18:14:41
Done.
| |
130 AssertZoomedIn(contents); | |
131 EXPECT_TRUE(ZoomIconIsShowing()); | |
132 ExpectIconIsResource(IDR_ZOOM_PLUS); | |
133 ExpectTooltipContainsZoom(); | |
134 | |
135 ResetZoom(); | |
136 AssertAtDefaultZoom(contents); | |
137 EXPECT_FALSE(ZoomIconIsShowing()); | |
138 } | |
139 | |
140 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedOutAndBack) { | |
141 content::WebContents* contents = SetUpTest(); | |
142 | |
143 ZoomOut(); | |
144 AssertZoomedOut(contents); | |
145 EXPECT_TRUE(ZoomIconIsShowing()); | |
146 ExpectIconIsResource(IDR_ZOOM_MINUS); | |
147 ExpectTooltipContainsZoom(); | |
148 | |
149 ZoomIn(); | |
150 AssertAtDefaultZoom(contents); | |
151 EXPECT_FALSE(ZoomIconIsShowing()); | |
152 } | |
153 | |
154 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, ZoomOutTwiceAndReset) { | |
155 content::WebContents* contents = SetUpTest(); | |
156 | |
157 ZoomOut(); | |
158 ZoomOut(); | |
159 AssertZoomedOut(contents); | |
160 EXPECT_TRUE(ZoomIconIsShowing()); | |
161 ExpectIconIsResource(IDR_ZOOM_MINUS); | |
162 ExpectTooltipContainsZoom(); | |
163 | |
164 ResetZoom(); | |
165 AssertAtDefaultZoom(contents); | |
166 EXPECT_FALSE(ZoomIconIsShowing()); | |
167 } | |
OLD | NEW |