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 "chrome/browser/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 typedef InProcessBrowserTest ZoomControllerBrowserTest; | |
24 | |
25 bool operator==(const ZoomController::ZoomChangedEventData& lhs, | 23 bool operator==(const ZoomController::ZoomChangedEventData& lhs, |
26 const ZoomController::ZoomChangedEventData& rhs) { | 24 const ZoomController::ZoomChangedEventData& rhs) { |
27 return lhs.web_contents == rhs.web_contents && | 25 return lhs.web_contents == rhs.web_contents && |
28 lhs.old_zoom_level == rhs.old_zoom_level && | 26 lhs.old_zoom_level == rhs.old_zoom_level && |
29 lhs.new_zoom_level == rhs.new_zoom_level && | 27 lhs.new_zoom_level == rhs.new_zoom_level && |
30 lhs.zoom_mode == rhs.zoom_mode && | 28 lhs.zoom_mode == rhs.zoom_mode && |
31 lhs.can_show_bubble == rhs.can_show_bubble; | 29 lhs.can_show_bubble == rhs.can_show_bubble; |
32 } | 30 } |
33 | 31 |
34 class ZoomChangedWatcher : public ZoomObserver { | 32 class ZoomChangedWatcher : public ZoomObserver { |
(...skipping 17 matching lines...) Expand all Loading... |
52 } | 50 } |
53 | 51 |
54 private: | 52 private: |
55 content::WebContents* web_contents_; | 53 content::WebContents* web_contents_; |
56 ZoomController::ZoomChangedEventData expected_event_data_; | 54 ZoomController::ZoomChangedEventData expected_event_data_; |
57 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 55 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
58 | 56 |
59 DISALLOW_COPY_AND_ASSIGN(ZoomChangedWatcher); | 57 DISALLOW_COPY_AND_ASSIGN(ZoomChangedWatcher); |
60 }; | 58 }; |
61 | 59 |
62 // TODO(wjmaclean): Enable this on Android when we can kill the process there. | 60 class TestZoomObserver : public ZoomObserver { |
| 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 |
63 #if defined(OS_ANDROID) | 71 #if defined(OS_ANDROID) |
64 #define MAYBE_CrashedTabsDoNotChangeZoom DISABLED_CrashedTabsDoNotChangeZoom | 72 #define MAYBE_CrashedTabsDoNotChangeZoom DISABLED_CrashedTabsDoNotChangeZoom |
65 #else | 73 #else |
66 #define MAYBE_CrashedTabsDoNotChangeZoom CrashedTabsDoNotChangeZoom | 74 #define MAYBE_CrashedTabsDoNotChangeZoom CrashedTabsDoNotChangeZoom |
67 #endif | 75 #endif |
68 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, | 76 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, |
69 MAYBE_CrashedTabsDoNotChangeZoom) { | 77 MAYBE_CrashedTabsDoNotChangeZoom) { |
70 // At the start of the test we are at a tab displaying about:blank. | 78 // At the start of the test we are at a tab displaying about:blank. |
71 content::WebContents* web_contents = | 79 content::WebContents* web_contents = |
72 browser()->tab_strip_model()->GetActiveWebContents(); | 80 browser()->tab_strip_model()->GetActiveWebContents(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 web_contents->GetController().GetLastCommittedEntry()->GetPageType()); | 134 web_contents->GetController().GetLastCommittedEntry()->GetPageType()); |
127 | 135 |
128 double old_zoom_level = zoom_controller->GetZoomLevel(); | 136 double old_zoom_level = zoom_controller->GetZoomLevel(); |
129 double new_zoom_level = old_zoom_level + 0.5; | 137 double new_zoom_level = old_zoom_level + 0.5; |
130 | 138 |
131 // The following attempt to change the zoom level for an error page should | 139 // The following attempt to change the zoom level for an error page should |
132 // fail. | 140 // fail. |
133 zoom_controller->SetZoomLevel(new_zoom_level); | 141 zoom_controller->SetZoomLevel(new_zoom_level); |
134 EXPECT_FLOAT_EQ(new_zoom_level, zoom_controller->GetZoomLevel()); | 142 EXPECT_FLOAT_EQ(new_zoom_level, zoom_controller->GetZoomLevel()); |
135 } | 143 } |
| 144 |
| 145 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, Observe) { |
| 146 content::WebContents* web_contents = |
| 147 browser()->tab_strip_model()->GetActiveWebContents(); |
| 148 ZoomController* zoom_controller = |
| 149 ZoomController::FromWebContents(web_contents); |
| 150 zoom_controller->AddObserver(&zoom_observer_); |
| 151 |
| 152 double new_zoom_level = 1.0; |
| 153 // When the event is initiated from HostZoomMap, the old zoom level is not |
| 154 // available. |
| 155 ZoomController::ZoomChangedEventData zoom_change_data( |
| 156 web_contents, |
| 157 new_zoom_level, |
| 158 new_zoom_level, |
| 159 ZoomController::ZOOM_MODE_DEFAULT, |
| 160 true); // We have a non-empty host, so this will be 'true'. |
| 161 EXPECT_CALL(zoom_observer_, OnZoomChanged(zoom_change_data)).Times(1); |
| 162 |
| 163 content::HostZoomMap* host_zoom_map = |
| 164 content::HostZoomMap::GetDefaultForBrowserContext( |
| 165 web_contents->GetBrowserContext()); |
| 166 |
| 167 host_zoom_map->SetZoomLevelForHost("about:blank", new_zoom_level); |
| 168 } |
OLD | NEW |