Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1366)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java

Issue 2875393003: Convert Download Tests to JUnit4 (Closed)
Patch Set: Fix ContextMenuTest issues Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java
index 9b7ce69305e716274ca4f6ef4dc03eb95ca17fa9..7d0f8e04f532fa9daab0f5e0b247cae800e01539 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java
@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.contextmenu;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
+import android.support.test.InstrumentationRegistry;
import android.support.test.filters.LargeTest;
import android.support.test.filters.MediumTest;
import android.support.test.filters.SmallTest;
@@ -14,6 +15,13 @@ import android.test.MoreAsserts;
import android.view.ContextMenu;
import android.view.KeyEvent;
+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.ThreadUtils;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.CommandLineFlags;
@@ -23,11 +31,14 @@ import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.compositor.layouts.LayoutManager;
-import org.chromium.chrome.browser.download.DownloadTestBase;
+import org.chromium.chrome.browser.download.DownloadTestRule;
+import org.chromium.chrome.browser.download.DownloadTestRule.CustomMainActivityStart;
import org.chromium.chrome.browser.firstrun.FirstRunStatus;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
import org.chromium.chrome.browser.tabmodel.TabModel;
+import org.chromium.chrome.test.ChromeActivityTestRule;
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
@@ -45,10 +56,15 @@ import java.util.concurrent.atomic.AtomicReference;
/**
* Context menu related tests
*/
-@CommandLineFlags.Add({
+@RunWith(ChromeJUnit4ClassRunner.class)
+@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
+ ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG,
ChromeSwitches.GOOGLE_BASE_URL + "=http://example.com/",
ChromeSwitches.HERB_FLAVOR_DISABLED_SWITCH})
-public class ContextMenuTest extends DownloadTestBase {
+public class ContextMenuTest implements CustomMainActivityStart {
+ @Rule
+ public DownloadTestRule mDownloadTestRule = new DownloadTestRule(this);
+
private static final String TEST_PATH =
"/chrome/test/data/android/contextmenu/context_menu_test.html";
@@ -63,13 +79,8 @@ public class ContextMenuTest extends DownloadTestBase {
FILENAME_GIF, FILENAME_PNG, FILENAME_WEBM
};
- @Override
- protected void setUp() throws Exception {
- mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
- mTestUrl = mTestServer.getURL(TEST_PATH);
- deleteTestFiles();
- super.setUp();
-
+ @Before
+ public void setUp() throws Exception {
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
@@ -78,8 +89,8 @@ public class ContextMenuTest extends DownloadTestBase {
});
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
mTestServer.stopAndDestroyServer();
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
@@ -88,61 +99,72 @@ public class ContextMenuTest extends DownloadTestBase {
}
});
deleteTestFiles();
- super.tearDown();
}
@Override
- public void startMainActivity() throws InterruptedException {
- startMainActivityWithURL(mTestUrl);
- assertWaitForPageScaleFactorMatch(0.5f);
+ public void customMainActivityStart() throws InterruptedException {
+ mTestServer = EmbeddedTestServer.createAndStartServer(
+ InstrumentationRegistry.getInstrumentation().getContext());
+ mTestUrl = mTestServer.getURL(TEST_PATH);
+ deleteTestFiles();
+ mDownloadTestRule.startMainActivityWithURL(mTestUrl);
+ mDownloadTestRule.assertWaitForPageScaleFactorMatch(0.5f);
}
+ @Test
@MediumTest
@Feature({"Browser", "Main"})
@RetryOnFailure
- public void testCopyLinkURL() throws InterruptedException, TimeoutException {
- Tab tab = getActivity().getActivityTab();
- ContextMenuUtils.selectContextMenuItem(getInstrumentation(), getActivity(), tab, "testLink",
+ public void testCopyLinkURL() throws Throwable {
+ Tab tab = mDownloadTestRule.getActivity().getActivityTab();
+ ContextMenuUtils.selectContextMenuItem(InstrumentationRegistry.getInstrumentation(),
+ mDownloadTestRule.getActivity(), tab, "testLink",
R.id.contextmenu_copy_link_address);
assertStringContains("test_link.html", getClipboardText());
}
+ @Test
@MediumTest
@Feature({"Browser"})
@RetryOnFailure
- public void testCopyImageLinkCopiesLinkURL() throws InterruptedException, TimeoutException {
- Tab tab = getActivity().getActivityTab();
- ContextMenuUtils.selectContextMenuItem(getInstrumentation(), getActivity(), tab,
- "testImageLink", R.id.contextmenu_copy_link_address);
+ public void testCopyImageLinkCopiesLinkURL() throws Throwable {
+ Tab tab = mDownloadTestRule.getActivity().getActivityTab();
+ ContextMenuUtils.selectContextMenuItem(InstrumentationRegistry.getInstrumentation(),
+ mDownloadTestRule.getActivity(), tab, "testImageLink",
+ R.id.contextmenu_copy_link_address);
assertStringContains("test_link.html", getClipboardText());
}
+ @Test
@MediumTest
@Feature({"Browser"})
@RetryOnFailure
- public void testCopyLinkTextSimple() throws InterruptedException, TimeoutException {
- Tab tab = getActivity().getActivityTab();
- ContextMenuUtils.selectContextMenuItem(getInstrumentation(), getActivity(), tab, "testLink",
- R.id.contextmenu_copy_link_text);
+ public void testCopyLinkTextSimple() throws Throwable {
+ Tab tab = mDownloadTestRule.getActivity().getActivityTab();
+ ContextMenuUtils.selectContextMenuItem(InstrumentationRegistry.getInstrumentation(),
+ mDownloadTestRule.getActivity(), tab, "testLink", R.id.contextmenu_copy_link_text);
- assertEquals("Clipboard text was not what was expected", "Test Link",
- getClipboardText());
+ Assert.assertEquals(
+ "Clipboard text was not what was expected", "Test Link", getClipboardText());
}
+ @Test
@MediumTest
@Feature({"Browser"})
@RetryOnFailure
- public void testCopyLinkTextComplex() throws InterruptedException, TimeoutException {
- Tab tab = getActivity().getActivityTab();
- ContextMenuUtils.selectContextMenuItem(getInstrumentation(), getActivity(), tab,
- "copyLinkTextComplex", R.id.contextmenu_copy_link_text);
+ public void testCopyLinkTextComplex() throws Throwable {
+ Tab tab = mDownloadTestRule.getActivity().getActivityTab();
+ ContextMenuUtils.selectContextMenuItem(InstrumentationRegistry.getInstrumentation(),
+ mDownloadTestRule.getActivity(), tab, "copyLinkTextComplex",
+ R.id.contextmenu_copy_link_text);
- assertEquals("Clipboard text was not what was expected",
+ Assert.assertEquals("Clipboard text was not what was expected",
"This is pretty extreme \n(newline). ", getClipboardText());
}
+ @Test
@MediumTest
@Feature({"Browser"})
@RetryOnFailure
@@ -156,6 +178,7 @@ public class ContextMenuTest extends DownloadTestBase {
* @Feature({"Browser"})
* @CommandLineFlags.Add(ChromeSwitches.DISABLE_DOCUMENT_MODE)
*/
+ @Test
@FlakyTest(message = "http://crbug.com/606939")
public void testLongPressOnImageLink() throws InterruptedException, TimeoutException {
checkOpenImageInNewTab(
@@ -164,32 +187,34 @@ public class ContextMenuTest extends DownloadTestBase {
private void checkOpenImageInNewTab(String domId, final String expectedPath)
throws InterruptedException, TimeoutException {
- final Tab activityTab = getActivity().getActivityTab();
+ final Tab activityTab = mDownloadTestRule.getActivity().getActivityTab();
final CallbackHelper newTabCallback = new CallbackHelper();
final AtomicReference<Tab> newTab = new AtomicReference<>();
- getActivity().getTabModelSelector().addObserver(new EmptyTabModelSelectorObserver() {
- @Override
- public void onNewTabCreated(Tab tab) {
- super.onNewTabCreated(tab);
+ mDownloadTestRule.getActivity().getTabModelSelector().addObserver(
+ new EmptyTabModelSelectorObserver() {
+ @Override
+ public void onNewTabCreated(Tab tab) {
+ super.onNewTabCreated(tab);
- if (tab.getParentId() != activityTab.getId()) return;
- newTab.set(tab);
- newTabCallback.notifyCalled();
+ if (tab.getParentId() != activityTab.getId()) return;
+ newTab.set(tab);
+ newTabCallback.notifyCalled();
- getActivity().getTabModelSelector().removeObserver(this);
- }
- });
+ mDownloadTestRule.getActivity().getTabModelSelector().removeObserver(this);
+ }
+ });
int callbackCount = newTabCallback.getCallCount();
- ContextMenuUtils.selectContextMenuItem(getInstrumentation(), getActivity(), activityTab,
- domId, R.id.contextmenu_open_image_in_new_tab);
+ ContextMenuUtils.selectContextMenuItem(InstrumentationRegistry.getInstrumentation(),
+ mDownloadTestRule.getActivity(), activityTab, domId,
+ R.id.contextmenu_open_image_in_new_tab);
try {
newTabCallback.waitForCallback(callbackCount);
} catch (TimeoutException ex) {
- fail("New tab never created from context menu press");
+ Assert.fail("New tab never created from context menu press");
}
// Only check for the URL matching as the tab will not be fully created in svelte mode.
@@ -202,77 +227,82 @@ public class ContextMenuTest extends DownloadTestBase {
}));
}
+ @Test
@MediumTest
@Feature({"Browser"})
@RetryOnFailure
public void testDismissContextMenuOnBack() throws InterruptedException, TimeoutException {
- Tab tab = getActivity().getActivityTab();
+ Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImage");
- assertNotNull("Context menu was not properly created", menu);
+ Assert.assertNotNull("Context menu was not properly created", menu);
CriteriaHelper.pollUiThread(new Criteria("Context menu did not have window focus") {
@Override
public boolean isSatisfied() {
- return !getActivity().hasWindowFocus();
+ return !mDownloadTestRule.getActivity().hasWindowFocus();
}
});
- getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
+ InstrumentationRegistry.getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
CriteriaHelper.pollUiThread(new Criteria("Activity did not regain focus.") {
@Override
public boolean isSatisfied() {
- return getActivity().hasWindowFocus();
+ return mDownloadTestRule.getActivity().hasWindowFocus();
}
});
}
+ @Test
@MediumTest
@Feature({"Browser"})
@RetryOnFailure
public void testDismissContextMenuOnClick() throws InterruptedException, TimeoutException {
- Tab tab = getActivity().getActivityTab();
+ Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImage");
- assertNotNull("Context menu was not properly created", menu);
+ Assert.assertNotNull("Context menu was not properly created", menu);
CriteriaHelper.pollUiThread(new Criteria("Context menu did not have window focus") {
@Override
public boolean isSatisfied() {
- return !getActivity().hasWindowFocus();
+ return !mDownloadTestRule.getActivity().hasWindowFocus();
}
});
- TestTouchUtils.singleClickView(getInstrumentation(), tab.getView(), 0, 0);
+ TestTouchUtils.singleClickView(
+ InstrumentationRegistry.getInstrumentation(), tab.getView(), 0, 0);
CriteriaHelper.pollUiThread(new Criteria("Activity did not regain focus.") {
@Override
public boolean isSatisfied() {
- return getActivity().hasWindowFocus();
+ return mDownloadTestRule.getActivity().hasWindowFocus();
}
});
}
+ @Test
@MediumTest
@Feature({"Browser"})
@RetryOnFailure
- public void testCopyEmailAddress() throws InterruptedException, TimeoutException {
- Tab tab = getActivity().getActivityTab();
- ContextMenuUtils.selectContextMenuItem(
- getInstrumentation(), getActivity(), tab, "testEmail", R.id.contextmenu_copy);
+ public void testCopyEmailAddress() throws Throwable {
+ Tab tab = mDownloadTestRule.getActivity().getActivityTab();
+ ContextMenuUtils.selectContextMenuItem(InstrumentationRegistry.getInstrumentation(),
+ mDownloadTestRule.getActivity(), tab, "testEmail", R.id.contextmenu_copy);
- assertEquals("Copied email address is not correct",
+ Assert.assertEquals("Copied email address is not correct",
"someone1@example.com,someone2@example.com", getClipboardText());
}
+ @Test
@MediumTest
@Feature({"Browser"})
@RetryOnFailure
- public void testCopyTelNumber() throws InterruptedException, TimeoutException {
- Tab tab = getActivity().getActivityTab();
- ContextMenuUtils.selectContextMenuItem(
- getInstrumentation(), getActivity(), tab, "testTel", R.id.contextmenu_copy);
+ public void testCopyTelNumber() throws Throwable {
+ Tab tab = mDownloadTestRule.getActivity().getActivityTab();
+ ContextMenuUtils.selectContextMenuItem(InstrumentationRegistry.getInstrumentation(),
+ mDownloadTestRule.getActivity(), tab, "testTel", R.id.contextmenu_copy);
- assertEquals("Copied tel number is not correct",
- "10000000000", getClipboardText());
+ Assert.assertEquals("Copied tel number is not correct", "10000000000", getClipboardText());
}
+ @Test
@LargeTest
@Feature({"Browser"})
@RetryOnFailure
@@ -281,6 +311,7 @@ public class ContextMenuTest extends DownloadTestBase {
saveMediaFromContextMenu("dataUrlIcon", R.id.contextmenu_save_image, FILENAME_GIF);
}
+ @Test
@LargeTest
@Feature({"Browser"})
@RetryOnFailure
@@ -289,13 +320,15 @@ public class ContextMenuTest extends DownloadTestBase {
saveMediaFromContextMenu("testImage", R.id.contextmenu_save_image, FILENAME_PNG);
}
+ @Test
@LargeTest
@Feature({"Browser"})
@RetryOnFailure
public void testSaveVideo()
throws InterruptedException, TimeoutException, SecurityException, IOException {
// Click the video to enable playback
- DOMUtils.clickNode(getActivity().getCurrentContentViewCore(), "videoDOMElement");
+ DOMUtils.clickNode(
+ mDownloadTestRule.getActivity().getCurrentContentViewCore(), "videoDOMElement");
saveMediaFromContextMenu("videoDOMElement", R.id.contextmenu_save_video, FILENAME_WEBM);
}
@@ -306,24 +339,26 @@ public class ContextMenuTest extends DownloadTestBase {
* This test only applies in tabbed mode. In document mode, Android handles the ordering of the
* tabs.
*/
+ @Test
@LargeTest
@Feature({"Browser"})
@RetryOnFailure
public void testOpenLinksInNewTabsAndVerifyTabIndexOrdering()
throws InterruptedException, TimeoutException {
- TabModel tabModel = getActivity().getCurrentTabModel();
+ TabModel tabModel = mDownloadTestRule.getActivity().getCurrentTabModel();
int numOpenedTabs = tabModel.getCount();
- Tab tab = getActivity().getActivityTab();
- ContextMenuUtils.selectContextMenuItem(getInstrumentation(), getActivity(), tab, "testLink",
- R.id.contextmenu_open_in_new_tab);
- getInstrumentation().waitForIdleSync();
+ Tab tab = mDownloadTestRule.getActivity().getActivityTab();
+ ContextMenuUtils.selectContextMenuItem(InstrumentationRegistry.getInstrumentation(),
+ mDownloadTestRule.getActivity(), tab, "testLink", R.id.contextmenu_open_in_new_tab);
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
int indexOfLinkPage = numOpenedTabs;
numOpenedTabs += 1;
- assertEquals("Number of open tabs does not match", numOpenedTabs , tabModel.getCount());
+ Assert.assertEquals(
+ "Number of open tabs does not match", numOpenedTabs, tabModel.getCount());
// Wait for any new tab animation to finish if we're being driven by the compositor.
- final LayoutManager layoutDriver = getActivity()
- .getCompositorViewHolder().getLayoutManager();
+ final LayoutManager layoutDriver =
+ mDownloadTestRule.getActivity().getCompositorViewHolder().getLayoutManager();
CriteriaHelper.pollUiThread(
new Criteria("Background tab animation not finished.") {
@Override
@@ -332,32 +367,35 @@ public class ContextMenuTest extends DownloadTestBase {
}
});
- ContextMenuUtils.selectContextMenuItem(getInstrumentation(), getActivity(), tab,
- "testLink2", R.id.contextmenu_open_in_new_tab);
- getInstrumentation().waitForIdleSync();
+ ContextMenuUtils.selectContextMenuItem(InstrumentationRegistry.getInstrumentation(),
+ mDownloadTestRule.getActivity(), tab, "testLink2",
+ R.id.contextmenu_open_in_new_tab);
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
int indexOfLinkPage2 = numOpenedTabs;
numOpenedTabs += 1;
- assertEquals("Number of open tabs does not match", numOpenedTabs, tabModel.getCount());
+ Assert.assertEquals(
+ "Number of open tabs does not match", numOpenedTabs, tabModel.getCount());
// Verify the Url is still the same of Parent page.
- assertEquals(mTestUrl, getActivity().getActivityTab().getUrl());
+ Assert.assertEquals(mTestUrl, mDownloadTestRule.getActivity().getActivityTab().getUrl());
// Verify that the background tabs were opened in the expected order.
String newTabUrl = mTestServer.getURL(
"/chrome/test/data/android/contextmenu/test_link.html");
- assertEquals(newTabUrl, tabModel.getTabAt(indexOfLinkPage).getUrl());
+ Assert.assertEquals(newTabUrl, tabModel.getTabAt(indexOfLinkPage).getUrl());
String imageUrl = mTestServer.getURL(
"/chrome/test/data/android/contextmenu/test_link2.html");
- assertEquals(imageUrl, tabModel.getTabAt(indexOfLinkPage2).getUrl());
+ Assert.assertEquals(imageUrl, tabModel.getTabAt(indexOfLinkPage2).getUrl());
}
+ @Test
@SmallTest
@Feature({"Browser", "ContextMenu"})
@RetryOnFailure
public void testContextMenuRetrievesLinkOptions()
throws TimeoutException, InterruptedException {
- Tab tab = getActivity().getActivityTab();
+ Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testLink");
Integer[] expectedItems = {R.id.contextmenu_open_in_new_tab,
@@ -366,12 +404,13 @@ public class ContextMenuTest extends DownloadTestBase {
assertMenuItemsAreEqual(menu, expectedItems);
}
+ @Test
@SmallTest
@Feature({"Browser", "ContextMenu"})
@RetryOnFailure
public void testContextMenuRetrievesImageOptions()
throws TimeoutException, InterruptedException {
- Tab tab = getActivity().getActivityTab();
+ Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImage");
Integer[] expectedItems = {R.id.contextmenu_save_image,
@@ -380,12 +419,13 @@ public class ContextMenuTest extends DownloadTestBase {
assertMenuItemsAreEqual(menu, expectedItems);
}
+ @Test
@SmallTest
@Feature({"Browser", "ContextMenu"})
@RetryOnFailure
public void testContextMenuRetrievesImageLinkOptions()
throws TimeoutException, InterruptedException {
- Tab tab = getActivity().getActivityTab();
+ Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImageLink");
Integer[] expectedItems = {R.id.contextmenu_open_in_new_tab,
@@ -396,13 +436,15 @@ public class ContextMenuTest extends DownloadTestBase {
assertMenuItemsAreEqual(menu, expectedItems);
}
+ @Test
@SmallTest
@Feature({"Browser", "ContextMenu"})
@RetryOnFailure
public void testContextMenuRetrievesVideoOptions()
throws TimeoutException, InterruptedException {
- Tab tab = getActivity().getActivityTab();
- DOMUtils.clickNode(getActivity().getCurrentContentViewCore(), "videoDOMElement");
+ Tab tab = mDownloadTestRule.getActivity().getActivityTab();
+ DOMUtils.clickNode(
+ mDownloadTestRule.getActivity().getCurrentContentViewCore(), "videoDOMElement");
ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "videoDOMElement");
Integer[] expectedItems = {R.id.contextmenu_save_video};
@@ -430,27 +472,35 @@ public class ContextMenuTest extends DownloadTestBase {
String expectedFilename) throws InterruptedException, TimeoutException,
SecurityException, IOException {
// Select "save [image/video]" in that menu.
- Tab tab = getActivity().getActivityTab();
- int callCount = getChromeDownloadCallCount();
- ContextMenuUtils.selectContextMenuItem(
- getInstrumentation(), getActivity(), tab, mediaDOMElement, saveMenuID);
+ Tab tab = mDownloadTestRule.getActivity().getActivityTab();
+ int callCount = mDownloadTestRule.getChromeDownloadCallCount();
+ ContextMenuUtils.selectContextMenuItem(InstrumentationRegistry.getInstrumentation(),
+ mDownloadTestRule.getActivity(), tab, mediaDOMElement, saveMenuID);
// Wait for the download to complete and see if we got the right file
- assertTrue(waitForChromeDownloadToFinish(callCount));
- checkLastDownload(expectedFilename);
+ Assert.assertTrue(mDownloadTestRule.waitForChromeDownloadToFinish(callCount));
+ mDownloadTestRule.checkLastDownload(expectedFilename);
}
- private String getClipboardText() {
- ClipboardManager clipMgr =
- (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
- ClipData clipData = clipMgr.getPrimaryClip();
- assertNotNull("Primary clip is null", clipData);
- assertTrue("Primary clip contains no items.", clipData.getItemCount() > 0);
- return clipData.getItemAt(0).getText().toString();
+ private String getClipboardText() throws Throwable {
+ final AtomicReference<String> clipboardTextRef = new AtomicReference<>();
+ mDownloadTestRule.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ ClipboardManager clipMgr =
+ (ClipboardManager) mDownloadTestRule.getActivity().getSystemService(
+ Context.CLIPBOARD_SERVICE);
+ ClipData clipData = clipMgr.getPrimaryClip();
+ Assert.assertNotNull("Primary clip is null", clipData);
+ Assert.assertTrue("Primary clip contains no items.", clipData.getItemCount() > 0);
+ clipboardTextRef.set(clipData.getItemAt(0).getText().toString());
+ }
+ });
+ return clipboardTextRef.get();
}
private void assertStringContains(String subString, String superString) {
- assertTrue("String '" + superString + "' does not contain '" + subString + "'",
+ Assert.assertTrue("String '" + superString + "' does not contain '" + subString + "'",
superString.contains(subString));
}
@@ -459,6 +509,6 @@ public class ContextMenuTest extends DownloadTestBase {
* downloads directory
*/
private void deleteTestFiles() {
- deleteFilesInDownloadDirectory(TEST_FILES);
+ mDownloadTestRule.deleteFilesInDownloadDirectory(TEST_FILES);
}
}
« no previous file with comments | « chrome/android/java_sources.gni ('k') | chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698