Chromium Code Reviews| 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_command_controller.h" | |
| 12 #include "chrome/browser/ui/browser_commands.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; | |
| 32 using content::WebContents; | |
| 33 using content::WebContentsTester; | |
|
Alexei Svitkine (slow)
2014/07/31 15:43:33
Do you need these using decls - I thought you remo
sarka
2014/07/31 16:05:57
My bad. Removing this patch.
Thanks
| |
| 34 | |
| 21 bool operator==(const ZoomController::ZoomChangedEventData& lhs, | 35 bool operator==(const ZoomController::ZoomChangedEventData& lhs, |
| 22 const ZoomController::ZoomChangedEventData& rhs) { | 36 const ZoomController::ZoomChangedEventData& rhs) { |
| 23 return lhs.web_contents == rhs.web_contents && | 37 return lhs.web_contents == rhs.web_contents && |
| 24 lhs.old_zoom_level == rhs.old_zoom_level && | 38 lhs.old_zoom_level == rhs.old_zoom_level && |
| 25 lhs.new_zoom_level == rhs.new_zoom_level && | 39 lhs.new_zoom_level == rhs.new_zoom_level && |
| 26 lhs.zoom_mode == rhs.zoom_mode && | 40 lhs.zoom_mode == rhs.zoom_mode && |
| 27 lhs.can_show_bubble == rhs.can_show_bubble; | 41 lhs.can_show_bubble == rhs.can_show_bubble; |
| 28 } | 42 } |
| 29 | 43 |
| 30 class TestZoomObserver : public ZoomObserver { | 44 class TestZoomObserver : public ZoomObserver { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 ZoomController::ZoomChangedEventData zoom_change_data2( | 132 ZoomController::ZoomChangedEventData zoom_change_data2( |
| 119 web_contents(), | 133 web_contents(), |
| 120 old_zoom_level, | 134 old_zoom_level, |
| 121 new_zoom_level, | 135 new_zoom_level, |
| 122 ZoomController::ZOOM_MODE_ISOLATED, | 136 ZoomController::ZOOM_MODE_ISOLATED, |
| 123 false /* can_show_bubble */); | 137 false /* can_show_bubble */); |
| 124 EXPECT_CALL(zoom_observer_, OnZoomChanged(zoom_change_data2)).Times(1); | 138 EXPECT_CALL(zoom_observer_, OnZoomChanged(zoom_change_data2)).Times(1); |
| 125 | 139 |
| 126 zoom_controller_->SetZoomLevel(new_zoom_level); | 140 zoom_controller_->SetZoomLevel(new_zoom_level); |
| 127 } | 141 } |
| 142 | |
| 143 class ZoomCommandsUnitTest : public BrowserWithTestWindowTest { | |
| 144 public: | |
| 145 ZoomCommandsUnitTest() {} | |
| 146 virtual ~ZoomCommandsUnitTest() {} | |
| 147 | |
| 148 content::WebContents* CreateTestWebContents() { | |
| 149 return content::WebContentsTester::CreateTestWebContents( | |
| 150 profile(), content::SiteInstance::Create(profile())); | |
| 151 } | |
| 152 | |
| 153 private: | |
| 154 DISALLOW_COPY_AND_ASSIGN(ZoomCommandsUnitTest); | |
| 155 }; | |
| 156 | |
| 157 TEST_F(ZoomCommandsUnitTest, OnMaxZoomIn) { | |
| 158 | |
|
Alexei Svitkine (slow)
2014/07/31 15:43:33
Nit: Remove empty line.
sarka
2014/07/31 16:02:03
Done.
| |
| 159 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
| 160 | |
| 161 GURL url("http://www.google.com"); | |
| 162 content::WebContents* contents1 = CreateTestWebContents(); | |
| 163 tab_strip_model->AppendWebContents(contents1, true); | |
| 164 content::WebContentsTester::For(contents1)->NavigateAndCommit(url); | |
| 165 | |
| 166 for (int i = 0; i < 9; ++i) { | |
| 167 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN); | |
| 168 } | |
| 169 | |
| 170 // TODO(a.sarkar.arun@gmail.com): Figure out why Zoom-In menu item is not | |
| 171 // disabled after Max-zoom is reached. Force disable Zoom-In menu item | |
| 172 // from the context menu since it breaks try jobs on bots. | |
| 173 if (chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)) | |
| 174 chrome::UpdateCommandEnabled(browser(), IDC_ZOOM_PLUS, false); | |
| 175 | |
| 176 bool dummy = false; | |
| 177 EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 500.0f); | |
| 178 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
| 179 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
| 180 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
| 181 } | |
| 182 | |
| 183 TEST_F(ZoomCommandsUnitTest, OnMaxZoomOut) { | |
| 184 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
| 185 | |
| 186 GURL url("http://www.google.com"); | |
| 187 content::WebContents* contents1 = CreateTestWebContents(); | |
| 188 tab_strip_model->AppendWebContents(contents1, true); | |
| 189 content::WebContentsTester::For(contents1)->NavigateAndCommit(url); | |
| 190 for (int i = 0; i < 7; ++i) { | |
| 191 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_OUT); | |
| 192 } | |
| 193 | |
| 194 bool dummy = false; | |
| 195 | |
| 196 EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 25.0f); | |
| 197 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
| 198 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
| 199 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
| 200 } | |
| 201 | |
| 202 TEST_F(ZoomCommandsUnitTest, OnZoomReset) { | |
| 203 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
| 204 | |
| 205 GURL url("http://www.google.com"); | |
| 206 content::WebContents* contents1 = CreateTestWebContents(); | |
| 207 tab_strip_model->AppendWebContents(contents1, true); | |
| 208 content::WebContentsTester::For(contents1)->NavigateAndCommit(url); | |
| 209 | |
| 210 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_RESET); | |
| 211 | |
| 212 bool dummy = false; | |
| 213 | |
| 214 EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 100.0f); | |
| 215 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
| 216 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
| 217 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
| 218 } | |
| 219 | |
| 220 TEST_F(ZoomCommandsUnitTest, OnZoomLevelChanged) { | |
| 221 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
| 222 | |
| 223 GURL url("http://www.google.com"); | |
| 224 content::WebContents* contents1 = CreateTestWebContents(); | |
| 225 tab_strip_model->AppendWebContents(contents1, true); | |
| 226 content::WebContentsTester::For(contents1)->NavigateAndCommit(url); | |
| 227 | |
| 228 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN); | |
| 229 | |
| 230 bool dummy = false; | |
| 231 | |
| 232 EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 110.0f); | |
| 233 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
| 234 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
| 235 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
| 236 } | |
| 237 | |
| 238 TEST_F(ZoomCommandsUnitTest, OnZoomChangedForActiveTab) { | |
| 239 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
| 240 | |
| 241 GURL url("http://www.google.com"); | |
| 242 GURL url1("http://code.google.com"); | |
| 243 | |
| 244 // Add First tab | |
| 245 content::WebContents* contents1 = CreateTestWebContents(); | |
| 246 tab_strip_model->AppendWebContents(contents1, true); | |
| 247 content::WebContentsTester::For(contents1)->NavigateAndCommit(url); | |
| 248 | |
| 249 for (int i = 0; i < 7; ++i) { | |
|
Alexei Svitkine (slow)
2014/07/31 15:41:56
Please add a comment explaining the purpose of thi
sarka
2014/07/31 16:02:03
Done.
| |
| 250 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_OUT); | |
| 251 } | |
| 252 | |
| 253 bool dummy = false; | |
| 254 | |
| 255 EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 100.0f); | |
| 256 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
| 257 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
| 258 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
| 259 | |
| 260 // Add Second tab | |
| 261 content::WebContents* contents2 = CreateTestWebContents(); | |
| 262 tab_strip_model->AppendWebContents(contents2, true); | |
| 263 content::WebContentsTester::For(contents2)->NavigateAndCommit(url1); | |
| 264 | |
| 265 tab_strip_model->ActivateTabAt(1, true); | |
| 266 EXPECT_TRUE(tab_strip_model->IsTabSelected(1)); | |
| 267 chrome_page_zoom::Zoom(contents2, content::PAGE_ZOOM_OUT); | |
| 268 | |
| 269 EXPECT_EQ(contents2->GetZoomPercent(&dummy, &dummy), 90.0f); | |
| 270 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
| 271 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
| 272 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
| 273 } | |
| 274 | |
| OLD | NEW |