How to use blocked method in wpt

Best JavaScript code snippet using wpt

42.integrity.js

Source:42.integrity.js Github

copy

Full Screen

...42 normally(allowed(() => this.db.prepare('SELECT 555')));43 normally(allowed(() => this.db.prepare('DELETE FROM entries')));44 });45 specify('while busy (blocked)', function () {46 whileBusy(this, blocked(() => this.db.prepare('SELECT 555')));47 whileBusy(this, blocked(() => this.db.prepare('DELETE FROM entries')));48 normally(allowed(() => this.db.prepare('SELECT 555')));49 normally(allowed(() => this.db.prepare('DELETE FROM entries')));50 });51 specify('while closed (blocked)', function () {52 whileClosed(this, blocked(() => this.db.prepare('SELECT 555')));53 whileClosed(this, blocked(() => this.db.prepare('DELETE FROM entries')));54 });55 });56 describe('Database#exec()', function () {57 specify('while iterating (blocked)', function () {58 whileIterating(this, blocked(() => this.db.exec('SELECT 555')));59 whileIterating(this, blocked(() => this.db.exec('DELETE FROM entries')));60 normally(allowed(() => this.db.exec('SELECT 555')));61 normally(allowed(() => this.db.exec('DELETE FROM entries')));62 });63 specify('while busy (blocked)', function () {64 whileBusy(this, blocked(() => this.db.exec('SELECT 555')));65 whileBusy(this, blocked(() => this.db.exec('DELETE FROM entries')));66 normally(allowed(() => this.db.exec('SELECT 555')));67 normally(allowed(() => this.db.exec('DELETE FROM entries')));68 });69 specify('while closed (blocked)', function () {70 whileClosed(this, blocked(() => this.db.exec('SELECT 555')));71 whileClosed(this, blocked(() => this.db.exec('DELETE FROM entries')));72 });73 });74 describe('Database#pragma()', function () {75 specify('while iterating (blocked)', function () {76 whileIterating(this, blocked(() => this.db.pragma('cache_size')));77 normally(allowed(() => this.db.pragma('cache_size')));78 });79 specify('while busy (blocked)', function () {80 whileBusy(this, blocked(() => this.db.pragma('cache_size')));81 normally(allowed(() => this.db.pragma('cache_size')));82 });83 specify('while closed (blocked)', function () {84 whileClosed(this, blocked(() => this.db.pragma('cache_size')));85 });86 });87 describe('Database#pragma(\'wal_checkpoint(RESTART)\')', function () {88 specify('while iterating (blocked)', function () {89 whileIterating(this, blocked(() => this.db.pragma('wal_checkpoint(RESTART)')));90 normally(allowed(() => this.db.pragma('wal_checkpoint(RESTART)')));91 });92 specify('while busy (blocked)', function () {93 whileBusy(this, blocked(() => this.db.pragma('wal_checkpoint(RESTART)')));94 normally(allowed(() => this.db.pragma('wal_checkpoint(RESTART)')));95 });96 specify('while closed (blocked)', function () {97 whileClosed(this, blocked(() => this.db.pragma('wal_checkpoint(RESTART)')));98 });99 });100 describe('Database#backup()', function () {101 specify('while iterating (allowed)', async function () {102 const promises = [];103 whileIterating(this, allowed(() => promises.push(this.db.backup(util.next()))));104 expect(promises.length).to.equal(5);105 return Promise.all(promises);106 });107 specify('while busy (allowed)', async function () {108 const promises = [];109 whileBusy(this, allowed(() => promises.push(this.db.backup(util.next()))));110 expect(promises.length).to.equal(5);111 return Promise.all(promises);112 });113 specify('while closed (blocked)', async function () {114 const promises = [];115 whileClosed(this, allowed(() => promises.push(this.db.backup(util.next()))));116 expect(promises.length).to.equal(1);117 return Promise.all(promises.map(p =>118 p.then(() => { throw new Error('Promise should have been rejected'); }, () => {})119 ));120 });121 });122 describe('Database#function()', function () {123 specify('while iterating (blocked)', function () {124 let i = 0;125 whileIterating(this, blocked(() => this.db.function(`fn_${++i}`, () => {})));126 expect(i).to.equal(5);127 normally(allowed(() => this.db.function(`fn_${++i}`, () => {})));128 });129 specify('while busy (blocked)', function () {130 let i = 0;131 whileBusy(this, blocked(() => this.db.function(`fn_${++i}`, () => {})));132 expect(i).to.equal(5);133 normally(allowed(() => this.db.function(`fn_${++i}`, () => {})));134 });135 specify('while closed (blocked)', function () {136 let i = 0;137 whileClosed(this, blocked(() => this.db.function(`fn_${++i}`, () => {})));138 expect(i).to.equal(1);139 });140 });141 describe('Database#aggregate()', function () {142 specify('while iterating (blocked)', function () {143 let i = 0;144 whileIterating(this, blocked(() => this.db.aggregate(`agg_${++i}`, { step: () => {} })));145 expect(i).to.equal(5);146 normally(allowed(() => this.db.aggregate(`agg_${++i}`, { step: () => {} })));147 });148 specify('while busy (blocked)', function () {149 let i = 0;150 whileBusy(this, blocked(() => this.db.aggregate(`agg_${++i}`, { step: () => {} })));151 expect(i).to.equal(5);152 normally(allowed(() => this.db.aggregate(`agg_${++i}`, { step: () => {} })));153 });154 specify('while closed (blocked)', function () {155 let i = 0;156 whileClosed(this, blocked(() => this.db.aggregate(`agg_${++i}`, { step: () => {} })));157 expect(i).to.equal(1);158 });159 });160 describe('Database#table()', function () {161 specify('while iterating (blocked)', function () {162 let i = 0;163 whileIterating(this, blocked(() => this.db.table(`tbl_${++i}`, { columns: ['x'], *rows() {} })));164 expect(i).to.equal(5);165 normally(allowed(() => this.db.table(`tbl_${++i}`, { columns: ['x'], *rows() {} })));166 });167 specify('while busy (blocked)', function () {168 let i = 0;169 whileBusy(this, blocked(() => this.db.table(`tbl_${++i}`, { columns: ['x'], *rows() {} })));170 expect(i).to.equal(5);171 normally(allowed(() => this.db.table(`tbl_${++i}`, { columns: ['x'], *rows() {} })));172 });173 specify('while closed (blocked)', function () {174 let i = 0;175 whileClosed(this, blocked(() => this.db.table(`tbl_${++i}`, { columns: ['x'], *rows() {} })));176 expect(i).to.equal(1);177 });178 });179 describe('Database#loadExtension()', function () {180 let filepath;181 before(function () {182 const releaseFilepath = path.join(__dirname, '..', 'build', 'Release', 'test_extension.node');183 const debugFilepath = path.join(__dirname, '..', 'build', 'Debug', 'test_extension.node');184 try {185 fs.accessSync(releaseFilepath);186 filepath = releaseFilepath;187 } catch (_) {188 fs.accessSync(debugFilepath);189 filepath = debugFilepath;190 }191 });192 specify('while iterating (blocked)', function () {193 whileIterating(this, blocked(() => this.db.loadExtension(filepath)));194 normally(allowed(() => this.db.loadExtension(filepath)));195 });196 specify('while busy (blocked)', function () {197 whileBusy(this, blocked(() => this.db.loadExtension(filepath)));198 normally(allowed(() => this.db.loadExtension(filepath)));199 });200 specify('while closed (blocked)', function () {201 whileClosed(this, blocked(() => this.db.loadExtension(filepath)));202 });203 });204 describe('Database#close()', function () {205 specify('while iterating (blocked)', function () {206 whileIterating(this, blocked(() => this.db.close()));207 normally(allowed(() => this.db.close()));208 });209 specify('while busy (blocked)', function () {210 whileBusy(this, blocked(() => this.db.close()));211 normally(allowed(() => this.db.close()));212 });213 specify('while closed (allowed)', function () {214 whileClosed(this, allowed(() => this.db.close()));215 });216 });217 describe('Database#defaultSafeIntegers()', function () {218 specify('while iterating (allowed)', function () {219 let bool = true;220 whileIterating(this, allowed(() => this.db.defaultSafeIntegers(bool = !bool)));221 });222 specify('while busy (allowed)', function () {223 let bool = true;224 whileBusy(this, allowed(() => this.db.defaultSafeIntegers(bool = !bool)));225 });226 specify('while closed (allowed)', function () {227 let bool = true;228 whileClosed(this, allowed(() => this.db.defaultSafeIntegers(bool = !bool)));229 });230 });231 describe('Database#open', function () {232 specify('while iterating (allowed)', function () {233 whileIterating(this, allowed(() => expect(this.db.open).to.be.true));234 });235 specify('while busy (allowed)', function () {236 whileBusy(this, allowed(() => expect(this.db.open).to.be.true));237 });238 specify('while closed (allowed)', function () {239 whileClosed(this, allowed(() => expect(this.db.open).to.be.false));240 });241 });242 describe('Database#inTransaction', function () {243 specify('while iterating (allowed)', function () {244 this.db.exec('BEGIN');245 whileIterating(this, allowed(() => expect(this.db.inTransaction).to.be.true));246 });247 specify('while busy (allowed)', function () {248 this.db.exec('BEGIN');249 whileBusy(this, allowed(() => expect(this.db.inTransaction).to.be.true));250 });251 specify('while closed (allowed)', function () {252 this.db.exec('BEGIN');253 whileClosed(this, allowed(() => expect(this.db.inTransaction).to.be.false));254 });255 });256 describe('Statement#run()', function () {257 specify('while iterating (blocked)', function () {258 whileIterating(this, blocked(() => this.writer.run()));259 normally(allowed(() => this.writer.run()));260 });261 specify('while busy (blocked)', function () {262 whileBusy(this, blocked(() => this.writer.run()));263 normally(allowed(() => this.writer.run()));264 });265 specify('while closed (blocked)', function () {266 whileClosed(this, blocked(() => this.writer.run()));267 });268 });269 describe('Statement#get()', function () {270 specify('while iterating (allowed)', function () {271 whileIterating(this, allowed(() => this.reader.get()));272 normally(allowed(() => this.reader.get()));273 });274 specify('while self-iterating (blocked)', function () {275 whileIterating(this, blocked(() => this.iterator.get()));276 normally(allowed(() => this.iterator.get()));277 });278 specify('while busy (blocked)', function () {279 whileBusy(this, blocked(() => this.reader.get()));280 normally(allowed(() => this.reader.get()));281 });282 specify('while closed (blocked)', function () {283 whileClosed(this, blocked(() => this.reader.get()));284 });285 });286 describe('Statement#all()', function () {287 specify('while iterating (allowed)', function () {288 whileIterating(this, allowed(() => this.reader.all()));289 normally(allowed(() => this.reader.all()));290 });291 specify('while self-iterating (blocked)', function () {292 whileIterating(this, blocked(() => this.iterator.all()));293 normally(allowed(() => this.iterator.all()));294 });295 specify('while busy (blocked)', function () {296 whileBusy(this, blocked(() => this.reader.all()));297 normally(allowed(() => this.reader.all()));298 });299 specify('while closed (blocked)', function () {300 whileClosed(this, blocked(() => this.reader.all()));301 });302 });303 describe('Statement#iterate()', function () {304 specify('while iterating (allowed)', function () {305 whileIterating(this, allowed(() => Array.from(this.reader.iterate())));306 normally(allowed(() => Array.from(this.reader.iterate())));307 });308 specify('while self-iterating (blocked)', function () {309 whileIterating(this, blocked(() => Array.from(this.iterator.iterate())));310 normally(allowed(() => Array.from(this.iterator.iterate())));311 });312 specify('while busy (blocked)', function () {313 whileBusy(this, blocked(() => Array.from(this.reader.iterate())));314 normally(allowed(() => Array.from(this.reader.iterate())));315 });316 specify('while closed (blocked)', function () {317 whileClosed(this, blocked(() => Array.from(this.reader.iterate())));318 });319 });320 describe('Statement#bind()', function () {321 const bind = (stmt) => {322 if (!stmt.__bound) {323 stmt.bind();324 stmt.__bound = true;325 }326 };327 specify('while iterating (allowed)', function () {328 whileIterating(this, allowed(() => bind(this.reader)));329 });330 specify('while self-iterating (blocked)', function () {331 whileIterating(this, blocked(() => bind(this.iterator)));332 normally(allowed(() => bind(this.iterator)));333 });334 specify('while busy (blocked)', function () {335 whileBusy(this, blocked(() => bind(this.reader)));336 normally(allowed(() => bind(this.reader)));337 });338 specify('while closed (blocked)', function () {339 whileClosed(this, blocked(() => bind(this.reader)));340 });341 });342 describe('Statement#pluck()', function () {343 specify('while iterating (allowed)', function () {344 whileIterating(this, allowed(() => this.reader.pluck()));345 normally(allowed(() => this.reader.pluck()));346 });347 specify('while self-iterating (blocked)', function () {348 whileIterating(this, blocked(() => this.iterator.pluck()));349 normally(allowed(() => this.iterator.pluck()));350 });351 specify('while busy (blocked)', function () {352 whileBusy(this, blocked(() => this.reader.pluck()));353 normally(allowed(() => this.reader.pluck()));354 });355 specify('while closed (allowed)', function () {356 whileClosed(this, allowed(() => this.reader.pluck()));357 });358 });359 describe('Statement#expand()', function () {360 specify('while iterating (allowed)', function () {361 whileIterating(this, allowed(() => this.reader.expand()));362 normally(allowed(() => this.reader.expand()));363 });364 specify('while self-iterating (blocked)', function () {365 whileIterating(this, blocked(() => this.iterator.expand()));366 normally(allowed(() => this.iterator.expand()));367 });368 specify('while busy (blocked)', function () {369 whileBusy(this, blocked(() => this.reader.expand()));370 normally(allowed(() => this.reader.expand()));371 });372 specify('while closed (allowed)', function () {373 whileClosed(this, allowed(() => this.reader.expand()));374 });375 });376 describe('Statement#raw()', function () {377 specify('while iterating (allowed)', function () {378 whileIterating(this, allowed(() => this.reader.raw()));379 normally(allowed(() => this.reader.raw()));380 });381 specify('while self-iterating (blocked)', function () {382 whileIterating(this, blocked(() => this.iterator.raw()));383 normally(allowed(() => this.iterator.raw()));384 });385 specify('while busy (blocked)', function () {386 whileBusy(this, blocked(() => this.reader.raw()));387 normally(allowed(() => this.reader.raw()));388 });389 specify('while closed (allowed)', function () {390 whileClosed(this, allowed(() => this.reader.raw()));391 });392 });393 describe('Statement#safeIntegers()', function () {394 specify('while iterating (allowed)', function () {395 whileIterating(this, allowed(() => this.reader.safeIntegers()));396 normally(allowed(() => this.reader.safeIntegers()));397 });398 specify('while self-iterating (blocked)', function () {399 whileIterating(this, blocked(() => this.iterator.safeIntegers()));400 normally(allowed(() => this.iterator.safeIntegers()));401 });402 specify('while busy (blocked)', function () {403 whileBusy(this, blocked(() => this.reader.safeIntegers()));404 normally(allowed(() => this.reader.safeIntegers()));405 });406 specify('while closed (allowed)', function () {407 whileClosed(this, allowed(() => this.reader.safeIntegers()));408 });409 });410 describe('Statement#columns()', function () {411 specify('while iterating (allowed)', function () {412 whileIterating(this, allowed(() => this.reader.columns()));413 normally(allowed(() => this.reader.columns()));414 });415 specify('while self-iterating (allowed)', function () {416 whileIterating(this, allowed(() => this.iterator.columns()));417 normally(allowed(() => this.iterator.columns()));418 });419 specify('while busy (blocked)', function () {420 whileBusy(this, blocked(() => this.reader.columns()));421 normally(allowed(() => this.reader.columns()));422 });423 specify('while closed (blocked)', function () {424 whileClosed(this, blocked(() => this.reader.columns()));425 });426 });427 describe('StatementIterator#next()', function () {428 specify('while iterating (allowed)', function () {429 const iterator = this.reader.iterate();430 try {431 whileIterating(this, allowed(() => iterator.next()));432 normally(allowed(() => iterator.next()));433 } finally {434 iterator.return();435 }436 });437 specify('while self-iterating (allowed)', function () {438 const iterator = this.iterator.iterate();439 try {440 let count = 0;441 for (const _ of iterator) {442 count += 1;443 iterator.next();444 }445 expect(count).to.equal(3);446 } finally {447 iterator.return();448 }449 });450 specify('while busy (blocked)', function () {451 const iterator = this.reader.iterate();452 try {453 whileBusy(this, blocked(() => iterator.next()));454 normally(allowed(() => iterator.next()));455 } finally {456 iterator.return();457 }458 });459 specify('while closed (allowed)', function () {460 const iterator = this.reader.iterate();461 iterator.return();462 whileClosed(this, allowed(() => iterator.next()));463 });464 });465 describe('StatementIterator#return()', function () {466 specify('while iterating (allowed)', function () {467 const iterator = this.reader.iterate();468 try {469 whileIterating(this, allowed(() => iterator.return()));470 normally(allowed(() => iterator.return()));471 } finally {472 iterator.return();473 }474 });475 specify('while self-iterating (allowed)', function () {476 const iterator = this.iterator.iterate();477 try {478 let count = 0;479 for (const _ of iterator) {480 count += 1;481 iterator.return();482 }483 expect(count).to.equal(1);484 } finally {485 iterator.return();486 }487 });488 specify('while busy (blocked)', function () {489 const iterator = this.reader.iterate();490 try {491 whileBusy(this, blocked(() => iterator.return()));492 normally(allowed(() => iterator.return()));493 } finally {494 iterator.return();495 }496 });497 specify('while closed (allowed)', function () {498 const iterator = this.reader.iterate();499 iterator.return();500 whileClosed(this, allowed(() => iterator.return()));501 });502 });...

