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 ZoomChangedWatcher : public ZoomObserver { | |
30 public: | |
31 ZoomChangedWatcher( | |
32 content::WebContents* web_contents, | |
33 const ZoomController::ZoomChangedEventData& expected_event_data) | |
34 : web_contents_(web_contents), | |
35 expected_event_data_(expected_event_data), | |
36 message_loop_runner_(new content::MessageLoopRunner) { | |
37 ZoomController::FromWebContents(web_contents)->AddObserver(this); | |
38 } | |
39 virtual ~ZoomChangedWatcher() {} | |
40 | |
41 void Wait() { message_loop_runner_->Run(); } | |
Dan Beam
2014/08/27 22:46:09
nit: \n
wjmaclean
2014/09/02 13:05:13
Done.
| |
42 virtual void OnZoomChanged( | |
43 const ZoomController::ZoomChangedEventData& event_data) OVERRIDE { | |
44 if (event_data == expected_event_data_) | |
45 message_loop_runner_->Quit(); | |
46 } | |
47 | |
48 private: | |
49 content::WebContents* web_contents_; | |
50 ZoomController::ZoomChangedEventData expected_event_data_; | |
51 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(ZoomChangedWatcher); | |
54 }; | |
55 | |
56 class TestZoomObserver : public ZoomObserver { | |
57 public: | |
58 MOCK_METHOD1(OnZoomChanged, | |
59 void(const ZoomController::ZoomChangedEventData&)); | |
60 }; | |
61 | |
62 class ZoomControllerBrowserTest : public InProcessBrowserTest { | |
63 protected: | |
Dan Beam
2014/08/27 22:46:09
nit: i'd say make public accessors with private me
wjmaclean
2014/09/02 13:05:12
Just realized we aren't using this anyway, so remo
| |
64 TestZoomObserver zoom_observer_; | |
65 }; | |
17 | 66 |
18 // TODO(wjmaclean): Enable this on Android when we can kill the process there. | 67 // TODO(wjmaclean): Enable this on Android when we can kill the process there. |
19 #if defined(OS_ANDROID) | 68 #if defined(OS_ANDROID) |
20 #define MAYBE_CrashedTabsDoNotChangeZoom DISABLED_CrashedTabsDoNotChangeZoom | 69 #define MAYBE_CrashedTabsDoNotChangeZoom DISABLED_CrashedTabsDoNotChangeZoom |
21 #else | 70 #else |
22 #define MAYBE_CrashedTabsDoNotChangeZoom CrashedTabsDoNotChangeZoom | 71 #define MAYBE_CrashedTabsDoNotChangeZoom CrashedTabsDoNotChangeZoom |
23 #endif | 72 #endif |
24 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, | 73 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, |
25 MAYBE_CrashedTabsDoNotChangeZoom) { | 74 MAYBE_CrashedTabsDoNotChangeZoom) { |
26 // At the start of the test we are at a tab displaying about:blank. | 75 // 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); | 89 base::KillProcess(host->GetHandle(), 0, false); |
41 crash_observer.Wait(); | 90 crash_observer.Wait(); |
42 } | 91 } |
43 EXPECT_FALSE(web_contents->GetRenderProcessHost()->HasConnection()); | 92 EXPECT_FALSE(web_contents->GetRenderProcessHost()->HasConnection()); |
44 | 93 |
45 // The following attempt to change the zoom level for a crashed tab should | 94 // The following attempt to change the zoom level for a crashed tab should |
46 // fail. | 95 // fail. |
47 zoom_controller->SetZoomLevel(new_zoom_level); | 96 zoom_controller->SetZoomLevel(new_zoom_level); |
48 EXPECT_FLOAT_EQ(old_zoom_level, zoom_controller->GetZoomLevel()); | 97 EXPECT_FLOAT_EQ(old_zoom_level, zoom_controller->GetZoomLevel()); |
49 } | 98 } |
99 | |
100 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, OnPreferenceChanged) { | |
101 content::WebContents* web_contents = | |
102 browser()->tab_strip_model()->GetActiveWebContents(); | |
103 double new_default_zoom_level = 1.0; | |
104 // Since this page uses the default zoom level, the changes to the default | |
105 // zoom level will change the zoom level for this web_contents. | |
106 ZoomController::ZoomChangedEventData zoom_change_data( | |
107 web_contents, | |
108 new_default_zoom_level, | |
109 new_default_zoom_level, | |
110 ZoomController::ZOOM_MODE_DEFAULT, | |
111 true); | |
112 ZoomChangedWatcher zoom_change_watcher(web_contents, zoom_change_data); | |
113 // TODO(wjmaclean) Convert this to call partition-specific zoom level prefs | |
Dan Beam
2014/08/27 22:46:09
add colon, e.g., TODO(wjmaclean): Convert
wjmaclean
2014/09/02 13:05:13
Done.
| |
114 // when they become available. | |
115 browser()->profile()->GetPrefs()->SetDouble(prefs::kDefaultZoomLevel, | |
116 new_default_zoom_level); | |
117 // Because this test relies on a round-trip IPC to/from the renderer process, | |
118 // we need to wait for it to propagate. | |
119 zoom_change_watcher.Wait(); | |
120 } | |
OLD | NEW |