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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/UrlManagerTest.java

Issue 2766373004: Convert the rest of chrome_public_test_apk InstrumentationTestCases to JUnit4 (Closed)
Patch Set: nits and rebase Created 3 years, 9 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/physicalweb/UrlManagerTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/UrlManagerTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/UrlManagerTest.java
index 4e2c8484782dfd1d8361ea5f2c1bc24e1317b700..265cc9718da846a09996bf15a5983ceae4b78464 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/UrlManagerTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/UrlManagerTest.java
@@ -5,13 +5,19 @@
package org.chromium.chrome.browser.physicalweb;
import android.content.SharedPreferences;
+import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
-import android.test.InstrumentationTestCase;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
import org.chromium.base.ContextUtils;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.FlakyTest;
import org.chromium.base.test.util.RetryOnFailure;
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
@@ -23,7 +29,8 @@ import java.util.Set;
/**
* Tests for {@link UrlManager}.
*/
-public class UrlManagerTest extends InstrumentationTestCase {
+@RunWith(ChromeJUnit4ClassRunner.class)
+public class UrlManagerTest {
private static final String URL1 = "https://example.com/";
private static final String TITLE1 = "Example";
private static final String DESC1 = "Example Website";
@@ -43,9 +50,8 @@ public class UrlManagerTest extends InstrumentationTestCase {
private UrlManager mUrlManager = null;
private MockPwsClient mMockPwsClient = null;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
ContextUtils.getAppSharedPreferences()
.edit()
.putInt(PREF_PHYSICAL_WEB, PHYSICAL_WEB_ON)
@@ -95,6 +101,7 @@ public class UrlManagerTest extends InstrumentationTestCase {
.apply();
}
+ @Test
@SmallTest
@RetryOnFailure
public void testAddUrlAfterClearAllUrlsWorks() {
@@ -104,17 +111,18 @@ public class UrlManagerTest extends InstrumentationTestCase {
addPwsResult2();
addUrlInfo1();
addUrlInfo2();
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
mUrlManager.clearAllUrls();
// Add some more URLs...this should not crash if we cleared correctly.
addUrlInfo1();
addUrlInfo2();
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
List<UrlInfo> urlInfos = mUrlManager.getUrls();
- assertEquals(2, urlInfos.size());
+ Assert.assertEquals(2, urlInfos.size());
}
+ @Test
@SmallTest
@RetryOnFailure
public void testClearNearbyUrlsWorks() {
@@ -122,23 +130,24 @@ public class UrlManagerTest extends InstrumentationTestCase {
addPwsResult2();
addUrlInfo1();
addUrlInfo2();
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
mUrlManager.clearNearbyUrls();
// Test that the URLs are not nearby, but do exist in the cache.
List<UrlInfo> urlInfos = mUrlManager.getUrls(true);
- assertEquals(0, urlInfos.size());
- assertTrue(mUrlManager.containsInAnyCache(URL1));
- assertTrue(mUrlManager.containsInAnyCache(URL2));
+ Assert.assertEquals(0, urlInfos.size());
+ Assert.assertTrue(mUrlManager.containsInAnyCache(URL1));
+ Assert.assertTrue(mUrlManager.containsInAnyCache(URL2));
mUrlManager.clearAllUrls();
// Test that cache is empty.
- assertFalse(mUrlManager.containsInAnyCache(URL1));
- assertFalse(mUrlManager.containsInAnyCache(URL2));
+ Assert.assertFalse(mUrlManager.containsInAnyCache(URL1));
+ Assert.assertFalse(mUrlManager.containsInAnyCache(URL2));
}
+ @Test
@SmallTest
@RetryOnFailure
public void testAddUrlGarbageCollectsForSize() throws Exception {
@@ -155,11 +164,12 @@ public class UrlManagerTest extends InstrumentationTestCase {
}
// Make our cache is missing the first URL and contains the others.
- assertFalse(mUrlManager.containsInAnyCache(URL1));
- assertTrue(mUrlManager.containsInAnyCache(URL1 + 1));
- assertTrue(mUrlManager.containsInAnyCache(URL1 + mUrlManager.getMaxCacheSize()));
+ Assert.assertFalse(mUrlManager.containsInAnyCache(URL1));
+ Assert.assertTrue(mUrlManager.containsInAnyCache(URL1 + 1));
+ Assert.assertTrue(mUrlManager.containsInAnyCache(URL1 + mUrlManager.getMaxCacheSize()));
}
+ @Test
@SmallTest
public void testAddUrlGarbageCollectsForAge() throws Exception {
// Add a URL with a phony timestamp.
@@ -173,10 +183,11 @@ public class UrlManagerTest extends InstrumentationTestCase {
mUrlManager.removeUrl(urlInfo2);
// Make sure only URL2 is still in the cache.
- assertFalse(mUrlManager.containsInAnyCache(URL1));
- assertTrue(mUrlManager.containsInAnyCache(URL2));
+ Assert.assertFalse(mUrlManager.containsInAnyCache(URL1));
+ Assert.assertTrue(mUrlManager.containsInAnyCache(URL2));
}
+ @Test
@SmallTest
public void testAddUrlUpdatesCache() throws Exception {
addEmptyPwsResult();
@@ -185,19 +196,20 @@ public class UrlManagerTest extends InstrumentationTestCase {
UrlInfo urlInfo = new UrlInfo(URL1);
mUrlManager.addUrl(urlInfo);
List<UrlInfo> urls = mUrlManager.getUrls(true);
- assertEquals(1, urls.size());
- assertEquals(urlInfo.getDistance(), urls.get(0).getDistance());
- assertEquals(urlInfo.getDeviceAddress(), urls.get(0).getDeviceAddress());
- assertEquals(urlInfo.getFirstSeenTimestamp(), urls.get(0).getFirstSeenTimestamp());
+ Assert.assertEquals(1, urls.size());
+ Assert.assertEquals(urlInfo.getDistance(), urls.get(0).getDistance(), 0);
+ Assert.assertEquals(urlInfo.getDeviceAddress(), urls.get(0).getDeviceAddress());
+ Assert.assertEquals(urlInfo.getFirstSeenTimestamp(), urls.get(0).getFirstSeenTimestamp());
urlInfo = new UrlInfo(URL1).setDistance(100.0).setDeviceAddress("00:11:22:33:AA:BB");
mUrlManager.addUrl(urlInfo);
urls = mUrlManager.getUrls(true);
- assertEquals(1, urls.size());
- assertEquals(urlInfo.getDistance(), urls.get(0).getDistance());
- assertEquals(urlInfo.getDeviceAddress(), urls.get(0).getDeviceAddress());
+ Assert.assertEquals(1, urls.size());
+ Assert.assertEquals(urlInfo.getDistance(), urls.get(0).getDistance(), 0);
+ Assert.assertEquals(urlInfo.getDeviceAddress(), urls.get(0).getDeviceAddress());
}
+ @Test
@SmallTest
@RetryOnFailure
public void testAddUrlTwiceWorks() throws Exception {
@@ -218,10 +230,11 @@ public class UrlManagerTest extends InstrumentationTestCase {
mUrlManager.removeUrl(urlInfo2);
// Make sure only URL2 is still in the cache.
- assertFalse(mUrlManager.containsInAnyCache(URL1));
- assertTrue(mUrlManager.containsInAnyCache(URL2));
+ Assert.assertFalse(mUrlManager.containsInAnyCache(URL1));
+ Assert.assertTrue(mUrlManager.containsInAnyCache(URL2));
}
+ @Test
@SmallTest
public void testGetUrlsSortsAndDedups() throws Exception {
// Construct results with matching group IDs and check that getUrls returns only the closest
@@ -236,23 +249,24 @@ public class UrlManagerTest extends InstrumentationTestCase {
mUrlManager.addUrl(new UrlInfo(URL3, 10.0, System.currentTimeMillis()));
mUrlManager.addUrl(new UrlInfo(URL4, 40.0, System.currentTimeMillis()));
mUrlManager.addUrl(new UrlInfo(URL5, 50.0, System.currentTimeMillis()));
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
// Make sure URLs are in order and duplicates are omitted.
List<UrlInfo> urlInfos = mUrlManager.getUrls();
- assertEquals(3, urlInfos.size());
- assertEquals(10.0, urlInfos.get(0).getDistance());
- assertEquals(URL3, urlInfos.get(0).getUrl());
- assertEquals(30.0, urlInfos.get(1).getDistance());
- assertEquals(URL1, urlInfos.get(1).getUrl());
- assertEquals(50.0, urlInfos.get(2).getDistance());
- assertEquals(URL5, urlInfos.get(2).getUrl());
+ Assert.assertEquals(3, urlInfos.size());
+ Assert.assertEquals(10.0, urlInfos.get(0).getDistance(), 0);
+ Assert.assertEquals(URL3, urlInfos.get(0).getUrl());
+ Assert.assertEquals(30.0, urlInfos.get(1).getDistance(), 0);
+ Assert.assertEquals(URL1, urlInfos.get(1).getUrl());
+ Assert.assertEquals(50.0, urlInfos.get(2).getDistance(), 0);
+ Assert.assertEquals(URL5, urlInfos.get(2).getUrl());
}
/*
* @SmallTest
* Bug=crbug.com/684148
*/
+ @Test
@DisabledTest
public void testSerializationWorksWithPoorlySerializedResult() throws Exception {
addPwsResult1();
@@ -260,7 +274,7 @@ public class UrlManagerTest extends InstrumentationTestCase {
long curTime = System.currentTimeMillis();
mUrlManager.addUrl(new UrlInfo(URL1, 99.5, curTime + 42));
mUrlManager.addUrl(new UrlInfo(URL2, 100.5, curTime + 43));
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
// Create an invalid serialization.
Set<String> serializedUrls = new HashSet<>();
@@ -274,11 +288,12 @@ public class UrlManagerTest extends InstrumentationTestCase {
// Make sure only the properly serialized URL is restored.
UrlManager urlManager = new UrlManager();
List<UrlInfo> urlInfos = urlManager.getUrls();
- assertEquals(0, urlInfos.size());
- assertTrue(urlManager.containsInAnyCache(URL1));
- assertTrue(urlManager.containsInAnyCache(URL2));
+ Assert.assertEquals(0, urlInfos.size());
+ Assert.assertTrue(urlManager.containsInAnyCache(URL1));
+ Assert.assertTrue(urlManager.containsInAnyCache(URL2));
}
+ @Test
@FlakyTest(message = "https://crbug.com/685471")
@SmallTest
@RetryOnFailure
@@ -288,18 +303,19 @@ public class UrlManagerTest extends InstrumentationTestCase {
long curTime = System.currentTimeMillis();
mUrlManager.addUrl(new UrlInfo(URL1, 99.5, curTime + 42));
mUrlManager.addUrl(new UrlInfo(URL2, 100.5, curTime + 43));
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
// Make sure all URLs are restored.
UrlManager urlManager = new UrlManager();
List<UrlInfo> urlInfos = urlManager.getUrls();
- assertEquals(0, urlInfos.size());
- assertTrue(urlManager.containsInAnyCache(URL1));
- assertTrue(urlManager.containsInAnyCache(URL2));
+ Assert.assertEquals(0, urlInfos.size());
+ Assert.assertTrue(urlManager.containsInAnyCache(URL1));
+ Assert.assertTrue(urlManager.containsInAnyCache(URL2));
Set<String> resolvedUrls = urlManager.getResolvedUrls();
- assertEquals(2, resolvedUrls.size());
+ Assert.assertEquals(2, resolvedUrls.size());
}
+ @Test
@SmallTest
@RetryOnFailure
public void testSerializationWorksWithGarbageCollection() throws Exception {
@@ -307,16 +323,17 @@ public class UrlManagerTest extends InstrumentationTestCase {
addPwsResult2();
mUrlManager.addUrl(new UrlInfo(URL1, 99.5, 42));
mUrlManager.addUrl(new UrlInfo(URL2, 100.5, 43));
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
// Make sure all URLs are restored.
UrlManager urlManager = new UrlManager();
List<UrlInfo> urlInfos = urlManager.getUrls();
- assertEquals(0, urlInfos.size());
+ Assert.assertEquals(0, urlInfos.size());
Set<String> resolvedUrls = urlManager.getResolvedUrls();
- assertEquals(0, resolvedUrls.size());
+ Assert.assertEquals(0, resolvedUrls.size());
}
+ @Test
@SmallTest
public void testUpgradeFromNone() throws Exception {
Set<String> oldResolvedUrls = new HashSet<String>();
@@ -345,7 +362,7 @@ public class UrlManagerTest extends InstrumentationTestCase {
}
}, 5000, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
- assertEquals(
+ Assert.assertEquals(
UrlManager.getVersion(), sharedPreferences.getInt(UrlManager.getVersionKey(), 0));
}
}

Powered by Google App Engine
This is Rietveld 408576698