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