OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <gtk/gtk.h> | 5 #include <gtk/gtk.h> |
6 | 6 |
7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
10 #include "chrome/browser/ui/browser_tabstrip.h" | 11 #include "chrome/browser/ui/browser_tabstrip.h" |
11 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
12 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" | 13 #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/browser_window_gtk.h" |
14 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" | 15 #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/gtk/view_id_util.h" |
16 #include "chrome/browser/ui/zoom/zoom_controller.h" | 17 #include "chrome/browser/ui/zoom/zoom_controller.h" |
17 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
18 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 20 #include "content/public/browser/host_zoom_map.h" |
19 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
20 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
21 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
22 #include "content/public/common/page_zoom.h" | 24 #include "content/public/common/page_zoom.h" |
23 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
25 | 27 |
26 // TODO(dbeam): share some testing code with ZoomBubbleGtkTest. | 28 // TODO(dbeam): share some testing code with ZoomBubbleGtkTest. |
27 | 29 |
28 namespace { | 30 namespace { |
29 | 31 |
30 int GetZoomPercent(content::WebContents* contents) { | 32 int GetZoomPercent(content::WebContents* contents) { |
31 bool dummy; | 33 bool dummy; |
32 return contents->GetZoomPercent(&dummy, &dummy); | 34 return contents->GetZoomPercent(&dummy, &dummy); |
33 } | 35 } |
34 | 36 |
35 void ExpectZoomedIn(content::WebContents* contents) { | 37 void ExpectZoomedIn(content::WebContents* contents) { |
36 EXPECT_GT(GetZoomPercent(contents), 100); | 38 EXPECT_GT(GetZoomPercent(contents), 100); |
37 } | 39 } |
38 | 40 |
39 void ExpectZoomedOut(content::WebContents* contents) { | 41 void ExpectZoomedOut(content::WebContents* contents) { |
40 EXPECT_LT(GetZoomPercent(contents), 100); | 42 EXPECT_LT(GetZoomPercent(contents), 100); |
41 } | 43 } |
42 | 44 |
43 void ExpectAtDefaultZoom(content::WebContents* contents) { | 45 void ExpectAtDefaultZoom(content::WebContents* contents) { |
44 EXPECT_EQ(GetZoomPercent(contents), 100); | 46 EXPECT_EQ(GetZoomPercent(contents), 100); |
45 } | 47 } |
46 | 48 |
| 49 void OnZoomLevelChanged(const base::Closure& callback, |
| 50 const std::string& host) { |
| 51 callback.Run(); |
47 } | 52 } |
48 | 53 |
| 54 } // namespace |
| 55 |
49 class LocationBarViewGtkZoomTest : public InProcessBrowserTest { | 56 class LocationBarViewGtkZoomTest : public InProcessBrowserTest { |
50 public: | 57 public: |
51 LocationBarViewGtkZoomTest() {} | 58 LocationBarViewGtkZoomTest() {} |
52 virtual ~LocationBarViewGtkZoomTest() {} | 59 virtual ~LocationBarViewGtkZoomTest() {} |
53 | 60 |
54 protected: | 61 protected: |
55 void ExpectTooltipContainsZoom() { | 62 void ExpectTooltipContainsZoom() { |
56 gchar* text = gtk_widget_get_tooltip_text(GetZoomWidget()); | 63 gchar* text = gtk_widget_get_tooltip_text(GetZoomWidget()); |
57 std::string tooltip(text); | 64 std::string tooltip(text); |
58 g_free(text); | 65 g_free(text); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 WaitForZoom(content::PAGE_ZOOM_OUT); | 98 WaitForZoom(content::PAGE_ZOOM_OUT); |
92 } | 99 } |
93 | 100 |
94 private: | 101 private: |
95 GtkWidget* GetZoomWidget() { | 102 GtkWidget* GetZoomWidget() { |
96 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | 103 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); |
97 return ViewIDUtil::GetWidget(GTK_WIDGET(window), VIEW_ID_ZOOM_BUTTON); | 104 return ViewIDUtil::GetWidget(GTK_WIDGET(window), VIEW_ID_ZOOM_BUTTON); |
98 } | 105 } |
99 | 106 |
100 void WaitForZoom(content::PageZoom zoom_action) { | 107 void WaitForZoom(content::PageZoom zoom_action) { |
101 content::WindowedNotificationObserver zoom_observer( | 108 scoped_refptr<content::MessageLoopRunner> loop_runner( |
102 content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | 109 new content::MessageLoopRunner); |
103 content::NotificationService::AllSources()); | 110 |
| 111 content::HostZoomMap::GetForBrowserContext( |
| 112 browser()->profile())->AddZoomLevelChangedCallback( |
| 113 base::Bind(&OnZoomLevelChanged, loop_runner->QuitClosure())); |
104 chrome::Zoom(browser(), zoom_action); | 114 chrome::Zoom(browser(), zoom_action); |
105 zoom_observer.Wait(); | 115 loop_runner->Run(); |
| 116 content::HostZoomMap::GetForBrowserContext( |
| 117 browser()->profile())->RemoveZoomLevelChangedCallback( |
| 118 base::Bind(&OnZoomLevelChanged, loop_runner->QuitClosure())); |
106 } | 119 } |
107 | 120 |
108 DISALLOW_COPY_AND_ASSIGN(LocationBarViewGtkZoomTest); | 121 DISALLOW_COPY_AND_ASSIGN(LocationBarViewGtkZoomTest); |
109 }; | 122 }; |
110 | 123 |
111 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedInAndBack) { | 124 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedInAndBack) { |
112 content::WebContents* contents = SetUpTest(); | 125 content::WebContents* contents = SetUpTest(); |
113 | 126 |
114 ZoomIn(); | 127 ZoomIn(); |
115 ExpectZoomedIn(contents); | 128 ExpectZoomedIn(contents); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 DCHECK_LT(GetZoomPercent(contents), zoom_level); | 176 DCHECK_LT(GetZoomPercent(contents), zoom_level); |
164 ExpectZoomedOut(contents); | 177 ExpectZoomedOut(contents); |
165 EXPECT_TRUE(ZoomIconIsShowing()); | 178 EXPECT_TRUE(ZoomIconIsShowing()); |
166 ExpectIconIsResource(IDR_ZOOM_MINUS); | 179 ExpectIconIsResource(IDR_ZOOM_MINUS); |
167 ExpectTooltipContainsZoom(); | 180 ExpectTooltipContainsZoom(); |
168 | 181 |
169 ResetZoom(); | 182 ResetZoom(); |
170 ExpectAtDefaultZoom(contents); | 183 ExpectAtDefaultZoom(contents); |
171 EXPECT_FALSE(ZoomIconIsShowing()); | 184 EXPECT_FALSE(ZoomIconIsShowing()); |
172 } | 185 } |
OLD | NEW |