Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: third_party/libaddressinput/chromium/cpp/test/country_rules_aggregator_test.cc

Issue 140823005: [rac] Download country code data in a single HTTP request. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add comment. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (C) 2013 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "country_rules_aggregator.h"
16
17 #include <libaddressinput/callback.h>
18 #include <libaddressinput/downloader.h>
19 #include <libaddressinput/storage.h>
20 #include <libaddressinput/util/basictypes.h>
21 #include <libaddressinput/util/scoped_ptr.h>
22
23 #include <cstddef>
24 #include <string>
25 #include <vector>
26
27 #include <gtest/gtest.h>
28
29 #include "fake_downloader.h"
30 #include "fake_storage.h"
31 #include "retriever.h"
32 #include "rule.h"
33 #include "ruleset.h"
34
35 namespace i18n {
36 namespace addressinput {
37
38 class CountryRulesAggregatorTest : public testing::Test {
39 public:
40 CountryRulesAggregatorTest()
41 : aggregator_(scoped_ptr<Retriever>(new Retriever(
42 FakeDownloader::kFakeDataUrl,
43 scoped_ptr<Downloader>(new FakeDownloader),
44 scoped_ptr<Storage>(new FakeStorage)))),
45 success_(false),
46 country_code_(),
47 ruleset_() {}
48
49 virtual ~CountryRulesAggregatorTest() {}
50
51 protected:
52 scoped_ptr<CountryRulesAggregator::Callback> BuildCallback() {
53 return ::i18n::addressinput::BuildScopedPtrCallback(
54 this, &CountryRulesAggregatorTest::OnRulesetReady);
55 }
56
57 CountryRulesAggregator aggregator_;
58 bool success_;
59 std::string country_code_;
60 scoped_ptr<Ruleset> ruleset_;
61
62 private:
63 void OnRulesetReady(bool success,
64 const std::string& country_code,
65 scoped_ptr<Ruleset> ruleset) {
66 success_ = success;
67 country_code_ = country_code;
68 ruleset_.reset(ruleset.release());
69 }
70
71 DISALLOW_COPY_AND_ASSIGN(CountryRulesAggregatorTest);
72 };
73
74 TEST_F(CountryRulesAggregatorTest, ValidRuleset) {
75 aggregator_.AggregateRules("US", BuildCallback());
76 EXPECT_TRUE(success_);
77 EXPECT_EQ("US", country_code_);
78 ASSERT_TRUE(ruleset_ != NULL);
79 EXPECT_LT(0, ruleset_->rule().GetSubKeys().size());
80 for (std::vector<std::string>::const_iterator
81 sub_key_it = ruleset_->rule().GetSubKeys().begin();
82 sub_key_it != ruleset_->rule().GetSubKeys().end();
83 ++sub_key_it) {
84 EXPECT_TRUE(ruleset_->GetSubRegionRuleset(*sub_key_it) != NULL);
85 }
86 }
87
88 } // namespace addressinput
89 } // namespace i18n
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698