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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/html/browsers/browsing-the-web/unloading-documents/beforeunload-canceling.html

Issue 2695813009: Import wpt@503f5b5f78ec4e87d144f78609f363f0ed0ea8db (Closed)
Patch Set: Skip some tests Created 3 years, 10 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
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <meta charset="utf-8">
3 <title>beforeunload return value cancelation behavior</title>
4 <link rel="help" href="https://html.spec.whatwg.org/multipage/webappapis.html#th e-event-handler-processing-algorithm">
5 <link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">
6 <script src="/resources/testharness.js"></script>
7 <script src="/resources/testharnessreport.js"></script>
8
9 <div id="log"></div>
10
11 <script>
12 "use strict";
13
14 async_test(t => {
15 let onbeforeunloadHappened = false;
16 window.onbeforeunload = t.step_func(() => {
17 onbeforeunloadHappened = true;
18 return "cancel me";
19 });
20
21 const listener = t.step_func(e => {
22 assert_true(onbeforeunloadHappened, "CustomEvent must be able to trigger the event handler");
23 assert_false(e.defaultPrevented, "The event must not have been canceled");
24 window.onbeforeunload = null;
25 t.done();
26 });
27
28 window.addEventListener("beforeunload", listener);
29
30 window.dispatchEvent(new CustomEvent("beforeunload"));
31 }, "Returning a string must not cancel the event: CustomEvent, non-cancelable");
32
33 async_test(t => {
34 let onbeforeunloadHappened = false;
35 window.onbeforeunload = t.step_func(() => {
36 onbeforeunloadHappened = true;
37 return "cancel me";
38 });
39
40 const listener = t.step_func(e => {
41 assert_true(onbeforeunloadHappened, "CustomEvent must be able to trigger the event handler");
42 assert_false(e.defaultPrevented, "The event must not have been canceled");
43 window.onbeforeunload = null;
44 t.done();
45 });
46
47 window.addEventListener("beforeunload", listener);
48
49 window.dispatchEvent(new CustomEvent("beforeunload", { cancelable: true }));
50 }, "Returning a string must not cancel the event: CustomEvent, cancelable");
51
52 const testCases = [
53 {
54 valueToReturn: null,
55 expectCancelation: false,
56 expectedReturnValue: ""
57 },
58 {
59 valueToReturn: undefined,
60 expectCancelation: false,
61 expectedReturnValue: ""
62 },
63 {
64 valueToReturn: "",
65 expectCancelation: true,
66 expectedReturnValue: ""
67 },
68 {
69 valueToReturn: false,
70 expectCancelation: true,
71 expectedReturnValue: "false"
72 },
73 {
74 valueToReturn: true,
75 expectCancelation: true,
76 expectedReturnValue: "true"
77 },
78 {
79 valueToReturn: 0,
80 expectCancelation: true,
81 expectedReturnValue: "0"
82 },
83 {
84 valueToReturn: null,
85 expectCancelation: false,
86 setReturnValue: "foo",
87 expectedReturnValue: "foo"
88 },
89 {
90 valueToReturn: undefined,
91 expectCancelation: false,
92 setReturnValue: "foo",
93 expectedReturnValue: "foo"
94 },
95 {
96 valueToReturn: "",
97 expectCancelation: true,
98 setReturnValue: "foo",
99 expectedReturnValue: "foo"
100 },
101 {
102 valueToReturn: false,
103 expectCancelation: true,
104 setReturnValue: "foo",
105 expectedReturnValue: "foo"
106 },
107 {
108 valueToReturn: true,
109 expectCancelation: true,
110 setReturnValue: "foo",
111 expectedReturnValue: "foo"
112 },
113 {
114 valueToReturn: 0,
115 expectCancelation: true,
116 setReturnValue: "foo",
117 expectedReturnValue: "foo"
118 }
119 ];
120
121 for (const testCase of testCases) {
122 const labelAboutReturnValue = testCase.setReturnValue === undefined ? "" :
123 `; setting returnValue to ${testCase.setReturnValue}`;
124
125 async_test(t => {
126 const iframe = document.createElement("iframe");
127 iframe.onload = t.step_func(() => {
128 iframe.contentWindow.runTest(t, testCase);
129 });
130
131 iframe.src = "beforeunload-canceling-1.html";
132 document.body.appendChild(iframe);
133 }, `Returning ${testCase.valueToReturn} with a real iframe unloading${labelAbo utReturnValue}`);
134 }
135 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698