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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageSavePageLaterEvaluationTest.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/offlinepages/OfflinePageSavePageLaterEvaluationTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageSavePageLaterEvaluationTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageSavePageLaterEvaluationTest.java
index 0a9240f53024700f882453e9e680854a3d2d604c..80d445034d13ab082904f2f09b91ca3881c1af05 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageSavePageLaterEvaluationTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageSavePageLaterEvaluationTest.java
@@ -10,6 +10,13 @@ import android.os.Environment;
import android.text.TextUtils;
import android.util.LongSparseArray;
+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.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
@@ -18,10 +25,12 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Manual;
import org.chromium.base.test.util.TimeoutScale;
import org.chromium.chrome.browser.ChromeActivity;
+import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.offlinepages.evaluation.OfflinePageEvaluationBridge;
import org.chromium.chrome.browser.offlinepages.evaluation.OfflinePageEvaluationBridge.OfflinePageEvaluationObserver;
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.components.offlinepages.BackgroundSavePageResult;
import java.io.BufferedReader;
@@ -33,7 +42,6 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -47,12 +55,19 @@ import java.util.concurrent.TimeUnit;
* record metrics (failure rate, time elapsed etc.) by writing metrics to a file on external
* storage. This will always use prerenderer.
*/
-@CommandLineFlags.Add({"disable-features=BackgroundLoader"})
-public class OfflinePageSavePageLaterEvaluationTest
- extends ChromeActivityTestCaseBase<ChromeActivity> {
+@RunWith(ChromeJUnit4ClassRunner.class)
+@CommandLineFlags.Add({"disable-features=BackgroundLoader",
+ ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
+ ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
+public class OfflinePageSavePageLaterEvaluationTest {
/**
* Class which is used to calculate time difference.
*/
+
+ @Rule
+ public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
+ new ChromeActivityTestRule<>(ChromeActivity.class);
+
static class TimeDelta {
public void setStartTime(Long startTime) {
mStartTime = startTime;
@@ -103,19 +118,15 @@ public class OfflinePageSavePageLaterEvaluationTest
private LongSparseArray<RequestMetadata> mRequestMetadata;
- public OfflinePageSavePageLaterEvaluationTest() {
- super(ChromeActivity.class);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
+ mActivityTestRule.startMainActivityOnBlankPage();
mRequestMetadata = new LongSparseArray<RequestMetadata>();
mCount = 0;
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
NotificationManager notificationManager =
(NotificationManager) ContextUtils.getApplicationContext().getSystemService(
Context.NOTIFICATION_SERVICE);
@@ -146,12 +157,6 @@ public class OfflinePageSavePageLaterEvaluationTest
"Timed out when clearing remaining requests!");
mBridge.closeLog();
mBridge.destroy();
- super.tearDown();
- }
-
- @Override
- public void startMainActivity() throws InterruptedException {
- startMainActivityOnBlankPage();
}
/**
@@ -212,7 +217,7 @@ public class OfflinePageSavePageLaterEvaluationTest
private void checkTrue(boolean condition, String message) {
if (!condition) {
log(TAG, message);
- fail();
+ Assert.fail();
}
}
@@ -232,7 +237,7 @@ public class OfflinePageSavePageLaterEvaluationTest
mBridge = new OfflinePageEvaluationBridge(
profile, useTestingScheduler, useBackgroundLoader);
if (mBridge == null) {
- fail("OfflinePageEvaluationBridge initialization failed!");
+ Assert.fail("OfflinePageEvaluationBridge initialization failed!");
return;
}
if (mBridge.isOfflinePageModelLoaded()) {
@@ -332,7 +337,7 @@ public class OfflinePageSavePageLaterEvaluationTest
private void processUrls(List<String> urls) throws InterruptedException, IOException {
if (mBridge == null) {
- fail("Test initialization error, aborting. No results would be written.");
+ Assert.fail("Test initialization error, aborting. No results would be written.");
return;
}
int count = 0;
@@ -369,7 +374,7 @@ public class OfflinePageSavePageLaterEvaluationTest
}
} catch (FileNotFoundException e) {
Log.e(TAG, e.getMessage(), e);
- fail(String.format("URL file %s is not found.", inputFilePath));
+ Assert.fail(String.format("URL file %s is not found.", inputFilePath));
}
}
@@ -497,11 +502,11 @@ public class OfflinePageSavePageLaterEvaluationTest
Boolean.parseBoolean(properties.getProperty("UseBackgroundLoader"));
} catch (FileNotFoundException e) {
Log.e(TAG, e.getMessage(), e);
- fail(String.format(
+ Assert.fail(String.format(
"Config file %s is not found, aborting the test.", CONFIG_FILE_PATH));
} catch (NumberFormatException e) {
Log.e(TAG, e.getMessage(), e);
- fail("Error parsing config file, aborting test.");
+ Assert.fail("Error parsing config file, aborting test.");
} finally {
if (inputStream != null) {
inputStream.close();
@@ -518,10 +523,10 @@ public class OfflinePageSavePageLaterEvaluationTest
* immediate processing also works on svelte devices. This flag will *not* affect normal
* devices.
*/
+ @Test
@Manual
@TimeoutScale(4)
- @CommandLineFlags
- .Add({"enable-features=OfflinePagesSvelteConcurrentLoading"})
+ @CommandLineFlags.Add({"enable-features=OfflinePagesSvelteConcurrentLoading"})
@CommandLineFlags.Remove({"disable-features=OfflinePagesSvelteConcurrentLoading"})
public void testFailureRate() throws IOException, InterruptedException {
parseConfigFile();
@@ -535,12 +540,12 @@ public class OfflinePageSavePageLaterEvaluationTest
* immediate processing also works on svelte devices. This flag will *not* affect normal
* devices.
*/
+ @Test
@Manual
@TimeoutScale(4)
- @CommandLineFlags
- .Add({"enable-features=BackgroundLoader,OfflinePagesSvelteConcurrentLoading"})
- @CommandLineFlags
- .Remove({"disable-features=BackgroundLoader,OfflinePagesSvelteConcurrentLoading"})
+ @CommandLineFlags.Add({"enable-features=BackgroundLoaderOfflinePagesSvelteConcurrentLoading"})
+ @CommandLineFlags.Remove({
+ "disable-features=BackgroundLoaderOfflinePagesSvelteConcurrentLoading"})
public void testBackgroundLoaderFailureRate() throws IOException, InterruptedException {
testFailureRate();
}

Powered by Google App Engine
This is Rietveld 408576698