| 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" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 controller_common_.reset(test_controller_common_); | 79 controller_common_.reset(test_controller_common_); |
| 80 } | 80 } |
| 81 virtual ~TestAutofillPopupController() {} | 81 virtual ~TestAutofillPopupController() {} |
| 82 | 82 |
| 83 void set_display(const gfx::Display& display) { | 83 void set_display(const gfx::Display& display) { |
| 84 test_controller_common_->set_display(display); | 84 test_controller_common_->set_display(display); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Making protected functions public for testing | 87 // Making protected functions public for testing |
| 88 using AutofillPopupControllerImpl::SetPopupBounds; | 88 using AutofillPopupControllerImpl::SetPopupBounds; |
| 89 using AutofillPopupControllerImpl::names; | 89 using AutofillPopupControllerImpl::GetLineCount; |
| 90 using AutofillPopupControllerImpl::subtexts; | 90 using AutofillPopupControllerImpl::GetSuggestionAt; |
| 91 using AutofillPopupControllerImpl::identifiers; | 91 using AutofillPopupControllerImpl::GetElidedValueAt; |
| 92 using AutofillPopupControllerImpl::GetElidedLabelAt; |
| 92 using AutofillPopupControllerImpl::selected_line; | 93 using AutofillPopupControllerImpl::selected_line; |
| 93 using AutofillPopupControllerImpl::SetSelectedLine; | 94 using AutofillPopupControllerImpl::SetSelectedLine; |
| 94 using AutofillPopupControllerImpl::SelectNextLine; | 95 using AutofillPopupControllerImpl::SelectNextLine; |
| 95 using AutofillPopupControllerImpl::SelectPreviousLine; | 96 using AutofillPopupControllerImpl::SelectPreviousLine; |
| 96 using AutofillPopupControllerImpl::RemoveSelectedLine; | 97 using AutofillPopupControllerImpl::RemoveSelectedLine; |
| 97 using AutofillPopupControllerImpl::popup_bounds; | 98 using AutofillPopupControllerImpl::popup_bounds; |
| 98 using AutofillPopupControllerImpl::element_bounds; | 99 using AutofillPopupControllerImpl::element_bounds; |
| 99 #if !defined(OS_ANDROID) | 100 #if !defined(OS_ANDROID) |
| 100 using AutofillPopupControllerImpl::GetNameFontListForRow; | 101 using AutofillPopupControllerImpl::GetValueFontListForRow; |
| 101 using AutofillPopupControllerImpl::subtext_font_list; | 102 using AutofillPopupControllerImpl::GetLabelFontList; |
| 102 using AutofillPopupControllerImpl::RowWidthWithoutText; | 103 using AutofillPopupControllerImpl::RowWidthWithoutText; |
| 103 #endif | 104 #endif |
| 104 using AutofillPopupControllerImpl::SetValues; | 105 using AutofillPopupControllerImpl::SetValues; |
| 105 using AutofillPopupControllerImpl::GetDesiredPopupWidth; | 106 using AutofillPopupControllerImpl::GetDesiredPopupWidth; |
| 106 using AutofillPopupControllerImpl::GetDesiredPopupHeight; | 107 using AutofillPopupControllerImpl::GetDesiredPopupHeight; |
| 107 using AutofillPopupControllerImpl::GetWeakPtr; | 108 using AutofillPopupControllerImpl::GetWeakPtr; |
| 108 MOCK_METHOD1(InvalidateRow, void(size_t)); | 109 MOCK_METHOD1(InvalidateRow, void(size_t)); |
| 109 MOCK_METHOD0(UpdateBoundsAndRedrawPopup, void()); | 110 MOCK_METHOD0(UpdateBoundsAndRedrawPopup, void()); |
| 110 MOCK_METHOD0(Hide, void()); | 111 MOCK_METHOD0(Hide, void()); |
| 111 | 112 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 EXPECT_CALL(*autofill_popup_controller_, | 180 EXPECT_CALL(*autofill_popup_controller_, |
| 180 UpdateBoundsAndRedrawPopup()); | 181 UpdateBoundsAndRedrawPopup()); |
| 181 | 182 |
| 182 popup_controller()->SetPopupBounds(popup_bounds); | 183 popup_controller()->SetPopupBounds(popup_bounds); |
| 183 | 184 |
| 184 EXPECT_EQ(popup_bounds, popup_controller()->popup_bounds()); | 185 EXPECT_EQ(popup_bounds, popup_controller()->popup_bounds()); |
| 185 } | 186 } |
| 186 | 187 |
| 187 TEST_F(AutofillPopupControllerUnitTest, ChangeSelectedLine) { | 188 TEST_F(AutofillPopupControllerUnitTest, ChangeSelectedLine) { |
| 188 // Set up the popup. | 189 // Set up the popup. |
| 189 std::vector<base::string16> names(2, base::string16()); | 190 std::vector<Suggestion> suggestions; |
| 190 std::vector<int> autofill_ids(2, 0); | 191 suggestions.push_back(Suggestion("", "", "", 0)); |
| 191 autofill_popup_controller_->Show(names, names, names, autofill_ids); | 192 suggestions.push_back(Suggestion("", "", "", 0)); |
| 193 autofill_popup_controller_->Show(suggestions); |
| 192 | 194 |
| 193 EXPECT_LT(autofill_popup_controller_->selected_line(), 0); | 195 EXPECT_LT(autofill_popup_controller_->selected_line(), 0); |
| 194 // Check that there are at least 2 values so that the first and last selection | 196 // Check that there are at least 2 values so that the first and last selection |
| 195 // are different. | 197 // are different. |
| 196 EXPECT_GE(2, | 198 EXPECT_GE(2, |
| 197 static_cast<int>(autofill_popup_controller_->subtexts().size())); | 199 static_cast<int>(autofill_popup_controller_->GetLineCount())); |
| 198 | 200 |
| 199 // Test wrapping before the front. | 201 // Test wrapping before the front. |
| 200 autofill_popup_controller_->SelectPreviousLine(); | 202 autofill_popup_controller_->SelectPreviousLine(); |
| 201 EXPECT_EQ(static_cast<int>( | 203 EXPECT_EQ(static_cast<int>( |
| 202 autofill_popup_controller_->subtexts().size() - 1), | 204 autofill_popup_controller_->GetLineCount() - 1), |
| 203 autofill_popup_controller_->selected_line()); | 205 autofill_popup_controller_->selected_line()); |
| 204 | 206 |
| 205 // Test wrapping after the end. | 207 // Test wrapping after the end. |
| 206 autofill_popup_controller_->SelectNextLine(); | 208 autofill_popup_controller_->SelectNextLine(); |
| 207 EXPECT_EQ(0, autofill_popup_controller_->selected_line()); | 209 EXPECT_EQ(0, autofill_popup_controller_->selected_line()); |
| 208 } | 210 } |
| 209 | 211 |
| 210 TEST_F(AutofillPopupControllerUnitTest, RedrawSelectedLine) { | 212 TEST_F(AutofillPopupControllerUnitTest, RedrawSelectedLine) { |
| 211 // Set up the popup. | 213 // Set up the popup. |
| 212 std::vector<base::string16> names(2, base::string16()); | 214 std::vector<Suggestion> suggestions; |
| 213 std::vector<int> autofill_ids(2, 0); | 215 suggestions.push_back(Suggestion("", "", "", 0)); |
| 214 autofill_popup_controller_->Show(names, names, names, autofill_ids); | 216 suggestions.push_back(Suggestion("", "", "", 0)); |
| 217 autofill_popup_controller_->Show(suggestions); |
| 215 | 218 |
| 216 // Make sure that when a new line is selected, it is invalidated so it can | 219 // Make sure that when a new line is selected, it is invalidated so it can |
| 217 // be updated to show it is selected. | 220 // be updated to show it is selected. |
| 218 int selected_line = 0; | 221 int selected_line = 0; |
| 219 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line)); | 222 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line)); |
| 220 autofill_popup_controller_->SetSelectedLine(selected_line); | 223 autofill_popup_controller_->SetSelectedLine(selected_line); |
| 221 | 224 |
| 222 // Ensure that the row isn't invalidated if it didn't change. | 225 // Ensure that the row isn't invalidated if it didn't change. |
| 223 EXPECT_CALL(*autofill_popup_controller_, | 226 EXPECT_CALL(*autofill_popup_controller_, |
| 224 InvalidateRow(selected_line)).Times(0); | 227 InvalidateRow(selected_line)).Times(0); |
| 225 autofill_popup_controller_->SetSelectedLine(selected_line); | 228 autofill_popup_controller_->SetSelectedLine(selected_line); |
| 226 | 229 |
| 227 // Change back to no selection. | 230 // Change back to no selection. |
| 228 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line)); | 231 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line)); |
| 229 autofill_popup_controller_->SetSelectedLine(-1); | 232 autofill_popup_controller_->SetSelectedLine(-1); |
| 230 } | 233 } |
| 231 | 234 |
| 232 TEST_F(AutofillPopupControllerUnitTest, RemoveLine) { | 235 TEST_F(AutofillPopupControllerUnitTest, RemoveLine) { |
| 233 // Set up the popup. | 236 // Set up the popup. |
| 234 std::vector<base::string16> names(3, base::string16()); | 237 std::vector<Suggestion> suggestions; |
| 235 std::vector<int> autofill_ids; | 238 suggestions.push_back(Suggestion("", "", "", 1)); |
| 236 autofill_ids.push_back(1); | 239 suggestions.push_back(Suggestion("", "", "", 1)); |
| 237 autofill_ids.push_back(1); | 240 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS)); |
| 238 autofill_ids.push_back(POPUP_ITEM_ID_AUTOFILL_OPTIONS); | 241 autofill_popup_controller_->Show(suggestions); |
| 239 autofill_popup_controller_->Show(names, names, names, autofill_ids); | |
| 240 | 242 |
| 241 // Generate a popup, so it can be hidden later. It doesn't matter what the | 243 // 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 | 244 // external_delegate thinks is being shown in the process, since we are just |
| 243 // testing the popup here. | 245 // testing the popup here. |
| 244 autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 246 autofill::GenerateTestAutofillPopup(external_delegate_.get()); |
| 245 | 247 |
| 246 // No line is selected so the removal should fail. | 248 // No line is selected so the removal should fail. |
| 247 EXPECT_FALSE(autofill_popup_controller_->RemoveSelectedLine()); | 249 EXPECT_FALSE(autofill_popup_controller_->RemoveSelectedLine()); |
| 248 | 250 |
| 249 // Try to remove the last entry and ensure it fails (it is an option). | 251 // Try to remove the last entry and ensure it fails (it is an option). |
| 250 autofill_popup_controller_->SetSelectedLine( | 252 autofill_popup_controller_->SetSelectedLine( |
| 251 autofill_popup_controller_->subtexts().size() - 1); | 253 autofill_popup_controller_->GetLineCount() - 1); |
| 252 EXPECT_FALSE(autofill_popup_controller_->RemoveSelectedLine()); | 254 EXPECT_FALSE(autofill_popup_controller_->RemoveSelectedLine()); |
| 253 EXPECT_LE(0, autofill_popup_controller_->selected_line()); | 255 EXPECT_LE(0, autofill_popup_controller_->selected_line()); |
| 254 | 256 |
| 255 // 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 |
| 256 // changed. | 258 // changed. |
| 257 EXPECT_CALL(*autofill_popup_controller_, UpdateBoundsAndRedrawPopup()); | 259 EXPECT_CALL(*autofill_popup_controller_, UpdateBoundsAndRedrawPopup()); |
| 258 autofill_popup_controller_->SetSelectedLine(0); | 260 autofill_popup_controller_->SetSelectedLine(0); |
| 259 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); | 261 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); |
| 260 | 262 |
| 261 // Remove the last entry. The popup should then be hidden since there are | 263 // Remove the last entry. The popup should then be hidden since there are |
| 262 // no Autofill entries left. | 264 // no Autofill entries left. |
| 263 EXPECT_CALL(*autofill_popup_controller_, Hide()); | 265 EXPECT_CALL(*autofill_popup_controller_, Hide()); |
| 264 autofill_popup_controller_->SetSelectedLine(0); | 266 autofill_popup_controller_->SetSelectedLine(0); |
| 265 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); | 267 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); |
| 266 } | 268 } |
| 267 | 269 |
| 268 TEST_F(AutofillPopupControllerUnitTest, RemoveOnlyLine) { | 270 TEST_F(AutofillPopupControllerUnitTest, RemoveOnlyLine) { |
| 269 // Set up the popup. | 271 // Set up the popup. |
| 270 std::vector<base::string16> names(1, base::string16()); | 272 std::vector<Suggestion> suggestions; |
| 271 std::vector<int> autofill_ids; | 273 suggestions.push_back(Suggestion("", "", "", 1)); |
| 272 autofill_ids.push_back(1); | 274 autofill_popup_controller_->Show(suggestions); |
| 273 autofill_popup_controller_->Show(names, names, names, autofill_ids); | |
| 274 | 275 |
| 275 // Generate a popup. | 276 // Generate a popup. |
| 276 autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 277 autofill::GenerateTestAutofillPopup(external_delegate_.get()); |
| 277 | 278 |
| 278 // Select the only line. | 279 // Select the only line. |
| 279 autofill_popup_controller_->SetSelectedLine(0); | 280 autofill_popup_controller_->SetSelectedLine(0); |
| 280 | 281 |
| 281 // Remove the only line. There should be no row invalidation and the popup | 282 // Remove the only line. There should be no row invalidation and the popup |
| 282 // should then be hidden since there are no Autofill entries left. | 283 // should then be hidden since there are no Autofill entries left. |
| 283 EXPECT_CALL(*autofill_popup_controller_, Hide()); | 284 EXPECT_CALL(*autofill_popup_controller_, Hide()); |
| 284 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(_)).Times(0); | 285 EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(_)).Times(0); |
| 285 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); | 286 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); |
| 286 } | 287 } |
| 287 | 288 |
| 288 TEST_F(AutofillPopupControllerUnitTest, SkipSeparator) { | 289 TEST_F(AutofillPopupControllerUnitTest, SkipSeparator) { |
| 289 // Set up the popup. | 290 // Set up the popup. |
| 290 std::vector<base::string16> names(3, base::string16()); | 291 std::vector<Suggestion> suggestions; |
| 291 std::vector<int> autofill_ids; | 292 suggestions.push_back(Suggestion("", "", "", 1)); |
| 292 autofill_ids.push_back(1); | 293 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_SEPARATOR)); |
| 293 autofill_ids.push_back(POPUP_ITEM_ID_SEPARATOR); | 294 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS)); |
| 294 autofill_ids.push_back(POPUP_ITEM_ID_AUTOFILL_OPTIONS); | 295 autofill_popup_controller_->Show(suggestions); |
| 295 autofill_popup_controller_->Show(names, names, names, autofill_ids); | |
| 296 | 296 |
| 297 autofill_popup_controller_->SetSelectedLine(0); | 297 autofill_popup_controller_->SetSelectedLine(0); |
| 298 | 298 |
| 299 // Make sure next skips the unselectable separator. | 299 // Make sure next skips the unselectable separator. |
| 300 autofill_popup_controller_->SelectNextLine(); | 300 autofill_popup_controller_->SelectNextLine(); |
| 301 EXPECT_EQ(2, autofill_popup_controller_->selected_line()); | 301 EXPECT_EQ(2, autofill_popup_controller_->selected_line()); |
| 302 | 302 |
| 303 // Make sure previous skips the unselectable separator. | 303 // Make sure previous skips the unselectable separator. |
| 304 autofill_popup_controller_->SelectPreviousLine(); | 304 autofill_popup_controller_->SelectPreviousLine(); |
| 305 EXPECT_EQ(0, autofill_popup_controller_->selected_line()); | 305 EXPECT_EQ(0, autofill_popup_controller_->selected_line()); |
| 306 } | 306 } |
| 307 | 307 |
| 308 TEST_F(AutofillPopupControllerUnitTest, RowWidthWithoutText) { | 308 TEST_F(AutofillPopupControllerUnitTest, RowWidthWithoutText) { |
| 309 std::vector<base::string16> names(4); | 309 // Give elements 1 and 3 subtexts and elements 2 and 3 icons, to ensure |
| 310 std::vector<base::string16> subtexts(4); | 310 // all combinations of subtexts and icons. |
| 311 std::vector<base::string16> icons(4); | 311 std::vector<Suggestion> suggestions; |
| 312 std::vector<int> ids(4); | 312 suggestions.push_back(Suggestion("", "", "", 0)); |
| 313 suggestions.push_back(Suggestion("", "x", "", 0)); |
| 314 suggestions.push_back(Suggestion("", "", "americanExpressCC", 0)); |
| 315 suggestions.push_back(Suggestion("", "x", "genericCC", 0)); |
| 313 | 316 |
| 314 // Set up some visible display so the text values are kept. | 317 // Set up some visible display so the text values are kept. |
| 315 gfx::Display display(0, gfx::Rect(0, 0, 100, 100)); | 318 gfx::Display display(0, gfx::Rect(0, 0, 100, 100)); |
| 316 autofill_popup_controller_->set_display(display); | 319 autofill_popup_controller_->set_display(display); |
| 317 | 320 |
| 318 // Give elements 1 and 3 subtexts and elements 2 and 3 icons, to ensure | 321 autofill_popup_controller_->Show(suggestions); |
| 319 // all combinations of subtexts and icons. | |
| 320 subtexts[1] = ASCIIToUTF16("x"); | |
| 321 subtexts[3] = ASCIIToUTF16("x"); | |
| 322 icons[2] = ASCIIToUTF16("americanExpressCC"); | |
| 323 icons[3] = ASCIIToUTF16("genericCC"); | |
| 324 autofill_popup_controller_->Show(names, subtexts, icons, ids); | |
| 325 | 322 |
| 326 int base_size = | 323 int base_size = |
| 327 AutofillPopupView::kEndPadding * 2 + | 324 AutofillPopupView::kEndPadding * 2 + |
| 328 kPopupBorderThickness * 2; | 325 kPopupBorderThickness * 2; |
| 329 int subtext_increase = AutofillPopupView::kNamePadding; | 326 int subtext_increase = AutofillPopupView::kNamePadding; |
| 330 | 327 |
| 331 EXPECT_EQ(base_size, autofill_popup_controller_->RowWidthWithoutText(0)); | 328 EXPECT_EQ(base_size, autofill_popup_controller_->RowWidthWithoutText(0)); |
| 332 EXPECT_EQ(base_size + subtext_increase, | 329 EXPECT_EQ(base_size + subtext_increase, |
| 333 autofill_popup_controller_->RowWidthWithoutText(1)); | 330 autofill_popup_controller_->RowWidthWithoutText(1)); |
| 334 EXPECT_EQ(base_size + AutofillPopupView::kIconPadding + | 331 EXPECT_EQ(base_size + AutofillPopupView::kIconPadding + |
| 335 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 332 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 336 IDR_AUTOFILL_CC_AMEX).Width(), | 333 IDR_AUTOFILL_CC_AMEX).Width(), |
| 337 autofill_popup_controller_->RowWidthWithoutText(2)); | 334 autofill_popup_controller_->RowWidthWithoutText(2)); |
| 338 EXPECT_EQ(base_size + subtext_increase + AutofillPopupView::kIconPadding + | 335 EXPECT_EQ(base_size + subtext_increase + AutofillPopupView::kIconPadding + |
| 339 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 336 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 340 IDR_AUTOFILL_CC_GENERIC).Width(), | 337 IDR_AUTOFILL_CC_GENERIC).Width(), |
| 341 autofill_popup_controller_->RowWidthWithoutText(3)); | 338 autofill_popup_controller_->RowWidthWithoutText(3)); |
| 342 } | 339 } |
| 343 | 340 |
| 344 TEST_F(AutofillPopupControllerUnitTest, UpdateDataListValues) { | 341 TEST_F(AutofillPopupControllerUnitTest, UpdateDataListValues) { |
| 345 std::vector<base::string16> items; | 342 std::vector<Suggestion> suggestions; |
| 346 items.push_back(base::string16()); | 343 suggestions.push_back(Suggestion("", "", "", 1)); |
| 347 std::vector<int> ids; | 344 autofill_popup_controller_->Show(suggestions); |
| 348 ids.push_back(1); | |
| 349 | |
| 350 autofill_popup_controller_->Show(items, items, items, ids); | |
| 351 | |
| 352 EXPECT_EQ(items, autofill_popup_controller_->names()); | |
| 353 EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); | |
| 354 | 345 |
| 355 // Add one data list entry. | 346 // Add one data list entry. |
| 347 base::string16 value1 = ASCIIToUTF16("data list value 1"); |
| 356 std::vector<base::string16> data_list_values; | 348 std::vector<base::string16> data_list_values; |
| 357 data_list_values.push_back(ASCIIToUTF16("data list value 1")); | 349 data_list_values.push_back(value1); |
| 358 | 350 |
| 359 autofill_popup_controller_->UpdateDataListValues(data_list_values, | 351 autofill_popup_controller_->UpdateDataListValues(data_list_values, |
| 360 data_list_values); | 352 data_list_values); |
| 361 | 353 |
| 362 // Update the expected values. | 354 ASSERT_EQ(3u, autofill_popup_controller_->GetLineCount()); |
| 363 items.insert(items.begin(), data_list_values[0]); | |
| 364 items.insert(items.begin() + 1, base::string16()); | |
| 365 ids.insert(ids.begin(), POPUP_ITEM_ID_DATALIST_ENTRY); | |
| 366 ids.insert(ids.begin() + 1, POPUP_ITEM_ID_SEPARATOR); | |
| 367 | 355 |
| 368 EXPECT_EQ(items, autofill_popup_controller_->names()); | 356 Suggestion result0 = autofill_popup_controller_->GetSuggestionAt(0); |
| 369 EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); | 357 EXPECT_EQ(value1, result0.value); |
| 358 EXPECT_EQ(value1, autofill_popup_controller_->GetElidedValueAt(0)); |
| 359 EXPECT_EQ(value1, result0.label); |
| 360 EXPECT_EQ(value1, autofill_popup_controller_->GetElidedLabelAt(0)); |
| 361 EXPECT_EQ(POPUP_ITEM_ID_DATALIST_ENTRY, result0.frontend_id); |
| 362 |
| 363 Suggestion result1 = autofill_popup_controller_->GetSuggestionAt(1); |
| 364 EXPECT_EQ(base::string16(), result1.value); |
| 365 EXPECT_EQ(base::string16(), result1.label); |
| 366 EXPECT_EQ(POPUP_ITEM_ID_SEPARATOR, result1.frontend_id); |
| 367 |
| 368 Suggestion result2 = autofill_popup_controller_->GetSuggestionAt(2); |
| 369 EXPECT_EQ(base::string16(), result2.value); |
| 370 EXPECT_EQ(base::string16(), result2.label); |
| 371 EXPECT_EQ(1, result2.frontend_id); |
| 370 | 372 |
| 371 // Add two data list entries (which should replace the current one). | 373 // Add two data list entries (which should replace the current one). |
| 372 data_list_values.push_back(ASCIIToUTF16("data list value 2")); | 374 base::string16 value2 = ASCIIToUTF16("data list value 2"); |
| 375 data_list_values.push_back(value2); |
| 376 |
| 377 autofill_popup_controller_->UpdateDataListValues(data_list_values, |
| 378 data_list_values); |
| 379 ASSERT_EQ(4u, autofill_popup_controller_->GetLineCount()); |
| 380 |
| 381 // Original one first, followed by new one, then separator. |
| 382 EXPECT_EQ(value1, autofill_popup_controller_->GetSuggestionAt(0).value); |
| 383 EXPECT_EQ(value1, autofill_popup_controller_->GetElidedValueAt(0)); |
| 384 EXPECT_EQ(value2, autofill_popup_controller_->GetSuggestionAt(1).value); |
| 385 EXPECT_EQ(value2, autofill_popup_controller_->GetElidedValueAt(1)); |
| 386 EXPECT_EQ(POPUP_ITEM_ID_SEPARATOR, |
| 387 autofill_popup_controller_->GetSuggestionAt(2).frontend_id); |
| 388 |
| 389 // Clear all data list values. |
| 390 data_list_values.clear(); |
| 391 autofill_popup_controller_->UpdateDataListValues(data_list_values, |
| 392 data_list_values); |
| 393 |
| 394 ASSERT_EQ(1u, autofill_popup_controller_->GetLineCount()); |
| 395 EXPECT_EQ(1, autofill_popup_controller_->GetSuggestionAt(0).frontend_id); |
| 396 } |
| 397 |
| 398 TEST_F(AutofillPopupControllerUnitTest, PopupsWithOnlyDataLists) { |
| 399 // Create the popup with a single datalist element. |
| 400 std::vector<Suggestion> suggestions; |
| 401 suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_DATALIST_ENTRY)); |
| 402 autofill_popup_controller_->Show(suggestions); |
| 403 |
| 404 // Replace the datalist element with a new one. |
| 405 base::string16 value1 = ASCIIToUTF16("data list value 1"); |
| 406 std::vector<base::string16> data_list_values; |
| 407 data_list_values.push_back(value1); |
| 373 | 408 |
| 374 autofill_popup_controller_->UpdateDataListValues(data_list_values, | 409 autofill_popup_controller_->UpdateDataListValues(data_list_values, |
| 375 data_list_values); | 410 data_list_values); |
| 376 | 411 |
| 377 // Update the expected values. | 412 ASSERT_EQ(1u, autofill_popup_controller_->GetLineCount()); |
| 378 items.insert(items.begin() + 1, data_list_values[1]); | 413 EXPECT_EQ(value1, autofill_popup_controller_->GetSuggestionAt(0).value); |
| 379 ids.insert(ids.begin(), POPUP_ITEM_ID_DATALIST_ENTRY); | 414 EXPECT_EQ(POPUP_ITEM_ID_DATALIST_ENTRY, |
| 380 | 415 autofill_popup_controller_->GetSuggestionAt(0).frontend_id); |
| 381 EXPECT_EQ(items, autofill_popup_controller_->names()); | |
| 382 EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); | |
| 383 | |
| 384 // Clear all data list values. | |
| 385 data_list_values.clear(); | |
| 386 | |
| 387 autofill_popup_controller_->UpdateDataListValues(data_list_values, | |
| 388 data_list_values); | |
| 389 | |
| 390 items.clear(); | |
| 391 items.push_back(base::string16()); | |
| 392 ids.clear(); | |
| 393 ids.push_back(1); | |
| 394 | |
| 395 EXPECT_EQ(items, autofill_popup_controller_->names()); | |
| 396 EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); | |
| 397 } | |
| 398 | |
| 399 TEST_F(AutofillPopupControllerUnitTest, PopupsWithOnlyDataLists) { | |
| 400 // Create the popup with a single datalist element. | |
| 401 std::vector<base::string16> items; | |
| 402 items.push_back(base::string16()); | |
| 403 std::vector<int> ids; | |
| 404 ids.push_back(POPUP_ITEM_ID_DATALIST_ENTRY); | |
| 405 | |
| 406 autofill_popup_controller_->Show(items, items, items, ids); | |
| 407 | |
| 408 EXPECT_EQ(items, autofill_popup_controller_->names()); | |
| 409 EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); | |
| 410 | |
| 411 // Replace the datalist element with a new one. | |
| 412 std::vector<base::string16> data_list_values; | |
| 413 data_list_values.push_back(ASCIIToUTF16("data list value 1")); | |
| 414 | |
| 415 autofill_popup_controller_->UpdateDataListValues(data_list_values, | |
| 416 data_list_values); | |
| 417 | |
| 418 EXPECT_EQ(data_list_values, autofill_popup_controller_->names()); | |
| 419 // The id value should stay the same. | |
| 420 EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); | |
| 421 | 416 |
| 422 // Clear datalist values and check that the popup becomes hidden. | 417 // Clear datalist values and check that the popup becomes hidden. |
| 423 EXPECT_CALL(*autofill_popup_controller_, Hide()); | 418 EXPECT_CALL(*autofill_popup_controller_, Hide()); |
| 424 data_list_values.clear(); | 419 data_list_values.clear(); |
| 425 autofill_popup_controller_->UpdateDataListValues(data_list_values, | 420 autofill_popup_controller_->UpdateDataListValues(data_list_values, |
| 426 data_list_values); | 421 data_list_values); |
| 427 } | 422 } |
| 428 | 423 |
| 429 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { | 424 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { |
| 430 ContentAutofillDriverFactory* factory = | 425 ContentAutofillDriverFactory* factory = |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 bounds, | 469 bounds, |
| 475 static_cast<AutofillPopupController*>(controller3.get())-> | 470 static_cast<AutofillPopupController*>(controller3.get())-> |
| 476 element_bounds()); | 471 element_bounds()); |
| 477 controller3->Hide(); | 472 controller3->Hide(); |
| 478 | 473 |
| 479 // Hide the test_controller to delete it. | 474 // Hide the test_controller to delete it. |
| 480 test_controller->DoHide(); | 475 test_controller->DoHide(); |
| 481 } | 476 } |
| 482 | 477 |
| 483 TEST_F(AutofillPopupControllerUnitTest, ProperlyResetController) { | 478 TEST_F(AutofillPopupControllerUnitTest, ProperlyResetController) { |
| 484 std::vector<base::string16> names(2); | 479 std::vector<Suggestion> suggestions; |
| 485 std::vector<int> ids(2); | 480 suggestions.push_back(Suggestion("", "", "", 0)); |
| 486 popup_controller()->SetValues(names, names, names, ids); | 481 suggestions.push_back(Suggestion("", "", "", 0)); |
| 482 popup_controller()->SetValues(suggestions); |
| 487 popup_controller()->SetSelectedLine(0); | 483 popup_controller()->SetSelectedLine(0); |
| 488 | 484 |
| 489 // Now show a new popup with the same controller, but with fewer items. | 485 // Now show a new popup with the same controller, but with fewer items. |
| 490 WeakPtr<AutofillPopupControllerImpl> controller = | 486 WeakPtr<AutofillPopupControllerImpl> controller = |
| 491 AutofillPopupControllerImpl::GetOrCreate( | 487 AutofillPopupControllerImpl::GetOrCreate( |
| 492 popup_controller()->GetWeakPtr(), | 488 popup_controller()->GetWeakPtr(), |
| 493 delegate()->GetWeakPtr(), | 489 delegate()->GetWeakPtr(), |
| 494 NULL, | 490 NULL, |
| 495 NULL, | 491 NULL, |
| 496 gfx::Rect(), | 492 gfx::Rect(), |
| 497 base::i18n::UNKNOWN_DIRECTION); | 493 base::i18n::UNKNOWN_DIRECTION); |
| 498 EXPECT_NE(0, controller->selected_line()); | 494 EXPECT_NE(0, controller->selected_line()); |
| 499 EXPECT_TRUE(controller->names().empty()); | 495 EXPECT_EQ(0u, controller->GetLineCount()); |
| 500 } | 496 } |
| 501 | 497 |
| 502 #if !defined(OS_ANDROID) | 498 #if !defined(OS_ANDROID) |
| 503 TEST_F(AutofillPopupControllerUnitTest, ElideText) { | 499 TEST_F(AutofillPopupControllerUnitTest, ElideText) { |
| 504 std::vector<base::string16> names; | 500 std::vector<Suggestion> suggestions; |
| 505 names.push_back(ASCIIToUTF16("Text that will need to be trimmed")); | 501 suggestions.push_back( |
| 506 names.push_back(ASCIIToUTF16("Untrimmed")); | 502 Suggestion("Text that will need to be trimmed", |
| 507 | 503 "Label that will be trimmed", "genericCC", 0)); |
| 508 std::vector<base::string16> subtexts; | 504 suggestions.push_back( |
| 509 subtexts.push_back(ASCIIToUTF16("Label that will be trimmed")); | 505 Suggestion("untrimmed", "Untrimmed", "genericCC", 0)); |
| 510 subtexts.push_back(ASCIIToUTF16("Untrimmed")); | |
| 511 | |
| 512 std::vector<base::string16> icons(2, ASCIIToUTF16("genericCC")); | |
| 513 std::vector<int> autofill_ids(2, 0); | |
| 514 | 506 |
| 515 // Show the popup once so we can easily generate the size it needs. | 507 // Show the popup once so we can easily generate the size it needs. |
| 516 autofill_popup_controller_->Show(names, subtexts, icons, autofill_ids); | 508 autofill_popup_controller_->Show(suggestions); |
| 517 | 509 |
| 518 // Ensure the popup will be too small to display all of the first row. | 510 // Ensure the popup will be too small to display all of the first row. |
| 519 int popup_max_width = | 511 int popup_max_width = |
| 520 gfx::GetStringWidth( | 512 gfx::GetStringWidth( |
| 521 names[0], autofill_popup_controller_->GetNameFontListForRow(0)) + | 513 suggestions[0].value, |
| 514 autofill_popup_controller_->GetValueFontListForRow(0)) + |
| 522 gfx::GetStringWidth( | 515 gfx::GetStringWidth( |
| 523 subtexts[0], autofill_popup_controller_->subtext_font_list()) - 25; | 516 suggestions[0].label, |
| 517 autofill_popup_controller_->GetLabelFontList()) - 25; |
| 524 gfx::Rect popup_bounds = gfx::Rect(0, 0, popup_max_width, 0); | 518 gfx::Rect popup_bounds = gfx::Rect(0, 0, popup_max_width, 0); |
| 525 autofill_popup_controller_->set_display(gfx::Display(0, popup_bounds)); | 519 autofill_popup_controller_->set_display(gfx::Display(0, popup_bounds)); |
| 526 | 520 |
| 527 autofill_popup_controller_->Show(names, subtexts, icons, autofill_ids); | 521 autofill_popup_controller_->Show(suggestions); |
| 528 | 522 |
| 529 // The first element was long so it should have been trimmed. | 523 // The first element was long so it should have been trimmed. |
| 530 EXPECT_NE(names[0], autofill_popup_controller_->names()[0]); | 524 EXPECT_NE(autofill_popup_controller_->GetSuggestionAt(0).value, |
| 531 EXPECT_NE(subtexts[0], autofill_popup_controller_->subtexts()[0]); | 525 autofill_popup_controller_->GetElidedValueAt(0)); |
| 526 EXPECT_NE(autofill_popup_controller_->GetSuggestionAt(0).label, |
| 527 autofill_popup_controller_->GetElidedLabelAt(0)); |
| 532 | 528 |
| 533 // The second element was shorter so it should be unchanged. | 529 // The second element was shorter so it should be unchanged. |
| 534 EXPECT_EQ(names[1], autofill_popup_controller_->names()[1]); | 530 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).value, |
| 535 EXPECT_EQ(subtexts[1], autofill_popup_controller_->subtexts()[1]); | 531 autofill_popup_controller_->GetElidedValueAt(1)); |
| 532 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).label, |
| 533 autofill_popup_controller_->GetElidedLabelAt(1)); |
| 536 } | 534 } |
| 537 #endif | 535 #endif |
| 538 | 536 |
| 539 } // namespace autofill | 537 } // namespace autofill |
| OLD | NEW |