| 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.app.AlertDialog; | 7 import android.app.AlertDialog; |
| 8 import android.test.suitebuilder.annotation.MediumTest; | 8 import android.test.suitebuilder.annotation.MediumTest; |
| 9 import android.test.suitebuilder.annotation.SmallTest; | 9 import android.test.suitebuilder.annotation.SmallTest; |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 @MediumTest | 54 @MediumTest |
| 55 @Feature({"Navigation"}) | 55 @Feature({"Navigation"}) |
| 56 public void testFormResubmissionContinue() throws Throwable { | 56 public void testFormResubmissionContinue() throws Throwable { |
| 57 // Load the url posting data for the first time. | 57 // Load the url posting data for the first time. |
| 58 postNavigation(); | 58 postNavigation(); |
| 59 mCallbackHelper.getOnPageFinishedHelper().waitForCallback(1); | 59 mCallbackHelper.getOnPageFinishedHelper().waitForCallback(1); |
| 60 | 60 |
| 61 // Trigger a reload and wait for the warning to be displayed. | 61 // Trigger a reload and wait for the warning to be displayed. |
| 62 reload(); | 62 reload(); |
| 63 getInstrumentation().waitForIdleSync(); | 63 getInstrumentation().waitForIdleSync(); |
| 64 AlertDialog dialog = (AlertDialog)RepostFormWarningDialog.getCurrentDial
og(); | 64 AlertDialog dialog = (AlertDialog) RepostFormWarningDialog.getCurrentDia
log(); |
| 65 assertNotNull("Form resubmission warning not shown upon reload.", dialog
); | 65 assertNotNull("Form resubmission warning not shown upon reload.", dialog
); |
| 66 | 66 |
| 67 // Click "Continue" and verify that the page is reloaded. | 67 // Click "Continue" and verify that the page is reloaded. |
| 68 clickButton(dialog, AlertDialog.BUTTON_POSITIVE); | 68 clickButton(dialog, AlertDialog.BUTTON_POSITIVE); |
| 69 mCallbackHelper.getOnPageFinishedHelper().waitForCallback(2); | 69 mCallbackHelper.getOnPageFinishedHelper().waitForCallback(2); |
| 70 | 70 |
| 71 // Verify that the reference to the dialog in RepostFormWarningDialog wa
s cleared. | 71 // Verify that the reference to the dialog in RepostFormWarningDialog wa
s cleared. |
| 72 assertNull("Form resubmission warning dialog was not dismissed correctly
.", | 72 assertNull("Form resubmission warning dialog was not dismissed correctly
.", |
| 73 RepostFormWarningDialog.getCurrentDialog()); | 73 RepostFormWarningDialog.getCurrentDialog()); |
| 74 } | 74 } |
| 75 | 75 |
| 76 /** | 76 /** |
| 77 * Verifies that cancelling the form reload prevents it from happening. Curr
ently the test waits | 77 * Verifies that cancelling the form reload prevents it from happening. Curr
ently the test waits |
| 78 * after the "Cancel" button is clicked to verify that the load was not trig
gered, which blocks | 78 * after the "Cancel" button is clicked to verify that the load was not trig
gered, which blocks |
| 79 * for CallbackHelper's default timeout upon each execution. | 79 * for CallbackHelper's default timeout upon each execution. |
| 80 */ | 80 */ |
| 81 @SmallTest | 81 @SmallTest |
| 82 @Feature({"Navigation"}) | 82 @Feature({"Navigation"}) |
| 83 public void testFormResubmissionCancel() throws Throwable { | 83 public void testFormResubmissionCancel() throws Throwable { |
| 84 // Load the url posting data for the first time. | 84 // Load the url posting data for the first time. |
| 85 postNavigation(); | 85 postNavigation(); |
| 86 mCallbackHelper.getOnPageFinishedHelper().waitForCallback(1); | 86 mCallbackHelper.getOnPageFinishedHelper().waitForCallback(1); |
| 87 | 87 |
| 88 // Trigger a reload and wait for the warning to be displayed. | 88 // Trigger a reload and wait for the warning to be displayed. |
| 89 reload(); | 89 reload(); |
| 90 getInstrumentation().waitForIdleSync(); | 90 getInstrumentation().waitForIdleSync(); |
| 91 AlertDialog dialog = (AlertDialog)RepostFormWarningDialog.getCurrentDial
og(); | 91 AlertDialog dialog = (AlertDialog) RepostFormWarningDialog.getCurrentDia
log(); |
| 92 assertNotNull("Form resubmission warning not shown upon reload.", dialog
); | 92 assertNotNull("Form resubmission warning not shown upon reload.", dialog
); |
| 93 | 93 |
| 94 // Click "Cancel" and verify that the page is not reloaded. | 94 // Click "Cancel" and verify that the page is not reloaded. |
| 95 clickButton(dialog, AlertDialog.BUTTON_NEGATIVE); | 95 clickButton(dialog, AlertDialog.BUTTON_NEGATIVE); |
| 96 boolean timedOut = false; | 96 boolean timedOut = false; |
| 97 try { | 97 try { |
| 98 mCallbackHelper.getOnPageFinishedHelper().waitForCallback(2); | 98 mCallbackHelper.getOnPageFinishedHelper().waitForCallback(2); |
| 99 } catch (TimeoutException ex) { | 99 } catch (TimeoutException ex) { |
| 100 timedOut = true; | 100 timedOut = true; |
| 101 } | 101 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 132 /** Clicks the given button in the given dialog. */ | 132 /** Clicks the given button in the given dialog. */ |
| 133 private void clickButton(final AlertDialog dialog, final int buttonId) throw
s Throwable { | 133 private void clickButton(final AlertDialog dialog, final int buttonId) throw
s Throwable { |
| 134 runTestOnUiThread(new Runnable() { | 134 runTestOnUiThread(new Runnable() { |
| 135 @Override | 135 @Override |
| 136 public void run() { | 136 public void run() { |
| 137 dialog.getButton(buttonId).performClick(); | 137 dialog.getButton(buttonId).performClick(); |
| 138 } | 138 } |
| 139 }); | 139 }); |
| 140 } | 140 } |
| 141 } | 141 } |
| OLD | NEW |