Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(496)

Side by Side Diff: components/autofill/core/browser/form_structure_unittest.cc

Issue 178263004: rAc - Only show countries we're able to fill in. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add FormStructure unit test Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/autofill/core/browser/form_structure.h" 5 #include "components/autofill/core/browser/form_structure.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/autofill_metrics.h" 10 #include "components/autofill/core/browser/autofill_metrics.h"
(...skipping 2341 matching lines...) Expand 10 before | Expand all | Expand 10 after
2352 "</form>" 2352 "</form>"
2353 "</autofillquery>"; 2353 "</autofillquery>";
2354 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), 2354 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(),
2355 &encoded_signatures, 2355 &encoded_signatures,
2356 &encoded_xml)); 2356 &encoded_xml));
2357 ASSERT_EQ(1U, encoded_signatures.size()); 2357 ASSERT_EQ(1U, encoded_signatures.size());
2358 EXPECT_EQ(kSignature, encoded_signatures[0]); 2358 EXPECT_EQ(kSignature, encoded_signatures[0]);
2359 EXPECT_EQ(kResponse, encoded_xml); 2359 EXPECT_EQ(kResponse, encoded_xml);
2360 } 2360 }
2361 2361
2362 TEST(FormStructureTest, PossibleValues) {
2363 FormData form_data;
2364 FormFieldData field;
2365 field.autocomplete_attribute = "billing country";
2366 field.option_contents.push_back(ASCIIToUTF16("Down Under"));
2367 field.option_values.push_back(ASCIIToUTF16("AU"));
2368 field.option_contents.push_back(ASCIIToUTF16("Fr"));
2369 field.option_values.push_back(ASCIIToUTF16(""));
2370 field.option_contents.push_back(ASCIIToUTF16("Germany"));
2371 field.option_values.push_back(ASCIIToUTF16("GRMNY"));
2372 form_data.fields.push_back(field);
2373 FormStructure form_structure(form_data);
2374
2375 bool unused;
2376 form_structure.ParseFieldTypesFromAutocompleteAttributes(&unused, &unused);
2377
2378 // All values in <option> value= or contents are returned, set to upper case.
2379 std::set<base::string16> possible_values =
2380 form_structure.PossibleValues(ADDRESS_BILLING_COUNTRY);
2381 EXPECT_EQ(5U, possible_values.size());
2382 EXPECT_NE(possible_values.end(), possible_values.find(ASCIIToUTF16("AU")));
2383 EXPECT_NE(possible_values.end(), possible_values.find(ASCIIToUTF16("FR")));
2384 EXPECT_NE(possible_values.end(),
2385 possible_values.find(ASCIIToUTF16("DOWN UNDER")));
2386 EXPECT_NE(possible_values.end(),
2387 possible_values.find(ASCIIToUTF16("GERMANY")));
2388 EXPECT_NE(possible_values.end(), possible_values.find(ASCIIToUTF16("GRMNY")));
2389 EXPECT_EQ(possible_values.end(), possible_values.find(ASCIIToUTF16("Fr")));
2390 EXPECT_EQ(possible_values.end(), possible_values.find(ASCIIToUTF16("DE")));
2391
2392 // No field for the given type; empty value set.
2393 EXPECT_EQ(0U, form_structure.PossibleValues(ADDRESS_HOME_COUNTRY).size());
2394
2395 // A freeform input (<input>) allows any value (overriding other <select>s).
2396 FormFieldData freeform_field;
2397 freeform_field.autocomplete_attribute = "billing country";
2398 form_data.fields.push_back(freeform_field);
2399 FormStructure form_structure2(form_data);
2400 EXPECT_EQ(0U, form_structure2.PossibleValues(ADDRESS_BILLING_COUNTRY).size());
Ilya Sherman 2014/03/05 23:30:57 You probably need to call ParseFieldTypesFromAutoc
Evan Stade 2014/03/06 01:13:44 ah, yes. Thanks.
2401 }
2402
2362 } // namespace autofill 2403 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/form_structure.cc ('k') | components/autofill/core/common/form_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698