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 #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" |
11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
12 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
13 #include "components/autofill/browser/autofill_external_delegate.h" | 13 #include "components/autofill/browser/autofill_external_delegate.h" |
14 #include "components/autofill/browser/autofill_manager.h" | 14 #include "components/autofill/browser/autofill_manager.h" |
15 #include "components/autofill/browser/test_autofill_external_delegate.h" | 15 #include "components/autofill/browser/test_autofill_external_delegate.h" |
16 #include "components/autofill/browser/test_autofill_manager_delegate.h" | 16 #include "components/autofill/browser/test_autofill_manager_delegate.h" |
| 17 #include "components/autofill/content/browser/autofill_driver_impl.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
20 #include "ui/gfx/display.h" | 21 #include "ui/gfx/display.h" |
21 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
22 | 23 |
23 using ::testing::_; | 24 using ::testing::_; |
24 using ::testing::AtLeast; | 25 using ::testing::AtLeast; |
25 using ::testing::NiceMock; | 26 using ::testing::NiceMock; |
26 using base::WeakPtr; | 27 using base::WeakPtr; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 class AutofillPopupControllerUnitTest : public ChromeRenderViewHostTestHarness { | 150 class AutofillPopupControllerUnitTest : public ChromeRenderViewHostTestHarness { |
150 public: | 151 public: |
151 AutofillPopupControllerUnitTest() | 152 AutofillPopupControllerUnitTest() |
152 : manager_delegate_(new MockAutofillManagerDelegate()), | 153 : manager_delegate_(new MockAutofillManagerDelegate()), |
153 autofill_popup_controller_(NULL) {} | 154 autofill_popup_controller_(NULL) {} |
154 virtual ~AutofillPopupControllerUnitTest() {} | 155 virtual ~AutofillPopupControllerUnitTest() {} |
155 | 156 |
156 virtual void SetUp() OVERRIDE { | 157 virtual void SetUp() OVERRIDE { |
157 ChromeRenderViewHostTestHarness::SetUp(); | 158 ChromeRenderViewHostTestHarness::SetUp(); |
158 | 159 |
159 AutofillManager::CreateForWebContentsAndDelegate( | 160 AutofillDriverImpl::CreateForWebContentsAndDelegate( |
160 web_contents(), | 161 web_contents(), |
161 manager_delegate_.get(), | 162 manager_delegate_.get(), |
162 "en-US", | 163 "en-US", |
163 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER); | 164 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER, |
| 165 false); |
| 166 AutofillDriverImpl* driver = |
| 167 AutofillDriverImpl::FromWebContents(web_contents()); |
164 external_delegate_.reset( | 168 external_delegate_.reset( |
165 new NiceMock<MockAutofillExternalDelegate>( | 169 new NiceMock<MockAutofillExternalDelegate>( |
166 web_contents(), AutofillManager::FromWebContents(web_contents()))); | 170 web_contents(), |
| 171 driver->autofill_manager())); |
167 | 172 |
168 autofill_popup_controller_ = | 173 autofill_popup_controller_ = |
169 new testing::NiceMock<TestAutofillPopupController>( | 174 new testing::NiceMock<TestAutofillPopupController>( |
170 external_delegate_->GetWeakPtr(), gfx::Rect()); | 175 external_delegate_->GetWeakPtr(), gfx::Rect()); |
171 } | 176 } |
172 | 177 |
173 virtual void TearDown() OVERRIDE { | 178 virtual void TearDown() OVERRIDE { |
174 // This will make sure the controller and the view (if any) are both | 179 // This will make sure the controller and the view (if any) are both |
175 // cleaned up. | 180 // cleaned up. |
176 if (autofill_popup_controller_) | 181 if (autofill_popup_controller_) |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 EXPECT_EQ(base_size, autofill_popup_controller_->RowWidthWithoutText(0)); | 358 EXPECT_EQ(base_size, autofill_popup_controller_->RowWidthWithoutText(0)); |
354 EXPECT_EQ(base_size + subtext_increase, | 359 EXPECT_EQ(base_size + subtext_increase, |
355 autofill_popup_controller_->RowWidthWithoutText(1)); | 360 autofill_popup_controller_->RowWidthWithoutText(1)); |
356 EXPECT_EQ(base_size + icon_increase, | 361 EXPECT_EQ(base_size + icon_increase, |
357 autofill_popup_controller_->RowWidthWithoutText(2)); | 362 autofill_popup_controller_->RowWidthWithoutText(2)); |
358 EXPECT_EQ(base_size + subtext_increase + icon_increase, | 363 EXPECT_EQ(base_size + subtext_increase + icon_increase, |
359 autofill_popup_controller_->RowWidthWithoutText(3)); | 364 autofill_popup_controller_->RowWidthWithoutText(3)); |
360 } | 365 } |
361 | 366 |
362 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { | 367 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { |
| 368 AutofillDriverImpl* driver = |
| 369 AutofillDriverImpl::FromWebContents(web_contents()); |
363 MockAutofillExternalDelegate delegate( | 370 MockAutofillExternalDelegate delegate( |
364 web_contents(), AutofillManager::FromWebContents(web_contents())); | 371 web_contents(), driver->autofill_manager()); |
365 | 372 |
366 WeakPtr<AutofillPopupControllerImpl> controller = | 373 WeakPtr<AutofillPopupControllerImpl> controller = |
367 AutofillPopupControllerImpl::GetOrCreate( | 374 AutofillPopupControllerImpl::GetOrCreate( |
368 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), NULL, | 375 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), NULL, |
369 gfx::Rect(), base::i18n::UNKNOWN_DIRECTION); | 376 gfx::Rect(), base::i18n::UNKNOWN_DIRECTION); |
370 EXPECT_TRUE(controller.get()); | 377 EXPECT_TRUE(controller.get()); |
371 | 378 |
372 controller->Hide(); | 379 controller->Hide(); |
373 | 380 |
374 controller = AutofillPopupControllerImpl::GetOrCreate( | 381 controller = AutofillPopupControllerImpl::GetOrCreate( |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 | 517 |
511 // The popup would be partially off the bottom and the right side of | 518 // The popup would be partially off the bottom and the right side of |
512 // the screen. | 519 // the screen. |
513 element_bounds.push_back( | 520 element_bounds.push_back( |
514 gfx::RectF(desired_width * 1.5, desired_height * 1.5, 0, 0)); | 521 gfx::RectF(desired_width * 1.5, desired_height * 1.5, 0, 0)); |
515 expected_popup_bounds.push_back( | 522 expected_popup_bounds.push_back( |
516 gfx::Rect((desired_width + 1) / 2, (desired_height + 1) / 2, | 523 gfx::Rect((desired_width + 1) / 2, (desired_height + 1) / 2, |
517 desired_width, desired_height)); | 524 desired_width, desired_height)); |
518 | 525 |
519 for (size_t i = 0; i < element_bounds.size(); ++i) { | 526 for (size_t i = 0; i < element_bounds.size(); ++i) { |
| 527 AutofillDriverImpl* driver = |
| 528 AutofillDriverImpl::FromWebContents(web_contents()); |
520 NiceMock<MockAutofillExternalDelegate> external_delegate( | 529 NiceMock<MockAutofillExternalDelegate> external_delegate( |
521 web_contents(), AutofillManager::FromWebContents(web_contents())); | 530 web_contents(), driver->autofill_manager()); |
522 TestAutofillPopupController* autofill_popup_controller = | 531 TestAutofillPopupController* autofill_popup_controller = |
523 new TestAutofillPopupController(external_delegate.GetWeakPtr(), | 532 new TestAutofillPopupController(external_delegate.GetWeakPtr(), |
524 element_bounds[i]); | 533 element_bounds[i]); |
525 | 534 |
526 autofill_popup_controller->set_display(display); | 535 autofill_popup_controller->set_display(display); |
527 autofill_popup_controller->Show(names, names, names, autofill_ids); | 536 autofill_popup_controller->Show(names, names, names, autofill_ids); |
528 | 537 |
529 EXPECT_EQ(expected_popup_bounds[i].ToString(), | 538 EXPECT_EQ(expected_popup_bounds[i].ToString(), |
530 autofill_popup_controller->popup_bounds().ToString()) << | 539 autofill_popup_controller->popup_bounds().ToString()) << |
531 "Popup bounds failed to match for test " << i; | 540 "Popup bounds failed to match for test " << i; |
532 | 541 |
533 // Hide the controller to delete it. | 542 // Hide the controller to delete it. |
534 autofill_popup_controller->DoHide(); | 543 autofill_popup_controller->DoHide(); |
535 } | 544 } |
536 } | 545 } |
537 | 546 |
538 } // namespace autofill | 547 } // namespace autofill |
OLD | NEW |