| Index: chrome/android/javatests/src/org/chromium/chrome/browser/permissions/PermissionTestCaseBase.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/permissions/PermissionTestCaseBase.java b/chrome/android/javatests/src/org/chromium/chrome/browser/permissions/PermissionTestCaseBase.java
|
| index 063c362bbd4200c9de65d01841fe9c71068680a9..c26db784f3ed13363f9071050b20a21bcaaa1e06 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/permissions/PermissionTestCaseBase.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/permissions/PermissionTestCaseBase.java
|
| @@ -136,6 +136,39 @@ public class PermissionTestCaseBase extends ChromeActivityTestCaseBase<ChromeAct
|
| super.tearDown();
|
| }
|
|
|
| + protected void setUpUrl(final String url) throws InterruptedException {
|
| + final String test_url = mTestServer.getURL(url);
|
| + loadUrl(test_url);
|
| + }
|
| +
|
| + /**
|
| + * Checks permission status via the navigator.permissions.query API
|
| + */
|
| + protected void checkPermissionStatus(final String permission, final String expected)
|
| + throws Exception {
|
| + final CallbackHelper callbackHelper = new CallbackHelper();
|
| + EmptyTabObserver updateWaiter = new EmptyTabObserver() {
|
| + @Override
|
| + public void onTitleUpdated(Tab tab) {
|
| + String title = getActivity().getActivityTab().getTitle();
|
| + String prefix = permission + " status: ";
|
| + if (!title.startsWith(prefix)) return;
|
| + String actual = title.substring(prefix.length());
|
| + assertEquals(expected, actual);
|
| + callbackHelper.notifyCalled();
|
| + }
|
| + };
|
| +
|
| + Tab tab = getActivity().getActivityTab();
|
| + tab.addObserver(updateWaiter);
|
| + runJavaScriptCodeInCurrentTab("navigator.permissions.query({ name: '" + permission
|
| + + "' }).then(({state}) => { window.document.title = '" + permission
|
| + + " status: ' + state; });");
|
| + callbackHelper.waitForCallback(0);
|
| + tab.removeObserver(updateWaiter);
|
| + runJavaScriptCodeInCurrentTab("window.document.title = 'banana';");
|
| + }
|
| +
|
| /**
|
| * Simulates clicking a button on an AlertDialog.
|
| */
|
| @@ -148,6 +181,13 @@ public class PermissionTestCaseBase extends ChromeActivityTestCaseBase<ChromeAct
|
| });
|
| }
|
|
|
| + /**
|
| + * Waits for an infobar to have been added since to the last call to this function.
|
| + */
|
| + protected void waitForInfoBar() throws Exception {
|
| + mListener.addInfoBarAnimationFinished("InfoBar not added.");
|
| + }
|
| +
|
| /**
|
| * Runs a permission prompt test that grants the permission and expects the page title to be
|
| * updated in response.
|
| @@ -165,8 +205,7 @@ public class PermissionTestCaseBase extends ChromeActivityTestCaseBase<ChromeAct
|
| protected void runAllowTest(PermissionUpdateWaiter updateWaiter, final String url,
|
| String javascript, int nUpdates, boolean withGesture, boolean isDialog,
|
| boolean hasSwitch, boolean toggleSwitch) throws Exception {
|
| - final String test_url = mTestServer.getURL(url);
|
| - loadUrl(test_url);
|
| + setUpUrl(url);
|
|
|
| if (withGesture) {
|
| runJavaScriptCodeInCurrentTab("functionToRun = '" + javascript + "'");
|
| @@ -178,21 +217,20 @@ public class PermissionTestCaseBase extends ChromeActivityTestCaseBase<ChromeAct
|
| if (isDialog) {
|
| DialogShownCriteria criteria = new DialogShownCriteria("Dialog not shown");
|
| CriteriaHelper.pollUiThread(criteria);
|
| - replyToDialogAndWaitForUpdates(
|
| - updateWaiter, criteria.getDialog(), nUpdates, true, hasSwitch, toggleSwitch);
|
| + replyToDialog(criteria.getDialog(), true, hasSwitch, toggleSwitch);
|
| } else {
|
| - replyToInfoBarAndWaitForUpdates(updateWaiter, nUpdates, true, hasSwitch, toggleSwitch);
|
| + waitForInfoBar();
|
| + replyToInfoBar(true, hasSwitch, toggleSwitch);
|
| }
|
| + updateWaiter.waitForNumUpdates(nUpdates);
|
| }
|
|
|
| /**
|
| * Replies to an infobar permission prompt, optionally checking for the presence of a
|
| - * persistence switch and toggling it. Waits for a provided number of updates to the page title
|
| - * in response.
|
| + * persistence switch and toggling it.
|
| */
|
| - private void replyToInfoBarAndWaitForUpdates(PermissionUpdateWaiter updateWaiter, int nUpdates,
|
| - boolean allow, boolean hasSwitch, boolean toggleSwitch) throws Exception {
|
| - mListener.addInfoBarAnimationFinished("InfoBar not added.");
|
| + protected void replyToInfoBar(boolean allow, boolean hasSwitch, boolean toggleSwitch)
|
| + throws Exception {
|
| InfoBar infobar = getInfoBars().get(0);
|
| assertNotNull(infobar);
|
|
|
| @@ -207,16 +245,13 @@ public class PermissionTestCaseBase extends ChromeActivityTestCaseBase<ChromeAct
|
| } else {
|
| assertTrue("Block button wasn't found", InfoBarUtil.clickSecondaryButton(infobar));
|
| }
|
| - updateWaiter.waitForNumUpdates(nUpdates);
|
| }
|
|
|
| /**
|
| * Replies to a dialog permission prompt, optionally checking for the presence of a
|
| - * persistence switch and toggling it. Waits for a provided number of updates to the page title
|
| - * in response.
|
| + * persistence switch and toggling it.
|
| */
|
| - private void replyToDialogAndWaitForUpdates(PermissionUpdateWaiter updateWaiter,
|
| - AlertDialog dialog, int nUpdates, boolean allow, boolean hasSwitch,
|
| + private void replyToDialog(AlertDialog dialog, boolean allow, boolean hasSwitch,
|
| boolean toggleSwitch) throws Exception {
|
| if (hasSwitch) {
|
| SwitchCompat persistSwitch =
|
| @@ -229,7 +264,6 @@ public class PermissionTestCaseBase extends ChromeActivityTestCaseBase<ChromeAct
|
| } else {
|
| clickButton(dialog, DialogInterface.BUTTON_NEGATIVE);
|
| }
|
| - updateWaiter.waitForNumUpdates(nUpdates);
|
| }
|
|
|
| private void checkAndToggleSwitch(final SwitchCompat persistSwitch, boolean toggleSwitch) {
|
|
|