Chromium Code Reviews| Index: LayoutTests/app_banner/app-banner-event-prompt.html |
| diff --git a/LayoutTests/app_banner/app-banner-event-prompt.html b/LayoutTests/app_banner/app-banner-event-prompt.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cd0bb2e488b73861043dcf91094e9ed05936cb43 |
| --- /dev/null |
| +++ b/LayoutTests/app_banner/app-banner-event-prompt.html |
| @@ -0,0 +1,87 @@ |
| +<!DOCTYPE html> |
| +<script src="../resources/testharness.js"></script> |
| +<script src="../resources/testharnessreport.js"></script> |
| +<script> |
| + |
| +var prompt_test_cases = [ |
| + { |
| + name: 'prompt', |
| + cancel: true, |
| + platform: 'foo', |
| + outcome: 'accepted' |
| + }, { |
| + name: 'prompt-dismissed', |
| + cancel: true, |
| + platform: '', |
| + outcome: 'dismissed' |
| + }, { |
| + name: 'prompt-before-preventDefault', |
| + cancel: false, |
| + platform: 'foo', |
| + outcome: 'accepted' |
| + } |
| +]; |
| + |
| +function verify_prompt_reject(e, t, callback) { |
| + e.prompt().then(t.unreached_func("prompt() promise should reject."), |
| + t.step_func(function(error) { |
| + assert_true( |
| + error instanceof DOMException, |
| + "Rejected promise should throw a DOMException." |
| + ); |
| + assert_equals( |
| + error.message, |
| + "The prompt() method may only be called once, following preventDefault().", |
| + "Rejected promise does not provide expected message." |
| + ); |
| + typeof callback === 'function' && callback(); |
| + }) |
| + ); |
| +} |
| + |
| +function prompt_test(index) { |
| + if (index >= prompt_test_cases.length) |
| + return; |
| + |
| + var test_case = prompt_test_cases[index]; |
| + async_test(function(t) { |
| + var event_handler = t.step_func(function(e) { |
| + // Remove the event handler to prevent it being used in subsequent |
| + // invocations of prompt_test(). |
| + window.removeEventListener('beforeinstallprompt', event_handler); |
| + |
| + assert_equals(e.platforms.length, 2, 'Number of platforms'); |
| + assert_equals(e.platforms[0], 'foo', 'First platform'); |
| + assert_equals(e.platforms[1], 'bar', 'Second platform'); |
| + |
| + if (test_case.cancel) { |
| + // Cancel the event, then call prompt() to restart the display pipeline. |
| + e.preventDefault(); |
| + e.prompt().then(function() { }, t.unreached_func("prompt() promise should resolve.")); |
| + } else { |
| + // A call to prompt() before preventDefault should reject. |
| + verify_prompt_reject(e, t); |
| + } |
| + |
| + e.userChoice.then(t.step_func(function(result) { |
| + assert_equals(result.platform, test_case.platform, 'Resolved platform'); |
| + assert_equals(result.outcome, test_case.outcome, 'Outcome'); |
|
mlamouri (slow - plz ping)
2015/06/24 13:56:51
What about:
e.userChoice.then(t.step_func(functio
dominickn
2015/06/24 23:09:13
Done. Also added tests for prompt() calls outside
|
| + }), t.unreached_func("userChoice promise should resolve.")); |
| + |
| + // A call to prompt() here should reject, as either preventDefault |
| + // has not been called, or prompt() has already been called. |
| + verify_prompt_reject(e, t, t.step_func(function() { |
| + prompt_test(index + 1); |
| + t.done(); |
| + })); |
| + }); |
| + window.addEventListener('beforeinstallprompt', event_handler); |
| + |
| + testRunner.dispatchBeforeInstallPromptEvent(index, ['foo', 'bar'], t.step_func(function(result) { |
| + testRunner.resolveBeforeInstallPromptPromise(index, test_case.platform); |
| + })); |
| + }, test_case.name); |
| +} |
| + |
| +prompt_test(0); |
| +</script> |