| Index: chrome/browser/ui/zoom/zoom_controller_unittest.cc
|
| diff --git a/chrome/browser/ui/zoom/zoom_controller_unittest.cc b/chrome/browser/ui/zoom/zoom_controller_unittest.cc
|
| index 2db242f6e9a7b1021d65da4f03c6f28d91f9f6de..739656042a31629b620caa6dadf8b6680b0e44dd 100644
|
| --- a/chrome/browser/ui/zoom/zoom_controller_unittest.cc
|
| +++ b/chrome/browser/ui/zoom/zoom_controller_unittest.cc
|
| @@ -6,10 +6,10 @@
|
| #include "base/prefs/pref_service.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/browser_finder.h"
|
| -#include "chrome/browser/ui/zoom/zoom_controller.h"
|
| -#include "chrome/browser/ui/zoom/zoom_observer.h"
|
| #include "chrome/test/base/chrome_render_view_host_test_harness.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| +#include "components/ui/zoom/zoom_controller.h"
|
| +#include "components/ui/zoom/zoom_observer.h"
|
| #include "content/public/browser/host_zoom_map.h"
|
| #include "content/public/browser/navigation_details.h"
|
| #include "content/public/common/frame_navigate_params.h"
|
| @@ -18,6 +18,8 @@
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| +using ui_zoom::ZoomController;
|
| +
|
| bool operator==(const ZoomController::ZoomChangedEventData& lhs,
|
| const ZoomController::ZoomChangedEventData& rhs) {
|
| return lhs.web_contents == rhs.web_contents &&
|
| @@ -27,10 +29,32 @@ bool operator==(const ZoomController::ZoomChangedEventData& lhs,
|
| lhs.can_show_bubble == rhs.can_show_bubble;
|
| }
|
|
|
| -class TestZoomObserver : public ZoomObserver {
|
| +class ZoomChangedWatcher : public ui_zoom::ZoomObserver {
|
| public:
|
| - MOCK_METHOD1(OnZoomChanged,
|
| - void(const ZoomController::ZoomChangedEventData&));
|
| + ZoomChangedWatcher(
|
| + ZoomController* zoom_controller,
|
| + const ZoomController::ZoomChangedEventData& expected_event_data)
|
| + : zoom_controller_(zoom_controller),
|
| + expected_event_data_(expected_event_data),
|
| + message_loop_runner_(new content::MessageLoopRunner) {
|
| + zoom_controller_->AddObserver(this);
|
| + }
|
| + ~ZoomChangedWatcher() override { zoom_controller_->RemoveObserver(this); }
|
| +
|
| + void Wait() { message_loop_runner_->Run(); }
|
| +
|
| + void OnZoomChanged(
|
| + const ZoomController::ZoomChangedEventData& event_data) override {
|
| + if (event_data == expected_event_data_)
|
| + message_loop_runner_->Quit();
|
| + }
|
| +
|
| + private:
|
| + ZoomController* zoom_controller_;
|
| + ZoomController::ZoomChangedEventData expected_event_data_;
|
| + scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ZoomChangedWatcher);
|
| };
|
|
|
| class ZoomControllerTest : public ChromeRenderViewHostTestHarness {
|
| @@ -38,7 +62,6 @@ class ZoomControllerTest : public ChromeRenderViewHostTestHarness {
|
| void SetUp() override {
|
| ChromeRenderViewHostTestHarness::SetUp();
|
| zoom_controller_.reset(new ZoomController(web_contents()));
|
| - zoom_controller_->AddObserver(&zoom_observer_);
|
|
|
| // This call is needed so that the RenderViewHost reports being alive. This
|
| // is only important for tests that call ZoomController::SetZoomLevel().
|
| @@ -47,14 +70,12 @@ class ZoomControllerTest : public ChromeRenderViewHostTestHarness {
|
| }
|
|
|
| void TearDown() override {
|
| - zoom_controller_->RemoveObserver(&zoom_observer_);
|
| zoom_controller_.reset();
|
| ChromeRenderViewHostTestHarness::TearDown();
|
| }
|
|
|
| protected:
|
| scoped_ptr<ZoomController> zoom_controller_;
|
| - TestZoomObserver zoom_observer_;
|
| };
|
|
|
| TEST_F(ZoomControllerTest, DidNavigateMainFrame) {
|
| @@ -65,9 +86,11 @@ TEST_F(ZoomControllerTest, DidNavigateMainFrame) {
|
| zoom_level,
|
| ZoomController::ZOOM_MODE_DEFAULT,
|
| false);
|
| - EXPECT_CALL(zoom_observer_, OnZoomChanged(zoom_change_data)).Times(1);
|
| + ZoomChangedWatcher zoom_change_watcher(zoom_controller_.get(),
|
| + zoom_change_data);
|
| zoom_controller_->DidNavigateMainFrame(content::LoadCommittedDetails(),
|
| content::FrameNavigateParams());
|
| + zoom_change_watcher.Wait();
|
| }
|
|
|
| TEST_F(ZoomControllerTest, Observe_ZoomController) {
|
| @@ -82,9 +105,13 @@ TEST_F(ZoomControllerTest, Observe_ZoomController) {
|
| old_zoom_level,
|
| ZoomController::ZOOM_MODE_ISOLATED,
|
| true /* can_show_bubble */);
|
| - EXPECT_CALL(zoom_observer_, OnZoomChanged(zoom_change_data1)).Times(1);
|
|
|
| - zoom_controller_->SetZoomMode(ZoomController::ZOOM_MODE_ISOLATED);
|
| + {
|
| + ZoomChangedWatcher zoom_change_watcher1(zoom_controller_.get(),
|
| + zoom_change_data1);
|
| + zoom_controller_->SetZoomMode(ZoomController::ZOOM_MODE_ISOLATED);
|
| + zoom_change_watcher1.Wait();
|
| + }
|
|
|
| ZoomController::ZoomChangedEventData zoom_change_data2(
|
| web_contents(),
|
| @@ -92,7 +119,11 @@ TEST_F(ZoomControllerTest, Observe_ZoomController) {
|
| new_zoom_level,
|
| ZoomController::ZOOM_MODE_ISOLATED,
|
| true /* can_show_bubble */);
|
| - EXPECT_CALL(zoom_observer_, OnZoomChanged(zoom_change_data2)).Times(1);
|
|
|
| - zoom_controller_->SetZoomLevel(new_zoom_level);
|
| + {
|
| + ZoomChangedWatcher zoom_change_watcher2(zoom_controller_.get(),
|
| + zoom_change_data2);
|
| + zoom_controller_->SetZoomLevel(new_zoom_level);
|
| + zoom_change_watcher2.Wait();
|
| + }
|
| }
|
|
|