How to use eLoadInPopup method in wpt

Best JavaScript code snippet using wpt

basic-popup-and-iframe-tests.https.js

Source:basic-popup-and-iframe-tests.https.js Github

copy

Full Screen

1/**2 * This test checks the Secure Context state of documents for various3 * permutations of document URI types and loading methods.4 *5 * The hierarchy that is tested is:6 *7 * creator-doc > createe-doc8 *9 * The creator-doc is one of:10 *11 * http:12 * https:13 *14 * The createe-doc is loaded as either a:15 *16 * popup17 * iframe18 * sandboxed-iframe19 *20 * into which we load and test:21 *22 * http:23 * https:24 * blob:25 * javascript:26 * about:blank27 * initial about:blank28 * srcdoc29 *30 * TODO once web-platform-tests supports it:31 * - test http://localhost32 * - test file:33 *34 * TODO once https://github.com/w3c/webappsec-secure-contexts/issues/26 is resolved35 * - test data:36 */37setup({explicit_done:true});38const host_and_dirname = location.host +39 location.pathname.substr(0, location.pathname.lastIndexOf("/") + 1);40// Flags to indicate where document types should be loaded for testing:41const eLoadInPopup = (1 << 0);42const eLoadInUnsandboxedIframe = (1 << 1);43const eLoadInSandboxedIframe = (1 << 2);44const eLoadInEverything = eLoadInPopup | eLoadInUnsandboxedIframe | eLoadInSandboxedIframe;45// Flags indicating if a document type is expected to be a Secure Context:46const eSecureNo = 1;47const eSecureIfCreatorSecure = 2;48// Flags indicating how the result of a test is obtained:49const eResultFromPostMessage = 1;50const eResultFromExaminationOnLoad = 2;51const eResultFromExaminationSync = 3;52const loadTypes = [53 new LoadType("an http: URI",54 eLoadInEverything,55 http_dir + "postMessage-helper.html",56 eSecureNo,57 eResultFromPostMessage),58 new LoadType("an https: URI",59 eLoadInEverything,60 https_dir + "postMessage-helper.https.html",61 eSecureIfCreatorSecure,62 eResultFromPostMessage),63 new LoadType("a blob: URI",64 eLoadInEverything,65 URL.createObjectURL(new Blob(["<script>(opener||parent).postMessage(isSecureContext, '*')</script>"], {type: "text/html"})),66 eSecureIfCreatorSecure,67 eResultFromPostMessage),68 new LoadType("a srcdoc",69 // popup not relevant:70 eLoadInUnsandboxedIframe | eLoadInSandboxedIframe,71 "<script>(opener||parent).postMessage(isSecureContext, '*')</script>",72 eSecureIfCreatorSecure,73 eResultFromPostMessage),74 new LoadType("a javascript: URI",75 // can't load in sandbox:76 eLoadInUnsandboxedIframe | eLoadInPopup,77 "javascript:(opener||parent).postMessage(isSecureContext, '*')",78 eSecureIfCreatorSecure,79 eResultFromPostMessage),80 new LoadType("about:blank",81 // can't obtain state if sandboxed:82 eLoadInUnsandboxedIframe | eLoadInPopup,83 "about:blank",84 eSecureIfCreatorSecure,85 eResultFromExaminationOnLoad),86 new LoadType("initial about:blank",87 // can't obtain state if sandboxed:88 eLoadInUnsandboxedIframe | eLoadInPopup,89 "about:blank", // we don't wait for this to load, so whatever90 eSecureIfCreatorSecure,91 eResultFromExaminationSync),92];93const loadTargets = [94 new LoadTarget("an iframe", eLoadInUnsandboxedIframe),95 new LoadTarget("a sandboxed iframe", eLoadInSandboxedIframe),96 new LoadTarget("a popup", eLoadInPopup),97];98function LoadType(description, loadInFlags, uri, expectedSecureFlag, resultFrom) {99 this.desc = description;100 this.loadInFlags = loadInFlags;101 this.uri = uri;102 this.expectedSecureFlag = expectedSecureFlag;103 this.resultFrom = resultFrom;104}105function LoadTarget(description, loadInFlag) {106 this.desc = description;107 this.loadInFlag = loadInFlag;108}109LoadTarget.prototype.open = function(loadType) {110 let loadTarget = this;111 this.currentTest.step(function() {112 assert_true((loadTarget.loadInFlag & loadType.loadInFlags) != 0,113 loadType.desc + " cannot be tested in " + loadTarget.desc);114 });115 if (this.loadInFlag == eLoadInUnsandboxedIframe) {116 let iframe = document.createElement("iframe");117 document.body.appendChild(iframe);118 iframe[loadType.desc == "a srcdoc" ? "srcdoc" : "src"] = loadType.uri;119 return iframe;120 }121 if (this.loadInFlag == eLoadInSandboxedIframe) {122 let iframe = document.body.appendChild(document.createElement("iframe"));123 iframe.setAttribute("sandbox", "allow-scripts");124 iframe[loadType.desc == "a srcdoc" ? "srcdoc" : "src"] = loadType.uri;125 return iframe;126 }127 if (this.loadInFlag == eLoadInPopup) {128 return window.open(loadType.uri);129 }130 this.currentTest.step(function() {131 assert_unreached("Unknown load type flag: " + loadInFlags);132 });133 return null;134}135LoadTarget.prototype.close = function(domTarget) {136 if (this.loadInFlag == eLoadInUnsandboxedIframe ||137 this.loadInFlag == eLoadInSandboxedIframe) {138 domTarget.remove();139 return;140 }141 if (this.loadInFlag == eLoadInPopup) {142 domTarget.close();143 return;144 }145 this.currentTest.step(function() {146 assert_unreached("Unknown load type flag: " + loadInFlags);147 });148}149LoadTarget.prototype.load_and_get_result_for = function(loadType) {150 if (!(loadType.loadInFlags & this.loadInFlag)) {151 return Promise.reject("not applicable");152 }153 if (!(this.loadInFlag & eLoadInPopup) &&154 location.protocol == "https:" &&155 loadType.uri.substr(0,5) == "http:") {156 // Mixed content blocker will prevent this load157 return Promise.reject("not applicable");158 }159 this.currentTest = async_test("Test Window.isSecureContext in " + this.desc +160 " loading " + loadType.desc)161 if (loadType.resultFrom == eResultFromExaminationSync) {162 let domTarget = this.open(loadType);163 let result = domTarget instanceof Window ?164 domTarget.isSecureContext : domTarget.contentWindow.isSecureContext;165 this.close(domTarget);166 return Promise.resolve(result);167 }168 let target = this;169 if (loadType.resultFrom == eResultFromExaminationOnLoad) {170 return new Promise(function(resolve, reject) {171 function handleLoad(event) {172 let result = domTarget instanceof Window ?173 domTarget.isSecureContext : domTarget.contentWindow.isSecureContext;174 domTarget.removeEventListener("load", handleLoad);175 target.close(domTarget);176 resolve(result);177 }178 let domTarget = target.open(loadType);179 domTarget.addEventListener("load", handleLoad, false);180 });181 }182 if (loadType.resultFrom == eResultFromPostMessage) {183 return new Promise(function(resolve, reject) {184 function handleMessage(event) {185 window.removeEventListener("message", handleMessage);186 target.close(domTarget);187 resolve(event.data);188 }189 window.addEventListener("message", handleMessage, false);190 let domTarget = target.open(loadType);191 });192 }193 return Promise.reject("unexpected 'result from' type");194}195let current_type_index = -1;196let current_target_index = 0;197function run_next_test() {198 current_type_index++;199 if (current_type_index >= loadTypes.length) {200 current_type_index = 0;201 current_target_index++;202 if (current_target_index >= loadTargets.length) {203 done();204 return; // all test permutations complete205 }206 }207 let loadTarget = loadTargets[current_target_index];208 let loadType = loadTypes[current_type_index];209 loadTarget.load_and_get_result_for(loadType).then(210 function(value) {211 run_next_test_soon();212 loadTarget.currentTest.step(function() {213 if (loadType.expectedSecureFlag == eSecureNo) {214 assert_false(value, loadType.desc + " in " + loadTarget.desc + " should not create a Secure Context");215 } else if (loadType.expectedSecureFlag == eSecureIfCreatorSecure) {216 if (!window.isSecureContext) {217 assert_false(value, loadType.desc + " in " + loadTarget.desc + " should not create a Secure Context when its creator is not a Secure Context.");218 } else {219 assert_true(value, loadType.desc + " in " + loadTarget.desc + " should create a Secure Context when its creator is a Secure Context");220 }221 } else {222 assert_unreached(loadType.desc + " - unknown expected secure flag: " + expectedSecureFlag);223 }224 loadTarget.currentTest.done();225 });226 },227 function(failReason) {228 run_next_test_soon();229 if (failReason == "not applicable") {230 return;231 }232 loadTarget.currentTest.step(function() {233 assert_unreached(loadType.desc + " - got unexpected rejected promise");234 });235 }236 );237}238function run_next_test_soon() {239 setTimeout(run_next_test, 0);240}241function begin() {242 test(function() {243 if (location.protocol == "http:") {244 assert_false(isSecureContext,245 "http: creator should not be a Secure Context");246 } else if (location.protocol == "https:") {247 assert_true(isSecureContext,248 "https: creator should be a Secure Context");249 } else {250 assert_unreached("Unknown location.protocol");251 }252 });253 run_next_test();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var eLoadInPopup = wptoolkit.eLoadInPopup;3var loadInPopup = wptoolkit.loadInPopup;4var eLoadInWindow = wptoolkit.eLoadInWindow;5var loadInWindow = wptoolkit.loadInWindow;6var params = {7 callback: function(window) {8 window.document.title = "myPopup";9 }10};11loadInWindow(params);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptk = require('wptoolkit');2var wptk = require('wptoolkit');3var wptk = require('wptoolkit');4var wptk = require('wptoolkit');5var wptk = require('wptoolkit');6var wptk = require('wptoolkit');7var wptk = require('wptoolkit');8var wptk = require('wptoolkit');9var wptk = require('wptoolkit');10var wptk = require('wptoolkit');

