Best JavaScript code snippet using wpt
apitest.js
Source:apitest.js
1/* Copyright (c) 2014, CableLabs, Inc.2 * All rights reserved.3 *4 * Redistribution and use in source and binary forms, with or without5 * modification, are permitted provided that the following conditions are met:6 *7 * 1. Redistributions of source code must retain the above copyright notice,8 * this list of conditions and the following disclaimer.9 *10 * 2. Redistributions in binary form must reproduce the above copyright notice,11 * this list of conditions and the following disclaimer in the documentation12 * and/or other materials provided with the distribution.13 *14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE24 * POSSIBILITY OF SUCH DAMAGE.25 */26apitest = function() {27 var video_element = $("#test_video").get()[0];28 var update_api_status = function($item, is_present) {29 var present = "glyphicon glyphicon-ok green";30 var missing = "glyphicon glyphicon-remove red";31 $item.addClass((is_present) ? present : missing);32 };33 // MediaKeys (check vendor-specific prefixes too)34 var stdmediakeys_present = ("MediaKeys" in window);35 var msmediakeys_present = ("MSMediaKeys" in window);36 var webkitmediakeys_present = ("WebKitMediaKeys" in window);37 var mediakeys_present = (stdmediakeys_present || msmediakeys_present || webkitmediakeys_present);38 var mediakeys;39 if (stdmediakeys_present) {40 update_api_status($("#api_mediakeys"), true);41 mediakeys = "MediaKeys";42 } else if (msmediakeys_present) {43 update_api_status($("#api_mediakeys"), true);44 $("#api_mediakeys_comment").text("Prefixed MSMediaKeys only")45 mediakeys = "MSMediaKeys";46 } else if (webkitmediakeys_present) {47 update_api_status($("#api_mediakeys"), true);48 $("#api_mediakeys_comment").text("Prefixed WebKitMediaKeys only")49 mediakeys = "WebKitMediaKeys";50 } else {51 update_api_status($("#api_mediakeys"), false);52 }53 var istypesupp_present = false;54 if (mediakeys_present) {55 istypesupp_present = ("isTypeSupported" in window[mediakeys]);56 update_api_status($("#api_istypesupp"), istypesupp_present);57 }58 var $api_mediakeys_attr = $("#api_mediakeys_attr");59 if ("mediaKeys" in video_element) {60 update_api_status($api_mediakeys_attr, true);61 } else if ("mediaKeys" in window) {62 update_api_status($api_mediakeys_attr, true);63 $("#api_mediakeys_attr_comment").text("Attribute found in Window, not in HTMLVideoElement");64 } else {65 update_api_status($api_mediakeys_attr, false);66 }67 // Key Systems68 var key_systems = [69 {70 name: "W3C Clear Key",71 keystring: "org.w3.clearkey",72 dom_id: "cdm_clearkey"73 },74 {75 name: "Microsoft PlayReady",76 keystring: "com.microsoft.playready",77 dom_id: "cdm_playready"78 },79 {80 name: "Google Widevine",81 keystring: "com.widevine.alpha",82 dom_id: "cdm_widevine"83 }84 ];85 var supported_system = null;86 for (i = 0; i < key_systems.length; i++) {87 $("#cdm_table").append("<tr><td>" + key_systems[i].name + "</td>" +88 "<td><pre>" + key_systems[i].keystring + "</pre></td>" +89 "<td><span id=\"" + key_systems[i].dom_id + "\">" + "</span></td></tr>");90 if (mediakeys_present && istypesupp_present) {91 if (window[mediakeys].isTypeSupported(key_systems[i].keystring)) {92 update_api_status($("#" + key_systems[i].dom_id), true);93 supported_system = key_systems[i].keystring;94 } else {95 update_api_status($("#" + key_systems[i].dom_id), false);96 }97 } else {98 update_api_status($("#" + key_systems[i].dom_id), false);99 }100 }101 // MediaKeys102 var mk;103 if (supported_system != null) {104 try {105 mk = new window[mediakeys](supported_system);106 update_api_status($("#api_mediakeys_construct"), true);107 } catch (ex) {108 if (ex instanceof ReferenceError) {109 update_api_status($("#api_mediakeys_construct"), false);110 $("#api_mediakeys_construct_comment").text("MediaKeys not present");111 } else if (ex instanceof DOMException) {112 update_api_status($("#api_mediakeys_construct"), true);113 $("#api_mediakeys_construct_comment").text("Error = " + ex.name + ". Message = " + ex.message);114 }115 }116 }117 var $api_setmediakeys = $("#api_setmediakeys");118 if ("setMediaKeys" in video_element) {119 update_api_status($api_setmediakeys, true);120 if (mk) {121 video_element["setMediaKeys"](mk);122 }123 } else if ("msSetMediaKeys" in video_element) {124 update_api_status($api_setmediakeys, true);125 $("#api_setmediakeys_comment").text("Prefixed msSetMediaKeys only");126 if (mk) {127 video_element["msSetMediaKeys"](mk);128 }129 } else if ("WebKitSetMediaKeys" in video_element) {130 update_api_status($api_setmediakeys, true);131 $("#api_setmediakeys_comment").text("Prefixed WebKitSetMediaKeys only");132 if (mk) {133 video_element["WebKitSetMediaKeys"](mk);134 }135 } else if ("setMediaKeys" in window) {136 update_api_status($api_setmediakeys, true);137 $("#api_setmediakeys_comment").text("Function found in Window, not in HTMLVideoElement");138 if (mk) {139 window["setMediaKeys"](mk);140 }141 } else if ("msSetMediaKeys" in window) {142 update_api_status($api_setmediakeys, true);143 $("#api_setmediakeys_comment").text("Prefixed msSetMediaKeys function found in Window, not in HTMLVideoElement");144 if (mk) {145 window["msSetMediaKeys"](mk);146 }147 } else if ("WebKitSetMediaKeys" in window) {148 update_api_status($api_setmediakeys, true);149 $("#api_setmediakeys_comment").text("Prefixed WebSetMediaKeys function found in Window, not in HTMLVideoElement");150 if (mk) {151 window["WebKitSetMediaKeys"](mk);152 }153 } else {154 update_api_status($api_setmediakeys, false);155 }...
patchedmediakeys_nop.js
Source:patchedmediakeys_nop.js
1/**2 * @license3 * Copyright 2016 Google Inc.4 *5 * Licensed under the Apache License, Version 2.0 (the "License");6 * you may not use this file except in compliance with the License.7 * You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17goog.provide('shaka.polyfill.PatchedMediaKeysNop');18goog.require('goog.asserts');19goog.require('shaka.log');20/**21 * Install a polyfill to stub out {@link http://goo.gl/blgtZZ EME draft22 * 12 March 2015} on browsers without EME. All methods will fail.23 */24shaka.polyfill.PatchedMediaKeysNop.install = function() {25 shaka.log.debug('PatchedMediaKeysNop.install');26 // Alias.27 var PatchedMediaKeysNop = shaka.polyfill.PatchedMediaKeysNop;28 // Install patches.29 navigator.requestMediaKeySystemAccess =30 PatchedMediaKeysNop.requestMediaKeySystemAccess;31 // Delete mediaKeys to work around strict mode compatibility issues.32 delete HTMLMediaElement.prototype['mediaKeys'];33 // Work around read-only declaration for mediaKeys by using a string.34 HTMLMediaElement.prototype['mediaKeys'] = null;35 HTMLMediaElement.prototype.setMediaKeys = PatchedMediaKeysNop.setMediaKeys;36 // These are not usable, but allow Player.isBrowserSupported to pass.37 window.MediaKeys = PatchedMediaKeysNop.MediaKeys;38 window.MediaKeySystemAccess = PatchedMediaKeysNop.MediaKeySystemAccess;39};40/**41 * An implementation of navigator.requestMediaKeySystemAccess.42 * Retrieve a MediaKeySystemAccess object.43 *44 * @this {!Navigator}45 * @param {string} keySystem46 * @param {!Array.<!MediaKeySystemConfiguration>} supportedConfigurations47 * @return {!Promise.<!MediaKeySystemAccess>}48 */49shaka.polyfill.PatchedMediaKeysNop.requestMediaKeySystemAccess =50 function(keySystem, supportedConfigurations) {51 shaka.log.debug('PatchedMediaKeysNop.requestMediaKeySystemAccess');52 goog.asserts.assert(this == navigator,53 'bad "this" for requestMediaKeySystemAccess');54 return Promise.reject(new Error(55 'The key system specified is not supported.'));56};57/**58 * An implementation of HTMLMediaElement.prototype.setMediaKeys.59 * Attach a MediaKeys object to the media element.60 *61 * @this {!HTMLMediaElement}62 * @param {MediaKeys} mediaKeys63 * @return {!Promise}64 */65shaka.polyfill.PatchedMediaKeysNop.setMediaKeys = function(mediaKeys) {66 shaka.log.debug('PatchedMediaKeysNop.setMediaKeys');67 goog.asserts.assert(this instanceof HTMLMediaElement,68 'bad "this" for setMediaKeys');69 if (mediaKeys == null) {70 return Promise.resolve();71 }72 return Promise.reject(new Error('MediaKeys not supported.'));73};74/**75 * An unusable constructor for MediaKeys.76 * @constructor77 * @struct78 * @implements {MediaKeys}79 */80shaka.polyfill.PatchedMediaKeysNop.MediaKeys = function() {81 throw new TypeError('Illegal constructor.');82};83/** @override */84shaka.polyfill.PatchedMediaKeysNop.MediaKeys.prototype.createSession =85 function() {};86/** @override */87shaka.polyfill.PatchedMediaKeysNop.MediaKeys.prototype.setServerCertificate =88 function() {};89/**90 * An unusable constructor for MediaKeySystemAccess.91 * @constructor92 * @struct93 * @implements {MediaKeySystemAccess}94 */95shaka.polyfill.PatchedMediaKeysNop.MediaKeySystemAccess = function() {96 throw new TypeError('Illegal constructor.');97};98/** @override */99shaka.polyfill.PatchedMediaKeysNop.MediaKeySystemAccess.prototype.100 getConfiguration = function() {};101/** @override */102shaka.polyfill.PatchedMediaKeysNop.MediaKeySystemAccess.prototype.103 createMediaKeys = function() {};104/** @override */105shaka.polyfill.PatchedMediaKeysNop.MediaKeySystemAccess.prototype....
Using AI Code Generation
1function runTest(config,qualifier) {2 var testname = testnamePrefix(qualifier, config.keysystem)3 + /video\/([^;]*)/.exec( config.videoType )[ 1 ]4 + ', check MediaKeys';5 var configuration = { audioCapabilities: [ { contentType: config.audioType } ],6 videoCapabilities: [ { contentType: config.videoType } ],7 sessionTypes: [ 'temporary' ] };8 async_test( function( test ) {9 _mediaSource;10 function onFailure(error) {11 forceTestFailureFromPromise(test, error);12 }13 function onMessage(event) {14 assert_unreached('Unexpected message event');15 }16 function onEncrypted(event) {17 assert_equals(event.target, _video);18 assert_true(event instanceof window.MediaEncryptedEvent);19 assert_equals(event.type, 'encrypted');20 assert_true(_mediaKeys instanceof window.MediaKeys);21 assert_equals(typeof _mediaKeys.createSession, 'function');22 _mediaKeySession = _mediaKeys.createSession('temporary');23 assert_true(_mediaKeySession instanceof window.MediaKeySession);24 _mediaKeySession.addEventListener('message', onMessage);25 _mediaKeySession.generateRequest( event.initDataType || event.initData.constructor.name,26 .then( function( success ) {27 _mediaKeySession.removeEventListener('message', onMessage);28 _video.setMediaKeys(null);29 _video.setMediaKeys(_mediaKeys);30 _mediaKeySession.generateRequest( event.initDataType || event.initData.constructor.name,31 .then( function( success ) {32 assert_unreached('Unexpected success from second generateRequest call');33 }).catch(function(error) {34 forceTestFailureFromPromise(test, error);35 });36 }).catch(function(error) {37 forceTestFailureFromPromise(test, error);38 });39 }40 function onSetMediaKeysSuccess() {41 assert_equals(_video.mediaKeys, _mediaKeys);42 _video.addEventListener('encrypted', onEncrypted);43 _mediaSource = new MediaSource();44 _video.src = URL.createObjectURL(_mediaSource);45 }
Using AI Code Generation
1var config = { initDataTypes: ['webm'], audioCapabilities: [{ contentType: 'audio/webm; codecs="vorbis"' }], videoCapabilities: [{ contentType: 'video/webm; codecs="vp8"' }] };2navigator.requestMediaKeySystemAccess('org.w3.clearkey', [config]).then(function(access) {3 return access.createMediaKeys();4}).then(function(mediaKeys) {5 return video.setMediaKeys(mediaKeys);6}).catch(function(error) {7 console.log(error.message);8});9var config = { initDataTypes: ['webm'], audioCapabilities: [{ contentType: 'audio/webm; codecs="vorbis"' }], videoCapabilities: [{ contentType: 'video/webm; codecs="vp8"' }] };10navigator.requestMediaKeySystemAccess('org.w3.clearkey', [config]).then(function(access) {11 return access.createMediaKeys();12}).then(function(mediaKeys) {13 return video.setMediaKeys(mediaKeys);14}).catch(function(error) {15 console.log(error.message);16});17var config = { initDataTypes: ['webm'], audioCapabilities: [{ contentType: 'audio/webm; codecs="vorbis"' }], videoCapabilities: [{ contentType: 'video/webm; codecs="vp8"' }] };18navigator.requestMediaKeySystemAccess('org.w3.clearkey', [config]).then(function(access) {19 return access.createMediaKeys();20}).then(function(mediaKeys) {21 return video.setMediaKeys(mediaKeys);22}).catch(function(error) {23 console.log(error.message);24});25var config = { initDataTypes: ['webm'], audioCapabilities: [{ contentType: 'audio/webm; codecs="vorbis"' }], videoCapabilities: [{ contentType: 'video/webm; codecs="vp8"' }] };26navigator.requestMediaKeySystemAccess('org.w3.clearkey', [config]).then(function(access) {27 return access.createMediaKeys();28}).then(function(mediaKeys) {29 return video.setMediaKeys(mediaKeys);30}).catch(function(error) {31 console.log(error.message);32});
Using AI Code Generation
1var wptRunner = new WptRunner();2wptRunner.setMediaKeys();3var wptRunner = new WptRunner();4wptRunner.setMediaKeys();5var wptRunner = new WptRunner();6wptRunner.setMediaKeys();7var wptRunner = new WptRunner();8wptRunner.setMediaKeys();9var wptRunner = new WptRunner();10wptRunner.setMediaKeys();11var wptRunner = new WptRunner();12wptRunner.setMediaKeys();13var wptRunner = new WptRunner();14wptRunner.setMediaKeys();15var wptRunner = new WptRunner();16wptRunner.setMediaKeys();17var wptRunner = new WptRunner();18wptRunner.setMediaKeys();19var wptRunner = new WptRunner();20wptRunner.setMediaKeys();21var wptRunner = new WptRunner();22wptRunner.setMediaKeys();23var wptRunner = new WptRunner();24wptRunner.setMediaKeys();25var wptRunner = new WptRunner();26wptRunner.setMediaKeys();27var wptRunner = new WptRunner();28wptRunner.setMediaKeys();29var wptRunner = new WptRunner();30wptRunner.setMediaKeys();
Using AI Code Generation
1var wptb = document.getElementById('wptb');2var mediaKeys = new MediaKeys();3wptb.setMediaKeys(mediaKeys);4wptb.addEventListener('encrypted', function(event) {5 var initData = event.initData;6 var keySystem = event.keySystem;7 var initDataType = event.initDataType;8 var session = mediaKeys.createSession(initDataType, initData);9 var xhr = new XMLHttpRequest();10 xhr.open('POST', licenseUrl, true);11 xhr.responseType = 'arraybuffer';12 xhr.onload = function() {13 session.update(xhr.response);14 };15 xhr.send(initData);16});17var wptb = document.getElementById('wptb');18var mediaKeys = new MediaKeys();19wptb.setMediaKeys(mediaKeys);20wptb.addEventListener('encrypted', function(event) {21 var initData = event.initData;22 var keySystem = event.keySystem;23 var initDataType = event.initDataType;24 var session = mediaKeys.createSession(initDataType, initData);25 var xhr = new XMLHttpRequest();26 xhr.responseType = 'arraybuffer';27 xhr.onload = function() {28 session.update(xhr.response);29 };30 xhr.send(JSON.stringify({31 }));32});
Using AI Code Generation
1var wptRunner = new WPTRunner();2wptRunner.setMediaKeys(mediaKeys);3wptRunner.setServer(server);4wptRunner.setPath(path);5wptRunner.setTestName(testName);6wptRunner.setOptions(options);7wptRunner.setCallback(callback);8wptRunner.run();9var WPTRunner = function() {10 this.setMediaKeys = function(mediaKeys) {11 this.mediaKeys = mediaKeys;12 };13 this.setServer = function(server) {14 this.server = server;15 };16 this.setPath = function(path) {17 this.path = path;18 };19 this.setTestName = function(testName) {20 this.testName = testName;21 };22 this.setOptions = function(options) {23 this.options = options;24 };25 this.setCallback = function(callback) {26 this.callback = callback;27 };28 this.run = function() {29 };30};31wptRunner.setMediaKeys(mediaKeys);32wptRunner.setServer(server);
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!!