| 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-access-userchoice-first', |
| 9 cancel: true, | 9 cancel: true, |
| 10 late: false, | 10 late: false, |
| 11 platform: 'foo', | 11 platform: 'foo', |
| 12 outcome: 'accepted' | 12 outcome: 'accepted', |
| 13 userChoice: true |
| 13 }, { | 14 }, { |
| 14 name: 'prompt-dismiss', | 15 name: 'prompt-accept-no-access-userchoice-first', |
| 16 cancel: true, |
| 17 late: false, |
| 18 platform: 'foo', |
| 19 outcome: 'accepted', |
| 20 userChoice: false |
| 21 }, { |
| 22 name: 'prompt-dismiss-access-userchoice-first', |
| 15 cancel: true, | 23 cancel: true, |
| 16 late: false, | 24 late: false, |
| 17 platform: '', | 25 platform: '', |
| 18 outcome: 'dismissed' | 26 outcome: 'dismissed', |
| 27 userChoice: true |
| 19 }, { | 28 }, { |
| 20 name: 'prompt-before-preventDefault', | 29 name: 'prompt-dismiss-no-access-userchoice-first', |
| 30 cancel: true, |
| 31 late: false, |
| 32 platform: '', |
| 33 outcome: 'dismissed', |
| 34 userChoice: false |
| 35 }, { |
| 36 name: 'prompt-before-preventDefault-access-userchoice-first', |
| 21 cancel: false, | 37 cancel: false, |
| 22 late: false, | 38 late: false, |
| 23 platform: 'foo', | 39 platform: 'foo', |
| 24 outcome: 'accepted' | 40 outcome: 'accepted', |
| 41 userChoice: true |
| 25 }, { | 42 }, { |
| 26 name: 'prompt-late-accept', | 43 name: 'prompt-before-preventDefault-no-access-userchoice-first', |
| 44 cancel: false, |
| 45 late: false, |
| 46 platform: 'foo', |
| 47 outcome: 'accepted', |
| 48 userChoice: false |
| 49 }, { |
| 50 name: 'prompt-late-accept-access-userchoice-first', |
| 27 cancel: true, | 51 cancel: true, |
| 28 late: true, | 52 late: true, |
| 29 platform: 'foo', | 53 platform: 'foo', |
| 30 outcome: 'accepted' | 54 outcome: 'accepted', |
| 55 userChoice: false |
| 31 }, { | 56 }, { |
| 32 name: 'prompt-late-dismiss', | 57 name: 'prompt-late-accept-no-access-userchoice-first', |
| 58 cancel: true, |
| 59 late: true, |
| 60 platform: 'foo', |
| 61 outcome: 'accepted', |
| 62 userChoice: false |
| 63 }, { |
| 64 name: 'prompt-late-dismiss-access-userchoice-first', |
| 33 cancel: true, | 65 cancel: true, |
| 34 late: true, | 66 late: true, |
| 35 platform: '', | 67 platform: '', |
| 36 outcome: 'dismissed' | 68 outcome: 'dismissed', |
| 69 userChoice: true |
| 37 }, { | 70 }, { |
| 38 name: 'prompt-late-without-preventDefault', | 71 name: 'prompt-late-dismiss-no-access-userchoice-first', |
| 72 cancel: true, |
| 73 late: true, |
| 74 platform: '', |
| 75 outcome: 'dismissed', |
| 76 userChoice: false |
| 77 }, { |
| 78 name: 'prompt-late-without-preventDefault-access-userchoice-first', |
| 39 cancel: false, | 79 cancel: false, |
| 40 late: true, | 80 late: true, |
| 41 platform: '', | 81 platform: '', |
| 42 outcome: 'dismissed' | 82 outcome: 'dismissed', |
| 83 userChoice: true |
| 84 }, { |
| 85 name: 'prompt-late-without-preventDefault-no-access-userchoice-first', |
| 86 cancel: false, |
| 87 late: true, |
| 88 platform: '', |
| 89 outcome: 'dismissed', |
| 90 userChoice: false |
| 43 } | 91 } |
| 44 ]; | 92 ]; |
| 45 | 93 |
| 46 function verify_prompt_resolve(e, t) { | 94 function verify_prompt_resolve(e, t) { |
| 47 e.prompt().then(function() { }, t.unreached_func("prompt() promise should re
solve.")); | 95 e.prompt().then(function() { }, t.unreached_func("prompt() promise should re
solve.")); |
| 48 } | 96 } |
| 49 | 97 |
| 50 function verify_prompt_reject(e, t) { | 98 function verify_prompt_reject(e, t) { |
| 51 e.prompt().then(t.unreached_func("prompt() promise should reject."), | 99 e.prompt().then(t.unreached_func("prompt() promise should reject."), |
| 52 t.step_func(function(error) { | 100 t.step_func(function(error) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 var event_handler = t.step_func(function(e) { | 133 var event_handler = t.step_func(function(e) { |
| 86 // Remove the event handler to prevent it being used in subsequent | 134 // Remove the event handler to prevent it being used in subsequent |
| 87 // invocations of prompt_test(). Save event object for call outside
handler. | 135 // invocations of prompt_test(). Save event object for call outside
handler. |
| 88 window.removeEventListener('beforeinstallprompt', event_handler); | 136 window.removeEventListener('beforeinstallprompt', event_handler); |
| 89 event = e; | 137 event = e; |
| 90 | 138 |
| 91 assert_equals(e.platforms.length, 2, 'Number of platforms'); | 139 assert_equals(e.platforms.length, 2, 'Number of platforms'); |
| 92 assert_equals(e.platforms[0], 'foo', 'First platform'); | 140 assert_equals(e.platforms[0], 'foo', 'First platform'); |
| 93 assert_equals(e.platforms[1], 'bar', 'Second platform'); | 141 assert_equals(e.platforms[1], 'bar', 'Second platform'); |
| 94 | 142 |
| 143 if (test_case.userChoice) { |
| 144 // Access userChoice to ensure it is independent of prompt. |
| 145 e.userChoice; |
| 146 } |
| 147 |
| 95 if (test_case.cancel) { | 148 if (test_case.cancel) { |
| 96 e.preventDefault(); | 149 e.preventDefault(); |
| 97 } | 150 } |
| 98 | 151 |
| 99 if (test_case.late) { | 152 if (test_case.late) { |
| 153 window.setTimeout(function() { |
| 154 assert_false(event == null, "event is null outside handler")
; |
| 155 |
| 156 // Test that firing prompt() outside of the handler resolves
or rejects correctly. |
| 157 if (test_case.cancel) { |
| 158 verify_prompt_resolve(event, t); |
| 159 } else { |
| 160 verify_prompt_reject(event, t); |
| 161 } |
| 162 // Check userChoice and call the next test. |
| 163 verify_userChoice(event, t, test_case, index); |
| 164 }, 0); |
| 100 return; | 165 return; |
| 101 } | 166 } |
| 102 | 167 |
| 103 if (test_case.cancel) { | 168 if (test_case.cancel) { |
| 104 // Call prompt() to restart the pipeline. | 169 // Call prompt() to restart the pipeline. |
| 105 verify_prompt_resolve(e, t); | 170 verify_prompt_resolve(e, t); |
| 106 } else { | 171 } else { |
| 107 // A call to prompt() before preventDefault should reject. | 172 // A call to prompt() before preventDefault should reject. |
| 108 verify_prompt_reject(e, t); | 173 verify_prompt_reject(e, t); |
| 109 } | 174 } |
| 110 | 175 |
| 111 // prompt() has been fired or the event has not been canceled, so ch
eck | 176 // prompt() has been fired or the event has not been canceled, so ch
eck |
| 112 // the userChoice promise and call the next test. | 177 // the userChoice promise and call the next test. |
| 113 verify_userChoice(e, t, test_case, index); | 178 verify_userChoice(e, t, test_case, index); |
| 114 }); | 179 }); |
| 115 window.addEventListener('beforeinstallprompt', event_handler); | 180 window.addEventListener('beforeinstallprompt', event_handler); |
| 116 | 181 |
| 117 testRunner.dispatchBeforeInstallPromptEvent(index, ['foo', 'bar'], t.ste
p_func(function(result) { | 182 testRunner.dispatchBeforeInstallPromptEvent(['foo', 'bar'], t.step_func(
function(result) { |
| 118 testRunner.resolveBeforeInstallPromptPromise(index, test_case.platfo
rm); | 183 testRunner.resolveBeforeInstallPromptPromise(test_case.platform); |
| 119 })); | 184 })); |
| 120 | |
| 121 // Test that firing prompt() outside of the handler resolves or rejects
correctly. | |
| 122 if (test_case.late) { | |
| 123 if (test_case.cancel) { | |
| 124 verify_prompt_resolve(event, t); | |
| 125 } else { | |
| 126 verify_prompt_reject(event, t); | |
| 127 } | |
| 128 // Check userChoice and call the next test. | |
| 129 verify_userChoice(event, t, test_case, index); | |
| 130 } | |
| 131 }, test_case.name); | 185 }, test_case.name); |
| 132 } | 186 } |
| 133 | 187 |
| 134 prompt_test(0); | 188 prompt_test(0); |
| 135 </script> | 189 </script> |
| OLD | NEW |