| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 39 void ExpectZoomedOut(content::WebContents* contents) { | 40 void ExpectZoomedOut(content::WebContents* contents) { |
| 40 EXPECT_LT(GetZoomPercent(contents), 100); | 41 EXPECT_LT(GetZoomPercent(contents), 100); |
| 41 } | 42 } |
| 42 | 43 |
| 43 void ExpectAtDefaultZoom(content::WebContents* contents) { | 44 void ExpectAtDefaultZoom(content::WebContents* contents) { |
| 44 EXPECT_EQ(GetZoomPercent(contents), 100); | 45 EXPECT_EQ(GetZoomPercent(contents), 100); |
| 45 } | 46 } |
| 46 | 47 |
| 47 } | 48 } |
| 48 | 49 |
| 49 class LocationBarViewGtkZoomTest : public InProcessBrowserTest { | 50 class LocationBarViewGtkZoomTest : public content::HostZoomMap::Observer, |
| 51 public InProcessBrowserTest { |
| 50 public: | 52 public: |
| 51 LocationBarViewGtkZoomTest() {} | 53 LocationBarViewGtkZoomTest() {} |
| 52 virtual ~LocationBarViewGtkZoomTest() {} | 54 virtual ~LocationBarViewGtkZoomTest() {} |
| 53 | 55 |
| 54 protected: | 56 protected: |
| 55 void ExpectTooltipContainsZoom() { | 57 void ExpectTooltipContainsZoom() { |
| 56 gchar* text = gtk_widget_get_tooltip_text(GetZoomWidget()); | 58 gchar* text = gtk_widget_get_tooltip_text(GetZoomWidget()); |
| 57 std::string tooltip(text); | 59 std::string tooltip(text); |
| 58 g_free(text); | 60 g_free(text); |
| 59 content::WebContents* contents = chrome::GetActiveWebContents(browser()); | 61 content::WebContents* contents = chrome::GetActiveWebContents(browser()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 84 } | 86 } |
| 85 | 87 |
| 86 void ZoomIn() { | 88 void ZoomIn() { |
| 87 WaitForZoom(content::PAGE_ZOOM_IN); | 89 WaitForZoom(content::PAGE_ZOOM_IN); |
| 88 } | 90 } |
| 89 | 91 |
| 90 void ZoomOut() { | 92 void ZoomOut() { |
| 91 WaitForZoom(content::PAGE_ZOOM_OUT); | 93 WaitForZoom(content::PAGE_ZOOM_OUT); |
| 92 } | 94 } |
| 93 | 95 |
| 96 virtual void OnZoomLevelChanged(const std::string& host) { |
| 97 message_loop_runner_->Quit(); |
| 98 } |
| 99 |
| 94 private: | 100 private: |
| 95 GtkWidget* GetZoomWidget() { | 101 GtkWidget* GetZoomWidget() { |
| 96 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | 102 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); |
| 97 return ViewIDUtil::GetWidget(GTK_WIDGET(window), VIEW_ID_ZOOM_BUTTON); | 103 return ViewIDUtil::GetWidget(GTK_WIDGET(window), VIEW_ID_ZOOM_BUTTON); |
| 98 } | 104 } |
| 99 | 105 |
| 100 void WaitForZoom(content::PageZoom zoom_action) { | 106 void WaitForZoom(content::PageZoom zoom_action) { |
| 101 content::WindowedNotificationObserver zoom_observer( | 107 Observe(content::HostZoomMap::GetForBrowserContext(browser()->profile())); |
| 102 content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | |
| 103 content::NotificationService::AllSources()); | |
| 104 chrome::Zoom(browser(), zoom_action); | 108 chrome::Zoom(browser(), zoom_action); |
| 105 zoom_observer.Wait(); | 109 message_loop_runner_ = new content::MessageLoopRunner; |
| 110 message_loop_runner_->Run(); |
| 106 } | 111 } |
| 107 | 112 |
| 113 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 114 |
| 108 DISALLOW_COPY_AND_ASSIGN(LocationBarViewGtkZoomTest); | 115 DISALLOW_COPY_AND_ASSIGN(LocationBarViewGtkZoomTest); |
| 109 }; | 116 }; |
| 110 | 117 |
| 111 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedInAndBack) { | 118 IN_PROC_BROWSER_TEST_F(LocationBarViewGtkZoomTest, DefaultToZoomedInAndBack) { |
| 112 content::WebContents* contents = SetUpTest(); | 119 content::WebContents* contents = SetUpTest(); |
| 113 | 120 |
| 114 ZoomIn(); | 121 ZoomIn(); |
| 115 ExpectZoomedIn(contents); | 122 ExpectZoomedIn(contents); |
| 116 EXPECT_TRUE(ZoomIconIsShowing()); | 123 EXPECT_TRUE(ZoomIconIsShowing()); |
| 117 ExpectIconIsResource(IDR_ZOOM_PLUS); | 124 ExpectIconIsResource(IDR_ZOOM_PLUS); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 DCHECK_LT(GetZoomPercent(contents), zoom_level); | 170 DCHECK_LT(GetZoomPercent(contents), zoom_level); |
| 164 ExpectZoomedOut(contents); | 171 ExpectZoomedOut(contents); |
| 165 EXPECT_TRUE(ZoomIconIsShowing()); | 172 EXPECT_TRUE(ZoomIconIsShowing()); |
| 166 ExpectIconIsResource(IDR_ZOOM_MINUS); | 173 ExpectIconIsResource(IDR_ZOOM_MINUS); |
| 167 ExpectTooltipContainsZoom(); | 174 ExpectTooltipContainsZoom(); |
| 168 | 175 |
| 169 ResetZoom(); | 176 ResetZoom(); |
| 170 ExpectAtDefaultZoom(contents); | 177 ExpectAtDefaultZoom(contents); |
| 171 EXPECT_FALSE(ZoomIconIsShowing()); | 178 EXPECT_FALSE(ZoomIconIsShowing()); |
| 172 } | 179 } |
| OLD | NEW |