Best JavaScript code snippet using wpt
rename_async_failure_handling.tentative.https.any.js
Source:rename_async_failure_handling.tentative.https.any.js
1// META: title=NativeIO API: Failures of rename are properly handled.2// META: global=window,worker3// META: script=resources/support.js4// META: timeout=long5'use strict';6setup(async () => {7 assert_implements(storageFoundation.rename, 'storageFoundation.rename is not' +8 ' implemented.');9});10promise_test(async testCase => {11 await reserveAndCleanupCapacity(testCase);12 const file1 = await storageFoundation.open('test_file_1');13 const file2 = await storageFoundation.open('test_file_2');14 testCase.add_cleanup(async () => {15 await file1.close();16 await file2.close();17 });18 const {buffer: writeBuffer1} = await file1.write(new Uint8Array([64, 65, 66, 67]), 0);19 const {buffer: writeBuffer2} = await file2.write(new Uint8Array([96, 97, 98, 99]), 0);20 await file1.close();21 await file2.close();22 await promise_rejects_dom(23 testCase, 'NoModificationAllowedError',24 storageFoundation.rename('test_file_1', 'test_file_2'));25 const fileNamesAfterRename = await storageFoundation.getAll();26 assert_in_array('test_file_1', fileNamesAfterRename);27 assert_in_array('test_file_2', fileNamesAfterRename);28 // Make sure that a failed rename does not modify file contents.29 const file1_after = await storageFoundation.open('test_file_1');30 const file2_after = await storageFoundation.open('test_file_2');31 testCase.add_cleanup(async () => {32 await file1_after.close();33 await file2_after.close();34 await storageFoundation.delete('test_file_1');35 await storageFoundation.delete('test_file_2');36 });37 const {buffer: readBuffer1} = await file1_after.read(new Uint8Array(4), 0);38 const {buffer: readBuffer2} = await file2_after.read(new Uint8Array(4), 0);39 assert_array_equals(40 readBuffer1, writeBuffer1,41 'the bytes read should match the bytes written');42 assert_array_equals(43 readBuffer2, writeBuffer2,44 'the bytes read should match the bytes written');45}, 'storageFoundation.rename does not overwrite an existing file.');46promise_test(async testCase => {47 await reserveAndCleanupCapacity(testCase);48 const file = await storageFoundation.open('test_file');49 testCase.add_cleanup(async () => {50 await file.close();51 await storageFoundation.delete('test_file');52 });53 await promise_rejects_dom(54 testCase, 'NoModificationAllowedError',55 storageFoundation.rename('test_file', 'renamed_test_file'));56 await file.close();57 const fileNamesAfterRename = await storageFoundation.getAll();58 assert_false(fileNamesAfterRename.includes('renamed_test_file'));59 assert_in_array('test_file', fileNamesAfterRename);60}, 'storageFoundation.rename does not allow renaming an open file.');61promise_test(async testCase => {62 await reserveAndCleanupCapacity(testCase);63 testCase.add_cleanup(async () => {64 await file.close();65 await storageFoundation.delete('test_file');66 for (let name of await storageFoundation.getAll()) {67 await storageFoundation.delete(name);68 }69 });70 const file = await storageFoundation.open('test_file');71 await file.close();72 for (let name of kBadNativeIoNames) {73 await promise_rejects_js(74 testCase, TypeError, storageFoundation.rename('test_file', name));75 await promise_rejects_js(76 testCase, TypeError, storageFoundation.rename(name, 'test_file_2'));77 }78}, 'storageFoundation.rename does not allow renaming from or to invalid names.');79promise_test(async testCase => {80 await reserveAndCleanupCapacity(testCase);81 const closed_file = await storageFoundation.open('closed_file');82 closed_file.close();83 const opened_file = await storageFoundation.open('opened_file');84 testCase.add_cleanup(async () => {85 await closed_file.close();86 await opened_file.close();87 await storageFoundation.delete('closed_file');88 await storageFoundation.delete('opened_file');89 });90 // First rename fails, as source is still open.91 await promise_rejects_dom(92 testCase, 'NoModificationAllowedError',93 storageFoundation.rename('opened_file', 'closed_file'));94 // First rename fails again, as source has not been unlocked.95 await promise_rejects_dom(96 testCase, 'NoModificationAllowedError',97 storageFoundation.rename('opened_file', 'closed_file'));98}, 'Failed storageFoundation.rename does not unlock the source.');99promise_test(async testCase => {100 await reserveAndCleanupCapacity(testCase);101 const closed_file = await storageFoundation.open('closed_file');102 await closed_file.close();103 const opened_file = await storageFoundation.open('opened_file');104 testCase.add_cleanup(async () => {105 await closed_file.close();106 await opened_file.close();107 await storageFoundation.delete('closed_file');108 await storageFoundation.delete('opened_file');109 });110 // First rename fails, as destination is still open.111 await promise_rejects_dom(112 testCase, 'NoModificationAllowedError',113 storageFoundation.rename('closed_file', 'opened_file'));114 // First rename fails again, as destination has not been unlocked.115 await promise_rejects_dom(116 testCase, 'NoModificationAllowedError',117 storageFoundation.rename('closed_file', 'opened_file'));118}, 'Failed storageFoundation.rename does not unlock the destination.');119promise_test(async testCase => {120 await reserveAndCleanupCapacity(testCase);121 // Make sure that the file does not exist.122 await storageFoundation.delete('does_not_exist');123 testCase.add_cleanup(async () => {124 await storageFoundation.delete('new_does_not_exist');125 });126 await promise_rejects_dom(127 testCase, 'NotFoundError',128 storageFoundation.rename('does_not_exist', 'new_does_not_exist'));...
rename_sync_failure_handling.tentative.https.any.js
Source:rename_sync_failure_handling.tentative.https.any.js
1// META: title=Synchronous NativeIO API: Failures of rename are properly handled.2// META: global=dedicatedworker3// META: script=resources/support.js4'use strict';5setup(() => {6 // Without this assertion, one test passes even if renameSync is not defined7 assert_implements(8 storageFoundation.renameSync, 'storageFoundation.renameSync is' +9 ' not implemented.');10});11test(testCase => {12 reserveAndCleanupCapacitySync(testCase);13 const file1 = storageFoundation.openSync('test_file_1');14 const file2 = storageFoundation.openSync('test_file_2');15 testCase.add_cleanup(() => {16 file1.close();17 file2.close();18 });19 const {buffer: writeBuffer1} = file1.write(new Uint8Array([64, 65, 66, 67]), 0);20 const {buffer: writeBuffer2} = file2.write(new Uint8Array([96, 97, 98, 99]), 0);21 file1.close();22 file2.close();23 assert_throws_dom(24 'NoModificationAllowedError',25 () => storageFoundation.renameSync('test_file_1', 'test_file_2'));26 const fileNamesAfterRename = storageFoundation.getAllSync();27 assert_in_array('test_file_1', fileNamesAfterRename);28 assert_in_array('test_file_2', fileNamesAfterRename);29 // Make sure that a failed rename does not modify file contents.30 const file1_after = storageFoundation.openSync('test_file_1');31 const file2_after = storageFoundation.openSync('test_file_2');32 testCase.add_cleanup(() => {33 file1_after.close();34 file2_after.close();35 storageFoundation.deleteSync('test_file_1');36 storageFoundation.deleteSync('test_file_2');37 });38 const {buffer: readBuffer1} = file1_after.read(new Uint8Array(4), 0);39 assert_array_equals(40 readBuffer1, writeBuffer1,41 'the bytes read should match the bytes written');42 const {buffer: readBuffer2} = file2_after.read(new Uint8Array(4), 0);43 assert_array_equals(44 readBuffer2, writeBuffer2,45 'the bytes read should match the bytes written');46}, 'storageFoundation.renameSync does not overwrite an existing file.');47test(testCase => {48 reserveAndCleanupCapacitySync(testCase);49 const file = storageFoundation.openSync('test_file');50 testCase.add_cleanup(() => {51 file.close();52 storageFoundation.deleteSync('test_file');53 });54 assert_throws_dom(55 'NoModificationAllowedError',56 () => storageFoundation.renameSync('test_file', 'renamed_test_file'));57 file.close();58 const fileNamesAfterRename = storageFoundation.getAllSync();59 assert_equals(fileNamesAfterRename.indexOf('renamed_test_file'), -1);60 assert_in_array('test_file', fileNamesAfterRename);61}, 'storageFoundation.renameSync allows renaming an open file.');62test(testCase => {63 reserveAndCleanupCapacitySync(testCase);64 testCase.add_cleanup(() => {65 file.close();66 storageFoundation.deleteSync('test_file');67 for (let name of storageFoundation.getAllSync()) {68 storageFoundation.deleteSync(name);69 }70 });71 const file = storageFoundation.openSync('test_file');72 file.close();73 for (let name of kBadNativeIoNames) {74 assert_throws_js(TypeError, () => storageFoundation.renameSync('test_file',75 name));76 assert_throws_js(TypeError, () => storageFoundation.renameSync(name,77 'test_file_2'));78 }79}, 'storageFoundation.renameSync does not allow renaming from or to invalid' +80 ' names.');81test(testCase => {82 reserveAndCleanupCapacitySync(testCase);83 const closed_file = storageFoundation.openSync('closed_file');84 closed_file.close();85 const opened_file = storageFoundation.openSync('opened_file');86 testCase.add_cleanup(() => {87 closed_file.close();88 opened_file.close();89 storageFoundation.deleteSync('closed_file');90 storageFoundation.deleteSync('opened_file');91 });92 // First rename fails, as source is still open.93 assert_throws_dom(94 'NoModificationAllowedError',95 () => storageFoundation.renameSync('opened_file', 'closed_file'));96 // First rename fails again, as source has not been unlocked.97 assert_throws_dom(98 'NoModificationAllowedError',99 () => storageFoundation.renameSync('opened_file', 'closed_file'));100}, 'Failed storageFoundation.renameSync does not unlock the source.');101test(testCase => {102 reserveAndCleanupCapacitySync(testCase);103 const closed_file = storageFoundation.openSync('closed_file');104 closed_file.close();105 const opened_file = storageFoundation.openSync('opened_file');106 testCase.add_cleanup(() => {107 closed_file.close();108 opened_file.close();109 storageFoundation.deleteSync('closed_file');110 storageFoundation.deleteSync('opened_file');111 });112 // First rename fails, as destination is still open.113 assert_throws_dom(114 'NoModificationAllowedError',115 () => storageFoundation.renameSync('closed_file', 'opened_file'));116 // First rename fails again, as destination has not been unlocked.117 assert_throws_dom(118 'NoModificationAllowedError',119 () => storageFoundation.renameSync('closed_file', 'opened_file'));120}, 'Failed storageFoundation.renameSync does not unlock the destination.');121test(testCase => {122 reserveAndCleanupCapacitySync(testCase);123 // Make sure that the file does not exist.124 storageFoundation.deleteSync('does_not_exist');125 testCase.add_cleanup(() => {126 storageFoundation.deleteSync('new_name');127 });128 assert_throws_dom(129 'NotFoundError',130 () => storageFoundation.renameSync('does_not_exist', 'new_name'));...
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Barack Obama');3page.get(function(err, resp) {4 console.log(resp);5});6var wptools = require('wptools');7var page = wptools.page('Barack Obama');8page.get(function(err, resp) {9 console.log(resp);10});11var wptools = require('wptools');12var page = wptools.page('Barack Obama');13page.get(function(err, resp) {14 console.log(resp);15});16var wptools = require('wptools');17var page = wptools.page('Barack Obama');18page.get(function(err, resp) {19 console.log(resp);20});21var wptools = require('wptools');22var page = wptools.page('Barack Obama');23page.get(function(err, resp) {24 console.log(resp);25});26var wptools = require('wptools');27var page = wptools.page('Barack Obama');28page.get(function(err, resp) {29 console.log(resp);30});31var wptools = require('wptools');32var page = wptools.page('Barack Obama');33page.get(function(err, resp) {34 console.log(resp);35});36var wptools = require('wptools');37var page = wptools.page('Barack Obama');38page.get(function(err, resp) {39 console.log(resp);40});41var wptools = require('wptools');42var page = wptools.page('Barack Obama');43page.get(function(err, resp) {44 console.log(resp);45});
Using AI Code Generation
1var wpt = require('webpagetest');2var webpagetest = new wpt('API_KEY');3}, function(err, data) {4 if (err) return console.error(err);5 console.log(data);6 console.log(data.data.runs[1].firstView.videoFrames);7 console.log(data.data.runs[1].firstView.videoFiles);8 webpagetest.opened_file(data.data.runs[1].firstView.videoFiles[0], function(err, data) {9 if (err) return console.error(err);10 console.log(data);11 });12});
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org','A.1c2a3b4c5d6e7f8g9h0i1j2k3l4m5n6o7p8q9r0s1t2u3v4w5x6y7z8');3wpt.getLocations(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10 if (err) {11 console.log(err);12 } else {13 console.log(data);14 }15});161. Fork it (
Using AI Code Generation
1var wpt = require('webpage');2var page = wpt.create();3 console.log("opened file? ", status);4 var content = page.evaluate(function() {5 return document.body.innerHTML;6 });7 console.log(content);8 phantom.exit();9});
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.0b6d8f0c1c1b7c7b0f0e7c0e1e1c7f7c');3 if (err) return console.error(err);4 wpt.getTestResults(data.data.testId, function(err, data) {5 if (err) return console.error(err);6 console.log(data);7 });8});
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!!