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