c3e32d805e83a350963118b4db8c9ad4014c9e4f
[platform/framework/web/crosswalk.git] / src / xwalk / test / android / core / javatests / src / org / xwalk / core / xwview / test / LoadTest.java
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Copyright (c) 2014 Intel Corporation. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 package org.xwalk.core.xwview.test;
7
8 import android.test.suitebuilder.annotation.SmallTest;
9
10 import org.chromium.base.test.util.DisabledTest;
11 import org.chromium.base.test.util.Feature;
12
13 /**
14  * Test suite for load().
15  */
16 public class LoadTest extends XWalkViewTestBase {
17     final String expectedTitle = "The WebKit Open Source Project";
18     final String expectedLocalTitle = "Crosswalk Sample Application";
19
20     @Override
21     public void setUp() throws Exception {
22         super.setUp();
23
24         setXWalkClient(new XWalkViewTestBase.TestXWalkClient());
25     }
26
27     // TODO(hengzhi): Since the device issue, it can not access the network,
28     // so disabled this test temporarily. It will be enabled later.
29     // @SmallTest
30     // @Feature({"Load"})
31     @DisabledTest
32     public void testHttpUrl() throws Throwable {
33         final String url = "http://www.webkit.org/";
34
35         loadUrlSync(url);
36         assertEquals(expectedTitle, getTitleOnUiThread());
37     }
38
39     // TODO(hengzhi): Since the device issue, it can not access the network,
40     // so disabled this test temporarily. It will be enabled later.
41     // @SmallTest
42     // @Feature({"Load"})
43     @DisabledTest
44     public void testHttpsUrl() throws Throwable {
45         final String url = "https://www.webkit.org/";
46
47         loadUrlSync(url);
48         assertEquals(expectedTitle, getTitleOnUiThread());
49     }
50
51     @SmallTest
52     @Feature({"Load"})
53     public void testAndroidAssetUrl() throws Throwable {
54         final String url = "file:///android_asset/www/index.html";
55
56         loadUrlSync(url);
57         assertEquals(expectedLocalTitle, getTitleOnUiThread());
58     }
59
60     @SmallTest
61     @Feature({"LoadWithData"})
62     public void testWithData() throws Throwable {
63         final String name = "index.html";
64         String fileContent = getFileContent(name);
65
66         loadDataSync(null, fileContent, "text/html", false);
67         assertEquals(expectedLocalTitle, getTitleOnUiThread());
68
69         loadDataSync(name, fileContent, "text/html", false);
70         assertEquals(expectedLocalTitle, getTitleOnUiThread());
71     }
72
73     @SmallTest
74     @Feature({"ContentScheme"})
75     public void testContentUrl() throws Throwable {
76         final String resource = "content_test";
77         final String contentUrl = TestContentProvider.createContentUrl(resource);
78
79         int count =
80                 TestContentProvider.getResourceRequestCount(getActivity(), resource);
81         loadUrlSync(contentUrl);
82         assertEquals(count + 1,
83                 TestContentProvider.getResourceRequestCount(getActivity(), resource));
84     }
85
86     @SmallTest
87     @Feature({"Load"})
88     public void testEmpytUrlAndContent() throws Throwable {
89         loadDataAsync(null, null, "text/html", false);
90         Thread.sleep(1000);
91         assertNotNull(getTitleOnUiThread());
92     }
93 }