AddressDetectionTest.java revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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
3// found in the LICENSE file.
4
5package org.chromium.content.browser;
6
7import android.test.suitebuilder.annotation.MediumTest;
8
9import org.chromium.base.test.util.Feature;
10
11/**
12 * Test suite for geographical US address detection.
13 */
14public class AddressDetectionTest extends ContentDetectionTestBase {
15
16    private static final String GEO_INTENT_PREFIX = "geo:0,0?q=";
17
18    private boolean isExpectedGeoIntent(String intentUrl, String expectedContent) {
19        if (intentUrl == null) return false;
20        final String expectedUrl = GEO_INTENT_PREFIX + urlForContent(expectedContent);
21        return intentUrl.equals(expectedUrl);
22    }
23
24    @MediumTest
25    @Feature({"ContentDetection", "TabContents"})
26    public void testMultipleAddressesInText() throws Throwable {
27        startActivityWithTestUrl("content/content_detection/geo_address_multiple.html");
28        assertWaitForPageScaleFactorMatch(1.0f);
29
30        assertTrue(isExpectedGeoIntent(scrollAndTapExpectingIntent("test1"),
31                "1600 Amphitheatre Parkway Mountain View, CA 94043"));
32
33        assertTrue(isExpectedGeoIntent(scrollAndTapExpectingIntent("test2"),
34                "76 Ninth Avenue 4th Floor New York, NY 10011"));
35    }
36
37    @MediumTest
38    @Feature({"ContentDetection", "TabContents"})
39    public void testSplitAddresses() throws Throwable {
40        startActivityWithTestUrl("content/content_detection/geo_address_split.html");
41        assertWaitForPageScaleFactorMatch(1.0f);
42
43        assertTrue(isExpectedGeoIntent(scrollAndTapExpectingIntent("test1"),
44                "9606 North MoPac Expressway Suite 400 Austin, TX 78759"));
45
46        assertTrue(isExpectedGeoIntent(scrollAndTapExpectingIntent("test2"),
47                "1818 Library Street Suite 400, VA 20190"));
48
49        assertTrue(isExpectedGeoIntent(scrollAndTapExpectingIntent("test3"),
50                "1818 Library Street Suite 400, VA 20190"));
51
52        assertTrue(isExpectedGeoIntent(scrollAndTapExpectingIntent("test4"),
53                "1818 Library Street Suite 400, VA 20190"));
54    }
55
56    @MediumTest
57    @Feature({"ContentDetection", "TabContents"})
58    public void testAddressLimits() throws Throwable {
59        startActivityWithTestUrl("content/content_detection/geo_address_limits.html");
60        assertWaitForPageScaleFactorMatch(1.0f);
61
62        assertTrue(isExpectedGeoIntent(scrollAndTapExpectingIntent("test1"),
63                "2590 Pearl Street Suite 100 Boulder, CO 80302"));
64
65        assertTrue(isExpectedGeoIntent(scrollAndTapExpectingIntent("test2"),
66                "6425 Penn Ave. Suite 700 Pittsburgh, PA 15206"));
67
68        assertTrue(isExpectedGeoIntent(scrollAndTapExpectingIntent("test3"),
69                "34 Main St. Boston, MA 02118"));
70
71        assertTrue(isExpectedGeoIntent(scrollAndTapExpectingIntent("test4"),
72                "1600 Amphitheatre Parkway Mountain View, CA 94043"));
73    }
74
75    @MediumTest
76    @Feature({"ContentDetection", "TabContents"})
77    public void testRealAddresses() throws Throwable {
78        startActivityWithTestUrl("content/content_detection/geo_address_real.html");
79        assertWaitForPageScaleFactorMatch(1.0f);
80
81        assertTrue(isExpectedGeoIntent(scrollAndTapExpectingIntent("test1"),
82                "57th Street and Lake Shore Drive Chicago, IL 60637"));
83
84        assertTrue(isExpectedGeoIntent(scrollAndTapExpectingIntent("test2"),
85                "57th Street and Lake Shore Drive Chicago, IL 60637"));
86
87        assertTrue(isExpectedGeoIntent(scrollAndTapExpectingIntent("test3"),
88                "57th Street and Lake Shore Drive Chicago, IL 60637"));
89
90        assertTrue(isExpectedGeoIntent(scrollAndTapExpectingIntent("test4"),
91                "79th Street, New York, NY, 10024-5192"));
92    }
93
94    @MediumTest
95    @Feature({"ContentDetection", "TabContents"})
96    public void testSpecialChars() throws Throwable {
97        startActivityWithTestUrl("content/content_detection/geo_address_special_chars.html");
98        assertWaitForPageScaleFactorMatch(1.0f);
99
100        assertTrue(isExpectedGeoIntent(scrollAndTapExpectingIntent("test1"),
101                "100 34th Avenue , San Francisco, CA 94121"));
102
103        assertTrue(isExpectedGeoIntent(scrollAndTapExpectingIntent("test2"),
104                "100 34th Avenue San Francisco, CA 94121"));
105    }
106}
107