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 26 matching lines...) Expand all Loading... |
37 }, { | 37 }, { |
38 name: 'prompt-late-without-preventDefault', | 38 name: 'prompt-late-without-preventDefault', |
39 cancel: false, | 39 cancel: false, |
40 late: true, | 40 late: true, |
41 platform: '', | 41 platform: '', |
42 outcome: 'dismissed' | 42 outcome: 'dismissed' |
43 } | 43 } |
44 ]; | 44 ]; |
45 | 45 |
46 function verify_prompt_resolve(e, t) { | 46 function verify_prompt_resolve(e, t) { |
47 e.prompt().then(function() { }, t.unreached_func("prompt() promise should re
solve.")); | 47 e.prompt().then(undefined, t.unreached_func("prompt() promise should resolve
.")); |
48 } | 48 } |
49 | 49 |
50 function verify_prompt_reject(e, t) { | 50 function verify_prompt_reject(e, t) { |
51 e.prompt().then(t.unreached_func("prompt() promise should reject."), | 51 e.prompt().then(t.unreached_func("prompt() promise should reject."), |
52 t.step_func(function(error) { | 52 t.step_func(function(error) { |
53 assert_true( | 53 assert_true( |
54 error instanceof DOMException, | 54 error instanceof DOMException, |
55 "Rejected promise should throw a DOMException." | 55 "Rejected promise should throw a DOMException." |
56 ); | 56 ); |
57 assert_equals( | 57 assert_equals( |
(...skipping 10 matching lines...) Expand all Loading... |
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 verify_prompt_reject(e, t); |
72 })).then(t.step_func(function() { | 72 })).then(t.step_func(function() { |
73 prompt_test(index + 1); | 73 prompt_test(index + 1); |
74 t.done(); | 74 t.done(); |
75 }), t.unreached_func("userChoice promise should resolve.")); | 75 }), t.unreached_func("userChoice promise should resolve.")); |
76 } | 76 } |
77 | 77 |
| 78 var events = []; // For storing the beforeinstallprompt event. |
78 function prompt_test(index) { | 79 function prompt_test(index) { |
79 if (index >= prompt_test_cases.length) | 80 if (index >= prompt_test_cases.length) |
80 return; | 81 return; |
81 | 82 |
82 var test_case = prompt_test_cases[index]; | 83 var test_case = prompt_test_cases[index]; |
83 async_test(function(t) { | 84 async_test(function(t) { |
84 var event = null; | |
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; | |
90 | 89 |
91 assert_equals(e.platforms.length, 2, 'Number of platforms'); | 90 assert_equals(e.platforms.length, 2, 'Number of platforms'); |
92 assert_equals(e.platforms[0], 'foo', 'First platform'); | 91 assert_equals(e.platforms[0], 'foo', 'First platform'); |
93 assert_equals(e.platforms[1], 'bar', 'Second platform'); | 92 assert_equals(e.platforms[1], 'bar', 'Second platform'); |
94 | 93 |
| 94 if (test_case.cancel) { |
| 95 e.preventDefault(); |
| 96 } |
| 97 |
95 if (test_case.late) { | 98 if (test_case.late) { |
| 99 // Exit the handler once we've stopped the event. |
| 100 events.push(e); |
96 return; | 101 return; |
97 } | 102 } |
98 | 103 |
99 if (test_case.cancel) { | 104 if (test_case.cancel) { |
100 // Cancel the event, then call prompt() to restart the display p
ipeline. | 105 // Call prompt() to restart the pipeline. |
101 e.preventDefault(); | |
102 verify_prompt_resolve(e, t); | 106 verify_prompt_resolve(e, t); |
103 } else { | 107 } else { |
104 // A call to prompt() before preventDefault should reject. | 108 // A call to prompt() before preventDefault should reject. |
105 verify_prompt_reject(e, t); | 109 verify_prompt_reject(e, t); |
106 } | 110 } |
107 | 111 |
108 // prompt() has been fired or the event has not been canceled, so ch
eck | 112 // prompt() has been fired or the event has not been canceled, so ch
eck |
109 // the userChoice promise and call the next test. | 113 // the userChoice promise and call the next test. |
110 verify_userChoice(e, t, test_case, index); | 114 verify_userChoice(e, t, test_case, index); |
111 }); | 115 }); |
112 window.addEventListener('beforeinstallprompt', event_handler); | 116 window.addEventListener('beforeinstallprompt', event_handler); |
113 | 117 |
114 testRunner.dispatchBeforeInstallPromptEvent(index, ['foo', 'bar'], t.ste
p_func(function(result) { | 118 testRunner.dispatchBeforeInstallPromptEvent(index, ['foo', 'bar'], t.ste
p_func(function(result) { |
115 testRunner.resolveBeforeInstallPromptPromise(index, test_case.platfo
rm); | 119 testRunner.resolveBeforeInstallPromptPromise(index, test_case.platfo
rm); |
116 })); | 120 })); |
117 | 121 |
118 // Test that firing prompt() outside of the handler resolves or rejects
correctly. | 122 // Test that firing prompt() outside of the handler resolves or rejects
correctly. |
119 if (test_case.late) { | 123 if (test_case.late) { |
| 124 e = events.pop(); |
120 if (test_case.cancel) { | 125 if (test_case.cancel) { |
121 event.preventDefault(); | 126 verify_prompt_resolve(e, t); |
122 verify_prompt_resolve(event, t); | |
123 } else { | 127 } else { |
124 verify_prompt_reject(event, t); | 128 verify_prompt_reject(e, t); |
125 } | 129 } |
126 // Check userChoice and call the next test. | 130 // Check userChoice and call the next test. |
127 verify_userChoice(event, t, test_case, index); | 131 verify_userChoice(e, t, test_case, index); |
128 } | 132 } |
129 }, test_case.name); | 133 }, test_case.name); |
130 } | 134 } |
131 | 135 |
132 prompt_test(0); | 136 prompt_test(0); |
133 </script> | 137 </script> |
OLD | NEW |