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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/widget/findinpage/FindTest.java

Issue 2853573002: Convert ChromeTabbedActivityTestCaseBase children to JUnit4 (Closed)
Patch Set: rebase 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/widget/findinpage/FindTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/widget/findinpage/FindTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/widget/findinpage/FindTest.java
index db94191d92bef4f845d9e478ee166660d8329704..a57cecf245a29bedf14ba50b19c617e76c27ffdc 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/widget/findinpage/FindTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/widget/findinpage/FindTest.java
@@ -13,6 +13,7 @@ package org.chromium.chrome.browser.widget.findinpage;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
+import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.support.test.filters.SmallTest;
import android.text.Spannable;
@@ -23,18 +24,30 @@ import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
+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.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.FlakyTest;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.R;
+import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.tab.Tab;
-import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
+import org.chromium.chrome.test.ChromeActivityTestRule;
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
+import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.FullscreenTestUtils;
import org.chromium.chrome.test.util.MenuUtils;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.KeyUtils;
+import org.chromium.content.browser.test.util.TouchCommon;
import org.chromium.content.browser.test.util.UiUtils;
import org.chromium.net.test.EmbeddedTestServer;
@@ -43,30 +56,39 @@ import java.util.concurrent.Callable;
/**
* Find in page tests.
*/
-public class FindTest extends ChromeTabbedActivityTestBase {
+@RunWith(ChromeJUnit4ClassRunner.class)
+@CommandLineFlags.Add({
+ ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
+ ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG,
+})
+public class FindTest {
+ @Rule
+ public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
+
private static final String FILEPATH = "/chrome/test/data/android/find/test.html";
private EmbeddedTestServer mTestServer;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
+ @Before
+ public void setUp() throws Exception {
+ mActivityTestRule.startMainActivityOnBlankPage();
+ mTestServer = EmbeddedTestServer.createAndStartServer(
+ InstrumentationRegistry.getInstrumentation().getContext());
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
mTestServer.stopAndDestroyServer();
- super.tearDown();
}
/**
* Returns the FindResults text.
*/
private String waitForFindResults(String expectedResult) {
- final TextView findResults = (TextView) getActivity().findViewById(R.id.find_status);
- assertNotNull(expectedResult);
- assertNotNull(findResults);
+ final TextView findResults =
+ (TextView) mActivityTestRule.getActivity().findViewById(R.id.find_status);
+ Assert.assertNotNull(expectedResult);
+ Assert.assertNotNull(findResults);
CriteriaHelper.pollUiThread(
Criteria.equals(expectedResult, new Callable<CharSequence>() {
@Override
@@ -83,8 +105,8 @@ public class FindTest extends ChromeTabbedActivityTestBase {
* @throws InterruptedException
*/
private void findInPageFromMenu() throws InterruptedException {
- MenuUtils.invokeCustomMenuActionSync(getInstrumentation(),
- getActivity(), R.id.find_in_page_id);
+ MenuUtils.invokeCustomMenuActionSync(InstrumentationRegistry.getInstrumentation(),
+ mActivityTestRule.getActivity(), R.id.find_in_page_id);
waitForFindInPageVisibility(true);
}
@@ -93,8 +115,9 @@ public class FindTest extends ChromeTabbedActivityTestBase {
CriteriaHelper.pollUiThread(new Criteria() {
@Override
public boolean isSatisfied() {
- FindToolbar findToolbar = (FindToolbar) getActivity().findViewById(
- R.id.find_toolbar);
+ FindToolbar findToolbar =
+ (FindToolbar) mActivityTestRule.getActivity().findViewById(
+ R.id.find_toolbar);
boolean isVisible = findToolbar != null && findToolbar.isShown();
return (visible == isVisible) && !findToolbar.isAnimating();
@@ -107,12 +130,12 @@ public class FindTest extends ChromeTabbedActivityTestBase {
findInPageFromMenu();
// FindToolbar should automatically get focus.
final TextView findQueryText = getFindQueryText();
- assertTrue("FindToolbar should have focus", findQueryText.hasFocus());
+ Assert.assertTrue("FindToolbar should have focus", findQueryText.hasFocus());
// We have to send each key 1-by-1 to trigger the right listeners in the toolbar.
KeyCharacterMap keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
final KeyEvent[] events = keyCharacterMap.getEvents(query.toCharArray());
- assertNotNull(events);
+ Assert.assertNotNull(events);
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
@@ -128,28 +151,31 @@ public class FindTest extends ChromeTabbedActivityTestBase {
private void loadTestAndVerifyFindInPage(String query, String expectedResult)
throws InterruptedException {
- loadUrl(mTestServer.getURL(FILEPATH));
+ mActivityTestRule.loadUrl(mTestServer.getURL(FILEPATH));
String findResults = findStringInPage(query, expectedResult);
- assertTrue("Expected: " + expectedResult + " Got: " + findResults + " for: "
- + mTestServer.getURL(FILEPATH),
+ Assert.assertTrue("Expected: " + expectedResult + " Got: " + findResults
+ + " for: " + mTestServer.getURL(FILEPATH),
findResults.contains(expectedResult));
}
private FindToolbar getFindToolbar() {
- final FindToolbar findToolbar = (FindToolbar) getActivity().findViewById(R.id.find_toolbar);
- assertNotNull("FindToolbar not found", findToolbar);
+ final FindToolbar findToolbar =
+ (FindToolbar) mActivityTestRule.getActivity().findViewById(R.id.find_toolbar);
+ Assert.assertNotNull("FindToolbar not found", findToolbar);
return findToolbar;
}
private EditText getFindQueryText() {
- final EditText findQueryText = (EditText) getActivity().findViewById(R.id.find_query);
- assertNotNull("FindQueryText not found", findQueryText);
+ final EditText findQueryText =
+ (EditText) mActivityTestRule.getActivity().findViewById(R.id.find_query);
+ Assert.assertNotNull("FindQueryText not found", findQueryText);
return findQueryText;
}
/**
* Verify Find In Page is not case sensitive.
*/
+ @Test
@MediumTest
@Feature({"FindInPage", "Main"})
@RetryOnFailure
@@ -160,6 +186,7 @@ public class FindTest extends ChromeTabbedActivityTestBase {
/**
* Verify Find In Page with just one result.
*/
+ @Test
@MediumTest
@Feature({"FindInPage"})
@RetryOnFailure
@@ -170,6 +197,7 @@ public class FindTest extends ChromeTabbedActivityTestBase {
/**
* Verify Find In Page with a multi-line string.
*/
+ @Test
@MediumTest
@Feature({"FindInPage"})
@RetryOnFailure
@@ -183,6 +211,7 @@ public class FindTest extends ChromeTabbedActivityTestBase {
* Test for Find In Page with a multi-line string. Search string has an extra character
* added to the end so it should not be found.
*/
+ @Test
@MediumTest
@Feature({"FindInPage"})
@RetryOnFailure
@@ -195,6 +224,7 @@ public class FindTest extends ChromeTabbedActivityTestBase {
/**
* Verify Find In Page Next button.
*/
+ @Test
@MediumTest
@Feature({"FindInPage"})
@RetryOnFailure
@@ -202,10 +232,12 @@ public class FindTest extends ChromeTabbedActivityTestBase {
String query = "pitts";
loadTestAndVerifyFindInPage(query, "1/7");
// TODO(jaydeepmehta): Verify number of results and match against boxes drawn.
- singleClickView(getActivity().findViewById(R.id.find_next_button));
+ TouchCommon.singleClickView(
+ mActivityTestRule.getActivity().findViewById(R.id.find_next_button));
waitForFindResults("2/7");
for (int i = 2; i <= 7; i++) {
- singleClickView(getActivity().findViewById(R.id.find_next_button));
+ TouchCommon.singleClickView(
+ mActivityTestRule.getActivity().findViewById(R.id.find_next_button));
}
waitForFindResults("1/7");
}
@@ -213,6 +245,7 @@ public class FindTest extends ChromeTabbedActivityTestBase {
/**
* Verify Find In Page Next/Previous button.
*/
+ @Test
@MediumTest
@Feature({"FindInPage"})
@RetryOnFailure
@@ -220,144 +253,164 @@ public class FindTest extends ChromeTabbedActivityTestBase {
String query = "pitts";
loadTestAndVerifyFindInPage(query, "1/7");
// TODO(jaydeepmehta): Verify number of results and match against boxes drawn.
- singleClickView(getActivity().findViewById(R.id.find_next_button));
+ TouchCommon.singleClickView(
+ mActivityTestRule.getActivity().findViewById(R.id.find_next_button));
waitForFindResults("2/7");
- singleClickView(getActivity().findViewById(R.id.find_prev_button));
+ TouchCommon.singleClickView(
+ mActivityTestRule.getActivity().findViewById(R.id.find_prev_button));
waitForFindResults("1/7");
}
/**
* Verify that Find in page toolbar is dismissed on entering fullscreen.
*/
+ @Test
@MediumTest
@Feature({"FindInPage"})
@RetryOnFailure
public void testFullscreen() throws InterruptedException {
loadTestAndVerifyFindInPage("pitts", "1/7");
- Tab tab = getActivity().getActivityTab();
- FullscreenTestUtils.togglePersistentFullscreenAndAssert(tab, true, getActivity());
+ Tab tab = mActivityTestRule.getActivity().getActivityTab();
+ FullscreenTestUtils.togglePersistentFullscreenAndAssert(
+ tab, true, mActivityTestRule.getActivity());
waitForFindInPageVisibility(false);
- FullscreenTestUtils.togglePersistentFullscreenAndAssert(tab, false, getActivity());
+ FullscreenTestUtils.togglePersistentFullscreenAndAssert(
+ tab, false, mActivityTestRule.getActivity());
waitForFindInPageVisibility(false);
}
+ @Test
@MediumTest
@Feature({"FindInPage"})
@RetryOnFailure
public void testResultsBarInitiallyVisible() throws InterruptedException {
- loadUrl(mTestServer.getURL(FILEPATH));
+ mActivityTestRule.loadUrl(mTestServer.getURL(FILEPATH));
findInPageFromMenu();
final FindToolbar findToolbar = getFindToolbar();
final View resultBar = findToolbar.getFindResultBar();
- assertNotNull(resultBar);
- assertEquals(View.VISIBLE, resultBar.getVisibility());
+ Assert.assertNotNull(resultBar);
+ Assert.assertEquals(View.VISIBLE, resultBar.getVisibility());
}
+ @Test
@MediumTest
@Feature({"FindInPage"})
@RetryOnFailure
public void testResultsBarVisibleAfterTypingText() throws InterruptedException {
- loadUrl(mTestServer.getURL(FILEPATH));
+ mActivityTestRule.loadUrl(mTestServer.getURL(FILEPATH));
findInPageFromMenu();
final FindToolbar findToolbar = getFindToolbar();
final View resultBar = findToolbar.getFindResultBar();
- assertNotNull(resultBar);
+ Assert.assertNotNull(resultBar);
final TextView findQueryText = getFindQueryText();
- KeyUtils.singleKeyEventView(getInstrumentation(), findQueryText, KeyEvent.KEYCODE_T);
- assertEquals(View.VISIBLE, resultBar.getVisibility());
- KeyUtils.singleKeyEventView(getInstrumentation(), findQueryText, KeyEvent.KEYCODE_DEL);
- assertEquals(View.VISIBLE, resultBar.getVisibility());
+ KeyUtils.singleKeyEventView(
+ InstrumentationRegistry.getInstrumentation(), findQueryText, KeyEvent.KEYCODE_T);
+ Assert.assertEquals(View.VISIBLE, resultBar.getVisibility());
+ KeyUtils.singleKeyEventView(
+ InstrumentationRegistry.getInstrumentation(), findQueryText, KeyEvent.KEYCODE_DEL);
+ Assert.assertEquals(View.VISIBLE, resultBar.getVisibility());
}
/**
* Verify Find In Page isn't dismissed and matches no results
* if invoked with an empty string.
*/
+ @Test
@MediumTest
@Feature({"FindInPage"})
public void testFindDismissOnEmptyString() throws InterruptedException {
- loadUrl(mTestServer.getURL(FILEPATH));
+ mActivityTestRule.loadUrl(mTestServer.getURL(FILEPATH));
findInPageFromMenu();
final FindToolbar findToolbar = getFindToolbar();
- assertEquals(View.VISIBLE, findToolbar.getVisibility());
+ Assert.assertEquals(View.VISIBLE, findToolbar.getVisibility());
final TextView findQueryText = getFindQueryText();
- KeyUtils.singleKeyEventView(getInstrumentation(), findQueryText, KeyEvent.KEYCODE_T);
- KeyUtils.singleKeyEventView(getInstrumentation(), findQueryText, KeyEvent.KEYCODE_DEL);
- KeyUtils.singleKeyEventView(getInstrumentation(), findQueryText, KeyEvent.KEYCODE_ENTER);
+ KeyUtils.singleKeyEventView(
+ InstrumentationRegistry.getInstrumentation(), findQueryText, KeyEvent.KEYCODE_T);
+ KeyUtils.singleKeyEventView(
+ InstrumentationRegistry.getInstrumentation(), findQueryText, KeyEvent.KEYCODE_DEL);
+ KeyUtils.singleKeyEventView(InstrumentationRegistry.getInstrumentation(), findQueryText,
+ KeyEvent.KEYCODE_ENTER);
- assertEquals(View.VISIBLE, findToolbar.getVisibility());
+ Assert.assertEquals(View.VISIBLE, findToolbar.getVisibility());
String findResults = waitForFindResults("");
- assertEquals(0, findResults.length());
+ Assert.assertEquals(0, findResults.length());
}
/**
* Verify FIP in IncognitoTabs.
*/
+ @Test
@SmallTest
@Feature({"FindInPage"})
@RetryOnFailure
public void testFindNextPreviousIncognitoTab() throws InterruptedException {
String query = "pitts";
- newIncognitoTabFromMenu();
+ mActivityTestRule.newIncognitoTabFromMenu();
loadTestAndVerifyFindInPage(query, "1/7");
// TODO(jaydeepmehta): Verify number of results and match against boxes drawn.
- singleClickView(getActivity().findViewById(R.id.find_next_button));
+ TouchCommon.singleClickView(
+ mActivityTestRule.getActivity().findViewById(R.id.find_next_button));
waitForFindResults("2/7");
- singleClickView(getActivity().findViewById(R.id.find_prev_button));
+ TouchCommon.singleClickView(
+ mActivityTestRule.getActivity().findViewById(R.id.find_prev_button));
waitForFindResults("1/7");
}
/**
* Verify Find in Page text isnt restored on Incognito Tabs.
*/
+ @Test
@MediumTest
@Feature({"FindInPage"})
@RetryOnFailure
public void testFipTextNotRestoredIncognitoTab() throws InterruptedException {
- newIncognitoTabFromMenu();
+ mActivityTestRule.newIncognitoTabFromMenu();
loadTestAndVerifyFindInPage("pitts", "1/7");
// close the fip
- final View v = getActivity().findViewById(R.id.close_find_button);
- singleClickView(v);
+ final View v = mActivityTestRule.getActivity().findViewById(R.id.close_find_button);
+ TouchCommon.singleClickView(v);
waitForFindInPageVisibility(false);
// Reopen and check the text.
findInPageFromMenu();
- UiUtils.settleDownUI(getInstrumentation());
+ UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation());
// Verify the text content.
final EditText e = getFindQueryText();
String myText = e.getText().toString();
- assertTrue("expected empty string : " + myText, myText.isEmpty());
+ Assert.assertTrue("expected empty string : " + myText, myText.isEmpty());
}
/**
* Verify pasted text in the FindQuery text box doesn't retain formatting
*/
+ @Test
@SmallTest
@Feature({"FindInPage"})
@RetryOnFailure
public void testPastedTextStylingRemoved() throws InterruptedException {
- loadUrl(mTestServer.getURL(FILEPATH));
+ mActivityTestRule.loadUrl(mTestServer.getURL(FILEPATH));
findInPageFromMenu();
final FindToolbar findToolbar = getFindToolbar();
- assertEquals(View.VISIBLE, findToolbar.getVisibility());
+ Assert.assertEquals(View.VISIBLE, findToolbar.getVisibility());
final EditText findQueryText = getFindQueryText();
- // Setup the clipboard with a selection of stylized text
- ClipboardManager clipboard = (ClipboardManager) (getInstrumentation().getTargetContext())
- .getSystemService(Context.CLIPBOARD_SERVICE);
- clipboard.setPrimaryClip(ClipData.newHtmlText("label", "text", "<b>text</b>"));
-
// Emulate pasting the text into the find query text box
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
+ // Setup the clipboard with a selection of stylized text
+ ClipboardManager clipboard =
+ (ClipboardManager) InstrumentationRegistry.getInstrumentation()
+ .getTargetContext()
+ .getSystemService(Context.CLIPBOARD_SERVICE);
+ clipboard.setPrimaryClip(ClipData.newHtmlText("label", "text", "<b>text</b>"));
+
findQueryText.onTextContextMenuItem(android.R.id.paste);
}
});
@@ -365,7 +418,7 @@ public class FindTest extends ChromeTabbedActivityTestBase {
// Resulting text in the find query box should be unstyled
final Spannable text = findQueryText.getText();
final StyleSpan[] spans = text.getSpans(0, text.length(), StyleSpan.class);
- assertEquals(0, spans.length);
+ Assert.assertEquals(0, spans.length);
}
/**
@@ -373,20 +426,22 @@ public class FindTest extends ChromeTabbedActivityTestBase {
* presence of IME. First back key should dismiss IME and second back key should dismiss
* Find in page toolbar.
*/
+ @Test
@MediumTest
@Feature({"FindInPage"})
@FlakyTest(message = "https://crbug.com/673930")
public void testBackKeyDoesNotDismissFindWhenImeIsPresent() throws InterruptedException {
- loadUrl(mTestServer.getURL(FILEPATH));
+ mActivityTestRule.loadUrl(mTestServer.getURL(FILEPATH));
findInPageFromMenu();
final TextView findQueryText = getFindQueryText();
- KeyUtils.singleKeyEventView(getInstrumentation(), findQueryText, KeyEvent.KEYCODE_A);
+ KeyUtils.singleKeyEventView(
+ InstrumentationRegistry.getInstrumentation(), findQueryText, KeyEvent.KEYCODE_A);
waitForIME(true);
// IME is present at this moment, so IME will consume BACK key.
- sendKeys(KeyEvent.KEYCODE_BACK);
+ InstrumentationRegistry.getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
waitForIME(false);
waitForFindInPageVisibility(true);
- sendKeys(KeyEvent.KEYCODE_BACK);
+ InstrumentationRegistry.getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
waitForFindInPageVisibility(false);
}
@@ -394,6 +449,7 @@ public class FindTest extends ChromeTabbedActivityTestBase {
* Verify Find in page toolbar is dismissed when device back key is pressed when IME
* is not present. First back key press itself will dismiss Find in page toolbar.
*/
+ @Test
@MediumTest
@Feature({"FindInPage"})
@RetryOnFailure
@@ -401,9 +457,10 @@ public class FindTest extends ChromeTabbedActivityTestBase {
loadTestAndVerifyFindInPage("pitts", "1/7");
waitForIME(true);
// Hide IME by clicking next button from find tool bar.
- singleClickView(getActivity().findViewById(R.id.find_next_button));
+ TouchCommon.singleClickView(
+ mActivityTestRule.getActivity().findViewById(R.id.find_next_button));
waitForIME(false);
- sendKeys(KeyEvent.KEYCODE_BACK);
+ InstrumentationRegistry.getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
waitForFindInPageVisibility(false);
}
@@ -412,14 +469,10 @@ public class FindTest extends ChromeTabbedActivityTestBase {
CriteriaHelper.pollUiThread(new Criteria("IME is not getting shown!") {
@Override
public boolean isSatisfied() {
- return org.chromium.ui.UiUtils.isKeyboardShowing(getActivity(), getFindQueryText())
+ return org.chromium.ui.UiUtils.isKeyboardShowing(
+ mActivityTestRule.getActivity(), getFindQueryText())
== imePresent;
}
});
}
-
- @Override
- public void startMainActivity() throws InterruptedException {
- startMainActivityOnBlankPage();
- }
}

Powered by Google App Engine
This is Rietveld 408576698