Home | History | Annotate | Download | only in autofill
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "base/string_util.h"
      6 #include "base/utf_string_conversions.h"
      7 #include "chrome/browser/autofill/autofill_field.h"
      8 #include "chrome/browser/autofill/field_types.h"
      9 #include "testing/gtest/include/gtest/gtest.h"
     10 
     11 namespace {
     12 
     13 TEST(AutofillFieldTest, Type) {
     14   AutofillField field;
     15   ASSERT_EQ(NO_SERVER_DATA, field.server_type());
     16   ASSERT_EQ(UNKNOWN_TYPE, field.heuristic_type());
     17 
     18   // |server_type_| is NO_SERVER_DATA, so |heuristic_type_| is returned.
     19   EXPECT_EQ(UNKNOWN_TYPE, field.type());
     20 
     21   // Set the heuristic type and check it.
     22   field.set_heuristic_type(NAME_FIRST);
     23   EXPECT_EQ(NAME_FIRST, field.type());
     24 
     25   // Set the server type and check it.
     26   field.set_server_type(ADDRESS_BILLING_LINE1);
     27   EXPECT_EQ(ADDRESS_BILLING_LINE1, field.type());
     28 
     29   // Remove the server type to make sure the heuristic type is preserved.
     30   field.set_server_type(NO_SERVER_DATA);
     31   EXPECT_EQ(NAME_FIRST, field.type());
     32 }
     33 
     34 TEST(AutofillFieldTest, IsEmpty) {
     35   AutofillField field;
     36   ASSERT_EQ(string16(), field.value);
     37 
     38   // Field value is empty.
     39   EXPECT_TRUE(field.IsEmpty());
     40 
     41   // Field value is non-empty.
     42   field.value = ASCIIToUTF16("Value");
     43   EXPECT_FALSE(field.IsEmpty());
     44 }
     45 
     46 TEST(AutofillFieldTest, FieldSignature) {
     47   AutofillField field;
     48   ASSERT_EQ(string16(), field.name);
     49   ASSERT_EQ(string16(), field.form_control_type);
     50 
     51   // Signature is empty.
     52   EXPECT_EQ("2085434232", field.FieldSignature());
     53 
     54   // Field name is set.
     55   field.name = ASCIIToUTF16("Name");
     56   EXPECT_EQ("1606968241", field.FieldSignature());
     57 
     58   // Field form control type is set.
     59   field.form_control_type = ASCIIToUTF16("Text");
     60   EXPECT_EQ("4246049809", field.FieldSignature());
     61 
     62   // Heuristic type does not affect FieldSignature.
     63   field.set_heuristic_type(NAME_FIRST);
     64   EXPECT_EQ("4246049809", field.FieldSignature());
     65 
     66   // Server type does not affect FieldSignature.
     67   field.set_server_type(NAME_LAST);
     68   EXPECT_EQ("4246049809", field.FieldSignature());
     69 }
     70 
     71 TEST(AutofillFieldTest, IsFieldFillable) {
     72   AutofillField field;
     73   ASSERT_EQ(UNKNOWN_TYPE, field.type());
     74 
     75   // Type is unknown.
     76   EXPECT_FALSE(field.IsFieldFillable());
     77 
     78   // Only heuristic type is set.
     79   field.set_heuristic_type(NAME_FIRST);
     80   EXPECT_TRUE(field.IsFieldFillable());
     81 
     82   // Only server type is set.
     83   field.set_heuristic_type(UNKNOWN_TYPE);
     84   field.set_server_type(NAME_LAST);
     85   EXPECT_TRUE(field.IsFieldFillable());
     86 
     87   // Both types set.
     88   field.set_heuristic_type(NAME_FIRST);
     89   field.set_server_type(NAME_LAST);
     90   EXPECT_TRUE(field.IsFieldFillable());
     91 }
     92 
     93 }  // namespace
     94