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

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

Issue 2860843002: Revert of Reland: Convert ChromeActivityTestCaseBase direct children to JUnit4 (Closed)
Patch Set: Created 3 years, 8 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/BluetoothChooserDialogTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/BluetoothChooserDialogTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/BluetoothChooserDialogTest.java
index 66861f7fc44bfeae3ba56d602adbee76cc3101f3..7055c591b62f3c69b320a315914204f4577ac57d 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/BluetoothChooserDialogTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/BluetoothChooserDialogTest.java
@@ -15,19 +15,10 @@
import android.widget.Button;
import android.widget.ListView;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
import org.chromium.base.ThreadUtils;
-import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.R;
-import org.chromium.chrome.test.ChromeActivityTestRule;
-import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
+import org.chromium.chrome.test.ChromeActivityTestCaseBase;
import org.chromium.components.location.LocationUtils;
import org.chromium.components.security_state.ConnectionSecurityLevel;
import org.chromium.content.browser.test.util.Criteria;
@@ -44,11 +35,8 @@
/**
* Tests for the BluetoothChooserDialog class.
*/
-@RunWith(ChromeJUnit4ClassRunner.class)
@RetryOnFailure
-@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
- ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
-public class BluetoothChooserDialogTest {
+public class BluetoothChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActivity> {
/**
* Works like the BluetoothChooserDialog class, but records calls to native methods instead of
* calling back to C++.
@@ -66,8 +54,8 @@
@Override
void nativeOnDialogFinished(
long nativeBluetoothChooserAndroid, int eventType, String deviceId) {
- Assert.assertEquals(nativeBluetoothChooserAndroid, mNativeBluetoothChooserDialogPtr);
- Assert.assertEquals(mFinishedEventType, -1);
+ assertEquals(nativeBluetoothChooserAndroid, mNativeBluetoothChooserDialogPtr);
+ assertEquals(mFinishedEventType, -1);
mFinishedEventType = eventType;
mFinishedDeviceId = deviceId;
// The native code calls closeDialog() when OnDialogFinished is called.
@@ -76,26 +64,26 @@
@Override
void nativeRestartSearch(long nativeBluetoothChooserAndroid) {
- Assert.assertTrue(mNativeBluetoothChooserDialogPtr != 0);
+ assertTrue(mNativeBluetoothChooserDialogPtr != 0);
mRestartSearchCount++;
}
@Override
void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndroid) {
// We shouldn't be running native functions if the native class has been destroyed.
- Assert.assertTrue(mNativeBluetoothChooserDialogPtr != 0);
+ assertTrue(mNativeBluetoothChooserDialogPtr != 0);
}
@Override
void nativeShowBluetoothAdapterOffLink(long nativeBluetoothChooserAndroid) {
// We shouldn't be running native functions if the native class has been destroyed.
- Assert.assertTrue(mNativeBluetoothChooserDialogPtr != 0);
+ assertTrue(mNativeBluetoothChooserDialogPtr != 0);
}
@Override
void nativeShowNeedLocationPermissionLink(long nativeBluetoothChooserAndroid) {
// We shouldn't be running native functions if the native class has been destroyed.
- Assert.assertTrue(mNativeBluetoothChooserDialogPtr != 0);
+ assertTrue(mNativeBluetoothChooserDialogPtr != 0);
}
}
@@ -103,13 +91,15 @@
private FakeLocationUtils mLocationUtils;
private BluetoothChooserDialogWithFakeNatives mChooserDialog;
- @Rule
- public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
- new ChromeActivityTestRule<>(ChromeActivity.class);
-
- @Before
- public void setUp() throws Exception {
- mActivityTestRule.startMainActivityOnBlankPage();
+ public BluetoothChooserDialogTest() {
+ super(ChromeActivity.class);
+ }
+
+ // ChromeActivityTestCaseBase:
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
mLocationUtils = new FakeLocationUtils();
LocationUtils.setFactory(new LocationUtils.Factory() {
@Override
@@ -120,9 +110,15 @@
mChooserDialog = createDialog();
}
- @After
- public void tearDown() throws Exception {
+ @Override
+ protected void tearDown() throws Exception {
LocationUtils.setFactory(null);
+ super.tearDown();
+ }
+
+ @Override
+ public void startMainActivity() throws InterruptedException {
+ startMainActivityOnBlankPage();
}
private BluetoothChooserDialogWithFakeNatives createDialog() {
@@ -130,7 +126,7 @@
new Callable<BluetoothChooserDialogWithFakeNatives>() {
@Override
public BluetoothChooserDialogWithFakeNatives call() {
- mWindowAndroid = new ActivityWindowAndroid(mActivityTestRule.getActivity());
+ mWindowAndroid = new ActivityWindowAndroid(getActivity());
BluetoothChooserDialogWithFakeNatives dialog =
new BluetoothChooserDialogWithFakeNatives(mWindowAndroid,
"https://origin.example.com/",
@@ -154,7 +150,7 @@
}
});
- Assert.assertEquals("Not all items have a view; positions may be incorrect.",
+ assertEquals("Not all items have a view; positions may be incorrect.",
items.getChildCount(), items.getAdapter().getCount());
// Verify first item selected gets selected.
@@ -185,12 +181,11 @@
return message.replaceAll("</?[^>]*link[^>]*>", "");
}
- @Test
@LargeTest
public void testCancel() {
ItemChooserDialog itemChooser = mChooserDialog.mItemChooserDialog;
Dialog dialog = itemChooser.getDialogForTesting();
- Assert.assertTrue(dialog.isShowing());
+ assertTrue(dialog.isShowing());
TextViewWithClickableSpans statusView =
(TextViewWithClickableSpans) dialog.findViewById(R.id.status);
@@ -199,11 +194,10 @@
// Before we add items to the dialog, the 'searching' message should be
// showing, the Commit button should be disabled and the list view hidden.
- Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString(
- R.string.bluetooth_searching)),
- statusView.getText().toString());
- Assert.assertFalse(button.isEnabled());
- Assert.assertEquals(View.GONE, items.getVisibility());
+ assertEquals(removeLinkTags(getActivity().getString(R.string.bluetooth_searching)),
+ statusView.getText().toString());
+ assertFalse(button.isEnabled());
+ assertEquals(View.GONE, items.getVisibility());
dialog.dismiss();
@@ -214,12 +208,11 @@
}
});
- Assert.assertEquals(BluetoothChooserDialog.DIALOG_FINISHED_CANCELLED,
+ assertEquals(BluetoothChooserDialog.DIALOG_FINISHED_CANCELLED,
mChooserDialog.mFinishedEventType);
- Assert.assertEquals("", mChooserDialog.mFinishedDeviceId);
- }
-
- @Test
+ assertEquals("", mChooserDialog.mFinishedDeviceId);
+ }
+
@LargeTest
public void testSelectItem() {
Dialog dialog = mChooserDialog.mItemChooserDialog.getDialogForTesting();
@@ -252,40 +245,38 @@
// the progress spinner should disappear, the Commit button should still
// be disabled (since nothing's selected), and the list view should
// show.
- Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString(
- R.string.bluetooth_searching)),
- statusView.getText().toString());
- Assert.assertFalse(button.isEnabled());
- Assert.assertEquals(View.VISIBLE, items.getVisibility());
- Assert.assertEquals(View.GONE, progress.getVisibility());
+ assertEquals(removeLinkTags(getActivity().getString(R.string.bluetooth_searching)),
+ statusView.getText().toString());
+ assertFalse(button.isEnabled());
+ assertEquals(View.VISIBLE, items.getVisibility());
+ assertEquals(View.GONE, progress.getVisibility());
ItemChooserDialog.ItemAdapter itemAdapter =
mChooserDialog.mItemChooserDialog.getItemAdapterForTesting();
- Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
+ assertTrue(itemAdapter.getItem(0).hasSameContents(
"id-1", "Name 1", null /* icon */, null /* iconDescription */));
- Assert.assertTrue(itemAdapter.getItem(1).hasSameContents("id-2", "Name 2",
+ assertTrue(itemAdapter.getItem(1).hasSameContents("id-2", "Name 2",
mChooserDialog.mConnectedIcon, mChooserDialog.mConnectedIconDescription));
- Assert.assertTrue(itemAdapter.getItem(2).hasSameContents("id-3", "Name 3",
+ assertTrue(itemAdapter.getItem(2).hasSameContents("id-3", "Name 3",
mChooserDialog.mSignalStrengthLevelIcon[1],
- mActivityTestRule.getActivity().getResources().getQuantityString(
+ getActivity().getResources().getQuantityString(
R.plurals.signal_strength_level_n_bars, 1, 1)));
// We show the connected icon even if the device has a signal strength.
- Assert.assertTrue(itemAdapter.getItem(3).hasSameContents("id-4", "Name 4",
+ assertTrue(itemAdapter.getItem(3).hasSameContents("id-4", "Name 4",
mChooserDialog.mConnectedIcon, mChooserDialog.mConnectedIconDescription));
selectItem(mChooserDialog, 2);
- Assert.assertEquals(
+ assertEquals(
BluetoothChooserDialog.DIALOG_FINISHED_SELECTED, mChooserDialog.mFinishedEventType);
- Assert.assertEquals("id-2", mChooserDialog.mFinishedDeviceId);
- }
-
- @Test
+ assertEquals("id-2", mChooserDialog.mFinishedDeviceId);
+ }
+
@LargeTest
public void testNoLocationPermission() {
ItemChooserDialog itemChooser = mChooserDialog.mItemChooserDialog;
Dialog dialog = itemChooser.getDialogForTesting();
- Assert.assertTrue(dialog.isShowing());
+ assertTrue(dialog.isShowing());
final TextViewWithClickableSpans statusView =
(TextViewWithClickableSpans) dialog.findViewById(R.id.status);
@@ -307,16 +298,15 @@
}
});
- Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString(
- R.string.bluetooth_need_location_permission)),
+ assertEquals(removeLinkTags(
+ getActivity().getString(R.string.bluetooth_need_location_permission)),
errorView.getText().toString());
- Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString(
- R.string.bluetooth_adapter_off_help)),
- statusView.getText().toString());
- Assert.assertFalse(button.isEnabled());
- Assert.assertEquals(View.VISIBLE, errorView.getVisibility());
- Assert.assertEquals(View.GONE, items.getVisibility());
- Assert.assertEquals(View.GONE, progress.getVisibility());
+ assertEquals(removeLinkTags(getActivity().getString(R.string.bluetooth_adapter_off_help)),
+ statusView.getText().toString());
+ assertFalse(button.isEnabled());
+ assertEquals(View.VISIBLE, errorView.getVisibility());
+ assertEquals(View.GONE, items.getVisibility());
+ assertEquals(View.GONE, progress.getVisibility());
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
@@ -328,7 +318,7 @@
// Permission was requested.
MoreAsserts.assertEquals(permissionDelegate.mPermissionsRequested,
new String[] {Manifest.permission.ACCESS_COARSE_LOCATION});
- Assert.assertNotNull(permissionDelegate.mCallback);
+ assertNotNull(permissionDelegate.mCallback);
// Grant permission.
mLocationUtils.mLocationGranted = true;
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@@ -340,19 +330,17 @@
}
});
- Assert.assertEquals(1, mChooserDialog.mRestartSearchCount);
- Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString(
- R.string.bluetooth_searching)),
+ assertEquals(1, mChooserDialog.mRestartSearchCount);
+ assertEquals(removeLinkTags(getActivity().getString(R.string.bluetooth_searching)),
statusView.getText().toString());
mChooserDialog.closeDialog();
}
- @Test
@LargeTest
public void testNoLocationServices() {
ItemChooserDialog itemChooser = mChooserDialog.mItemChooserDialog;
Dialog dialog = itemChooser.getDialogForTesting();
- Assert.assertTrue(dialog.isShowing());
+ assertTrue(dialog.isShowing());
final TextViewWithClickableSpans statusView =
(TextViewWithClickableSpans) dialog.findViewById(R.id.status);
@@ -378,16 +366,16 @@
}
});
- Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString(
- R.string.bluetooth_need_location_services_on)),
+ assertEquals(removeLinkTags(
+ getActivity().getString(R.string.bluetooth_need_location_services_on)),
errorView.getText().toString());
- Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString(
- R.string.bluetooth_need_location_permission_help)),
- statusView.getText().toString());
- Assert.assertFalse(button.isEnabled());
- Assert.assertEquals(View.VISIBLE, errorView.getVisibility());
- Assert.assertEquals(View.GONE, items.getVisibility());
- Assert.assertEquals(View.GONE, progress.getVisibility());
+ assertEquals(removeLinkTags(getActivity().getString(
+ R.string.bluetooth_need_location_permission_help)),
+ statusView.getText().toString());
+ assertFalse(button.isEnabled());
+ assertEquals(View.VISIBLE, errorView.getVisibility());
+ assertEquals(View.GONE, items.getVisibility());
+ assertEquals(View.GONE, progress.getVisibility());
// Turn on Location Services.
mLocationUtils.mSystemLocationSettingsEnabled = true;
@@ -395,14 +383,12 @@
@Override
public void run() {
mChooserDialog.mLocationModeBroadcastReceiver.onReceive(
- mActivityTestRule.getActivity(),
- new Intent(LocationManager.MODE_CHANGED_ACTION));
- }
- });
-
- Assert.assertEquals(1, mChooserDialog.mRestartSearchCount);
- Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString(
- R.string.bluetooth_searching)),
+ getActivity(), new Intent(LocationManager.MODE_CHANGED_ACTION));
+ }
+ });
+
+ assertEquals(1, mChooserDialog.mRestartSearchCount);
+ assertEquals(removeLinkTags(getActivity().getString(R.string.bluetooth_searching)),
statusView.getText().toString());
mChooserDialog.closeDialog();
@@ -410,12 +396,11 @@
// TODO(jyasskin): Test when the user denies Chrome the ability to ask for permission.
- @Test
@LargeTest
public void testTurnOnAdapter() {
final ItemChooserDialog itemChooser = mChooserDialog.mItemChooserDialog;
Dialog dialog = itemChooser.getDialogForTesting();
- Assert.assertTrue(dialog.isShowing());
+ assertTrue(dialog.isShowing());
final TextViewWithClickableSpans statusView =
(TextViewWithClickableSpans) dialog.findViewById(R.id.status);
@@ -433,16 +418,14 @@
}
});
- Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString(
- R.string.bluetooth_adapter_off)),
+ assertEquals(removeLinkTags(getActivity().getString(R.string.bluetooth_adapter_off)),
errorView.getText().toString());
- Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString(
- R.string.bluetooth_adapter_off_help)),
- statusView.getText().toString());
- Assert.assertFalse(button.isEnabled());
- Assert.assertEquals(View.VISIBLE, errorView.getVisibility());
- Assert.assertEquals(View.GONE, items.getVisibility());
- Assert.assertEquals(View.GONE, progress.getVisibility());
+ assertEquals(removeLinkTags(getActivity().getString(R.string.bluetooth_adapter_off_help)),
+ statusView.getText().toString());
+ assertFalse(button.isEnabled());
+ assertEquals(View.VISIBLE, errorView.getVisibility());
+ assertEquals(View.GONE, items.getVisibility());
+ assertEquals(View.GONE, progress.getVisibility());
// Turn on adapter.
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@@ -452,9 +435,9 @@
}
});
- Assert.assertEquals(View.GONE, errorView.getVisibility());
- Assert.assertEquals(View.GONE, items.getVisibility());
- Assert.assertEquals(View.VISIBLE, progress.getVisibility());
+ assertEquals(View.GONE, errorView.getVisibility());
+ assertEquals(View.GONE, items.getVisibility());
+ assertEquals(View.VISIBLE, progress.getVisibility());
mChooserDialog.closeDialog();
}

Powered by Google App Engine
This is Rietveld 408576698