Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / android / shell / javatests / src / org / chromium / chrome / shell / ChromeShellUrlTest.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.shell;
6
7 import android.test.suitebuilder.annotation.SmallTest;
8
9 import org.chromium.base.ThreadUtils;
10 import org.chromium.base.test.util.Feature;
11 import org.chromium.content.browser.ContentViewCore;
12 import org.chromium.content.browser.ContentViewRenderView;
13 import org.chromium.ui.base.WindowAndroid;
14
15 import java.util.Locale;
16 import java.util.concurrent.atomic.AtomicBoolean;
17 import java.util.concurrent.atomic.AtomicReference;
18
19 /**
20  * Basic sanity test for loading urls in ChromeShell.
21  */
22 public class ChromeShellUrlTest extends ChromeShellTestBase {
23     // URL used for base tests.
24     private static final String URL = "data:text";
25
26     @SmallTest
27     @Feature({"Main"})
28     public void testBaseStartup() throws InterruptedException {
29         ChromeShellActivity activity = launchChromeShellWithUrl(URL);
30         waitForActiveShellToBeDoneLoading();
31
32         // Make sure the activity was created as expected.
33         assertNotNull(activity);
34     }
35
36     @SmallTest
37     @Feature({"Main"})
38     public void testChromeWelcomePageLoads() throws InterruptedException {
39         String welcomeUrl = "chrome://welcome/";
40         final ChromeShellActivity activity = launchChromeShellWithUrl(welcomeUrl);
41         waitForActiveShellToBeDoneLoading();
42
43         // Make sure the activity was created as expected.
44         assertNotNull(activity);
45
46         // Ensure we have a valid ContentViewCore.
47         final AtomicReference<ContentViewCore> contentViewCore =
48                 new AtomicReference<ContentViewCore>();
49         ThreadUtils.runOnUiThreadBlocking(new Runnable() {
50             @Override
51             public void run() {
52                 contentViewCore.set(activity.getActiveContentViewCore());
53             }
54         });
55         assertNotNull(contentViewCore.get());
56         assertNotNull(contentViewCore.get().getContainerView());
57
58         // Ensure the correct page has been loaded, ie. not interstitial, and title/url should
59         // be sane. Note, a typical correct title is: "Welcome to Chromium", whereas a wrong one
60         // would be on the form "chrome://welcome/ is not available".
61         final AtomicBoolean isShowingInterstitialPage = new AtomicBoolean();
62         final AtomicReference<String> url = new AtomicReference<String>();
63         final AtomicReference<String> title = new AtomicReference<String>();
64         ThreadUtils.runOnUiThreadBlocking(new Runnable() {
65             @Override
66             public void run() {
67                 isShowingInterstitialPage.set(contentViewCore.get().isShowingInterstitialPage());
68                 url.set(contentViewCore.get().getUrl());
69                 title.set(contentViewCore.get().getTitle());
70             }
71         });
72         assertFalse("Showed interstitial page instead of welcome page",
73                 isShowingInterstitialPage.get());
74         assertNotNull("URL was null", url.get());
75         assertTrue("URL did not contain: " + welcomeUrl + ". Was: " + url.get(),
76                 url.get().contains(welcomeUrl));
77         assertNotNull("Title was null", title.get());
78         assertFalse("Title should not contain: " + welcomeUrl + ". Was: " + title.get(),
79                 title.get().toLowerCase(Locale.US).contains(welcomeUrl));
80     }
81
82     /**
83      * Tests that creating an extra ContentViewRenderView does not cause an assert because we would
84      * initialize the compositor twice http://crbug.com/162312
85      */
86     @SmallTest
87     @Feature({"Main"})
88     public void testCompositorInit() throws InterruptedException {
89         // Start the ChromeShell, this loads the native library and create an instance of
90         // ContentViewRenderView.
91         final ChromeShellActivity activity = launchChromeShellWithUrl(URL);
92         waitForActiveShellToBeDoneLoading();
93
94         // Now create a new ContentViewRenderView, it should not assert.
95         try {
96             runTestOnUiThread(new Runnable() {
97                 @Override
98                 public void run() {
99                     WindowAndroid windowAndroid = new WindowAndroid(
100                             getInstrumentation().getTargetContext().getApplicationContext());
101                     ContentViewRenderView contentViewRenderView =
102                             new ContentViewRenderView(getInstrumentation().getTargetContext(),
103                                     windowAndroid);
104                     contentViewRenderView.setCurrentContentViewCore(
105                             activity.getActiveContentViewCore());
106                 }
107             });
108         } catch (Throwable e) {
109             e.printStackTrace();
110             fail("Could not create a ContentViewRenderView: " + e);
111         }
112     }
113 }