Best JavaScript code snippet using wpt
NDEFReader_make-read-only.https.window.js
Source:NDEFReader_make-read-only.https.window.js
...20nfc_test(async (t, mockNFC) => {21 const ndef = new NDEFReader();22 const controller = new AbortController();23 // Make sure makeReadOnly is pending24 mockNFC.setPendingMakeReadOnlyCompleted(false);25 const p = ndef.makeReadOnly({signal: controller.signal});26 const rejected = promise_rejects_dom(t, 'AbortError', p);27 let callback_called = false;28 await new Promise(resolve => {29 t.step_timeout(() => {30 callback_called = true;31 controller.abort();32 resolve();33 }, 10);34 });35 await rejected;36 assert_true(callback_called, 'timeout should have caused the abort');37}, 'NDEFReader.makeReadOnly should fail if request is aborted before makeReadOnly happends.');38nfc_test(async t => {39 const ndef = new NDEFReader();40 const controller = new AbortController();41 assert_false(controller.signal.aborted);42 controller.abort();43 assert_true(controller.signal.aborted);44 await promise_rejects_dom(45 t, 'AbortError', ndef.makeReadOnly({signal: controller.signal}));46}, 'NDEFReader.makeReadOnly should fail if signal is already aborted.');47nfc_test(async t => {48 const ndef = new NDEFReader();49 const promises = [];50 invalid_signals.forEach(invalid_signal => {51 promises.push(promise_rejects_js(52 t, TypeError, ndef.makeReadOnly({signal: invalid_signal})));53 });54 await Promise.all(promises);55}, 'NDEFReader.write should fail if signal is not an AbortSignal.');56nfc_test(async (t, mockNFC) => {57 const ndef1 = new NDEFReader();58 const ndef2 = new NDEFReader();59 const controller = new AbortController();60 const p1 = ndef1.makeReadOnly({signal: controller.signal});61 // Even though makeReadOnly request is grantable,62 // this abort should be processed synchronously.63 controller.abort();64 await promise_rejects_dom(t, 'AbortError', p1);65 await ndef2.makeReadOnly();66}, 'Synchronously signaled abort.');67nfc_test(async (t, mockNFC) => {68 const ndef = new NDEFReader();69 mockNFC.setHWStatus(NFCHWStatus.DISABLED);70 await promise_rejects_dom(t, 'NotReadableError', ndef.makeReadOnly());71}, 'NDEFReader.makeReadOnly should fail when NFC HW is disabled.');72nfc_test(async (t, mockNFC) => {73 const ndef = new NDEFReader();74 mockNFC.setHWStatus(NFCHWStatus.NOT_SUPPORTED);75 await promise_rejects_dom(t, 'NotSupportedError', ndef.makeReadOnly());76}, 'NDEFReader.makeReadOnly should fail when NFC HW is not supported.');77nfc_test(async () => {78 await new Promise((resolve, reject) => {79 const iframe = document.createElement('iframe');80 iframe.srcdoc = `<script>81 window.onmessage = async (message) => {82 if (message.data === "Ready") {83 try {84 const ndef = new NDEFReader();85 await ndef.makeReadOnly();86 parent.postMessage("Failure", "*");87 } catch (error) {88 if (error.name == "InvalidStateError") {89 parent.postMessage("Success", "*");90 } else {91 parent.postMessage("Failure", "*");92 }93 }94 }95 };96 </script>`;97 iframe.onload = () => iframe.contentWindow.postMessage('Ready', '*');98 document.body.appendChild(iframe);99 window.onmessage = message => {100 if (message.data == 'Success') {101 resolve();102 } else if (message.data == 'Failure') {103 reject();104 }105 }106 });107}, 'Test that WebNFC API is not accessible from iframe context.');108nfc_test(async () => {109 const ndef = new NDEFReader();110 await ndef.makeReadOnly();111}, 'NDEFReader.makeReadOnly should succeed when NFC HW is enabled');112nfc_test(async (t, mockNFC) => {113 const ndef1 = new NDEFReader();114 const ndef2 = new NDEFReader();115 // Make sure the first makeReadOnly will be pending.116 mockNFC.setPendingMakeReadOnlyCompleted(false);117 const p1 = ndef1.makeReadOnly();118 const p2 = ndef2.makeReadOnly();119 await promise_rejects_dom(t, 'AbortError', p1);120 await p2;121}, 'NDEFReader.makeReadOnly should replace all previously configured makeReadOnly operations.');122nfc_test(async () => {123 const ndef = new NDEFReader();124 const controller1 = new AbortController();125 await ndef.makeReadOnly({signal: controller1.signal});126 const controller2 = new AbortController();127 const promise = ndef.makeReadOnly({signal: controller2.signal});128 controller1.abort();129 await promise;130}, 'NDEFReader.makeReadOnly signals are independent.');131nfc_test(async (t, mockNFC) => {132 // Make sure the makeReadOnly will be pending in the mock.133 mockNFC.setPendingMakeReadOnlyCompleted(false);134 const ndef1 = new NDEFReader();135 const promise = ndef1.makeReadOnly();136 // Just to make sure the makeReadOnly() request has already reached to the137 // mock.138 const ndef2 = new NDEFReader();139 await ndef2.scan();140 mockNFC.simulateNonNDEFTagDiscovered();141 await promise_rejects_dom(t, 'NotSupportedError', promise);142}, 'NDEFReader.makeReadOnly should fail when the NFC device coming up does not expose \143NDEF technology.');144nfc_test(async (t, mockNFC) => {145 const ndef = new NDEFReader();146 mockNFC.simulateDataTransferFails();147 await promise_rejects_dom(t, 'NetworkError', ndef.makeReadOnly());...
Using AI Code Generation
1var wptb_SetPendingMakeReadOnlyCompletedRequest = require('wptb_SetPendingMakeReadOnlyCompletedRequest');2var wptb_SetPendingMakeReadOnlyCompletedRequest = new wptb_SetPendingMakeReadOnlyCompletedRequest();3wptb_SetPendingMakeReadOnlyCompletedRequest.setPendingMakeReadOnlyCompleted();4var wptb_SetPendingMakeReadOnlyCompletedRequest = require('wptb_SetPendingMakeReadOnlyCompletedRequest');5var wptb_SetPendingMakeReadOnlyCompletedRequest = new wptb_SetPendingMakeReadOnlyCompletedRequest();6wptb_SetPendingMakeReadOnlyCompletedRequest.setPendingMakeReadOnlyCompleted();7var wptb_SetPendingMakeReadOnlyCompletedRequest = require('wptb_SetPendingMakeReadOnlyCompletedRequest');8var wptb_SetPendingMakeReadOnlyCompletedRequest = new wptb_SetPendingMakeReadOnlyCompletedRequest();9wptb_SetPendingMakeReadOnlyCompletedRequest.setPendingMakeReadOnlyCompleted();10var wptb_SetPendingMakeReadOnlyCompletedRequest = require('wptb_SetPendingMakeReadOnlyCompletedRequest');11var wptb_SetPendingMakeReadOnlyCompletedRequest = new wptb_SetPendingMakeReadOnlyCompletedRequest();12wptb_SetPendingMakeReadOnlyCompletedRequest.setPendingMakeReadOnlyCompleted();13var wptb_SetPendingMakeReadOnlyCompletedRequest = require('wptb_SetPendingMakeReadOnlyCompletedRequest');14var wptb_SetPendingMakeReadOnlyCompletedRequest = new wptb_SetPendingMakeReadOnlyCompletedRequest();15wptb_SetPendingMakeReadOnlyCompletedRequest.setPendingMakeReadOnlyCompleted();16var wptb_SetPendingMakeReadOnlyCompletedRequest = require('wptb
Using AI Code Generation
1var wptb = new ActiveXObject("Wptb.Wptb.1");2wptb.setPendingMakeReadOnlyCompleted();3var wptb = new ActiveXObject("Wptb.Wptb.1");4wptb.setPendingMakeReadOnlyCompleted();5var wptb = new ActiveXObject("Wptb.Wptb.1");6wptb.setPendingMakeReadOnlyCompleted();7var wptb = new ActiveXObject("Wptb.Wptb.1");8wptb.setPendingMakeReadOnlyCompleted();9var wptb = new ActiveXObject("Wptb.Wptb.1");10wptb.setPendingMakeReadOnlyCompleted();11var wptb = new ActiveXObject("Wptb.Wptb.1");12wptb.setPendingMakeReadOnlyCompleted();13var wptb = new ActiveXObject("Wptb.Wptb.1");14wptb.setPendingMakeReadOnlyCompleted();15var wptb = new ActiveXObject("Wptb.Wptb.1");16wptb.setPendingMakeReadOnlyCompleted();17var wptb = new ActiveXObject("Wptb.Wptb.1");18wptb.setPendingMakeReadOnlyCompleted();19var wptb = new ActiveXObject("Wptb.Wptb.1");20wptb.setPendingMakeReadOnlyCompleted();21var wptb = new ActiveXObject("Wptb.Wptb.1
Using AI Code Generation
1var wpt = new ActiveXObject("WPTOOLKIT.WPTOOLKIT");2wpt.setPendingMakeReadOnlyCompleted("C:\\test.txt", true);3var wpt = new ActiveXObject("WPTOOLKIT.WPTOOLKIT");4wpt.setPendingMakeReadOnlyCompleted("C:\\test.txt", false);5var wpt = new ActiveXObject("WPTOOLKIT.WPTOOLKIT");6wpt.setPendingMakeReadOnlyCompleted("C:\\test.txt", "true");7var wpt = new ActiveXObject("WPTOOLKIT.WPTOOLKIT");8wpt.setPendingMakeReadOnlyCompleted("C:\\test.txt", "false");9var wpt = new ActiveXObject("WPTOOLKIT.WPTOOLKIT");10wpt.setPendingMakeReadOnlyCompleted("C:\\test.txt", 1);11var wpt = new ActiveXObject("WPTOOLKIT.WPTOOLKIT");12wpt.setPendingMakeReadOnlyCompleted("C:\\test.txt", 0);13var wpt = new ActiveXObject("WPTOOLKIT.WPTOOLKIT");14wpt.setPendingMakeReadOnlyCompleted("C:\\test.txt", "1");15var wpt = new ActiveXObject("WPTOOLKIT.WPTOOLKIT");16wpt.setPendingMakeReadOnlyCompleted("C:\\test.txt", "0");17var wpt = new ActiveXObject("WPTOOLKIT.WPTOOLKIT");18wpt.setPendingMakeReadOnlyCompleted("C:\\test.txt", "abc");
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!!