OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.support.test.filters.MediumTest; | 7 import android.support.test.filters.MediumTest; |
8 | 8 |
| 9 import org.junit.Assert; |
| 10 import org.junit.Rule; |
| 11 import org.junit.Test; |
| 12 import org.junit.runner.RunWith; |
| 13 |
| 14 import org.chromium.base.test.BaseJUnit4ClassRunner; |
9 import org.chromium.base.test.util.CommandLineFlags; | 15 import org.chromium.base.test.util.CommandLineFlags; |
10 import org.chromium.base.test.util.Feature; | 16 import org.chromium.base.test.util.Feature; |
11 import org.chromium.base.test.util.RetryOnFailure; | 17 import org.chromium.base.test.util.RetryOnFailure; |
12 import org.chromium.content.common.ContentSwitches; | 18 import org.chromium.content.common.ContentSwitches; |
13 | 19 |
14 /** | 20 /** |
15 * Test suite for email address detection. | 21 * Test suite for email address detection. |
16 */ | 22 */ |
| 23 @RunWith(BaseJUnit4ClassRunner.class) |
17 @CommandLineFlags.Add({ContentSwitches.ENABLE_CONTENT_INTENT_DETECTION}) | 24 @CommandLineFlags.Add({ContentSwitches.ENABLE_CONTENT_INTENT_DETECTION}) |
18 public class EmailAddressDetectionTest extends ContentDetectionTestBase { | 25 public class EmailAddressDetectionTest { |
| 26 @Rule |
| 27 public ContentDetectionActivityTestRule mActivityTestRule = |
| 28 new ContentDetectionActivityTestRule(); |
19 | 29 |
20 private static final String EMAIL_INTENT_PREFIX = "mailto:"; | 30 private static final String EMAIL_INTENT_PREFIX = "mailto:"; |
21 | 31 |
22 private boolean isExpectedEmailIntent(String intentUrl, String expectedConte
nt) { | 32 private boolean isExpectedEmailIntent(String intentUrl, String expectedConte
nt) { |
23 if (intentUrl == null) return false; | 33 if (intentUrl == null) return false; |
24 final String expectedUrl = EMAIL_INTENT_PREFIX + urlForContent(expectedC
ontent); | 34 final String expectedUrl = |
| 35 EMAIL_INTENT_PREFIX + mActivityTestRule.urlForContent(expectedCo
ntent); |
25 return intentUrl.equals(expectedUrl); | 36 return intentUrl.equals(expectedUrl); |
26 } | 37 } |
27 | 38 |
| 39 @Test |
28 @MediumTest | 40 @MediumTest |
29 @Feature({"ContentDetection", "TabContents"}) | 41 @Feature({"ContentDetection", "TabContents"}) |
30 @RetryOnFailure | 42 @RetryOnFailure |
31 public void testValidEmailAddresses() throws Throwable { | 43 public void testValidEmailAddresses() throws Throwable { |
32 startActivityWithTestUrl("content/test/data/android/content_detection/em
ail.html"); | 44 mActivityTestRule.launchContentShellWithUrlSync( |
| 45 "content/test/data/android/content_detection/email.html"); |
33 | 46 |
34 // valid_1: i.want.a.pony@chromium.org. | 47 // valid_1: i.want.a.pony@chromium.org. |
35 String intentUrl = scrollAndTapExpectingIntent("valid_1"); | 48 String intentUrl = mActivityTestRule.scrollAndTapExpectingIntent("valid_
1"); |
36 assertTrue(isExpectedEmailIntent(intentUrl, "i.want.a.pony@chromium.org"
)); | 49 Assert.assertTrue(isExpectedEmailIntent(intentUrl, "i.want.a.pony@chromi
um.org")); |
37 | 50 |
38 // valid_2: nyan_cat@chromium.org. | 51 // valid_2: nyan_cat@chromium.org. |
39 intentUrl = scrollAndTapExpectingIntent("valid_2"); | 52 intentUrl = mActivityTestRule.scrollAndTapExpectingIntent("valid_2"); |
40 assertTrue(isExpectedEmailIntent(intentUrl, "nyan_cat@chromium.org")); | 53 Assert.assertTrue(isExpectedEmailIntent(intentUrl, "nyan_cat@chromium.or
g")); |
41 | 54 |
42 // valid_3: 123@456.com. | 55 // valid_3: 123@456.com. |
43 intentUrl = scrollAndTapExpectingIntent("valid_3"); | 56 intentUrl = mActivityTestRule.scrollAndTapExpectingIntent("valid_3"); |
44 assertTrue(isExpectedEmailIntent(intentUrl, "123@456.com")); | 57 Assert.assertTrue(isExpectedEmailIntent(intentUrl, "123@456.com")); |
45 } | 58 } |
46 } | 59 } |
OLD | NEW |