Best JavaScript code snippet using wpt
close-method.window.js
Source:close-method.window.js
1function assert_closed_opener(w, closed, opener) {2 assert_equals(w.closed, closed);3 assert_equals(w.opener, opener);4}5async_test(t => {6 const openee = window.open();7 assert_closed_opener(openee, false, self);8 openee.onunload = t.step_func(() => {9 assert_closed_opener(openee, true, self);10 t.step_timeout(() => {11 assert_closed_opener(openee, true, null);12 t.done();13 }, 0);14 });15 openee.close();16 assert_closed_opener(openee, true, self);17}, "window.close() queues a task to discard, but window.closed knows immediately");18async_test(t => {19 const openee = window.open("", "greatname");20 assert_closed_opener(openee, false, self);21 openee.close();22 assert_closed_opener(openee, true, self);23 const openee2 = window.open("", "greatname");24 assert_not_equals(openee, openee2);25 assert_closed_opener(openee, true, self); // Ensure second window.open() call was synchronous26 openee2.onunload = t.step_func(() => {27 assert_closed_opener(openee2, true, self);28 t.step_timeout(() => {29 assert_closed_opener(openee, true, null);30 assert_closed_opener(openee2, true, null);31 t.done();32 }, 0);33 });34 openee2.close();35 assert_closed_opener(openee, true, self); // Ensure second close() call was synchronous36 assert_closed_opener(openee2, true, self);...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!