Chromium Code Reviews| 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..fd88024db3d5be6a8801dcd4c746c974f19805b4 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,21 +1,27 @@ |
| -// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| // 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.filters.SmallTest; |
| -import android.test.InstrumentationTestCase; |
| 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.junit.Test; |
|
jbudorick
2017/03/01 23:10:19
import order?
I'm surprised this wasn't flagged e
the real yoland
2017/03/08 23:35:31
Oops, my bad, I bypassed this one.
Fixed now
|
| +import org.chromium.base.test.BaseJUnit4ClassRunner; |
| +import org.junit.runner.RunWith; |
| +import android.support.test.InstrumentationRegistry; |
| +import org.junit.Assert; |
| +import org.junit.Before; |
| /** |
| * Test of BrowserStartupController |
| */ |
| -public class BrowserStartupControllerTest extends InstrumentationTestCase { |
| +@RunWith(BaseJUnit4ClassRunner.class) |
| +public class BrowserStartupControllerTest { |
| private TestBrowserStartupController mController; |
| @@ -84,9 +90,9 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase { |
| } |
| } |
| - @Override |
| - protected void setUp() throws Exception { |
| - super.setUp(); |
| + @Before |
| + |
|
jbudorick
2017/03/01 23:10:19
There shouldn't be a blank line here.
the real yoland
2017/03/08 23:35:31
Done, fixed for all tests
|
| + 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 +100,7 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase { |
| BrowserStartupController.overrideInstanceForTest(mController); |
| } |
| + @Test |
| @SmallTest |
| public void testSingleAsynchronousStartupRequest() { |
| mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; |
| @@ -107,25 +114,26 @@ 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,27 @@ 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 +205,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 +216,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 +239,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 +251,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 +277,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 +309,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 +320,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 +343,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 +355,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 +375,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 +400,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 +408,23 @@ 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 +438,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 +456,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, |
| + 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 +485,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(); |
| } |
| } |