How to use sameOriginURL method in wpt

Best JavaScript code snippet using wpt

frame-observer-test.js

Source:frame-observer-test.js Github

copy

Full Screen

1import { delay, waitFor } from '../../test-util/wait';2import {3 FrameObserver,4 onDocumentReady,5 onNextDocumentReady,6 $imports,7} from '../frame-observer';8function waitForEvent(target, event) {9 return new Promise(resolve => {10 target.addEventListener(event, () => resolve());11 });12}13function waitForCall(spy) {14 return waitFor(() => spy.called, 300 /* timeout */);15}16describe('annotator/frame-observer', () => {17 let container;18 afterEach(() => {19 container.remove();20 });21 beforeEach(() => {22 container = document.createElement('div');23 document.body.append(container);24 });25 describe('FrameObserver', () => {26 let frameObserver;27 let onFrameAdded;28 let onFrameRemoved;29 const sandbox = sinon.createSandbox();30 function createAnnotatableIFrame(31 attribute = 'enable-annotation',32 value = ''33 ) {34 const iframe = document.createElement('iframe');35 iframe.setAttribute(attribute, value);36 container.appendChild(iframe);37 return iframe;38 }39 function waitForIFrameUnload(iframe) {40 return new Promise(resolve =>41 iframe.contentWindow.addEventListener('unload', resolve)42 );43 }44 beforeEach(() => {45 sandbox.stub(console, 'warn');46 $imports.$mock({47 // Disable debouncing48 'lodash.debounce': callback => callback,49 });50 onFrameAdded = sandbox.stub();51 onFrameRemoved = sandbox.stub();52 frameObserver = new FrameObserver(53 container,54 onFrameAdded,55 onFrameRemoved56 );57 });58 afterEach(() => {59 container.remove();60 frameObserver.disconnect();61 sandbox.restore();62 $imports.$restore();63 });64 it('triggers onFrameAdded when an annotatable iframe is added', async () => {65 const iframe = createAnnotatableIFrame();66 await waitForCall(onFrameAdded);67 assert.calledWith(onFrameAdded, iframe);68 });69 it("doesn't trigger onFrameAdded when non-annotatable iframes are added", async () => {70 createAnnotatableIFrame('dummy-attribute');71 await delay(10);72 assert.notCalled(onFrameAdded);73 });74 it('removal of the annotatable iframe triggers onFrameRemoved', async () => {75 const iframe = createAnnotatableIFrame();76 await waitForCall(onFrameAdded);77 assert.calledOnce(onFrameAdded);78 assert.calledWith(onFrameAdded, iframe);79 iframe.remove();80 await waitForCall(onFrameRemoved);81 assert.calledOnce(onFrameRemoved);82 assert.calledWith(onFrameRemoved, iframe);83 });84 it('removal of the `enable-annotation` attribute triggers onFrameRemoved', async () => {85 const iframe = createAnnotatableIFrame();86 await waitForCall(onFrameAdded);87 assert.calledOnce(onFrameAdded);88 assert.calledWith(onFrameAdded, iframe);89 iframe.removeAttribute('enable-annotation');90 await waitForCall(onFrameRemoved);91 assert.calledOnce(onFrameRemoved);92 assert.calledWith(onFrameRemoved, iframe);93 });94 it('changing the `src` attribute triggers onFrameRemoved', async () => {95 const iframe = createAnnotatableIFrame();96 await waitForCall(onFrameAdded);97 assert.calledOnce(onFrameAdded);98 assert.calledWith(onFrameAdded, iframe);99 iframe.setAttribute('src', 'http://localhost:1');100 await waitForIFrameUnload(iframe);101 assert.calledOnce(onFrameRemoved);102 assert.calledWith(onFrameRemoved, iframe);103 });104 it(`doesn't call onFrameAdded if FrameObserver is disconnected`, async () => {105 frameObserver.disconnect();106 const iframe = createAnnotatableIFrame();107 frameObserver._discoverFrames(); // Emulate a race condition108 await onNextDocumentReady(iframe);109 assert.notCalled(onFrameAdded);110 });111 it("doesn't trigger onFrameAdded when annotatable iframe is from a different domain", async () => {112 const iframe = createAnnotatableIFrame();113 iframe.setAttribute('src', 'http://localhost:1');114 await waitForCall(console.warn);115 assert.notCalled(onFrameAdded);116 assert.calledOnce(console.warn);117 });118 });119 function createFrame(src) {120 const frame = document.createElement('iframe');121 frame.src = src;122 container.append(frame);123 return frame;124 }125 const sameOriginURL = new URL(126 '/base/annotator/test/empty.html',127 document.location.href128 ).href;129 // A cross-origin local URL that "loads" fast (whether the load succeeds or130 // fails doesn't matter for these tests). We assume that nothing else is131 // listening on the port.132 const crossOriginURL = 'http://localhost:12345/test.html';133 describe('onDocumentReady', () => {134 it('invokes callback with current document if it is already ready', async () => {135 const callback = sinon.stub();136 const frame = createFrame(sameOriginURL);137 await waitForEvent(frame, 'load');138 onDocumentReady(frame, callback);139 await waitForCall(callback);140 assert.calledOnce(callback);141 assert.calledWith(callback, null);142 const doc = callback.args[0][1];143 assert.equal(doc.location.href, sameOriginURL);144 });145 it('invokes callback when current document becomes ready', async () => {146 let resolveDocReady;147 const docReady = new Promise(resolve => (resolveDocReady = resolve));148 const callback = sinon149 .stub()150 .callsFake((err, doc) => resolveDocReady(doc));151 // We use a randomized URL so that the browser won't have a cached copy152 // that loads instantly. This will force execution through the code path153 // that waits for 'DOMContentLoaded' before triggering the callback.154 const docURL = `${sameOriginURL}?random=${Math.random()}`;155 const frame = createFrame(docURL);156 onDocumentReady(frame, callback, { pollInterval: 0 });157 await docReady;158 assert.calledOnce(callback);159 assert.calledWith(callback, null);160 const doc = callback.args[0][1];161 assert.equal(doc.location.href, docURL);162 });163 it('invokes callback for subsequent navigations to same-origin documents', async () => {164 const callback = sinon.stub();165 const frame = createFrame(sameOriginURL);166 await waitForEvent(frame, 'load');167 onDocumentReady(frame, callback);168 await waitForCall(callback);169 frame.src = sameOriginURL + 'v2';170 await waitForEvent(frame, 'load');171 assert.calledTwice(callback);172 });173 it('invokes callback with error if document is cross-origin', async () => {174 const callback = sinon.stub();175 const frame = createFrame(crossOriginURL);176 await waitForEvent(frame, 'load');177 onDocumentReady(frame, callback);178 await waitForCall(callback);179 assert.calledOnce(callback);180 assert.calledWith(callback, sinon.match.instanceOf(Error));181 const error = callback.args[0][0];182 assert.equal(error.message, 'Frame is cross-origin');183 });184 it('stops polling when subscription is canceled', async () => {185 const callback = sinon.stub();186 const frame = createFrame(sameOriginURL);187 await waitForEvent(frame, 'load');188 const unsubscribe = onDocumentReady(frame, callback);189 await waitForCall(callback);190 callback.resetHistory();191 unsubscribe();192 frame.src = sameOriginURL + '?v2';193 await waitForEvent(frame, 'load');194 assert.notCalled(callback);195 });196 it('does not start polling if "unload" event is received after subscription is canceled', async () => {197 const clock = sinon.useFakeTimers();198 try {199 const callback = sinon.stub();200 const frame = createFrame(sameOriginURL);201 await waitForEvent(frame, 'load');202 const unsubscribe = onDocumentReady(frame, callback);203 clock.tick();204 assert.calledOnce(callback);205 callback.resetHistory();206 const contentWindow = frame.contentWindow;207 unsubscribe();208 contentWindow.dispatchEvent(new Event('unload'));209 frame.src = sameOriginURL + '?v2';210 await waitForEvent(frame, 'load');211 clock.tick(50); // Wait for any active polling to trigger212 assert.notCalled(callback);213 } finally {214 clock.restore();215 }216 });217 it('does not invoke callback if subscription is immediately canceled', async () => {218 const callback = sinon.stub();219 const frame = createFrame(sameOriginURL);220 await waitForEvent(frame, 'load');221 const unsubscribe = onDocumentReady(frame, callback);222 unsubscribe();223 frame.src = sameOriginURL + '?v2';224 await waitForEvent(frame, 'load');225 assert.notCalled(callback);226 });227 });228 describe('onNextDocumentReady', () => {229 it('it resolves when a document first becomes ready in the frame', async () => {230 const frame = createFrame(sameOriginURL);231 const doc = await onNextDocumentReady(frame);232 assert.equal(doc.location.href, sameOriginURL);233 });234 it('it rejects if frame document is cross-origin', async () => {235 const frame = createFrame(crossOriginURL);236 let error;237 try {238 await onNextDocumentReady(frame);239 } catch (e) {240 error = e;241 }242 assert.instanceOf(error, Error);243 assert.equal(error.message, 'Frame is cross-origin');244 });245 });...

Full Screen

Full Screen

importScripts_3rdParty_worker.js

Source:importScripts_3rdParty_worker.js Github

copy

Full Screen

1const workerURL = 'http://mochi.test:8888/tests/dom/workers/test/importScripts_3rdParty_worker.js';2onmessage = function(a) {3 if (a.data.nested) {4 var worker = new Worker(workerURL);5 worker.onmessage = function(event) {6 postMessage(event.data);7 }8 worker.onerror = function(event) {9 event.preventDefault();10 postMessage({ error: event instanceof ErrorEvent &&11 event.filename == workerURL });12 }13 a.data.nested = false;14 worker.postMessage(a.data);15 return;16 }17 // This first URL will use the same origin of this script.18 var sameOriginURL = new URL(a.data.url);19 var fileName1 = 42;20 // This is cross-origin URL.21 var crossOriginURL = new URL(a.data.url);22 crossOriginURL.host = 'example.com';23 crossOriginURL.port = 80;24 var fileName2 = 42;25 if (a.data.test == 'none') {26 importScripts(crossOriginURL.href);27 return;28 }29 try {30 importScripts(sameOriginURL.href);31 } catch(e) {32 if (!(e instanceof SyntaxError)) {33 postMessage({ result: false });34 return;35 }36 fileName1 = e.fileName;37 }38 if (fileName1 != sameOriginURL.href || !fileName1) {39 postMessage({ result: false });40 return;41 }42 if (a.data.test == 'try') {43 var exception;44 try {45 importScripts(crossOriginURL.href);46 } catch(e) {47 fileName2 = e.filename;48 exception = e;49 }50 postMessage({ result: fileName2 == workerURL &&51 exception.name == "NetworkError" &&52 exception.code == DOMException.NETWORK_ERR });53 return;54 }55 if (a.data.test == 'eventListener') {56 addEventListener("error", function(event) {57 event.preventDefault();58 postMessage({result: event instanceof ErrorEvent &&59 event.filename == workerURL });60 });61 }62 if (a.data.test == 'onerror') {63 onerror = function(...args) {64 postMessage({result: args[1] == workerURL });65 }66 }67 importScripts(crossOriginURL.href);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7var wpt = require('webpagetest');8var wpt = new WebPageTest('www.webpagetest.org');9wpt.getLocations(function(err, data) {10 if (err) return console.error(err);11 console.log(data);12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org');15 if (err) return console.error(err);16 console.log(data);17});18var wpt = require('webpagetest');19var wpt = new WebPageTest('www.webpagetest.org');20 if (err) return console.error(err);21 console.log(data);22});23var wpt = require('webpagetest');24var wpt = new WebPageTest('www.webpagetest.org');25 if (err) return console.error(err);26 console.log(data);27});28var wpt = require('webpagetest');29var wpt = new WebPageTest('www.webpagetest.org');30 if (err) return console.error(err);31 console.log(data);32});33var wpt = require('webpagetest');34var wpt = new WebPageTest('www.webpagetest.org');35 if (err) return console.error(err);36 console.log(data);37});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wpt = require('wpt');11var wpt = new WebPageTest('www.webpagetest.org');12wpt.getLocations(function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var wpt = require('wpt');20var wpt = new WebPageTest('www.webpagetest.org');21wpt.getLocations(function(err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var wpt = require('wpt');29var wpt = new WebPageTest('www.webpagetest.org');30wpt.getLocations(function(err, data) {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37var wpt = require('wpt');38var wpt = new WebPageTest('www.webpagetest.org');39wpt.getLocations(function(err, data) {40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});46var wpt = require('wpt');47var wpt = new WebPageTest('www.webpagetest.org');48wpt.getLocations(function(err, data) {49 if (err) {50 console.log(err);51 } else {52 console.log(data);53 }54});55var wpt = require('wpt');56var wpt = new WebPageTest('www.webpagetest.org');57wpt.getLocations(function(err, data) {58 if (err) {59 console.log(err);60 } else {61 console.log(data);62 }63});64var wpt = require('wpt');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef12345678');3wpt.sameOriginURL(url, function(err, data) {4 console.log(data);5});6var wpt = require('webpagetest');7var wpt = WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef12345678');8wpt.sameOriginURL(url, function(err, data) {9 if (err) {10 console.log('Error', err);11 } else {12 console.log(data);13 }14});15var wpt = require('webpagetest');16var wpt = WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef12345678');17wpt.sameOriginURL(url, function(err, data) {18 if (err) {19 console.log('Error', err);20 } else {21 console.log(data);22 }23});24var wpt = require('webpagetest');25var wpt = WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef12345678');26wpt.sameOriginURL(url, function(err, data) {27 if (err) {28 console.log('Error', err);29 } else {30 console.log(data);31 }32});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2console.log(url);3var sameOriginURL = function(url){4 return url;5}6exports.sameOriginURL = sameOriginURL;7exports.sameOriginURL = sameOriginURL;8var sameOriginURL = function(url){9 return url;10}11exports.sameOriginURL = sameOriginURL;12console.log(url);

Full Screen

Using AI Code Generation

copy

Full Screen

1var xhr = new XMLHttpRequest();2xhr.open('GET', url, true);3xhr.onreadystatechange = function() {4 if (xhr.readyState == 4) {5 if (xhr.status == 200) {6 var response = xhr.responseText;7 if (response.indexOf('WebPagetest') != -1) {8 wpt.log('Success: sameOriginURL');9 } else {10 wpt.log('Error: sameOriginURL');11 }12 } else {13 wpt.log('Error: sameOriginURL');14 }15 }16};17xhr.send();18var xhr = new XMLHttpRequest();19xhr.open('GET', url, true);20xhr.onreadystatechange = function() {21 if (xhr.readyState == 4) {22 if (xhr.status == 200) {23 var response = xhr.responseText;24 if (response.indexOf('WebPagetest') != -1) {25 wpt.log('Success: sameOriginURL');26 } else {27 wpt.log('Error: sameOriginURL');28 }29 } else {30 wpt.log('Error: sameOriginURL');31 }32 }33};34xhr.send();35var xhr = new XMLHttpRequest();36xhr.open('GET', url, true);37xhr.onreadystatechange = function() {38 if (xhr.readyState == 4) {39 if (xhr.status == 200) {40 var response = xhr.responseText;41 if (response.indexOf('WebPagetest

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptutils = require('wptutils.js');2function onPageLoad() {3 var serverOrigin = wptutils.getServerOrigin();4 var pageOrigin = wptutils.getPageOrigin();5 var pageURL = wptutils.getPageURL();6 var serverURL = wptutils.getServerURL();7 var serverName = wptutils.getServerName();8 var serverPort = wptutils.getServerPort();9 console.log('Server Origin: ' + serverOrigin);10 console.log('Page Origin: ' + pageOrigin);11 console.log('Page URL: ' + pageURL);12 console.log('Server URL: ' + serverURL);13 console.log('Server Name: ' + serverName);14 console.log('Server Port: ' + serverPort);15}16wptutils.onPageLoad(onPageLoad);

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