How to use ev method in storybook-root

Best JavaScript code snippet using storybook-root

multi-touch-interactions.js

Source:multi-touch-interactions.js Github

copy

Full Screen

1setup({explicit_done: true});2var debug = document.getElementById("debug");3function debug_print (x) {4/* uncomment below statement to show debug messages */5// document.getElementById("debug").innerHTML += x;6}7var starting_elements = {};8function check_list_subset_of_targetlist(list, list_name, targetlist, targetlist_name) {9 var exist_in_targetlist;10 for(i=0; i<list.length; i++) {11 exist_in_targetlist=false;12 for(j=0; j<targetlist.length; j++)13 if(list.item(i).identifier==targetlist.item(j).identifier)14 exist_in_targetlist=true;15 assert_true(exist_in_targetlist, list_name + ".item("+i+") exists in " + targetlist_name);16 }17}18function check_list_subset_of_two_targetlists(list, list_name, targetlist1, targetlist1_name, targetlist2, targetlist2_name) {19 var exist_in_targetlists;20 for(i=0; i<list.length; i++) {21 exist_in_targetlists=false;22 for(j=0; j<targetlist1.length; j++)23 if(list.item(i).identifier==targetlist1.item(j).identifier)24 exist_in_targetlists=true;25 if(!exist_in_targetlists)26 for(j=0; j<targetlist2.length; j++)27 if(list.item(i).identifier==targetlist2.item(j).identifier)28 exist_in_targetlists=true;29 assert_true(exist_in_targetlists, list_name + ".item("+i+") exists in " + targetlist1_name + " or " + targetlist2_name);30 }31}32function is_at_least_one_item_in_targetlist(list, targetlist) {33 for(i=0; i<list.length; i++)34 for(j=0; j<targetlist.length; j++)35 if(list.item(i).identifier==targetlist.item(j).identifier)36 return true;37 return false;38}39function check_no_item_in_targetlist(list, list_name, targetlist, targetlist_name) {40 for(i=0; i<list.length; i++)41 for(j=0; j<targetlist.length; j++) {42 assert_false(list.item(i).identifier==targetlist.item(j).identifier, list_name + ".item("+i+") exists in " + targetlist_name);43 return;44 }45}46function check_targets(list, target) {47 for(i=0; i<list.length; i++)48 assert_true(list.item(i).target==target, "item(" + i + ").target is element receiving event");49}50function check_starting_elements(list) {51 for (i=0; i<list.length; i++) {52 assert_equals(list.item(i).target, starting_elements[list.item(i).identifier], "item(" + i + ").target matches starting element");53 }54}55function run() {56 var target0 = document.getElementById("target0");57 var target1 = document.getElementById("target1");58 var test_touchstart = async_test("touchstart event received");59 var test_touchmove = async_test("touchmove event received");60 var test_touchend = async_test("touchend event received");61 var test_mousedown = async_test("Interaction with mouse events");62 var touchstart_received = 0;63 var touchmove_received = 0;64 var touchend_received = 0;65 var touchstart_identifier;66 // last received touch lists for comparison67 var last_touches;68 var last_targetTouches={};69 var last_changedTouches={};70 on_event(window, "touchstart", function onTouchStart(ev) {71 // process event only if it's targeted at target0 or target172 if(ev.target != target0 && ev.target != target1 )73 return;74 ev.preventDefault();75 if(!touchstart_received) {76 // Check event ordering TA: 1.6.177 test_touchstart.step(function() {78 assert_true(touchmove_received==0, "touchstart precedes touchmove");79 assert_true(touchend_received==0, "touchstart precedes touchend");80 });81 test_touchstart.done();82 test_mousedown.done(); // If we got here, then the mouse event test is not needed.83 }84 touchstart_received++;85 // TA: 1.3.2.2, 1.3.2.486 test(function() {87 assert_true(ev.changedTouches.length >= 1, "changedTouches.length is at least 1");88 assert_true(ev.changedTouches.length <= ev.touches.length, "changedTouches.length is smaller than touches.length");89 check_list_subset_of_targetlist(ev.changedTouches, "changedTouches", ev.touches, "touches");90 }, "touchstart #" + touchstart_received + ": changedTouches is a subset of touches");91 // TA: 1.3.3.2, 1.3.3.392 test(function() {93 assert_true(ev.targetTouches.length >= 1, "targetTouches.length is at least 1");94 assert_true(ev.targetTouches.length <= ev.touches.length, "targetTouches.length is smaller than touches.length");95 check_list_subset_of_targetlist(ev.targetTouches, "targetTouches", ev.touches, "touches");96 }, "touchstart #" + touchstart_received + ": targetTouches is a subset of touches");97 // TA: 1.3.3.998 test(function() {99 check_targets(ev.targetTouches, ev.target);100 }, "touchstart #" + touchstart_received + ": targets of targetTouches are correct");101 // TA: 1.3.4.2102 test(function() {103 assert_true(ev.touches.length >= 1, "touches.length is at least 1");104 }, "touchstart #" + touchstart_received + ": touches.length is valid");105 if(touchstart_received == 1) {106 // TA: 1.3.3.5, 1.3.3.7107 test(function() {108 assert_true(ev.targetTouches.length <= ev.changedTouches.length, "targetTouches.length is smaller than changedTouches.length");109 check_list_subset_of_targetlist(ev.targetTouches, "targetTouches", ev.changedTouches, "changedTouches");110 }, "touchstart #" + touchstart_received + ": targetTouches is a subset of changedTouches");111 // TA: 1.3.4.3112 test(function() {113 assert_true(ev.touches.length==ev.changedTouches.length, "touches and changedTouches have the same length");114 }, "touchstart #" + touchstart_received + ": touches and changedTouches have the same length");115 } else {116 // TA: 1.3.3.6117 test(function() {118 var diff_in_targetTouches = ev.targetTouches.length - (last_targetTouches[ev.target.id] ? last_targetTouches[ev.target.id].length : 0);119 assert_true(diff_in_targetTouches > 0, "targetTouches.length is larger than last received targetTouches.length");120 assert_true(diff_in_targetTouches <= ev.changedTouches.length, "change in targetTouches.length is smaller than changedTouches.length");121 }, "touchstart #" + touchstart_received + ": change in targetTouches.length is valid");122 // TA: 1.3.3.8123 test(function() {124 assert_true(is_at_least_one_item_in_targetlist(ev.targetTouches, ev.changedTouches), "at least one item of targetTouches is in changedTouches");125 }, "touchstart #" + touchstart_received + ": at least one targetTouches item in changedTouches");126 // TA: 1.3.4.4127 test(function() {128 var diff_in_touches = ev.touches.length - last_touches.length;129 assert_true(diff_in_touches > 0, "touches.length is larger than last received touches.length");130 assert_true(diff_in_touches == ev.changedTouches.length, "change in touches.length equals changedTouches.length");131 }, "touchstart #" + touchstart_received + ": change in touches.length is valid");132 // TA: 1.3.4.5133 test(function() {134 check_list_subset_of_two_targetlists(ev.touches, "touches", ev.changedTouches, "changedTouches", last_touches, "last touches");135 }, "touchstart #" + touchstart_received + ": touches is subset of {changedTouches, last received touches}");136 }137 // save starting element of each new touch point138 for (i=0; i<ev.changedTouches.length; i++) {139 starting_elements[ev.changedTouches.item(i).identifier] = ev.changedTouches.item(i).target;140 }141 last_touches = ev.touches;142 last_targetTouches[ev.target.id] = ev.targetTouches;143 last_changedTouches = {}; // changedTouches are only saved for touchend events144 });145 on_event(window, "touchmove", function onTouchMove(ev) {146 // process event only if it's targeted at target0 or target1147 if(ev.target != target0 && ev.target != target1 )148 return;149 ev.preventDefault();150 // TA: 1.6.1151 test_touchmove.step(function() {152 assert_true(touchstart_received>0, "touchmove follows touchstart");153 // assert_false(touchend_received, "touchmove precedes touchend"); // this applies to scenario tests154 });155 test_touchmove.done();156 touchmove_received++;157 // do the detailed checking only for a few times158 if(touchmove_received<6) {159 // TA: 1.4.2.2, 1.4.2.4160 test(function() {161 assert_true(ev.changedTouches.length >= 1, "changedTouches.length is at least 1");162 assert_true(ev.changedTouches.length <= ev.touches.length, "changedTouches.length is smaller than touches.length");163 check_list_subset_of_targetlist(ev.changedTouches, "changedTouches", ev.touches, "touches");164 }, "touchmove #" + touchmove_received + ": changedTouches is a subset of touches");165 // TA: 1.4.3.2, 1.4.3.4166 test(function() {167 assert_true(ev.targetTouches.length >= 1, "targetTouches.length is at least 1");168 assert_true(ev.targetTouches.length <= ev.touches.length, "targetTouches.length is smaller than touches.length");169 check_list_subset_of_targetlist(ev.targetTouches, "targetTouches", ev.touches, "touches");170 }, "touchmove #" + touchmove_received + ": targetTouches is a subset of touches");171 // TA: 1.4.3.6172 test(function() {173 assert_true(is_at_least_one_item_in_targetlist(ev.targetTouches, ev.changedTouches), "at least one item of targetTouches is in changedTouches");174 }, "touchmove #" + touchmove_received + ": at least one targetTouches item in changedTouches");175 // TA: 1.4.3.8176 test(function() {177 check_targets(ev.targetTouches, ev.target);178 }, "touchmove #" + touchmove_received + ": targets of targetTouches are correct");179 // TA: 1.4.4.2180 test(function() {181 assert_true(ev.touches.length==last_touches.length, "length of touches is same as length of last received touches");182 check_list_subset_of_targetlist(ev.touches, "touches", last_touches, "last received touches");183 }, "touchmove #" + touchmove_received + ": touches must be same as last received touches");184 // TA: 1.6.3185 check_starting_elements(ev.changedTouches);186 }187 last_touches = ev.touches;188 last_targetTouches[ev.target.id] = ev.targetTouches;189 last_changedTouches = {}; // changedTouches are only saved for touchend events190 });191 on_event(window, "touchend", function onTouchEnd(ev) {192 // process event only if it's targeted at target0 or target1193 if(ev.target != target0 && ev.target != target1 )194 return;195 test_touchend.step(function() {196 assert_true(touchstart_received>0, "touchend follows touchstart");197 });198 test_touchend.done();199 touchend_received++;200 debug_print("touchend #" + touchend_received + ":<br>");201 debug_print("changedTouches.length=" + ev.changedTouches.length + "<br>");202 debug_print("targetTouches.length=" + ev.targetTouches.length + "<br>");203 debug_print("touches.length=" + ev.touches.length + "<br>");204 for(i=0; i<ev.changedTouches.length; i++)205 debug_print("changedTouches.item(" + i + ").target=" + ev.changedTouches.item(i).target.id + "<br>");206 // TA: 1.5.2.2207 test(function() {208 assert_true(ev.changedTouches.length >= 1, "changedTouches.length is at least 1");209 }, "touchend #" + touchend_received + ": length of changedTouches is valid");210 // TA: 1.5.2.3211 test(function() {212 check_list_subset_of_targetlist(ev.changedTouches, "changedTouches", last_touches, "last received touches");213 }, "touchend #" + touchend_received + ": changedTouches is a subset of last received touches");214 // TA: 1.5.2.4, 1.5.2.5215 test(function() {216 check_no_item_in_targetlist(ev.changedTouches, "changedTouches", ev.touches, "touches");217 check_no_item_in_targetlist(ev.changedTouches, "changedTouches", ev.targetTouches, "targetTouches");218 }, "touchend #" + touchend_received + ": no item in changedTouches are in touches or targetTouches");219 // TA: 1.5.2.6220 test(function() {221 var found=false;222 for (i=0; i<ev.changedTouches.length; i++)223 if (ev.changedTouches.item(i).target == ev.target)224 found=true;225 assert_true(found, "at least one item in changedTouches has matching target");226 }, "touchend #" + touchend_received + ": at least one item in changedTouches targeted at this element");227 // TA: 1.5.3.2, 1.5.3.3228 test(function() {229 assert_true(ev.targetTouches.length >= 0, "targetTouches.length is non-negative");230 assert_true(ev.targetTouches.length <= ev.touches.length, "targetTouches.length is smaller than touches.length");231 check_list_subset_of_targetlist(ev.targetTouches, "targetTouches", ev.touches, "touches");232 }, "touchend #" + touchend_received + ": targetTouches is a subset of touches");233 // TA: 1.5.3.5 (new)234 test(function() {235 check_targets(ev.targetTouches, ev.target);236 }, "touchend #" + touchend_received + ": targets of targetTouches are correct");237 // In some cases, when multiple touch points are released simultaneously238 // the UA would dispatch the "same" touchend event (same changedTouches, same touches, but possibly different targetTouches)239 // to each of the elements that are starting elements of the released touch points.240 // in these situations, the subsequent events are exempt from TA 1.5.3.4 and 1.5.4.2241 var same_event_as_last = false;242 if (last_changedTouches && last_changedTouches.length==ev.changedTouches.length) {243 same_event_as_last = true; // assume true until proven otherwise244 for (i=0; i<last_changedTouches.length; i++) {245 var match = false;246 for (j=0; j<ev.changedTouches.length; j++)247 if (last_changedTouches.item(i) == ev.changedTouches.item(j)) {248 match = true;249 break;250 }251 if (!match)252 same_event_as_last = false;253 }254 }255 if (!same_event_as_last) {256 // TA: 1.5.3.4257 // Getting semi-random failures on this and 1.5.4.2.258 // See 1.5.4.2. Not sure if it's the same issue...259 test(function() {260 assert_true(last_targetTouches[ev.target.id].length > 0, "last received targetTouches.length is not zero");261 var diff_in_targetTouches = last_targetTouches[ev.target.id].length - ev.targetTouches.length;262 debug_print("diff_in_targetTouches=" + diff_in_targetTouches + "<br>");263 assert_true(diff_in_targetTouches > 0, "targetTouches.length is smaller than last received targetTouches.length");264 assert_true(diff_in_targetTouches <= ev.changedTouches.length, "change in targetTouches.length is smaller than changedTouches.length");265 }, "touchend #" + touchend_received + ": change in targetTouches.length is valid");266 // TA: 1.5.4.2267 // Getting semi-random failures on this and 1.5.3.4.268 // It looks like if fingers are lifted simultaneously, the "same" touchend event can be dispatched to two target elements269 // but adapted to the element (same touches, changedTouches but different targetTouches).270 // When one event is processed after another, ev.touches would end up being identical to last_touches, leading to failure.271 // Question is why done() does not stop the processing of the latter event.272 test(function() {273 assert_true(last_touches.length > 0, "last received touches.length is not zero");274 var diff_in_touches = last_touches.length - ev.touches.length;275 debug_print("diff_in_touches=" + diff_in_touches + "<br>");276 assert_true(diff_in_touches > 0, "touches.length is smaller than last received touches.length");277 assert_equals(diff_in_touches, ev.changedTouches.length, "change in touches.length equals changedTouches.length");278 }, "touchend #" + touchend_received + ": change in touches.length is valid");279 }280 // TA: 1.6.4281 debug_print("touchend #" + touchend_received + ": TA 1.6.4<br>");282 test(function() {283 check_starting_elements(ev.changedTouches);284 }, "touchend #" + touchend_received + ": event dispatched to correct element<br>");285 debug_print("touchend #" + touchend_received + ": saving touch lists<br>");286 last_touches = ev.touches;287 last_targetTouches[ev.target.id] = ev.targetTouches;288 last_changedTouches = ev.changedTouches;289 debug_print("touchend #" + touchend_received + ": done<br>");290 if(ev.touches.length==0)291 done();292 });293 on_event(target0, "mousedown", function onMouseDown(ev) {294 test_mousedown.step(function() {295 assert_true(touchstart_received,296 "The touchstart event must be dispatched before any mouse " +297 "events. (If this fails, it might mean that the user agent does " +298 "not implement W3C touch events at all.)"299 );300 });301 test_mousedown.done();302 if (!touchstart_received) {303 // Abort the tests. If touch events are not supported, then most of304 // the other event handlers will never be called, and the test will305 // time out with misleading results.306 done();307 }308 });...

Full Screen

Full Screen

test_ev_certs.js

Source:test_ev_certs.js Github

copy

Full Screen

...38function check_cert_err(cert_name, expected_error) {39 let cert = certdb.findCertByNickname(null, cert_name);40 checkCertErrorGeneric(certdb, cert, expected_error, certificateUsageSSLServer);41}42function check_ee_for_ev(cert_name, expected_ev) {43 let cert = certdb.findCertByNickname(null, cert_name);44 checkEVStatus(certdb, cert, certificateUsageSSLServer, expected_ev);45}46function run_test() {47 for (let i = 0 ; i < certList.length; i++) {48 let cert_filename = certList[i] + ".pem";49 addCertFromFile(certdb, "test_ev_certs/" + cert_filename, ',,');50 }51 load_ca("evroot");52 load_ca("non-evroot-ca");53 // setup and start ocsp responder54 Services.prefs.setCharPref("network.dns.localDomains",55 'www.example.com, crl.example.com');56 Services.prefs.setIntPref("security.OCSP.enabled", 1);57 add_test(function () {58 clearOCSPCache();59 let ocspResponder = start_ocsp_responder(60 gEVExpected ? ["int-ev-valid", "ev-valid"]61 : ["ev-valid"]);62 check_ee_for_ev("ev-valid", gEVExpected);63 ocspResponder.stop(run_next_test);64 });65 add_test(function () {66 clearOCSPCache();67 let ocspResponder = start_ocsp_responder(68 gEVExpected ? ["int-ev-valid-anypolicy-int", "ev-valid-anypolicy-int"]69 : ["ev-valid-anypolicy-int"]);70 check_ee_for_ev("ev-valid-anypolicy-int", gEVExpected);71 ocspResponder.stop(run_next_test);72 });73 add_test(function() {74 clearOCSPCache();75 let ocspResponder = start_ocsp_responder(["non-ev-root"]);76 check_ee_for_ev("non-ev-root", false);77 ocspResponder.stop(run_next_test);78 });79 add_test(function() {80 clearOCSPCache();81 let ocspResponder = gEVExpected ? start_ocsp_responder(["int-ev-valid"])82 : failingOCSPResponder();83 check_ee_for_ev("no-ocsp-url-cert", false);84 ocspResponder.stop(run_next_test);85 });86 // bug 917380: Check that explicitly removing trust from an EV root actually87 // causes the root to be untrusted.88 const nsIX509Cert = Ci.nsIX509Cert;89 add_test(function() {90 let evRootCA = certdb.findCertByNickname(null, evrootnick);91 certdb.setCertTrust(evRootCA, nsIX509Cert.CA_CERT, 0);92 clearOCSPCache();93 let ocspResponder = failingOCSPResponder();94 check_cert_err("ev-valid", SEC_ERROR_UNKNOWN_ISSUER);95 ocspResponder.stop(run_next_test);96 });97 // bug 917380: Check that a trusted EV root is trusted after disabling and98 // re-enabling trust.99 add_test(function() {100 let evRootCA = certdb.findCertByNickname(null, evrootnick);101 certdb.setCertTrust(evRootCA, nsIX509Cert.CA_CERT,102 Ci.nsIX509CertDB.TRUSTED_SSL |103 Ci.nsIX509CertDB.TRUSTED_EMAIL |104 Ci.nsIX509CertDB.TRUSTED_OBJSIGN);105 clearOCSPCache();106 let ocspResponder = start_ocsp_responder(107 gEVExpected ? ["int-ev-valid", "ev-valid"]108 : ["ev-valid"]);109 check_ee_for_ev("ev-valid", gEVExpected);110 ocspResponder.stop(run_next_test);111 });112 add_test(function () {113 check_no_ocsp_requests("ev-valid", SEC_ERROR_POLICY_VALIDATION_FAILED);114 });115 add_test(function () {116 check_no_ocsp_requests("non-ev-root", SEC_ERROR_POLICY_VALIDATION_FAILED);117 });118 add_test(function () {119 check_no_ocsp_requests("no-ocsp-url-cert", SEC_ERROR_POLICY_VALIDATION_FAILED);120 });121 // Check OneCRL OCSP request skipping works correctly122 add_test(function () {123 // enable OneCRL OCSP skipping - allow staleness of up to 30 hours124 Services.prefs.setIntPref("security.onecrl.maximum_staleness_in_seconds", 108000);125 // set the blocklist-background-update-timer value to the recent past126 Services.prefs.setIntPref("app.update.lastUpdateTime.blocklist-background-update-timer",127 Math.floor(Date.now() / 1000) - 1);128 clearOCSPCache();129 // the intermediate should not have an associated OCSP request130 let ocspResponder = start_ocsp_responder(["ev-valid"]);131 check_ee_for_ev("ev-valid", gEVExpected);132 Services.prefs.clearUserPref("security.onecrl.maximum_staleness_in_seconds");133 ocspResponder.stop(run_next_test);134 });135 add_test(function () {136 // disable OneCRL OCSP Skipping (no staleness allowed)137 Services.prefs.setIntPref("security.onecrl.maximum_staleness_in_seconds", 0);138 clearOCSPCache();139 let ocspResponder = start_ocsp_responder(140 gEVExpected ? ["int-ev-valid", "ev-valid"]141 : ["ev-valid"]);142 check_ee_for_ev("ev-valid", gEVExpected);143 Services.prefs.clearUserPref("security.onecrl.maximum_staleness_in_seconds");144 ocspResponder.stop(run_next_test);145 });146 add_test(function () {147 // enable OneCRL OCSP skipping - allow staleness of up to 30 hours148 Services.prefs.setIntPref("security.onecrl.maximum_staleness_in_seconds", 108000);149 // set the blocklist-background-update-timer value to the more distant past150 Services.prefs.setIntPref("app.update.lastUpdateTime.blocklist-background-update-timer",151 Math.floor(Date.now() / 1000) - 108080);152 clearOCSPCache();153 let ocspResponder = start_ocsp_responder(154 gEVExpected ? ["int-ev-valid", "ev-valid"]155 : ["ev-valid"]);156 check_ee_for_ev("ev-valid", gEVExpected);157 Services.prefs.clearUserPref("security.onecrl.maximum_staleness_in_seconds");158 ocspResponder.stop(run_next_test);159 });160 add_test(function () {161 // test that setting "security.onecrl.via.amo" results in the correct162 // OCSP behavior when services.kinto.onecrl.checked is in the distant past163 // and blacklist-background-update-timer is recent164 Services.prefs.setBoolPref("security.onecrl.via.amo", false);165 // enable OneCRL OCSP skipping - allow staleness of up to 30 hours166 Services.prefs.setIntPref("security.onecrl.maximum_staleness_in_seconds", 108000);167 // set the blocklist-background-update-timer value to the recent past168 // (services.kinto.onecrl.checked defaults to 0)169 Services.prefs.setIntPref("app.update.lastUpdateTime.blocklist-background-update-timer",170 Math.floor(Date.now() / 1000) - 1);171 clearOCSPCache();172 // the intermediate should have an associated OCSP request173 let ocspResponder = start_ocsp_responder(174 gEVExpected ? ["int-ev-valid", "ev-valid"]175 : ["ev-valid"]);176 check_ee_for_ev("ev-valid", gEVExpected);177 ocspResponder.stop(run_next_test);178 });179 add_test(function () {180 // test that setting "security.onecrl.via.amo" results in the correct181 // OCSP behavior when services.kinto.onecrl.checked is recent182 Services.prefs.setBoolPref("security.onecrl.via.amo", false);183 // enable OneCRL OCSP skipping - allow staleness of up to 30 hours184 Services.prefs.setIntPref("security.onecrl.maximum_staleness_in_seconds", 108000);185 // now set services.kinto.onecrl.checked to a recent value186 Services.prefs.setIntPref("services.kinto.onecrl.checked",187 Math.floor(Date.now() / 1000) - 1);188 clearOCSPCache();189 // the intermediate should not have an associated OCSP request190 let ocspResponder = start_ocsp_responder(["ev-valid"]);191 check_ee_for_ev("ev-valid", gEVExpected);192 // The tests following this assume no OCSP bypass193 Services.prefs.setIntPref("security.onecrl.maximum_staleness_in_seconds", 0);194 Services.prefs.clearUserPref("security.onecrl.via.amo");195 Services.prefs.clearUserPref("services.kinto.onecrl.checked");196 ocspResponder.stop(run_next_test);197 });198 // Test the EV continues to work with flags after successful EV verification199 add_test(function () {200 clearOCSPCache();201 let ocspResponder = start_ocsp_responder(202 gEVExpected ? ["int-ev-valid", "ev-valid"]203 : ["ev-valid"]);204 check_ee_for_ev("ev-valid", gEVExpected);205 ocspResponder.stop(function () {206 // without net it must be able to EV verify207 let failingOcspResponder = failingOCSPResponder();208 let cert = certdb.findCertByNickname(null, "ev-valid");209 let hasEVPolicy = {};210 let verifiedChain = {};211 let flags = Ci.nsIX509CertDB.FLAG_LOCAL_ONLY |212 Ci.nsIX509CertDB.FLAG_MUST_BE_EV;213 let error = certdb.verifyCertNow(cert, certificateUsageSSLServer, flags,214 null, verifiedChain, hasEVPolicy);215 equal(hasEVPolicy.value, gEVExpected,216 "Actual and expected EV status should match for local only EV");217 equal(error,218 gEVExpected ? PRErrorCodeSuccess : SEC_ERROR_POLICY_VALIDATION_FAILED,219 "Actual and expected error code should match for local only EV");220 failingOcspResponder.stop(run_next_test);221 });222 });223 // Bug 991815 old but valid intermediates are OK224 add_test(function () {225 clearOCSPCache();226 let ocspResponder = startOCSPResponder(SERVER_PORT, "www.example.com", [],227 "test_ev_certs",228 gEVExpected ? ["int-ev-valid", "ev-valid"]229 : ["ev-valid"],230 [], [],231 gEVExpected ? ["longvalidityalmostold", "good"]232 : ["good"]);233 check_ee_for_ev("ev-valid", gEVExpected);234 ocspResponder.stop(run_next_test);235 });236 // Bug 991815 old but valid end-entities are NOT OK for EV237 // Unfortunately because of soft-fail we consider these OK for DV.238 add_test(function () {239 clearOCSPCache();240 // Since Mozilla::pkix does not consider the old almost invalid OCSP241 // response valid, it does not cache the old response and thus242 // makes a separate request for DV243 let debugCertNickArray = ["int-ev-valid", "ev-valid", "ev-valid"];244 let debugResponseArray = ["good", "longvalidityalmostold",245 "longvalidityalmostold"];246 let ocspResponder = startOCSPResponder(SERVER_PORT, "www.example.com", [],247 "test_ev_certs",248 gEVExpected ? debugCertNickArray : ["ev-valid"],249 [], [],250 gEVExpected ? debugResponseArray251 : ["longvalidityalmostold"]);252 check_ee_for_ev("ev-valid", false);253 ocspResponder.stop(run_next_test);254 });255 // Bug 991815 Valid but Ancient (almost two year old) responses are Not OK for256 // EV (still OK for soft fail DV)257 add_test(function () {258 clearOCSPCache();259 let debugCertNickArray = ["int-ev-valid", "ev-valid", "ev-valid"];260 let debugResponseArray = ["good", "ancientstillvalid",261 "ancientstillvalid"];262 let ocspResponder = startOCSPResponder(SERVER_PORT, "www.example.com", [],263 "test_ev_certs",264 gEVExpected ? debugCertNickArray : ["ev-valid"],265 [], [],266 gEVExpected ? debugResponseArray267 : ["ancientstillvalid"]);268 check_ee_for_ev("ev-valid", false);269 ocspResponder.stop(run_next_test);270 });271 run_next_test();272}273// bug 950240: add FLAG_MUST_BE_EV to CertVerifier::VerifyCert274// to prevent spurious OCSP requests that race with OCSP stapling.275// This has the side-effect of saying an EV certificate is not EV if276// it hasn't already been verified (e.g. on the verification thread when277// connecting to a site).278// This flag is mostly a hack that should be removed once FLAG_LOCAL_ONLY279// works as intended.280function check_no_ocsp_requests(cert_name, expected_error) {281 clearOCSPCache();282 let ocspResponder = failingOCSPResponder();...

Full Screen

Full Screen

fetch_event_worker.js

Source:fetch_event_worker.js Github

copy

Full Screen

1var seenIndex = false;2onfetch = function(ev) {3 if (ev.request.url.includes("ignore")) {4 return;5 }6 if (ev.request.url.includes("bare-synthesized.txt")) {7 ev.respondWith(Promise.resolve(8 new Response("synthesized response body", {})9 ));10 }11 else if (ev.request.url.includes('file_CrossSiteXHR_server.sjs')) {12 // N.B. this response would break the rules of CORS if it were allowed, but13 // this test relies upon the preflight request not being intercepted and14 // thus this response should not be used.15 if (ev.request.method == 'OPTIONS') {16 ev.respondWith(new Response('', {headers: {'Access-Control-Allow-Origin': '*',17 'Access-Control-Allow-Headers': 'X-Unsafe'}}))18 } else if (ev.request.url.includes('example.org')) {19 ev.respondWith(fetch(ev.request));20 }21 }22 else if (ev.request.url.includes("synthesized-404.txt")) {23 ev.respondWith(Promise.resolve(24 new Response("synthesized response body", { status: 404 })25 ));26 }27 else if (ev.request.url.includes("synthesized-headers.txt")) {28 ev.respondWith(Promise.resolve(29 new Response("synthesized response body", {30 headers: {31 "X-Custom-Greeting": "Hello"32 }33 })34 ));35 }36 else if (ev.request.url.includes("test-respondwith-response.txt")) {37 ev.respondWith(new Response("test-respondwith-response response body", {}));38 }39 else if (ev.request.url.includes("synthesized-redirect-real-file.txt")) {40 ev.respondWith(Promise.resolve(41 Response.redirect("fetch/real-file.txt")42 ));43 }44 else if (ev.request.url.includes("synthesized-redirect-twice-real-file.txt")) {45 ev.respondWith(Promise.resolve(46 Response.redirect("synthesized-redirect-real-file.txt")47 ));48 }49 else if (ev.request.url.includes("synthesized-redirect-synthesized.txt")) {50 ev.respondWith(Promise.resolve(51 Response.redirect("bare-synthesized.txt")52 ));53 }54 else if (ev.request.url.includes("synthesized-redirect-twice-synthesized.txt")) {55 ev.respondWith(Promise.resolve(56 Response.redirect("synthesized-redirect-synthesized.txt")57 ));58 }59 else if (ev.request.url.includes("rejected.txt")) {60 ev.respondWith(Promise.reject());61 }62 else if (ev.request.url.includes("nonresponse.txt")) {63 ev.respondWith(Promise.resolve(5));64 }65 else if (ev.request.url.includes("nonresponse2.txt")) {66 ev.respondWith(Promise.resolve({}));67 }68 else if (ev.request.url.includes("nonpromise.txt")) {69 try {70 // This should coerce to Promise(5) instead of throwing71 ev.respondWith(5);72 } catch (e) {73 // test is expecting failure, so return a success if we get a thrown74 // exception75 ev.respondWith(new Response('respondWith(5) threw ' + e));76 }77 }78 else if (ev.request.url.includes("headers.txt")) {79 var ok = true;80 ok &= ev.request.headers.get("X-Test1") == "header1";81 ok &= ev.request.headers.get("X-Test2") == "header2";82 ev.respondWith(Promise.resolve(83 new Response(ok.toString(), {})84 ));85 }86 else if (ev.request.url.includes("nonexistent_image.gif")) {87 var imageAsBinaryString = atob("R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs");88 var imageLength = imageAsBinaryString.length;89 // If we just pass |imageAsBinaryString| to the Response constructor, an90 // encoding conversion occurs that corrupts the image. Instead, we need to91 // convert it to a typed array.92 // typed array.93 var imageAsArray = new Uint8Array(imageLength);94 for (var i = 0; i < imageLength; ++i) {95 imageAsArray[i] = imageAsBinaryString.charCodeAt(i);96 }97 ev.respondWith(Promise.resolve(98 new Response(imageAsArray, { headers: { "Content-Type": "image/gif" } })99 ));100 }101 else if (ev.request.url.includes("nonexistent_script.js")) {102 ev.respondWith(Promise.resolve(103 new Response("check_intercepted_script();", {})104 ));105 }106 else if (ev.request.url.includes("nonexistent_stylesheet.css")) {107 ev.respondWith(Promise.resolve(108 new Response("#style-test { background-color: black !important; }", {109 headers : {110 "Content-Type": "text/css"111 }112 })113 ));114 }115 else if (ev.request.url.includes("nonexistent_page.html")) {116 ev.respondWith(Promise.resolve(117 new Response("<script>window.frameElement.test_result = true;</script>", {118 headers : {119 "Content-Type": "text/html"120 }121 })122 ));123 }124 else if (ev.request.url.includes("nonexistent_worker_script.js")) {125 ev.respondWith(Promise.resolve(126 new Response("postMessage('worker-intercept-success')", {})127 ));128 }129 else if (ev.request.url.includes("nonexistent_imported_script.js")) {130 ev.respondWith(Promise.resolve(131 new Response("check_intercepted_script();", {})132 ));133 }134 else if (ev.request.url.includes("deliver-gzip")) {135 // Don't handle the request, this will make Necko perform a network request, at136 // which point SetApplyConversion must be re-enabled, otherwise the request137 // will fail.138 return;139 }140 else if (ev.request.url.includes("hello.gz")) {141 ev.respondWith(fetch("fetch/deliver-gzip.sjs"));142 }143 else if (ev.request.url.includes("hello-after-extracting.gz")) {144 ev.respondWith(fetch("fetch/deliver-gzip.sjs").then(function(res) {145 return res.text().then(function(body) {146 return new Response(body, { status: res.status, statusText: res.statusText, headers: res.headers });147 });148 }));149 }150 else if (ev.request.url.includes('opaque-on-same-origin')) {151 var url = 'http://example.com/tests/dom/security/test/cors/file_CrossSiteXHR_server.sjs?status=200';152 ev.respondWith(fetch(url, { mode: 'no-cors' }));153 }154 else if (ev.request.url.includes('opaque-no-cors')) {155 if (ev.request.mode != "no-cors") {156 ev.respondWith(Promise.reject());157 return;158 }159 var url = 'http://example.com/tests/dom/security/test/cors/file_CrossSiteXHR_server.sjs?status=200';160 ev.respondWith(fetch(url, { mode: ev.request.mode }));161 }162 else if (ev.request.url.includes('cors-for-no-cors')) {163 if (ev.request.mode != "no-cors") {164 ev.respondWith(Promise.reject());165 return;166 }167 var url = 'http://example.com/tests/dom/security/test/cors/file_CrossSiteXHR_server.sjs?status=200&allowOrigin=*';168 ev.respondWith(fetch(url));169 }170 else if (ev.request.url.includes('example.com')) {171 ev.respondWith(fetch(ev.request));172 }173 else if (ev.request.url.includes("index.html")) {174 if (seenIndex) {175 var body = "<script>" +176 "opener.postMessage({status: 'ok', result: " + ev.isReload + "," +177 "message: 'reload status should be indicated'}, '*');" +178 "opener.postMessage({status: 'done'}, '*');" +179 "</script>";180 ev.respondWith(new Response(body, {headers: {'Content-Type': 'text/html'}}));181 } else {182 seenIndex = true;183 ev.respondWith(fetch(ev.request.url));184 }185 }186 else if (ev.request.url.includes("body-")) {187 ev.respondWith(ev.request.text().then(function (body) {188 return new Response(body + body);189 }));190 }191 else if (ev.request.url.includes('something.txt')) {192 ev.respondWith(Response.redirect('fetch/somethingelse.txt'));193 }194 else if (ev.request.url.includes('somethingelse.txt')) {195 ev.respondWith(new Response('something else response body', {}));196 }197 else if (ev.request.url.includes('redirect_serviceworker.sjs')) {198 // The redirect_serviceworker.sjs server-side JavaScript file redirects to199 // 'http://mochi.test:8888/tests/dom/workers/test/serviceworkers/worker.js'200 // The redirected fetch should not go through the SW since the original201 // fetch was initiated from a SW.202 ev.respondWith(fetch('redirect_serviceworker.sjs'));203 }204 else if (ev.request.url.includes('load_cross_origin_xml_document_synthetic.xml')) {205 if (ev.request.mode != 'same-origin') {206 ev.respondWith(Promise.reject());207 return;208 }209 ev.respondWith(Promise.resolve(210 new Response("<response>body</response>", { headers: {'Content-Type': 'text/xtml'}})211 ));212 }213 else if (ev.request.url.includes('load_cross_origin_xml_document_cors.xml')) {214 if (ev.request.mode != 'same-origin') {215 ev.respondWith(Promise.reject());216 return;217 }218 var url = 'http://example.com/tests/dom/security/test/cors/file_CrossSiteXHR_server.sjs?status=200&allowOrigin=*';219 ev.respondWith(fetch(url, { mode: 'cors' }));220 }221 else if (ev.request.url.includes('load_cross_origin_xml_document_opaque.xml')) {222 if (ev.request.mode != 'same-origin') {223 Promise.resolve(224 new Response("<error>Invalid Request mode</error>", { headers: {'Content-Type': 'text/xtml'}})225 );226 return;227 }228 var url = 'http://example.com/tests/dom/security/test/cors/file_CrossSiteXHR_server.sjs?status=200';229 ev.respondWith(fetch(url, { mode: 'no-cors' }));230 }231 else if (ev.request.url.includes('xhr-method-test.txt')) {232 ev.respondWith(new Response('intercepted ' + ev.request.method));233 }234 else if (ev.request.url.includes('empty-header')) {235 if (!ev.request.headers.has("emptyheader") ||236 ev.request.headers.get("emptyheader") !== "") {237 ev.respondWith(Promise.reject());238 return;239 }240 ev.respondWith(new Response("emptyheader"));241 }242 else if (ev.request.url.includes('fetchevent-extendable')) {243 if (ev instanceof ExtendableEvent) {244 ev.respondWith(new Response("extendable"));245 } else {246 ev.respondWith(Promise.reject());247 }248 }249 else if (ev.request.url.includes('fetchevent-request')) {250 if ((new FetchEvent("foo")).request === null) {251 ev.respondWith(new Response("nullable"));252 } else {253 ev.respondWith(Promise.reject());254 }255 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ev } from 'storybook-root';2ev('my-event', { foo: 'bar' });3import { ev } from 'storybook-root';4ev('my-event', { foo: 'bar' });5const ev = (event, detail) => window.dispatchEvent(new CustomEvent(event, { detail }));6export { ev };7const ev = (event, detail) => window.dispatchEvent(new CustomEvent(event, { detail }));8export { ev };9import { ev } from 'storybook-root';10ev('my-event', { foo: 'bar' });11import { ev } from 'storybook-root';12ev('my-event', { foo: 'bar' });13const ev = (event, detail) => window.dispatchEvent(new CustomEvent(event, { detail }));14export { ev };15const ev = (event, detail) => window.dispatchEvent(new CustomEvent(event, { detail }));16export { ev };17import { ev } from 'storybook-root';18ev('my-event', { foo: 'bar' });19import { ev } from 'storybook-root';20ev('my-event', { foo: 'bar' });21const ev = (event, detail) => window.dispatchEvent(new CustomEvent(event, { detail }));22export { ev };23const ev = (event, detail) => window.dispatchEvent(new CustomEvent(event, { detail }));24export { ev };25import { ev } from 'storybook-root';26ev('my-event', { foo: 'bar' });27import { ev } from 'storybook-root';28ev('my-event', { foo: 'bar' });29const ev = (event, detail) => window.dispatchEvent(new CustomEvent(event, { detail }));30export { ev };31const ev = (event, detail) => window.dispatchEvent

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configure } from '@storybook/react';2import { ev } from '../test.js';3configure(() => {4 const req = require.context('../src', true, /\.stories\.js$/);5 req.keys().forEach(filename => req(filename));6}, module);7import { addDecorator } from '@storybook/react';8import { ev } from '../test.js';9addDecorator(storyFn => {10 ev('storybook-root', storyFn());11});12module.exports = (baseConfig, env, config) => {13 config.module.rules.push({14 loader: require.resolve('babel-loader'),15 options: {16 },17 });18 return config;19};

Full Screen

Using AI Code Generation

copy

Full Screen

1import { storiesOf } from "@storybook/react";2import { ev } from "storybook-root";3storiesOf("test", module).add("test", () => {4 ev("test", "test");5 return <div>test</div>;6});7import { configure } from "@storybook/react";8import { on } from "storybook-root";9on("test", (name, data) => {10 console.log(name, data);11});12configure(require.context("../src", true, /\.stories\.js$/), module);13import { on } from "storybook-root";14on("test", (name, data) => {15 console.log(name, data);16});17import React from "react";18import { storiesOf } from "@storybook/react";19import { ev } from "storybook-root";20storiesOf("test", module).add("test", () => {21 ev("test", "test");22 return <div>test</div>;23});24import React from "react";25import { storiesOf } from "@storybook/react";26import { on } from "storybook-root";27on("test", (name, data) => {28 console.log(name, data);29});30storiesOf("test2", module).add("test2", () => {31 return <div>test2</div>;32});33import React from "react";34import { storiesOf } from "@storybook/react";35import { on } from "storybook-root";36on("test", (name, data) => {37 console.log(name, data);38});39storiesOf("test3", module).add("test3", () => {40 return <div>test3</div>;41});42import React from "react";43import { storiesOf } from "@storybook/react";44import { on } from "storybook-root";45on("test", (name, data) => {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { addDecorator } from '@storybook/react';2import { withRoot } from 'storybook-root';3addDecorator(withRoot);4import { addDecorator } from '@storybook/react';5import { withRoot } from 'storybook-root';6addDecorator(withRoot);7import { addDecorator } from '@storybook/react';8import { withRoot } from 'storybook-root';9addDecorator(withRoot);10import { addDecorator } from '@storybook/react';11import { withRoot } from 'storybook-root';12addDecorator(withRoot);13import { addDecorator } from '@storybook/react';14import { withRoot } from 'storybook-root';15addDecorator(withRoot);16import { addDecorator } from '@storybook/react';17import { withRoot } from 'storybook-root';18addDecorator(withRoot);19import { addDecorator } from '@storybook/react';20import { withRoot } from 'storybook-root';21addDecorator(withRoot);22import { addDecorator } from '@storybook/react';23import { withRoot } from 'storybook-root';24addDecorator(withRoot);25import { addDecorator } from '@storybook/react';26import { withRoot } from 'storybook-root';27addDecorator(withRoot);

Full Screen

Using AI Code Generation

copy

Full Screen

1const root = document.getElementById('storybook-preview-iframe').contentWindow.document.getElementById('root');2root.ev('click', 'button');3root.ev('click', 'button', {text: 'Click Me'});4const root = document.getElementById('storybook-preview-iframe').contentWindow.document.getElementById('root');5root.ev('click', 'button');6root.ev('click', 'button', {text: 'Click Me'});7const root = document.getElementById('storybook-preview-iframe').contentWindow.document.getElementById('root');8root.ev('click', 'button');9root.ev('click', 'button', {text: 'Click Me'});10const root = document.getElementById('storybook-preview-iframe').contentWindow.document.getElementById('root');11root.ev('click', 'button');12root.ev('click', 'button', {text: 'Click Me'});13const root = document.getElementById('storybook-preview-iframe').contentWindow.document.getElementById('root');14root.ev('click', 'button');15root.ev('click', 'button', {text: 'Click Me'});16const root = document.getElementById('storybook-preview-iframe').contentWindow.document.getElementById('root');17root.ev('click', 'button');18root.ev('click', 'button', {text: 'Click Me'});19const root = document.getElementById('storybook-preview-iframe').contentWindow.document.getElementById('root');20root.ev('click', 'button');21root.ev('click', 'button', {text: 'Click Me'});22const root = document.getElementById('storybook-preview-iframe').contentWindow.document.getElementById('root');23root.ev('click', 'button');24root.ev('click', 'button', {text: 'Click Me'});25const root = document.getElementById('storybook-preview-iframe').contentWindow.document.getElementById('root');26root.ev('click', 'button');27root.ev('click', 'button', {text: 'Click Me'});

Full Screen

Using AI Code Generation

copy

Full Screen

1const ev = require('storybook-root').ev;2const {expect} = require('chai');3const {assert} = require('chai');4const {should} = require('chai');5const {spy} = require('sinon');6const {stub} = require('sinon');7describe('test', function() {8 it('test', function() {9 let spy = sinon.spy();10 let stub = sinon.stub();11 let mock = sinon.mock();12 let expect = chai.expect;13 let assert = chai.assert;14 let should = chai.should();15 let ev = storybook-root.ev;16 });17});18{19 "scripts": {20 },21 "devDependencies": {22 }23}24module.exports = {25 ev: require('storybook-root'),26 spy: require('sinon').spy,27 stub: require('sinon').stub,28 mock: require('sinon').mock,29 expect: require('chai').expect,30 assert: require('chai').assert,31 should: require('chai').should,32};33import { configure } from '@storybook/react';34import { setOptions } from '@storybook/addon-options';35setOptions({

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ev } from 'storybook-root';2ev('my-event', {data: 'my-data'});3import { addEventListener } from 'storybook-root';4addEventListener('my-event', (data) => {5 console.log(data);6});7import { addEventListener } from 'storybook-root';8const eventName = 'my-event';9addEventListener(eventName, (data) => {10 console.log(data);11});12import { addEventListener } from 'storybook-root';13const eventName = 'my-event';14addEventListener(eventName, (data) => {15 console.log(data);16});17import { addEventListener } from 'storybook-root';18const eventName = 'my-event';19addEventListener(eventName, (data) => {20 console.log(data);21});22import { addEventListener } from 'storybook-root';23const eventName = 'my-event';24addEventListener(eventName, (data) => {25 console.log(data);26});27import { addEventListener } from 'storybook-root';28const eventName = 'my-event';29addEventListener(eventName, (data) => {30 console.log(data);31});32import { addEventListener } from 'storybook-root';33const eventName = 'my-event';34addEventListener(eventName, (data) => {35 console.log(data);36});37import { addEventListener } from 'storybook-root';38const eventName = 'my-event';39addEventListener(eventName, (data) => {40 console.log(data);41});42import { addEventListener } from 'storybook-root';43const eventName = 'my-event';44addEventListener(eventName, (data) => {45 console.log(data);46});

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 storybook-root 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