Commit c70f2bb7 authored by Mathias Carlen's avatar Mathias Carlen Committed by Commit Bot

[AA Direct Actions] Fix flaky direct action test.

Before this patch, three different activity types were tested in the
same test. That resulted in the activities to interfere with one
another. This patch splits the tests up into one test file per
activity.

R=szermatt@chromium.org

Bug: 1018183
Change-Id: Ie09202e9ac69e96ac207ffe3f43b4e00e592d343
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1910088Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarStephane Zermatten <szermatt@chromium.org>
Commit-Queue: Mathias Carlen <mcarlen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714497}
parent cb19c20d
......@@ -91,7 +91,9 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/device_dialog/ItemChooserDialogTest.java",
"javatests/src/org/chromium/chrome/browser/device_dialog/UsbChooserDialogTest.java",
"javatests/src/org/chromium/chrome/browser/directactions/CloseTabDirectActionHandlerTest.java",
"javatests/src/org/chromium/chrome/browser/directactions/DirectActionAvailabilityTest.java",
"javatests/src/org/chromium/chrome/browser/directactions/DirectActionAvailabilityCustomTabTest.java",
"javatests/src/org/chromium/chrome/browser/directactions/DirectActionAvailabilityTabbedTest.java",
"javatests/src/org/chromium/chrome/browser/directactions/DirectActionAvailabilityWebappTest.java",
"javatests/src/org/chromium/chrome/browser/directactions/DirectActionTestRule.java",
"javatests/src/org/chromium/chrome/browser/directactions/DirectActionTestUtils.java",
"javatests/src/org/chromium/chrome/browser/directactions/DirectActionsInActivityTest.java",
......
......@@ -4,7 +4,6 @@
package org.chromium.chrome.browser.directactions;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import android.annotation.TargetApi;
import android.content.Intent;
......@@ -18,7 +17,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.chrome.browser.ChromeActivity;
......@@ -26,16 +24,8 @@ import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.customtabs.CustomTabActivityTestRule;
import org.chromium.chrome.browser.customtabs.CustomTabsTestUtils;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.webapps.WebappActivityTestRule;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.browser.Features.DisableFeatures;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import java.util.List;
/**
* Tests the availability of core direct actions in different activities.
......@@ -48,32 +38,13 @@ import java.util.List;
@DisableFeatures(ChromeFeatureList.AUTOFILL_ASSISTANT_DIRECT_ACTIONS)
@MinAndroidSdkLevel(Build.VERSION_CODES.N)
@TargetApi(24) // For java.util.function.Consumer.
public class DirectActionAvailabilityTest {
@Rule
public ChromeTabbedActivityTestRule mTabbedActivityTestRule =
new ChromeTabbedActivityTestRule();
public class DirectActionAvailabilityCustomTabTest {
@Rule
public CustomTabActivityTestRule mCustomTabActivityTestRule = new CustomTabActivityTestRule();
@Rule
public WebappActivityTestRule mWebAppActivityTestRule = new WebappActivityTestRule();
@Rule
public DirectActionTestRule mDirectActionRule = new DirectActionTestRule();
@Test
@MediumTest
@Feature({"DirectActions"})
public void testCoreDirectActionInTabbedActivity() throws Exception {
mTabbedActivityTestRule.startMainActivityOnBlankPage();
assertThat(setupActivityAndGetDirectAction(mTabbedActivityTestRule),
Matchers.containsInAnyOrder("go_back", "reload", "go_forward", "bookmark_this_page",
"downloads", "preferences", "open_history", "help", "new_tab", "close_tab",
"close_all_tabs"));
}
@Test
@MediumTest
@Feature({"DirectActions"})
......@@ -82,49 +53,9 @@ public class DirectActionAvailabilityTest {
InstrumentationRegistry.getTargetContext(), "about:blank");
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(intent);
assertThat(setupActivityAndGetDirectAction(mCustomTabActivityTestRule),
assertThat(
DirectActionTestUtils.setupActivityAndGetDirectAction(mCustomTabActivityTestRule),
Matchers.containsInAnyOrder(
"go_back", "reload", "go_forward", "bookmark_this_page", "preferences"));
}
@Test
@MediumTest
@Feature({"DirectActions"})
@DisabledTest(message = "https://crbug.com/1018183")
public void testCoreDirectActionInWebappActivity() throws Exception {
mWebAppActivityTestRule.startWebappActivity();
assertThat(setupActivityAndGetDirectAction(mWebAppActivityTestRule),
Matchers.containsInAnyOrder("go_back", "reload", "go_forward"));
}
private List<String> setupActivityAndGetDirectAction(ChromeActivityTestRule<?> rule)
throws Exception {
allowGoForward(rule);
return DirectActionTestUtils.callOnGetDirectActions(rule.getActivity());
}
/**
* Forces availability of the "go_forward" direct action on the current tab by loading another
* URL then navigating back to the current one.
*
* <p>The activity of the given rule must have been started and have loaded a page.
*/
public static void allowGoForward(ChromeActivityTestRule<?> rule) throws Exception {
ChromeActivity activity = rule.getActivity();
String initialUrl = TestThreadUtils.runOnUiThreadBlocking(
() -> activity.getCurrentWebContents().getLastCommittedUrl());
// Any built-in page that is not about:blank and is reasonably cheap to render will do,
// here.
String visitedUrl = "chrome://version/";
assertThat(initialUrl, Matchers.not(Matchers.equalTo(visitedUrl)));
rule.loadUrl(visitedUrl);
Tab tab = activity.getTabModelSelector().getCurrentTab();
TestThreadUtils.runOnUiThreadBlocking(
() -> activity.getCurrentWebContents().getNavigationController().goBack());
ChromeTabUtils.waitForTabPageLoaded(tab, initialUrl);
assertTrue(tab.canGoForward());
}
}
// 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.directactions;
import static org.junit.Assert.assertThat;
import android.annotation.TargetApi;
import android.os.Build;
import android.support.test.filters.MediumTest;
import org.hamcrest.Matchers;
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.base.test.util.Feature;
import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.browser.Features.DisableFeatures;
/**
* Tests the availability of core direct actions in different activities.
*
* <p>This tests both {@link DirectActionInitializer} and its integration with {@link
* ChromeActivity} and its different subclasses.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@DisableFeatures(ChromeFeatureList.AUTOFILL_ASSISTANT_DIRECT_ACTIONS)
@MinAndroidSdkLevel(Build.VERSION_CODES.N)
@TargetApi(24) // For java.util.function.Consumer.
public class DirectActionAvailabilityTabbedTest {
@Rule
public ChromeTabbedActivityTestRule mTabbedActivityTestRule =
new ChromeTabbedActivityTestRule();
@Rule
public DirectActionTestRule mDirectActionRule = new DirectActionTestRule();
@Before
public void setUp() throws Exception {
// Using OnBlank times out when waiting for NTP. Using null makes the test work.
mTabbedActivityTestRule.startMainActivityWithURL(null);
}
@Test
@MediumTest
@RetryOnFailure
@Feature({"DirectActions"})
public void testCoreDirectActionInTabbedActivity() throws Exception {
assertThat(DirectActionTestUtils.setupActivityAndGetDirectAction(mTabbedActivityTestRule),
Matchers.containsInAnyOrder("go_back", "reload", "go_forward", "bookmark_this_page",
"downloads", "preferences", "open_history", "help", "new_tab", "close_tab",
"close_all_tabs"));
}
}
// 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.directactions;
import static org.junit.Assert.assertThat;
import android.annotation.TargetApi;
import android.os.Build;
import android.support.test.filters.MediumTest;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.webapps.WebappActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.Features.DisableFeatures;
/**
* Tests the availability of core direct actions in different activities.
*
* <p>This tests both {@link DirectActionInitializer} and its integration with {@link
* ChromeActivity} and its different subclasses.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@DisableFeatures(ChromeFeatureList.AUTOFILL_ASSISTANT_DIRECT_ACTIONS)
@MinAndroidSdkLevel(Build.VERSION_CODES.N)
@TargetApi(24) // For java.util.function.Consumer.
public class DirectActionAvailabilityWebappTest {
@Rule
public WebappActivityTestRule mWebAppActivityTestRule = new WebappActivityTestRule();
@Rule
public DirectActionTestRule mDirectActionRule = new DirectActionTestRule();
@Test
@MediumTest
@Feature({"DirectActions"})
public void testCoreDirectActionInWebappActivity() throws Exception {
mWebAppActivityTestRule.startWebappActivity();
assertThat(DirectActionTestUtils.setupActivityAndGetDirectAction(mWebAppActivityTestRule),
Matchers.containsInAnyOrder("go_back", "reload", "go_forward"));
}
}
......@@ -4,11 +4,19 @@
package org.chromium.chrome.browser.directactions;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import android.os.Bundle;
import android.os.CancellationSignal;
import org.hamcrest.Matchers;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import java.util.ArrayList;
......@@ -17,7 +25,7 @@ import java.util.List;
/**
* Utilities for writing tests that check for or perform direct actions on an activity.
*/
public class DirectActionTestUtils {
class DirectActionTestUtils {
/** Perform a direct action, with the given name. */
public static void callOnPerformDirectActions(
ChromeActivity activity, String actionId, Callback<Bundle> callback) {
......@@ -43,6 +51,41 @@ public class DirectActionTestUtils {
return directActions;
}
/**
* Sets the ChromeActivityTestRule by forcing "go_forward" to be available.
*
* <p>The activity of the given rule must have been started and have loaded a page.
*/
static List<String> setupActivityAndGetDirectAction(ChromeActivityTestRule<?> rule)
throws Exception {
allowGoForward(rule);
return callOnGetDirectActions(rule.getActivity());
}
/**
* Forces availability of the "go_forward" direct action on the current tab by loading another
* URL then navigating back to the current one.
*
* <p>The activity of the given rule must have been started and have loaded a page.
*/
static void allowGoForward(ChromeActivityTestRule<?> rule) throws Exception {
ChromeActivity activity = rule.getActivity();
String initialUrl = TestThreadUtils.runOnUiThreadBlocking(
() -> activity.getCurrentWebContents().getLastCommittedUrl());
// Any built-in page that is not about:blank and is reasonably cheap to render will do,
// here.
String visitedUrl = "chrome://version/";
assertThat(initialUrl, Matchers.not(Matchers.equalTo(visitedUrl)));
rule.loadUrl(visitedUrl);
Tab tab = activity.getTabModelSelector().getCurrentTab();
TestThreadUtils.runOnUiThreadBlocking(
() -> activity.getCurrentWebContents().getNavigationController().goBack());
ChromeTabUtils.waitForTabPageLoaded(tab, initialUrl);
assertTrue(tab.canGoForward());
}
private DirectActionTestUtils() {
// This is a utility class; it is not meant to be instantiated.
}
......
file://components/autofill_assistant/OWNERS
\ No newline at end of file
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