Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc

Issue 12188020: Adding the page and DPI scale adjustment for Autofill Popups. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed Ted's nits Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/autofill/test_autofill_external_delegate.h" 7 #include "chrome/browser/autofill/test_autofill_external_delegate.h"
8 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" 8 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 18 matching lines...) Expand all
29 {} 29 {}
30 virtual void ClearPreviewedForm() OVERRIDE {} 30 virtual void ClearPreviewedForm() OVERRIDE {}
31 31
32 MOCK_METHOD0(ControllerDestroyed, void()); 32 MOCK_METHOD0(ControllerDestroyed, void());
33 }; 33 };
34 34
35 class TestAutofillPopupController : public AutofillPopupControllerImpl { 35 class TestAutofillPopupController : public AutofillPopupControllerImpl {
36 public: 36 public:
37 explicit TestAutofillPopupController( 37 explicit TestAutofillPopupController(
38 AutofillExternalDelegate* external_delegate, 38 AutofillExternalDelegate* external_delegate,
39 const gfx::Rect& element_bounds) 39 const gfx::RectF& element_bounds)
40 : AutofillPopupControllerImpl(external_delegate, NULL, element_bounds) {} 40 : AutofillPopupControllerImpl(external_delegate, NULL, element_bounds) {}
41 virtual ~TestAutofillPopupController() {} 41 virtual ~TestAutofillPopupController() {}
42 42
43 void set_display(const gfx::Display display) { 43 void set_display(const gfx::Display display) {
44 display_ = display; 44 display_ = display;
45 } 45 }
46 virtual gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const 46 virtual gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const
47 OVERRIDE { 47 OVERRIDE {
48 return display_; 48 return display_;
49 } 49 }
(...skipping 19 matching lines...) Expand all
69 } 69 }
70 bool RemoveSelectedLine() { 70 bool RemoveSelectedLine() {
71 return AutofillPopupControllerImpl::RemoveSelectedLine(); 71 return AutofillPopupControllerImpl::RemoveSelectedLine();
72 } 72 }
73 void DoHide() { 73 void DoHide() {
74 AutofillPopupControllerImpl::Hide(); 74 AutofillPopupControllerImpl::Hide();
75 } 75 }
76 const gfx::Rect& popup_bounds() const { 76 const gfx::Rect& popup_bounds() const {
77 return AutofillPopupControllerImpl::popup_bounds(); 77 return AutofillPopupControllerImpl::popup_bounds();
78 } 78 }
79 const gfx::Rect& element_bounds() const { 79 const gfx::RectF& element_bounds() const {
80 return AutofillPopupControllerImpl::element_bounds(); 80 return AutofillPopupControllerImpl::element_bounds();
81 } 81 }
82 #if !defined(OS_ANDROID) 82 #if !defined(OS_ANDROID)
83 const gfx::Font& name_font() const { 83 const gfx::Font& name_font() const {
84 return AutofillPopupControllerImpl::name_font(); 84 return AutofillPopupControllerImpl::name_font();
85 } 85 }
86 const gfx::Font& subtext_font() const { 86 const gfx::Font& subtext_font() const {
87 return AutofillPopupControllerImpl::subtext_font(); 87 return AutofillPopupControllerImpl::subtext_font();
88 } 88 }
89 #endif 89 #endif
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 NULL, 273 NULL,
274 gfx::Rect()); 274 gfx::Rect());
275 EXPECT_EQ(controller, controller2); 275 EXPECT_EQ(controller, controller2);
276 controller->Hide(); 276 controller->Hide();
277 277
278 testing::NiceMock<TestAutofillPopupController>* test_controller = 278 testing::NiceMock<TestAutofillPopupController>* test_controller =
279 new testing::NiceMock<TestAutofillPopupController>(&delegate, 279 new testing::NiceMock<TestAutofillPopupController>(&delegate,
280 gfx::Rect()); 280 gfx::Rect());
281 EXPECT_CALL(*test_controller, Hide()); 281 EXPECT_CALL(*test_controller, Hide());
282 282
283 gfx::Rect bounds(0, 0, 1, 2); 283 gfx::RectF bounds(0.f, 0.f, 1.f, 2.f);
284 AutofillPopupControllerImpl* controller3 = 284 AutofillPopupControllerImpl* controller3 =
285 AutofillPopupControllerImpl::GetOrCreate( 285 AutofillPopupControllerImpl::GetOrCreate(
286 test_controller, 286 test_controller,
287 &delegate, 287 &delegate,
288 NULL, 288 NULL,
289 bounds); 289 bounds);
290 EXPECT_EQ( 290 EXPECT_EQ(
291 bounds, 291 bounds,
292 static_cast<AutofillPopupController*>(controller3)->element_bounds()); 292 static_cast<AutofillPopupController*>(controller3)->element_bounds());
293 controller3->Hide(); 293 controller3->Hide();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 autofill_popup_controller_->Show(names, names, names, autofill_ids); 337 autofill_popup_controller_->Show(names, names, names, autofill_ids);
338 int desired_width = autofill_popup_controller_->GetDesiredPopupWidth(); 338 int desired_width = autofill_popup_controller_->GetDesiredPopupWidth();
339 int desired_height = autofill_popup_controller_->GetDesiredPopupHeight(); 339 int desired_height = autofill_popup_controller_->GetDesiredPopupHeight();
340 340
341 // Setup the visible screen space. 341 // Setup the visible screen space.
342 gfx::Display display(0, gfx::Rect(0, 0, 342 gfx::Display display(0, gfx::Rect(0, 0,
343 desired_width * 2, desired_height * 2)); 343 desired_width * 2, desired_height * 2));
344 344
345 // Store the possible element bounds and the popup bounds they should result 345 // Store the possible element bounds and the popup bounds they should result
346 // in. 346 // in.
347 std::vector<gfx::Rect> element_bounds; 347 std::vector<gfx::RectF> element_bounds;
348 std::vector<gfx::Rect> expected_popup_bounds; 348 std::vector<gfx::Rect> expected_popup_bounds;
349 349
350 // The popup grows down and to the right. 350 // The popup grows down and to the right.
351 element_bounds.push_back(gfx::Rect(0, 0, 0, 0)); 351 element_bounds.push_back(gfx::RectF(0, 0, 0, 0));
352 expected_popup_bounds.push_back( 352 expected_popup_bounds.push_back(
353 gfx::Rect(0, 0, desired_width, desired_height)); 353 gfx::Rect(0, 0, desired_width, desired_height));
354 354
355 // The popup grows down and to the left. 355 // The popup grows down and to the left.
356 element_bounds.push_back(gfx::Rect(2 * desired_width, 0, 0, 0)); 356 element_bounds.push_back(gfx::RectF(2 * desired_width, 0, 0, 0));
357 expected_popup_bounds.push_back( 357 expected_popup_bounds.push_back(
358 gfx::Rect(desired_width, 0, desired_width, desired_height)); 358 gfx::Rect(desired_width, 0, desired_width, desired_height));
359 359
360 // The popup grows up and to the right. 360 // The popup grows up and to the right.
361 element_bounds.push_back(gfx::Rect(0, 2 * desired_height, 0, 0)); 361 element_bounds.push_back(gfx::RectF(0, 2 * desired_height, 0, 0));
362 expected_popup_bounds.push_back( 362 expected_popup_bounds.push_back(
363 gfx::Rect(0, desired_height, desired_width, desired_height)); 363 gfx::Rect(0, desired_height, desired_width, desired_height));
364 364
365 // The popup grows up and to the left. 365 // The popup grows up and to the left.
366 element_bounds.push_back( 366 element_bounds.push_back(
367 gfx::Rect(2 * desired_width, 2 * desired_height, 0, 0)); 367 gfx::RectF(2 * desired_width, 2 * desired_height, 0, 0));
368 expected_popup_bounds.push_back( 368 expected_popup_bounds.push_back(
369 gfx::Rect(desired_width, desired_height, desired_width, desired_height)); 369 gfx::Rect(desired_width, desired_height, desired_width, desired_height));
370 370
371 // The popup would be partial off the top and left side of the screen. 371 // The popup would be partial off the top and left side of the screen.
372 element_bounds.push_back( 372 element_bounds.push_back(
373 gfx::Rect(-desired_width / 2, -desired_height / 2, 0, 0)); 373 gfx::RectF(-desired_width / 2, -desired_height / 2, 0, 0));
374 expected_popup_bounds.push_back( 374 expected_popup_bounds.push_back(
375 gfx::Rect(0, 0, desired_width, desired_height)); 375 gfx::Rect(0, 0, desired_width, desired_height));
376 376
377 // The popup would be partially off the bottom and the right side of 377 // The popup would be partially off the bottom and the right side of
378 // the screen. 378 // the screen.
379 element_bounds.push_back( 379 element_bounds.push_back(
380 gfx::Rect(desired_width * 1.5, desired_height * 1.5, 0, 0)); 380 gfx::RectF(desired_width * 1.5, desired_height * 1.5, 0, 0));
381 expected_popup_bounds.push_back(gfx::Rect( 381 expected_popup_bounds.push_back(gfx::Rect(
382 desired_width / 2, desired_height /2, desired_width, desired_height)); 382 desired_width / 2, desired_height /2, desired_width, desired_height));
383 383
384 for (size_t i = 0; i < element_bounds.size(); ++i) { 384 for (size_t i = 0; i < element_bounds.size(); ++i) {
385 TestAutofillPopupController autofill_popup_controller(&external_delegate_, 385 TestAutofillPopupController autofill_popup_controller(&external_delegate_,
386 element_bounds[i]); 386 element_bounds[i]);
387 autofill_popup_controller.set_display(display); 387 autofill_popup_controller.set_display(display);
388 autofill_popup_controller.Show(names, names, names, autofill_ids); 388 autofill_popup_controller.Show(names, names, names, autofill_ids);
389 389
390 EXPECT_EQ(expected_popup_bounds[i].ToString(), 390 EXPECT_EQ(expected_popup_bounds[i].ToString(),
391 autofill_popup_controller.popup_bounds().ToString()) << 391 autofill_popup_controller.popup_bounds().ToString()) <<
392 "Popup bounds failed to match for test " << i; 392 "Popup bounds failed to match for test " << i;
393 } 393 }
394 } 394 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_popup_controller_impl.cc ('k') | chrome/common/autofill_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698