OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.chrome.browser.share; | 5 package org.chromium.chrome.browser.share; |
6 | 6 |
7 import android.content.Intent; | 7 import android.content.Intent; |
8 import android.test.suitebuilder.annotation.SmallTest; | 8 import android.test.suitebuilder.annotation.SmallTest; |
9 | 9 |
10 import org.chromium.chrome.shell.ChromeShellTestBase; | 10 import org.chromium.chrome.shell.ChromeShellTestBase; |
11 import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils; | 11 import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils; |
12 | 12 |
13 /** | 13 /** |
14 * Tests sharing URLs in reader mode (DOM distiller) | 14 * Tests sharing URLs in reader mode (DOM distiller) |
15 */ | 15 */ |
16 public class ShareUrlTest extends ChromeShellTestBase { | 16 public class ShareUrlTest extends ChromeShellTestBase { |
17 private static final String HTTP_URL = "http://www.google.com/"; | 17 private static final String HTTP_URL = "http://www.google.com/"; |
18 private static final String HTTPS_URL = "https://www.google.com/"; | 18 private static final String HTTPS_URL = "https://www.google.com/"; |
19 | 19 |
20 @Override | 20 @Override |
21 protected void setUp() throws Exception { | 21 protected void setUp() throws Exception { |
22 super.setUp(); | 22 super.setUp(); |
23 | 23 |
24 // load native methods in DomDistillerUrlUtils | 24 // load native methods in DomDistillerUrlUtils |
25 startChromeBrowserProcessSync(getInstrumentation().getTargetContext()); | 25 startChromeBrowserProcessSync(getInstrumentation().getTargetContext()); |
26 } | 26 } |
27 | 27 |
28 private void assertCorrectUrl(String originalUrl, String sharedUrl) { | 28 private void assertCorrectUrl(String originalUrl, String sharedUrl) { |
29 Intent intent = ShareHelper.getShareIntent("", sharedUrl, null); | 29 Intent intent = ShareHelper.getShareIntent( |
| 30 getInstrumentation().getTargetContext(), "", sharedUrl, null); |
30 assert (intent.hasExtra(Intent.EXTRA_TEXT)); | 31 assert (intent.hasExtra(Intent.EXTRA_TEXT)); |
31 String url = intent.getStringExtra(Intent.EXTRA_TEXT); | 32 String url = intent.getStringExtra(Intent.EXTRA_TEXT); |
32 assertEquals(originalUrl, url); | 33 assertEquals(originalUrl, url); |
33 } | 34 } |
34 | 35 |
35 @SmallTest | 36 @SmallTest |
36 public void testNormalUrl() { | 37 public void testNormalUrl() { |
37 assertCorrectUrl(HTTP_URL, HTTP_URL); | 38 assertCorrectUrl(HTTP_URL, HTTP_URL); |
38 assertCorrectUrl(HTTPS_URL, HTTPS_URL); | 39 assertCorrectUrl(HTTPS_URL, HTTPS_URL); |
39 } | 40 } |
40 | 41 |
41 @SmallTest | 42 @SmallTest |
42 public void testDistilledUrl() { | 43 public void testDistilledUrl() { |
43 final String DomDistillerScheme = "chrome-distiller"; | 44 final String DomDistillerScheme = "chrome-distiller"; |
44 String distilledHttpUrl = | 45 String distilledHttpUrl = |
45 DomDistillerUrlUtils.getDistillerViewUrlFromUrl(DomDistillerSche
me, HTTP_URL); | 46 DomDistillerUrlUtils.getDistillerViewUrlFromUrl(DomDistillerSche
me, HTTP_URL); |
46 String distilledHttpsUrl = | 47 String distilledHttpsUrl = |
47 DomDistillerUrlUtils.getDistillerViewUrlFromUrl(DomDistillerSche
me, HTTPS_URL); | 48 DomDistillerUrlUtils.getDistillerViewUrlFromUrl(DomDistillerSche
me, HTTPS_URL); |
48 | 49 |
49 assertCorrectUrl(HTTP_URL, distilledHttpUrl); | 50 assertCorrectUrl(HTTP_URL, distilledHttpUrl); |
50 assertCorrectUrl(HTTPS_URL, distilledHttpsUrl); | 51 assertCorrectUrl(HTTPS_URL, distilledHttpsUrl); |
51 } | 52 } |
52 } | 53 } |
OLD | NEW |