Full Screen

Full Screen

browser_webconsole_warning_group_multiples.js

Source:browser_webconsole_warning_group_multiples.js Github

copy

Full Screen

1/* Any copyright is dedicated to the Public Domain.2 * http://creativecommons.org/publicdomain/zero/1.0/ */3// Test that warning messages can be grouped, per navigation and category, and that4// interacting with these groups works as expected.5"use strict";6requestLongerTimeout(2);7const TEST_FILE =8 "browser/devtools/client/webconsole/test/browser/test-warning-groups.html";9const TEST_URI = "http://example.org/" + TEST_FILE;10const TRACKER_URL = "http://tracking.example.com/";11const FILE_PATH =12 "browser/devtools/client/webconsole/test/browser/test-image.png";13const CONTENT_BLOCKED_URL = TRACKER_URL + FILE_PATH;14const STORAGE_BLOCKED_URL = "http://example.com/" + FILE_PATH;15const COOKIE_BEHAVIOR_PREF = "network.cookie.cookieBehavior";16const COOKIE_BEHAVIORS_REJECT_FOREIGN = 1;17const CONTENT_BLOCKED_GROUP_LABEL =18 "The resource at “<URL>” was blocked because content blocking is enabled.";19const STORAGE_BLOCKED_GROUP_LABEL =20 "Request to access cookie or storage on “<URL>” " +21 "was blocked because we are blocking all third-party storage access requests and " +22 "content blocking is enabled.";23const { UrlClassifierTestUtils } = ChromeUtils.import(24 "resource://testing-common/UrlClassifierTestUtils.jsm"25);26UrlClassifierTestUtils.addTestTrackers();27registerCleanupFunction(function() {28 UrlClassifierTestUtils.cleanupTestTrackers();29});30pushPref("privacy.trackingprotection.enabled", true);31pushPref("devtools.webconsole.groupWarningMessages", true);32add_task(async function testContentBlockingMessage() {33 await pushPref(COOKIE_BEHAVIOR_PREF, COOKIE_BEHAVIORS_REJECT_FOREIGN);34 await pushPref("devtools.webconsole.persistlog", true);35 const hud = await openNewTabAndConsole(TEST_URI);36 info(37 "Log a tracking protection message to check a single message isn't grouped"38 );39 let onContentBlockedMessage = waitForMessage(40 hud,41 CONTENT_BLOCKED_URL,42 ".warn"43 );44 emitContentBlockingMessage(hud);45 let { node } = await onContentBlockedMessage;46 is(47 node.querySelector(".warning-indent"),48 null,49 "The message has the expected style"50 );51 is(52 node.querySelector(".indent").getAttribute("data-indent"),53 "0",54 "The message has the expected indent"55 );56 info("Log a simple message");57 await logString(hud, "simple message 1");58 info(59 "Log a second tracking protection message to check that it causes the grouping"60 );61 let onContentBlockedWarningGroupMessage = waitForMessage(62 hud,63 CONTENT_BLOCKED_GROUP_LABEL,64 ".warn"65 );66 emitContentBlockingMessage(hud);67 const {68 node: contentBlockedWarningGroupNode,69 } = await onContentBlockedWarningGroupMessage;70 is(71 contentBlockedWarningGroupNode.querySelector(".warning-group-badge")72 .textContent,73 "2",74 "The badge has the expected text"75 );76 checkConsoleOutputForWarningGroup(hud, [77 `▶︎⚠ ${CONTENT_BLOCKED_GROUP_LABEL}`,78 `simple message 1`,79 ]);80 let onStorageBlockedWarningGroupMessage = waitForMessage(81 hud,82 STORAGE_BLOCKED_URL,83 ".warn"84 );85 emitStorageAccessBlockedMessage(hud);86 ({ node } = await onStorageBlockedWarningGroupMessage);87 is(88 node.querySelector(".warning-indent"),89 null,90 "The message has the expected style"91 );92 is(93 node.querySelector(".indent").getAttribute("data-indent"),94 "0",95 "The message has the expected indent"96 );97 info("Log a second simple message");98 await logString(hud, "simple message 2");99 checkConsoleOutputForWarningGroup(hud, [100 `▶︎⚠ ${CONTENT_BLOCKED_GROUP_LABEL}`,101 `simple message 1`,102 `${STORAGE_BLOCKED_URL}`,103 `simple message 2`,104 ]);105 info(106 "Log a second storage blocked message to check that it creates another group"107 );108 onStorageBlockedWarningGroupMessage = waitForMessage(109 hud,110 STORAGE_BLOCKED_GROUP_LABEL,111 ".warn"112 );113 emitStorageAccessBlockedMessage(hud);114 const {115 node: storageBlockedWarningGroupNode,116 } = await onStorageBlockedWarningGroupMessage;117 is(118 storageBlockedWarningGroupNode.querySelector(".warning-group-badge")119 .textContent,120 "2",121 "The badge has the expected text"122 );123 info("Expand the second warning group");124 storageBlockedWarningGroupNode.querySelector(".arrow").click();125 await waitFor(() => findMessage(hud, STORAGE_BLOCKED_URL));126 checkConsoleOutputForWarningGroup(hud, [127 `▶︎⚠ ${CONTENT_BLOCKED_GROUP_LABEL}`,128 `simple message 1`,129 `▼︎⚠ ${STORAGE_BLOCKED_GROUP_LABEL}`,130 `| ${STORAGE_BLOCKED_URL}?3`,131 `| ${STORAGE_BLOCKED_URL}?4`,132 `simple message 2`,133 ]);134 info(135 "Add another storage blocked message to check it does go into the opened group"136 );137 let onStorageBlockedMessage = waitForMessage(138 hud,139 STORAGE_BLOCKED_URL,140 ".warn"141 );142 emitStorageAccessBlockedMessage(hud);143 await onStorageBlockedMessage;144 checkConsoleOutputForWarningGroup(hud, [145 `▶︎⚠ ${CONTENT_BLOCKED_GROUP_LABEL}`,146 `simple message 1`,147 `▼︎⚠ ${STORAGE_BLOCKED_GROUP_LABEL}`,148 `| ${STORAGE_BLOCKED_URL}?3`,149 `| ${STORAGE_BLOCKED_URL}?4`,150 `| ${STORAGE_BLOCKED_URL}?5`,151 `simple message 2`,152 ]);153 info(154 "Add a content blocked message to check the first group badge is updated"155 );156 emitContentBlockingMessage();157 await waitForBadgeNumber(contentBlockedWarningGroupNode, 3);158 info("Expand the first warning group");159 contentBlockedWarningGroupNode.querySelector(".arrow").click();160 await waitFor(() => findMessage(hud, CONTENT_BLOCKED_URL));161 checkConsoleOutputForWarningGroup(hud, [162 `▼︎⚠ ${CONTENT_BLOCKED_GROUP_LABEL}`,163 `| ${CONTENT_BLOCKED_URL}?1`,164 `| ${CONTENT_BLOCKED_URL}?2`,165 `| ${CONTENT_BLOCKED_URL}?6`,166 `simple message 1`,167 `▼︎⚠ ${STORAGE_BLOCKED_GROUP_LABEL}`,168 `| ${STORAGE_BLOCKED_URL}?3`,169 `| ${STORAGE_BLOCKED_URL}?4`,170 `| ${STORAGE_BLOCKED_URL}?5`,171 `simple message 2`,172 ]);173 info("Reload the page and wait for it to be ready");174 await reloadPage();175 // Also wait for the navigation message to be displayed.176 await waitFor(() => findMessage(hud, "Navigated to"));177 info("Add a storage blocked message and a content blocked one");178 onStorageBlockedMessage = waitForMessage(hud, STORAGE_BLOCKED_URL, ".warn");179 emitStorageAccessBlockedMessage(hud);180 await onStorageBlockedMessage;181 onContentBlockedMessage = waitForMessage(hud, CONTENT_BLOCKED_URL, ".warn");182 emitContentBlockingMessage(hud);183 await onContentBlockedMessage;184 checkConsoleOutputForWarningGroup(hud, [185 `▼︎⚠ ${CONTENT_BLOCKED_GROUP_LABEL}`,186 `| ${CONTENT_BLOCKED_URL}?1`,187 `| ${CONTENT_BLOCKED_URL}?2`,188 `| ${CONTENT_BLOCKED_URL}?6`,189 `simple message 1`,190 `▼︎⚠ ${STORAGE_BLOCKED_GROUP_LABEL}`,191 `| ${STORAGE_BLOCKED_URL}?3`,192 `| ${STORAGE_BLOCKED_URL}?4`,193 `| ${STORAGE_BLOCKED_URL}?5`,194 `simple message 2`,195 `Navigated to`,196 `${STORAGE_BLOCKED_URL}?7`,197 `${CONTENT_BLOCKED_URL}?8`,198 ]);199 info(200 "Add a storage blocked message and a content blocked one to create warningGroups"201 );202 onStorageBlockedWarningGroupMessage = waitForMessage(203 hud,204 STORAGE_BLOCKED_GROUP_LABEL,205 ".warn"206 );207 emitStorageAccessBlockedMessage();208 await onStorageBlockedWarningGroupMessage;209 onContentBlockedWarningGroupMessage = waitForMessage(210 hud,211 CONTENT_BLOCKED_GROUP_LABEL,212 ".warn"213 );214 emitContentBlockingMessage();215 await onContentBlockedWarningGroupMessage;216 checkConsoleOutputForWarningGroup(hud, [217 `▼︎⚠ ${CONTENT_BLOCKED_GROUP_LABEL}`,218 `| ${CONTENT_BLOCKED_URL}?1`,219 `| ${CONTENT_BLOCKED_URL}?2`,220 `| ${CONTENT_BLOCKED_URL}?6`,221 `simple message 1`,222 `▼︎⚠ ${STORAGE_BLOCKED_GROUP_LABEL}`,223 `| ${STORAGE_BLOCKED_URL}?3`,224 `| ${STORAGE_BLOCKED_URL}?4`,225 `| ${STORAGE_BLOCKED_URL}?5`,226 `simple message 2`,227 `Navigated to`,228 `▶︎⚠ ${STORAGE_BLOCKED_GROUP_LABEL}`,229 `▶︎⚠ ${CONTENT_BLOCKED_GROUP_LABEL}`,230 ]);231});232let cpt = 0;233const now = Date.now();234/**235 * Emit a Content Blocking message. This is done by loading an image from an origin236 * tagged as tracker. The image is loaded with a incremented counter query parameter237 * each time so we can get the warning message.238 */239function emitContentBlockingMessage() {240 const url = `${CONTENT_BLOCKED_URL}?${++cpt}-${now}`;241 SpecialPowers.spawn(gBrowser.selectedBrowser, [url], function(innerURL) {242 content.wrappedJSObject.loadImage(innerURL);243 });244}245/**246 * Emit a Storage blocked message. This is done by loading an image from a different247 * origin, with the cookier permission rejecting foreign origin cookie access.248 */249function emitStorageAccessBlockedMessage() {250 const url = `${STORAGE_BLOCKED_URL}?${++cpt}-${now}`;251 SpecialPowers.spawn(gBrowser.selectedBrowser, [url], function(innerURL) {252 content.wrappedJSObject.loadImage(innerURL);253 });254}255/**256 * Log a string from the content page.257 *258 * @param {WebConsole} hud259 * @param {String} str260 */261function logString(hud, str) {262 const onMessage = waitForMessage(hud, str);263 SpecialPowers.spawn(gBrowser.selectedBrowser, [str], function(arg) {264 content.console.log(arg);265 });266 return onMessage;267}268function waitForBadgeNumber(messageNode, expectedNumber) {269 return waitFor(270 () =>271 messageNode.querySelector(".warning-group-badge").textContent ==272 expectedNumber273 );...

