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

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/BrowserStartupControllerTest.java

Issue 2708243004: Auto convert content shell tests to JUnit4 (Closed)
Patch Set: New test added from WebContentsTest 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: content/public/android/javatests/src/org/chromium/content/browser/BrowserStartupControllerTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/BrowserStartupControllerTest.java b/content/public/android/javatests/src/org/chromium/content/browser/BrowserStartupControllerTest.java
index c1276c8c39d6c83b0b8f15420920dab04198f5a1..7bd36f3610ca802c096734c49423fa4501d6dca2 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/BrowserStartupControllerTest.java
+++ b/content/public/android/javatests/src/org/chromium/content/browser/BrowserStartupControllerTest.java
@@ -1,22 +1,28 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors. All rights reserved.
boliu 2017/03/10 18:32:32 don't modify date
the real yoland 2017/03/10 19:31:58 Done
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.content.browser;
+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.ThreadUtils;
import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.base.library_loader.LoaderErrors;
import org.chromium.base.library_loader.ProcessInitException;
+import org.chromium.base.test.BaseJUnit4ClassRunner;
/**
* Test of BrowserStartupController
*/
-public class BrowserStartupControllerTest extends InstrumentationTestCase {
-
+@RunWith(BaseJUnit4ClassRunner.class)
+public class BrowserStartupControllerTest {
private TestBrowserStartupController mController;
private static class TestBrowserStartupController extends BrowserStartupController {
@@ -84,9 +90,8 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
}
}
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
mController = new TestBrowserStartupController();
// Setting the static singleton instance field enables more correct testing, since it is
// is possible to call {@link BrowserStartupController#browserStartupComplete(int)} instead
@@ -94,6 +99,7 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
BrowserStartupController.overrideInstanceForTest(mController);
}
+ @Test
@SmallTest
public void testSingleAsynchronousStartupRequest() {
mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS;
@@ -107,25 +113,27 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
try {
mController.startBrowserProcessesAsync(true, callback);
} catch (Exception e) {
- fail("Browser should have started successfully");
+ Assert.fail("Browser should have started successfully");
}
}
});
- assertTrue("Asynchronous mode should have been set.",
+ Assert.assertTrue("Asynchronous mode should have been set.",
BrowserStartupController.browserMayStartAsynchonously());
- assertEquals("The browser process should have been initialized one time.", 1,
+ Assert.assertEquals("The browser process should have been initialized one time.", 1,
mController.initializedCounter());
// Wait for callbacks to complete.
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
- assertTrue("Callback should have been executed.", callback.mHasStartupResult);
- assertTrue("Callback should have been a success.", callback.mWasSuccess);
- assertFalse("Callback should be told that the browser process was not already started.",
+ Assert.assertTrue("Callback should have been executed.", callback.mHasStartupResult);
+ Assert.assertTrue("Callback should have been a success.", callback.mWasSuccess);
+ Assert.assertFalse(
+ "Callback should be told that the browser process was not already started.",
callback.mAlreadyStarted);
}
+ @Test
@SmallTest
public void testMultipleAsynchronousStartupRequests() {
mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS;
@@ -141,7 +149,7 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
try {
mController.startBrowserProcessesAsync(true, callback1);
} catch (Exception e) {
- fail("Browser should have started successfully");
+ Assert.fail("Browser should have started successfully");
}
}
});
@@ -151,7 +159,7 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
try {
mController.startBrowserProcessesAsync(true, callback2);
} catch (Exception e) {
- fail("Browser should have started successfully");
+ Assert.fail("Browser should have started successfully");
}
}
});
@@ -162,26 +170,28 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
}
});
- assertTrue("Asynchronous mode should have been set.",
+ Assert.assertTrue("Asynchronous mode should have been set.",
BrowserStartupController.browserMayStartAsynchonously());
- assertEquals("The browser process should have been initialized one time.", 1,
+ Assert.assertEquals("The browser process should have been initialized one time.", 1,
mController.initializedCounter());
// Wait for callbacks to complete.
- getInstrumentation().waitForIdleSync();
-
- assertTrue("Callback 1 should have been executed.", callback1.mHasStartupResult);
- assertTrue("Callback 1 should have been a success.", callback1.mWasSuccess);
- assertTrue("Callback 2 should have been executed.", callback2.mHasStartupResult);
- assertTrue("Callback 2 should have been a success.", callback2.mWasSuccess);
- assertTrue("Callback 3 should have been executed.", callback3.mHasStartupResult);
- assertTrue("Callback 3 should have been a success.", callback3.mWasSuccess);
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
+
+ Assert.assertTrue("Callback 1 should have been executed.", callback1.mHasStartupResult);
+ Assert.assertTrue("Callback 1 should have been a success.", callback1.mWasSuccess);
+ Assert.assertTrue("Callback 2 should have been executed.", callback2.mHasStartupResult);
+ Assert.assertTrue("Callback 2 should have been a success.", callback2.mWasSuccess);
+ Assert.assertTrue("Callback 3 should have been executed.", callback3.mHasStartupResult);
+ Assert.assertTrue("Callback 3 should have been a success.", callback3.mWasSuccess);
// Some startup tasks might have been enqueued after the browser process was started, but
// not the first one which kicked of the startup.
- assertFalse("Callback 1 should be told that the browser process was not already started.",
+ Assert.assertFalse(
+ "Callback 1 should be told that the browser process was not already started.",
callback1.mAlreadyStarted);
}
+ @Test
@SmallTest
public void testConsecutiveAsynchronousStartupRequests() {
mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS;
@@ -196,7 +206,7 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
try {
mController.startBrowserProcessesAsync(true, callback1);
} catch (Exception e) {
- fail("Browser should have started successfully");
+ Assert.fail("Browser should have started successfully");
}
}
});
@@ -207,18 +217,18 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
}
});
- assertTrue("Asynchronous mode should have been set.",
+ Assert.assertTrue("Asynchronous mode should have been set.",
BrowserStartupController.browserMayStartAsynchonously());
- assertEquals("The browser process should have been initialized one time.", 1,
+ Assert.assertEquals("The browser process should have been initialized one time.", 1,
mController.initializedCounter());
// Wait for callbacks to complete.
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
- assertTrue("Callback 1 should have been executed.", callback1.mHasStartupResult);
- assertTrue("Callback 1 should have been a success.", callback1.mWasSuccess);
- assertTrue("Callback 2 should have been executed.", callback2.mHasStartupResult);
- assertTrue("Callback 2 should have been a success.", callback2.mWasSuccess);
+ Assert.assertTrue("Callback 1 should have been executed.", callback1.mHasStartupResult);
+ Assert.assertTrue("Callback 1 should have been a success.", callback1.mWasSuccess);
+ Assert.assertTrue("Callback 2 should have been executed.", callback2.mHasStartupResult);
+ Assert.assertTrue("Callback 2 should have been a success.", callback2.mWasSuccess);
final TestStartupCallback callback3 = new TestStartupCallback();
final TestStartupCallback callback4 = new TestStartupCallback();
@@ -230,7 +240,7 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
try {
mController.startBrowserProcessesAsync(true, callback3);
} catch (Exception e) {
- fail("Browser should have started successfully");
+ Assert.fail("Browser should have started successfully");
}
}
});
@@ -242,18 +252,19 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
});
// Wait for callbacks to complete.
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
- assertTrue("Callback 3 should have been executed.", callback3.mHasStartupResult);
- assertTrue("Callback 3 should have been a success.", callback3.mWasSuccess);
- assertTrue("Callback 3 should be told that the browser process was already started.",
+ Assert.assertTrue("Callback 3 should have been executed.", callback3.mHasStartupResult);
+ Assert.assertTrue("Callback 3 should have been a success.", callback3.mWasSuccess);
+ Assert.assertTrue("Callback 3 should be told that the browser process was already started.",
callback3.mAlreadyStarted);
- assertTrue("Callback 4 should have been executed.", callback4.mHasStartupResult);
- assertTrue("Callback 4 should have been a success.", callback4.mWasSuccess);
- assertTrue("Callback 4 should be told that the browser process was already started.",
+ Assert.assertTrue("Callback 4 should have been executed.", callback4.mHasStartupResult);
+ Assert.assertTrue("Callback 4 should have been a success.", callback4.mWasSuccess);
+ Assert.assertTrue("Callback 4 should be told that the browser process was already started.",
callback4.mAlreadyStarted);
}
+ @Test
@SmallTest
public void testSingleFailedAsynchronousStartupRequest() {
mController.mStartupResult = BrowserStartupController.STARTUP_FAILURE;
@@ -267,23 +278,24 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
try {
mController.startBrowserProcessesAsync(true, callback);
} catch (Exception e) {
- fail("Browser should have started successfully");
+ Assert.fail("Browser should have started successfully");
}
}
});
- assertTrue("Asynchronous mode should have been set.",
+ Assert.assertTrue("Asynchronous mode should have been set.",
BrowserStartupController.browserMayStartAsynchonously());
- assertEquals("The browser process should have been initialized one time.", 1,
+ Assert.assertEquals("The browser process should have been initialized one time.", 1,
mController.initializedCounter());
// Wait for callbacks to complete.
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
- assertTrue("Callback should have been executed.", callback.mHasStartupResult);
- assertTrue("Callback should have been a failure.", callback.mWasFailure);
+ Assert.assertTrue("Callback should have been executed.", callback.mHasStartupResult);
+ Assert.assertTrue("Callback should have been a failure.", callback.mWasFailure);
}
+ @Test
@SmallTest
public void testConsecutiveFailedAsynchronousStartupRequests() {
mController.mStartupResult = BrowserStartupController.STARTUP_FAILURE;
@@ -298,7 +310,7 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
try {
mController.startBrowserProcessesAsync(true, callback1);
} catch (Exception e) {
- fail("Browser should have started successfully");
+ Assert.fail("Browser should have started successfully");
}
}
});
@@ -309,18 +321,18 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
}
});
- assertTrue("Asynchronous mode should have been set.",
+ Assert.assertTrue("Asynchronous mode should have been set.",
BrowserStartupController.browserMayStartAsynchonously());
- assertEquals("The browser process should have been initialized one time.", 1,
+ Assert.assertEquals("The browser process should have been initialized one time.", 1,
mController.initializedCounter());
// Wait for callbacks to complete.
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
- assertTrue("Callback 1 should have been executed.", callback1.mHasStartupResult);
- assertTrue("Callback 1 should have been a failure.", callback1.mWasFailure);
- assertTrue("Callback 2 should have been executed.", callback2.mHasStartupResult);
- assertTrue("Callback 2 should have been a failure.", callback2.mWasFailure);
+ Assert.assertTrue("Callback 1 should have been executed.", callback1.mHasStartupResult);
+ Assert.assertTrue("Callback 1 should have been a failure.", callback1.mWasFailure);
+ Assert.assertTrue("Callback 2 should have been executed.", callback2.mHasStartupResult);
+ Assert.assertTrue("Callback 2 should have been a failure.", callback2.mWasFailure);
final TestStartupCallback callback3 = new TestStartupCallback();
final TestStartupCallback callback4 = new TestStartupCallback();
@@ -332,7 +344,7 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
try {
mController.startBrowserProcessesAsync(true, callback3);
} catch (Exception e) {
- fail("Browser should have started successfully");
+ Assert.fail("Browser should have started successfully");
}
}
});
@@ -344,14 +356,15 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
});
// Wait for callbacks to complete.
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
- assertTrue("Callback 3 should have been executed.", callback3.mHasStartupResult);
- assertTrue("Callback 3 should have been a failure.", callback3.mWasFailure);
- assertTrue("Callback 4 should have been executed.", callback4.mHasStartupResult);
- assertTrue("Callback 4 should have been a failure.", callback4.mWasFailure);
+ Assert.assertTrue("Callback 3 should have been executed.", callback3.mHasStartupResult);
+ Assert.assertTrue("Callback 3 should have been a failure.", callback3.mWasFailure);
+ Assert.assertTrue("Callback 4 should have been executed.", callback4.mHasStartupResult);
+ Assert.assertTrue("Callback 4 should have been a failure.", callback4.mWasFailure);
}
+ @Test
@SmallTest
public void testSingleSynchronousRequest() {
mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS;
@@ -363,17 +376,18 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
try {
mController.startBrowserProcessesSync(false);
} catch (Exception e) {
- fail("Browser should have started successfully");
+ Assert.fail("Browser should have started successfully");
}
}
});
- assertFalse("Synchronous mode should have been set",
+ Assert.assertFalse("Synchronous mode should have been set",
BrowserStartupController.browserMayStartAsynchonously());
- assertEquals("The browser process should have been initialized one time.", 1,
+ Assert.assertEquals("The browser process should have been initialized one time.", 1,
mController.initializedCounter());
}
+ @Test
@SmallTest
public void testAsyncThenSyncRequests() {
mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS;
@@ -387,7 +401,7 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
try {
mController.startBrowserProcessesAsync(true, callback);
} catch (Exception e) {
- fail("Browser should have started successfully");
+ Assert.fail("Browser should have started successfully");
}
// To ensure that the async startup doesn't complete too soon we have
// to do both these in a since Runnable instance. This avoids the
@@ -395,22 +409,24 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
try {
mController.startBrowserProcessesSync(false);
} catch (Exception e) {
- fail("Browser should have started successfully");
+ Assert.fail("Browser should have started successfully");
}
}
});
- assertFalse("Synchronous mode should have been set",
+ Assert.assertFalse("Synchronous mode should have been set",
BrowserStartupController.browserMayStartAsynchonously());
- assertEquals("The browser process should have been initialized twice.", 2,
+ Assert.assertEquals("The browser process should have been initialized twice.", 2,
mController.initializedCounter());
- assertTrue("Callback should have been executed.", callback.mHasStartupResult);
- assertTrue("Callback should have been a success.", callback.mWasSuccess);
- assertFalse("Callback should be told that the browser process was not already started.",
+ Assert.assertTrue("Callback should have been executed.", callback.mHasStartupResult);
+ Assert.assertTrue("Callback should have been a success.", callback.mWasSuccess);
+ Assert.assertFalse(
+ "Callback should be told that the browser process was not already started.",
callback.mAlreadyStarted);
}
+ @Test
@SmallTest
public void testSyncThenAsyncRequests() {
mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS;
@@ -424,15 +440,15 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
try {
mController.startBrowserProcessesSync(false);
} catch (Exception e) {
- fail("Browser should have started successfully");
+ Assert.fail("Browser should have started successfully");
}
}
});
- assertEquals("The browser process should have been initialized once.", 1,
+ Assert.assertEquals("The browser process should have been initialized once.", 1,
mController.initializedCounter());
- assertFalse("Synchronous mode should have been set",
+ Assert.assertFalse("Synchronous mode should have been set",
BrowserStartupController.browserMayStartAsynchonously());
// Kick off the asynchronous startup request. This should just queue the callback.
@@ -442,23 +458,24 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
try {
mController.startBrowserProcessesAsync(true, callback);
} catch (Exception e) {
- fail("Browser should have started successfully");
+ Assert.fail("Browser should have started successfully");
}
}
});
- assertEquals("The browser process should not have been initialized a second time.", 1,
- mController.initializedCounter());
+ Assert.assertEquals("The browser process should not have been initialized a second time.",
+ 1, mController.initializedCounter());
// Wait for callbacks to complete.
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
- assertTrue("Callback should have been executed.", callback.mHasStartupResult);
- assertTrue("Callback should have been a success.", callback.mWasSuccess);
- assertTrue("Callback should be told that the browser process was already started.",
+ Assert.assertTrue("Callback should have been executed.", callback.mHasStartupResult);
+ Assert.assertTrue("Callback should have been a success.", callback.mWasSuccess);
+ Assert.assertTrue("Callback should be told that the browser process was already started.",
callback.mAlreadyStarted);
}
+ @Test
@SmallTest
public void testLibraryLoadFails() {
mController.mLibraryLoadSucceeds = false;
@@ -470,18 +487,18 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase {
public void run() {
try {
mController.startBrowserProcessesAsync(true, callback);
- fail("Browser should not have started successfully");
+ Assert.fail("Browser should not have started successfully");
} catch (Exception e) {
// Exception expected, ignore.
}
}
});
- assertEquals("The browser process should not have been initialized.", 0,
+ Assert.assertEquals("The browser process should not have been initialized.", 0,
mController.initializedCounter());
// Wait for callbacks to complete.
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
}
}

Powered by Google App Engine
This is Rietveld 408576698