| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ui/zoom/zoom_controller.h" | 5 #include "components/ui/zoom/zoom_controller.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/process/kill.h" | 8 #include "base/process/kill.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" | 12 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
| 16 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
| 17 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/common/page_type.h" | 19 #include "content/public/common/page_type.h" |
| 20 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 | 22 |
| 23 using ui_zoom::ZoomController; |
| 24 using ui_zoom::ZoomObserver; |
| 25 |
| 23 bool operator==(const ZoomController::ZoomChangedEventData& lhs, | 26 bool operator==(const ZoomController::ZoomChangedEventData& lhs, |
| 24 const ZoomController::ZoomChangedEventData& rhs) { | 27 const ZoomController::ZoomChangedEventData& rhs) { |
| 25 return lhs.web_contents == rhs.web_contents && | 28 return lhs.web_contents == rhs.web_contents && |
| 26 lhs.old_zoom_level == rhs.old_zoom_level && | 29 lhs.old_zoom_level == rhs.old_zoom_level && |
| 27 lhs.new_zoom_level == rhs.new_zoom_level && | 30 lhs.new_zoom_level == rhs.new_zoom_level && |
| 28 lhs.zoom_mode == rhs.zoom_mode && | 31 lhs.zoom_mode == rhs.zoom_mode && |
| 29 lhs.can_show_bubble == rhs.can_show_bubble; | 32 lhs.can_show_bubble == rhs.can_show_bubble; |
| 30 } | 33 } |
| 31 | 34 |
| 32 class ZoomChangedWatcher : public ZoomObserver { | 35 class ZoomChangedWatcher : public ZoomObserver { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 50 } | 53 } |
| 51 | 54 |
| 52 private: | 55 private: |
| 53 content::WebContents* web_contents_; | 56 content::WebContents* web_contents_; |
| 54 ZoomController::ZoomChangedEventData expected_event_data_; | 57 ZoomController::ZoomChangedEventData expected_event_data_; |
| 55 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 58 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 56 | 59 |
| 57 DISALLOW_COPY_AND_ASSIGN(ZoomChangedWatcher); | 60 DISALLOW_COPY_AND_ASSIGN(ZoomChangedWatcher); |
| 58 }; | 61 }; |
| 59 | 62 |
| 60 class TestZoomObserver : public ZoomObserver { | 63 typedef InProcessBrowserTest ZoomControllerBrowserTest; |
| 61 public: | |
| 62 MOCK_METHOD1(OnZoomChanged, | |
| 63 void(const ZoomController::ZoomChangedEventData&)); | |
| 64 }; | |
| 65 | |
| 66 class ZoomControllerBrowserTest: public InProcessBrowserTest { | |
| 67 protected: | |
| 68 TestZoomObserver zoom_observer_; | |
| 69 }; | |
| 70 | 64 |
| 71 #if defined(OS_ANDROID) | 65 #if defined(OS_ANDROID) |
| 72 #define MAYBE_CrashedTabsDoNotChangeZoom DISABLED_CrashedTabsDoNotChangeZoom | 66 #define MAYBE_CrashedTabsDoNotChangeZoom DISABLED_CrashedTabsDoNotChangeZoom |
| 73 #else | 67 #else |
| 74 #define MAYBE_CrashedTabsDoNotChangeZoom CrashedTabsDoNotChangeZoom | 68 #define MAYBE_CrashedTabsDoNotChangeZoom CrashedTabsDoNotChangeZoom |
| 75 #endif | 69 #endif |
| 76 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, | 70 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, |
| 77 MAYBE_CrashedTabsDoNotChangeZoom) { | 71 MAYBE_CrashedTabsDoNotChangeZoom) { |
| 78 // At the start of the test we are at a tab displaying about:blank. | 72 // At the start of the test we are at a tab displaying about:blank. |
| 79 content::WebContents* web_contents = | 73 content::WebContents* web_contents = |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 132 |
| 139 // The following attempt to change the zoom level for an error page should | 133 // The following attempt to change the zoom level for an error page should |
| 140 // fail. | 134 // fail. |
| 141 zoom_controller->SetZoomLevel(new_zoom_level); | 135 zoom_controller->SetZoomLevel(new_zoom_level); |
| 142 EXPECT_FLOAT_EQ(new_zoom_level, zoom_controller->GetZoomLevel()); | 136 EXPECT_FLOAT_EQ(new_zoom_level, zoom_controller->GetZoomLevel()); |
| 143 } | 137 } |
| 144 | 138 |
| 145 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, Observe) { | 139 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, Observe) { |
| 146 content::WebContents* web_contents = | 140 content::WebContents* web_contents = |
| 147 browser()->tab_strip_model()->GetActiveWebContents(); | 141 browser()->tab_strip_model()->GetActiveWebContents(); |
| 148 ZoomController* zoom_controller = | |
| 149 ZoomController::FromWebContents(web_contents); | |
| 150 zoom_controller->AddObserver(&zoom_observer_); | |
| 151 | 142 |
| 152 double new_zoom_level = 1.0; | 143 double new_zoom_level = 1.0; |
| 153 // When the event is initiated from HostZoomMap, the old zoom level is not | 144 // When the event is initiated from HostZoomMap, the old zoom level is not |
| 154 // available. | 145 // available. |
| 155 ZoomController::ZoomChangedEventData zoom_change_data( | 146 ZoomController::ZoomChangedEventData zoom_change_data( |
| 156 web_contents, | 147 web_contents, |
| 157 new_zoom_level, | 148 new_zoom_level, |
| 158 new_zoom_level, | 149 new_zoom_level, |
| 159 ZoomController::ZOOM_MODE_DEFAULT, | 150 ZoomController::ZOOM_MODE_DEFAULT, |
| 160 true); // We have a non-empty host, so this will be 'true'. | 151 true); // We have a non-empty host, so this will be 'true'. |
| 161 EXPECT_CALL(zoom_observer_, OnZoomChanged(zoom_change_data)).Times(1); | 152 ZoomChangedWatcher zoom_change_watcher(web_contents, zoom_change_data); |
| 162 | 153 |
| 163 content::HostZoomMap* host_zoom_map = | 154 content::HostZoomMap* host_zoom_map = |
| 164 content::HostZoomMap::GetDefaultForBrowserContext( | 155 content::HostZoomMap::GetDefaultForBrowserContext( |
| 165 web_contents->GetBrowserContext()); | 156 web_contents->GetBrowserContext()); |
| 166 | 157 |
| 167 host_zoom_map->SetZoomLevelForHost("about:blank", new_zoom_level); | 158 host_zoom_map->SetZoomLevelForHost("about:blank", new_zoom_level); |
| 159 zoom_change_watcher.Wait(); |
| 168 } | 160 } |
| OLD | NEW |