// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.chrome.testshell;

import android.test.suitebuilder.annotation.SmallTest;

import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.ContentViewRenderView;

public class ChromiumTestShellUrlTest extends ChromiumTestShellTestBase {
    // URL used for base tests.
    private static final String URL = "data:text";

    @SmallTest
    @Feature({"Main"})
    public void testBaseStartup() throws Exception {
        ChromiumTestShellActivity activity = launchChromiumTestShellWithUrl(URL);
        waitForActiveShellToBeDoneLoading();

        // Make sure the activity was created as expected.
        assertNotNull(activity);
    }

    /**
     * Tests that creating an extra ContentViewRenderView does not cause an assert because we would
     * initialize the compositor twice http://crbug.com/162312
     */
    @SmallTest
    @Feature({"Main"})
    public void testCompositorInit() throws Exception {
        // Start the ChromiumTestShell, this loads the native library and create an instance of
        // ContentViewRenderView.
        final ChromiumTestShellActivity activity = launchChromiumTestShellWithUrl(URL);
        waitForActiveShellToBeDoneLoading();

        // Now create a new ContentViewRenderView, it should not assert.
        try {
            runTestOnUiThread(new Runnable() {
                @Override
                public void run() {
                    ContentViewRenderView contentViewRenderView =
                            new ContentViewRenderView(getInstrumentation().getTargetContext());
                    contentViewRenderView.setCurrentContentView(activity.getActiveContentView());
                }
            });
        } catch (Throwable e) {
            fail("Could not create a ContentViewRenderView: " + e);
        }
    }
}
@@ -259,16 +259,54 @@
 lTest;%0A%0A
+import org.chromium.base.ThreadUtils;%0A
 import o
@@ -388,26 +388,231 @@
 tentView
-RenderView
+;%0Aimport org.chromium.content.browser.ContentViewCore;%0Aimport org.chromium.content.browser.ContentViewRenderView;%0A%0Aimport java.util.concurrent.atomic.AtomicBoolean;%0Aimport java.util.concurrent.atomic.AtomicReference
 ;%0A%0Apubli
@@ -835,32 +835,43 @@
 tartup() throws 
+Interrupted
 Exception %7B%0A    
@@ -1093,16 +1093,2559 @@
 %0A    %7D%0A%0A
+    @SmallTest%0A    @Feature(%7B%22Main%22%7D)%0A    public void testChromeWelcomePageLoads() throws InterruptedException %7B%0A        String welcomeUrl = %22chrome://welcome/%22;%0A        final ChromiumTestShellActivity activity = launchChromiumTestShellWithUrl(welcomeUrl);%0A        waitForActiveShellToBeDoneLoading();%0A%0A        // Make sure the activity was created as expected.%0A        assertNotNull(activity);%0A%0A        // Ensure we have a ContentView and ContentViewCore.%0A        final AtomicReference%3CContentView%3E contentView = new AtomicReference%3CContentView%3E();%0A        final AtomicReference%3CContentViewCore%3E contentViewCore =%0A                new AtomicReference%3CContentViewCore%3E();%0A        ThreadUtils.runOnUiThreadBlocking(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                ContentView activeContentView = activity.getActiveContentView();%0A                contentView.set(activeContentView);%0A                if (activeContentView != null) %7B%0A                    contentViewCore.set(activeContentView.getContentViewCore());%0A                %7D%0A            %7D%0A        %7D);%0A        assertNotNull(contentView.get());%0A        assertNotNull(contentViewCore.get());%0A%0A        // Ensure the correct page has been loaded, ie. not interstitial, and title/url should%0A        // be sane. Note, a typical correct title is: %22Welcome to Chromium%22, whereas a wrong one%0A        // would be on the form %22chrome://welcome/ is not available%22.%0A        final AtomicBoolean isShowingInterstitialPage = new AtomicBoolean();%0A        final AtomicReference%3CString%3E url = new AtomicReference%3CString%3E();%0A        final AtomicReference%3CString%3E title = new AtomicReference%3CString%3E();%0A        ThreadUtils.runOnUiThreadBlocking(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                isShowingInterstitialPage.set(contentViewCore.get().isShowingInterstitialPage());%0A                url.set(contentViewCore.get().getUrl());%0A                title.set(contentViewCore.get().getTitle());%0A            %7D%0A        %7D);%0A        assertFalse(%22Showed interstitial page instead of welcome page%22,%0A                isShowingInterstitialPage.get());%0A        assertNotNull(%22URL was null%22, url.get());%0A        assertTrue(%22URL did not contain: %22 + welcomeUrl + %22. Was: %22 + url.get(),%0A                url.get().contains(welcomeUrl));%0A        assertNotNull(%22Title was null%22, title.get());%0A        assertFalse(%22Title should not contain: %22 + welcomeUrl + %22. Was: %22 + title.get(),%0A                title.get().toLowerCase().contains(welcomeUrl));%0A    %7D%0A%0A
     /**%0A
@@ -3897,16 +3897,27 @@
  throws 
+Interrupted
 Exceptio

Add test to ensure Chrome welcome page loads on Android.