Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: third_party/WebKit/LayoutTests/virtual/threaded/fast/canvas-toBlob/canvas-createImageBitmap-blob-in-workers.html

Issue 2189733003: Remove virtual test suits virtual/threaded/fast/canvas-toBlob (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <script>
8 jsTestIsAsync = true;
9 var worker = new Worker('../../../../fast/canvas/resources/canvas-createImageBit map-blob-in-workers.js');
10
11 description('Test race condition for createImageBitmap from blob in workers and main.');
12
13 var imgWidth = 20;
14 var imgHeight = 20;
15 var numOfBitmaps = 5;
16 var bitmapArray = [];
17
18 var canvas1 = document.createElement("canvas");
19 var ctx1 = canvas1.getContext("2d");
20 ctx1.fillStyle = "#FF0000";
21 ctx1.fillRect(0, 0, imgWidth, imgHeight);
22
23 function compareImageData(data1, data2)
24 {
25 if (data1.length != data2.length) {
26 testFailed("The two image have different dimensions");
27 finishJSTest();
28 }
29 for (var i = 0; i < data1.length; i++) {
30 if (data1[i] != data2[i]) {
31 testFailed("The two image have different pixel data");
32 finishJSTest();
33 }
34 }
35 }
36
37 var getMessageFromWorker = new Promise((resolve, reject) => {
38 function onMessage(e) {
39 resolve(e.data.data);
40 worker.removeEventListener("message", onMessage);
41 }
42 worker.addEventListener("message", onMessage);
43 });
44
45 // check that the created ImageBitmaps from worker and main have the same pixel
46 // data as the source, which is the canvas1.toBlob
47 var newImg = new Image();
48 canvas1.toBlob(function(blob) {
49 worker.postMessage(blob);
50 for (var i = 0; i < numOfBitmaps; i++) {
51 createImageBitmap(blob).then(imageBitmap => {
52 bitmapArray.push(imageBitmap);
53 if (bitmapArray.length == numOfBitmaps) {
54 var url = URL.createObjectURL(blob);
55 newImg.src = url;
56 }
57 });
58 }
59 });
60
61 var imageLoaded = new Promise((resolve, reject) => {
62 newImg.onload = function() {
63 var canvas2 = document.createElement("canvas");
64 var ctx2 = canvas2.getContext("2d");
65 ctx2.drawImage(newImg, 0, 0, imgWidth, imgHeight);
66 resolve(ctx2.getImageData(0, 0, imgWidth, imgHeight).data);
67 };
68 });
69
70 Promise.all([imageLoaded, getMessageFromWorker]).then(([imageDataFromImg, imageB itmapFromWorker]) => {
71 var canvas3 = document.createElement("canvas");
72 var ctx3 = canvas3.getContext("2d");
73 for (var i = 0; i < numOfBitmaps; i++) {
74 ctx3.clearRect(0, 0, imgWidth, imgHeight);
75 ctx3.drawImage(bitmapArray[i], 0, 0, imgWidth, imgHeight);
76 var imageData = ctx3.getImageData(0, 0, imgWidth, imgHeight).data;
77 compareImageData(imageData, imageDataFromImg);
78 }
79
80 ctx3.clearRect(0, 0, imgWidth, imgHeight);
81 ctx3.drawImage(imageBitmapFromWorker, 0, 0, imgWidth, imgHeight);
82 var imageData = ctx3.getImageData(0, 0, imgWidth, imgHeight).data;
83 compareImageData(imageData, imageDataFromImg);
84 testPassed("ImageBitmaps created from blob in worker and in main have the sa me pixel data");
85 finishJSTest();
86 });
87
88 </script>
89 </body>
90 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698