| 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/pref_service.h" | 7 #include "base/prefs/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/browser/ui/autofill/popup_constants.h" | 11 #include "chrome/browser/ui/autofill/popup_constants.h" |
| 12 #include "chrome/browser/ui/autofill/test_popup_controller_common.h" | 12 #include "chrome/browser/ui/autofill/test_popup_controller_common.h" |
| 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 15 #include "components/autofill/content/browser/content_autofill_driver.h" | 15 #include "components/autofill/content/browser/content_autofill_driver.h" |
| 16 #include "components/autofill/content/browser/content_autofill_driver_factory.h" |
| 16 #include "components/autofill/core/browser/autofill_external_delegate.h" | 17 #include "components/autofill/core/browser/autofill_external_delegate.h" |
| 17 #include "components/autofill/core/browser/autofill_manager.h" | 18 #include "components/autofill/core/browser/autofill_manager.h" |
| 18 #include "components/autofill/core/browser/autofill_test_utils.h" | 19 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 19 #include "components/autofill/core/browser/popup_item_ids.h" | 20 #include "components/autofill/core/browser/popup_item_ids.h" |
| 20 #include "components/autofill/core/browser/test_autofill_client.h" | 21 #include "components/autofill/core/browser/test_autofill_client.h" |
| 21 #include "components/autofill/core/browser/test_autofill_external_delegate.h" | 22 #include "components/autofill/core/browser/test_autofill_external_delegate.h" |
| 23 #include "content/public/browser/web_contents.h" |
| 22 #include "grit/components_scaled_resources.h" | 24 #include "grit/components_scaled_resources.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "ui/gfx/display.h" | 28 #include "ui/gfx/display.h" |
| 27 #include "ui/gfx/rect.h" | 29 #include "ui/gfx/rect.h" |
| 28 #include "ui/gfx/text_utils.h" | 30 #include "ui/gfx/text_utils.h" |
| 29 | 31 |
| 30 using ::testing::_; | 32 using ::testing::_; |
| 31 using ::testing::AtLeast; | 33 using ::testing::AtLeast; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 class AutofillPopupControllerUnitTest : public ChromeRenderViewHostTestHarness { | 124 class AutofillPopupControllerUnitTest : public ChromeRenderViewHostTestHarness { |
| 123 public: | 125 public: |
| 124 AutofillPopupControllerUnitTest() | 126 AutofillPopupControllerUnitTest() |
| 125 : autofill_client_(new MockAutofillClient()), | 127 : autofill_client_(new MockAutofillClient()), |
| 126 autofill_popup_controller_(NULL) {} | 128 autofill_popup_controller_(NULL) {} |
| 127 ~AutofillPopupControllerUnitTest() override {} | 129 ~AutofillPopupControllerUnitTest() override {} |
| 128 | 130 |
| 129 void SetUp() override { | 131 void SetUp() override { |
| 130 ChromeRenderViewHostTestHarness::SetUp(); | 132 ChromeRenderViewHostTestHarness::SetUp(); |
| 131 | 133 |
| 132 ContentAutofillDriver::CreateForWebContentsAndDelegate( | 134 ContentAutofillDriverFactory::CreateForWebContentsAndDelegate( |
| 133 web_contents(), | 135 web_contents(), autofill_client_.get(), "en-US", |
| 134 autofill_client_.get(), | |
| 135 "en-US", | |
| 136 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER); | 136 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER); |
| 137 ContentAutofillDriverFactory* factory = |
| 138 ContentAutofillDriverFactory::FromWebContents(web_contents()); |
| 137 ContentAutofillDriver* driver = | 139 ContentAutofillDriver* driver = |
| 138 ContentAutofillDriver::FromWebContents(web_contents()); | 140 factory->DriverForFrame(web_contents()->GetMainFrame()); |
| 139 external_delegate_.reset( | 141 external_delegate_.reset( |
| 140 new NiceMock<MockAutofillExternalDelegate>( | 142 new NiceMock<MockAutofillExternalDelegate>( |
| 141 driver->autofill_manager(), | 143 driver->autofill_manager(), |
| 142 driver)); | 144 driver)); |
| 143 | 145 |
| 144 autofill_popup_controller_ = | 146 autofill_popup_controller_ = |
| 145 new testing::NiceMock<TestAutofillPopupController>( | 147 new testing::NiceMock<TestAutofillPopupController>( |
| 146 external_delegate_->GetWeakPtr(),gfx::Rect()); | 148 external_delegate_->GetWeakPtr(),gfx::Rect()); |
| 147 } | 149 } |
| 148 | 150 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); | 420 EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); |
| 419 | 421 |
| 420 // Clear datalist values and check that the popup becomes hidden. | 422 // Clear datalist values and check that the popup becomes hidden. |
| 421 EXPECT_CALL(*autofill_popup_controller_, Hide()); | 423 EXPECT_CALL(*autofill_popup_controller_, Hide()); |
| 422 data_list_values.clear(); | 424 data_list_values.clear(); |
| 423 autofill_popup_controller_->UpdateDataListValues(data_list_values, | 425 autofill_popup_controller_->UpdateDataListValues(data_list_values, |
| 424 data_list_values); | 426 data_list_values); |
| 425 } | 427 } |
| 426 | 428 |
| 427 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { | 429 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { |
| 430 ContentAutofillDriverFactory* factory = |
| 431 ContentAutofillDriverFactory::FromWebContents(web_contents()); |
| 428 ContentAutofillDriver* driver = | 432 ContentAutofillDriver* driver = |
| 429 ContentAutofillDriver::FromWebContents(web_contents()); | 433 factory->DriverForFrame(web_contents()->GetMainFrame()); |
| 430 MockAutofillExternalDelegate delegate(driver->autofill_manager(), driver); | 434 MockAutofillExternalDelegate delegate(driver->autofill_manager(), driver); |
| 431 | 435 |
| 432 WeakPtr<AutofillPopupControllerImpl> controller = | 436 WeakPtr<AutofillPopupControllerImpl> controller = |
| 433 AutofillPopupControllerImpl::GetOrCreate( | 437 AutofillPopupControllerImpl::GetOrCreate( |
| 434 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), | 438 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), |
| 435 NULL, NULL, gfx::Rect(), base::i18n::UNKNOWN_DIRECTION); | 439 NULL, NULL, gfx::Rect(), base::i18n::UNKNOWN_DIRECTION); |
| 436 EXPECT_TRUE(controller.get()); | 440 EXPECT_TRUE(controller.get()); |
| 437 | 441 |
| 438 controller->Hide(); | 442 controller->Hide(); |
| 439 | 443 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 EXPECT_NE(names[0], autofill_popup_controller_->names()[0]); | 530 EXPECT_NE(names[0], autofill_popup_controller_->names()[0]); |
| 527 EXPECT_NE(subtexts[0], autofill_popup_controller_->subtexts()[0]); | 531 EXPECT_NE(subtexts[0], autofill_popup_controller_->subtexts()[0]); |
| 528 | 532 |
| 529 // The second element was shorter so it should be unchanged. | 533 // The second element was shorter so it should be unchanged. |
| 530 EXPECT_EQ(names[1], autofill_popup_controller_->names()[1]); | 534 EXPECT_EQ(names[1], autofill_popup_controller_->names()[1]); |
| 531 EXPECT_EQ(subtexts[1], autofill_popup_controller_->subtexts()[1]); | 535 EXPECT_EQ(subtexts[1], autofill_popup_controller_->subtexts()[1]); |
| 532 } | 536 } |
| 533 #endif | 537 #endif |
| 534 | 538 |
| 535 } // namespace autofill | 539 } // namespace autofill |
| OLD | NEW |