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

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: 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',
9 cancel: true,
10 platform: 'foo',
11 outcome: 'accepted'
12 }, {
13 name: 'prompt-dismissed',
14 cancel: true,
15 platform: '',
16 outcome: 'dismissed'
17 }, {
18 name: 'prompt-before-preventDefault',
19 cancel: false,
20 platform: 'foo',
21 outcome: 'accepted'
22 }
23 ];
24
25 function verify_prompt_reject(e, t, callback) {
26 e.prompt().then(t.unreached_func("prompt() promise should reject."),
27 t.step_func(function(error) {
28 assert_true(
29 error instanceof DOMException,
30 "Rejected promise should throw a DOMException."
31 );
32 assert_equals(
33 error.message,
34 "The prompt() method may only be called once, following preventD efault().",
35 "Rejected promise does not provide expected message."
36 );
37 typeof callback === 'function' && callback();
38 })
39 );
40 }
41
42 function prompt_test(index) {
43 if (index >= prompt_test_cases.length)
44 return;
45
46 var test_case = prompt_test_cases[index];
47 async_test(function(t) {
48 var event_handler = t.step_func(function(e) {
49 // Remove the event handler to prevent it being used in subsequent
50 // invocations of prompt_test().
51 window.removeEventListener('beforeinstallprompt', event_handler);
52
53 assert_equals(e.platforms.length, 2, 'Number of platforms');
54 assert_equals(e.platforms[0], 'foo', 'First platform');
55 assert_equals(e.platforms[1], 'bar', 'Second platform');
56
57 if (test_case.cancel) {
58 // Cancel the event, then call prompt() to restart the display p ipeline.
59 e.preventDefault();
60 e.prompt().then(function() { }, t.unreached_func("prompt() promi se should resolve."));
61 } else {
62 // A call to prompt() before preventDefault should reject.
63 verify_prompt_reject(e, t);
64 }
65
66 e.userChoice.then(t.step_func(function(result) {
67 assert_equals(result.platform, test_case.platform, 'Resolved pla tform');
68 assert_equals(result.outcome, test_case.outcome, 'Outcome');
mlamouri (slow - plz ping) 2015/06/24 13:56:51 What about: e.userChoice.then(t.step_func(functio
dominickn 2015/06/24 23:09:13 Done. Also added tests for prompt() calls outside
69 }), t.unreached_func("userChoice promise should resolve."));
70
71 // A call to prompt() here should reject, as either preventDefault
72 // has not been called, or prompt() has already been called.
73 verify_prompt_reject(e, t, t.step_func(function() {
74 prompt_test(index + 1);
75 t.done();
76 }));
77 });
78 window.addEventListener('beforeinstallprompt', event_handler);
79
80 testRunner.dispatchBeforeInstallPromptEvent(index, ['foo', 'bar'], t.ste p_func(function(result) {
81 testRunner.resolveBeforeInstallPromptPromise(index, test_case.platfo rm);
82 }));
83 }, test_case.name);
84 }
85
86 prompt_test(0);
87 </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