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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/html/browsers/the-window-object/window-open-noopener.html

Issue 2477133002: Import wpt@306326cfe973b6c7019c50879ad03b02825c7539 (Closed)
Patch Set: Modify TestExpectations or download new baselines for tests. Created 4 years, 1 month 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>window.open() with "noopener" tests</title>
4 <script src=/resources/testharness.js></script>
5 <script src=/resources/testharnessreport.js></script>
6 <script>
7 var testData = [
8 { testDescription: "window.open() with 'noopener' should not reuse existing ta rget",
9 secondWindowFeatureString: "noopener",
10 shouldReuse: false },
11 { testDescription: "noopener needs to be present as a token on its own",
12 secondWindowFeatureString: "noopener=1",
13 shouldReuse: true },
14 { testDescription: "noopener needs to be present as a token on its own again",
15 secondWindowFeatureString: "noopener=0",
16 shouldReuse: true },
17 { testDescription: "noopener needs to be present as a token on its own yet aga in",
18 secondWindowFeatureString: "make me noopener",
19 shouldReuse: true },
20 { testDescription: "Trailing noopener should work",
21 secondWindowFeatureString: "abc def, \n\r noopener",
22 shouldReuse: false },
23 { testDescription: "Leading noopener should work",
24 secondWindowFeatureString: "noopener \f\t , hey, there",
25 shouldReuse: false },
26 { testDescription: "Interior noopener should work",
27 secondWindowFeatureString: "and now, noopener , hey, there",
28 shouldReuse: false },
29 ];
30
31 var tests = [];
32 /**
33 * Loop over our testData array and kick off an async test for each entry. Each
34 * async test opens a window using window.open() with some per-test unique name,
35 * then tries to do a second window.open() call with the same name and the
36 * test-specific feature string. It then checks whether that second
37 * window.open() call reuses the existing window, whether the return value of
38 * the second window.open() call is correct (it should be null in the noopener
39 * cases and non-null in the cases when the existing window gets reused) and so
40 * forth.
41 */
42 for (var i = 0; i < testData.length; ++i) {
43 var test = testData[i];
44 var t = async_test(test.testDescription);
45 tests.push(t);
46 t.secondWindowFeatureString = test.secondWindowFeatureString;
47 t.windowName = "someuniquename" + i;
48
49 if (test.shouldReuse) {
50 t.step(function() {
51 var windowName = this.windowName;
52
53 var w1 = window.open("", windowName);
54 this.add_cleanup(function() { w1.close(); });
55
56 assert_equals(w1.opener, window);
57
58 var w2 = window.open("", windowName, this.secondWindowFeatureString);
59 assert_equals(w2, w1);
60 assert_equals(w2.opener, w1.opener);
61 assert_equals(w2.opener, window);
62 this.done();
63 });
64 } else {
65 t.step(function() {
66 var w1;
67 this.add_cleanup(function() { w1.close(); });
68
69 var windowName = this.windowName;
70 var channel = new BroadcastChannel(windowName);
71
72 channel.onmessage = this.step_func_done(function(e) {
73 var data = e.data;
74 assert_equals(data.name, windowName, "Should have the right name");
75 assert_equals(data.haveOpener, false, "Should not have opener");
76 assert_equals(w1.opener, window);
77 assert_equals(w1.location.href, "about:blank");
78 });
79
80 w1 = window.open("", windowName);
81 assert_equals(w1.opener, window);
82
83 var w2 = window.open("support/noopener-target.html?" + windowName,
84 windowName, this.secondWindowFeatureString);
85 assert_equals(w2, null);
86
87 assert_equals(w1.opener, window);
88 });
89 }
90 }
91
92 /**
93 * Loop over the special targets that ignore noopener and check that doing a
94 * window.open() with those targets correctly reuses the existing window.
95 */
96 for (var target of ["_self", "_parent", "_top"]) {
97 var t = async_test("noopener window.open targeting " + target);
98 tests.push(t);
99 t.openedWindow = window.open(`javascript:var w2 = window.open("", "${target}", "noopener"); this.checkValues(w2); this.close(); void(0);`);
100 assert_equals(t.openedWindow.opener, window);
101 t.openedWindow.checkValues = t.step_func_done(function(win) {
102 assert_equals(win, this.openedWindow);
103 });
104 }
105 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698