How to use eLoadInUnsandboxedIframe 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 wpt = new WebPageTest('www.webpagetest.org');2 console.log(data);3});4var wpt = new WebPageTest('www.webpagetest.org');5 console.log(data);6});7var wpt = new WebPageTest('www.webpagetest.org');8 console.log(data);9});10var wpt = new WebPageTest('www.webpagetest.org');11 console.log(data);12});13var wpt = new WebPageTest('www.webpagetest.org');14 console.log(data);15});16var wpt = new WebPageTest('www.webpagetest.org');17 console.log(data);18});19var wpt = new WebPageTest('www.webpagetest.org');20 console.log(data);21});22var wpt = new WebPageTest('www.webpagetest.org');23 console.log(data);24});25var wpt = new WebPageTest('www

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptb = window.top.wptb;2var wptb = window.top.wptb;3var wptb = window.top.wptb;4var wptb = window.top.wptb;5var wptb = window.top.wptb;6var wptb = window.top.wptb;7var wptb = window.top.wptb;8var wptb = window.top.wptb;9var wptb = window.top.wptb;10var wptb = window.top.wptb;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = new WebPageTest();2wpt.onLoadFinished = function() {3 console.log("onLoadFinished");4 console.log("Page title is " + this.evaluate(function() {5 return document.title;6 }));7 this.render("google.png");8 this.exit();9};10wpt.onConsoleMessage = function(msg) {11 console.log(msg);12};13var wpt = new WebPageTest();14wpt.onLoadFinished = function() {15 console.log("onLoadFinished");16 console.log("Page title is " + this.evaluate(function() {17 return document.title;18 }));19 this.render("google.png");20 this.exit();21};22wpt.onConsoleMessage = function(msg) {23 console.log(msg);24};25var wpt = new WebPageTest();26wpt.onLoadFinished = function() {27 console.log("onLoadFinished");28 console.log("Page title is " + this.evaluate(function() {29 return document.title;30 }));31 this.render("google.png");32 this.exit();33};34wpt.onConsoleMessage = function(msg) {35 console.log(msg);36};37var wpt = new WebPageTest();38wpt.onLoadFinished = function() {39 console.log("onLoadFinished");40 console.log("Page title is " + this.evaluate(function() {41 return document.title;42 }));43 this.render("google.png");44 this.exit();45};46wpt.onConsoleMessage = function(msg) {47 console.log(msg);48};49var wpt = new WebPageTest();50wpt.onLoadFinished = function() {51 console.log("onLoadFinished");52 console.log("Page title is " + this.evaluate(function() {53 return document.title;54 }));55 this.render("google.png");56 this.exit();57};

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require("wptools");2var worker = require("worker");3exports.main = function () {4 var iframe = wptools.eLoadInUnsandboxedIframe(url);5 iframe.addEventListener("load", function () {6 worker.port.emit("loaded", url);7 });8};9var wptools = require("wptools");10var self = require("self");11exports.main = function () {12 var url = self.data.url("test.html");13 var iframe = wptools.eLoadInUnsandboxedIframe(url);14 iframe.addEventListener("load", function () {15 console.log("loaded");16 });17};18function onLoad() {19 console.log("loaded");20}21var wptools = exports;22wptools.eLoadInUnsandboxedIframe = function (url) {23 var iframe = document.createElement("iframe");24 iframe.setAttribute("src", url);25 iframe.setAttribute("type", "content");26 iframe.setAttribute("style", "display:none;");27 document.documentElement.appendChild(iframe);28 return iframe;29}30I've tested this with a build of Firefox 4.0b7pre (2011-01-06) on Windows XP SP3

Full Screen

Using AI Code Generation

copy

Full Screen

1function test() {2 var iframe = document.createElement('iframe');3 iframe.id = 'testFrame';4 document.body.appendChild(iframe);5 wpt.eLoadInUnsandboxedIframe(iframe.id, url);6}7<body onload="test();">8<body onload="test();">9function test() {10 var iframe = document.createElement('iframe');11 iframe.id = 'testFrame';12 document.body.appendChild(iframe);13 wpt.eLoadInUnsandboxedIframe(iframe.id, url);14}15<body onload="test();">16function test() {17 var iframe = document.createElement('iframe');18 iframe.id = 'testFrame';19 document.body.appendChild(iframe);20 wpt.eLoadInUnsandboxedIframe(iframe.id, url);21}22<body onload="test();">23function test() {24 var iframe = document.createElement('iframe');25 iframe.id = 'testFrame';

Full Screen

Using AI Code Generation

copy

Full Screen

1var iframeId = "iframeId";2var iframeName = "iframeName";3var iframeHeight = "1000px";4var iframeWidth = "1000px";5var iframeScrolling = "yes";6var iframeOnload = "iframeOnload()";7var iframeOnerror = "iframeOnerror()";8var iframeOnabort = "iframeOnabort()";9var iframeOnunload = "iframeOnunload()";10var iframeOnmessage = "iframeOnmessage()";11var iframeOnresize = "iframeOnresize()";12var iframeOnscroll = "iframeOnscroll()";13var iframeOnbeforeunload = "iframeOnbeforeunload()";14var iframeOnblur = "iframeOnblur()";15var iframeOnfocus = "iframeOnfocus()";16var iframeOnhashchange = "iframeOnhashchange()";17var iframeOnpopstate = "iframeOnpopstate()";18var iframeOnstorage = "iframeOnstorage()";19var iframeOncontextmenu = "iframeOncontextmenu()";20var iframeOncopy = "iframeOncopy()";21var iframeOncut = "iframeOncut()";22var iframeOnpaste = "iframeOnpaste()";

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