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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/feedback/FeedbackCollectorTest.java

Issue 2831823003: Convert ChromeActivityTestCaseBase direct children to JUnit4 (Closed)
Patch Set: rebase and convert newly added test Created 3 years, 8 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/feedback/FeedbackCollectorTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/feedback/FeedbackCollectorTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/feedback/FeedbackCollectorTest.java
index 4f1bbeb90549fdb236dba6409e7ed90ff56e929c..9e1a79979826977e528b506b999d7f2166b9317d 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/feedback/FeedbackCollectorTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/feedback/FeedbackCollectorTest.java
@@ -7,15 +7,25 @@ package org.chromium.chrome.browser.feedback;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
+import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
+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.RetryOnFailure;
import org.chromium.chrome.browser.ChromeActivity;
+import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings;
import org.chromium.chrome.browser.profiles.Profile;
-import org.chromium.chrome.test.ChromeActivityTestCaseBase;
+import org.chromium.chrome.test.ChromeActivityTestRule;
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.content.browser.test.util.UiUtils;
import org.chromium.net.ConnectionType;
@@ -32,8 +42,15 @@ import javax.annotation.Nullable;
/**
* Test for {@link FeedbackCollector}.
*/
+@RunWith(ChromeJUnit4ClassRunner.class)
@RetryOnFailure
-public class FeedbackCollectorTest extends ChromeActivityTestCaseBase<ChromeActivity> {
+@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
+ ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
+public class FeedbackCollectorTest {
+ @Rule
+ public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
+ new ChromeActivityTestRule<>(ChromeActivity.class);
+
private static final int CONNECTIVITY_TASK_TIMEOUT_MS = 10;
private ChromeActivity mActivity;
@@ -41,10 +58,6 @@ public class FeedbackCollectorTest extends ChromeActivityTestCaseBase<ChromeActi
private TestFeedbackCollector mCollector;
private TestConnectivityTask mTestConnectivityTask;
- public FeedbackCollectorTest() {
- super(ChromeActivity.class);
- }
-
/**
* Class for facilitating testing of {@link FeedbackCollector}. All public methods are
* automatically run on the UI thread, to simplify testing code.
@@ -189,10 +202,10 @@ public class FeedbackCollectorTest extends ChromeActivityTestCaseBase<ChromeActi
}
}
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mActivity = getActivity();
+ @Before
+ public void setUp() throws Exception {
+ mActivityTestRule.startMainActivityOnBlankPage();
+ mActivity = mActivityTestRule.getActivity();
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
@@ -201,11 +214,7 @@ public class FeedbackCollectorTest extends ChromeActivityTestCaseBase<ChromeActi
});
}
- @Override
- public void startMainActivity() throws InterruptedException {
- startMainActivityOnBlankPage();
- }
-
+ @Test
@SmallTest
@Feature({"Feedback"})
public void testGatheringOfData() {
@@ -218,15 +227,16 @@ public class FeedbackCollectorTest extends ChromeActivityTestCaseBase<ChromeActi
mCollector.setScreenshot(bitmap);
Bundle bundle = mCollector.getBundle();
- assertEquals("http://www.example.com/", bundle.getString(FeedbackCollector.URL_KEY));
- assertEquals("CONNECTED", bundle.getString(ConnectivityTask.CHROME_HTTPS_KEY));
- assertEquals("some description", mCollector.getDescription());
- assertEquals("bar", bundle.getString("foo"));
- assertEquals(bitmap, mCollector.getScreenshot());
- assertEquals("false",
+ Assert.assertEquals("http://www.example.com/", bundle.getString(FeedbackCollector.URL_KEY));
+ Assert.assertEquals("CONNECTED", bundle.getString(ConnectivityTask.CHROME_HTTPS_KEY));
+ Assert.assertEquals("some description", mCollector.getDescription());
+ Assert.assertEquals("bar", bundle.getString("foo"));
+ Assert.assertEquals(bitmap, mCollector.getScreenshot());
+ Assert.assertEquals("false",
bundle.getString(DataReductionProxySettings.DATA_REDUCTION_PROXY_ENABLED_KEY));
}
+ @Test
@SmallTest
@Feature({"Feedback"})
public void testGatheringOfDataWithCallback() throws InterruptedException {
@@ -240,27 +250,29 @@ public class FeedbackCollectorTest extends ChromeActivityTestCaseBase<ChromeActi
}
};
mCollector = createCollector("http://www.example.com/", callback);
- assertFalse("Result should not be ready directly after creation.", hasResult.get());
+ Assert.assertFalse("Result should not be ready directly after creation.", hasResult.get());
ConnectivityTask.FeedbackData feedbackData = createFeedbackData();
mCollector.onResult(feedbackData);
- assertFalse("Result should not be ready after connectivity data.", hasResult.get());
+ Assert.assertFalse("Result should not be ready after connectivity data.", hasResult.get());
mCollector.setDescription("some description");
mCollector.add("foo", "bar");
Bitmap bitmap = createBitmap();
mCollector.onGotBitmap(bitmap);
// Wait until the callback has been called.
- assertTrue("Failed to acquire semaphore.", semaphore.tryAcquire(1, TimeUnit.SECONDS));
- assertTrue("Result should be ready after retrieving all data.", hasResult.get());
+ Assert.assertTrue(
+ "Failed to acquire semaphore.", semaphore.tryAcquire(1, TimeUnit.SECONDS));
+ Assert.assertTrue("Result should be ready after retrieving all data.", hasResult.get());
Bundle bundle = mCollector.getBundle();
- assertEquals("http://www.example.com/", bundle.getString(FeedbackCollector.URL_KEY));
- assertEquals("CONNECTED", bundle.getString(ConnectivityTask.CHROME_HTTPS_KEY));
- assertEquals("some description", mCollector.getDescription());
- assertEquals("bar", bundle.getString("foo"));
- assertEquals(bitmap, mCollector.getScreenshot());
+ Assert.assertEquals("http://www.example.com/", bundle.getString(FeedbackCollector.URL_KEY));
+ Assert.assertEquals("CONNECTED", bundle.getString(ConnectivityTask.CHROME_HTTPS_KEY));
+ Assert.assertEquals("some description", mCollector.getDescription());
+ Assert.assertEquals("bar", bundle.getString("foo"));
+ Assert.assertEquals(bitmap, mCollector.getScreenshot());
}
+ @Test
@SmallTest
@Feature({"Feedback"})
public void testGatheringOfDataTimesOut() throws InterruptedException {
@@ -274,28 +286,30 @@ public class FeedbackCollectorTest extends ChromeActivityTestCaseBase<ChromeActi
}
};
mCollector = createCollector(null, callback);
- assertFalse("Result should not be ready directly after creation.", hasResult.get());
+ Assert.assertFalse("Result should not be ready directly after creation.", hasResult.get());
ConnectivityTask.FeedbackData feedbackData = createFeedbackData();
// Set the feedback data on the connectivity task instead of through callback.
mTestConnectivityTask.setFeedbackData(feedbackData);
- assertFalse("Result should not be ready after connectivity data.", hasResult.get());
+ Assert.assertFalse("Result should not be ready after connectivity data.", hasResult.get());
Bitmap bitmap = createBitmap();
mCollector.onGotBitmap(bitmap);
// This timeout task should trigger the callback.
mCollector.setTimedOut(true);
mCollector.maybePostResult();
- UiUtils.settleDownUI(getInstrumentation());
+ UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation());
// Wait until the callback has been called.
- assertTrue("Failed to acquire semaphore.", semaphore.tryAcquire(1, TimeUnit.SECONDS));
- assertTrue("Result should be ready after retrieving all data.", hasResult.get());
+ Assert.assertTrue(
+ "Failed to acquire semaphore.", semaphore.tryAcquire(1, TimeUnit.SECONDS));
+ Assert.assertTrue("Result should be ready after retrieving all data.", hasResult.get());
Bundle bundle = mCollector.getBundle();
- assertEquals("CONNECTED", bundle.getString(ConnectivityTask.CHROME_HTTPS_KEY));
- assertEquals(bitmap, mCollector.getScreenshot());
+ Assert.assertEquals("CONNECTED", bundle.getString(ConnectivityTask.CHROME_HTTPS_KEY));
+ Assert.assertEquals(bitmap, mCollector.getScreenshot());
}
+ @Test
@SmallTest
@Feature({"Feedback"})
public void testGatheringOfDataAlwaysWaitForScreenshot() throws InterruptedException {
@@ -309,29 +323,30 @@ public class FeedbackCollectorTest extends ChromeActivityTestCaseBase<ChromeActi
}
};
mCollector = createCollector(null, callback);
- assertFalse("Result should not be ready directly after creation.", hasResult.get());
+ Assert.assertFalse("Result should not be ready directly after creation.", hasResult.get());
ConnectivityTask.FeedbackData feedbackData = createFeedbackData();
mCollector.onResult(feedbackData);
- assertFalse("Result should not be ready after connectivity data.", hasResult.get());
+ Assert.assertFalse("Result should not be ready after connectivity data.", hasResult.get());
// This timeout task should not trigger the callback.
mCollector.setTimedOut(true);
mCollector.maybePostResult();
- UiUtils.settleDownUI(getInstrumentation());
- assertFalse("Result should not be ready after timeout.", hasResult.get());
+ UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation());
+ Assert.assertFalse("Result should not be ready after timeout.", hasResult.get());
// Trigger callback by finishing taking the screenshot.
Bitmap bitmap = createBitmap();
mCollector.onGotBitmap(bitmap);
// Wait until the callback has been called.
- assertTrue("Failed to acquire semaphore.", semaphore.tryAcquire(1, TimeUnit.SECONDS));
- assertTrue("Result should be ready after retrieving all data.", hasResult.get());
+ Assert.assertTrue(
+ "Failed to acquire semaphore.", semaphore.tryAcquire(1, TimeUnit.SECONDS));
+ Assert.assertTrue("Result should be ready after retrieving all data.", hasResult.get());
Bundle bundle = mCollector.getBundle();
// The FeedbackData should have been gathered from the ConnectivityTask directly.
- assertEquals("CONNECTED", bundle.getString(ConnectivityTask.CHROME_HTTPS_KEY));
- assertEquals(bitmap, mCollector.getScreenshot());
+ Assert.assertEquals("CONNECTED", bundle.getString(ConnectivityTask.CHROME_HTTPS_KEY));
+ Assert.assertEquals(bitmap, mCollector.getScreenshot());
}
private static ConnectivityTask.FeedbackData createFeedbackData() {

Powered by Google App Engine
This is Rietveld 408576698