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 2e555f5daecc66d3b2f6fdfedeea20178a588579..9c7a7cda798c98adf4712ed7e95e026f7563d66d 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/BluetoothChooserDialogTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/BluetoothChooserDialogTest.java |
@@ -6,7 +6,10 @@ package org.chromium.chrome.browser; |
import android.Manifest; |
import android.app.Dialog; |
+import android.content.Context; |
+import android.content.Intent; |
import android.content.pm.PackageManager; |
+import android.location.LocationManager; |
import android.test.MoreAsserts; |
import android.test.suitebuilder.annotation.SmallTest; |
import android.view.View; |
@@ -15,6 +18,7 @@ import android.widget.ListView; |
import org.chromium.base.ThreadUtils; |
import org.chromium.chrome.R; |
+import org.chromium.chrome.browser.preferences.LocationSettings; |
import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
import org.chromium.components.security_state.ConnectionSecurityLevel; |
import org.chromium.content.browser.test.util.Criteria; |
@@ -39,6 +43,7 @@ public class BluetoothChooserDialogTest extends ChromeActivityTestCaseBase<Chrom |
static class BluetoothChooserDialogWithFakeNatives extends BluetoothChooserDialog { |
int mFinishedEventType = -1; |
String mFinishedDeviceId; |
+ int mRestartSearchCount = 0; |
BluetoothChooserDialogWithFakeNatives(WindowAndroid windowAndroid, String origin, |
int securityLevel, long nativeBluetoothChooserDialogPtr) { |
@@ -55,7 +60,9 @@ public class BluetoothChooserDialogTest extends ChromeActivityTestCaseBase<Chrom |
} |
@Override |
- void nativeRestartSearch(long nativeBluetoothChooserAndroid) {} |
+ void nativeRestartSearch(long nativeBluetoothChooserAndroid) { |
+ mRestartSearchCount++; |
+ } |
@Override |
void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndroid) {} |
@@ -68,6 +75,7 @@ public class BluetoothChooserDialogTest extends ChromeActivityTestCaseBase<Chrom |
} |
private ActivityWindowAndroid mWindowAndroid; |
+ private TestLocationSettings mLocationSettings; |
private BluetoothChooserDialogWithFakeNatives mChooserDialog; |
public BluetoothChooserDialogTest() { |
@@ -79,10 +87,18 @@ public class BluetoothChooserDialogTest extends ChromeActivityTestCaseBase<Chrom |
@Override |
protected void setUp() throws Exception { |
super.setUp(); |
+ mLocationSettings = new TestLocationSettings(getActivity()); |
+ LocationSettings.setInstanceForTesting(mLocationSettings); |
mChooserDialog = createDialog(); |
} |
@Override |
+ protected void tearDown() throws Exception { |
+ LocationSettings.setInstanceForTesting(null); |
+ super.tearDown(); |
+ } |
+ |
+ @Override |
public void startMainActivity() throws InterruptedException { |
startMainActivityOnBlankPage(); |
} |
@@ -140,13 +156,11 @@ public class BluetoothChooserDialogTest extends ChromeActivityTestCaseBase<Chrom |
} |
/** |
- * The messages include <link> ... </link> or <link1> ... </link1>, <link2> ... </link2> |
- * sections that are used to create clickable spans. For testing the messages, this function |
- * returns the raw string without the tags. |
+ * The messages include <*link*> ... </*link*> sections that are used to create clickable spans. |
+ * For testing the messages, this function returns the raw string without the tags. |
*/ |
private static String removeLinkTags(String message) { |
- return message.replaceAll("</?link1>", "").replaceAll( |
- "</?link2>", "").replaceAll("</?link>", ""); |
+ return message.replaceAll("</?[^>]*link[^>]*>", ""); |
} |
@SmallTest |
@@ -270,12 +284,71 @@ public class BluetoothChooserDialogTest extends ChromeActivityTestCaseBase<Chrom |
@Override |
public void run() { |
permissionDelegate.mCallback.onRequestPermissionsResult( |
- new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, |
+ new String[] {Manifest.permission.ACCESS_COARSE_LOCATION}, |
new int[] {PackageManager.PERMISSION_GRANTED}); |
} |
}); |
- assertEquals(removeLinkTags(getActivity().getString(R.string.bluetooth_adapter_off_help)), |
+ assertEquals(1, mChooserDialog.mRestartSearchCount); |
+ assertEquals(removeLinkTags(getActivity().getString(R.string.bluetooth_searching)), |
+ statusView.getText().toString()); |
+ |
+ mChooserDialog.closeDialog(); |
+ } |
+ |
+ @SmallTest |
+ public void testNoLocationServices() throws InterruptedException { |
+ ItemChooserDialog itemChooser = mChooserDialog.mItemChooserDialog; |
+ Dialog dialog = itemChooser.getDialogForTesting(); |
+ assertTrue(dialog.isShowing()); |
+ |
+ final TextViewWithClickableSpans statusView = |
+ (TextViewWithClickableSpans) dialog.findViewById(R.id.status); |
+ final TextViewWithClickableSpans errorView = |
+ (TextViewWithClickableSpans) dialog.findViewById(R.id.not_found_message); |
+ final View items = dialog.findViewById(R.id.items); |
+ final Button button = (Button) dialog.findViewById(R.id.positive); |
+ final View progress = dialog.findViewById(R.id.progress); |
+ |
+ final TestAndroidPermissionDelegate permissionDelegate = |
+ new TestAndroidPermissionDelegate(); |
+ mWindowAndroid.setAndroidPermissionDelegate(permissionDelegate); |
+ |
+ // Grant permissions, and turn off location services. |
+ permissionDelegate.mLocationGranted = true; |
+ mLocationSettings.mSystemLocationSettingsEnabled = false; |
+ |
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
+ @Override |
+ public void run() { |
+ mChooserDialog.notifyDiscoveryState( |
+ BluetoothChooserDialog.DISCOVERY_FAILED_TO_START); |
+ } |
+ }); |
+ |
+ assertEquals(removeLinkTags( |
+ getActivity().getString(R.string.bluetooth_need_location_services_on)), |
+ errorView.getText().toString()); |
+ 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. |
+ mLocationSettings.mSystemLocationSettingsEnabled = true; |
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
+ @Override |
+ public void run() { |
+ mChooserDialog.mLocationModeBroadcastReceiver.onReceive( |
+ getActivity(), new Intent(LocationManager.MODE_CHANGED_ACTION)); |
+ } |
+ }); |
+ |
+ assertEquals(1, mChooserDialog.mRestartSearchCount); |
+ assertEquals(removeLinkTags(getActivity().getString(R.string.bluetooth_searching)), |
statusView.getText().toString()); |
mChooserDialog.closeDialog(); |
@@ -310,4 +383,17 @@ public class BluetoothChooserDialogTest extends ChromeActivityTestCaseBase<Chrom |
} |
} |
} |
+ |
+ private static class TestLocationSettings extends LocationSettings { |
+ public TestLocationSettings(Context context) { |
+ super(context); |
+ } |
+ |
+ public boolean mSystemLocationSettingsEnabled = true; |
+ |
+ @Override |
+ public boolean isSystemLocationSettingEnabled() { |
+ return mSystemLocationSettingsEnabled; |
+ } |
+ } |
} |