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. | |
Evan Stade
2012/10/02 18:35:59
is this TODO ever going to be accomplished? if not
Dan Beam
2012/10/02 19:34:14
yes, it's going to be fixed
| |
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 } | |
Evan Stade
2012/10/02 18:35:59
no line return before }
Dan Beam
2012/10/02 19:34:14
Done.
| |
53 | |
54 virtual ~LocationBarViewGtkZoomTest() { | |
55 } | |
Evan Stade
2012/10/02 18:35:59
ditto
Dan Beam
2012/10/02 19:34:14
Done.
| |
56 | |
57 protected: | |
58 void ExpectTooltipContains(int percent) { | |
59 gchar* text = gtk_widget_get_tooltip_text(GetZoomWidget()); | |
60 std::string tooltip(text); | |
61 g_free(text); | |
62 EXPECT_FALSE(tooltip.find(base::IntToString(percent)) == std::string::npos); | |
63 } | |
64 | |
65 bool ZoomIconIsShowing() { | |
66 return gtk_widget_get_visible(GetZoomWidget()); | |
67 } | |
68 | |
69 void ExpectIconIsResource(int resource_id) { | |
70 // TODO(dbeam): actually compare the image bits with gfx::test::IsEqual? | |
71 content::WebContents* contents = chrome::GetActiveWebContents(browser()); | |
72 ZoomController* zoom_controller = ZoomController::FromWebContents(contents); | |
73 EXPECT_EQ(resource_id, zoom_controller->GetResourceForZoomLevel()); | |
74 } | |
75 | |
76 void ResetZoom() { | |
77 WaitForZoom(content::PAGE_ZOOM_RESET); | |
78 } | |
79 | |
80 content::WebContents* SetUpTest() { | |
81 content::WebContents* contents = chrome::GetActiveWebContents(browser()); | |
82 ResetZoom(); | |
83 AssertAtDefaultZoom(contents); | |
84 return contents; | |
85 } | |
86 | |
87 void ZoomIn() { | |
88 WaitForZoom(content::PAGE_ZOOM_IN); | |
89 } | |
90 | |
91 void ZoomOut() { | |
92 WaitForZoom(content::PAGE_ZOOM_OUT); | |
93 } | |
94 | |
95 private: | |
96 GtkWidget* GetZoomWidget() { | |
97 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | |
98 return ViewIDUtil::GetWidget(GTK_WIDGET(window), VIEW_ID_ZOOM_BUTTON); | |
99 } | |
100 | |
101 void WaitForZoom(content::PageZoom zoom_action) { | |
102 content::WindowedNotificationObserver zoom_observer( | |
103 content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | |
104 content::NotificationService::AllSources()); | |
105 chrome::Zoom(browser(), zoom_action); | |
106 zoom_observer.Wait(); | |
107 } | |
108 | |
109 DISALLOW_COPY_AND_ASSIGN(LocationBarViewGtkZoomTest); | |
110 }; | |
111 | |
112 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedInAndBack) { | |
113 content::WebContents* contents = SetUpTest(); | |
114 | |
115 ZoomIn(); | |
116 AssertZoomedIn(contents); | |
117 EXPECT_TRUE(ZoomIconIsShowing()); | |
118 ExpectIconIsResource(IDR_ZOOM_PLUS); | |
119 ExpectTooltipContains(110); | |
120 | |
121 ZoomOut(); // Back to default, in theory. | |
122 AssertAtDefaultZoom(contents); | |
123 EXPECT_FALSE(ZoomIconIsShowing()); | |
124 } | |
125 | |
126 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, ZoomInTwiceAndReset) { | |
127 content::WebContents* contents = SetUpTest(); | |
128 | |
129 ZoomIn(); | |
130 ZoomIn(); | |
131 AssertZoomedIn(contents); | |
132 EXPECT_TRUE(ZoomIconIsShowing()); | |
133 ExpectIconIsResource(IDR_ZOOM_PLUS); | |
134 ExpectTooltipContains(125); | |
135 | |
136 ResetZoom(); | |
137 AssertAtDefaultZoom(contents); | |
138 EXPECT_FALSE(ZoomIconIsShowing()); | |
139 } | |
140 | |
141 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedOutAndBack) { | |
142 content::WebContents* contents = SetUpTest(); | |
143 | |
144 ZoomOut(); | |
145 AssertZoomedOut(contents); | |
146 EXPECT_TRUE(ZoomIconIsShowing()); | |
147 ExpectIconIsResource(IDR_ZOOM_MINUS); | |
148 ExpectTooltipContains(90); | |
149 | |
150 ZoomIn(); | |
151 AssertAtDefaultZoom(contents); | |
152 EXPECT_FALSE(ZoomIconIsShowing()); | |
153 } | |
154 | |
155 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, ZoomOutTwiceAndReset) { | |
156 content::WebContents* contents = SetUpTest(); | |
157 | |
158 ZoomOut(); | |
159 ZoomOut(); | |
160 AssertZoomedOut(contents); | |
161 EXPECT_TRUE(ZoomIconIsShowing()); | |
162 ExpectIconIsResource(IDR_ZOOM_MINUS); | |
163 ExpectTooltipContains(75); | |
164 | |
165 ResetZoom(); | |
166 AssertAtDefaultZoom(contents); | |
167 EXPECT_FALSE(ZoomIconIsShowing()); | |
168 } | |
OLD | NEW |