Home | History | Annotate | Download | only in zoom
      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.
      4 
      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/host_zoom_map.h"
     15 #include "content/public/browser/navigation_details.h"
     16 #include "content/public/common/frame_navigate_params.h"
     17 #include "content/public/test/test_utils.h"
     18 #include "testing/gmock/include/gmock/gmock.h"
     19 #include "testing/gtest/include/gtest/gtest.h"
     20 
     21 class TestZoomObserver : public ZoomObserver {
     22  public:
     23   MOCK_METHOD2(OnZoomChanged, void(content::WebContents*, bool));
     24 };
     25 
     26 class ZoomControllerTest : public ChromeRenderViewHostTestHarness {
     27  public:
     28   virtual void SetUp() OVERRIDE {
     29     ChromeRenderViewHostTestHarness::SetUp();
     30     zoom_controller_.reset(new ZoomController(web_contents()));
     31     zoom_controller_->set_observer(&zoom_observer_);
     32   }
     33 
     34   virtual void TearDown() OVERRIDE {
     35     zoom_controller_.reset();
     36     ChromeRenderViewHostTestHarness::TearDown();
     37   }
     38 
     39  protected:
     40   scoped_ptr<ZoomController> zoom_controller_;
     41   TestZoomObserver zoom_observer_;
     42 };
     43 
     44 TEST_F(ZoomControllerTest, DidNavigateMainFrame) {
     45   EXPECT_CALL(zoom_observer_, OnZoomChanged(web_contents(), false)).Times(1);
     46   zoom_controller_->DidNavigateMainFrame(content::LoadCommittedDetails(),
     47                                          content::FrameNavigateParams());
     48 }
     49 
     50 TEST_F(ZoomControllerTest, OnPreferenceChanged) {
     51   EXPECT_CALL(zoom_observer_, OnZoomChanged(web_contents(), false)).Times(1);
     52   profile()->GetPrefs()->SetDouble(prefs::kDefaultZoomLevel, 110.0f);
     53 }
     54 
     55 TEST_F(ZoomControllerTest, Observe) {
     56   EXPECT_CALL(zoom_observer_, OnZoomChanged(web_contents(), false)).Times(1);
     57 
     58   content::HostZoomMap* host_zoom_map =
     59       content::HostZoomMap::GetForBrowserContext(
     60           web_contents()->GetBrowserContext());
     61 
     62   host_zoom_map->SetZoomLevelForHost(std::string(), 110.0f);
     63 }
     64