| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser; | 5 package org.chromium.chrome.browser; |
| 6 | 6 |
| 7 import android.content.DialogInterface; | 7 import android.content.DialogInterface; |
| 8 import android.support.test.filters.MediumTest; | 8 import android.support.test.filters.MediumTest; |
| 9 import android.support.v7.app.AlertDialog; | 9 import android.support.v7.app.AlertDialog; |
| 10 import android.util.Log; | 10 import android.util.Log; |
| 11 import android.view.View; | 11 import android.view.View; |
| 12 import android.widget.Button; | 12 import android.widget.Button; |
| 13 import android.widget.CheckBox; | 13 import android.widget.CheckBox; |
| 14 import android.widget.EditText; | 14 import android.widget.EditText; |
| 15 | 15 |
| 16 import org.chromium.base.ThreadUtils; | 16 import org.chromium.base.ThreadUtils; |
| 17 import org.chromium.base.test.util.CallbackHelper; |
| 17 import org.chromium.base.test.util.Feature; | 18 import org.chromium.base.test.util.Feature; |
| 18 import org.chromium.base.test.util.RetryOnFailure; | 19 import org.chromium.base.test.util.RetryOnFailure; |
| 19 import org.chromium.base.test.util.UrlUtils; | 20 import org.chromium.base.test.util.UrlUtils; |
| 20 import org.chromium.chrome.R; | 21 import org.chromium.chrome.R; |
| 21 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 22 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
| 22 import org.chromium.content.browser.test.util.Criteria; | 23 import org.chromium.content.browser.test.util.Criteria; |
| 23 import org.chromium.content.browser.test.util.CriteriaHelper; | 24 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 24 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; | 25 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; |
| 25 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEval
uateJavaScriptResultHelper; | 26 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEval
uateJavaScriptResultHelper; |
| 27 import org.chromium.content_public.browser.GestureStateListener; |
| 26 | 28 |
| 27 import java.util.concurrent.Callable; | 29 import java.util.concurrent.Callable; |
| 28 import java.util.concurrent.ExecutionException; | 30 import java.util.concurrent.ExecutionException; |
| 29 import java.util.concurrent.TimeoutException; | 31 import java.util.concurrent.TimeoutException; |
| 30 | 32 |
| 31 /** | 33 /** |
| 32 * Test suite for displaying and functioning of modal dialogs. | 34 * Test suite for displaying and functioning of modal dialogs. |
| 33 */ | 35 */ |
| 34 @RetryOnFailure | 36 @RetryOnFailure |
| 35 public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
{ | 37 public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
{ |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 assertTrue("Failed to find prompt view in prompt dialog.", result); | 162 assertTrue("Failed to find prompt view in prompt dialog.", result); |
| 161 | 163 |
| 162 clickOk(jsDialog); | 164 clickOk(jsDialog); |
| 163 assertTrue("JavaScript execution should continue after closing prompt.", | 165 assertTrue("JavaScript execution should continue after closing prompt.", |
| 164 scriptEvent.waitUntilHasValue()); | 166 scriptEvent.waitUntilHasValue()); |
| 165 | 167 |
| 166 String resultString = scriptEvent.getJsonResultAndClear(); | 168 String resultString = scriptEvent.getJsonResultAndClear(); |
| 167 assertEquals("Invalid return value.", '"' + promptText + '"', resultStri
ng); | 169 assertEquals("Invalid return value.", '"' + promptText + '"', resultStri
ng); |
| 168 } | 170 } |
| 169 | 171 |
| 172 private static class TapGestureStateListener extends GestureStateListener { |
| 173 private CallbackHelper mCallbackHelper = new CallbackHelper(); |
| 174 |
| 175 public int getCallCount() { |
| 176 return mCallbackHelper.getCallCount(); |
| 177 } |
| 178 |
| 179 public void waitForTap(int currentCallCount) |
| 180 throws InterruptedException, TimeoutException { |
| 181 mCallbackHelper.waitForCallback(currentCallCount); |
| 182 } |
| 183 |
| 184 @Override |
| 185 public void onSingleTap(boolean consumed) { |
| 186 mCallbackHelper.notifyCalled(); |
| 187 } |
| 188 } |
| 189 |
| 190 /** |
| 191 * Taps on a view and waits for a callback. |
| 192 */ |
| 193 private void tapViewAndWait() throws InterruptedException, TimeoutException
{ |
| 194 final TapGestureStateListener tapGestureStateListener = |
| 195 new TapGestureStateListener(); |
| 196 int callCount = tapGestureStateListener.getCallCount(); |
| 197 getActivity().getCurrentContentViewCore() |
| 198 .addGestureStateListener(tapGestureStateListener); |
| 199 |
| 200 singleClickView(getActivity().getActivityTab().getView()); |
| 201 tapGestureStateListener.waitForTap(callCount); |
| 202 } |
| 203 |
| 170 /** | 204 /** |
| 171 * Verifies beforeunload dialogs are shown and they block/allow navigation | 205 * Verifies beforeunload dialogs are shown and they block/allow navigation |
| 172 * as appropriate. | 206 * as appropriate. |
| 173 */ | 207 */ |
| 174 @MediumTest | 208 @MediumTest |
| 175 @Feature({"Browser", "Main"}) | 209 @Feature({"Browser", "Main"}) |
| 176 public void testBeforeUnloadDialog() | 210 public void testBeforeUnloadDialog() |
| 177 throws InterruptedException, TimeoutException, ExecutionException { | 211 throws InterruptedException, TimeoutException, ExecutionException { |
| 178 loadUrl(BEFORE_UNLOAD_URL); | 212 loadUrl(BEFORE_UNLOAD_URL); |
| 213 // JavaScript onbeforeunload dialogs require a user gesture. |
| 214 tapViewAndWait(); |
| 179 executeJavaScriptAndWaitForDialog("history.back();"); | 215 executeJavaScriptAndWaitForDialog("history.back();"); |
| 180 | 216 |
| 181 JavascriptAppModalDialog jsDialog = getCurrentDialog(); | 217 JavascriptAppModalDialog jsDialog = getCurrentDialog(); |
| 182 assertNotNull("No dialog showing.", jsDialog); | 218 assertNotNull("No dialog showing.", jsDialog); |
| 183 checkButtonPresenceVisibilityText(jsDialog, 0, R.string.cancel, "Cancel"
); | 219 checkButtonPresenceVisibilityText(jsDialog, 0, R.string.cancel, "Cancel"
); |
| 184 clickCancel(jsDialog); | 220 clickCancel(jsDialog); |
| 185 | 221 |
| 186 assertEquals(BEFORE_UNLOAD_URL, getActivity().getCurrentContentViewCore(
) | 222 assertEquals(BEFORE_UNLOAD_URL, getActivity().getCurrentContentViewCore(
) |
| 187 .getWebContents().getUrl()); | 223 .getWebContents().getUrl()); |
| 188 executeJavaScriptAndWaitForDialog("history.back();"); | 224 executeJavaScriptAndWaitForDialog("history.back();"); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 199 assertEquals(EMPTY_PAGE, getActivity().getCurrentContentViewCore() | 235 assertEquals(EMPTY_PAGE, getActivity().getCurrentContentViewCore() |
| 200 .getWebContents().getUrl()); | 236 .getWebContents().getUrl()); |
| 201 } | 237 } |
| 202 | 238 |
| 203 /** | 239 /** |
| 204 * Verifies that when showing a beforeunload dialogs as a result of a page | 240 * Verifies that when showing a beforeunload dialogs as a result of a page |
| 205 * reload, the correct UI strings are used. | 241 * reload, the correct UI strings are used. |
| 206 */ | 242 */ |
| 207 @MediumTest | 243 @MediumTest |
| 208 @Feature({"Browser", "Main"}) | 244 @Feature({"Browser", "Main"}) |
| 209 public void testBeforeUnloadOnReloadDialog() throws InterruptedException, Ex
ecutionException { | 245 public void testBeforeUnloadOnReloadDialog() |
| 246 throws InterruptedException, TimeoutException, ExecutionException { |
| 210 loadUrl(BEFORE_UNLOAD_URL); | 247 loadUrl(BEFORE_UNLOAD_URL); |
| 248 // JavaScript onbeforeunload dialogs require a user gesture. |
| 249 tapViewAndWait(); |
| 211 executeJavaScriptAndWaitForDialog("window.location.reload();"); | 250 executeJavaScriptAndWaitForDialog("window.location.reload();"); |
| 212 | 251 |
| 213 JavascriptAppModalDialog jsDialog = getCurrentDialog(); | 252 JavascriptAppModalDialog jsDialog = getCurrentDialog(); |
| 214 assertNotNull("No dialog showing.", jsDialog); | 253 assertNotNull("No dialog showing.", jsDialog); |
| 215 | 254 |
| 216 checkButtonPresenceVisibilityText(jsDialog, 0, R.string.cancel, "Cancel"
); | 255 checkButtonPresenceVisibilityText(jsDialog, 0, R.string.cancel, "Cancel"
); |
| 217 checkButtonPresenceVisibilityText(jsDialog, 2, R.string.reload, "Reload"
); | 256 checkButtonPresenceVisibilityText(jsDialog, 2, R.string.reload, "Reload"
); |
| 218 } | 257 } |
| 219 | 258 |
| 220 /** | 259 /** |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 button.getVisibility()); | 438 button.getVisibility()); |
| 400 assertEquals("'" + readableName + "' button has wrong text", | 439 assertEquals("'" + readableName + "' button has wrong text", |
| 401 getActivity().getResources().getString(expectedTextResourceId), | 440 getActivity().getResources().getString(expectedTextResourceId), |
| 402 button.getText().toString()); | 441 button.getText().toString()); |
| 403 } | 442 } |
| 404 | 443 |
| 405 private TestCallbackHelperContainer getActiveTabTestCallbackHelperContainer(
) { | 444 private TestCallbackHelperContainer getActiveTabTestCallbackHelperContainer(
) { |
| 406 return new TestCallbackHelperContainer(getActivity().getCurrentContentVi
ewCore()); | 445 return new TestCallbackHelperContainer(getActivity().getCurrentContentVi
ewCore()); |
| 407 } | 446 } |
| 408 } | 447 } |
| OLD | NEW |