Best JavaScript code snippet using playwright-internal
cartoRendererTest.js
Source:cartoRendererTest.js
1module("cartoRenderer");2test("TestCartoRenderer_Constructor", function() {3 expect(8);4 var canvas = document.createElement("canvas"),5 context = canvas.getContext("2d"),6 hitCanvas = document.createElement("canvas"),7 hitContext = canvas.getContext("2d"),8 options = {};9 var carto = new SuperMap.CartoRenderer(context, hitContext, options);10 equal(carto.CLASS_NAME, "SuperMap.CartoRenderer", "CartoRenderer_Constructor");11 ok(carto.context != null, "CartoRenderer_Constructor");12 ok(carto.hitContext != null, "CartoRenderer_Constructor");13 equal(carto.symbolizer, null, "CartoRenderer_Constructor");14 equal(carto.layer, null, "CartoRenderer_Constructor");15 equal( typeof carto.pointImagesInfo, "object", "CartoRenderer_Constructor");16 equal(carto.imagesBackup.length, 0, "CartoRenderer_Constructor");17 equal(carto.tempImage, null, "CartoRenderer_Constructor");18});19test("TestCartoRenderer_Destroy", function() {20 expect(4);21 var canvas = document.createElement("canvas"),22 context = canvas.getContext("2d"),23 hitCanvas = document.createElement("canvas"),24 hitContext = canvas.getContext("2d"),25 options = {};26 var carto = new SuperMap.CartoRenderer(context, hitContext, options);27 carto.destroy();28 equal(carto.context, null, "CartoRenderer_Destroy");29 equal(carto.symbolizer, null, "CartoRenderer_Destroy");30 equal(carto.pointImagesInfo, null, "CartoRenderer_Destroy");31 equal(carto.imagesBackup, null, "CartoRenderer_Destroy");32});33test("TestCartoRenderer_Support", function() {34 expect(1);35 var canvas = document.createElement("canvas"),36 context = canvas.getContext("2d"),37 hitCanvas = document.createElement("canvas"),38 hitContext = canvas.getContext("2d"),39 options = {};40 var carto = new SuperMap.CartoRenderer(context, hitContext, options);41 var isSupport = carto.supported();42 equal(isSupport, !!canvas.getContext, "CartoRenderer_Support");43});44test("TestCartoRenderer_ApplyStyle", function() {45 expect(2);46 var canvas = document.createElement("canvas"),47 context = canvas.getContext("2d"),48 hitCanvas = document.createElement("canvas"),49 hitContext = canvas.getContext("2d"),50 options = {};51 var carto = new SuperMap.CartoRenderer(context, hitContext, options);52 var can = document.createElement("canvas"), 53 ctx = canvas.getContext("2d"),54 style = {55 fillStyle: "#ababab",56 lineWidth: 557 };58 carto.applyStyle(ctx, style);59 for(var st in style){60 equal(ctx[st], style[st], "CartoRenderer_ApplyStyle");61 }62});63test("TestCartoRenderer_DrawFeature", function() {64 expect(1);65 var canvas = document.createElement("canvas"),66 context = canvas.getContext("2d"),67 hitCanvas = document.createElement("canvas"),68 hitContext = canvas.getContext("2d"),69 options = {};70 var carto = new SuperMap.CartoRenderer(context, hitContext, options);71 var geo = new SuperMap.Geometry.Point(50, 50),72 feature = new SuperMap.Feature.Vector(geo),73 style = new SuperMap.Style(),74 layerType = "POINT";75 feature.layerIndex = 10;76 geo.type = "POINT";77 geo.points = [50, 50];78 var rendered = carto.drawFeature(feature, style, layerType);79 equal(rendered, true, "CartoRenderer_DrawFeature");80});81test("TestCartoRenderer_DrawGeometry", function() {82 expect(1);83 var canvas = document.createElement("canvas"),84 context = canvas.getContext("2d"),85 hitCanvas = document.createElement("canvas"),86 hitContext = canvas.getContext("2d"),87 options = {};88 var carto = new SuperMap.CartoRenderer(context, hitContext, options);89 var can = document.createElement("canvas"), 90 ctx = canvas.getContext("2d"),91 hitCan = document.createElement("canvas"), 92 hitCtx = canvas.getContext("2d"),93 geometry = new SuperMap.Geometry.Point(50, 50),94 style = new SuperMap.Style(),95 hitColor = carto.featureIdToHex("SuperMap.Feature.Vector_14", 10),96 attributs = {},97 layerType = "THEME";98 geometry.type = "TEXT";99 var drawed = carto.drawGeometry(ctx, hitCtx, geometry, style, hitColor, attributs, layerType);100 var geometry0 = new SuperMap.Geometry.MultiPoint([101 new SuperMap.Geometry.Point(50, 50),102 new SuperMap.Geometry.Point(100, 50),103 new SuperMap.Geometry.Point(10, 100)104 ]);105 geometry0.type = "POINT";106 geometry0.parts = [];107 var drawed = carto.drawGeometry(ctx, hitCtx, geometry0, style, hitColor, attributs, layerType);108 layerType = "";109 var geometry1 = new SuperMap.Geometry.LineString([110 new SuperMap.Geometry.Point(50, 50),111 new SuperMap.Geometry.Point(100, 50)112 ]);113 geometry1.type = "LINE";114 geometry1.parts = geometry1.components;115 geometry1.points = geometry1.components;116 var drawed = carto.drawGeometry(ctx, hitCtx, geometry1, style, hitColor, attributs, layerType);117 118 var geometry2 = new SuperMap.Geometry.Polygon([119 new SuperMap.Geometry.LinearRing([120 new SuperMap.Geometry.Point(50, 50),121 new SuperMap.Geometry.Point(100, 50),122 new SuperMap.Geometry.Point(10, 100)123 ])124 ]);125 geometry2.type = "REGION";126 geometry2.parts = geometry2.components;127 geometry2.points = geometry2.components; 128 var drawed = carto.drawGeometry(ctx, hitCtx, geometry2, style, hitColor, attributs, layerType); 129 equal(drawed, true, "CartoRenderer_DrawGeometry");130});131test("TestCartoRenderer_DrawText", function() {132 expect(4);133 var canvas = document.createElement("canvas"),134 context = canvas.getContext("2d"),135 hitCanvas = document.createElement("canvas"),136 hitContext = canvas.getContext("2d"),137 options = {};138 var carto = new SuperMap.CartoRenderer(context, hitContext, options);139 var can = document.createElement("canvas"), 140 ctx = canvas.getContext("2d"),141 hitCan = document.createElement("canvas"), 142 hitCtx = canvas.getContext("2d"),143 geometry = new SuperMap.Geometry.Point(50, 50),144 style = new SuperMap.Style(),145 attributes = {};146 geometry.texts = ["DDDDD", "EEEEEE"];147 geometry.parts = [1];148 geometry.points = [149 new SuperMap.Geometry.Point(50, 50),150 new SuperMap.Geometry.Point(100, 50),151 new SuperMap.Geometry.Point(10, 100),152 new SuperMap.Geometry.Point(100, 100)153 ]; 154 style.textName = "AAAAA";155 style.bold = true;156 style.rotation = 30;157 style.haloRadius = 5;158 style.backColor = "#ABABAB";159 style.foreColor = "#FFFFFF";160 style.textHeight = 10;161 style.fontWeight = 700;162 var drawed = carto.drawText(ctx, hitCtx, geometry, style, attributes);163 equal(drawed, true, "CartoRenderer_DrawText");164 equal(style.fontWeight, 700, "CartoRenderer_DrawText");165 equal(ctx.strokeStyle, "#000000", "CartoRenderer_DrawText");166 equal(ctx.fillStyle, "#000000", "CartoRenderer_DrawText");167});168test("TestCartoRenderer_DrawPoint", function() {169 var canvas = document.createElement("canvas"),170 context = canvas.getContext("2d"),171 hitCanvas = document.createElement("canvas"),172 hitContext = canvas.getContext("2d"),173 options = {};174 var carto = new SuperMap.CartoRenderer(context, hitContext, options);175 var can = document.createElement("canvas"), 176 ctx = canvas.getContext("2d"),177 hitCan = document.createElement("canvas"), 178 hitCtx = canvas.getContext("2d"),179 geometry = {180 points: [181 new SuperMap.Geometry.Point(50, 50),182 new SuperMap.Geometry.Point(50, 50)183 ]184 },185 style = new SuperMap.Style();186 var drawed = carto.drawPoint(ctx, hitCtx, geometry, style);187 equal(drawed, true, "CartoRenderer_DrawText");188 equal(ctx.lineWidth, 1, "CartoRenderer_DrawText");189 equal(ctx.strokeStyle, "#cc3333", "CartoRenderer_DrawText");190 equal(ctx.fillStyle, "#ffcc00", "CartoRenderer_DrawText");191});192test("TestCartoRenderer_DrawImagePoint", function() {193 expect(5);194 var canvas = document.createElement("canvas"),195 context = canvas.getContext("2d"),196 hitCanvas = document.createElement("canvas"),197 hitContext = canvas.getContext("2d"),198 options = {};199 var carto = new SuperMap.CartoRenderer(context, hitContext, options);200 var can = document.createElement("canvas"), 201 ctx = canvas.getContext("2d"),202 hitCan = document.createElement("canvas"), 203 hitCtx = canvas.getContext("2d"),204 style = new SuperMap.Style(),205 x = 50, y = 50;206 207 style.pointFile = "Images/Day.jpg";208 style.imageSmoothingEnabled = null;209 carto.layer = {210 map: {211 getZoom: function() {212 return 5;213 }214 }215 };216 carto.drawImagePoint(ctx, hitCtx, style, x, y);217 equal(ctx.globalAlpha, 1, "CartoRenderer_DrawImagePoint");218 equal(ctx.globalCompositeOperation, "source-over", "CartoRenderer_DrawImagePoint");219 style.pointFile = "Images/Day.png";220 carto.drawImagePoint(ctx, hitCtx, style, x, y);221 equal(ctx.lineWidth, 1, "CartoRenderer_DrawImagePoint");222 equal(ctx.strokeStyle, "#000000", "CartoRenderer_DrawImagePoint");223 equal(ctx.fillStyle, "#000000", "CartoRenderer_DrawImagePoint");224});225test("TestCartoRenderer_DrawVectorPoint", function() {226 expect(0);227 var canvas = document.createElement("canvas"),228 context = canvas.getContext("2d"),229 hitCanvas = document.createElement("canvas"),230 hitContext = canvas.getContext("2d"),231 options = {};232 var carto = new SuperMap.CartoRenderer(context, hitContext, options);233 var can = document.createElement("canvas"), 234 ctx = canvas.getContext("2d"),235 W = 100, H = 50, x = 50, y = 50;236 carto.drawVectorPoint(ctx, W, H, x, y);237});238test("TestCartoRenderer_DrawLine", function() {239 expect(12);240 var canvas = document.createElement("canvas"),241 context = canvas.getContext("2d"),242 hitCanvas = document.createElement("canvas"),243 hitContext = canvas.getContext("2d"),244 options = {};245 var carto = new SuperMap.CartoRenderer(context, hitContext, options);246 var can = document.createElement("canvas"), 247 ctx = canvas.getContext("2d"),248 hitCan = document.createElement("canvas"), 249 hitCtx = canvas.getContext("2d"),250 geometry = new SuperMap.Geometry.LineString([251 new SuperMap.Geometry.Point(50, 50),252 new SuperMap.Geometry.Point(100, 50)253 ]),254 style = new SuperMap.Style(),255 isRegion = true;256 style.offset = {257 x: 0,258 y: 0259 };260 style.lineDashOffset = 0;261 geometry.points = geometry.components;262 geometry.parts = [2, 2]; 263 var drawed = carto.drawLine(ctx, hitCtx, geometry, style, isRegion);264 equal(style.offset.x, 0, "CartoRenderer_DrawLine");265 equal(style.offset.y, 0, "CartoRenderer_DrawLine");266 equal(hitCtx.globalCompositeOperation, "source-over", "CartoRenderer_DrawLine");267 equal(ctx.globalCompositeOperation, "source-over", "CartoRenderer_DrawLine");268 equal(drawed, true, "CartoRenderer_DrawLine");269 style.lineDasharray = [1, 2, 1];270 style.strokeOpacity = 0.5;271 style.fillOpacity = 0.8;272 style.lineOpacity = 0.2;273 var drawed1 = carto.drawLine(ctx, hitCtx, geometry, style, isRegion);274 //equal(ctx.lineDashOffset, 0, "CartoRenderer_DrawLine");275 equal(drawed1, true, "CartoRenderer_DrawLine");276 ctx.setLineDash = false;277 isRegion = false;278 var drawed2 = carto.drawLine(ctx, hitCtx, geometry, style, isRegion);279 equal(style.offset.x, 0, "CartoRenderer_DrawLine");280 equal(style.offset.y, 0, "CartoRenderer_DrawLine");281 equal(hitCtx.globalCompositeOperation, "source-over", "CartoRenderer_DrawLine");282 equal(ctx.globalCompositeOperation, "source-over", "CartoRenderer_DrawLine");283 equal(ctx.globalAlpha, 0.5, "CartoRenderer_DrawLine");284 equal(drawed2, true, "CartoRenderer_DrawLine");285});286test("TestCartoRenderer_DrawDotedLine", function() {287 expect(1);288 var canvas = document.createElement("canvas"),289 context = canvas.getContext("2d"),290 hitCanvas = document.createElement("canvas"),291 hitContext = canvas.getContext("2d"),292 options = {};293 var carto = new SuperMap.CartoRenderer(context, hitContext, options);294 var can = document.createElement("canvas"), 295 ctx = canvas.getContext("2d"),296 hitCan = document.createElement("canvas"), 297 hitCtx = canvas.getContext("2d"),298 points = [299 new SuperMap.Geometry.Point(50, 50),300 new SuperMap.Geometry.Point(100, 50),301 new SuperMap.Geometry.Point(100, 100)302 ],303 startIndex = 0,304 length = 2,305 style = new SuperMap.Style(),306 isRegion = true,307 noLine = false;308 style.fillOpacity = 0.5;309 style.strokeOpacity = 0.8;310 style.offset = {};311 carto.drawDotedLine(ctx, hitCtx, points, startIndex, length, style, isRegion, noLine);...
RCSDK.js
Source:RCSDK.js
...30 * This is for internal use only31 * @protected32 * @returns {Request}33 */34 RCSDK.prototype.getRequest = function() { return require('./core/http/Request').$get(this.getContext()); };35 /**36 * This is for internal use only37 * @protected38 * @returns {Response}39 */40 RCSDK.prototype.getResponse = function(status, statusText, body, headers) {41 return require('./core/http/Response').$get(this.getContext(), status, statusText, body, headers);42 };43 /**44 * @returns {AjaxObserver}45 */46 RCSDK.prototype.getAjaxObserver = function() { return require('./core/AjaxObserver').$get(this.getContext()); };47 /**48 * This is for internal use only49 * @protected50 * @returns {XhrResponse}51 */52 RCSDK.prototype.getXhrResponse = function() { return require('./core/xhr/XhrResponse').$get(this.getContext()); };53 /**54 * @returns {Platform}55 */56 RCSDK.prototype.getPlatform = function() { return require('./core/Platform').$get(this.getContext()); };57 /**58 * @returns {Cache}59 */60 RCSDK.prototype.getCache = function() { return require('./core/Cache').$get(this.getContext()); };61 /**62 * @returns {Subscription}63 */64 RCSDK.prototype.getSubscription = function() { return require('./core/Subscription').$get(this.getContext()); };65 /**66 * @returns {PageVisibility}67 */68 RCSDK.prototype.getPageVisibility = function() { return require('./core/PageVisibility').$get(this.getContext()); };69 /**70 * @returns {Helper}71 */72 RCSDK.prototype.getHelper = function() { return require('./core/Helper').$get(this.getContext()); };73 /**74 * @returns {Observable}75 */76 RCSDK.prototype.getObservable = function() { return require('./core/Observable').$get(this.getContext()); };77 /**78 * @returns {Validator}79 */80 RCSDK.prototype.getValidator = function() { return require('./core/Validator').$get(this.getContext()); };81 /**82 * @returns {Log}83 */84 RCSDK.prototype.getLog = function() { return require('./core/Log').$get(this.getContext()); };85 /**86 * @returns {Utils}87 */88 RCSDK.prototype.getUtils = function() { return require('./core/Utils').$get(this.getContext()); };89 /**90 * @returns {List}91 */92 RCSDK.prototype.getList = function() { return require('./core/List').$get(this.getContext()); };93 // Helpers94 /**95 * @returns {CountryHelper}96 */97 RCSDK.prototype.getCountryHelper = function() { return require('./helpers/Country').$get(this.getContext()); };98 /**99 * @returns {DeviceModelHelper}100 */101 RCSDK.prototype.getDeviceModelHelper = function() { return require('./helpers/DeviceModel').$get(this.getContext()); };102 /**103 * @returns {LanguageHelper}104 */105 RCSDK.prototype.getLanguageHelper = function() { return require('./helpers/Language').$get(this.getContext()); };106 /**107 * @returns {LocationHelper}108 */109 RCSDK.prototype.getLocationHelper = function() { return require('./helpers/Location').$get(this.getContext()); };110 /**111 * @returns {ShippingMethodHelper}112 */113 RCSDK.prototype.getShippingMethodHelper = function() { return require('./helpers/ShippingMethod').$get(this.getContext()); };114 /**115 * @returns {StateHelper}116 */117 RCSDK.prototype.getStateHelper = function() { return require('./helpers/State').$get(this.getContext()); };118 /**119 * @returns {TimezoneHelper}120 */121 RCSDK.prototype.getTimezoneHelper = function() { return require('./helpers/Timezone').$get(this.getContext()); };122 /**123 * @returns {AccountHelper}124 */125 RCSDK.prototype.getAccountHelper = function() { return require('./helpers/Account').$get(this.getContext()); };126 /**127 * @returns {BlockedNumberHelper}128 */129 RCSDK.prototype.getBlockedNumberHelper = function() { return require('./helpers/BlockedNumber').$get(this.getContext()); };130 /**131 * @returns {CallHelper}132 */133 RCSDK.prototype.getCallHelper = function() { return require('./helpers/Call').$get(this.getContext()); };134 /**135 * @returns {ConferencingHelper}136 */137 RCSDK.prototype.getConferencingHelper = function() { return require('./helpers/Conferencing').$get(this.getContext()); };138 /**139 * @returns {ContactHelper}140 */141 RCSDK.prototype.getContactHelper = function() { return require('./helpers/Contact').$get(this.getContext()); };142 /**143 * @returns {ContactGroupHelper}144 */145 RCSDK.prototype.getContactGroupHelper = function() { return require('./helpers/ContactGroup').$get(this.getContext()); };146 /**147 * @returns {DeviceHelper}148 */149 RCSDK.prototype.getDeviceHelper = function() { return require('./helpers/Device').$get(this.getContext()); };150 /**151 * @returns {ExtensionHelper}152 */153 RCSDK.prototype.getExtensionHelper = function() { return require('./helpers/Extension').$get(this.getContext()); };154 /**155 * @returns {ForwardingNumberHelper}156 */157 RCSDK.prototype.getForwardingNumberHelper = function() { return require('./helpers/ForwardingNumber').$get(this.getContext()); };158 /**159 * @returns {MessageHelper}160 */161 RCSDK.prototype.getMessageHelper = function() { return require('./helpers/Message').$get(this.getContext()); };162 /**163 * @returns {PhoneNumberHelper}164 */165 RCSDK.prototype.getPhoneNumberHelper = function() { return require('./helpers/PhoneNumber').$get(this.getContext()); };166 /**167 * @returns {PresenceHelper}168 */169 RCSDK.prototype.getPresenceHelper = function() { return require('./helpers/Presence').$get(this.getContext()); };170 /**171 * @returns {RingoutHelper}172 */173 RCSDK.prototype.getRingoutHelper = function() { return require('./helpers/Ringout').$get(this.getContext()); };174 /**175 * @returns {ServiceHelper}176 */177 RCSDK.prototype.getServiceHelper = function() { return require('./helpers/Service').$get(this.getContext()); };178 if (!injections179 || !('CryptoJS' in injections)180 || !('localStorage' in injections)181 || !('Promise' in injections)182 || !('PUBNUB' in injections)183 || !('XHR' in injections)) throw new Error('Injections object is not complete');184 injections.XHR = (injections.XHR || function() {185 try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e1) {}186 try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e2) {}187 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e3) {}188 throw new Error("This browser does not support XMLHttpRequest.");189 });190 return RCSDK;191 };...
sushigameIngredients.js
Source:sushigameIngredients.js
...38 "Rice",39 100,40 "A",41 function (xPos, yPos) {42 CanvasManager.getContext().fillStyle = "white"43 CanvasManager.getContext().beginPath()44 CanvasManager.getContext().arc(xPos, yPos, 15, 0, Math.PI*2)45 CanvasManager.getContext().fill()46 CanvasManager.getContext().arc(xPos, yPos, 15, 0, Math.PI*2)47 CanvasManager.getContext().stroke()48 CanvasManager.getContext().closePath()49 },50 function (xPos, yPos) {51 // CanvasManager.getContext().drawImage(Ingredient.riceStockSprite, xPos, yPos)52 CanvasManager.getContext().fillStyle = "white"53 CanvasManager.getContext().beginPath()54 CanvasManager.getContext().arc(xPos, yPos, 15, 0, Math.PI*2)55 CanvasManager.getContext().fill()56 CanvasManager.getContext().arc(xPos, yPos, 15, 0, Math.PI*2)57 CanvasManager.getContext().stroke()58 CanvasManager.getContext().closePath()59 }60)61Ingredient.roe = new Ingredient(62 "Salmon Roe",63 200,64 "Z",65 function (xPos, yPos) {66 // CanvasManager.getContext().drawImage(Ingredient.roeSprite, xPos, yPos)67 let displayRoe = function (xPos, yPos) {68 CanvasManager.getContext().fillStyle = "orangered"69 CanvasManager.getContext().beginPath()70 CanvasManager.getContext().arc(xPos, yPos, 8, 0, Math.PI*2)71 CanvasManager.getContext().fill()72 CanvasManager.getContext().closePath()73 CanvasManager.getContext().fillStyle = "darkorange"74 CanvasManager.getContext().beginPath()75 CanvasManager.getContext().arc(xPos, yPos, 6, 0, Math.PI*2)76 CanvasManager.getContext().fill()77 CanvasManager.getContext().closePath()78 CanvasManager.getContext().fillStyle = "firebrick"79 CanvasManager.getContext().beginPath()80 CanvasManager.getContext().arc(xPos, yPos, 2, 0, Math.PI*2)81 CanvasManager.getContext().fill()82 CanvasManager.getContext().closePath()83 CanvasManager.getContext().fillStyle = "darkorange"84 CanvasManager.getContext().beginPath()85 CanvasManager.getContext().arc(xPos - 1, yPos - 5, 3, 0, Math.PI*2)86 CanvasManager.getContext().fill()87 CanvasManager.getContext().closePath()88 CanvasManager.getContext().fillStyle = "white"89 CanvasManager.getContext().beginPath()90 CanvasManager.getContext().arc(xPos - 1, yPos - 6, 1, 0, Math.PI*2)91 CanvasManager.getContext().fill()92 CanvasManager.getContext().closePath()93 }94 displayRoe(xPos, yPos - 8)95 displayRoe(xPos - 8, yPos + 5)96 displayRoe(xPos + 8, yPos + 5)97 },98 function (xPos, yPos) {99 // CanvasManager.getContext().drawImage(Ingredient.roeStockSprite, xPos, yPos)100 let displayRoe = function (xPos, yPos) {101 CanvasManager.getContext().fillStyle = "orangered"102 CanvasManager.getContext().beginPath()103 CanvasManager.getContext().arc(xPos, yPos, 8, 0, Math.PI*2)104 CanvasManager.getContext().fill()105 CanvasManager.getContext().closePath()106 CanvasManager.getContext().fillStyle = "darkorange"107 CanvasManager.getContext().beginPath()108 CanvasManager.getContext().arc(xPos, yPos, 6, 0, Math.PI*2)109 CanvasManager.getContext().fill()110 CanvasManager.getContext().closePath()111 CanvasManager.getContext().fillStyle = "firebrick"112 CanvasManager.getContext().beginPath()113 CanvasManager.getContext().arc(xPos, yPos, 2, 0, Math.PI*2)114 CanvasManager.getContext().fill()115 CanvasManager.getContext().closePath()116 CanvasManager.getContext().fillStyle = "darkorange"117 CanvasManager.getContext().beginPath()118 CanvasManager.getContext().arc(xPos - 1, yPos - 5, 3, 0, Math.PI*2)119 CanvasManager.getContext().fill()120 CanvasManager.getContext().closePath()121 CanvasManager.getContext().fillStyle = "white"122 CanvasManager.getContext().beginPath()123 CanvasManager.getContext().arc(xPos - 1, yPos - 6, 1, 0, Math.PI*2)124 CanvasManager.getContext().fill()125 CanvasManager.getContext().closePath()126 }127 displayRoe(xPos, yPos - 8)128 displayRoe(xPos - 8, yPos + 5)129 displayRoe(xPos + 8, yPos + 5)130 }131)132Ingredient.nori = new Ingredient(133 "Nori",134 100,135 "E",136 function (xPos, yPos) {137 xPos -= 8138 yPos -= 8139 CanvasManager.getContext().fillStyle = "black"140 CanvasManager.getContext().fillRect(xPos, yPos, 15, 25)141 CanvasManager.getContext().fillStyle = "darkgreen"142 CanvasManager.getContext().fillRect(xPos + 1, yPos, 3, 8)143 CanvasManager.getContext().fillRect(xPos + 1, yPos + 9, 3, 10)144 CanvasManager.getContext().fillRect(xPos + 1, yPos + 20, 3, 5)145 CanvasManager.getContext().fillRect(xPos + 6, yPos, 3, 10)146 CanvasManager.getContext().fillRect(xPos + 6, yPos + 11, 3, 5)147 CanvasManager.getContext().fillRect(xPos + 6, yPos + 16, 3, 8)148 CanvasManager.getContext().fillRect(xPos + 11, yPos, 3, 5)149 CanvasManager.getContext().fillRect(xPos + 11, yPos + 6, 3, 8)150 CanvasManager.getContext().fillRect(xPos + 11, yPos + 15, 3, 10)151 },152 function (xPos, yPos) {153 // CanvasManager.getContext().drawImage(Ingredient.noriStockSprite, xPos, yPos)154 xPos -= 8155 yPos -= 8156 CanvasManager.getContext().fillStyle = "black"157 CanvasManager.getContext().fillRect(xPos, yPos, 15, 25)158 CanvasManager.getContext().fillStyle = "darkgreen"159 CanvasManager.getContext().fillRect(xPos + 1, yPos, 3, 8)160 CanvasManager.getContext().fillRect(xPos + 1, yPos + 9, 3, 10)161 CanvasManager.getContext().fillRect(xPos + 1, yPos + 20, 3, 5)162 CanvasManager.getContext().fillRect(xPos + 6, yPos, 3, 10)163 CanvasManager.getContext().fillRect(xPos + 6, yPos + 11, 3, 5)164 CanvasManager.getContext().fillRect(xPos + 6, yPos + 16, 3, 8)165 CanvasManager.getContext().fillRect(xPos + 11, yPos, 3, 5)166 CanvasManager.getContext().fillRect(xPos + 11, yPos + 6, 3, 8)167 CanvasManager.getContext().fillRect(xPos + 11, yPos + 15, 3, 10)168 }169)170Ingredient.avocado = new Ingredient(171 "Avocado",172 400,173 "R",174 function(xPos, yPos) {175 CanvasManager.getContext().drawImage(Ingredient.avocadoSprite, xPos, yPos)176 },177 function (xPos, yPos) {178 CanvasManager.getContext().drawImage(Ingredient.avocadoStockSprite, xPos, yPos)179 }180)181Ingredient.salmon = new Ingredient(182 "Salmon",183 600,184 "Q",185 function(xPos, yPos) {186 },187 function (xPos, yPos) {188 189 }190)191Ingredient.tuna = new Ingredient(192 "Tuna",...
sushigameClock.js
Source:sushigameClock.js
1class Clock {2 constructor() {3 }4 displayDot(xPos, yPos) {5 CanvasManager.getContext().beginPath()6 CanvasManager.getContext().arc(xPos, yPos, 1, 0, Math.PI*2)7 CanvasManager.getContext().closePath()8 CanvasManager.getContext().stroke()9 }10 displayClock(xPos, yPos) {11 CanvasManager.getContext().fillStyle = "white"12 CanvasManager.getContext().beginPath()13 CanvasManager.getContext().arc(xPos, yPos, 20, 0, Math.PI*2)14 CanvasManager.getContext().closePath()15 CanvasManager.getContext().fill()16 CanvasManager.getContext().stroke()17 this.displayDot(xPos, yPos)18 this.displayDot(xPos, yPos - 15)19 this.displayDot(xPos + 8, yPos - 13)20 this.displayDot(xPos + 14, yPos - 7)21 this.displayDot(xPos + 15, yPos)22 this.displayDot(xPos + 14, yPos + 7)23 this.displayDot(xPos + 8, yPos + 13)24 this.displayDot(xPos, yPos + 15)25 this.displayDot(xPos - 8, yPos + 13)26 this.displayDot(xPos - 13, yPos + 7)27 this.displayDot(xPos - 15, yPos)28 this.displayDot(xPos - 13, yPos - 7)29 this.displayDot(yPos - 8, yPos - 13)30 }31 displayMinutes(iterator, xPos, yPos) {32 let minutes = iterator%6033 minutes = Math.floor(minutes/5) * 534 CanvasManager.getContext().beginPath()35 CanvasManager.getContext().moveTo(xPos, yPos)36 switch (minutes) {37 case 0:38 CanvasManager.getContext().lineTo(xPos, yPos - 15)39 break40 case 5:41 CanvasManager.getContext().lineTo(xPos + 8, yPos - 13)42 break43 case 10:44 CanvasManager.getContext().lineTo(xPos + 14, yPos - 7)45 break46 case 15:47 CanvasManager.getContext().lineTo(xPos + 15, yPos)48 break49 case 20:50 CanvasManager.getContext().lineTo(xPos + 14, yPos + 7)51 break52 case 25:53 CanvasManager.getContext().lineTo(xPos + 8, yPos + 13)54 break55 case 30:56 CanvasManager.getContext().lineTo(xPos, yPos + 15)57 break58 case 35:59 CanvasManager.getContext().lineTo(xPos - 8, yPos + 13)60 break61 case 40:62 CanvasManager.getContext().lineTo(xPos - 13, yPos + 7)63 break64 case 45:65 CanvasManager.getContext().lineTo(xPos - 15, yPos)66 break67 case 50:68 CanvasManager.getContext().lineTo(xPos - 13, yPos - 7)69 break70 case 55:71 CanvasManager.getContext().lineTo(xPos - 8, yPos - 13)72 break73 } 74 CanvasManager.getContext().stroke()75 }76 displayHours(iterator, xPos, yPos) {77 let hours = Math.floor((iterator%720)/60)78 CanvasManager.getContext().beginPath()79 CanvasManager.getContext().moveTo(xPos, yPos)80 switch (hours) {81 case 0:82 CanvasManager.getContext().lineTo(xPos, yPos - 10)83 break84 case 1:85 CanvasManager.getContext().lineTo(xPos + 4, yPos - 7)86 break87 case 2:88 CanvasManager.getContext().lineTo(xPos + 8, yPos - 5)89 break90 case 3:91 CanvasManager.getContext().lineTo(xPos + 10, yPos)92 break93 case 4:94 CanvasManager.getContext().lineTo(xPos + 8, yPos + 5)95 break96 case 5:97 CanvasManager.getContext().lineTo(xPos + 4, yPos + 7)98 break99 case 6:100 CanvasManager.getContext().lineTo(xPos, yPos + 10)101 break102 case 7:103 CanvasManager.getContext().lineTo(xPos - 5, yPos + 8)104 break105 case 8:106 CanvasManager.getContext().lineTo(xPos - 8, yPos + 5)107 break108 case 9:109 CanvasManager.getContext().lineTo(xPos - 10, yPos)110 break111 case 10:112 CanvasManager.getContext().lineTo(xPos - 8, yPos - 5)113 break114 case 11:115 CanvasManager.getContext().lineTo(xPos - 5, yPos - 8)116 break117 }118 CanvasManager.getContext().stroke()119 }120 displayTime(iterator, xPos, yPos) {121 this.displayClock(xPos, yPos)122 this.displayMinutes(iterator, xPos, yPos)123 this.displayHours(iterator, xPos, yPos)124 }...
drawing_shapes.js
Source:drawing_shapes.js
1function draw() {2 var canvas_rect = document.getElementById('canvas_rect');3 if(canvas_rect.getContext){4 var ctx = canvas_rect.getContext('2d');5 6 //(x, y, width, height)7 ctx.fillRect(25, 25, 100, 100);8 ctx.clearRect(45, 45, 60, 60);9 ctx.strokeRect(50, 50, 50, 50);10 }11 var canvas_line = document.getElementById('canvas_line');12 if(canvas_line.getContext){13 var ctx = canvas_line.getContext('2d');14 15 ctx.beginPath();16 //x, y17 ctx.beginPath();18 ctx.moveTo(75, 50);19 ctx.lineTo(100, 75);20 ctx.lineTo(100, 25);21 ctx.fill();22 }23 var canvas_arc = document.getElementById('canvas_arc');24 if(canvas_arc.getContext){25 var ctx = canvas_arc.getContext('2d');26 27 ctx.beginPath();28 //(x, y, radius, startAngle, endAngle, anticlockwise)29 ctx.arc(75, 75, 50, 0, Math.PI *2, true); //outer circle30 ctx.moveTo(110, 75);31 ctx.arc(75, 75, 35, 0, Math.PI, false); //Mouth (clockwise)32 ctx.moveTo(65, 65);33 ctx.arc(60, 65, 5, 0, Math.PI * 2, true); //left eye34 ctx.moveTo(95, 65);35 ctx.arc(90, 65, 5, 0, Math.PI * 2, true); //right eye36 ctx.stroke();37 }38 var canvas_arcs = document.getElementById('canvas_arcs');39 if(canvas_arcs.getContext) {40 var ctx = canvas_arcs.getContext('2d');41 42 for (var i=0; i < 3; i++) {43 for (var j=0; j<3; j++) {44 ctx.beginPath();45 var x = 25 + j * 50; // x coordinate46 var y = 25 + i * 50; // y coordinate47 var radius = 20; // Arc radius48 var startAngle = 0; // Starting point on circle49 var endAngle = Math.PI + (Math.PI * j) / 2; // End point on circle50 var anticlockwise = i % 2 !== 0; // clockwise or anticlockwise51 ctx.arc(x, y, radius, startAngle, endAngle, anticlockwise);52 if(i>1) {53 ctx.fill();54 }55 else {56 ctx.stroke();57 }58 }59 }60 }61 var quadratic_curve = document.getElementById('quadratic_curve');62 if(quadratic_curve.getContext) {63 var ctx = quadratic_curve.getContext('2d');64 ctx.beginPath();65 ctx.moveTo(30, 0);66 //px1, py1, x2, y267 ctx.quadraticCurveTo(5, 50, 20, 150);68 ctx.moveTo(90, 0);69 //px1, py1, px2, py2, x2, y270 ctx.bezierCurveTo(30, 40, 140, 100, 100, 150);71 ctx.stroke();72 }73 var rect = document.getElementById('rect');74 if(rect.getContext){75 var ctx = rect.getContext('2d');76 ctx.moveTo(20, 20);77 //x1, y1, x2, y2, radius78 ctx.arcTo(80, 80, 50, 150, 50);79 ctx.stroke();80 }81 var path2d = document.getElementById('path2d');82 if(path2d.getContext) {83 var ctx = path2d.getContext('2d');84 var rectangle = new Path2D();85 rectangle.rect(10, 10, 50, 50);86 var circle = new Path2D();87 circle.moveTo(125, 35);88 circle.arc(100, 35, 25, 0, 2*Math.PI);89 ctx.stroke(rectangle);90 ctx.fill(circle);91 }...
main.js
Source:main.js
...5}6function drawBlindfold(){7 var canvas = document.getElementById('blindfold-canvas');8 if (canvas.getContext){9 var context = canvas.getContext('2d');10 }11 context.fillStyle = '#333333';12 context.fillRect(0,0,800,200);13 context.stroke();14}15function drawVerticalLine(x, lineWidth){16 var canvas = document.getElementById('amidakuji-canvas');17 if (canvas.getContext){18 var context = canvas.getContext('2d');19 }20 context.strokeStyle = '#1253A4';21 context.lineWidth = lineWidth;22 context.beginPath();23 context.moveTo(x, 0);24 context.lineTo(x, $('#amidakuji-canvas').height());25 context.stroke();26}27function drawHorizontalLine(startX, endX, y, lineWidth){28 var canvas = document.getElementById('amidakuji-canvas');29 if (canvas.getContext){30 var context = canvas.getContext('2d');31 }32 context.strokeStyle = '#1253A4';33 context.lineWidth = lineWidth;34 context.beginPath();35 context.moveTo(startX, y);36 context.lineTo(endX, y);37 context.stroke();38}39function drawVerticalLines(n, lineWidth){40 var canvas = document.getElementById('amidakuji-canvas');41 if (canvas.getContext){42 var context = canvas.getContext('2d');43 }44 var diff = Math.floor( $('#amidakuji-canvas').width() /(n-1));45 for(var i = 0; i < n; i++){46 drawVerticalLine(Math.floor(lineWidth / 2) + diff * i, lineWidth);47 addLotButton($('#amidakuji-canvas').offset().left + Math.floor(lineWidth / 2) + diff * i, $('#amidakuji-canvas').offset().top);48 }49}50function drawHorizontalLines(columnN, rowN, lineWidth){51 var canvas = document.getElementById('amidakuji-canvas');52 if (canvas.getContext){53 var context = canvas.getContext('2d');54 }55 var offSet = 30;56 var columnDiff = Math.floor($('#amidakuji-canvas').width()/(columnN - 1));57 var rowDiff = Math.floor(($('#amidakuji-canvas').height() - lineWidth - offSet * 2)/(rowN - 1));58 for(var i = 0; i < columnN - 1; i++){59 for(var j = 0; j < rowN; j++){60 drawHorizontalLine(Math.floor(lineWidth / 2) + columnDiff * i, 61 Math.floor(lineWidth / 2) + columnDiff * (i + 1), 62 Math.floor(lineWidth / 2) + rowDiff * j + offSet, 63 lineWidth);64 }65 }66}67function addLotButton(width, height) {68 var amidakuji = document.getElementById('button-area');69 var id = 'rotButton' + (amidakuji.getElementsByTagName('input').length).toString();70 $('#button-area').append(71 $('<input></input>')72 .attr('id', id)73 .attr('type', 'button')74 );75 var button = document.getElementById('amidakuji-canvas');76 $('#'+id).click(function(){77 var canvas = document.getElementById('blindfold-canvas');78 if (canvas.getContext){79 var context = canvas.getContext('2d');80 }81 context.clearRect(0,0,800,200);82 context.stroke();83 84 })85 return;...
2d.getcontext.extraargs.worker.js
Source:2d.getcontext.extraargs.worker.js
...10 throw reason;11});12t.step(function() {13var offscreenCanvas = new OffscreenCanvas(100, 50);14var ctx = offscreenCanvas.getContext('2d');15var offscreenCanvas2 = new OffscreenCanvas(100, 50);16_assertDifferent(offscreenCanvas2.getContext('2d', false, {}, [], 1, "2"), null, "offscreenCanvas2.getContext('2d', false, {}, [], 1, \"2\")", "null");17_assertDifferent(offscreenCanvas2.getContext('2d', 123), null, "offscreenCanvas2.getContext('2d', 123)", "null");18_assertDifferent(offscreenCanvas2.getContext('2d', "test"), null, "offscreenCanvas2.getContext('2d', \"test\")", "null");19_assertDifferent(offscreenCanvas2.getContext('2d', undefined), null, "offscreenCanvas2.getContext('2d', undefined)", "null");20_assertDifferent(offscreenCanvas2.getContext('2d', null), null, "offscreenCanvas2.getContext('2d', null)", "null");21_assertDifferent(offscreenCanvas2.getContext('2d', Symbol.hasInstance), null, "offscreenCanvas2.getContext('2d', Symbol.hasInstance)", "null");22t.done();23});...
canvas-getContext-invalid.js
Source:canvas-getContext-invalid.js
1description("Test that invalid canvas getContext() requests return null.");2canvas = document.createElement('canvas');3shouldBe("canvas.getContext('')", "null");4shouldBe("canvas.getContext('2d#')", "null");5shouldBe("canvas.getContext('This is clearly not a valid context name.')", "null");6shouldBe("canvas.getContext('2d\0')", "null");7shouldBe("canvas.getContext('2\uFF44')", "null");...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: `example.png` });7 await browser.close();8})();9const { webkit } = require('playwright');10(async () => {11 const browser = await webkit.launch();12 const context = await browser.newContext();13 const page = await context.newPage();14 await page.screenshot({ path: `example.png` });15 await browser.close();16})();17const { firefox } = require('playwright');18(async () => {19 const browser = await firefox.launch();20 const context = await browser.newContext();21 const page = await context.newPage();22 await page.screenshot({ path: `example.png` });23 await browser.close();24})();25const { webkit } = require('playwright');26(async () => {27 const browser = await webkit.launch();28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.screenshot({ path: `example.png` });31 await browser.close();32})();33const { firefox } = require('playwright');34(async () => {35 const browser = await firefox.launch();36 const context = await browser.newContext();37 const page = await context.newPage();38 await page.screenshot({ path: `example.png` });39 await browser.close();40})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await browser.close();7})();8const { chromium } = require('playwright');9(async () => {10 const browser = await chromium.launch();11 const context = await browser.newContext();12 const page = await context.newPage();13 await browser.close();14})();15const { chromium } = require('playwright');16(async () => {17 const browser = await chromium.launch();18 const context = await browser.newContext();19 const page = await context.newPage();20 await browser.close();21})();22const { chromium } = require('playwright');23(async () => {24 const browser = await chromium.launch();25 const context = await browser.newContext();26 const page = await context.newPage();27 await browser.close();28})();29const { chromium } = require('playwright');30(async () => {31 const browser = await chromium.launch();32 const context = await browser.newContext();33 const page = await context.newPage();34 await browser.close();35})();36const { chromium } = require('playwright');37(async () => {38 const browser = await chromium.launch();39 const context = await browser.newContext();40 const page = await context.newPage();41 await browser.close();42})();43const { chromium } = require('playwright');44(async () => {45 const browser = await chromium.launch();46 const context = await browser.newContext();47 const page = await context.newPage();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: `example.png` });7 await browser.close();8})();
Using AI Code Generation
1const playwright = require("playwright");2(async () => {3 for (const browserType of BROWSER) {4 const browser = await playwright[browserType].launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.screenshot({ path: `example-${browserType}.png` });8 await browser.close();9 }10})();11const playwright = require("playwright");12(async () => {13 for (const browserType of BROWSER) {14 const browser = await playwright[browserType].launch();15 const page = await browser.newPage();16 await page.screenshot({ path: `example-${browserType}.png` });17 await browser.close();18 }19})();20Error: Protocol error (Target.createTarget):
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: `example.png` });7 await browser.close();8})();9const { chromium } = require('playwright');10(async () => {11 const browser = await chromium.launch({ headless: false });12 const context = await browser.newContext();13 const page = await context.newPage();14 await page.screenshot({ path: `example.png` });15 await browser.close();16})();17const { chromium } = require('playwright');18(async () => {19 const browser = await chromium.launch({ headless: false });20 const context = await browser.newContext();21 const page = await context.newPage();22 await page.screenshot({ path: `example.png` });23 await browser.close();24})();25const { chromium } = require('playwright');26(async () => {27 const browser = await chromium.launch({ headless: false });28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.screenshot({ path: `example.png` });31 await browser.close();32})();33const { chromium } = require('playwright');34(async () => {35 const browser = await chromium.launch({ headless: false });36 const context = await browser.newContext();37 const page = await context.newPage();38 await page.screenshot({ path: `example.png` });39 await browser.close();40})();41const { chromium } = require('playwright');42(async () => {43 const browser = await chromium.launch({ headless: false });
Using AI Code Generation
1const page = await context.newPage();2const context = await browser.newContext();3const browser = await chromium.launch();4const context = await browser.newContext();5const page = await browser.newPage();6const browser = await chromium.launch();7const page = await browser.newPage();8const browser = await chromium.launch();9const page = await context.newPage();10const context = await browser.newContext();11const browser = await chromium.launch();12const context = await browser.newContext();13const page = await browser.newPage();14const browser = await chromium.launch();15const page = await browser.newPage();16const browser = await chromium.launch();17const page = await context.newPage();18const context = await browser.newContext();19const browser = await chromium.launch();20const context = await browser.newContext();21const page = await browser.newPage();22const browser = await chromium.launch();23const page = await browser.newPage();24const browser = await chromium.launch();25const page = await context.newPage();26const context = await browser.newContext();27const browser = await chromium.launch();28const context = await browser.newContext();29const page = await browser.newPage();30const browser = await chromium.launch();31const page = await browser.newPage();32const browser = await chromium.launch();33const page = await context.newPage();34const context = await browser.newContext();35const browser = await chromium.launch();36const context = await browser.newContext();37const page = await browser.newPage();38const browser = await chromium.launch();39const page = await browser.newPage();40const browser = await chromium.launch();41const page = await context.newPage();42const context = await browser.newContext();43const browser = await chromium.launch();44const context = await browser.newContext();45const page = await browser.newPage();46const browser = await chromium.launch();47const page = await browser.newPage();48const browser = await chromium.launch();49const page = await context.newPage();50const context = await browser.newContext();
Using AI Code Generation
1const playwright = require('playwright');2const { InternalAPI } = require('playwright/lib/server/cjs/playwright');3const context = InternalAPI.getContext();4const page = context.page;5const frame = page.mainFrame();6const element = frame.$('text=Click me');7await element.click();8const playwright = require('playwright');9const { InternalAPI } = require('playwright/lib/server/cjs/playwright');10const context = InternalAPI.getContext();11const page = context.page;12const frame = page.mainFrame();13const element = frame.$('text=Click me');14await element.click();15const playwright = require('playwright');16const { InternalAPI } = require('playwright/lib/server/cjs/playwright');17const context = InternalAPI.getContext();18const page = context.page;19const frame = page.mainFrame();20const element = frame.$('text=Click me');21await element.click();22const playwright = require('playwright');23const { InternalAPI } = require('playwright/lib/server/cjs/playwright
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!