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

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

Issue 2476563002: bluetooth: Fix crash when accepting location permission (Closed)
Patch Set: Address juncai's comments Created 4 years, 1 month 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
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3c35e6deed2171c2ae24cfcf0190d883d7a8376c..fd4967035356fc3d6fa5827b2d98358547e62fe3 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/BluetoothChooserDialogTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/BluetoothChooserDialogTest.java
@@ -64,17 +64,27 @@ public class BluetoothChooserDialogTest extends ChromeActivityTestCaseBase<Chrom
@Override
void nativeRestartSearch(long nativeBluetoothChooserAndroid) {
+ assertTrue(mNativeBluetoothChooserDialogPtr != 0);
mRestartSearchCount++;
}
@Override
- void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndroid) {}
+ void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndroid) {
+ // We shouldn't be running native functions if the native class has been destroyed.
+ assertTrue(mNativeBluetoothChooserDialogPtr != 0);
+ }
@Override
- void nativeShowBluetoothAdapterOffLink(long nativeBluetoothChooserAndroid) {}
+ void nativeShowBluetoothAdapterOffLink(long nativeBluetoothChooserAndroid) {
+ // We shouldn't be running native functions if the native class has been destroyed.
+ assertTrue(mNativeBluetoothChooserDialogPtr != 0);
+ }
@Override
- void nativeShowNeedLocationPermissionLink(long nativeBluetoothChooserAndroid) {}
+ void nativeShowNeedLocationPermissionLink(long nativeBluetoothChooserAndroid) {
+ // We shouldn't be running native functions if the native class has been destroyed.
+ assertTrue(mNativeBluetoothChooserDialogPtr != 0);
+ }
}
private ActivityWindowAndroid mWindowAndroid;
@@ -253,7 +263,7 @@ public class BluetoothChooserDialogTest extends ChromeActivityTestCaseBase<Chrom
final View progress = dialog.findViewById(R.id.progress);
final TestAndroidPermissionDelegate permissionDelegate =
- new TestAndroidPermissionDelegate();
+ new TestAndroidPermissionDelegate(dialog);
mWindowAndroid.setAndroidPermissionDelegate(permissionDelegate);
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@@ -296,11 +306,16 @@ public class BluetoothChooserDialogTest extends ChromeActivityTestCaseBase<Chrom
}
});
- assertEquals(1, mChooserDialog.mRestartSearchCount);
- assertEquals(removeLinkTags(getActivity().getString(R.string.bluetooth_searching)),
- statusView.getText().toString());
+ // TODO(661862): Remove once the dialog no longer closes when the window loses
+ // focus.
+ assertTrue(mChooserDialog.mFinishedEventType != -1);
- mChooserDialog.closeDialog();
+ // TODO(661862): Uncomment once the dialog no longer closes when the window
+ // loses focus.
+ // assertEquals(1, mChooserDialog.mRestartSearchCount);
+ // assertEquals(removeLinkTags(getActivity().getString(R.string.bluetooth_searching)),
+ // statusView.getText().toString());
+ // mChooserDialog.closeDialog();
}
@LargeTest
@@ -318,7 +333,7 @@ public class BluetoothChooserDialogTest extends ChromeActivityTestCaseBase<Chrom
final View progress = dialog.findViewById(R.id.progress);
final TestAndroidPermissionDelegate permissionDelegate =
- new TestAndroidPermissionDelegate();
+ new TestAndroidPermissionDelegate(dialog);
mWindowAndroid.setAndroidPermissionDelegate(permissionDelegate);
// Grant permissions, and turn off location services.
@@ -364,9 +379,14 @@ public class BluetoothChooserDialogTest extends ChromeActivityTestCaseBase<Chrom
// TODO(jyasskin): Test when the user denies Chrome the ability to ask for permission.
private static class TestAndroidPermissionDelegate implements AndroidPermissionDelegate {
+ Dialog mDialog = null;
PermissionCallback mCallback = null;
String[] mPermissionsRequested = null;
+ public TestAndroidPermissionDelegate(Dialog dialog) {
+ mDialog = dialog;
+ }
+
@Override
public boolean hasPermission(String permission) {
return false;
@@ -376,12 +396,16 @@ public class BluetoothChooserDialogTest extends ChromeActivityTestCaseBase<Chrom
public boolean canRequestPermission(String permission) {
return true;
}
+
@Override
public boolean isPermissionRevokedByPolicy(String permission) {
return false;
}
+
@Override
public void requestPermissions(String[] permissions, PermissionCallback callback) {
+ // Requesting for permission takes away focus from the window.
+ mDialog.onWindowFocusChanged(false /* hasFocus */);
mPermissionsRequested = permissions;
if (permissions.length == 1
&& permissions[0].equals(Manifest.permission.ACCESS_COARSE_LOCATION)) {
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698