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

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 testing prompt() call outside handler 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 ];
39
40 function verify_prompt_reject(e, t) {
41 e.prompt().then(t.unreached_func("prompt() promise should reject."),
42 t.step_func(function(error) {
43 assert_true(
44 error instanceof DOMException,
45 "Rejected promise should throw a DOMException."
46 );
47 assert_equals(
48 error.message,
49 "The prompt() method may only be called once, following preventD efault().",
50 "Rejected promise does not provide expected message."
51 );
52 })
53 );
54 }
55
56 function verify_userChoice(e, t, test_case, index) {
57 e.userChoice.then(t.step_func(function(result) {
58 assert_equals(result.platform, test_case.platform, 'Resolved platform');
59 assert_equals(result.outcome, test_case.outcome, 'Outcome');
60 })).then(t.step_func(function() {
61 verify_prompt_reject(e, t);
62 })).then(t.step_func(function() {
63 prompt_test(index + 1);
64 t.done();
65 }), t.unreached_func("userChoice promise should resolve."));
66 }
67
68 function prompt_test(index) {
69 if (index >= prompt_test_cases.length)
70 return;
71
72 var test_case = prompt_test_cases[index];
73 async_test(function(t) {
74 var event = null;
75 var event_handler = t.step_func(function(e) {
76 // Remove the event handler to prevent it being used in subsequent
77 // invocations of prompt_test(). Save event object for call outside handler.
78 window.removeEventListener('beforeinstallprompt', event_handler);
79 event = e;
80
81 assert_equals(e.platforms.length, 2, 'Number of platforms');
82 assert_equals(e.platforms[0], 'foo', 'First platform');
83 assert_equals(e.platforms[1], 'bar', 'Second platform');
84
85 if (test_case.cancel) {
mlamouri (slow - plz ping) 2015/06/25 10:17:36 You are assuming test_case.cancel will be true if
dominickn 2015/06/25 17:30:21 Done.
86 // Cancel the event, then call prompt() to restart the display p ipeline.
87 e.preventDefault();
88 if (!test_case.late) {
89 // Fire prompt() in the event handler.
90 e.prompt().then(function() { }, t.unreached_func("prompt() p romise should resolve."));
91 }
92 } else {
93 // A call to prompt() before preventDefault should reject.
94 verify_prompt_reject(e, t);
95 }
96
97 if (!test_case.late) {
98 // prompt() has been fired or the event has not been canceled, s o check
99 // the userChoice promise and call the next test.
100 verify_userChoice(e, t, test_case, index);
101 }
102 });
103 window.addEventListener('beforeinstallprompt', event_handler);
104
105 testRunner.dispatchBeforeInstallPromptEvent(index, ['foo', 'bar'], t.ste p_func(function(result) {
106 testRunner.resolveBeforeInstallPromptPromise(index, test_case.platfo rm);
107 }));
108
109 // Test firing the prompt() and checking userChoice outside the event ha ndler.
110 if (test_case.late) {
111 event.prompt().then(function() { }, t.unreached_func("prompt() promi se should resolve."));
mlamouri (slow - plz ping) 2015/06/25 10:17:36 ... and here, given that preventDefault() wasn't c
dominickn 2015/06/25 17:30:21 Done.
112 verify_userChoice(event, t, test_case, index);
113 }
114 }, test_case.name);
115 }
116
117 prompt_test(0);
118 </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