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

Unified Diff: chrome/android/junit/src/org/chromium/chrome/browser/gcore/GoogleApiClientHelperTest.java

Issue 2239003002: Revert of [Android] Update all Robolectric tests to Robolectric 3.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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/junit/src/org/chromium/chrome/browser/gcore/GoogleApiClientHelperTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/gcore/GoogleApiClientHelperTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/gcore/GoogleApiClientHelperTest.java
index 270fc670fbcec9f48f2a287e2bf124000ebf8205..cc8e786735c47d198937b35400faa160e5606c8f 100644
--- a/chrome/android/junit/src/org/chromium/chrome/browser/gcore/GoogleApiClientHelperTest.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/gcore/GoogleApiClientHelperTest.java
@@ -23,8 +23,8 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
import org.robolectric.annotation.Config;
-import org.robolectric.shadows.ShadowLooper;
/**
* Tests for {@link GoogleApiClientHelper}
@@ -52,14 +52,16 @@
@Feature({"GCore"})
public void connectionAttemptDelayTest() {
GoogleApiClientHelper helper = new GoogleApiClientHelper(mMockClient);
-
- ShadowLooper.pauseMainLooper();
- helper.onConnectionFailed(new ConnectionResult(ConnectionResult.SERVICE_UPDATING));
- verify(mMockClient, times(0)).connect();
- ShadowLooper.unPauseMainLooper();
-
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
- verify(mMockClient, times(1)).connect();
+ ConnectionResult mockResult = mock(ConnectionResult.class);
+ when(mockResult.getErrorCode()).thenReturn(ConnectionResult.SERVICE_UPDATING);
+
+ Robolectric.pauseMainLooper();
+ helper.onConnectionFailed(mockResult);
+ verify(mMockClient, never()).connect();
+ Robolectric.unPauseMainLooper();
+
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
+ verify(mMockClient).connect();
}
/** Tests that the connection handler gives up after a number of connection attempts. */
@@ -68,24 +70,28 @@
public void connectionFailureTest() {
GoogleApiClientHelper helper = new GoogleApiClientHelper(mMockClient);
- helper.onConnectionFailed(new ConnectionResult(ConnectionResult.DEVELOPER_ERROR));
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
+ ConnectionResult mockResult = mock(ConnectionResult.class);
+ when(mockResult.getErrorCode()).thenReturn(ConnectionResult.DEVELOPER_ERROR);
+
+ helper.onConnectionFailed(mockResult);
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
// Should not retry on unrecoverable errors
verify(mMockClient, never()).connect();
// Connection attempts
+ when(mockResult.getErrorCode()).thenReturn(ConnectionResult.SERVICE_UPDATING);
for (int i = 0; i < ConnectedTask.RETRY_NUMBER_LIMIT; i++) {
- helper.onConnectionFailed(new ConnectionResult(ConnectionResult.SERVICE_UPDATING));
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
+ helper.onConnectionFailed(mockResult);
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
}
// Should have tried to connect every time.
verify(mMockClient, times(ConnectedTask.RETRY_NUMBER_LIMIT)).connect();
// Try again
- helper.onConnectionFailed(new ConnectionResult(ConnectionResult.SERVICE_UPDATING));
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
+ helper.onConnectionFailed(mockResult);
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
// The connection handler should have given up, no new call.
verify(mMockClient, times(ConnectedTask.RETRY_NUMBER_LIMIT)).connect();
@@ -96,11 +102,13 @@
@Feature({"GCore"})
public void connectionAttemptsResetTest() {
GoogleApiClientHelper helper = new GoogleApiClientHelper(mMockClient);
+ ConnectionResult mockResult = mock(ConnectionResult.class);
+ when(mockResult.getErrorCode()).thenReturn(ConnectionResult.SERVICE_UPDATING);
// Connection attempts
for (int i = 0; i < ConnectedTask.RETRY_NUMBER_LIMIT - 1; i++) {
- helper.onConnectionFailed(new ConnectionResult(ConnectionResult.SERVICE_UPDATING));
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
+ helper.onConnectionFailed(mockResult);
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
}
// Should have tried to connect every time.
@@ -108,19 +116,19 @@
// Connection successful now
helper.onConnected(null);
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
for (int i = 0; i < ConnectedTask.RETRY_NUMBER_LIMIT; i++) {
- helper.onConnectionFailed(new ConnectionResult(ConnectionResult.SERVICE_UPDATING));
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
+ helper.onConnectionFailed(mockResult);
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
}
// A success should allow for more connection attempts.
verify(mMockClient, times(ConnectedTask.RETRY_NUMBER_LIMIT * 2 - 1)).connect();
// This should not result in a connection attempt, the limit is still there.
- helper.onConnectionFailed(new ConnectionResult(ConnectionResult.SERVICE_UPDATING));
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
+ helper.onConnectionFailed(mockResult);
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
// The connection handler should have given up, no new call.
verify(mMockClient, times(ConnectedTask.RETRY_NUMBER_LIMIT * 2 - 1)).connect();
@@ -130,7 +138,7 @@
@Feature({"GCore"})
public void lifecycleManagementTest() {
GoogleApiClientHelper helper = new GoogleApiClientHelper(mMockClient);
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
Activity mockActivity = mock(Activity.class);
ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.CREATED);
@@ -147,8 +155,8 @@
// Should be disconnected when we go in the background
ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STOPPED);
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
- verify(mMockClient, times(1)).disconnect();
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
+ verify(mMockClient).disconnect();
// Should be reconnected when we come in the foreground
ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STARTED);
@@ -169,7 +177,7 @@
@Feature({"GCore"})
public void lifecycleManagementDelayTest() {
GoogleApiClientHelper helper = new GoogleApiClientHelper(mMockClient);
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
Activity mockActivity = mock(Activity.class);
ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.CREATED);
helper.setDisconnectionDelay(5000);
@@ -179,12 +187,12 @@
// Should not be disconnected when we go in the background
ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STOPPED);
- ShadowLooper.runUiThreadTasks();
- verify(mMockClient, times(0)).disconnect();
+ Robolectric.runUiThreadTasks();
+ verify(mMockClient, never()).disconnect();
// Should be disconnected when we wait.
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
- verify(mMockClient, times(1)).disconnect();
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
+ verify(mMockClient).disconnect();
// Should be reconnected when we come in the foreground
ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STARTED);
@@ -192,11 +200,11 @@
// Should not disconnect when we became visible during the delay
ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STOPPED);
- ShadowLooper.runUiThreadTasks();
- verify(mMockClient, times(1)).disconnect();
- ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STARTED);
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
- verify(mMockClient, times(1)).disconnect();
+ Robolectric.runUiThreadTasks();
+ verify(mMockClient).disconnect();
+ ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STARTED);
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
+ verify(mMockClient).disconnect();
}
@Test
@@ -204,7 +212,7 @@
public void disconnectionCancellingTest() {
int disconnectionTimeout = 5000;
GoogleApiClientHelper helper = new GoogleApiClientHelper(mMockClient);
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
Activity mockActivity = mock(Activity.class);
ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.CREATED);
helper.setDisconnectionDelay(disconnectionTimeout);
@@ -214,9 +222,9 @@
// We go in the background and come back before the end of the timeout.
ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STOPPED);
- ShadowLooper.idleMainLooper(disconnectionTimeout - 42);
- ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STARTED);
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
+ Robolectric.idleMainLooper(disconnectionTimeout - 42);
+ ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STARTED);
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
// The client should not have been disconnected, which would drop requests otherwise.
verify(mMockClient, never()).disconnect();
@@ -228,7 +236,7 @@
int disconnectionTimeout = 5000;
int arbitraryNumberOfSeconds = 42;
GoogleApiClientHelper helper = new GoogleApiClientHelper(mMockClient);
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
Activity mockActivity = mock(Activity.class);
ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.CREATED);
helper.setDisconnectionDelay(disconnectionTimeout);
@@ -238,15 +246,15 @@
// We go in the background and extend the delay
ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STOPPED);
- ShadowLooper.idleMainLooper(disconnectionTimeout - arbitraryNumberOfSeconds);
+ Robolectric.idleMainLooper(disconnectionTimeout - arbitraryNumberOfSeconds);
helper.willUseConnection();
// The client should not have been disconnected.
- ShadowLooper.idleMainLooper(disconnectionTimeout - arbitraryNumberOfSeconds);
+ Robolectric.idleMainLooper(disconnectionTimeout - arbitraryNumberOfSeconds);
verify(mMockClient, never()).disconnect();
// After the full timeout it should still disconnect though
- ShadowLooper.idleMainLooper(arbitraryNumberOfSeconds);
+ Robolectric.idleMainLooper(arbitraryNumberOfSeconds);
verify(mMockClient).disconnect();
// The client is now disconnected then
@@ -261,7 +269,7 @@
@Feature({"GCore"})
public void willUseConnectionForegroundTest() {
GoogleApiClientHelper helper = new GoogleApiClientHelper(mMockClient);
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
Activity mockActivity = mock(Activity.class);
ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.CREATED);
helper.setDisconnectionDelay(5000);
@@ -271,11 +279,11 @@
// We are in the foreground
ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STARTED);
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
// Disconnections should not be scheduled when in the foreground.
helper.willUseConnection();
- ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
+ Robolectric.runUiThreadTasksIncludingDelayedTasks();
verify(mMockClient, never()).disconnect();
}
}

Powered by Google App Engine
This is Rietveld 408576698