| 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/browser/ui/zoom/zoom_controller.h" | 9 #include "chrome/browser/ui/zoom/zoom_controller.h" |
| 10 #include "chrome/browser/ui/zoom/zoom_observer.h" | 10 #include "chrome/browser/ui/zoom/zoom_observer.h" |
| 11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
| 12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 14 #include "content/public/browser/host_zoom_map.h" | 14 #include "content/public/browser/host_zoom_map.h" |
| 15 #include "content/public/browser/navigation_details.h" | 15 #include "content/public/browser/navigation_details.h" |
| 16 #include "content/public/common/frame_navigate_params.h" | 16 #include "content/public/common/frame_navigate_params.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 "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 bool operator==(const ZoomController::ZoomChangedEventData& lhs, | 22 bool operator==(const ZoomController::ZoomChangedEventData& lhs, |
| 22 const ZoomController::ZoomChangedEventData& rhs) { | 23 const ZoomController::ZoomChangedEventData& rhs) { |
| 23 return lhs.web_contents == rhs.web_contents && | 24 return lhs.web_contents == rhs.web_contents && |
| 24 lhs.old_zoom_level == rhs.old_zoom_level && | 25 lhs.old_zoom_level == rhs.old_zoom_level && |
| 25 lhs.new_zoom_level == rhs.new_zoom_level && | 26 lhs.new_zoom_level == rhs.new_zoom_level && |
| 26 lhs.zoom_mode == rhs.zoom_mode && | 27 lhs.zoom_mode == rhs.zoom_mode && |
| 27 lhs.can_show_bubble == rhs.can_show_bubble; | 28 lhs.can_show_bubble == rhs.can_show_bubble; |
| 28 } | 29 } |
| 29 | 30 |
| 30 class TestZoomObserver : public ZoomObserver { | 31 class TestZoomObserver : public ZoomObserver { |
| 31 public: | 32 public: |
| 32 MOCK_METHOD1(OnZoomChanged, | 33 MOCK_METHOD1(OnZoomChanged, |
| 33 void(const ZoomController::ZoomChangedEventData&)); | 34 void(const ZoomController::ZoomChangedEventData&)); |
| 34 }; | 35 }; |
| 35 | 36 |
| 36 class ZoomControllerTest : public ChromeRenderViewHostTestHarness { | 37 class ZoomControllerTest : public ChromeRenderViewHostTestHarness { |
| 37 public: | 38 public: |
| 38 virtual void SetUp() OVERRIDE { | 39 virtual void SetUp() OVERRIDE { |
| 39 ChromeRenderViewHostTestHarness::SetUp(); | 40 ChromeRenderViewHostTestHarness::SetUp(); |
| 40 zoom_controller_.reset(new ZoomController(web_contents())); | 41 zoom_controller_.reset(new ZoomController(web_contents())); |
| 41 zoom_controller_->AddObserver(&zoom_observer_); | 42 zoom_controller_->AddObserver(&zoom_observer_); |
| 43 |
| 44 // This call is needed so that the RenderViewHost reports being alive. This |
| 45 // is only important for tests that call ZoomController::SetZoomLevel(). |
| 46 content::RenderViewHostTester::For(rvh())->CreateRenderView( |
| 47 base::string16(), MSG_ROUTING_NONE, MSG_ROUTING_NONE, -1, false); |
| 42 } | 48 } |
| 43 | 49 |
| 44 virtual void TearDown() OVERRIDE { | 50 virtual void TearDown() OVERRIDE { |
| 45 zoom_controller_->RemoveObserver(&zoom_observer_); | 51 zoom_controller_->RemoveObserver(&zoom_observer_); |
| 46 zoom_controller_.reset(); | 52 zoom_controller_.reset(); |
| 47 ChromeRenderViewHostTestHarness::TearDown(); | 53 ChromeRenderViewHostTestHarness::TearDown(); |
| 48 } | 54 } |
| 49 | 55 |
| 50 protected: | 56 protected: |
| 51 scoped_ptr<ZoomController> zoom_controller_; | 57 scoped_ptr<ZoomController> zoom_controller_; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 ZoomController::ZoomChangedEventData zoom_change_data2( | 107 ZoomController::ZoomChangedEventData zoom_change_data2( |
| 102 web_contents(), | 108 web_contents(), |
| 103 old_zoom_level, | 109 old_zoom_level, |
| 104 new_zoom_level, | 110 new_zoom_level, |
| 105 ZoomController::ZOOM_MODE_ISOLATED, | 111 ZoomController::ZOOM_MODE_ISOLATED, |
| 106 false /* can_show_bubble */); | 112 false /* can_show_bubble */); |
| 107 EXPECT_CALL(zoom_observer_, OnZoomChanged(zoom_change_data2)).Times(1); | 113 EXPECT_CALL(zoom_observer_, OnZoomChanged(zoom_change_data2)).Times(1); |
| 108 | 114 |
| 109 zoom_controller_->SetZoomLevel(new_zoom_level); | 115 zoom_controller_->SetZoomLevel(new_zoom_level); |
| 110 } | 116 } |
| OLD | NEW |