summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/autofill/autofill_dialog_i18n_input_unittest.cc
blob: d8ea9dd346cef8557ad4784951297ba2586415a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h"

#include "components/autofill/core/browser/field_types.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui.h"

namespace autofill {
namespace i18ninput {

namespace {

const size_t kNumberOfAddressLinesUS = 6;

}  // namespace

TEST(AutofillDialogI18nInput, USShippingAddress) {
  DetailInputs inputs;
  std::string language_code;
  BuildAddressInputs(common::ADDRESS_TYPE_SHIPPING, "US", &inputs,
                     &language_code);

  ASSERT_EQ(kNumberOfAddressLinesUS, inputs.size());
  EXPECT_EQ(NAME_FULL, inputs[0].type);
  EXPECT_EQ(ADDRESS_HOME_COUNTRY, inputs[kNumberOfAddressLinesUS - 1].type);
  EXPECT_EQ("en", language_code);
}

TEST(AutofillDialogI18nInput, USBillingAddress) {
  DetailInputs inputs;
  BuildAddressInputs(common::ADDRESS_TYPE_BILLING, "US", &inputs, NULL);

  ASSERT_EQ(kNumberOfAddressLinesUS, inputs.size());
  EXPECT_EQ(NAME_BILLING_FULL, inputs[0].type);
  EXPECT_EQ(ADDRESS_BILLING_COUNTRY, inputs[kNumberOfAddressLinesUS - 1].type);
}

TEST(AutofillDialogI18nInput, USCityStateAndZipCodeShareInputRow) {
  DetailInputs inputs;
  BuildAddressInputs(common::ADDRESS_TYPE_SHIPPING, "US", &inputs, NULL);
  ASSERT_EQ(kNumberOfAddressLinesUS, inputs.size());

  int input_index = 2;

  // Inputs before or after [ City ] [ State ] [ Zip ] should be on other lines.
  EXPECT_NE(inputs[input_index - 1].length, DetailInput::SHORT);

  const DetailInput& city = inputs[input_index++];
  EXPECT_EQ(ADDRESS_HOME_CITY, city.type);
  EXPECT_EQ(city.length, DetailInput::SHORT);

  const DetailInput& state = inputs[input_index++];
  EXPECT_EQ(ADDRESS_HOME_STATE, state.type);
  EXPECT_EQ(state.length, DetailInput::SHORT);

  const DetailInput& zip = inputs[input_index++];
  EXPECT_EQ(ADDRESS_HOME_ZIP, zip.type);
  EXPECT_EQ(zip.length, DetailInput::SHORT);

  EXPECT_NE(inputs[input_index].length, DetailInput::SHORT);
}

TEST(AutofillDialogI18nInput, IvoryCoastNoStreetLine2) {
  DetailInputs inputs;
  std::string language_code;
  BuildAddressInputs(common::ADDRESS_TYPE_SHIPPING, "CI", &inputs,
                     &language_code);
  for (size_t i = 0; i < inputs.size(); ++i) {
    EXPECT_NE(ADDRESS_HOME_LINE2, inputs[i].type);
  }
  EXPECT_EQ("fr", language_code);
}

}  // namespace i18ninput
}  // namespace autofill