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