Full Screen

Using AI Code Generation

copy

Full Screen

1wptbBuilder.eLoadInPopup( 'test', 'test' );2add_action( 'wp_ajax_test', 'test' );3function test() {4 $response = array(5 );6 echo json_encode( $response );7 wp_die();8}

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2popup.show();3var wptools = require('wptools');4popup.show();5var wptools = require('wptools');6popup.show();7var wptools = require('wptools');8popup.show();9var wptools = require('wptools');10popup.show();11var wptools = require('wptools');12popup.show();13var wptools = require('wptools');14popup.show();15var wptools = require('wptools');16popup.show();17var wptools = require('w

Full Screen

Using AI Code Generation

copy

Full Screen

1var textfield = wptextfield.eloadInPopup();2textfield.value = "Text field value";3var value = textfield.value;4var myVar = textfield.value;5textfield.setVar("myVar");6var value = textfield.getVar("myVar");7textfield.value = textfield.getVar("myVar");8textfield.setVar("myVar", "Text field value");9textfield.value = textfield.getVar("myVar");10textfield.value = textfield.getVar("myVar");11textfield.setVar("myVar", "Text field value");12textfield.value = textfield.getVar("myVar");13textfield.value = textfield.getVar("myVar");14textfield.setVar("myVar", "Text field value");15textfield.value = textfield.getVar("myVar");

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful