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