Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1439)

Side by Side Diff: LayoutTests/app_banner/app-banner-event-prompt.html

Issue 1202043002: Adding tests for the prompt() method on the beforeinstallprompt event (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressing reviewer comments and adding additional test Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script>
4 <script>
5
6 var prompt_test_cases = [
7 {
8 name: 'prompt-accept',
9 cancel: true,
10 late: false,
11 platform: 'foo',
12 outcome: 'accepted'
13 }, {
14 name: 'prompt-dismiss',
15 cancel: true,
16 late: false,
17 platform: '',
18 outcome: 'dismissed'
19 }, {
20 name: 'prompt-before-preventDefault',
21 cancel: false,
22 late: false,
23 platform: 'foo',
24 outcome: 'accepted'
25 }, {
26 name: 'prompt-late-accept',
27 cancel: true,
28 late: true,
29 platform: 'foo',
30 outcome: 'accepted'
31 }, {
32 name: 'prompt-late-dismiss',
33 cancel: true,
34 late: true,
35 platform: '',
36 outcome: 'dismissed'
37 }, {
38 name: 'prompt-late-without-preventDefault',
39 cancel: false,
40 late: true,
41 platform: '',
42 outcome: 'dismissed'
43 }
44 ];
45
46 function verify_prompt_resolve(e, t) {
47 e.prompt().then(function() { }, t.unreached_func("prompt() promise should re solve."));
48 }
49
50 function verify_prompt_reject(e, t) {
51 e.prompt().then(t.unreached_func("prompt() promise should reject."),
52 t.step_func(function(error) {
53 assert_true(
54 error instanceof DOMException,
55 "Rejected promise should throw a DOMException."
56 );
57 assert_equals(
58 error.message,
59 "The prompt() method may only be called once, following preventD efault().",
60 "Rejected promise does not provide expected message."
61 );
62 })
63 );
64 }
65
66 function verify_userChoice(e, t, test_case, index) {
67 e.userChoice.then(t.step_func(function(result) {
68 assert_equals(result.platform, test_case.platform, 'Resolved platform');
69 assert_equals(result.outcome, test_case.outcome, 'Outcome');
70 })).then(t.step_func(function() {
71 verify_prompt_reject(e, t);
72 })).then(t.step_func(function() {
73 prompt_test(index + 1);
74 t.done();
75 }), t.unreached_func("userChoice promise should resolve."));
76 }
77
78 function prompt_test(index) {
79 if (index >= prompt_test_cases.length)
80 return;
81
82 var test_case = prompt_test_cases[index];
83 async_test(function(t) {
84 var event = null;
85 var event_handler = t.step_func(function(e) {
86 // Remove the event handler to prevent it being used in subsequent
87 // invocations of prompt_test(). Save event object for call outside handler.
88 window.removeEventListener('beforeinstallprompt', event_handler);
89 event = e;
90
91 assert_equals(e.platforms.length, 2, 'Number of platforms');
92 assert_equals(e.platforms[0], 'foo', 'First platform');
93 assert_equals(e.platforms[1], 'bar', 'Second platform');
94
95 if (test_case.late) {
96 return;
97 }
98
99 if (test_case.cancel) {
100 // Cancel the event, then call prompt() to restart the display p ipeline.
101 e.preventDefault();
102 verify_prompt_resolve(e, t);
103 } else {
104 // A call to prompt() before preventDefault should reject.
105 verify_prompt_reject(e, t);
106 }
107
108 // prompt() has been fired or the event has not been canceled, so ch eck
109 // the userChoice promise and call the next test.
110 verify_userChoice(e, t, test_case, index);
111 });
112 window.addEventListener('beforeinstallprompt', event_handler);
113
114 testRunner.dispatchBeforeInstallPromptEvent(index, ['foo', 'bar'], t.ste p_func(function(result) {
115 testRunner.resolveBeforeInstallPromptPromise(index, test_case.platfo rm);
116 }));
117
118 // Test that firing prompt() outside of the handler resolves or rejects correctly.
119 if (test_case.late) {
120 if (test_case.cancel) {
121 event.preventDefault();
122 verify_prompt_resolve(event, t);
123 } else {
124 verify_prompt_reject(event, t);
125 }
126 // Check userChoice and call the next test.
127 verify_userChoice(event, t, test_case, index);
128 }
129 }, test_case.name);
130 }
131
132 prompt_test(0);
133 </script>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698