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 #include <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "chrome/browser/autofill/autofill_manager.h" | 9 #include "chrome/browser/autofill/autofill_manager.h" |
| 10 #include "chrome/browser/autofill/test_autofill_external_delegate.h" | 10 #include "chrome/browser/autofill/test_autofill_external_delegate.h" |
| 11 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | 11 #include "chrome/browser/autofill/test_autofill_manager_delegate.h" |
| 12 #include "chrome/common/form_data.h" | 12 #include "chrome/common/form_data.h" |
| 13 #include "chrome/common/form_field_data.h" | 13 #include "chrome/common/form_field_data.h" |
| 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 15 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
| 16 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
| 20 #include "ui/gfx/rect.h" | 20 #include "ui/gfx/rect.h" |
| 21 | 21 |
| 22 using content::BrowserThread; | 22 using content::BrowserThread; |
| 23 using testing::_; | 23 using testing::_; |
| 24 using WebKit::WebAutofillClient; | 24 using WebKit::WebAutofillClient; |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // A constant value to use as the Autofill query ID. | 28 // A constant value to use as the Autofill query ID. |
| 29 const int kQueryId = 5; | 29 const int kQueryId = 5; |
| 30 | 30 |
| 31 // A constant value to use as an Autofill profile ID. | 31 // A constant value to use as an Autofill profile ID. |
| 32 const int kAutofillProfileId = 1; | 32 const int kAutofillProfileId = 1; |
| 33 | 33 |
| 34 class MockAutofillExternalDelegate : | 34 class MockAutofillExternalDelegate : public AutofillExternalDelegate { |
| 35 public autofill::TestAutofillExternalDelegate { | |
| 36 public: | 35 public: |
| 37 MockAutofillExternalDelegate(content::WebContents* web_contents, | 36 MockAutofillExternalDelegate(content::WebContents* web_contents, |
| 38 AutofillManager* autofill_manger) | 37 AutofillManager* autofill_manger) |
| 39 : TestAutofillExternalDelegate(web_contents, autofill_manger) {} | 38 : AutofillExternalDelegate(web_contents, autofill_manger) {} |
| 39 | |
| 40 ~MockAutofillExternalDelegate() {} | 40 ~MockAutofillExternalDelegate() {} |
| 41 | 41 |
| 42 MOCK_METHOD4(ApplyAutofillSuggestions, void( | 42 MOCK_METHOD0(ClearPreviewedForm, void()); |
| 43 const std::vector<string16>& labels, | 43 }; |
|
Ilya Sherman
2013/02/26 09:24:57
nit: "private: DISALLOW_COPY_AND_ASSIGN(...)"
kaiwang
2013/02/26 22:18:40
Done.
| |
| 44 const std::vector<string16>& sub_labels, | |
| 45 const std::vector<string16>& icons, | |
| 46 const std::vector<int>& identifiers)); | |
| 47 | 44 |
| 48 MOCK_METHOD0(ClearPreviewedForm, void()); | 45 class MockAutofillManagerDelegate |
| 49 | 46 : public autofill::TestAutofillManagerDelegate { |
| 50 MOCK_METHOD1(EnsurePopupForElement, void(const gfx::RectF& element_bounds)); | 47 public: |
| 48 MOCK_METHOD6(ShowAutofillPopup, | |
| 49 void(const gfx::RectF& element_bounds, | |
| 50 const std::vector<string16>& values, | |
| 51 const std::vector<string16>& labels, | |
| 52 const std::vector<string16>& icons, | |
| 53 const std::vector<int>& identifiers, | |
| 54 AutofillPopupDelegate* delegate)); | |
| 51 | 55 |
| 52 MOCK_METHOD0(HideAutofillPopup, void()); | 56 MOCK_METHOD0(HideAutofillPopup, void()); |
| 53 }; | 57 }; |
|
Ilya Sherman
2013/02/26 09:24:57
nit: "private: DISALLOW_COPY_AND_ASSIGN(...)"
kaiwang
2013/02/26 22:18:40
Done.
| |
| 54 | 58 |
| 55 class MockAutofillManager : public AutofillManager { | 59 class MockAutofillManager : public AutofillManager { |
| 56 public: | 60 public: |
| 57 explicit MockAutofillManager(content::WebContents* web_contents, | 61 explicit MockAutofillManager(content::WebContents* web_contents, |
| 58 autofill::AutofillManagerDelegate* delegate) | 62 MockAutofillManagerDelegate* delegate) |
| 59 // Force to use the constructor designated for unit test, but we don't | 63 // Force to use the constructor designated for unit test, but we don't |
| 60 // really need personal_data in this test so we pass a NULL pointer. | 64 // really need personal_data in this test so we pass a NULL pointer. |
| 61 : AutofillManager(web_contents, delegate, NULL) { | 65 : AutofillManager(web_contents, delegate, NULL) { |
| 62 } | 66 } |
| 63 virtual ~MockAutofillManager() {} | 67 virtual ~MockAutofillManager() {} |
| 64 | 68 |
| 65 MOCK_METHOD4(OnFillAutofillFormData, | 69 MOCK_METHOD4(OnFillAutofillFormData, |
| 66 void(int query_id, | 70 void(int query_id, |
| 67 const FormData& form, | 71 const FormData& form, |
| 68 const FormFieldData& field, | 72 const FormFieldData& field, |
| 69 int unique_id)); | 73 int unique_id)); |
| 70 }; | 74 }; |
| 71 | 75 |
| 72 } // namespace | 76 } // namespace |
| 73 | 77 |
| 74 class AutofillExternalDelegateUnitTest | 78 class AutofillExternalDelegateUnitTest |
| 75 : public ChromeRenderViewHostTestHarness { | 79 : public ChromeRenderViewHostTestHarness { |
| 76 public: | 80 public: |
| 77 AutofillExternalDelegateUnitTest() | 81 AutofillExternalDelegateUnitTest() |
| 78 : ui_thread_(BrowserThread::UI, &message_loop_) {} | 82 : ui_thread_(BrowserThread::UI, &message_loop_) {} |
| 79 virtual ~AutofillExternalDelegateUnitTest() {} | 83 virtual ~AutofillExternalDelegateUnitTest() {} |
| 80 | 84 |
| 81 protected: | 85 protected: |
| 82 // Set up the expectation for a platform specific OnQuery call and then | 86 // Set up the expectation for a platform specific OnQuery call and then |
| 83 // execute it with the given QueryId. | 87 // execute it with the given QueryId. |
|
Ilya Sherman
2013/02/26 09:24:57
nit: Please update this comment.
kaiwang
2013/02/26 22:18:40
Done.
| |
| 84 void IssueOnQuery(int query_id) { | 88 void IssueOnQuery(int query_id) { |
| 85 const FormData form; | 89 const FormData form; |
| 86 FormFieldData field; | 90 FormFieldData field; |
| 87 field.is_focusable = true; | 91 field.is_focusable = true; |
| 88 field.should_autocomplete = true; | 92 field.should_autocomplete = true; |
| 89 const gfx::RectF element_bounds; | 93 const gfx::RectF element_bounds; |
| 90 | 94 |
| 91 EXPECT_CALL(*external_delegate_, EnsurePopupForElement(element_bounds)); | |
| 92 external_delegate_->OnQuery(query_id, form, field, element_bounds, false); | 95 external_delegate_->OnQuery(query_id, form, field, element_bounds, false); |
| 93 } | 96 } |
| 94 | 97 |
| 98 MockAutofillManagerDelegate manager_delegate_; | |
| 95 scoped_ptr<MockAutofillManager> autofill_manager_; | 99 scoped_ptr<MockAutofillManager> autofill_manager_; |
| 96 scoped_ptr<testing::NiceMock<MockAutofillExternalDelegate> > | 100 scoped_ptr<testing::NiceMock<MockAutofillExternalDelegate> > |
| 97 external_delegate_; | 101 external_delegate_; |
| 98 | 102 |
| 99 private: | 103 private: |
| 100 virtual void SetUp() OVERRIDE { | 104 virtual void SetUp() OVERRIDE { |
| 101 ChromeRenderViewHostTestHarness::SetUp(); | 105 ChromeRenderViewHostTestHarness::SetUp(); |
| 102 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); | 106 autofill_manager_.reset( |
| 103 autofill_manager_.reset(new MockAutofillManager( | 107 new MockAutofillManager(web_contents(), &manager_delegate_)); |
| 104 web_contents(), | |
| 105 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()))); | |
| 106 external_delegate_.reset( | 108 external_delegate_.reset( |
| 107 new testing::NiceMock<MockAutofillExternalDelegate>( | 109 new testing::NiceMock<MockAutofillExternalDelegate>( |
| 108 web_contents(), | 110 web_contents(), |
| 109 autofill_manager_.get())); | 111 autofill_manager_.get())); |
| 110 } | 112 } |
| 111 | 113 |
| 112 virtual void TearDown() OVERRIDE { | 114 virtual void TearDown() OVERRIDE { |
| 113 // Order of destruction is important as AutofillManager relies on | 115 // Order of destruction is important as AutofillManager relies on |
| 114 // PersonalDataManager to be around when it gets destroyed. Also, a real | 116 // PersonalDataManager to be around when it gets destroyed. Also, a real |
| 115 // AutofillManager is tied to the lifetime of the WebContents, so it must | 117 // AutofillManager is tied to the lifetime of the WebContents, so it must |
| 116 // be destroyed at the destruction of the WebContents. | 118 // be destroyed at the destruction of the WebContents. |
| 117 autofill_manager_.reset(); | 119 autofill_manager_.reset(); |
| 118 external_delegate_.reset(); | 120 external_delegate_.reset(); |
| 119 ChromeRenderViewHostTestHarness::TearDown(); | 121 ChromeRenderViewHostTestHarness::TearDown(); |
| 120 } | 122 } |
| 121 | 123 |
| 122 content::TestBrowserThread ui_thread_; | 124 content::TestBrowserThread ui_thread_; |
| 123 | 125 |
| 124 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateUnitTest); | 126 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateUnitTest); |
| 125 }; | 127 }; |
| 126 | 128 |
| 127 // Test that our external delegate called the virtual methods at the right time. | 129 // Test that our external delegate called the virtual methods at the right time. |
| 128 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { | 130 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { |
| 129 IssueOnQuery(kQueryId); | 131 IssueOnQuery(kQueryId); |
| 130 | 132 |
| 131 // The enums must be cast to ints to prevent compile errors on linux_rel. | 133 // The enums must be cast to ints to prevent compile errors on linux_rel. |
| 132 EXPECT_CALL(*external_delegate_, | 134 EXPECT_CALL(manager_delegate_, |
| 133 ApplyAutofillSuggestions(_, _, _, testing::ElementsAre( | 135 ShowAutofillPopup( |
| 134 kAutofillProfileId, | 136 _, _, _, _, |
| 135 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), | 137 testing::ElementsAre( |
| 136 static_cast<int>( | 138 kAutofillProfileId, |
| 137 WebAutofillClient::MenuItemIDAutofillOptions)))); | 139 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), |
| 140 static_cast<int>( | |
| 141 WebAutofillClient::MenuItemIDAutofillOptions)), | |
| 142 external_delegate_.get())); | |
| 138 | 143 |
| 139 // This should call ApplyAutofillSuggestions. | 144 // This should call ShowAutofillPopup. |
| 140 std::vector<string16> autofill_item; | 145 std::vector<string16> autofill_item; |
| 141 autofill_item.push_back(string16()); | 146 autofill_item.push_back(string16()); |
| 142 std::vector<int> autofill_ids; | 147 std::vector<int> autofill_ids; |
| 143 autofill_ids.push_back(kAutofillProfileId); | 148 autofill_ids.push_back(kAutofillProfileId); |
| 144 external_delegate_->OnSuggestionsReturned(kQueryId, | 149 external_delegate_->OnSuggestionsReturned(kQueryId, |
| 145 autofill_item, | 150 autofill_item, |
| 146 autofill_item, | 151 autofill_item, |
| 147 autofill_item, | 152 autofill_item, |
| 148 autofill_ids); | 153 autofill_ids); |
| 149 | 154 |
| 150 // Called by DidAutofillSuggestions, add expectation to remove warning. | 155 // Called by DidAutofillSuggestions, add expectation to remove warning. |
| 151 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); | 156 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); |
| 152 | 157 |
| 153 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); | 158 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
| 154 | 159 |
| 155 // This should trigger a call to hide the popup since | 160 // This should trigger a call to hide the popup since we've selected an |
| 156 // we've selected an option. | 161 // option. |
| 157 external_delegate_->DidAcceptSuggestion(autofill_item[0], autofill_ids[0]); | 162 external_delegate_->DidAcceptSuggestion(autofill_item[0], autofill_ids[0]); |
| 158 } | 163 } |
| 159 | 164 |
| 160 // Test that data list elements for a node will appear in the Autofill popup. | 165 // Test that data list elements for a node will appear in the Autofill popup. |
| 161 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { | 166 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { |
| 162 IssueOnQuery(kQueryId); | 167 IssueOnQuery(kQueryId); |
| 163 | 168 |
| 164 std::vector<string16> data_list_items; | 169 std::vector<string16> data_list_items; |
| 165 data_list_items.push_back(string16()); | 170 data_list_items.push_back(string16()); |
| 166 std::vector<int> data_list_ids; | 171 std::vector<int> data_list_ids; |
| 167 data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry); | 172 data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry); |
| 168 | 173 |
| 169 external_delegate_->SetCurrentDataListValues(data_list_items, | 174 external_delegate_->SetCurrentDataListValues(data_list_items, |
| 170 data_list_items, | 175 data_list_items, |
| 171 data_list_items, | 176 data_list_items, |
| 172 data_list_ids); | 177 data_list_ids); |
| 173 | 178 |
| 174 // The enums must be cast to ints to prevent compile errors on linux_rel. | 179 // The enums must be cast to ints to prevent compile errors on linux_rel. |
| 175 EXPECT_CALL(*external_delegate_, | 180 EXPECT_CALL(manager_delegate_, |
| 176 ApplyAutofillSuggestions( | 181 ShowAutofillPopup( |
| 177 _, _, _, testing::ElementsAre( | 182 _, _, _, _, |
| 183 testing::ElementsAre( | |
| 178 static_cast<int>( | 184 static_cast<int>( |
| 179 WebAutofillClient::MenuItemIDDataListEntry), | 185 WebAutofillClient::MenuItemIDDataListEntry), |
| 180 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), | 186 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), |
| 181 kAutofillProfileId, | 187 kAutofillProfileId, |
| 182 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), | 188 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), |
| 183 static_cast<int>( | 189 static_cast<int>( |
| 184 WebAutofillClient::MenuItemIDAutofillOptions)))); | 190 WebAutofillClient::MenuItemIDAutofillOptions)), |
| 191 external_delegate_.get())); | |
| 185 | 192 |
| 186 // This should call ApplyAutofillSuggestions. | 193 // This should call ShowAutofillPopup. |
| 187 std::vector<string16> autofill_item; | 194 std::vector<string16> autofill_item; |
| 188 autofill_item.push_back(string16()); | 195 autofill_item.push_back(string16()); |
| 189 std::vector<int> autofill_ids; | 196 std::vector<int> autofill_ids; |
| 190 autofill_ids.push_back(kAutofillProfileId); | 197 autofill_ids.push_back(kAutofillProfileId); |
| 191 external_delegate_->OnSuggestionsReturned(kQueryId, | 198 external_delegate_->OnSuggestionsReturned(kQueryId, |
| 192 autofill_item, | 199 autofill_item, |
| 193 autofill_item, | 200 autofill_item, |
| 194 autofill_item, | 201 autofill_item, |
| 195 autofill_ids); | 202 autofill_ids); |
| 196 | 203 |
| 197 // Try calling OnSuggestionsReturned with no Autofill values and ensure | 204 // Try calling OnSuggestionsReturned with no Autofill values and ensure |
| 198 // the datalist items are still shown. | 205 // the datalist items are still shown. |
| 199 // The enum must be cast to an int to prevent compile errors on linux_rel. | 206 // The enum must be cast to an int to prevent compile errors on linux_rel. |
| 200 EXPECT_CALL(*external_delegate_, | 207 EXPECT_CALL(manager_delegate_, |
| 201 ApplyAutofillSuggestions( | 208 ShowAutofillPopup( |
| 202 _, _, _, testing::ElementsAre( | 209 _, _, _, _, |
| 210 testing::ElementsAre( | |
| 203 static_cast<int>( | 211 static_cast<int>( |
| 204 WebAutofillClient::MenuItemIDDataListEntry)))); | 212 WebAutofillClient::MenuItemIDDataListEntry)), |
| 213 external_delegate_.get())); | |
| 205 | 214 |
| 206 autofill_item = std::vector<string16>(); | 215 autofill_item = std::vector<string16>(); |
| 207 autofill_ids = std::vector<int>(); | 216 autofill_ids = std::vector<int>(); |
| 208 external_delegate_->OnSuggestionsReturned(kQueryId, | 217 external_delegate_->OnSuggestionsReturned(kQueryId, |
| 209 autofill_item, | 218 autofill_item, |
| 210 autofill_item, | 219 autofill_item, |
| 211 autofill_item, | 220 autofill_item, |
| 212 autofill_ids); | 221 autofill_ids); |
| 213 } | 222 } |
| 214 | 223 |
| 215 // Test that the Autofill delegate doesn't try and fill a form with a | 224 // Test that the Autofill delegate doesn't try and fill a form with a |
| 216 // negative unique id. | 225 // negative unique id. |
| 217 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { | 226 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { |
| 218 // Ensure it doesn't try to preview the negative id. | 227 // Ensure it doesn't try to preview the negative id. |
| 219 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); | 228 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); |
| 220 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); | 229 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); |
| 221 external_delegate_->DidSelectSuggestion(-1); | 230 external_delegate_->DidSelectSuggestion(-1); |
| 222 | 231 |
| 223 // Ensure it doesn't try to fill the form in with the negative id. | 232 // Ensure it doesn't try to fill the form in with the negative id. |
| 233 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | |
| 224 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); | 234 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); |
| 225 external_delegate_->DidAcceptSuggestion(string16(), -1); | 235 external_delegate_->DidAcceptSuggestion(string16(), -1); |
| 226 } | 236 } |
| 227 | 237 |
| 228 // Test that the ClearPreview IPC is only sent the form was being previewed | 238 // Test that the ClearPreview IPC is only sent the form was being previewed |
| 229 // (i.e. it isn't autofilling a password). | 239 // (i.e. it isn't autofilling a password). |
| 230 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { | 240 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { |
| 231 // Called by DidSelectSuggestion, add expectation to remove | 241 // Called by DidSelectSuggestion, add expectation to remove warning. |
| 232 // warning. | |
| 233 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); | 242 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); |
| 234 | 243 |
| 235 // Ensure selecting a new password entries or Autofill entries will | 244 // Ensure selecting a new password entries or Autofill entries will |
| 236 // cause any previews to get cleared. | 245 // cause any previews to get cleared. |
| 237 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); | 246 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); |
| 238 external_delegate_->DidSelectSuggestion( | 247 external_delegate_->DidSelectSuggestion( |
| 239 WebAutofillClient::MenuItemIDPasswordEntry); | 248 WebAutofillClient::MenuItemIDPasswordEntry); |
| 240 | 249 |
| 241 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); | 250 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); |
| 242 external_delegate_->DidSelectSuggestion(1); | 251 external_delegate_->DidSelectSuggestion(1); |
| 243 } | 252 } |
| 244 | 253 |
| 245 // Test that the popup is hidden once we are done editing the autofill field. | 254 // Test that the popup is hidden once we are done editing the autofill field. |
| 246 TEST_F(AutofillExternalDelegateUnitTest, | 255 TEST_F(AutofillExternalDelegateUnitTest, |
| 247 ExternalDelegateHidePopupAfterEditing) { | 256 ExternalDelegateHidePopupAfterEditing) { |
| 248 EXPECT_CALL(*external_delegate_, EnsurePopupForElement(_)); | 257 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _)); |
| 249 EXPECT_CALL(*external_delegate_, ApplyAutofillSuggestions(_, _, _, _)); | |
| 250 | |
| 251 autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 258 autofill::GenerateTestAutofillPopup(external_delegate_.get()); |
| 252 | 259 |
| 253 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); | 260 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
| 254 | |
| 255 external_delegate_->DidEndTextFieldEditing(); | 261 external_delegate_->DidEndTextFieldEditing(); |
| 256 } | 262 } |
| 257 | 263 |
| 258 // Test that the popup is marked as visible after recieving password | 264 // Test that the popup is marked as visible after recieving password |
| 259 // suggestions. | 265 // suggestions. |
| 260 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegatePasswordSuggestions) { | 266 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegatePasswordSuggestions) { |
| 261 std::vector<string16> suggestions; | 267 std::vector<string16> suggestions; |
| 262 suggestions.push_back(string16()); | 268 suggestions.push_back(string16()); |
| 263 | 269 |
| 264 FormFieldData field; | 270 FormFieldData field; |
| 265 field.is_focusable = true; | 271 field.is_focusable = true; |
| 266 field.should_autocomplete = true; | 272 field.should_autocomplete = true; |
| 267 const gfx::RectF element_bounds; | 273 const gfx::RectF element_bounds; |
| 268 | 274 |
| 269 EXPECT_CALL(*external_delegate_, EnsurePopupForElement(element_bounds)); | |
| 270 | |
| 271 // The enums must be cast to ints to prevent compile errors on linux_rel. | 275 // The enums must be cast to ints to prevent compile errors on linux_rel. |
| 272 EXPECT_CALL(*external_delegate_, | 276 EXPECT_CALL(manager_delegate_, |
| 273 ApplyAutofillSuggestions(_, _, _, testing::ElementsAre( | 277 ShowAutofillPopup( |
| 274 static_cast<int>( | 278 _, _, _, _, |
| 275 WebAutofillClient::MenuItemIDPasswordEntry)))); | 279 testing::ElementsAre( |
| 280 static_cast<int>( | |
| 281 WebAutofillClient::MenuItemIDPasswordEntry)), | |
| 282 external_delegate_.get())); | |
| 276 | 283 |
| 277 external_delegate_->OnShowPasswordSuggestions(suggestions, | 284 external_delegate_->OnShowPasswordSuggestions(suggestions, |
| 278 field, | 285 field, |
| 279 element_bounds); | 286 element_bounds); |
| 280 | 287 |
| 281 // Called by DidAutofillSuggestions, add expectation to remove warning. | 288 // Called by DidAutofillSuggestions, add expectation to remove warning. |
| 282 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); | 289 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); |
| 283 | 290 |
| 284 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); | 291 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
| 285 | 292 |
| 286 // This should trigger a call to hide the popup since | 293 // This should trigger a call to hide the popup since |
| 287 // we've selected an option. | 294 // we've selected an option. |
| 288 external_delegate_->DidAcceptSuggestion( | 295 external_delegate_->DidAcceptSuggestion( |
| 289 suggestions[0], | 296 suggestions[0], |
| 290 WebAutofillClient::MenuItemIDPasswordEntry); | 297 WebAutofillClient::MenuItemIDPasswordEntry); |
| 291 } | 298 } |
| OLD | NEW |