Commit 6db6ead4 authored by Ian Vollick's avatar Ian Vollick Committed by Commit Bot

Fix NoTouchActivityTest errors

Dino tests have been moved to a separate DinoActivityTest.
I've also disabled the currently broken safe browsing test.
See crbug.com/947232

Bug: 968239
Change-Id: I546a464580a6b0d13fe9d568572486ab89ea62db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1634426
Commit-Queue: Ian Vollick <vollick@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664515}
parent 9b201f90
// Copyright 2019 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.browser.touchless;
import android.content.Intent;
import android.net.Uri;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.EmbeddedTestServer;
/**
* Tests for DinoActivity.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public class DinoActivityTest {
@Rule
public ChromeActivityTestRule<DinoActivity> mActivityTestRule =
new ChromeActivityTestRule<>(DinoActivity.class);
private EmbeddedTestServer mTestServer;
private DinoActivity mActivity;
@Before
public void setUp() throws InterruptedException {
mTestServer = EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext());
}
@After
public void tearDown() {
mTestServer.stopAndDestroyServer();
}
/**
* Tests that the Dino game is launchable.
*/
@Test
@MediumTest
public void testDinoGameIsLaunchable() throws Throwable {
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setClassName(InstrumentationRegistry.getTargetContext().getPackageName(),
NoTouchActivity.DINOSAUR_GAME_INTENT);
mActivityTestRule.startMainActivityFromIntent(i, null);
mActivity = mActivityTestRule.getActivity();
Assert.assertFalse(mActivity.getActivityTab().isNativePage());
TestThreadUtils.runOnUiThreadBlocking(() -> {
Assert.assertEquals("chrome://dino/",
mActivity.getActivityTab().getWebContents().getLastCommittedUrl());
});
}
/**
* Tests that the Dino ACTION but with different URL loads dino.
*/
@Test
@MediumTest
public void testDinoGameOnlyLoadsDino() throws Throwable {
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setClassName(InstrumentationRegistry.getTargetContext().getPackageName(),
NoTouchActivity.DINOSAUR_GAME_INTENT);
i.setData(Uri.parse("https://www.google.com"));
mActivityTestRule.startMainActivityFromIntent(i, null);
mActivity = mActivityTestRule.getActivity();
Assert.assertFalse(mActivity.getActivityTab().isNativePage());
TestThreadUtils.runOnUiThreadBlocking(() -> {
Assert.assertEquals("chrome://dino/",
mActivity.getActivityTab().getWebContents().getLastCommittedUrl());
});
}
}
...@@ -6,8 +6,6 @@ package org.chromium.chrome.browser.touchless; ...@@ -6,8 +6,6 @@ package org.chromium.chrome.browser.touchless;
import static org.chromium.chrome.browser.ChromeInactivityTracker.NTP_LAUNCH_DELAY_IN_MINS_PARAM; import static org.chromium.chrome.browser.ChromeInactivityTracker.NTP_LAUNCH_DELAY_IN_MINS_PARAM;
import android.content.Intent;
import android.net.Uri;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
...@@ -19,6 +17,7 @@ import org.junit.Test; ...@@ -19,6 +17,7 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.chrome.browser.ChromeInactivityTracker; import org.chromium.chrome.browser.ChromeInactivityTracker;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.MockSafeBrowsingApiHandler; import org.chromium.chrome.browser.MockSafeBrowsingApiHandler;
...@@ -70,47 +69,6 @@ public class NoTouchActivityTest { ...@@ -70,47 +69,6 @@ public class NoTouchActivityTest {
mActivity.getActivityTab().getNativePage() instanceof TouchlessNewTabPage); mActivity.getActivityTab().getNativePage() instanceof TouchlessNewTabPage);
} }
/**
* Tests that the Dino game is launchable.
*/
@Test
@MediumTest
public void testDinoGameIsLaunchable() throws Throwable {
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setClassName(InstrumentationRegistry.getTargetContext().getPackageName(),
NoTouchActivity.DINOSAUR_GAME_INTENT);
mActivityTestRule.startMainActivityFromIntent(i, null);
mActivity = mActivityTestRule.getActivity();
Assert.assertFalse(mActivity.getActivityTab().isNativePage());
TestThreadUtils.runOnUiThreadBlocking(() -> {
Assert.assertEquals("chrome://dino/",
mActivity.getActivityTab().getWebContents().getLastCommittedUrl());
});
}
/**
* Tests that the Dino ACTION but with different URL loads dino.
*/
@Test
@MediumTest
public void testDinoGameOnlyLoadsDino() throws Throwable {
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setClassName(InstrumentationRegistry.getTargetContext().getPackageName(),
NoTouchActivity.DINOSAUR_GAME_INTENT);
i.setData(Uri.parse("https://www.google.com"));
mActivityTestRule.startMainActivityFromIntent(i, null);
mActivity = mActivityTestRule.getActivity();
Assert.assertFalse(mActivity.getActivityTab().isNativePage());
TestThreadUtils.runOnUiThreadBlocking(() -> {
Assert.assertEquals("chrome://dino/",
mActivity.getActivityTab().getWebContents().getLastCommittedUrl());
});
}
/** /**
* Tests that the Tab persists through recreation. * Tests that the Tab persists through recreation.
*/ */
...@@ -196,7 +154,7 @@ public class NoTouchActivityTest { ...@@ -196,7 +154,7 @@ public class NoTouchActivityTest {
* Tests that Safe Browsing and interstitials work. * Tests that Safe Browsing and interstitials work.
*/ */
@Test @Test
@MediumTest @DisabledTest(message = "crbug.com/947232")
public void testSafeBrowsing() throws Throwable { public void testSafeBrowsing() throws Throwable {
mActivityTestRule.startMainActivityFromLauncher(); mActivityTestRule.startMainActivityFromLauncher();
mActivity = mActivityTestRule.getActivity(); mActivity = mActivityTestRule.getActivity();
......
...@@ -65,6 +65,7 @@ touchless_java_sources = [ ...@@ -65,6 +65,7 @@ touchless_java_sources = [
] ]
touchless_test_java_sources = [ touchless_test_java_sources = [
"touchless/javatests/src/org/chromium/chrome/browser/touchless/DinoActivityTest.java",
"touchless/javatests/src/org/chromium/chrome/browser/touchless/NoTouchActivityTest.java", "touchless/javatests/src/org/chromium/chrome/browser/touchless/NoTouchActivityTest.java",
"touchless/javatests/src/org/chromium/chrome/browser/touchless/TouchlessNavigationRecorderTest.java", "touchless/javatests/src/org/chromium/chrome/browser/touchless/TouchlessNavigationRecorderTest.java",
"touchless/javatests/src/org/chromium/chrome/browser/touchless/TouchlessNewTabPageMediatorTest.java", "touchless/javatests/src/org/chromium/chrome/browser/touchless/TouchlessNewTabPageMediatorTest.java",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment