Best JavaScript code snippet using wpt
battery-interface.js
Source:battery-interface.js
...7 * };8 *9 */10 test(function() {11 assert_idl_attribute(navigator, 'getBattery', 'navigator must have getBattery attribute');12 }, 'getBattery is present on navigator');13 navigator.getBattery().then(function (battery) {14 /**15 *16 * interface BatteryManager : EventTarget {17 * readonly attribute boolean charging;18 * readonly attribute unrestricted double chargingTime;19 * readonly attribute unrestricted double dischargingTime;20 * readonly attribute double level;21 * attribute EventHandler onchargingchange;22 * attribute EventHandler onchargingtimechange;23 * attribute EventHandler ondischargingtimechange;24 * attribute EventHandler onlevelchange;25 * };26 *27 */28 // interface BatteryManager : EventTarget {29 test(function() {30 assert_own_property(window, 'BatteryManager');31 }, 'window has an own property BatteryManager');32 test(function() {33 assert_true(battery instanceof EventTarget);34 }, 'battery inherits from EventTarget');35 // readonly attribute boolean charging;36 test(function() {37 assert_idl_attribute(battery, 'charging', 'battery must have charging attribute');38 }, 'charging attribute exists');39 test(function() {40 assert_readonly(battery, 'charging', 'charging must be readonly')41 }, 'charging attribute is readonly');42 // readonly attribute unrestricted double chargingTime;43 test(function() {44 assert_idl_attribute(battery, 'chargingTime', 'battery must have chargingTime attribute');45 }, 'chargingTime attribute exists');46 test(function() {47 assert_readonly(battery, 'chargingTime', 'chargingTime must be readonly')48 }, 'chargingTime attribute is readonly');49 // readonly attribute unrestricted double dischargingTime;50 test(function() {51 assert_idl_attribute(battery, 'dischargingTime', 'battery must have dischargingTime attribute');52 }, 'dischargingTime attribute exists');53 test(function() {54 assert_readonly(battery, 'dischargingTime', 'dischargingTime must be readonly')55 }, 'dischargingTime attribute is readonly');56 // readonly attribute double level;57 test(function() {58 assert_idl_attribute(battery, 'level', 'battery must have level attribute');59 }, 'level attribute exists');60 test(function() {61 assert_readonly(battery, 'level', 'level must be readonly')62 }, 'level attribute is readonly');63 // attribute EventHandler onchargingchange;64 test(function() {65 assert_idl_attribute(battery, 'onchargingchange', 'battery must have onchargingchange attribute');66 }, 'onchargingchange attribute exists');67 test(function() {68 assert_equals(battery.onchargingchange, null, 'onchargingchange must be null')69 }, 'onchargingchange is null');70 test(function() {71 var desc = 'onchargingchange did not accept callable object',72 func = function() {},73 desc = 'Expected to find onchargingchange attribute on battery object';74 assert_idl_attribute(battery, 'onchargingchange', desc);75 window.onchargingchange = func;76 assert_equals(window.onchargingchange, func, desc);77 }, 'onchargingchange is set to function');78 test(function() {79 var desc = 'onchargingchange did not treat noncallable as null';80 battery.onchargingchange = function() {};81 battery.onchargingchange = {};82 assert_equals(battery.onchargingchange, null, desc);83 }, 'onchargingchange: treat object as null');84 test(function() {85 var desc = 'onchargingchange did not treat noncallable as null';86 battery.onchargingchange = function() {};87 battery.onchargingchange = {88 call: 'test'89 };90 assert_equals(battery.onchargingchange, null, desc);91 }, 'onchargingchange: treat object with non-callable call property as null');92 test(function() {93 var desc = 'onchargingchange did not treat noncallable (string) as null';94 battery.onchargingchange = function() {};95 battery.onchargingchange = 'string';96 assert_equals(battery.onchargingchange, null, desc);97 }, 'onchargingchange: treat string as null');98 test(function() {99 var desc = 'onchargingchange did not treat noncallable (number) as null';100 battery.onchargingchange = function() {};101 battery.onchargingchange = 123;102 assert_equals(battery.onchargingchange, null, desc);103 }, 'onchargingchange: treat number as null');104 test(function() {105 var desc = 'onchargingchange did not treat noncallable (undefined) as null';106 battery.onchargingchange = function() {};107 battery.onchargingchange = undefined;108 assert_equals(battery.onchargingchange, null, desc);109 }, 'onchargingchange: treat undefined as null');110 test(function() {111 var desc = 'onchargingchange did not treat noncallable (array) as null';112 battery.onchargingchange = function() {};113 battery.onchargingchange = [];114 assert_equals(battery.onchargingchange, null, desc);115 }, 'onchargingchange: treat array as null');116 // attribute EventHandler onchargingtimechange;117 test(function() {118 assert_idl_attribute(battery, 'onchargingtimechange', 'battery must have onchargingtimechange attribute');119 }, 'onchargingtimechange attribute exists');120 test(function() {121 assert_equals(battery.onchargingtimechange, null, 'onchargingtimechange must be null')122 }, 'onchargingtimechange is null');123 test(function() {124 var desc = 'onchargingtimechange did not accept callable object',125 func = function() {},126 desc = 'Expected to find onchargingtimechange attribute on battery object';127 assert_idl_attribute(battery, 'onchargingtimechange', desc);128 window.onchargingtimechange = func;129 assert_equals(window.onchargingtimechange, func, desc);130 }, 'onchargingtimechange is set to function');131 test(function() {132 var desc = 'onchargingtimechange did not treat noncallable as null';133 battery.onchargingtimechange = function() {};134 battery.onchargingtimechange = {};135 assert_equals(battery.onchargingtimechange, null, desc);136 }, 'onchargingtimechange: treat object as null');137 test(function() {138 var desc = 'onchargingtimechange did not treat noncallable as null';139 battery.onchargingtimechange = function() {};140 battery.onchargingtimechange = {141 call: 'test'142 };143 assert_equals(battery.onchargingtimechange, null, desc);144 }, 'onchargingtimechange: treat object with non-callable call property as null');145 test(function() {146 var desc = 'onchargingtimechange did not treat noncallable (string) as null';147 battery.onchargingtimechange = function() {};148 battery.onchargingtimechange = 'string';149 assert_equals(battery.onchargingtimechange, null, desc);150 }, 'onchargingtimechange: treat string as null');151 test(function() {152 var desc = 'onchargingtimechange did not treat noncallable (number) as null';153 battery.onchargingtimechange = function() {};154 battery.onchargingtimechange = 123;155 assert_equals(battery.onchargingtimechange, null, desc);156 }, 'onchargingtimechange: treat number as null');157 test(function() {158 var desc = 'onchargingtimechange did not treat noncallable (undefined) as null';159 battery.onchargingtimechange = function() {};160 battery.onchargingtimechange = undefined;161 assert_equals(battery.onchargingtimechange, null, desc);162 }, 'onchargingtimechange: treat undefined as null');163 test(function() {164 var desc = 'onchargingtimechange did not treat noncallable (array) as null';165 battery.onchargingtimechange = function() {};166 battery.onchargingtimechange = [];167 assert_equals(battery.onchargingtimechange, null, desc);168 }, 'onchargingtimechange: treat array as null');169 // attribute EventHandler ondischargingtimechange;170 test(function() {171 assert_idl_attribute(battery, 'ondischargingtimechange', 'battery must have ondischargingtimechange attribute');172 }, 'ondischargingtimechange attribute exists');173 test(function() {174 assert_equals(battery.ondischargingtimechange, null, 'ondischargingtimechange must be null')175 }, 'ondischargingtimechange is null');176 test(function() {177 var desc = 'ondischargingtimechange did not accept callable object',178 func = function() {},179 desc = 'Expected to find ondischargingtimechange attribute on battery object';180 assert_idl_attribute(battery, 'ondischargingtimechange', desc);181 window.ondischargingtimechange = func;182 assert_equals(window.ondischargingtimechange, func, desc);183 }, 'ondischargingtimechange is set to function');184 test(function() {185 var desc = 'ondischargingtimechange did not treat noncallable as null';186 battery.ondischargingtimechange = function() {};187 battery.ondischargingtimechange = {};188 assert_equals(battery.ondischargingtimechange, null, desc);189 }, 'ondischargingtimechange: treat object as null');190 test(function() {191 var desc = 'ondischargingtimechange did not treat noncallable as null';192 battery.ondischargingtimechange = function() {};193 battery.ondischargingtimechange = {194 call: 'test'195 };196 assert_equals(battery.ondischargingtimechange, null, desc);197 }, 'ondischargingtimechange: treat object with non-callable call property as null');198 test(function() {199 var desc = 'ondischargingtimechange did not treat noncallable (string) as null';200 battery.ondischargingtimechange = function() {};201 battery.ondischargingtimechange = 'string';202 assert_equals(battery.ondischargingtimechange, null, desc);203 }, 'ondischargingtimechange: treat string as null');204 test(function() {205 var desc = 'ondischargingtimechange did not treat noncallable (number) as null';206 battery.ondischargingtimechange = function() {};207 battery.ondischargingtimechange = 123;208 assert_equals(battery.ondischargingtimechange, null, desc);209 }, 'ondischargingtimechange: treat number as null');210 test(function() {211 var desc = 'ondischargingtimechange did not treat noncallable (undefined) as null';212 battery.ondischargingtimechange = function() {};213 battery.ondischargingtimechange = undefined;214 assert_equals(battery.ondischargingtimechange, null, desc);215 }, 'ondischargingtimechange: treat undefined as null');216 test(function() {217 var desc = 'ondischargingtimechange did not treat noncallable (array) as null';218 battery.ondischargingtimechange = function() {};219 battery.ondischargingtimechange = [];220 assert_equals(battery.ondischargingtimechange, null, desc);221 }, 'ondischargingtimechange: treat array as null');222 // attribute EventHandler onlevelchange;223 test(function() {224 assert_idl_attribute(battery, 'onlevelchange', 'battery must have onlevelchange attribute');225 }, 'onlevelchange attribute exists');226 test(function() {227 assert_equals(battery.onlevelchange, null, 'onlevelchange must be null')228 }, 'onlevelchange is null');229 test(function() {230 var desc = 'onlevelchange did not accept callable object',231 func = function() {},232 desc = 'Expected to find onlevelchange attribute on battery object';233 assert_idl_attribute(battery, 'onlevelchange', desc);234 window.onlevelchange = func;235 assert_equals(window.onlevelchange, func, desc);236 }, 'onlevelchange is set to function');237 test(function() {238 var desc = 'onlevelchange did not treat noncallable as null';239 battery.onlevelchange = function() {};240 battery.onlevelchange = {};241 assert_equals(battery.onlevelchange, null, desc);242 }, 'onlevelchange: treat object as null');243 test(function() {244 var desc = 'onlevelchange did not treat noncallable as null';245 battery.onlevelchange = function() {};246 battery.onlevelchange = {247 call: 'test'...
Using AI Code Generation
1import { assert_idl_attribute } from "resources/testharness.js";2import { assert_unreached } from "resources/testharness.js";3import { assert_array_equals } from "resources/testharness.js";4import { assert_throws } from "resources/testharness.js";5import { assert_equals } from "resources/testharness.js";6import { assert_true } from "resources/testharness.js";7import { assert_false } from "resources/testharness.js";8import { assert_class_string } from "resources/testharness.js";9import { assert_own_property } from "resources/testharness.js";10import { assert_inherits } from "resources/testharness.js";11import { assert_not_equals } from "resources/testharness.js";12import { assert_object_equals } from "resources/testharness.js";13import { assert_approx_equals } from "resources/testharness.js";14import { assert_regexp_match } from "resources/testharness.js";15import { assert_not_regexp_match } from "resources/testharness.js";16import { assert_array_approx_equals } from "resources/testharness.js";17import { assert_array_not_approx_equals } from "resources/testharness.js";18import { assert_array_not_equals } from "resources/testharness.js";19import { assert_less_than } from "resources/testharness.js";
Using AI Code Generation
1assert_idl_attribute(object, "attributeName", "message");2assert_idl_attribute(object, "attributeName");3assert_idl_attribute(object, "attributeName", "message", "description");4assert_idl_attributes(object, ["attributeName1", "attributeName2"], "message");5assert_idl_attributes(object, ["attributeName1", "attributeName2"]);6assert_idl_attributes(object, ["attributeName1", "attributeName2"], "message", "description");7assert_idl_method(object, "methodName", "message");8assert_idl_method(object, "methodName");9assert_idl_method(object, "methodName", "message", "description");10assert_idl_methods(object, ["methodName1", "methodName2"], "message");11assert_idl_methods(object, ["methodName1", "methodName2"]);12assert_idl_methods(object, ["methodName1", "methodName2"], "message", "description");13assert_idl_const(object, "constName", "message");14assert_idl_const(object, "constName");15assert_idl_const(object, "constName", "message", "description");16assert_idl_consts(object, ["constName1", "constName2"], "message");17assert_idl_consts(object, ["constName1", "constName2"]);18assert_idl_consts(object, ["constName1", "constName2"], "message", "description");19assert_idl_attribute_equals(object, "attributeName", expectedValue, "message");20assert_idl_attribute_equals(object, "attributeName", expectedValue);21assert_idl_attribute_equals(object, "attributeName", expectedValue, "message", "description");22assert_idl_attribute_not_equals(object, "attributeName", expectedValue, "message");23assert_idl_attribute_not_equals(object, "attributeName", expectedValue);24assert_idl_attribute_not_equals(object, "attributeName", expectedValue, "message", "description");
Using AI Code Generation
1function test() {2 var iframe = document.createElement("iframe");3 iframe.onload = function() {4 assert_idl_attribute(iframe.contentWindow, "navigator", "navigator attribute present");5 assert_idl_attribute(iframe.contentWindow, "document", "document attribute present");6 assert_idl_attribute(iframe.contentWindow, "location", "location attribute present");7 assert_idl_attribute(iframe.contentWindow, "history", "history attribute present");8 assert_idl_attribute(iframe.contentWindow, "top", "top attribute present");9 assert_idl_attribute(iframe.contentWindow, "parent", "parent attribute present");10 assert_idl_attribute(iframe.contentWindow, "opener", "opener attribute present");11 assert_idl_attribute(iframe.contentWindow, "frameElement", "frameElement attribute present");12 assert_idl_attribute(iframe.contentWindow, "frames", "frames attribute present");13 assert_idl_attribute(iframe.contentWindow, "self", "self attribute present");14 assert_idl_attribute(iframe.contentWindow, "window", "window attribute present");15 assert_idl_attribute(iframe.contentWindow, "close", "close attribute present");16 assert_idl_attribute(iframe.contentWindow, "closed", "closed attribute present");17 assert_idl_attribute(iframe.contentWindow, "stop", "stop attribute present");18 assert_idl_attribute(iframe.contentWindow, "focus", "focus attribute present");19 assert_idl_attribute(iframe.contentWindow, "blur", "blur attribute present");20 assert_idl_attribute(iframe.contentWindow, "postMessage", "postMessage attribute present");21 assert_idl_attribute(iframe.contentWindow, "print", "print attribute present");22 assert_idl_attribute(iframe.contentWindow, "alert", "alert attribute present");23 assert_idl_attribute(iframe.contentWindow, "confirm", "confirm attribute present");24 assert_idl_attribute(iframe.contentWindow, "prompt", "prompt attribute present");25 assert_idl_attribute(iframe.contentWindow, "moveTo", "moveTo attribute present");26 assert_idl_attribute(iframe.contentWindow, "moveBy", "moveBy attribute present");27 assert_idl_attribute(iframe.contentWindow, "resizeTo", "resizeTo attribute present");28 assert_idl_attribute(iframe.contentWindow, "resizeBy", "resizeBy attribute present");
Using AI Code Generation
1const assert_idl_attribute = idlUtils.assert_idl_attribute;2const assert_false = idlUtils.assert_false;3const assert_true = idlUtils.assert_true;4const assert_equals = idlUtils.assert_equals;5const assert_throws = idlUtils.assert_throws;6const assert_array_equals = idlUtils.assert_array_equals;7const assert_in_array = idlUtils.assert_in_array;8const assert_own_property = idlUtils.assert_own_property;9const assert_class_string = idlUtils.assert_class_string;10const assert_regexp_match = idlUtils.assert_regexp_match;11const assert_unreached = idlUtils.assert_unreached;12const assert_readonly = idlUtils.assert_readonly;13const assert_not_readonly = idlUtils.assert_not_readonly;14const assert_throws_dom = idlUtils.assert_throws_dom;15const assert_name = idlUtils.assert_name;16const assert_type = idlUtils.assert_type;17const assert_member = idlUtils.assert_member;18const assert_enum = idlUtils.assert_enum;19const assert_implements = idlUtils.assert_implements;20const assert_true = idlUtils.assert_true;21const assert_false = idlUtils.assert_false;22const assert_equals = idlUtils.assert_equals;23const assert_array_equals = idlUtils.assert_array_equals;24const assert_own_property = idlUtils.assert_own_property;25const assert_in_array = idlUtils.assert_in_array;26const assert_class_string = idlUtils.assert_class_string;27const assert_regexp_match = idlUtils.assert_regexp_match;28const assert_throws = idlUtils.assert_throws;29const assert_throws_dom = idlUtils.assert_throws_dom;30const assert_unreached = idlUtils.assert_unreached;31const assert_readonly = idlUtils.assert_readonly;32const assert_not_readonly = idlUtils.assert_not_readonly;33const assert_name = idlUtils.assert_name;34const assert_type = idlUtils.assert_type;35const assert_member = idlUtils.assert_member;36const assert_enum = idlUtils.assert_enum;37const assert_implements = idlUtils.assert_implements;38const assert_true = idlUtils.assert_true;39const assert_false = idlUtils.assert_false;40const assert_equals = idlUtils.assert_equals;41const assert_array_equals = idlUtils.assert_array_equals;
Using AI Code Generation
1test(() => {2 assert_idl_attribute(window, "openDatabase");3}, "window interface: openDatabase exists");4from __future__ import absolute_import5from __future__ import print_function6import os7import sys8import shutil9import subprocess10import random11import tempfile12import time13import re14import json15import argparse16import glob17import traceback18import multiprocessing19import logging20import logging.config21import six22from six.moves import queue23from six.moves import range24from six.moves import urllib25from six.moves.urllib.parse import urlparse26from six.moves.urllib.parse import urlunparse27from six.moves.urllib.parse import urljoin28from six.moves.urllib.parse import urlsplit29from six.moves.urllib.parse import urlunsplit30from six.moves.urllib.parse import quote31from six.moves.urllib.parse import unquote32from six.moves.urllib.parse import quote_plus33from six.moves.urllib.parse import unquote_plus34from six.moves.urllib.parse import urlencode35from six.moves.urllib.parse import parse_qsl36from six.moves.urllib.parse import parse_qs37from six.moves.urllib.parse import parse_qsl38from six.moves.urllib.parse import unquote_to_bytes39from six.moves.urllib.request import pathname2url40from six.moves.urllib.request import url2pathname41from six.moves.urllib.request import urlopen42from six.moves.urllib.request import Request43from six.moves.urllib.request import HTTPError44from six.moves.urllib.request import URLError45from six.moves.urllib.request import urlretrieve46from six.moves.urllib.request import urlcleanup47from six.moves.urllib.request import FTPHandler48from six.moves.urllib.request import build_opener49from six.moves.urllib.request import install_opener50from six.moves.urllib.request import ProxyHandler51from six.moves.urllib.request import ProxyBasicAuthHandler52from six.moves.urllib.request import ProxyDigestAuthHandler53from six.moves.urllib.request import HTTPDefaultErrorHandler
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!!