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

Unified Diff: content/common/android/address_parser_unittest.cc

Issue 10456007: [Android] Split the address parser from AddressDetector for WebView use. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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: content/common/android/address_parser_unittest.cc
diff --git a/content/renderer/android/address_detector_unittest.cc b/content/common/android/address_parser_unittest.cc
similarity index 93%
rename from content/renderer/android/address_detector_unittest.cc
rename to content/common/android/address_parser_unittest.cc
index 43c0addee095a99e90c1b88ce38382a3c2fe3980..1cabff2ead4e133b543efcd8e44c319efa64f1d4 100644
--- a/content/renderer/android/address_detector_unittest.cc
+++ b/content/common/android/address_parser_unittest.cc
@@ -2,25 +2,25 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/renderer/android/address_detector.h"
+#include "content/common/android/address_parser.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
-using content::AddressDetector;
+using content::AddressParser;
-class AddressDetectorTest : public testing::Test {
+class AddressParserTest : public testing::Test {
public:
- AddressDetectorTest() {}
+ AddressParserTest() {}
void TokenizeWords(const string16& content,
- AddressDetector::WordList* words) const {
- AddressDetector::String16Tokenizer tokenizer(content.begin(),
+ AddressParser::WordList* words) const {
+ AddressParser::String16Tokenizer tokenizer(content.begin(),
content.end(), kWhitespaceUTF16);
while (tokenizer.GetNext()) {
- words->push_back(AddressDetector::Word(tokenizer.token_begin(),
+ words->push_back(AddressParser::Word(tokenizer.token_begin(),
tokenizer.token_end()));
}
}
@@ -29,8 +29,8 @@ class AddressDetectorTest : public testing::Test {
string16 content_16 = UTF8ToUTF16(content);
string16 result;
- AddressDetector::HouseNumberParser parser;
- AddressDetector::Word word;
+ AddressParser::HouseNumberParser parser;
+ AddressParser::Word word;
if (parser.Parse(content_16.begin(), content_16.end(), &word))
result = string16(word.begin, word.end);
return UTF16ToUTF8(result);
@@ -42,18 +42,17 @@ class AddressDetectorTest : public testing::Test {
bool GetState(const std::string& state, size_t* state_index) const {
string16 state_16 = UTF8ToUTF16(state);
- AddressDetector::String16Tokenizer tokenizer(state_16.begin(),
- state_16.end(),
- kWhitespaceUTF16);
+ AddressParser::String16Tokenizer tokenizer(state_16.begin(),
+ state_16.end(), kWhitespaceUTF16);
if (!tokenizer.GetNext())
return false;
size_t state_last_word;
- AddressDetector::WordList words;
- words.push_back(AddressDetector::Word(tokenizer.token_begin(),
- tokenizer.token_end()));
- return AddressDetector::FindStateStartingInWord(
- &words, 0, &state_last_word, &tokenizer, state_index);
+ AddressParser::WordList words;
+ words.push_back(AddressParser::Word(tokenizer.token_begin(),
+ tokenizer.token_end()));
+ return AddressParser::FindStateStartingInWord(&words, 0,
+ &state_last_word, &tokenizer, state_index);
}
bool IsState(const std::string& state) const {
@@ -66,28 +65,26 @@ class AddressDetectorTest : public testing::Test {
EXPECT_TRUE(GetState(state, &state_index));
string16 zip_16 = UTF8ToUTF16(zip);
- AddressDetector::WordList words;
+ AddressParser::WordList words;
TokenizeWords(zip_16, &words);
EXPECT_TRUE(words.size() == 1);
- return AddressDetector::IsZipValid(words.front(), state_index);
+ return AddressParser::IsZipValid(words.front(), state_index);
}
bool IsLocationName(const std::string& street) const {
string16 street_16 = UTF8ToUTF16(street);
- AddressDetector::WordList words;
+ AddressParser::WordList words;
TokenizeWords(street_16, &words);
EXPECT_TRUE(words.size() == 1);
- return AddressDetector::IsValidLocationName(words.front());
+ return AddressParser::IsValidLocationName(words.front());
}
std::string FindAddress(const std::string& content) const {
string16 content_16 = UTF8ToUTF16(content);
string16 result_16;
size_t start, end;
- AddressDetector detector;
- std::string content_text;
- if (detector.FindContent(content_16.begin(), content_16.end(),
- &start, &end, &content_text))
+ if (AddressParser::FindContent(content_16.begin(), content_16.end(),
+ &start, &end))
result_16 = content_16.substr(start, end - start);
return UTF16ToUTF8(result_16);
}
@@ -101,10 +98,10 @@ class AddressDetectorTest : public testing::Test {
}
private:
- DISALLOW_COPY_AND_ASSIGN(AddressDetectorTest);
+ DISALLOW_COPY_AND_ASSIGN(AddressParserTest);
};
-TEST_F(AddressDetectorTest, HouseNumber) {
+TEST_F(AddressParserTest, HouseNumber) {
// Tests cases with valid home numbers.
EXPECT_EQ(GetHouseNumber("4 my house"), "4");
EXPECT_EQ(GetHouseNumber("Something 4 my house"), "4");
@@ -149,7 +146,7 @@ TEST_F(AddressDetectorTest, HouseNumber) {
EXPECT_FALSE(ContainsHouseNumber(""));
}
-TEST_F(AddressDetectorTest, FindState) {
+TEST_F(AddressParserTest, FindState) {
// The complete set of state codes and names is tested together with their
// returned state indices in the zip code test.
EXPECT_TRUE(IsState("CALIFORNIA"));
@@ -161,7 +158,7 @@ TEST_F(AddressDetectorTest, FindState) {
EXPECT_FALSE(IsState("zz"));
}
-TEST_F(AddressDetectorTest, ZipCode) {
+TEST_F(AddressParserTest, ZipCode) {
EXPECT_TRUE(IsZipValid("90000", "CA"));
EXPECT_TRUE(IsZipValid("01234", "MA"));
EXPECT_TRUE(IsZipValid("99999-9999", "Alaska"));
@@ -296,7 +293,7 @@ TEST_F(AddressDetectorTest, ZipCode) {
EXPECT_TRUE(IsZipValid("83000", "Wyoming"));
}
-TEST_F(AddressDetectorTest, LocationName) {
+TEST_F(AddressParserTest, LocationName) {
EXPECT_FALSE(IsLocationName("str-eet"));
EXPECT_FALSE(IsLocationName("somewhere"));
@@ -515,7 +512,7 @@ TEST_F(AddressDetectorTest, LocationName) {
EXPECT_TRUE(IsLocationName("xrd"));
}
-TEST_F(AddressDetectorTest, NumberPrefixCases) {
+TEST_F(AddressParserTest, NumberPrefixCases) {
EXPECT_EQ(FindAddress("Cafe 21\n750 Fifth Ave. San Diego, California 92101"),
"750 Fifth Ave. San Diego, California 92101");
EXPECT_EQ(FindAddress(
@@ -526,7 +523,7 @@ TEST_F(AddressDetectorTest, NumberPrefixCases) {
EXPECT_TRUE(IsAddress("123 4th Avenue, Somewhere in NY 10000"));
}
-TEST_F(AddressDetectorTest, FullAddress) {
+TEST_F(AddressParserTest, FullAddress) {
// Test US Google corporate addresses. Expects a full string match.
EXPECT_TRUE(IsAddress("1600 Amphitheatre Parkway Mountain View, CA 94043"));
EXPECT_TRUE(IsAddress("201 S. Division St. Suite 500 Ann Arbor, MI 48104"));

Powered by Google App Engine
This is Rietveld 408576698