Full Screen

Full Screen

request-blocking.js

Source:request-blocking.js Github

copy

Full Screen

1/* This Source Code Form is subject to the terms of the Mozilla Public2 * License, v. 2.0. If a copy of the MPL was not distributed with this3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */4"use strict";5const {6 ADD_BLOCKED_URL,7 DISABLE_MATCHING_URLS,8 TOGGLE_BLOCKED_URL,9 UPDATE_BLOCKED_URL,10 REMOVE_BLOCKED_URL,11 REMOVE_ALL_BLOCKED_URLS,12 ENABLE_ALL_BLOCKED_URLS,13 DISABLE_ALL_BLOCKED_URLS,14 TOGGLE_BLOCKING_ENABLED,15} = require("devtools/client/netmonitor/src/constants");16function RequestBlocking() {17 return {18 blockedUrls: [],19 blockingEnabled: true,20 };21}22function requestBlockingReducer(state = RequestBlocking(), action) {23 switch (action.type) {24 case ADD_BLOCKED_URL:25 return addBlockedUrl(state, action);26 case REMOVE_BLOCKED_URL:27 return removeBlockedUrl(state, action);28 case REMOVE_ALL_BLOCKED_URLS:29 return removeAllBlockedUrls(state, action);30 case UPDATE_BLOCKED_URL:31 return updateBlockedUrl(state, action);32 case TOGGLE_BLOCKED_URL:33 return toggleBlockedUrl(state, action);34 case TOGGLE_BLOCKING_ENABLED:35 return toggleBlockingEnabled(state, action);36 case ENABLE_ALL_BLOCKED_URLS:37 return enableAllBlockedUrls(state, action);38 case DISABLE_ALL_BLOCKED_URLS:39 return disableAllBlockedUrls(state, action);40 case DISABLE_MATCHING_URLS:41 return disableOrRemoveMatchingUrls(state, action);42 default:43 return state;44 }45}46function toggleBlockingEnabled(state, action) {47 return {48 ...state,49 blockingEnabled: action.enabled,50 };51}52function addBlockedUrl(state, action) {53 // The user can paste in a list of URLS so we need to cleanse the input54 // Pasting a list turns new lines into spaces55 const uniqueUrls = [...new Set(action.url.split(" "))].map(url => url.trim());56 const newUrls = uniqueUrls57 // Ensure the URL isn't already blocked58 .filter(url => url && !state.blockedUrls.some(item => item.url === url))59 // Add new URLs as enabled by default60 .map(url => ({ url, enabled: true }));61 // If the user is trying to block a URL that's currently in the list but disabled,62 // re-enable the old item63 const currentBlockedUrls = state.blockedUrls.map(item =>64 uniqueUrls.includes(item.url) ? { url: item.url, enabled: true } : item65 );66 const blockedUrls = [...currentBlockedUrls, ...newUrls];67 return {68 ...state,69 blockedUrls,70 };71}72function removeBlockedUrl(state, action) {73 return {74 ...state,75 blockedUrls: state.blockedUrls.filter(item => item.url != action.url),76 };77}78function removeAllBlockedUrls(state, action) {79 return {80 ...state,81 blockedUrls: [],82 };83}84function enableAllBlockedUrls(state, action) {85 const blockedUrls = state.blockedUrls.map(item => ({86 ...item,87 enabled: true,88 }));89 return {90 ...state,91 blockedUrls,92 };93}94function disableAllBlockedUrls(state, action) {95 const blockedUrls = state.blockedUrls.map(item => ({96 ...item,97 enabled: false,98 }));99 return {100 ...state,101 blockedUrls,102 };103}104function updateBlockedUrl(state, action) {105 const { oldUrl, newUrl } = action;106 let { blockedUrls } = state;107 if (!blockedUrls.find(item => item.url === newUrl)) {108 blockedUrls = blockedUrls.map(item => {109 if (item.url === oldUrl) {110 return { ...item, url: newUrl };111 }112 return item;113 });114 } else {115 blockedUrls = blockedUrls.filter(item => item.url != oldUrl);116 }117 return {118 ...state,119 blockedUrls,120 };121}122function toggleBlockedUrl(state, action) {123 const blockedUrls = state.blockedUrls.map(item => {124 if (item.url === action.url) {125 return { ...item, enabled: !item.enabled };126 }127 return item;128 });129 return {130 ...state,131 blockedUrls,132 };133}134function disableOrRemoveMatchingUrls(state, action) {135 const blockedUrls = state.blockedUrls136 .map(item => {137 // If the url matches exactly, remove the entry138 if (action.url === item.url) {139 return null;140 }141 // If just a partial match, disable the entry142 if (action.url.includes(item.url)) {143 return { ...item, enabled: false };144 }145 return item;146 })147 .filter(Boolean);148 return {149 ...state,150 blockedUrls,151 };152}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var page = require('webpage').create(),2 system = require('system'),3 t, address;4if (system.args.length === 1) {5 console.log('Usage: loadspeed.js <some URL>');6 phantom.exit(1);7} else {8 t = Date.now();9 address = system.args[1];10 page.open(address, function (status) {11 if (status !== 'success') {12 console.log('FAIL to load the address');13 } else {14 t = Date.now() - t;15 console.log('Loading time ' + t + ' msec');16 }17 phantom.exit();18 });19}20var page = require('webpage').create(),21 system = require('system'),22 t, address;23if (system.args.length === 1) {24 console.log('Usage: loadspeed.js <some URL>');25 phantom.exit(1);26} else {27 t = Date.now();28 address = system.args[1];29 page.open(address, function (status) {30 if (status !== 'success') {31 console.log('FAIL to load the address');32 } else {33 t = Date.now() - t;34 console.log('Loading time ' + t + ' msec');35 }36 });37}38var page = require('webpage').create(),39 system = require('system'),40 t, address;41if (system.args.length === 1) {42 console.log('Usage: loadspeed.js <some URL>');43 phantom.exit(1);44} else {45 t = Date.now();46 address = system.args[1];47 page.open(address, function (status) {48 if (status !== 'success') {49 console.log('FAIL to load the address');50 } else {51 t = Date.now() - t;52 console.log('Loading time ' + t + ' msec');53 }54 });55}56var page = require('webpage').create(),57 system = require('system'),58 t, address;59if (system.args.length === 1) {60 console.log('Usage: loadspeed.js <some URL>');61 phantom.exit(1);62} else {63 t = Date.now();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Builder, By, Key, until } = require('selenium-webdriver');2const { Options } = require('selenium-webdriver/chrome');3const chrome = require('selenium-webdriver/chrome');4const path = require('chromedriver').path;5const options = new Options();6options.setChromeBinaryPath(path);7options.addArguments("--headless");8options.addArguments("--disable-gpu");9options.addArguments("--disable-dev-shm-usage");10options.addArguments("--no-sandbox");11async function example() {12 let driver = await new Builder()13 .forBrowser('chrome')14 .setChromeOptions(options)15 .build();16 try {17 await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);18 await driver.wait(until.titleIs('webdriver - Google Search'), 1000);19 } finally {20 await driver.quit();21 }22}23example();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3 .then(function(data) {4 console.log(data);5 })6 .catch(function(err) {7 console.log(err);8 });

Full Screen

Using AI Code Generation

copy

Full Screen

1var WebPageTest = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = { location: 'Dulles:Chrome', firstViewOnly: true };4wpt.runTest(url, options, function(err, data) {5 if (err) return console.error(err);6 console.log('Test Results: %j', data);7});8var WebPageTest = require('webpagetest');9var wpt = new WebPageTest('www.webpagetest.org');10var options = { location: 'Dulles:Chrome', firstViewOnly: true };11wpt.runTest(url, options, function(err, data) {12 if (err) return console.error(err);13 console.log('Test Results: %j', data);14});15var WebPageTest = require('webpagetest');16var wpt = new WebPageTest('www.webpagetest.org');17var options = { location: 'Dulles:Chrome', firstViewOnly: true };18wpt.runTest(url, options, function(err, data) {19 if (err) return console.error(err);20 console.log('Test Results: %j', data);21});22var WebPageTest = require('webpagetest');23var wpt = new WebPageTest('www.webpagetest.org');24var options = { location: 'Dulles:Chrome', firstViewOnly: true };25wpt.runTest(url, options, function(err, data) {26 if (err) return console.error(err);27 console.log('Test Results: %j', data);28});29var WebPageTest = require('webpagetest');30var wpt = new WebPageTest('www.webpagetest.org');31var options = { location: 'Dulles:Chrome', firstViewOnly: true };32wpt.runTest(url, options, function(err, data) {33 if (err) return console.error(err);34 console.log('Test Results: %j', data

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('webpagetest');2const fs = require('fs');3const util = require('util');4const exec = util.promisify(require('child_process').exec);5const { promisify } = require('util');6const writeFile = promisify(fs.writeFile);7const readFile = promisify(fs.readFile);8const appendFile = promisify(fs.appendFile);9const { execSync } = require('child_process');10const { performance } = require('perf_hooks');11const { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } = require('constants');12const { exit } = require('process');13const { Console } = require('console');14const { type } = require('os');15const { resolve } = require('path');16const { rejects } = require('assert');17const { SSL_OP_TLS_ROLLBACK_BUG } = require('constants');18const { ESRCH } = require('constants');19const { EADDRNOTAVAIL } = require('constants');20const { EAI_AGAIN } = require('constants');21const { EAI_BADFLAGS } = require('constants');22const { EAI_FAIL } = require('constants');23const { EAI_FAMILY } = require('constants');24const { EAI_MEMORY } = require('constants');25const { EAI_NODATA } = require('constants');26const { EAI_NONAME } = require('constants');27const { EAI_SERVICE } = require('constants');28const { EAI_SOCKTYPE } = require('constants');29const { EAI_SYSTEM } = require('constants');30const { EAI_OVERFLOW } = require('constants');31const { EAI_BADHINTS } = require('constants');32const { EAI_PROTOCOL } = require('constants');33const { EAI_MAX } = require('constants');34const { EADDRINUSE } = require('constants');35const { EADDRNOTAVAIL } = require('constants');36const { EAFNOSUPPORT } = require('constants');37const { EAGAIN } = require('constants');38const { EAI_ADDRFAMILY } = require('constants');39const { EAI_AGAIN } = require('constants');40const { EAI_BADFLAGS } = require('constants');41const { EAI_FAIL } = require('constants');42const { EAI_FAMILY } = require('constants');43const { EAI_MEMORY } = require('constants');44const { EAI_NODATA } = require('constants');45const { EAI_NON

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var webpagetest = new wpt(options);5webpagetest.runTest(url, function(err, data) {6 if (err) return console.error(err);7 console.log('Test submitted to WebPageTest for %s', url);8 console.log('View your test at: %s', data.data.userUrl);9 console.log('View the raw results at: %s', data.data.jsonUrl);10 console.log('View the test status at: %s', data.data.statusTextUrl);11 console.log('You can also run the same test again at: %s', data.data.repeatViewUrl);12 console.log('You can also run a repeat view of the test at: %s', data.data.repeatViewUrl);13});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', 'A.3c7d3f1f9c9b0d3f0cbf5f3f3b2c3b2e');5var params = {6};7wpt.runTest(url, params).then(function(data) {8 console.log(data);9}).catch(function(err) {10 console.error(err);11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var webPageTest = new wpt(options);5webPageTest.runTest(url, {6}, function(err, data) {7 if (err) return console.error(err);8 console.log(data);9});

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