| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/common/android/address_parser.h" | 5 #include "android_webview/native/address_parser.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "android_webview/native/address_parser_internal.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "content/common/android/address_parser_internal.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 using namespace content::address_parser; | 17 using namespace android_webview::address_parser; |
| 18 using namespace content::address_parser::internal; | 18 using namespace android_webview::address_parser::internal; |
| 19 | 19 |
| 20 class AddressParserTest : public testing::Test { | 20 class AddressParserTest : public testing::Test { |
| 21 public: | 21 public: |
| 22 AddressParserTest() {} | 22 AddressParserTest() {} |
| 23 | 23 |
| 24 void TokenizeWords(const base::string16& content, WordList* words) const { | 24 void TokenizeWords(const base::string16& content, WordList* words) const { |
| 25 String16Tokenizer tokenizer(content.begin(), content.end(), | 25 String16Tokenizer tokenizer(content.begin(), content.end(), |
| 26 base::kWhitespaceUTF16); | 26 base::kWhitespaceUTF16); |
| 27 while (tokenizer.GetNext()) { | 27 while (tokenizer.GetNext()) { |
| 28 words->push_back(Word(tokenizer.token_begin(), tokenizer.token_end())); | 28 words->push_back(Word(tokenizer.token_begin(), tokenizer.token_end())); |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 EXPECT_TRUE(IsLocationName("way")); | 511 EXPECT_TRUE(IsLocationName("way")); |
| 512 EXPECT_TRUE(IsLocationName("ways")); | 512 EXPECT_TRUE(IsLocationName("ways")); |
| 513 EXPECT_TRUE(IsLocationName("well")); | 513 EXPECT_TRUE(IsLocationName("well")); |
| 514 EXPECT_TRUE(IsLocationName("wells")); | 514 EXPECT_TRUE(IsLocationName("wells")); |
| 515 EXPECT_TRUE(IsLocationName("xing")); | 515 EXPECT_TRUE(IsLocationName("xing")); |
| 516 EXPECT_TRUE(IsLocationName("xrd")); | 516 EXPECT_TRUE(IsLocationName("xrd")); |
| 517 } | 517 } |
| 518 | 518 |
| 519 TEST_F(AddressParserTest, NumberPrefixCases) { | 519 TEST_F(AddressParserTest, NumberPrefixCases) { |
| 520 EXPECT_EQ(FindAddress("Cafe 21\n750 Fifth Ave. San Diego, California 92101"), | 520 EXPECT_EQ(FindAddress("Cafe 21\n750 Fifth Ave. San Diego, California 92101"), |
| 521 "750 Fifth Ave. San Diego, California 92101"); | 521 "750 Fifth Ave. San Diego, California 92101"); |
| 522 EXPECT_EQ(FindAddress( | 522 EXPECT_EQ(FindAddress("Century City 15\n 10250 Santa Monica Boulevard Los " |
| 523 "Century City 15\n 10250 Santa Monica Boulevard Los Angeles, CA 90067"), | 523 "Angeles, CA 90067"), |
| 524 "10250 Santa Monica Boulevard Los Angeles, CA 90067"); | 524 "10250 Santa Monica Boulevard Los Angeles, CA 90067"); |
| 525 EXPECT_EQ(FindAddress("123 45\n67 My Street, Somewhere, NY 10000"), | 525 EXPECT_EQ(FindAddress("123 45\n67 My Street, Somewhere, NY 10000"), |
| 526 "67 My Street, Somewhere, NY 10000"); | 526 "67 My Street, Somewhere, NY 10000"); |
| 527 EXPECT_TRUE(IsAddress("123 4th Avenue, Somewhere in NY 10000")); | 527 EXPECT_TRUE(IsAddress("123 4th Avenue, Somewhere in NY 10000")); |
| 528 } | 528 } |
| 529 | 529 |
| 530 TEST_F(AddressParserTest, FullAddress) { | 530 TEST_F(AddressParserTest, FullAddress) { |
| 531 // Test US Google corporate addresses. Expects a full string match. | 531 // Test US Google corporate addresses. Expects a full string match. |
| 532 EXPECT_TRUE(IsAddress("1600 Amphitheatre Parkway Mountain View, CA 94043")); | 532 EXPECT_TRUE(IsAddress("1600 Amphitheatre Parkway Mountain View, CA 94043")); |
| 533 EXPECT_TRUE(IsAddress("201 S. Division St. Suite 500 Ann Arbor, MI 48104")); | 533 EXPECT_TRUE(IsAddress("201 S. Division St. Suite 500 Ann Arbor, MI 48104")); |
| 534 EXPECT_TRUE(ContainsAddress( | 534 EXPECT_TRUE(ContainsAddress( |
| 535 "Millennium at Midtown 10 10th Street NE Suite 600 Atlanta, GA 30309")); | 535 "Millennium at Midtown 10 10th Street NE Suite 600 Atlanta, GA 30309")); |
| 536 EXPECT_TRUE(IsAddress( | 536 EXPECT_TRUE( |
| 537 "9606 North MoPac Expressway Suite 400 Austin, TX 78759")); | 537 IsAddress("9606 North MoPac Expressway Suite 400 Austin, TX 78759")); |
| 538 EXPECT_TRUE(IsAddress("2590 Pearl Street Suite 100 Boulder, CO 80302")); | 538 EXPECT_TRUE(IsAddress("2590 Pearl Street Suite 100 Boulder, CO 80302")); |
| 539 EXPECT_TRUE(IsAddress("5 Cambridge Center, Floors 3-6 Cambridge, MA 02142")); | 539 EXPECT_TRUE(IsAddress("5 Cambridge Center, Floors 3-6 Cambridge, MA 02142")); |
| 540 EXPECT_TRUE(IsAddress("410 Market St Suite 415 Chapel Hill, NC 27516")); | 540 EXPECT_TRUE(IsAddress("410 Market St Suite 415 Chapel Hill, NC 27516")); |
| 541 EXPECT_TRUE(IsAddress("20 West Kinzie St. Chicago, IL 60654")); | 541 EXPECT_TRUE(IsAddress("20 West Kinzie St. Chicago, IL 60654")); |
| 542 EXPECT_TRUE(IsAddress("114 Willits Street Birmingham, MI 48009")); | 542 EXPECT_TRUE(IsAddress("114 Willits Street Birmingham, MI 48009")); |
| 543 EXPECT_TRUE(IsAddress("19540 Jamboree Road 2nd Floor Irvine, CA 92612")); | 543 EXPECT_TRUE(IsAddress("19540 Jamboree Road 2nd Floor Irvine, CA 92612")); |
| 544 EXPECT_TRUE(IsAddress("747 6th Street South, Kirkland, WA 98033")); | 544 EXPECT_TRUE(IsAddress("747 6th Street South, Kirkland, WA 98033")); |
| 545 EXPECT_TRUE(IsAddress("301 S. Blount St. Suite 301 Madison, WI 53703")); | 545 EXPECT_TRUE(IsAddress("301 S. Blount St. Suite 301 Madison, WI 53703")); |
| 546 EXPECT_TRUE(IsAddress("76 Ninth Avenue 4th Floor New York, NY 10011")); | 546 EXPECT_TRUE(IsAddress("76 Ninth Avenue 4th Floor New York, NY 10011")); |
| 547 EXPECT_TRUE(ContainsAddress( | 547 EXPECT_TRUE(ContainsAddress( |
| 548 "Chelsea Markset Space, 75 Ninth Avenue 2nd and 4th Floors New York, \ | 548 "Chelsea Markset Space, 75 Ninth Avenue 2nd and 4th Floors New York, \ |
| 549 NY 10011")); | 549 NY 10011")); |
| 550 EXPECT_TRUE(IsAddress("6425 Penn Ave. Suite 700 Pittsburgh, PA 15206")); | 550 EXPECT_TRUE(IsAddress("6425 Penn Ave. Suite 700 Pittsburgh, PA 15206")); |
| 551 EXPECT_TRUE(IsAddress("1818 Library Street Suite 400 Reston, VA 20190")); | 551 EXPECT_TRUE(IsAddress("1818 Library Street Suite 400 Reston, VA 20190")); |
| 552 EXPECT_TRUE(IsAddress("345 Spear Street Floors 2-4 San Francisco, CA 94105")); | 552 EXPECT_TRUE(IsAddress("345 Spear Street Floors 2-4 San Francisco, CA 94105")); |
| 553 EXPECT_TRUE(IsAddress("604 Arizona Avenue Santa Monica, CA 90401")); | 553 EXPECT_TRUE(IsAddress("604 Arizona Avenue Santa Monica, CA 90401")); |
| 554 EXPECT_TRUE(IsAddress("651 N. 34th St. Seattle, WA 98103")); | 554 EXPECT_TRUE(IsAddress("651 N. 34th St. Seattle, WA 98103")); |
| 555 EXPECT_TRUE(IsAddress( | 555 EXPECT_TRUE(IsAddress( |
| 556 "1101 New York Avenue, N.W. Second Floor Washington, DC 20005")); | 556 "1101 New York Avenue, N.W. Second Floor Washington, DC 20005")); |
| 557 | 557 |
| 558 // Other tests. | 558 // Other tests. |
| 559 EXPECT_TRUE(IsAddress("57th Street and Lake Shore Drive\nChicago, IL 60637")); | 559 EXPECT_TRUE(IsAddress("57th Street and Lake Shore Drive\nChicago, IL 60637")); |
| 560 EXPECT_TRUE(IsAddress("308 Congress Street Boston, MA 02210")); | 560 EXPECT_TRUE(IsAddress("308 Congress Street Boston, MA 02210")); |
| 561 EXPECT_TRUE(ContainsAddress( | 561 EXPECT_TRUE(ContainsAddress( |
| 562 "Central Park West at 79th Street, New York, NY, 10024-5192")); | 562 "Central Park West at 79th Street, New York, NY, 10024-5192")); |
| 563 EXPECT_TRUE(ContainsAddress( | 563 EXPECT_TRUE(ContainsAddress( |
| 564 "Lincoln Park | 100 34th Avenue • San Francisco, CA 94121 | 41575036")); | 564 "Lincoln Park | 100 34th Avenue • San Francisco, CA 94121 | 41575036")); |
| 565 | 565 |
| 566 EXPECT_EQ(FindAddress("Lorem ipsum dolor sit amet, consectetur adipisicing " \ | 566 EXPECT_EQ( |
| 567 "elit, sed do 1600 Amphitheatre Parkway Mountain View, CA 94043 " \ | 567 FindAddress( |
| 568 "eiusmod tempor incididunt ut labore et dolore magna aliqua."), | 568 "Lorem ipsum dolor sit amet, consectetur adipisicing " |
| 569 "elit, sed do 1600 Amphitheatre Parkway Mountain View, CA 94043 " |
| 570 "eiusmod tempor incididunt ut labore et dolore magna aliqua."), |
| 569 "1600 Amphitheatre Parkway Mountain View, CA 94043"); | 571 "1600 Amphitheatre Parkway Mountain View, CA 94043"); |
| 570 | 572 |
| 571 EXPECT_EQ(FindAddress("2590 Pearl Street Suite 100 Boulder, CO 80302 6425 " \ | 573 EXPECT_EQ(FindAddress("2590 Pearl Street Suite 100 Boulder, CO 80302 6425 " |
| 572 "Penn Ave. Suite 700 Pittsburgh, PA 15206"), | 574 "Penn Ave. Suite 700 Pittsburgh, PA 15206"), |
| 573 "2590 Pearl Street Suite 100 Boulder, CO 80302"); | 575 "2590 Pearl Street Suite 100 Boulder, CO 80302"); |
| 574 | 576 |
| 575 EXPECT_TRUE(IsAddress("5400 Preston Oaks Rd Dallas TX 75254")); | 577 EXPECT_TRUE(IsAddress("5400 Preston Oaks Rd Dallas TX 75254")); |
| 576 EXPECT_TRUE(IsAddress("5400 Preston Oaks Road Dallas TX 75254")); | 578 EXPECT_TRUE(IsAddress("5400 Preston Oaks Road Dallas TX 75254")); |
| 577 EXPECT_TRUE(IsAddress("5400 Preston Oaks Ave Dallas TX 75254")); | 579 EXPECT_TRUE(IsAddress("5400 Preston Oaks Ave Dallas TX 75254")); |
| 578 | 580 |
| 579 EXPECT_TRUE(ContainsAddress( | 581 EXPECT_TRUE(ContainsAddress( |
| 580 "住所は 1600 Amphitheatre Parkway Mountain View, CA 94043 です。")); | 582 "住所は 1600 Amphitheatre Parkway Mountain View, CA 94043 です。")); |
| 581 | 583 |
| 582 EXPECT_FALSE(ContainsAddress("1 st. too-short, CA 90000")); | 584 EXPECT_FALSE(ContainsAddress("1 st. too-short, CA 90000")); |
| 583 EXPECT_TRUE(ContainsAddress("1 st. long enough, CA 90000")); | 585 EXPECT_TRUE(ContainsAddress("1 st. long enough, CA 90000")); |
| 584 | 586 |
| 585 EXPECT_TRUE(ContainsAddress("1 st. some city in al 35000")); | 587 EXPECT_TRUE(ContainsAddress("1 st. some city in al 35000")); |
| 586 EXPECT_FALSE(ContainsAddress("1 book st Aquinas et al 35000")); | 588 EXPECT_FALSE(ContainsAddress("1 book st Aquinas et al 35000")); |
| 587 | 589 |
| 588 EXPECT_FALSE(ContainsAddress("1 this comes too late: street, CA 90000")); | 590 EXPECT_FALSE(ContainsAddress("1 this comes too late: street, CA 90000")); |
| 589 EXPECT_TRUE(ContainsAddress("1 this is ok: street, CA 90000")); | 591 EXPECT_TRUE(ContainsAddress("1 this is ok: street, CA 90000")); |
| 590 | 592 |
| 591 EXPECT_FALSE(ContainsAddress( | 593 EXPECT_FALSE(ContainsAddress( |
| 592 "1 street I love verbosity, so I'm writing an address with too many " \ | 594 "1 street I love verbosity, so I'm writing an address with too many " |
| 593 "words CA 90000")); | 595 "words CA 90000")); |
| 594 EXPECT_TRUE(ContainsAddress("1 street 2 3 4 5 6 7 8 9 10 11 12, CA 90000")); | 596 EXPECT_TRUE(ContainsAddress("1 street 2 3 4 5 6 7 8 9 10 11 12, CA 90000")); |
| 595 | 597 |
| 596 EXPECT_TRUE(IsAddress("79th Street 1st Floor New York City, NY 10024-5192")); | 598 EXPECT_TRUE(IsAddress("79th Street 1st Floor New York City, NY 10024-5192")); |
| 597 | 599 |
| 598 EXPECT_FALSE(ContainsAddress("123 Fake Street, Springfield, Springfield")); | 600 EXPECT_FALSE(ContainsAddress("123 Fake Street, Springfield, Springfield")); |
| 599 EXPECT_FALSE(ContainsAddress("999 Street Avenue, City, ZZ 98765")); | 601 EXPECT_FALSE(ContainsAddress("999 Street Avenue, City, ZZ 98765")); |
| 600 EXPECT_FALSE(ContainsAddress("76 Here be dragons, CA 94043")); | 602 EXPECT_FALSE(ContainsAddress("76 Here be dragons, CA 94043")); |
| 601 EXPECT_FALSE(ContainsAddress("1 This, has, too* many, lines, to, be* valid")); | 603 EXPECT_FALSE(ContainsAddress("1 This, has, too* many, lines, to, be* valid")); |
| 602 EXPECT_FALSE(ContainsAddress( | 604 EXPECT_FALSE(ContainsAddress( |
| 603 "1 Supercalifragilisticexpialidocious is too long, CA 90000")); | 605 "1 Supercalifragilisticexpialidocious is too long, CA 90000")); |
| 604 EXPECT_FALSE(ContainsAddress("")); | 606 EXPECT_FALSE(ContainsAddress("")); |
| 605 } | 607 } |
| 606 | 608 |
| 607 TEST_F(AddressParserTest, FullAddressWithoutZipCode) { | 609 TEST_F(AddressParserTest, FullAddressWithoutZipCode) { |
| 608 EXPECT_TRUE(IsAddress("1600 Amphitheatre Parkway Mountain View, CA")); | 610 EXPECT_TRUE(IsAddress("1600 Amphitheatre Parkway Mountain View, CA")); |
| 609 EXPECT_TRUE(IsAddress("201 S. Division St. Suite 500 Ann Arbor, MI")); | 611 EXPECT_TRUE(IsAddress("201 S. Division St. Suite 500 Ann Arbor, MI")); |
| 610 } | 612 } |
| OLD | NEW |