Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / ManualTests / drag-image-no-crash.html
blobdad8c072808a64ba6088086164df18a2b59df86d
1 <html>
2 <body>
3 <script>
4 // This is a 10x10 24-bits RGB BMP image in white.
5 var imageString =
6 "Qk12AQAAAAAAADYAAAAoAAAACgAAAAoAAAABABgAAAAAAEABAAATCwAAEwsAAAAAAAAAAAAAAAAA" +
7 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +
8 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +
9 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +
10 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +
11 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +
12 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
14 // Raw image byets.
15 var imageRaw = window.atob(imageString).split("");
17 // 10x10x3 bytes are image data.
18 var pixelBytes = 300;
19 var beginByte = imageRaw.length - pixelBytes;
21 function generateNewImage()
23 // Add 1 to image data.
24 for (var i = beginByte; i < imageRaw.length; ++i) {
25 var c = imageRaw[i].charCodeAt(0);
26 if (c == 255) {
27 imageRaw[i] = String.fromCharCode(0);
28 } else {
29 imageRaw[i] = String.fromCharCode(c+1);
30 break;
34 var bmpImage = new Image();
35 bmpImage.src = "data:image/bmp;base64," + window.btoa(imageRaw.join(""));
36 return bmpImage;
39 var imageCount = 0;
40 function addImage()
42 if (imageCount >= 1000 * 1000)
43 return;
44 document.getElementById("imageCanvas").appendChild(generateNewImage());
45 window.setTimeout("addImage()", 1);
48 function runTest()
50 document.getElementById("dragFrame").contentWindow.location.href =
51 "about:blank";
52 addImage();
54 </script>
55 <p>To run this test:</p>
56 <p>1. Drag this text 10 times:
57 <iframe id="dragFrame" width="50" height="30">.</iframe></p>
58 <p>2. Click this <button onclick="runTest();">Start</button> button.</p>
59 <p>3. Let it run for 5 minutes and browser shouldn't crash.</p>
60 <div id="imageCanvas"></div>
62 <script>
63 // Write this content to the iframe.
64 var content =
65 "<" + "body" + ">" +
66 "<" + "script" + ">" +
67 "function dragStartHandler()" +
68 "{" +
69 " var img = new Image();" +
70 " img.src = 'data:image/bmp;base64," + imageString + "';" +
71 " event.dataTransfer.setDragImage(img, 10, 10);" +
72 "}" +
73 "</" + "script" + ">" +
74 "<span ondragstart='dragStartHandler()'" +
75 " style='-webkit-user-select:none;" +
76 " -webkit-user-drag: element;" +
77 " position: absolute; top: 0; left: 0;" +
78 " background-color: blue;'>HERE</span>" +
79 "</" + "body" + ">";
81 var doc = document.getElementById("dragFrame");
82 doc.contentDocument.open();
83 doc.contentDocument.write(content);
84 doc.contentDocument.close();
85 </script>
86 </body>
87 </html>