summaryrefslogtreecommitdiff
path: root/chromium/third_party/libaddressinput/chromium/fallback_data_store_unittest.cc
blob: 558a0a6896dd036664d5a7956330b456e9a239f6 (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
// 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 "third_party/libaddressinput/chromium/fallback_data_store.h"

#include <cstddef>
#include <ctime>
#include <string>

#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libaddressinput/src/cpp/src/util/json.h"
#include "third_party/libaddressinput/src/cpp/src/validating_util.h"

namespace autofill {

using i18n::addressinput::Json;
using i18n::addressinput::ValidatingUtil;

TEST(FallbackDataStore, Parsability) {
  std::string data;
  ASSERT_TRUE(FallbackDataStore::Get("data/US", &data));

  // Should be stale.
  EXPECT_FALSE(ValidatingUtil::UnwrapTimestamp(&data, time(NULL)));

  // Should be uncorrupted.
  EXPECT_TRUE(ValidatingUtil::UnwrapChecksum(&data));

  // Should be valid JSON.
  Json json;
  ASSERT_TRUE(json.ParseObject(data));

  // Should not have a string for "data/US", because "data/US" is a dictionary.
  std::string value;
  EXPECT_FALSE(json.GetStringValueForKey("data/US", &value));

  // Should have a dictionary with "data/US" identifier.
  const std::vector<const Json*>& sub_dicts = json.GetSubDictionaries();
  bool key_found = false;
  for (std::vector<const Json*>::const_iterator it = sub_dicts.begin();
       it != sub_dicts.end(); ++it) {
    const Json* sub_dict = *it;
    EXPECT_TRUE(sub_dict->GetStringValueForKey("id", &value));
    key_found |= value == "data/US";
  }
  EXPECT_TRUE(key_found);
}

}  // namespace autofill