| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
| 3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
| 4 <script> | 4 <script> |
| 5 | 5 |
| 6 var prompt_test_cases = [ | 6 var prompt_test_cases = [ |
| 7 { | 7 { |
| 8 name: 'prompt-accept', | 8 name: 'prompt-accept', |
| 9 cancel: true, | 9 cancel: true, |
| 10 late: false, | 10 late: false, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 ); | 56 ); |
| 57 assert_equals( | 57 assert_equals( |
| 58 error.message, | 58 error.message, |
| 59 "The prompt() method may only be called once, following preventD
efault().", | 59 "The prompt() method may only be called once, following preventD
efault().", |
| 60 "Rejected promise does not provide expected message." | 60 "Rejected promise does not provide expected message." |
| 61 ); | 61 ); |
| 62 }) | 62 }) |
| 63 ); | 63 ); |
| 64 } | 64 } |
| 65 | 65 |
| 66 function verify_userChoice(e, t, test_case, index) { | 66 function verify_userChoice(e, t, test_case, index, prompt_called) { |
| 67 e.userChoice.then(t.step_func(function(result) { | 67 e.userChoice.then(t.step_func(function(result) { |
| 68 assert_equals(result.platform, test_case.platform, 'Resolved platform'); | 68 assert_equals(result.platform, test_case.platform, 'Resolved platform'); |
| 69 assert_equals(result.outcome, test_case.outcome, 'Outcome'); | 69 assert_equals(result.outcome, test_case.outcome, 'Outcome'); |
| 70 })).then(t.step_func(function() { | 70 })).then(t.step_func(function() { |
| 71 verify_prompt_reject(e, t); | 71 if (prompt_called) { |
| 72 verify_prompt_resolve(e, t); |
| 73 } else { |
| 74 verify_prompt_reject(e, t); |
| 75 } |
| 72 })).then(t.step_func(function() { | 76 })).then(t.step_func(function() { |
| 73 prompt_test(index + 1); | 77 prompt_test(index + 1); |
| 74 t.done(); | 78 t.done(); |
| 75 }), t.unreached_func("userChoice promise should resolve.")); | 79 }), t.unreached_func("userChoice promise should resolve.")); |
| 76 } | 80 } |
| 77 | 81 |
| 78 function prompt_test(index) { | 82 function prompt_test(index) { |
| 79 if (index >= prompt_test_cases.length) | 83 if (index >= prompt_test_cases.length) |
| 80 return; | 84 return; |
| 81 | 85 |
| 82 var test_case = prompt_test_cases[index]; | 86 var test_case = prompt_test_cases[index]; |
| 83 async_test(function(t) { | 87 async_test(function(t) { |
| 84 var event = null; | 88 var event = null; |
| 85 var event_handler = t.step_func(function(e) { | 89 var event_handler = t.step_func(function(e) { |
| 86 // Remove the event handler to prevent it being used in subsequent | 90 // Remove the event handler to prevent it being used in subsequent |
| 87 // invocations of prompt_test(). Save event object for call outside
handler. | 91 // invocations of prompt_test(). Save event object for call outside
handler. |
| 88 window.removeEventListener('beforeinstallprompt', event_handler); | 92 window.removeEventListener('beforeinstallprompt', event_handler); |
| 89 event = e; | 93 event = e; |
| 90 | 94 |
| 91 assert_equals(e.platforms.length, 2, 'Number of platforms'); | 95 assert_equals(e.platforms.length, 2, 'Number of platforms'); |
| 92 assert_equals(e.platforms[0], 'foo', 'First platform'); | 96 assert_equals(e.platforms[0], 'foo', 'First platform'); |
| 93 assert_equals(e.platforms[1], 'bar', 'Second platform'); | 97 assert_equals(e.platforms[1], 'bar', 'Second platform'); |
| 94 | 98 |
| 99 if (test_case.cancel) { |
| 100 e.preventDefault(); |
| 101 } |
| 102 |
| 95 if (test_case.late) { | 103 if (test_case.late) { |
| 96 return; | 104 return; |
| 97 } | 105 } |
| 98 | 106 |
| 99 if (test_case.cancel) { | 107 if (test_case.cancel) { |
| 100 // Cancel the event, then call prompt() to restart the display p
ipeline. | 108 // Call prompt() to restart the pipeline. |
| 101 e.preventDefault(); | |
| 102 verify_prompt_resolve(e, t); | 109 verify_prompt_resolve(e, t); |
| 103 } else { | 110 } else { |
| 104 // A call to prompt() before preventDefault should reject. | 111 // A call to prompt() before preventDefault should reject. |
| 105 verify_prompt_reject(e, t); | 112 verify_prompt_reject(e, t); |
| 106 } | 113 } |
| 107 | 114 |
| 108 // prompt() has been fired or the event has not been canceled, so ch
eck | 115 // prompt() has been fired or the event has not been canceled, so ch
eck |
| 109 // the userChoice promise and call the next test. | 116 // the userChoice promise and call the next test. |
| 110 verify_userChoice(e, t, test_case, index); | 117 verify_userChoice(e, t, test_case, index, test_case.cancel); |
| 111 }); | 118 }); |
| 112 window.addEventListener('beforeinstallprompt', event_handler); | 119 window.addEventListener('beforeinstallprompt', event_handler); |
| 113 | 120 |
| 114 testRunner.dispatchBeforeInstallPromptEvent(index, ['foo', 'bar'], t.ste
p_func(function(result) { | 121 testRunner.dispatchBeforeInstallPromptEvent(index, ['foo', 'bar'], t.ste
p_func(function(result) { |
| 115 testRunner.resolveBeforeInstallPromptPromise(index, test_case.platfo
rm); | 122 testRunner.resolveBeforeInstallPromptPromise(index, test_case.platfo
rm); |
| 116 })); | 123 })); |
| 117 | 124 |
| 118 // Test that firing prompt() outside of the handler resolves or rejects
correctly. | 125 // Test that firing prompt() outside of the handler resolves or rejects
correctly. |
| 119 if (test_case.late) { | 126 if (test_case.late) { |
| 120 if (test_case.cancel) { | 127 if (test_case.cancel) { |
| 121 event.preventDefault(); | |
| 122 verify_prompt_resolve(event, t); | 128 verify_prompt_resolve(event, t); |
| 123 } else { | 129 } else { |
| 124 verify_prompt_reject(event, t); | 130 verify_prompt_reject(event, t); |
| 125 } | 131 } |
| 126 // Check userChoice and call the next test. | 132 // Check userChoice and call the next test. |
| 127 verify_userChoice(event, t, test_case, index); | 133 verify_userChoice(event, t, test_case, index, test_case.cancel); |
| 128 } | 134 } |
| 129 }, test_case.name); | 135 }, test_case.name); |
| 130 } | 136 } |
| 131 | 137 |
| 132 prompt_test(0); | 138 prompt_test(0); |
| 133 </script> | 139 </script> |
| OLD | NEW |