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

Side by Side Diff: chrome/browser/ui/gtk/location_bar_view_gtk_browsertest.cc

Issue 12039058: content: convert zoom notifications to observer usage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 10 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
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_window.h" 11 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" 12 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h"
12 #include "chrome/browser/ui/gtk/browser_window_gtk.h" 13 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
13 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" 14 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
14 #include "chrome/browser/ui/gtk/view_id_util.h" 15 #include "chrome/browser/ui/gtk/view_id_util.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 WaitForZoom(content::PAGE_ZOOM_OUT); 101 WaitForZoom(content::PAGE_ZOOM_OUT);
95 } 102 }
96 103
97 private: 104 private:
98 GtkWidget* GetZoomWidget() { 105 GtkWidget* GetZoomWidget() {
99 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); 106 gfx::NativeWindow window = browser()->window()->GetNativeWindow();
100 return ViewIDUtil::GetWidget(GTK_WIDGET(window), VIEW_ID_ZOOM_BUTTON); 107 return ViewIDUtil::GetWidget(GTK_WIDGET(window), VIEW_ID_ZOOM_BUTTON);
101 } 108 }
102 109
103 void WaitForZoom(content::PageZoom zoom_action) { 110 void WaitForZoom(content::PageZoom zoom_action) {
104 content::WindowedNotificationObserver zoom_observer( 111 scoped_refptr<content::MessageLoopRunner> loop_runner(
105 content::NOTIFICATION_ZOOM_LEVEL_CHANGED, 112 new content::MessageLoopRunner);
106 content::NotificationService::AllSources()); 113 content::HostZoomMap::ZoomLevelChangedCallback callback(
114 base::Bind(&OnZoomLevelChanged, loop_runner->QuitClosure()));
115 content::HostZoomMap::GetForBrowserContext(
116 browser()->profile())->AddZoomLevelChangedCallback(callback);
107 chrome::Zoom(browser(), zoom_action); 117 chrome::Zoom(browser(), zoom_action);
108 zoom_observer.Wait(); 118 loop_runner->Run();
119 content::HostZoomMap::GetForBrowserContext(
120 browser()->profile())->RemoveZoomLevelChangedCallback(callback);
109 } 121 }
110 122
111 DISALLOW_COPY_AND_ASSIGN(LocationBarViewGtkZoomTest); 123 DISALLOW_COPY_AND_ASSIGN(LocationBarViewGtkZoomTest);
112 }; 124 };
113 125
114 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedInAndBack) { 126 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedInAndBack) {
115 content::WebContents* contents = SetUpTest(); 127 content::WebContents* contents = SetUpTest();
116 128
117 ZoomIn(); 129 ZoomIn();
118 ExpectZoomedIn(contents); 130 ExpectZoomedIn(contents);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 DCHECK_LT(GetZoomPercent(contents), zoom_level); 178 DCHECK_LT(GetZoomPercent(contents), zoom_level);
167 ExpectZoomedOut(contents); 179 ExpectZoomedOut(contents);
168 EXPECT_TRUE(ZoomIconIsShowing()); 180 EXPECT_TRUE(ZoomIconIsShowing());
169 ExpectIconIsResource(IDR_ZOOM_MINUS); 181 ExpectIconIsResource(IDR_ZOOM_MINUS);
170 ExpectTooltipContainsZoom(); 182 ExpectTooltipContainsZoom();
171 183
172 ResetZoom(); 184 ResetZoom();
173 ExpectAtDefaultZoom(contents); 185 ExpectAtDefaultZoom(contents);
174 EXPECT_FALSE(ZoomIconIsShowing()); 186 EXPECT_FALSE(ZoomIconIsShowing());
175 } 187 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/browser_toolbar_gtk.cc ('k') | chrome/browser/ui/toolbar/wrench_menu_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698