| Index: chrome/android/javatests/src/org/chromium/chrome/browser/WebShareTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/WebShareTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/WebShareTest.java
|
| index eac5d19bd920587b5b8d2bd72b0b6de3feb386a6..341dfd4966ad03791af4790f5203e37bd37b728e 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/WebShareTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/WebShareTest.java
|
| @@ -7,16 +7,8 @@
|
| import android.content.Context;
|
| import android.content.Intent;
|
| import android.os.Build;
|
| -import android.support.test.InstrumentationRegistry;
|
| import android.support.test.filters.MediumTest;
|
| import android.support.v7.app.AlertDialog;
|
| -
|
| -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.CallbackHelper;
|
| import org.chromium.base.test.util.CommandLineFlags;
|
| @@ -24,20 +16,11 @@
|
| import org.chromium.chrome.browser.share.ShareHelper;
|
| import org.chromium.chrome.browser.tab.EmptyTabObserver;
|
| import org.chromium.chrome.browser.tab.Tab;
|
| -import org.chromium.chrome.test.ChromeActivityTestRule;
|
| -import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
| -import org.chromium.content.browser.test.util.TouchCommon;
|
| +import org.chromium.chrome.test.ChromeActivityTestCaseBase;
|
| import org.chromium.net.test.EmbeddedTestServer;
|
|
|
| /** Test suite for Web Share (navigator.share) functionality. */
|
| -@RunWith(ChromeJUnit4ClassRunner.class)
|
| -@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
|
| - ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
|
| -public class WebShareTest {
|
| - @Rule
|
| - public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
|
| - new ChromeActivityTestRule<>(ChromeActivity.class);
|
| -
|
| +public class WebShareTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| private static final String TEST_FILE = "/content/test/data/android/webshare.html";
|
|
|
| private EmbeddedTestServer mTestServer;
|
| @@ -60,7 +43,7 @@
|
|
|
| @Override
|
| public void onTitleUpdated(Tab tab) {
|
| - String title = mActivityTestRule.getActivity().getActivityTab().getTitle();
|
| + String title = getActivity().getActivityTab().getTitle();
|
| // Wait until the title indicates either success or failure.
|
| if (!title.equals("Success") && !title.startsWith("Fail:")) return;
|
| mStatus = title;
|
| @@ -73,24 +56,27 @@
|
| }
|
| }
|
|
|
| - @Before
|
| - public void setUp() throws Exception {
|
| - mActivityTestRule.startMainActivityOnBlankPage();
|
| -
|
| - mTestServer = EmbeddedTestServer.createAndStartServer(
|
| - InstrumentationRegistry.getInstrumentation().getContext());
|
| + public WebShareTest() {
|
| + super(ChromeActivity.class);
|
| + }
|
| +
|
| + @Override
|
| + protected void setUp() throws Exception {
|
| + super.setUp();
|
| +
|
| + mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
|
|
|
| mUrl = mTestServer.getURL(TEST_FILE);
|
|
|
| - mTab = mActivityTestRule.getActivity().getActivityTab();
|
| + mTab = getActivity().getActivityTab();
|
| mUpdateWaiter = new WebShareUpdateWaiter();
|
| mTab.addObserver(mUpdateWaiter);
|
|
|
| mReceivedIntent = null;
|
| }
|
|
|
| - @After
|
| - public void tearDown() throws Exception {
|
| + @Override
|
| + protected void tearDown() throws Exception {
|
| mTab.removeObserver(mUpdateWaiter);
|
| mTestServer.stopAndDestroyServer();
|
|
|
| @@ -98,33 +84,32 @@
|
| ShareHelper.setForceCustomChooserForTesting(false);
|
| ShareHelper.setFakeIntentReceiverForTesting(null);
|
|
|
| + super.tearDown();
|
| }
|
|
|
| /**
|
| * Verify that WebShare is missing by default (without a flag).
|
| * @throws Exception
|
| */
|
| - @Test
|
| @MediumTest
|
| @Feature({"WebShare"})
|
| public void testWebShareMissingWithoutFlag() throws Exception {
|
| - mActivityTestRule.loadUrl(mUrl);
|
| - mActivityTestRule.runJavaScriptCodeInCurrentTab("initiate_share()");
|
| - Assert.assertEquals("Fail: navigator.share === undefined", mUpdateWaiter.waitForUpdate());
|
| + loadUrl(mUrl);
|
| + runJavaScriptCodeInCurrentTab("initiate_share()");
|
| + assertEquals("Fail: navigator.share === undefined", mUpdateWaiter.waitForUpdate());
|
| }
|
|
|
| /**
|
| * Verify that WebShare fails if called without a user gesture.
|
| * @throws Exception
|
| */
|
| - @Test
|
| @MediumTest
|
| @CommandLineFlags.Add("enable-blink-features=WebShare")
|
| @Feature({"WebShare"})
|
| public void testWebShareNoUserGesture() throws Exception {
|
| - mActivityTestRule.loadUrl(mUrl);
|
| - mActivityTestRule.runJavaScriptCodeInCurrentTab("initiate_share()");
|
| - Assert.assertEquals(
|
| + loadUrl(mUrl);
|
| + runJavaScriptCodeInCurrentTab("initiate_share()");
|
| + assertEquals(
|
| "Fail: SecurityError: Must be handling a user gesture to perform a share request.",
|
| mUpdateWaiter.waitForUpdate());
|
| }
|
| @@ -133,23 +118,20 @@
|
| * Verify that WebShare fails if the origin trial is disabled.
|
| * @throws Exception
|
| */
|
| - @Test
|
| - @MediumTest
|
| - @CommandLineFlags.Add({"enable-blink-features=WebShare",
|
| - "origin-trial-disabled-features=WebShare"})
|
| + @MediumTest
|
| + @CommandLineFlags.Add({
|
| + "enable-blink-features=WebShare", "origin-trial-disabled-features=WebShare"})
|
| @Feature({"WebShare"})
|
| public void testWebShareOriginTrialDisabled() throws Exception {
|
| - mActivityTestRule.loadUrl(mUrl);
|
| - TouchCommon.singleClickView(mTab.getView());
|
| - Assert.assertEquals(
|
| - "Fail: SecurityError: WebShare is disabled.", mUpdateWaiter.waitForUpdate());
|
| + loadUrl(mUrl);
|
| + singleClickView(mTab.getView());
|
| + assertEquals("Fail: SecurityError: WebShare is disabled.", mUpdateWaiter.waitForUpdate());
|
| }
|
|
|
| /**
|
| * Verify WebShare fails if share is called from a user gesture, and canceled.
|
| * @throws Exception
|
| */
|
| - @Test
|
| @MediumTest
|
| @CommandLineFlags.Add("enable-blink-features=WebShare")
|
| @Feature({"WebShare"})
|
| @@ -168,21 +150,20 @@
|
| // Click again to start another share. This is necessary to work around
|
| // https://crbug.com/636274 (callback is not canceled until next share is
|
| // initiated). This also serves as a regression test for https://crbug.com/640324.
|
| - TouchCommon.singleClickView(mTab.getView());
|
| - }
|
| - });
|
| -
|
| - mActivityTestRule.loadUrl(mUrl);
|
| - // Click (instead of directly calling the JavaScript function) to simulate a user gesture.
|
| - TouchCommon.singleClickView(mTab.getView());
|
| - Assert.assertEquals("Fail: AbortError: Share canceled", mUpdateWaiter.waitForUpdate());
|
| + singleClickView(mTab.getView());
|
| + }
|
| + });
|
| +
|
| + loadUrl(mUrl);
|
| + // Click (instead of directly calling the JavaScript function) to simulate a user gesture.
|
| + singleClickView(mTab.getView());
|
| + assertEquals("Fail: AbortError: Share canceled", mUpdateWaiter.waitForUpdate());
|
| }
|
|
|
| /**
|
| * Verify WebShare succeeds if share is called from a user gesture, and app chosen.
|
| * @throws Exception
|
| */
|
| - @Test
|
| @MediumTest
|
| @CommandLineFlags.Add("enable-blink-features=WebShare")
|
| @Feature({"WebShare"})
|
| @@ -212,23 +193,22 @@
|
| }
|
| });
|
|
|
| - mActivityTestRule.loadUrl(mUrl);
|
| - // Click (instead of directly calling the JavaScript function) to simulate a user gesture.
|
| - TouchCommon.singleClickView(mTab.getView());
|
| - Assert.assertEquals("Success", mUpdateWaiter.waitForUpdate());
|
| + loadUrl(mUrl);
|
| + // Click (instead of directly calling the JavaScript function) to simulate a user gesture.
|
| + singleClickView(mTab.getView());
|
| + assertEquals("Success", mUpdateWaiter.waitForUpdate());
|
|
|
| // The actual intent to be delivered to the target is in the EXTRA_INTENT of the chooser
|
| // intent.
|
| - Assert.assertNotNull(mReceivedIntent);
|
| - Assert.assertTrue(mReceivedIntent.hasExtra(Intent.EXTRA_INTENT));
|
| + assertNotNull(mReceivedIntent);
|
| + assertTrue(mReceivedIntent.hasExtra(Intent.EXTRA_INTENT));
|
| Intent innerIntent = mReceivedIntent.getParcelableExtra(Intent.EXTRA_INTENT);
|
| - Assert.assertNotNull(innerIntent);
|
| - Assert.assertEquals(Intent.ACTION_SEND, innerIntent.getAction());
|
| - Assert.assertTrue(innerIntent.hasExtra(Intent.EXTRA_SUBJECT));
|
| - Assert.assertEquals("Test Title", innerIntent.getStringExtra(Intent.EXTRA_SUBJECT));
|
| - Assert.assertTrue(innerIntent.hasExtra(Intent.EXTRA_TEXT));
|
| - Assert.assertEquals(
|
| - "Test Text https://test.url/", innerIntent.getStringExtra(Intent.EXTRA_TEXT));
|
| + assertNotNull(innerIntent);
|
| + assertEquals(Intent.ACTION_SEND, innerIntent.getAction());
|
| + assertTrue(innerIntent.hasExtra(Intent.EXTRA_SUBJECT));
|
| + assertEquals("Test Title", innerIntent.getStringExtra(Intent.EXTRA_SUBJECT));
|
| + assertTrue(innerIntent.hasExtra(Intent.EXTRA_TEXT));
|
| + assertEquals("Test Text https://test.url/", innerIntent.getStringExtra(Intent.EXTRA_TEXT));
|
| }
|
|
|
| /**
|
| @@ -238,7 +218,6 @@
|
| *
|
| * @throws Exception
|
| */
|
| - @Test
|
| @MediumTest
|
| @CommandLineFlags.Add("enable-blink-features=WebShare")
|
| @Feature({"WebShare"})
|
| @@ -256,10 +235,10 @@
|
|
|
| ShareHelper.setForceCustomChooserForTesting(true);
|
|
|
| - mActivityTestRule.loadUrl(mUrl);
|
| - // Click (instead of directly calling the JavaScript function) to simulate a user gesture.
|
| - TouchCommon.singleClickView(mTab.getView());
|
| - Assert.assertEquals("Fail: AbortError: Share canceled", mUpdateWaiter.waitForUpdate());
|
| + loadUrl(mUrl);
|
| + // Click (instead of directly calling the JavaScript function) to simulate a user gesture.
|
| + singleClickView(mTab.getView());
|
| + assertEquals("Fail: AbortError: Share canceled", mUpdateWaiter.waitForUpdate());
|
| }
|
|
|
| /**
|
| @@ -269,7 +248,6 @@
|
| *
|
| * @throws Exception
|
| */
|
| - @Test
|
| @MediumTest
|
| @CommandLineFlags.Add("enable-blink-features=WebShare")
|
| @Feature({"WebShare"})
|
| @@ -292,17 +270,22 @@
|
|
|
| ShareHelper.setForceCustomChooserForTesting(true);
|
|
|
| - mActivityTestRule.loadUrl(mUrl);
|
| - // Click (instead of directly calling the JavaScript function) to simulate a user gesture.
|
| - TouchCommon.singleClickView(mTab.getView());
|
| - Assert.assertEquals("Success", mUpdateWaiter.waitForUpdate());
|
| -
|
| - Assert.assertNotNull(mReceivedIntent);
|
| - Assert.assertEquals(Intent.ACTION_SEND, mReceivedIntent.getAction());
|
| - Assert.assertTrue(mReceivedIntent.hasExtra(Intent.EXTRA_SUBJECT));
|
| - Assert.assertEquals("Test Title", mReceivedIntent.getStringExtra(Intent.EXTRA_SUBJECT));
|
| - Assert.assertTrue(mReceivedIntent.hasExtra(Intent.EXTRA_TEXT));
|
| - Assert.assertEquals(
|
| - "Test Text https://test.url/", mReceivedIntent.getStringExtra(Intent.EXTRA_TEXT));
|
| + loadUrl(mUrl);
|
| + // Click (instead of directly calling the JavaScript function) to simulate a user gesture.
|
| + singleClickView(mTab.getView());
|
| + assertEquals("Success", mUpdateWaiter.waitForUpdate());
|
| +
|
| + assertNotNull(mReceivedIntent);
|
| + assertEquals(Intent.ACTION_SEND, mReceivedIntent.getAction());
|
| + assertTrue(mReceivedIntent.hasExtra(Intent.EXTRA_SUBJECT));
|
| + assertEquals("Test Title", mReceivedIntent.getStringExtra(Intent.EXTRA_SUBJECT));
|
| + assertTrue(mReceivedIntent.hasExtra(Intent.EXTRA_TEXT));
|
| + assertEquals("Test Text https://test.url/",
|
| + mReceivedIntent.getStringExtra(Intent.EXTRA_TEXT));
|
| + }
|
| +
|
| + @Override
|
| + public void startMainActivity() throws InterruptedException {
|
| + startMainActivityOnBlankPage();
|
| }
|
| }
|
|
|