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

Unified 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: Temporarily switch to staging URL. 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 side-by-side diff with in-line comments
Download patch
Index: third_party/libaddressinput/chromium/cpp/test/country_rules_aggregator_test.cc
diff --git a/third_party/libaddressinput/chromium/cpp/test/country_rules_aggregator_test.cc b/third_party/libaddressinput/chromium/cpp/test/country_rules_aggregator_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b82675b097082639c7bc8357dd8f6e6d8170f90c
--- /dev/null
+++ b/third_party/libaddressinput/chromium/cpp/test/country_rules_aggregator_test.cc
@@ -0,0 +1,109 @@
+// Copyright (C) 2013 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "country_rules_aggregator.h"
+
+#include <libaddressinput/callback.h>
+#include <libaddressinput/downloader.h>
+#include <libaddressinput/storage.h>
+#include <libaddressinput/util/basictypes.h>
+#include <libaddressinput/util/scoped_ptr.h>
+
+#include <algorithm>
+#include <cstddef>
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include "fake_downloader.h"
+#include "fake_storage.h"
+#include "retriever.h"
+#include "rule.h"
+#include "ruleset.h"
+
+namespace i18n {
+namespace addressinput {
+
+class CountryRulesAggregatorTest : public testing::Test {
+ public:
+ CountryRulesAggregatorTest()
+ : aggregator_(scoped_ptr<Retriever>(new Retriever(
+ FakeDownloader::kFakeDataUrl,
+ scoped_ptr<Downloader>(new FakeDownloader),
+ scoped_ptr<Storage>(new FakeStorage)))),
+ success_(false),
+ country_code_(),
+ ruleset_() {}
+
+ virtual ~CountryRulesAggregatorTest() {}
+
+ protected:
+ scoped_ptr<CountryRulesAggregator::Callback> BuildCallback() {
+ return ::i18n::addressinput::BuildScopedPtrCallback(
+ this, &CountryRulesAggregatorTest::OnRulesetReady);
+ }
+
+ CountryRulesAggregator aggregator_;
+ bool success_;
+ std::string country_code_;
+ scoped_ptr<Ruleset> ruleset_;
+
+ private:
+ void OnRulesetReady(bool success,
+ const std::string& country_code,
+ scoped_ptr<Ruleset> ruleset) {
+ success_ = success;
+ country_code_ = country_code;
+ ruleset_.reset(ruleset.release());
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(CountryRulesAggregatorTest);
+};
+
+TEST_F(CountryRulesAggregatorTest, ValidRuleset) {
+ aggregator_.AggregateRules("CH", BuildCallback());
+ EXPECT_TRUE(success_);
+ EXPECT_EQ("CH", country_code_);
+ ASSERT_TRUE(ruleset_ != NULL);
+
+ const std::vector<std::string>& sub_keys = ruleset_->rule().GetSubKeys();
+ EXPECT_TRUE(sub_keys.size() > 0);
+ for (std::vector<std::string>::const_iterator sub_key_it = sub_keys.begin();
+ sub_key_it != sub_keys.end(); ++sub_key_it) {
+ EXPECT_TRUE(ruleset_->GetSubRegionRuleset(*sub_key_it) != NULL);
+ }
+
+ std::vector<std::string> non_default_languages =
+ ruleset_->rule().GetLanguages();
+ std::vector<std::string>::iterator default_lang_it =
+ std::find(non_default_languages.begin(),
+ non_default_languages.end(),
+ ruleset_->rule().GetLanguage());
+ if (default_lang_it != non_default_languages.end()) {
+ non_default_languages.erase(default_lang_it);
+ }
+
+ EXPECT_TRUE(non_default_languages.size() > 0);
+ for (std::vector<std::string>::const_iterator
+ lang_it = non_default_languages.begin();
+ lang_it != non_default_languages.end();
+ ++lang_it) {
+ EXPECT_TRUE(ruleset_->GetLanguageCodeRule(*lang_it).GetLanguage() !=
+ ruleset_->rule().GetLanguage());
+ }
+}
+
+} // namespace addressinput
+} // namespace i18n

Powered by Google App Engine
This is Rietveld 408576698