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/process/kill.h" | 8 #include "base/process/kill.h" |
| 9 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/common/pref_names.h" |
10 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
11 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
12 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
13 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
14 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" |
15 | 19 |
16 typedef InProcessBrowserTest ZoomControllerBrowserTest; | 20 bool operator==(const ZoomController::ZoomChangedEventData& lhs, |
| 21 const ZoomController::ZoomChangedEventData& rhs) { |
| 22 return lhs.web_contents == rhs.web_contents && |
| 23 lhs.old_zoom_level == rhs.old_zoom_level && |
| 24 lhs.new_zoom_level == rhs.new_zoom_level && |
| 25 lhs.zoom_mode == rhs.zoom_mode && |
| 26 lhs.can_show_bubble == rhs.can_show_bubble; |
| 27 } |
| 28 |
| 29 class TestZoomObserver : public ZoomObserver { |
| 30 public: |
| 31 MOCK_METHOD1(OnZoomChanged, |
| 32 void(const ZoomController::ZoomChangedEventData&)); |
| 33 }; |
| 34 |
| 35 class ZoomControllerBrowserTest: public InProcessBrowserTest { |
| 36 protected: |
| 37 TestZoomObserver zoom_observer_; |
| 38 }; |
17 | 39 |
18 // TODO(wjmaclean): Enable this on Android when we can kill the process there. | 40 // TODO(wjmaclean): Enable this on Android when we can kill the process there. |
19 #if defined(OS_ANDROID) | 41 #if defined(OS_ANDROID) |
20 #define MAYBE_CrashedTabsDoNotChangeZoom DISABLED_CrashedTabsDoNotChangeZoom | 42 #define MAYBE_CrashedTabsDoNotChangeZoom DISABLED_CrashedTabsDoNotChangeZoom |
21 #else | 43 #else |
22 #define MAYBE_CrashedTabsDoNotChangeZoom CrashedTabsDoNotChangeZoom | 44 #define MAYBE_CrashedTabsDoNotChangeZoom CrashedTabsDoNotChangeZoom |
23 #endif | 45 #endif |
24 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, | 46 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, |
25 MAYBE_CrashedTabsDoNotChangeZoom) { | 47 MAYBE_CrashedTabsDoNotChangeZoom) { |
26 // At the start of the test we are at a tab displaying about:blank. | 48 // At the start of the test we are at a tab displaying about:blank. |
(...skipping 13 matching lines...) Expand all Loading... |
40 base::KillProcess(host->GetHandle(), 0, false); | 62 base::KillProcess(host->GetHandle(), 0, false); |
41 crash_observer.Wait(); | 63 crash_observer.Wait(); |
42 } | 64 } |
43 EXPECT_FALSE(web_contents->GetRenderProcessHost()->HasConnection()); | 65 EXPECT_FALSE(web_contents->GetRenderProcessHost()->HasConnection()); |
44 | 66 |
45 // The following attempt to change the zoom level for a crashed tab should | 67 // The following attempt to change the zoom level for a crashed tab should |
46 // fail. | 68 // fail. |
47 zoom_controller->SetZoomLevel(new_zoom_level); | 69 zoom_controller->SetZoomLevel(new_zoom_level); |
48 EXPECT_FLOAT_EQ(old_zoom_level, zoom_controller->GetZoomLevel()); | 70 EXPECT_FLOAT_EQ(old_zoom_level, zoom_controller->GetZoomLevel()); |
49 } | 71 } |
| 72 |
| 73 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, OnPreferenceChanged) { |
| 74 content::WebContents* web_contents = |
| 75 browser()->tab_strip_model()->GetActiveWebContents(); |
| 76 ZoomController* zoom_controller = |
| 77 ZoomController::FromWebContents(web_contents); |
| 78 zoom_controller->AddObserver(&zoom_observer_); |
| 79 double new_default_zoom_level = 1.0; |
| 80 // Since this page uses the default zoom level, the changes to the default |
| 81 // zoom level will change the zoom level for this web_contents. |
| 82 ZoomController::ZoomChangedEventData zoom_change_data( |
| 83 web_contents, |
| 84 new_default_zoom_level, |
| 85 new_default_zoom_level, |
| 86 ZoomController::ZOOM_MODE_DEFAULT, |
| 87 false); |
| 88 EXPECT_CALL(zoom_observer_, OnZoomChanged(zoom_change_data)).Times(1); |
| 89 browser()->profile()->GetZoomLevelPrefs()->SetDouble(prefs::kDefaultZoomLevel, |
| 90 new_default_zoom_level); |
| 91 } |
| 92 |
| 93 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, Observe) { |
| 94 content::WebContents* web_contents = |
| 95 browser()->tab_strip_model()->GetActiveWebContents(); |
| 96 ZoomController* zoom_controller = |
| 97 ZoomController::FromWebContents(web_contents); |
| 98 zoom_controller->AddObserver(&zoom_observer_); |
| 99 |
| 100 double new_zoom_level = 1.0; |
| 101 // When the event is initiated from HostZoomMap, the old zoom level is not |
| 102 // available. |
| 103 ZoomController::ZoomChangedEventData zoom_change_data( |
| 104 web_contents, |
| 105 new_zoom_level, |
| 106 new_zoom_level, |
| 107 ZoomController::ZOOM_MODE_DEFAULT, |
| 108 true); // We have a non-empty host, so this will be 'true'. |
| 109 EXPECT_CALL(zoom_observer_, OnZoomChanged(zoom_change_data)).Times(1); |
| 110 |
| 111 content::HostZoomMap* host_zoom_map = |
| 112 content::HostZoomMap::GetDefaultForBrowserContext( |
| 113 web_contents->GetBrowserContext()); |
| 114 |
| 115 host_zoom_map->SetZoomLevelForHost("about:blank", new_zoom_level); |
| 116 } |
| 117 |
| 118 |
OLD | NEW |