OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.permissions; |
| 6 |
| 7 import android.support.test.filters.MediumTest; |
| 8 |
| 9 import org.junit.Assert; |
| 10 |
| 11 import org.chromium.base.test.util.CallbackHelper; |
| 12 import org.chromium.base.test.util.CommandLineFlags; |
| 13 import org.chromium.base.test.util.Feature; |
| 14 import org.chromium.base.test.util.RetryOnFailure; |
| 15 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
| 16 import org.chromium.chrome.browser.tab.Tab; |
| 17 import org.chromium.content.browser.test.util.Criteria; |
| 18 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 19 |
| 20 /** |
| 21 * Test suite for interaction between permissions requests and navigation. |
| 22 */ |
| 23 @RetryOnFailure |
| 24 public class PermissionNavigationTest extends PermissionTestCaseBase { |
| 25 private static final String TEST_FILE = "/content/test/data/android/permissi
on_navigation.html"; |
| 26 |
| 27 public PermissionNavigationTest() {} |
| 28 |
| 29 /** |
| 30 * Check that modal permission prompts and queued permission requests are re
moved upon |
| 31 * navigation. |
| 32 * |
| 33 * @throws Exception |
| 34 */ |
| 35 @MediumTest |
| 36 @Feature({"Permissions"}) |
| 37 @CommandLineFlags.Add({NO_GESTURE_FEATURE, FORCE_FIELDTRIAL, FORCE_FIELDTRIA
L_PARAMS}) |
| 38 public void testNavigationDismissesModalPermissionPrompt() throws Exception
{ |
| 39 setUpUrl(TEST_FILE); |
| 40 runJavaScriptCodeInCurrentTab("requestGeolocationPermission()"); |
| 41 DialogShownCriteria criteriaShown = new DialogShownCriteria("Dialog not
shown", true); |
| 42 CriteriaHelper.pollUiThread(criteriaShown); |
| 43 Assert.assertEquals(0, PermissionDialogController.getInstance().getQueue
LengthForTesting()); |
| 44 |
| 45 runJavaScriptCodeInCurrentTab("requestNotificationPermission()"); |
| 46 CriteriaHelper.pollInstrumentationThread(new Criteria("Request not queue
d") { |
| 47 @Override |
| 48 public boolean isSatisfied() { |
| 49 return PermissionDialogController.getInstance().getQueueLengthFo
rTesting() == 1; |
| 50 } |
| 51 }); |
| 52 |
| 53 runJavaScriptCodeInCurrentTab("navigate()"); |
| 54 |
| 55 Tab tab = getActivity().getActivityTab(); |
| 56 final CallbackHelper callbackHelper = new CallbackHelper(); |
| 57 EmptyTabObserver navigationWaiter = new EmptyTabObserver() { |
| 58 @Override |
| 59 public void onDidFinishNavigation(Tab tab, String url, boolean isInM
ainFrame, |
| 60 boolean isErrorPage, boolean hasCommitted, boolean isSameDoc
ument, |
| 61 boolean isFragmentNavigation, Integer pageTransition, int er
rorCode, |
| 62 int httpStatusCode) { |
| 63 callbackHelper.notifyCalled(); |
| 64 } |
| 65 }; |
| 66 tab.addObserver(navigationWaiter); |
| 67 callbackHelper.waitForCallback(0); |
| 68 tab.removeObserver(navigationWaiter); |
| 69 |
| 70 DialogShownCriteria criteriaNotShown = new DialogShownCriteria("Dialog s
hown", false); |
| 71 CriteriaHelper.pollUiThread(criteriaNotShown); |
| 72 } |
| 73 } |
OLD | NEW |