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
3 // found in the LICENSE file.
5 #include "base/message_loop/message_loop.h"
6 #include "base/prefs/pref_service.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_finder.h"
9 #include "chrome/browser/ui/zoom/zoom_controller.h"
10 #include "chrome/browser/ui/zoom/zoom_observer.h"
11 #include "chrome/common/pref_names.h"
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
13 #include "chrome/test/base/testing_profile.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/host_zoom_map.h"
16 #include "content/public/browser/navigation_details.h"
17 #include "content/public/common/frame_navigate_params.h"
18 #include "content/public/test/test_utils.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h"
22 class TestZoomObserver
: public ZoomObserver
{
24 MOCK_METHOD2(OnZoomChanged
, void(content::WebContents
*, bool));
27 class ZoomControllerTest
: public ChromeRenderViewHostTestHarness
{
29 virtual void SetUp() OVERRIDE
{
30 ChromeRenderViewHostTestHarness::SetUp();
31 zoom_controller_
.reset(new ZoomController(web_contents()));
32 zoom_controller_
->set_observer(&zoom_observer_
);
35 virtual void TearDown() OVERRIDE
{
36 zoom_controller_
.reset();
37 ChromeRenderViewHostTestHarness::TearDown();
41 scoped_ptr
<ZoomController
> zoom_controller_
;
42 TestZoomObserver zoom_observer_
;
45 TEST_F(ZoomControllerTest
, DidNavigateMainFrame
) {
46 EXPECT_CALL(zoom_observer_
, OnZoomChanged(web_contents(), false)).Times(1);
47 zoom_controller_
->DidNavigateMainFrame(content::LoadCommittedDetails(),
48 content::FrameNavigateParams());
51 TEST_F(ZoomControllerTest
, OnPreferenceChanged
) {
52 EXPECT_CALL(zoom_observer_
, OnZoomChanged(web_contents(), false)).Times(1);
53 profile()->GetPrefs()->SetDouble(prefs::kDefaultZoomLevel
, 110.0f
);
56 TEST_F(ZoomControllerTest
, Observe
) {
57 EXPECT_CALL(zoom_observer_
, OnZoomChanged(web_contents(), false)).Times(1);
59 content::HostZoomMap
* host_zoom_map
=
60 content::HostZoomMap::GetForBrowserContext(
61 web_contents()->GetBrowserContext());
63 host_zoom_map
->SetZoomLevelForHost(std::string(), 110.0f
);