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