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 | |
5 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
6 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/app/chrome_command_ids.h" | |
9 #include "chrome/browser/chrome_page_zoom.h" | |
7 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_commands.h" | |
12 #include "chrome/browser/ui/browser_command_controller.h" | |
8 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
9 #include "chrome/browser/ui/zoom/zoom_controller.h" | 15 #include "chrome/browser/ui/zoom/zoom_controller.h" |
10 #include "chrome/browser/ui/zoom/zoom_observer.h" | 16 #include "chrome/browser/ui/zoom/zoom_observer.h" |
11 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "chrome/test/base/browser_with_test_window_test.h" | |
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
13 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
14 #include "content/public/browser/host_zoom_map.h" | 21 #include "content/public/browser/host_zoom_map.h" |
15 #include "content/public/browser/navigation_details.h" | 22 #include "content/public/browser/navigation_details.h" |
23 #include "content/public/browser/site_instance.h" | |
24 #include "content/public/browser/web_contents.h" | |
16 #include "content/public/common/frame_navigate_params.h" | 25 #include "content/public/common/frame_navigate_params.h" |
17 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
27 #include "content/public/test/web_contents_tester.h" | |
18 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
20 | 30 |
31 using content::SiteInstance; | |
Ben Goodger (Google)
2014/06/16 17:37:34
nit: prevailing style in chromium is to avoid doin
sarka
2014/06/16 20:25:57
Hi Ben, Did you mean to comment about a particular
Alexei Svitkine (slow)
2014/06/17 19:44:01
I think Ben is suggesting to remove the "using" st
| |
32 using content::WebContents; | |
33 using content::WebContentsTester; | |
34 | |
21 class TestZoomObserver : public ZoomObserver { | 35 class TestZoomObserver : public ZoomObserver { |
22 public: | 36 public: |
23 MOCK_METHOD2(OnZoomChanged, void(content::WebContents*, bool)); | 37 MOCK_METHOD2(OnZoomChanged, void(content::WebContents*, bool)); |
24 }; | 38 }; |
25 | 39 |
26 class ZoomControllerTest : public ChromeRenderViewHostTestHarness { | 40 class ZoomControllerTest : public ChromeRenderViewHostTestHarness { |
27 public: | 41 public: |
28 virtual void SetUp() OVERRIDE { | 42 virtual void SetUp() OVERRIDE { |
29 ChromeRenderViewHostTestHarness::SetUp(); | 43 ChromeRenderViewHostTestHarness::SetUp(); |
30 zoom_controller_.reset(new ZoomController(web_contents())); | 44 zoom_controller_.reset(new ZoomController(web_contents())); |
(...skipping 23 matching lines...) Expand all Loading... | |
54 | 68 |
55 TEST_F(ZoomControllerTest, Observe) { | 69 TEST_F(ZoomControllerTest, Observe) { |
56 EXPECT_CALL(zoom_observer_, OnZoomChanged(web_contents(), false)).Times(1); | 70 EXPECT_CALL(zoom_observer_, OnZoomChanged(web_contents(), false)).Times(1); |
57 | 71 |
58 content::HostZoomMap* host_zoom_map = | 72 content::HostZoomMap* host_zoom_map = |
59 content::HostZoomMap::GetForBrowserContext( | 73 content::HostZoomMap::GetForBrowserContext( |
60 web_contents()->GetBrowserContext()); | 74 web_contents()->GetBrowserContext()); |
61 | 75 |
62 host_zoom_map->SetZoomLevelForHost(std::string(), 110.0f); | 76 host_zoom_map->SetZoomLevelForHost(std::string(), 110.0f); |
63 } | 77 } |
78 | |
79 class ZoomCommandsUnitTest : public BrowserWithTestWindowTest { | |
80 public: | |
81 ZoomCommandsUnitTest() {} | |
82 virtual ~ZoomCommandsUnitTest() {} | |
83 | |
84 WebContents* CreateTestWebContents() { | |
85 return WebContentsTester::CreateTestWebContents( | |
86 profile(), SiteInstance::Create(profile())); | |
87 } | |
88 | |
89 private: | |
90 DISALLOW_COPY_AND_ASSIGN(ZoomCommandsUnitTest); | |
91 }; | |
92 | |
93 TEST_F(ZoomCommandsUnitTest, OnMaxZoomIn) { | |
94 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
95 | |
96 GURL url("http://www.google.com"); | |
97 WebContents* contents1 = CreateTestWebContents(); | |
98 tab_strip_model->AppendWebContents(contents1, true); | |
99 WebContentsTester::For(contents1)->NavigateAndCommit(url); | |
100 | |
101 for (int i = 0; i < 9; ++i) { | |
102 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN); | |
103 } | |
104 | |
105 bool dummy = false; | |
106 | |
107 EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 500.0f); | |
108 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
109 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
110 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
111 } | |
112 | |
113 TEST_F(ZoomCommandsUnitTest, OnMaxZoomOut) { | |
114 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
115 | |
116 GURL url("http://www.google.com"); | |
117 WebContents* contents1 = CreateTestWebContents(); | |
118 tab_strip_model->AppendWebContents(contents1, true); | |
119 WebContentsTester::For(contents1)->NavigateAndCommit(url); | |
120 | |
121 for (int i = 0; i < 7; ++i) { | |
122 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_OUT); | |
123 } | |
124 | |
125 bool dummy = false; | |
126 | |
127 EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 25.0f); | |
128 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
129 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
130 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
131 } | |
132 | |
133 TEST_F(ZoomCommandsUnitTest, OnZoomReset) { | |
134 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
135 | |
136 GURL url("http://www.google.com"); | |
137 WebContents* contents1 = CreateTestWebContents(); | |
138 tab_strip_model->AppendWebContents(contents1, true); | |
139 WebContentsTester::For(contents1)->NavigateAndCommit(url); | |
140 | |
141 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_RESET); | |
142 | |
143 bool dummy = false; | |
144 | |
145 EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 100.0f); | |
146 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
147 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
148 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
149 } | |
150 | |
151 TEST_F(ZoomCommandsUnitTest, OnZoomLevelChanged) { | |
152 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
153 | |
154 GURL url("http://www.google.com"); | |
155 WebContents* contents1 = CreateTestWebContents(); | |
156 tab_strip_model->AppendWebContents(contents1, true); | |
157 WebContentsTester::For(contents1)->NavigateAndCommit(url); | |
158 | |
159 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN); | |
160 | |
161 bool dummy = false; | |
162 | |
163 EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 110.0f); | |
164 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
165 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
166 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
167 } | |
168 | |
169 TEST_F(ZoomCommandsUnitTest, OnZoomChangedForActiveTab) { | |
170 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
171 | |
172 GURL url("http://www.google.com"); | |
173 GURL url1("http://code.google.com"); | |
174 | |
175 // Add First tab | |
176 WebContents* contents1 = CreateTestWebContents(); | |
177 tab_strip_model->AppendWebContents(contents1, true); | |
178 WebContentsTester::For(contents1)->NavigateAndCommit(url); | |
179 | |
180 bool dummy = false; | |
181 | |
182 EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 100.0f); | |
183 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
184 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
185 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
186 | |
187 // Add Second tab | |
188 WebContents* contents2 = CreateTestWebContents(); | |
189 tab_strip_model->AppendWebContents(contents2, true); | |
190 WebContentsTester::For(contents2)->NavigateAndCommit(url1); | |
191 | |
192 tab_strip_model->ActivateTabAt(1, true); | |
193 EXPECT_TRUE(tab_strip_model->IsTabSelected(1)); | |
194 chrome_page_zoom::Zoom(contents2, content::PAGE_ZOOM_OUT); | |
195 | |
196 EXPECT_EQ(contents2->GetZoomPercent(&dummy, &dummy), 90.0f); | |
197 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
198 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
199 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
200 } | |
OLD | NEW |