| Index: third_party/libaddressinput/chromium/cpp/test/fake_downloader.cc
|
| diff --git a/third_party/libaddressinput/chromium/cpp/test/fake_downloader.cc b/third_party/libaddressinput/chromium/cpp/test/fake_downloader.cc
|
| index 602231266bf0444e7762f0b46748c7947c484538..c48c61965aa36b1859d3d47661629c8ab72ffeb5 100644
|
| --- a/third_party/libaddressinput/chromium/cpp/test/fake_downloader.cc
|
| +++ b/third_party/libaddressinput/chromium/cpp/test/fake_downloader.cc
|
| @@ -34,6 +34,15 @@ const char kDataFileName[] = TEST_DATA_DIR "/countryinfo.txt";
|
| // The number of characters in the fake data URL prefix.
|
| const size_t kFakeDataUrlLength = sizeof FakeDownloader::kFakeDataUrl - 1;
|
|
|
| +// Each key begins with this string.
|
| +const char kKeyPrefix[] = "data/";
|
| +
|
| +// The number of characters in the key prefix.
|
| +const size_t kKeyPrefixLength = sizeof kKeyPrefix - 1;
|
| +
|
| +// The number of characters in a country-level key.
|
| +const size_t kCountryKeyLength = kKeyPrefixLength + 2;
|
| +
|
| std::map<std::string, std::string> InitData() {
|
| std::map<std::string, std::string> data;
|
| std::ifstream file(kDataFileName);
|
| @@ -42,14 +51,33 @@ std::map<std::string, std::string> InitData() {
|
| std::string line;
|
| while (file.good()) {
|
| std::getline(file, line);
|
| + if (line.compare(0, kKeyPrefixLength, kKeyPrefix, kKeyPrefixLength) != 0) {
|
| + continue;
|
| + }
|
| +
|
| std::string::size_type divider = line.find('=');
|
| - if (divider != std::string::npos) {
|
| - data.insert(std::make_pair(
|
| - FakeDownloader::kFakeDataUrl + (line.substr(0, divider)),
|
| - line.substr(divider + 1)));
|
| + if (divider == std::string::npos) {
|
| + continue;
|
| + }
|
| +
|
| + std::string key = line.substr(0, divider);
|
| + std::string value = line.substr(divider + 1);
|
| + std::string url =
|
| + FakeDownloader::kFakeDataUrl + key.substr(0, kCountryKeyLength);
|
| + std::map<std::string, std::string>::iterator data_it = data.find(url);
|
| + if (data_it != data.end()) {
|
| + data_it->second += ", \"" + key + "\": " + value;
|
| + } else {
|
| + data.insert(std::make_pair(url, "{\"" + key + "\": " + value));
|
| }
|
| }
|
| file.close();
|
| +
|
| + for (std::map<std::string, std::string>::iterator data_it = data.begin();
|
| + data_it != data.end(); ++data_it) {
|
| + data_it->second += "}";
|
| + }
|
| +
|
| return data;
|
| }
|
|
|
| @@ -70,11 +98,14 @@ void FakeDownloader::Download(const std::string& url,
|
| GetData().find(url);
|
| bool success = data_it != GetData().end();
|
| std::string data = success ? data_it->second : std::string();
|
| - if (!success && !url.compare(0, kFakeDataUrlLength, kFakeDataUrl)) {
|
| - // URLs that start with "https://i18napis.appspot.com/ssl-address/" prefix,
|
| - // but do not have associated data will always return "{}" with status code
|
| - // 200. FakeDownloader imitates this behavior for URLs that start with
|
| - // "test:///" prefix.
|
| + if (!success &&
|
| + url.compare(
|
| + 0, kFakeDataUrlLength, kFakeDataUrl, kFakeDataUrlLength) == 0) {
|
| + // URLs that start with
|
| + // "https://i18napis.appspot.com/ssl-aggregate-address/" prefix, but do not
|
| + // have associated data will always return "{}" with status code 200.
|
| + // FakeDownloader imitates this behavior for URLs that start with "test:///"
|
| + // prefix.
|
| success = true;
|
| data = "{}";
|
| }
|
|
|