summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornewt <newt@chromium.org>2016-02-01 16:06:45 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-02 00:07:43 +0000
commit913701b1fa2ea8a63f095454d8147d1a3b8262af (patch)
treec45a9682f3ec10dcf8227ef8e827f1c2135d31a3
parent09fd68866e3c016bd0f0ffca096039a22e235a60 (diff)
downloadchromium_src-913701b1fa2ea8a63f095454d8147d1a3b8262af.zip
chromium_src-913701b1fa2ea8a63f095454d8147d1a3b8262af.tar.gz
chromium_src-913701b1fa2ea8a63f095454d8147d1a3b8262af.tar.bz2
Convert NativePageFactoryTest to run using Robolectric.
Huzzah for way faster tests! These tests now take only 35ms to run. Review URL: https://codereview.chromium.org/1641353004 Cr-Commit-Position: refs/heads/master@{#372826}
-rw-r--r--chrome/android/BUILD.gn5
-rw-r--r--chrome/android/junit/src/org/chromium/chrome/browser/ntp/NativePageFactoryTest.java (renamed from chrome/android/javatests/src/org/chromium/chrome/browser/ntp/NativePageFactoryTest.java)71
2 files changed, 39 insertions, 37 deletions
diff --git a/chrome/android/BUILD.gn b/chrome/android/BUILD.gn
index 282800d..ff4bfda 100644
--- a/chrome/android/BUILD.gn
+++ b/chrome/android/BUILD.gn
@@ -275,11 +275,12 @@ junit_binary("chrome_junit_tests") {
"junit/src/org/chromium/chrome/browser/media/router/ChromeMediaRouterTestBase.java",
"junit/src/org/chromium/chrome/browser/media/router/cast/DiscoveryCallbackTest.java",
"junit/src/org/chromium/chrome/browser/media/router/cast/TestUtils.java",
+ "junit/src/org/chromium/chrome/browser/notifications/NotificationUIManagerUnitTest.java",
+ "junit/src/org/chromium/chrome/browser/ntp/NativePageFactoryTest.java",
"junit/src/org/chromium/chrome/browser/omaha/ResponseParserTest.java",
"junit/src/org/chromium/chrome/browser/omaha/VersionNumberTest.java",
- "junit/src/org/chromium/chrome/browser/util/NonThreadSafeTest.java",
- "junit/src/org/chromium/chrome/browser/notifications/NotificationUIManagerUnitTest.java",
"junit/src/org/chromium/chrome/browser/snackbar/SnackbarCollectionUnitTest.java",
+ "junit/src/org/chromium/chrome/browser/util/NonThreadSafeTest.java",
"junit/src/org/chromium/chrome/browser/webapps/WebappDataStorageTest.java",
"junit/src/org/chromium/chrome/browser/webapps/WebappRegistryTest.java",
]
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/NativePageFactoryTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/ntp/NativePageFactoryTest.java
index eacf6b0..fc557a0 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/NativePageFactoryTest.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/ntp/NativePageFactoryTest.java
@@ -5,9 +5,6 @@
package org.chromium.chrome.browser.ntp;
import android.app.Activity;
-import android.test.InstrumentationTestCase;
-import android.test.UiThreadTest;
-import android.test.suitebuilder.annotation.SmallTest;
import android.view.View;
import org.chromium.chrome.browser.NativePage;
@@ -15,11 +12,19 @@ import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.ntp.NativePageFactory.NativePageType;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
+import org.chromium.testing.local.LocalRobolectricTestRunner;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.annotation.Config;
/**
* Tests public methods in NativePageFactory.
*/
-public class NativePageFactoryTest extends InstrumentationTestCase {
+@RunWith(LocalRobolectricTestRunner.class)
+@Config(manifest = Config.NONE)
+public class NativePageFactoryTest {
private static class MockNativePage implements NativePage {
public final NativePageType type;
@@ -49,7 +54,7 @@ public class NativePageFactoryTest extends InstrumentationTestCase {
case RECENT_TABS:
return UrlConstants.RECENT_TABS_HOST;
default:
- fail("Unexpected NativePageType: " + type);
+ Assert.fail("Unexpected NativePageType: " + type);
return null;
}
}
@@ -148,15 +153,21 @@ public class NativePageFactoryTest extends InstrumentationTestCase {
return urlCombo.expectedType != NativePageType.RECENT_TABS;
}
+ @Before
+ public void setUp() {
+ NativePageFactory.setNativePageBuilderForTesting(new MockNativePageBuilder());
+ }
+
/**
* Ensures that NativePageFactory.isNativePageUrl() returns true for native page URLs.
*/
- private void runTestPostiveIsNativePageUrl() {
+ @Test
+ public void testPositiveIsNativePageUrl() {
for (UrlCombo urlCombo : VALID_URLS) {
String url = urlCombo.url;
- assertTrue(url, NativePageFactory.isNativePageUrl(url, false));
+ Assert.assertTrue(url, NativePageFactory.isNativePageUrl(url, false));
if (isValidInIncognito(urlCombo)) {
- assertTrue(url, NativePageFactory.isNativePageUrl(url, true));
+ Assert.assertTrue(url, NativePageFactory.isNativePageUrl(url, true));
}
}
}
@@ -165,10 +176,11 @@ public class NativePageFactoryTest extends InstrumentationTestCase {
* Ensures that NativePageFactory.isNativePageUrl() returns false for URLs that don't
* correspond to a native page.
*/
- private void runTestNegativeIsNativePageUrl() {
+ @Test
+ public void testNegativeIsNativePageUrl() {
for (String invalidUrl : INVALID_URLS) {
- assertFalse(invalidUrl, NativePageFactory.isNativePageUrl(invalidUrl, false));
- assertFalse(invalidUrl, NativePageFactory.isNativePageUrl(invalidUrl, true));
+ Assert.assertFalse(invalidUrl, NativePageFactory.isNativePageUrl(invalidUrl, false));
+ Assert.assertFalse(invalidUrl, NativePageFactory.isNativePageUrl(invalidUrl, true));
}
}
@@ -176,7 +188,8 @@ public class NativePageFactoryTest extends InstrumentationTestCase {
* Ensures that NativePageFactory.createNativePageForURL() returns a native page of the right
* type and reuses the candidate page if it's the right type.
*/
- private void runTestCreateNativePage() {
+ @Test
+ public void testCreateNativePage() {
NativePageType[] candidateTypes = new NativePageType[] { NativePageType.NONE,
NativePageType.NTP, NativePageType.BOOKMARKS, NativePageType.RECENT_TABS };
for (boolean isIncognito : new boolean[] {true, false}) {
@@ -190,13 +203,13 @@ public class NativePageFactoryTest extends InstrumentationTestCase {
String debugMessage = String.format(
"Failed test case: isIncognito=%s, urlCombo={%s,%s}, candidateType=%s",
isIncognito, urlCombo.url, urlCombo.expectedType, candidateType);
- assertNotNull(debugMessage, page);
- assertEquals(debugMessage, 1, page.updateForUrlCalls);
- assertEquals(debugMessage, urlCombo.expectedType, page.type);
+ Assert.assertNotNull(debugMessage, page);
+ Assert.assertEquals(debugMessage, 1, page.updateForUrlCalls);
+ Assert.assertEquals(debugMessage, urlCombo.expectedType, page.type);
if (candidateType == urlCombo.expectedType) {
- assertSame(debugMessage, candidate, page);
+ Assert.assertSame(debugMessage, candidate, page);
} else {
- assertNotSame(debugMessage, candidate, page);
+ Assert.assertNotSame(debugMessage, candidate, page);
}
}
}
@@ -207,31 +220,19 @@ public class NativePageFactoryTest extends InstrumentationTestCase {
* Ensures that NativePageFactory.createNativePageForURL() returns null for URLs that don't
* correspond to a native page.
*/
- private void runTestCreateNativePageWithInvalidUrl() {
+ @Test
+ public void testCreateNativePageWithInvalidUrl() {
for (UrlCombo urlCombo : VALID_URLS) {
if (!isValidInIncognito(urlCombo)) {
- assertNull(urlCombo.url, NativePageFactory.createNativePageForURL(urlCombo.url,
- null, null, null, null, true));
+ Assert.assertNull(urlCombo.url, NativePageFactory.createNativePageForURL(
+ urlCombo.url, null, null, null, null, true));
}
}
for (boolean isIncognito : new boolean[] {true, false}) {
for (String invalidUrl : INVALID_URLS) {
- assertNull(invalidUrl, NativePageFactory.createNativePageForURL(invalidUrl, null,
- null, null, null, isIncognito));
+ Assert.assertNull(invalidUrl, NativePageFactory.createNativePageForURL(invalidUrl,
+ null, null, null, null, isIncognito));
}
}
}
-
- /**
- * Runs all the runTest* methods defined above.
- */
- @SmallTest
- @UiThreadTest
- public void testNativePageFactory() {
- NativePageFactory.setNativePageBuilderForTesting(new MockNativePageBuilder());
- runTestPostiveIsNativePageUrl();
- runTestNegativeIsNativePageUrl();
- runTestCreateNativePage();
- runTestCreateNativePageWithInvalidUrl();
- }
}