Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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.h" | |
| 6 #include "chrome/browser/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/browser/notification_details.h" | |
| 18 #include "content/public/browser/notification_source.h" | |
| 19 #include "content/public/browser/notification_types.h" | |
| 20 #include "content/public/common/frame_navigate_params.h" | |
| 21 #include "content/public/test/test_browser_thread.h" | |
| 22 #include "content/public/test/test_utils.h" | |
| 23 #include "testing/gmock/include/gmock/gmock.h" | |
| 24 #include "testing/gtest/include/gtest/gtest.h" | |
| 25 | |
| 26 class TestZoomObserver : public ZoomObserver { | |
| 27 public: | |
| 28 MOCK_METHOD2(OnZoomChanged, void(content::WebContents*, bool)); | |
| 29 }; | |
| 30 | |
| 31 class ZoomControllerTest : public ChromeRenderViewHostTestHarness { | |
| 32 public: | |
| 33 ZoomControllerTest() | |
| 34 : ui_thread_(content::BrowserThread::UI, MessageLoop::current()) {} | |
| 35 | |
| 36 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.
| |
| 37 ChromeRenderViewHostTestHarness::SetUp(); | |
| 38 zoom_controller_.reset(new ZoomController(web_contents())); | |
| 39 zoom_controller_->set_observer(&zoom_observer_); | |
| 40 } | |
| 41 | |
| 42 void TearDown() OVERRIDE { | |
|
Evan Stade
2012/11/17 01:33:06
ditto
Dan Beam
2012/11/17 01:53:42
Done.
| |
| 43 zoom_controller_.reset(); | |
| 44 ChromeRenderViewHostTestHarness::TearDown(); | |
| 45 } | |
| 46 | |
| 47 protected: | |
| 48 scoped_ptr<ZoomController> zoom_controller_; | |
| 49 TestZoomObserver zoom_observer_; | |
| 50 | |
| 51 private: | |
| 52 content::TestBrowserThread ui_thread_; | |
| 53 DISALLOW_COPY_AND_ASSIGN(ZoomControllerTest); | |
| 54 }; | |
| 55 | |
| 56 TEST_F(ZoomControllerTest, DidNavigateMainFrame) { | |
| 57 EXPECT_CALL(zoom_observer_, OnZoomChanged(web_contents(), false)).Times(1); | |
| 58 zoom_controller_->DidNavigateMainFrame(content::LoadCommittedDetails(), | |
| 59 content::FrameNavigateParams()); | |
| 60 } | |
| 61 | |
| 62 TEST_F(ZoomControllerTest, OnPreferenceChanged) { | |
| 63 EXPECT_CALL(zoom_observer_, OnZoomChanged(web_contents(), false)).Times(1); | |
| 64 profile()->GetPrefs()->SetDouble(prefs::kDefaultZoomLevel, 110.0f); | |
| 65 } | |
| 66 | |
| 67 TEST_F(ZoomControllerTest, Observe) { | |
| 68 EXPECT_CALL(zoom_observer_, OnZoomChanged(web_contents(), false)).Times(1); | |
| 69 | |
| 70 content::HostZoomMap* host_zoom_map = | |
| 71 content::HostZoomMap::GetForBrowserContext( | |
| 72 web_contents()->GetBrowserContext()); | |
| 73 | |
| 74 content::WindowedNotificationObserver notification_observer( | |
| 75 content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | |
| 76 content::NotificationService::AllSources()); | |
| 77 | |
| 78 host_zoom_map->SetZoomLevel(std::string(), 110.0f); | |
| 79 | |
| 80 notification_observer.Wait(); | |
| 81 } | |
| OLD | NEW |