Update mojo sdk to rev 1dc8a9a5db73d3718d99917fadf31f5fb2ebad4f
[chromium-blink-merge.git] / third_party / libaddressinput / chromium / fallback_data_store_unittest.cc
blob558a0a6896dd036664d5a7956330b456e9a239f6
1 // Copyright 2014 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.
5 #include "third_party/libaddressinput/chromium/fallback_data_store.h"
7 #include <cstddef>
8 #include <ctime>
9 #include <string>
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/libaddressinput/src/cpp/src/util/json.h"
13 #include "third_party/libaddressinput/src/cpp/src/validating_util.h"
15 namespace autofill {
17 using i18n::addressinput::Json;
18 using i18n::addressinput::ValidatingUtil;
20 TEST(FallbackDataStore, Parsability) {
21 std::string data;
22 ASSERT_TRUE(FallbackDataStore::Get("data/US", &data));
24 // Should be stale.
25 EXPECT_FALSE(ValidatingUtil::UnwrapTimestamp(&data, time(NULL)));
27 // Should be uncorrupted.
28 EXPECT_TRUE(ValidatingUtil::UnwrapChecksum(&data));
30 // Should be valid JSON.
31 Json json;
32 ASSERT_TRUE(json.ParseObject(data));
34 // Should not have a string for "data/US", because "data/US" is a dictionary.
35 std::string value;
36 EXPECT_FALSE(json.GetStringValueForKey("data/US", &value));
38 // Should have a dictionary with "data/US" identifier.
39 const std::vector<const Json*>& sub_dicts = json.GetSubDictionaries();
40 bool key_found = false;
41 for (std::vector<const Json*>::const_iterator it = sub_dicts.begin();
42 it != sub_dicts.end(); ++it) {
43 const Json* sub_dict = *it;
44 EXPECT_TRUE(sub_dict->GetStringValueForKey("id", &value));
45 key_found |= value == "data/US";
47 EXPECT_TRUE(key_found);
50 } // namespace autofill