Commit 86fa36be authored by Anita Woodruff's avatar Anita Woodruff Committed by Commit Bot

[Android Tests] Fix up disabled tests in NotificationPlatformBridgeTest

- Turns out these tests were failing because notification permissions
were switched from info bars to modals a while ago and these tests were
never updated.

Bug: 853405
Change-Id: Ia663240507a7fa674f96170c4fdcbfdc9c028ec9
Reviewed-on: https://chromium-review.googlesource.com/1145309
Commit-Queue: Anita Woodruff <awdf@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577898}
parent e459c6e9
......@@ -44,6 +44,7 @@ public class GeolocationTest {
@Before
public void setUp() throws Exception {
mPermissionRule.setUpActivity();
LocationSettingsTestUtil.setSystemLocationSettingEnabled(true);
LocationProviderOverrider.setLocationProviderImpl(new MockLocationProvider());
}
......
......@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.permissions;
import android.support.test.filters.MediumTest;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -34,6 +35,11 @@ public class MediaTest {
public MediaTest() {}
@Before
public void setUp() throws Exception {
mPermissionRule.setUpActivity();
}
private void testMediaPermissionsPlumbing(String prefix, String script, int numUpdates,
boolean withGesture, boolean isDialog) throws Exception {
Tab tab = mPermissionRule.getActivity().getActivityTab();
......
......@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.permissions;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -33,6 +34,11 @@ public class PermissionNavigationTest {
public PermissionNavigationTest() {}
@Before
public void setUp() throws Exception {
mPermissionRule.setUpActivity();
}
/**
* Check that modal permission prompts and queued permission requests are removed upon
* navigation.
......
......@@ -60,7 +60,7 @@ public class PermissionTestRule extends ChromeActivityTestRule<ChromeActivity> {
* Waits till a JavaScript callback which updates the page title is called the specified number
* of times. The page title is expected to be of the form <prefix>: <count>.
*/
protected static class PermissionUpdateWaiter extends EmptyTabObserver {
public static class PermissionUpdateWaiter extends EmptyTabObserver {
private CallbackHelper mCallbackHelper;
private String mPrefix;
private int mExpectedCount;
......@@ -136,13 +136,19 @@ public class PermissionTestRule extends ChromeActivityTestRule<ChromeActivity> {
}
private void ruleSetUp() throws Throwable {
// TODO(https://crbug.com/867446): Refactor to use EmbeddedTestServerRule.
mTestServer = EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext());
}
/**
* Starts an activity and listens for info-bars appearing/disappearing.
*/
void setUpActivity() throws InterruptedException {
startMainActivityOnBlankPage();
InfoBarContainer container =
getActivity().getTabModelSelector().getCurrentTab().getInfoBarContainer();
mListener = new InfoBarTestAnimationListener();
container.addAnimationListener(mListener);
// TODO(yolandyan): refactor to use EmbeddedTestServerRule
mTestServer = EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext());
}
private void ruleTearDown() throws Exception {
......@@ -150,9 +156,16 @@ public class PermissionTestRule extends ChromeActivityTestRule<ChromeActivity> {
}
protected void setUpUrl(final String url) throws InterruptedException {
loadUrl(mTestServer.getURL(url));
loadUrl(getURL(url));
}
public String getURL(String url) {
return mTestServer.getURL(url);
}
public String getOrigin() {
return mTestServer.getURL("/");
}
/**
* Simulates clicking a button on an PermissionDialogView.
*/
......@@ -181,23 +194,55 @@ public class PermissionTestRule extends ChromeActivityTestRule<ChromeActivity> {
String javascript, int nUpdates, boolean withGesture, boolean isDialog)
throws Exception {
setUpUrl(url);
if (withGesture) {
runJavaScriptCodeInCurrentTabWithGesture(javascript);
} else {
runJavaScriptCodeInCurrentTab(javascript);
}
replyToPromptAndWaitForUpdates(updateWaiter, true, nUpdates, isDialog);
}
/**
* Runs a permission prompt test that grants the permission and expects the page title to be
* updated in response.
* @param updateWaiter The update waiter to wait for callbacks. Should be added as an observer
* to the current tab prior to calling this method.
* @param javascript The JS function to run in the current tab to execute the test and update
* the page title.
* @param nUpdates How many updates of the page title to wait for.
* @param withGesture True if we require a user gesture to trigger the prompt.
* @param isDialog True if we are expecting a permission dialog, false for an infobar.
* @throws Exception
*/
public void runDenyTest(PermissionUpdateWaiter updateWaiter, final String url,
String javascript, int nUpdates, boolean withGesture, boolean isDialog)
throws Exception {
setUpUrl(url);
if (withGesture) {
runJavaScriptCodeInCurrentTab("functionToRun = '" + javascript + "'");
TouchCommon.singleClickView(getActivity().getActivityTab().getView());
runJavaScriptCodeInCurrentTabWithGesture(javascript);
} else {
runJavaScriptCodeInCurrentTab(javascript);
}
replyToPromptAndWaitForUpdates(updateWaiter, false, nUpdates, isDialog);
}
private void replyToPromptAndWaitForUpdates(PermissionUpdateWaiter updateWaiter, boolean allow,
int nUpdates, boolean isDialog) throws Exception {
if (isDialog) {
DialogShownCriteria criteria = new DialogShownCriteria("Dialog not shown", true);
CriteriaHelper.pollUiThread(criteria);
replyToDialogAndWaitForUpdates(updateWaiter, criteria.getDialog(), nUpdates, true);
replyToDialogAndWaitForUpdates(updateWaiter, criteria.getDialog(), nUpdates, allow);
} else {
replyToInfoBarAndWaitForUpdates(updateWaiter, nUpdates, true);
replyToInfoBarAndWaitForUpdates(updateWaiter, nUpdates, allow);
}
}
private void runJavaScriptCodeInCurrentTabWithGesture(String javascript)
throws InterruptedException, java.util.concurrent.TimeoutException {
runJavaScriptCodeInCurrentTab("functionToRun = '" + javascript + "'");
TouchCommon.singleClickView(getActivity().getActivityTab().getView());
}
/**
* Replies to an infobar permission prompt and waits for a provided number
* of updates to the page title in response.
......
......@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.permissions;
import android.support.test.filters.MediumTest;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -30,6 +31,11 @@ public class QuotaTest {
private static final String TEST_FILE = "/content/test/data/android/quota_permissions.html";
@Before
public void setUp() throws Exception {
mPermissionRule.setUpActivity();
}
public QuotaTest() {}
private void testQuotaPermissionsPlumbing(
......
......@@ -39,6 +39,17 @@
}
document.title = message;
}
// Some tests require a count of how frequently they were invoked.
var message_counts = {}
function addCountAndSendToTest(message) {
if (message in message_counts) {
message_counts[message]++;
} else {
message_counts[message] = 1;
}
document.title = message + ': ' + message_counts[message];
}
</script>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment