| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 var event_handler = t.step_func(function(e) { | 85 var event_handler = t.step_func(function(e) { |
| 86 // Remove the event handler to prevent it being used in subsequent | 86 // Remove the event handler to prevent it being used in subsequent |
| 87 // invocations of prompt_test(). Save event object for call outside
handler. | 87 // invocations of prompt_test(). Save event object for call outside
handler. |
| 88 window.removeEventListener('beforeinstallprompt', event_handler); | 88 window.removeEventListener('beforeinstallprompt', event_handler); |
| 89 event = e; | 89 event = e; |
| 90 | 90 |
| 91 assert_equals(e.platforms.length, 2, 'Number of platforms'); | 91 assert_equals(e.platforms.length, 2, 'Number of platforms'); |
| 92 assert_equals(e.platforms[0], 'foo', 'First platform'); | 92 assert_equals(e.platforms[0], 'foo', 'First platform'); |
| 93 assert_equals(e.platforms[1], 'bar', 'Second platform'); | 93 assert_equals(e.platforms[1], 'bar', 'Second platform'); |
| 94 | 94 |
| 95 if (test_case.cancel) { |
| 96 e.preventDefault(); |
| 97 } |
| 98 |
| 95 if (test_case.late) { | 99 if (test_case.late) { |
| 96 return; | 100 return; |
| 97 } | 101 } |
| 98 | 102 |
| 99 if (test_case.cancel) { | 103 if (test_case.cancel) { |
| 100 // Cancel the event, then call prompt() to restart the display p
ipeline. | 104 // Call prompt() to restart the pipeline. |
| 101 e.preventDefault(); | |
| 102 verify_prompt_resolve(e, t); | 105 verify_prompt_resolve(e, t); |
| 103 } else { | 106 } else { |
| 104 // A call to prompt() before preventDefault should reject. | 107 // A call to prompt() before preventDefault should reject. |
| 105 verify_prompt_reject(e, t); | 108 verify_prompt_reject(e, t); |
| 106 } | 109 } |
| 107 | 110 |
| 108 // prompt() has been fired or the event has not been canceled, so ch
eck | 111 // prompt() has been fired or the event has not been canceled, so ch
eck |
| 109 // the userChoice promise and call the next test. | 112 // the userChoice promise and call the next test. |
| 110 verify_userChoice(e, t, test_case, index); | 113 verify_userChoice(e, t, test_case, index); |
| 111 }); | 114 }); |
| 112 window.addEventListener('beforeinstallprompt', event_handler); | 115 window.addEventListener('beforeinstallprompt', event_handler); |
| 113 | 116 |
| 114 testRunner.dispatchBeforeInstallPromptEvent(index, ['foo', 'bar'], t.ste
p_func(function(result) { | 117 testRunner.dispatchBeforeInstallPromptEvent(index, ['foo', 'bar'], t.ste
p_func(function(result) { |
| 115 testRunner.resolveBeforeInstallPromptPromise(index, test_case.platfo
rm); | 118 testRunner.resolveBeforeInstallPromptPromise(index, test_case.platfo
rm); |
| 116 })); | 119 })); |
| 117 | 120 |
| 118 // Test that firing prompt() outside of the handler resolves or rejects
correctly. | 121 // Test that firing prompt() outside of the handler resolves or rejects
correctly. |
| 119 if (test_case.late) { | 122 if (test_case.late) { |
| 120 if (test_case.cancel) { | 123 if (test_case.cancel) { |
| 121 event.preventDefault(); | |
| 122 verify_prompt_resolve(event, t); | 124 verify_prompt_resolve(event, t); |
| 123 } else { | 125 } else { |
| 124 verify_prompt_reject(event, t); | 126 verify_prompt_reject(event, t); |
| 125 } | 127 } |
| 126 // Check userChoice and call the next test. | 128 // Check userChoice and call the next test. |
| 127 verify_userChoice(event, t, test_case, index); | 129 verify_userChoice(event, t, test_case, index); |
| 128 } | 130 } |
| 129 }, test_case.name); | 131 }, test_case.name); |
| 130 } | 132 } |
| 131 | 133 |
| 132 prompt_test(0); | 134 prompt_test(0); |
| 133 </script> | 135 </script> |
| OLD | NEW |