| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "components/autofill/core/browser/test_autofill_external_delegate.h" | 25 #include "components/autofill/core/browser/test_autofill_external_delegate.h" |
| 26 #include "components/prefs/pref_service.h" | 26 #include "components/prefs/pref_service.h" |
| 27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 #include "ui/gfx/geometry/rect.h" | 30 #include "ui/gfx/geometry/rect.h" |
| 31 #include "ui/gfx/text_utils.h" | 31 #include "ui/gfx/text_utils.h" |
| 32 | 32 |
| 33 using ::testing::_; | 33 using ::testing::_; |
| 34 using ::testing::AtLeast; | 34 using ::testing::AtLeast; |
| 35 using ::testing::Mock; |
| 35 using ::testing::NiceMock; | 36 using ::testing::NiceMock; |
| 36 using base::ASCIIToUTF16; | 37 using base::ASCIIToUTF16; |
| 37 using base::WeakPtr; | 38 using base::WeakPtr; |
| 38 | 39 |
| 39 namespace autofill { | 40 namespace autofill { |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 class MockAutofillExternalDelegate : public AutofillExternalDelegate { | 43 class MockAutofillExternalDelegate : public AutofillExternalDelegate { |
| 43 public: | 44 public: |
| 44 MockAutofillExternalDelegate(AutofillManager* autofill_manager, | 45 MockAutofillExternalDelegate(AutofillManager* autofill_manager, |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 autofill_popup_controller_->Show(suggestions); | 240 autofill_popup_controller_->Show(suggestions); |
| 240 | 241 |
| 241 // Generate a popup, so it can be hidden later. It doesn't matter what the | 242 // Generate a popup, so it can be hidden later. It doesn't matter what the |
| 242 // external_delegate thinks is being shown in the process, since we are just | 243 // external_delegate thinks is being shown in the process, since we are just |
| 243 // testing the popup here. | 244 // testing the popup here. |
| 244 autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 245 autofill::GenerateTestAutofillPopup(external_delegate_.get()); |
| 245 | 246 |
| 246 // No line is selected so the removal should fail. | 247 // No line is selected so the removal should fail. |
| 247 EXPECT_FALSE(autofill_popup_controller_->RemoveSelectedLine()); | 248 EXPECT_FALSE(autofill_popup_controller_->RemoveSelectedLine()); |
| 248 | 249 |
| 250 // Select the first entry. |
| 251 base::Optional<int> selected_line(0); |
| 252 EXPECT_CALL(*autofill_popup_view_, |
| 253 OnSelectedRowChanged(kNoSelection, selected_line)); |
| 254 autofill_popup_controller_->SetSelectedLine(selected_line); |
| 255 Mock::VerifyAndClearExpectations(autofill_popup_view()); |
| 256 |
| 249 // Remove the first entry. The popup should be redrawn since its size has | 257 // Remove the first entry. The popup should be redrawn since its size has |
| 250 // changed. | 258 // changed. |
| 259 EXPECT_CALL(*autofill_popup_view_, OnSelectedRowChanged(_, _)).Times(0); |
| 251 EXPECT_CALL(*autofill_popup_controller_, OnSuggestionsChanged()); | 260 EXPECT_CALL(*autofill_popup_controller_, OnSuggestionsChanged()); |
| 252 autofill_popup_controller_->SetSelectedLine(0); | |
| 253 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); | 261 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); |
| 262 Mock::VerifyAndClearExpectations(autofill_popup_view()); |
| 263 |
| 264 // Select the last entry. |
| 265 EXPECT_CALL(*autofill_popup_view_, |
| 266 OnSelectedRowChanged(kNoSelection, selected_line)); |
| 267 autofill_popup_controller_->SetSelectedLine(selected_line); |
| 268 Mock::VerifyAndClearExpectations(autofill_popup_view()); |
| 254 | 269 |
| 255 // Remove the last entry. The popup should then be hidden since there are | 270 // Remove the last entry. The popup should then be hidden since there are |
| 256 // no Autofill entries left. | 271 // no Autofill entries left. |
| 272 EXPECT_CALL(*autofill_popup_view_, OnSelectedRowChanged(_, _)).Times(0); |
| 257 EXPECT_CALL(*autofill_popup_controller_, Hide()); | 273 EXPECT_CALL(*autofill_popup_controller_, Hide()); |
| 258 autofill_popup_controller_->SetSelectedLine(0); | |
| 259 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); | 274 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); |
| 260 } | 275 } |
| 261 | 276 |
| 262 TEST_F(AutofillPopupControllerUnitTest, RemoveOnlyLine) { | 277 TEST_F(AutofillPopupControllerUnitTest, RemoveOnlyLine) { |
| 263 // Set up the popup. | 278 // Set up the popup. |
| 264 std::vector<Suggestion> suggestions; | 279 std::vector<Suggestion> suggestions; |
| 265 suggestions.push_back(Suggestion("", "", "", 1)); | 280 suggestions.push_back(Suggestion("", "", "", 1)); |
| 266 autofill_popup_controller_->Show(suggestions); | 281 autofill_popup_controller_->Show(suggestions); |
| 267 | 282 |
| 268 // Generate a popup. | 283 // Generate a popup. |
| 269 autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 284 autofill::GenerateTestAutofillPopup(external_delegate_.get()); |
| 270 | 285 |
| 286 // No selection immediately after drawing popup. |
| 287 EXPECT_FALSE(autofill_popup_controller_->selected_line()); |
| 288 |
| 271 // Select the only line. | 289 // Select the only line. |
| 272 base::Optional<int> selected_line(0); | 290 base::Optional<int> selected_line(0); |
| 291 EXPECT_CALL(*autofill_popup_view_, |
| 292 OnSelectedRowChanged(kNoSelection, selected_line)); |
| 273 autofill_popup_controller_->SetSelectedLine(selected_line); | 293 autofill_popup_controller_->SetSelectedLine(selected_line); |
| 274 EXPECT_CALL(*autofill_popup_view_, | 294 Mock::VerifyAndClearExpectations(autofill_popup_view()); |
| 275 OnSelectedRowChanged(kNoSelection, selected_line)) | |
| 276 .Times(0); | |
| 277 | 295 |
| 278 // Remove the only line. The popup should then be hidden since there are no | 296 // Remove the only line. The popup should then be hidden since there are no |
| 279 // Autofill entries left. | 297 // Autofill entries left. |
| 280 EXPECT_CALL(*autofill_popup_controller_, Hide()); | 298 EXPECT_CALL(*autofill_popup_controller_, Hide()); |
| 281 EXPECT_CALL(*autofill_popup_view_, | 299 EXPECT_CALL(*autofill_popup_view_, OnSelectedRowChanged(_, _)).Times(0); |
| 282 OnSelectedRowChanged(selected_line, kNoSelection)); | |
| 283 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); | 300 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); |
| 284 } | 301 } |
| 285 | 302 |
| 286 TEST_F(AutofillPopupControllerUnitTest, SkipSeparator) { | 303 TEST_F(AutofillPopupControllerUnitTest, SkipSeparator) { |
| 287 // Set up the popup. | 304 // Set up the popup. |
| 288 std::vector<Suggestion> suggestions; | 305 std::vector<Suggestion> suggestions; |
| 289 suggestions.push_back(Suggestion("", "", "", 1)); | 306 suggestions.push_back(Suggestion("", "", "", 1)); |
| 290 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_SEPARATOR)); | 307 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_SEPARATOR)); |
| 291 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS)); | 308 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS)); |
| 292 autofill_popup_controller_->Show(suggestions); | 309 autofill_popup_controller_->Show(suggestions); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 | 526 |
| 510 // The second element was shorter so it should be unchanged. | 527 // The second element was shorter so it should be unchanged. |
| 511 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).value, | 528 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).value, |
| 512 autofill_popup_controller_->GetElidedValueAt(1)); | 529 autofill_popup_controller_->GetElidedValueAt(1)); |
| 513 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).label, | 530 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).label, |
| 514 autofill_popup_controller_->GetElidedLabelAt(1)); | 531 autofill_popup_controller_->GetElidedLabelAt(1)); |
| 515 } | 532 } |
| 516 #endif | 533 #endif |
| 517 | 534 |
| 518 } // namespace autofill | 535 } // namespace autofill |
| OLD | NEW |