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