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

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

Issue 15769018: [Autofill] Determine Popup RTLness from page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix android compile Created 7 years, 6 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
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/memory/weak_ptr.h" 6 #include "base/memory/weak_ptr.h"
7 #include "base/prefs/testing_pref_service.h" 7 #include "base/prefs/testing_pref_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" 9 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
10 #include "chrome/browser/ui/autofill/autofill_popup_view.h" 10 #include "chrome/browser/ui/autofill/autofill_popup_view.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 TestingPrefServiceSimple prefs_; 57 TestingPrefServiceSimple prefs_;
58 58
59 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); 59 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate);
60 }; 60 };
61 61
62 class TestAutofillPopupController : public AutofillPopupControllerImpl { 62 class TestAutofillPopupController : public AutofillPopupControllerImpl {
63 public: 63 public:
64 explicit TestAutofillPopupController( 64 explicit TestAutofillPopupController(
65 base::WeakPtr<AutofillExternalDelegate> external_delegate, 65 base::WeakPtr<AutofillExternalDelegate> external_delegate,
66 const gfx::RectF& element_bounds) 66 const gfx::RectF& element_bounds)
67 : AutofillPopupControllerImpl(external_delegate, NULL, element_bounds) {} 67 : AutofillPopupControllerImpl(
68 external_delegate, NULL, element_bounds,
69 base::i18n::UNKNOWN_DIRECTION) {}
68 virtual ~TestAutofillPopupController() {} 70 virtual ~TestAutofillPopupController() {}
69 71
70 void set_display(const gfx::Display display) { 72 void set_display(const gfx::Display display) {
71 display_ = display; 73 display_ = display;
72 } 74 }
73 virtual gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const 75 virtual gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const
74 OVERRIDE { 76 OVERRIDE {
75 return display_; 77 return display_;
76 } 78 }
77 79
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 autofill_popup_controller_->RowWidthWithoutText(3)); 359 autofill_popup_controller_->RowWidthWithoutText(3));
358 } 360 }
359 361
360 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { 362 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) {
361 MockAutofillExternalDelegate delegate( 363 MockAutofillExternalDelegate delegate(
362 web_contents(), AutofillManager::FromWebContents(web_contents())); 364 web_contents(), AutofillManager::FromWebContents(web_contents()));
363 365
364 WeakPtr<AutofillPopupControllerImpl> controller = 366 WeakPtr<AutofillPopupControllerImpl> controller =
365 AutofillPopupControllerImpl::GetOrCreate( 367 AutofillPopupControllerImpl::GetOrCreate(
366 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), NULL, 368 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), NULL,
367 gfx::Rect()); 369 gfx::Rect(), base::i18n::UNKNOWN_DIRECTION);
368 EXPECT_TRUE(controller.get()); 370 EXPECT_TRUE(controller.get());
369 371
370 controller->Hide(); 372 controller->Hide();
371 373
372 controller = AutofillPopupControllerImpl::GetOrCreate( 374 controller = AutofillPopupControllerImpl::GetOrCreate(
373 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), NULL, 375 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), NULL,
374 gfx::Rect()); 376 gfx::Rect(), base::i18n::UNKNOWN_DIRECTION);
375 EXPECT_TRUE(controller.get()); 377 EXPECT_TRUE(controller.get());
376 378
377 WeakPtr<AutofillPopupControllerImpl> controller2 = 379 WeakPtr<AutofillPopupControllerImpl> controller2 =
378 AutofillPopupControllerImpl::GetOrCreate(controller, 380 AutofillPopupControllerImpl::GetOrCreate(controller,
379 delegate.GetWeakPtr(), 381 delegate.GetWeakPtr(),
380 NULL, 382 NULL,
381 gfx::Rect()); 383 gfx::Rect(),
384 base::i18n::UNKNOWN_DIRECTION);
382 EXPECT_EQ(controller.get(), controller2.get()); 385 EXPECT_EQ(controller.get(), controller2.get());
383 controller->Hide(); 386 controller->Hide();
384 387
385 testing::NiceMock<TestAutofillPopupController>* test_controller = 388 testing::NiceMock<TestAutofillPopupController>* test_controller =
386 new testing::NiceMock<TestAutofillPopupController>(delegate.GetWeakPtr(), 389 new testing::NiceMock<TestAutofillPopupController>(delegate.GetWeakPtr(),
387 gfx::Rect()); 390 gfx::Rect());
388 EXPECT_CALL(*test_controller, Hide()); 391 EXPECT_CALL(*test_controller, Hide());
389 392
390 gfx::RectF bounds(0.f, 0.f, 1.f, 2.f); 393 gfx::RectF bounds(0.f, 0.f, 1.f, 2.f);
391 base::WeakPtr<AutofillPopupControllerImpl> controller3 = 394 base::WeakPtr<AutofillPopupControllerImpl> controller3 =
392 AutofillPopupControllerImpl::GetOrCreate( 395 AutofillPopupControllerImpl::GetOrCreate(
393 test_controller->GetWeakPtr(), 396 test_controller->GetWeakPtr(),
394 delegate.GetWeakPtr(), 397 delegate.GetWeakPtr(),
395 NULL, 398 NULL,
396 bounds); 399 bounds,
400 base::i18n::UNKNOWN_DIRECTION);
397 EXPECT_EQ( 401 EXPECT_EQ(
398 bounds, 402 bounds,
399 static_cast<AutofillPopupController*>(controller3.get())-> 403 static_cast<AutofillPopupController*>(controller3.get())->
400 element_bounds()); 404 element_bounds());
401 controller3->Hide(); 405 controller3->Hide();
402 406
403 // Hide the test_controller to delete it. 407 // Hide the test_controller to delete it.
404 test_controller->DoHide(); 408 test_controller->DoHide();
405 } 409 }
406 410
407 TEST_F(AutofillPopupControllerUnitTest, ProperlyResetController) { 411 TEST_F(AutofillPopupControllerUnitTest, ProperlyResetController) {
408 std::vector<string16> names(2); 412 std::vector<string16> names(2);
409 std::vector<int> ids(2); 413 std::vector<int> ids(2);
410 popup_controller()->SetValues(names, names, names, ids); 414 popup_controller()->SetValues(names, names, names, ids);
411 popup_controller()->SetSelectedLine(0); 415 popup_controller()->SetSelectedLine(0);
412 416
413 // Now show a new popup with the same controller, but with fewer items. 417 // Now show a new popup with the same controller, but with fewer items.
414 WeakPtr<AutofillPopupControllerImpl> controller = 418 WeakPtr<AutofillPopupControllerImpl> controller =
415 AutofillPopupControllerImpl::GetOrCreate( 419 AutofillPopupControllerImpl::GetOrCreate(
416 popup_controller()->GetWeakPtr(), 420 popup_controller()->GetWeakPtr(),
417 delegate()->GetWeakPtr(), 421 delegate()->GetWeakPtr(),
418 NULL, 422 NULL,
419 gfx::Rect()); 423 gfx::Rect(),
424 base::i18n::UNKNOWN_DIRECTION);
420 EXPECT_NE(0, controller->selected_line()); 425 EXPECT_NE(0, controller->selected_line());
421 EXPECT_TRUE(controller->names().empty()); 426 EXPECT_TRUE(controller->names().empty());
422 } 427 }
423 428
424 #if !defined(OS_ANDROID) 429 #if !defined(OS_ANDROID)
425 TEST_F(AutofillPopupControllerUnitTest, ElideText) { 430 TEST_F(AutofillPopupControllerUnitTest, ElideText) {
426 std::vector<string16> names; 431 std::vector<string16> names;
427 names.push_back(ASCIIToUTF16("Text that will need to be trimmed")); 432 names.push_back(ASCIIToUTF16("Text that will need to be trimmed"));
428 names.push_back(ASCIIToUTF16("Untrimmed")); 433 names.push_back(ASCIIToUTF16("Untrimmed"));
429 434
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 EXPECT_EQ(expected_popup_bounds[i].ToString(), 529 EXPECT_EQ(expected_popup_bounds[i].ToString(),
525 autofill_popup_controller->popup_bounds().ToString()) << 530 autofill_popup_controller->popup_bounds().ToString()) <<
526 "Popup bounds failed to match for test " << i; 531 "Popup bounds failed to match for test " << i;
527 532
528 // Hide the controller to delete it. 533 // Hide the controller to delete it.
529 autofill_popup_controller->DoHide(); 534 autofill_popup_controller->DoHide();
530 } 535 }
531 } 536 }
532 537
533 } // namespace autofill 538 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698