// Copyright (c) 2011 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 <string>

#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autofill/address.h"
#include "chrome/browser/autofill/autofill_type.h"
#include "testing/gtest/include/gtest/gtest.h"

// Test that the getters and setters for country code are working.
TEST(AddressTest, CountryCode) {
  Address address;
  EXPECT_EQ(std::string(), address.country_code());

  address.set_country_code("US");
  EXPECT_EQ("US", address.country_code());

  address.set_country_code("CA");
  EXPECT_EQ("CA", address.country_code());
}

// Test that country codes are properly decoded as country names.
TEST(AddressTest, GetCountry) {
  Address address;
  EXPECT_EQ(std::string(), address.country_code());

  // Make sure that nothing breaks when the country code is missing.
  string16 country = address.GetInfo(ADDRESS_HOME_COUNTRY);
  EXPECT_EQ(string16(), country);

  address.set_country_code("US");
  country = address.GetInfo(ADDRESS_HOME_COUNTRY);
  EXPECT_EQ(ASCIIToUTF16("United States"), country);

  address.set_country_code("CA");
  country = address.GetInfo(ADDRESS_HOME_COUNTRY);
  EXPECT_EQ(ASCIIToUTF16("Canada"), country);
}

// Test that we properly detect country codes appropriate for each country.
TEST(AddressTest, SetCountry) {
  Address address;
  EXPECT_EQ(std::string(), address.country_code());

  // Test basic conversion.
  address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("United States"));
  string16 country = address.GetInfo(ADDRESS_HOME_COUNTRY);
  EXPECT_EQ("US", address.country_code());
  EXPECT_EQ(ASCIIToUTF16("United States"), country);

  // Test basic synonym detection.
  address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("USA"));
  country = address.GetInfo(ADDRESS_HOME_COUNTRY);
  EXPECT_EQ("US", address.country_code());
  EXPECT_EQ(ASCIIToUTF16("United States"), country);

  // Test case-insensitivity.
  address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("canADA"));
  country = address.GetInfo(ADDRESS_HOME_COUNTRY);
  EXPECT_EQ("CA", address.country_code());
  EXPECT_EQ(ASCIIToUTF16("Canada"), country);

  // Test country code detection.
  address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("JP"));
  country = address.GetInfo(ADDRESS_HOME_COUNTRY);
  EXPECT_EQ("JP", address.country_code());
  EXPECT_EQ(ASCIIToUTF16("Japan"), country);

  // Test that we ignore unknown countries.
  address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Unknown"));
  country = address.GetInfo(ADDRESS_HOME_COUNTRY);
  EXPECT_EQ(std::string(), address.country_code());
  EXPECT_EQ(string16(), country);
}

// Test that we properly match typed values to stored country data.
TEST(AddressTest, IsCountry) {
  Address address;
  address.set_country_code("US");

  const char* const kValidMatches[] = {
    "United States",
    "USA",
    "US",
    "United states",
    "us"
  };
  for (size_t i = 0; i < arraysize(kValidMatches); ++i) {
    SCOPED_TRACE(kValidMatches[i]);
    FieldTypeSet possible_field_types;
    address.GetPossibleFieldTypes(ASCIIToUTF16(kValidMatches[i]),
                                  &possible_field_types);
    ASSERT_EQ(1U, possible_field_types.size());
    EXPECT_EQ(ADDRESS_HOME_COUNTRY, *possible_field_types.begin());
  }

  const char* const kInvalidMatches[] = {
    "United",
    "Garbage"
  };
  for (size_t i = 0; i < arraysize(kInvalidMatches); ++i) {
    FieldTypeSet possible_field_types;
    address.GetPossibleFieldTypes(ASCIIToUTF16(kInvalidMatches[i]),
                                  &possible_field_types);
    EXPECT_EQ(0U, possible_field_types.size());
  }

  // Make sure that garbage values don't match when the country code is empty.
  address.set_country_code("");
  EXPECT_EQ(std::string(), address.country_code());
  FieldTypeSet possible_field_types;
  address.GetPossibleFieldTypes(ASCIIToUTF16("Garbage"),
                                &possible_field_types);
  EXPECT_EQ(0U, possible_field_types.size());
}
