| 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/autofill_driver_impl.h" | 15 #include "components/autofill/content/browser/autofill_driver_impl.h" |
| 16 #include "components/autofill/core/browser/autofill_external_delegate.h" | 16 #include "components/autofill/core/browser/autofill_external_delegate.h" |
| 17 #include "components/autofill/core/browser/autofill_manager.h" | 17 #include "components/autofill/core/browser/autofill_manager.h" |
| 18 #include "components/autofill/core/browser/autofill_test_utils.h" | 18 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 19 #include "components/autofill/core/browser/popup_item_ids.h" |
| 19 #include "components/autofill/core/browser/test_autofill_external_delegate.h" | 20 #include "components/autofill/core/browser/test_autofill_external_delegate.h" |
| 20 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" | 21 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" |
| 21 #include "grit/webkit_resources.h" | 22 #include "grit/webkit_resources.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 24 #include "third_party/WebKit/public/web/WebAutofillClient.h" | |
| 25 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "ui/gfx/display.h" | 26 #include "ui/gfx/display.h" |
| 27 #include "ui/gfx/rect.h" | 27 #include "ui/gfx/rect.h" |
| 28 #include "ui/gfx/text_utils.h" | 28 #include "ui/gfx/text_utils.h" |
| 29 | 29 |
| 30 using ::testing::_; | 30 using ::testing::_; |
| 31 using ::testing::AtLeast; | 31 using ::testing::AtLeast; |
| 32 using ::testing::NiceMock; | 32 using ::testing::NiceMock; |
| 33 using base::ASCIIToUTF16; | 33 using base::ASCIIToUTF16; |
| 34 using base::WeakPtr; | 34 using base::WeakPtr; |
| 35 using blink::WebAutofillClient; | |
| 36 | 35 |
| 37 namespace autofill { | 36 namespace autofill { |
| 38 namespace { | 37 namespace { |
| 39 | 38 |
| 40 class MockAutofillExternalDelegate : public AutofillExternalDelegate { | 39 class MockAutofillExternalDelegate : public AutofillExternalDelegate { |
| 41 public: | 40 public: |
| 42 MockAutofillExternalDelegate(AutofillManager* autofill_manager, | 41 MockAutofillExternalDelegate(AutofillManager* autofill_manager, |
| 43 AutofillDriver* autofill_driver) | 42 AutofillDriver* autofill_driver) |
| 44 : AutofillExternalDelegate(autofill_manager, autofill_driver) {} | 43 : AutofillExternalDelegate(autofill_manager, autofill_driver) {} |
| 45 virtual ~MockAutofillExternalDelegate() {} | 44 virtual ~MockAutofillExternalDelegate() {} |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line)); | 229 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line)); |
| 231 autofill_popup_controller_->SetSelectedLine(-1); | 230 autofill_popup_controller_->SetSelectedLine(-1); |
| 232 } | 231 } |
| 233 | 232 |
| 234 TEST_F(AutofillPopupControllerUnitTest, RemoveLine) { | 233 TEST_F(AutofillPopupControllerUnitTest, RemoveLine) { |
| 235 // Set up the popup. | 234 // Set up the popup. |
| 236 std::vector<base::string16> names(3, base::string16()); | 235 std::vector<base::string16> names(3, base::string16()); |
| 237 std::vector<int> autofill_ids; | 236 std::vector<int> autofill_ids; |
| 238 autofill_ids.push_back(1); | 237 autofill_ids.push_back(1); |
| 239 autofill_ids.push_back(1); | 238 autofill_ids.push_back(1); |
| 240 autofill_ids.push_back(WebAutofillClient::MenuItemIDAutofillOptions); | 239 autofill_ids.push_back(POPUP_ITEM_ID_AUTOFILL_OPTIONS); |
| 241 autofill_popup_controller_->Show(names, names, names, autofill_ids); | 240 autofill_popup_controller_->Show(names, names, names, autofill_ids); |
| 242 | 241 |
| 243 // 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 |
| 244 // 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 |
| 245 // testing the popup here. | 244 // testing the popup here. |
| 246 autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 245 autofill::GenerateTestAutofillPopup(external_delegate_.get()); |
| 247 | 246 |
| 248 // No line is selected so the removal should fail. | 247 // No line is selected so the removal should fail. |
| 249 EXPECT_FALSE(autofill_popup_controller_->RemoveSelectedLine()); | 248 EXPECT_FALSE(autofill_popup_controller_->RemoveSelectedLine()); |
| 250 | 249 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 EXPECT_CALL(*autofill_popup_controller_, Hide()); | 284 EXPECT_CALL(*autofill_popup_controller_, Hide()); |
| 286 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(_)).Times(0); | 285 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(_)).Times(0); |
| 287 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); | 286 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); |
| 288 } | 287 } |
| 289 | 288 |
| 290 TEST_F(AutofillPopupControllerUnitTest, SkipSeparator) { | 289 TEST_F(AutofillPopupControllerUnitTest, SkipSeparator) { |
| 291 // Set up the popup. | 290 // Set up the popup. |
| 292 std::vector<base::string16> names(3, base::string16()); | 291 std::vector<base::string16> names(3, base::string16()); |
| 293 std::vector<int> autofill_ids; | 292 std::vector<int> autofill_ids; |
| 294 autofill_ids.push_back(1); | 293 autofill_ids.push_back(1); |
| 295 autofill_ids.push_back(WebAutofillClient::MenuItemIDSeparator); | 294 autofill_ids.push_back(POPUP_ITEM_ID_SEPARATOR); |
| 296 autofill_ids.push_back(WebAutofillClient::MenuItemIDAutofillOptions); | 295 autofill_ids.push_back(POPUP_ITEM_ID_AUTOFILL_OPTIONS); |
| 297 autofill_popup_controller_->Show(names, names, names, autofill_ids); | 296 autofill_popup_controller_->Show(names, names, names, autofill_ids); |
| 298 | 297 |
| 299 autofill_popup_controller_->SetSelectedLine(0); | 298 autofill_popup_controller_->SetSelectedLine(0); |
| 300 | 299 |
| 301 // Make sure next skips the unselectable separator. | 300 // Make sure next skips the unselectable separator. |
| 302 autofill_popup_controller_->SelectNextLine(); | 301 autofill_popup_controller_->SelectNextLine(); |
| 303 EXPECT_EQ(2, autofill_popup_controller_->selected_line()); | 302 EXPECT_EQ(2, autofill_popup_controller_->selected_line()); |
| 304 | 303 |
| 305 // Make sure previous skips the unselectable separator. | 304 // Make sure previous skips the unselectable separator. |
| 306 autofill_popup_controller_->SelectPreviousLine(); | 305 autofill_popup_controller_->SelectPreviousLine(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 // Add one data list entry. | 356 // Add one data list entry. |
| 358 std::vector<base::string16> data_list_values; | 357 std::vector<base::string16> data_list_values; |
| 359 data_list_values.push_back(ASCIIToUTF16("data list value 1")); | 358 data_list_values.push_back(ASCIIToUTF16("data list value 1")); |
| 360 | 359 |
| 361 autofill_popup_controller_->UpdateDataListValues(data_list_values, | 360 autofill_popup_controller_->UpdateDataListValues(data_list_values, |
| 362 data_list_values); | 361 data_list_values); |
| 363 | 362 |
| 364 // Update the expected values. | 363 // Update the expected values. |
| 365 items.insert(items.begin(), data_list_values[0]); | 364 items.insert(items.begin(), data_list_values[0]); |
| 366 items.insert(items.begin() + 1, base::string16()); | 365 items.insert(items.begin() + 1, base::string16()); |
| 367 ids.insert(ids.begin(), WebAutofillClient::MenuItemIDDataListEntry); | 366 ids.insert(ids.begin(), POPUP_ITEM_ID_DATALIST_ENTRY); |
| 368 ids.insert(ids.begin() + 1, WebAutofillClient::MenuItemIDSeparator); | 367 ids.insert(ids.begin() + 1, POPUP_ITEM_ID_SEPARATOR); |
| 369 | 368 |
| 370 EXPECT_EQ(items, autofill_popup_controller_->names()); | 369 EXPECT_EQ(items, autofill_popup_controller_->names()); |
| 371 EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); | 370 EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); |
| 372 | 371 |
| 373 // Add two data list entries (which should replace the current one). | 372 // Add two data list entries (which should replace the current one). |
| 374 data_list_values.push_back(ASCIIToUTF16("data list value 2")); | 373 data_list_values.push_back(ASCIIToUTF16("data list value 2")); |
| 375 | 374 |
| 376 autofill_popup_controller_->UpdateDataListValues(data_list_values, | 375 autofill_popup_controller_->UpdateDataListValues(data_list_values, |
| 377 data_list_values); | 376 data_list_values); |
| 378 | 377 |
| 379 // Update the expected values. | 378 // Update the expected values. |
| 380 items.insert(items.begin() + 1, data_list_values[1]); | 379 items.insert(items.begin() + 1, data_list_values[1]); |
| 381 ids.insert(ids.begin(), WebAutofillClient::MenuItemIDDataListEntry); | 380 ids.insert(ids.begin(), POPUP_ITEM_ID_DATALIST_ENTRY); |
| 382 | 381 |
| 383 EXPECT_EQ(items, autofill_popup_controller_->names()); | 382 EXPECT_EQ(items, autofill_popup_controller_->names()); |
| 384 EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); | 383 EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); |
| 385 | 384 |
| 386 // Clear all data list values. | 385 // Clear all data list values. |
| 387 data_list_values.clear(); | 386 data_list_values.clear(); |
| 388 | 387 |
| 389 autofill_popup_controller_->UpdateDataListValues(data_list_values, | 388 autofill_popup_controller_->UpdateDataListValues(data_list_values, |
| 390 data_list_values); | 389 data_list_values); |
| 391 | 390 |
| 392 items.clear(); | 391 items.clear(); |
| 393 items.push_back(base::string16()); | 392 items.push_back(base::string16()); |
| 394 ids.clear(); | 393 ids.clear(); |
| 395 ids.push_back(1); | 394 ids.push_back(1); |
| 396 | 395 |
| 397 EXPECT_EQ(items, autofill_popup_controller_->names()); | 396 EXPECT_EQ(items, autofill_popup_controller_->names()); |
| 398 EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); | 397 EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); |
| 399 } | 398 } |
| 400 | 399 |
| 401 TEST_F(AutofillPopupControllerUnitTest, PopupsWithOnlyDataLists) { | 400 TEST_F(AutofillPopupControllerUnitTest, PopupsWithOnlyDataLists) { |
| 402 // Create the popup with a single datalist element. | 401 // Create the popup with a single datalist element. |
| 403 std::vector<base::string16> items; | 402 std::vector<base::string16> items; |
| 404 items.push_back(base::string16()); | 403 items.push_back(base::string16()); |
| 405 std::vector<int> ids; | 404 std::vector<int> ids; |
| 406 ids.push_back(WebAutofillClient::MenuItemIDDataListEntry); | 405 ids.push_back(POPUP_ITEM_ID_DATALIST_ENTRY); |
| 407 | 406 |
| 408 autofill_popup_controller_->Show(items, items, items, ids); | 407 autofill_popup_controller_->Show(items, items, items, ids); |
| 409 | 408 |
| 410 EXPECT_EQ(items, autofill_popup_controller_->names()); | 409 EXPECT_EQ(items, autofill_popup_controller_->names()); |
| 411 EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); | 410 EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); |
| 412 | 411 |
| 413 // Replace the datalist element with a new one. | 412 // Replace the datalist element with a new one. |
| 414 std::vector<base::string16> data_list_values; | 413 std::vector<base::string16> data_list_values; |
| 415 data_list_values.push_back(ASCIIToUTF16("data list value 1")); | 414 data_list_values.push_back(ASCIIToUTF16("data list value 1")); |
| 416 | 415 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 EXPECT_NE(names[0], autofill_popup_controller_->names()[0]); | 529 EXPECT_NE(names[0], autofill_popup_controller_->names()[0]); |
| 531 EXPECT_NE(subtexts[0], autofill_popup_controller_->subtexts()[0]); | 530 EXPECT_NE(subtexts[0], autofill_popup_controller_->subtexts()[0]); |
| 532 | 531 |
| 533 // The second element was shorter so it should be unchanged. | 532 // The second element was shorter so it should be unchanged. |
| 534 EXPECT_EQ(names[1], autofill_popup_controller_->names()[1]); | 533 EXPECT_EQ(names[1], autofill_popup_controller_->names()[1]); |
| 535 EXPECT_EQ(subtexts[1], autofill_popup_controller_->subtexts()[1]); | 534 EXPECT_EQ(subtexts[1], autofill_popup_controller_->subtexts()[1]); |
| 536 } | 535 } |
| 537 #endif | 536 #endif |
| 538 | 537 |
| 539 } // namespace autofill | 538 } // namespace autofill |
| OLD | NEW |