OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/browser/ui/browser_finder.h" | 8 #include "chrome/browser/ui/browser_finder.h" |
9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
11 #include "components/ui/zoom/zoom_controller.h" | 11 #include "components/ui/zoom/zoom_controller.h" |
12 #include "components/ui/zoom/zoom_observer.h" | 12 #include "components/ui/zoom/zoom_observer.h" |
13 #include "components/ui/zoom/zoom_test_utils.h" | |
13 #include "content/public/browser/host_zoom_map.h" | 14 #include "content/public/browser/host_zoom_map.h" |
14 #include "content/public/browser/navigation_details.h" | 15 #include "content/public/browser/navigation_details.h" |
15 #include "content/public/common/frame_navigate_params.h" | 16 #include "content/public/common/frame_navigate_params.h" |
16 #include "content/public/test/test_renderer_host.h" | 17 #include "content/public/test/test_renderer_host.h" |
17 #include "content/public/test/test_utils.h" | 18 #include "content/public/test/test_utils.h" |
18 #include "ipc/ipc_message.h" | 19 #include "ipc/ipc_message.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 using ui_zoom::ZoomController; | 23 using ui_zoom::ZoomController; |
23 | 24 using ui_zoom::ZoomChangedWatcher; |
Lei Zhang
2015/10/23 18:14:32
Change before Control
wjmaclean
2015/10/29 15:33:36
Done.
| |
24 bool operator==(const ZoomController::ZoomChangedEventData& lhs, | |
25 const ZoomController::ZoomChangedEventData& rhs) { | |
26 return lhs.web_contents == rhs.web_contents && | |
27 lhs.old_zoom_level == rhs.old_zoom_level && | |
28 lhs.new_zoom_level == rhs.new_zoom_level && | |
29 lhs.zoom_mode == rhs.zoom_mode && | |
30 lhs.can_show_bubble == rhs.can_show_bubble; | |
31 } | |
32 | |
33 class ZoomChangedWatcher : public ui_zoom::ZoomObserver { | |
34 public: | |
35 ZoomChangedWatcher( | |
36 ZoomController* zoom_controller, | |
37 const ZoomController::ZoomChangedEventData& expected_event_data) | |
38 : zoom_controller_(zoom_controller), | |
39 expected_event_data_(expected_event_data), | |
40 message_loop_runner_(new content::MessageLoopRunner) { | |
41 zoom_controller_->AddObserver(this); | |
42 } | |
43 ~ZoomChangedWatcher() override { zoom_controller_->RemoveObserver(this); } | |
44 | |
45 void Wait() { message_loop_runner_->Run(); } | |
46 | |
47 void OnZoomChanged( | |
48 const ZoomController::ZoomChangedEventData& event_data) override { | |
49 if (event_data == expected_event_data_) | |
50 message_loop_runner_->Quit(); | |
51 } | |
52 | |
53 private: | |
54 ZoomController* zoom_controller_; | |
55 ZoomController::ZoomChangedEventData expected_event_data_; | |
56 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
57 | |
58 DISALLOW_COPY_AND_ASSIGN(ZoomChangedWatcher); | |
59 }; | |
60 | 25 |
61 class ZoomControllerTest : public ChromeRenderViewHostTestHarness { | 26 class ZoomControllerTest : public ChromeRenderViewHostTestHarness { |
62 public: | 27 public: |
63 void SetUp() override { | 28 void SetUp() override { |
64 ChromeRenderViewHostTestHarness::SetUp(); | 29 ChromeRenderViewHostTestHarness::SetUp(); |
65 zoom_controller_.reset(new ZoomController(web_contents())); | 30 zoom_controller_.reset(new ZoomController(web_contents())); |
66 | 31 |
67 // This call is needed so that the RenderViewHost reports being alive. This | 32 // This call is needed so that the RenderViewHost reports being alive. This |
68 // is only important for tests that call ZoomController::SetZoomLevel(). | 33 // is only important for tests that call ZoomController::SetZoomLevel(). |
69 content::RenderViewHostTester::For(rvh())->CreateTestRenderView( | 34 content::RenderViewHostTester::For(rvh())->CreateTestRenderView( |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 ZoomController::ZOOM_MODE_MANUAL, | 124 ZoomController::ZOOM_MODE_MANUAL, |
160 false /* can_show_bubble */); | 125 false /* can_show_bubble */); |
161 { | 126 { |
162 ZoomChangedWatcher zoom_change_watcher2(zoom_controller_.get(), | 127 ZoomChangedWatcher zoom_change_watcher2(zoom_controller_.get(), |
163 zoom_change_data2); | 128 zoom_change_data2); |
164 zoom_controller_->SetZoomLevel(new_zoom_level2); | 129 zoom_controller_->SetZoomLevel(new_zoom_level2); |
165 zoom_change_watcher2.Wait(); | 130 zoom_change_watcher2.Wait(); |
166 } | 131 } |
167 | 132 |
168 } | 133 } |
OLD | NEW |