Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..78a3839cf88b20bd716c115524e32d244f91c0b5 |
| --- /dev/null |
| +++ b/chrome/browser/ui/zoom/zoom_controller_unittest.cc |
| @@ -0,0 +1,81 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/message_loop.h" |
| +#include "chrome/browser/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/common/pref_names.h" |
| +#include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| +#include "chrome/test/base/testing_profile.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/host_zoom_map.h" |
| +#include "content/public/browser/navigation_details.h" |
| +#include "content/public/browser/notification_details.h" |
| +#include "content/public/browser/notification_source.h" |
| +#include "content/public/browser/notification_types.h" |
| +#include "content/public/common/frame_navigate_params.h" |
| +#include "content/public/test/test_browser_thread.h" |
| +#include "content/public/test/test_utils.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +class TestZoomObserver : public ZoomObserver { |
| + public: |
| + MOCK_METHOD2(OnZoomChanged, void(content::WebContents*, bool)); |
| +}; |
| + |
| +class ZoomControllerTest : public ChromeRenderViewHostTestHarness { |
| + public: |
| + ZoomControllerTest() |
| + : ui_thread_(content::BrowserThread::UI, MessageLoop::current()) {} |
| + |
| + void SetUp() OVERRIDE { |
|
Evan Stade
2012/11/17 01:33:06
shouldn't this be virtual void SetUp() OVERRIDE?
Dan Beam
2012/11/17 01:53:42
Done.
|
| + ChromeRenderViewHostTestHarness::SetUp(); |
| + zoom_controller_.reset(new ZoomController(web_contents())); |
| + zoom_controller_->set_observer(&zoom_observer_); |
| + } |
| + |
| + void TearDown() OVERRIDE { |
|
Evan Stade
2012/11/17 01:33:06
ditto
Dan Beam
2012/11/17 01:53:42
Done.
|
| + zoom_controller_.reset(); |
| + ChromeRenderViewHostTestHarness::TearDown(); |
| + } |
| + |
| + protected: |
| + scoped_ptr<ZoomController> zoom_controller_; |
| + TestZoomObserver zoom_observer_; |
| + |
| + private: |
| + content::TestBrowserThread ui_thread_; |
| + DISALLOW_COPY_AND_ASSIGN(ZoomControllerTest); |
| +}; |
| + |
| +TEST_F(ZoomControllerTest, DidNavigateMainFrame) { |
| + EXPECT_CALL(zoom_observer_, OnZoomChanged(web_contents(), false)).Times(1); |
| + zoom_controller_->DidNavigateMainFrame(content::LoadCommittedDetails(), |
| + content::FrameNavigateParams()); |
| +} |
| + |
| +TEST_F(ZoomControllerTest, OnPreferenceChanged) { |
| + EXPECT_CALL(zoom_observer_, OnZoomChanged(web_contents(), false)).Times(1); |
| + profile()->GetPrefs()->SetDouble(prefs::kDefaultZoomLevel, 110.0f); |
| +} |
| + |
| +TEST_F(ZoomControllerTest, Observe) { |
| + EXPECT_CALL(zoom_observer_, OnZoomChanged(web_contents(), false)).Times(1); |
| + |
| + content::HostZoomMap* host_zoom_map = |
| + content::HostZoomMap::GetForBrowserContext( |
| + web_contents()->GetBrowserContext()); |
| + |
| + content::WindowedNotificationObserver notification_observer( |
| + content::NOTIFICATION_ZOOM_LEVEL_CHANGED, |
| + content::NotificationService::AllSources()); |
| + |
| + host_zoom_map->SetZoomLevel(std::string(), 110.0f); |
| + |
| + notification_observer.Wait(); |
| +} |