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 typedef InProcessBrowserTest ZoomControllerBrowserTest; |
17 | 21 |
| 22 bool operator==(const ZoomController::ZoomChangedEventData& lhs, |
| 23 const ZoomController::ZoomChangedEventData& rhs) { |
| 24 return lhs.web_contents == rhs.web_contents && |
| 25 lhs.old_zoom_level == rhs.old_zoom_level && |
| 26 lhs.new_zoom_level == rhs.new_zoom_level && |
| 27 lhs.zoom_mode == rhs.zoom_mode && |
| 28 lhs.can_show_bubble == rhs.can_show_bubble; |
| 29 } |
| 30 |
| 31 class ZoomChangedWatcher : public ZoomObserver { |
| 32 public: |
| 33 ZoomChangedWatcher( |
| 34 content::WebContents* web_contents, |
| 35 const ZoomController::ZoomChangedEventData& expected_event_data) |
| 36 : web_contents_(web_contents), |
| 37 expected_event_data_(expected_event_data), |
| 38 message_loop_runner_(new content::MessageLoopRunner) { |
| 39 ZoomController::FromWebContents(web_contents)->AddObserver(this); |
| 40 } |
| 41 virtual ~ZoomChangedWatcher() {} |
| 42 |
| 43 void Wait() { message_loop_runner_->Run(); } |
| 44 |
| 45 virtual void OnZoomChanged( |
| 46 const ZoomController::ZoomChangedEventData& event_data) OVERRIDE { |
| 47 if (event_data == expected_event_data_) |
| 48 message_loop_runner_->Quit(); |
| 49 } |
| 50 |
| 51 private: |
| 52 content::WebContents* web_contents_; |
| 53 ZoomController::ZoomChangedEventData expected_event_data_; |
| 54 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(ZoomChangedWatcher); |
| 57 }; |
| 58 |
18 // TODO(wjmaclean): Enable this on Android when we can kill the process there. | 59 // TODO(wjmaclean): Enable this on Android when we can kill the process there. |
19 #if defined(OS_ANDROID) | 60 #if defined(OS_ANDROID) |
20 #define MAYBE_CrashedTabsDoNotChangeZoom DISABLED_CrashedTabsDoNotChangeZoom | 61 #define MAYBE_CrashedTabsDoNotChangeZoom DISABLED_CrashedTabsDoNotChangeZoom |
21 #else | 62 #else |
22 #define MAYBE_CrashedTabsDoNotChangeZoom CrashedTabsDoNotChangeZoom | 63 #define MAYBE_CrashedTabsDoNotChangeZoom CrashedTabsDoNotChangeZoom |
23 #endif | 64 #endif |
24 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, | 65 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, |
25 MAYBE_CrashedTabsDoNotChangeZoom) { | 66 MAYBE_CrashedTabsDoNotChangeZoom) { |
26 // At the start of the test we are at a tab displaying about:blank. | 67 // At the start of the test we are at a tab displaying about:blank. |
27 content::WebContents* web_contents = | 68 content::WebContents* web_contents = |
(...skipping 12 matching lines...) Expand all Loading... |
40 base::KillProcess(host->GetHandle(), 0, false); | 81 base::KillProcess(host->GetHandle(), 0, false); |
41 crash_observer.Wait(); | 82 crash_observer.Wait(); |
42 } | 83 } |
43 EXPECT_FALSE(web_contents->GetRenderProcessHost()->HasConnection()); | 84 EXPECT_FALSE(web_contents->GetRenderProcessHost()->HasConnection()); |
44 | 85 |
45 // The following attempt to change the zoom level for a crashed tab should | 86 // The following attempt to change the zoom level for a crashed tab should |
46 // fail. | 87 // fail. |
47 zoom_controller->SetZoomLevel(new_zoom_level); | 88 zoom_controller->SetZoomLevel(new_zoom_level); |
48 EXPECT_FLOAT_EQ(old_zoom_level, zoom_controller->GetZoomLevel()); | 89 EXPECT_FLOAT_EQ(old_zoom_level, zoom_controller->GetZoomLevel()); |
49 } | 90 } |
| 91 |
| 92 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, OnPreferenceChanged) { |
| 93 content::WebContents* web_contents = |
| 94 browser()->tab_strip_model()->GetActiveWebContents(); |
| 95 double new_default_zoom_level = 1.0; |
| 96 // Since this page uses the default zoom level, the changes to the default |
| 97 // zoom level will change the zoom level for this web_contents. |
| 98 ZoomController::ZoomChangedEventData zoom_change_data( |
| 99 web_contents, |
| 100 new_default_zoom_level, |
| 101 new_default_zoom_level, |
| 102 ZoomController::ZOOM_MODE_DEFAULT, |
| 103 true); |
| 104 ZoomChangedWatcher zoom_change_watcher(web_contents, zoom_change_data); |
| 105 // TODO(wjmaclean): Convert this to call partition-specific zoom level prefs |
| 106 // when they become available. |
| 107 browser()->profile()->GetPrefs()->SetDouble(prefs::kDefaultZoomLevel, |
| 108 new_default_zoom_level); |
| 109 // Because this test relies on a round-trip IPC to/from the renderer process, |
| 110 // we need to wait for it to propagate. |
| 111 zoom_change_watcher.Wait(); |
| 112 } |
OLD | NEW |