image/test/mochitest/test_bug478398.html

branch
TOR_BUG_9701
changeset 10
ac0c01689b40
equal deleted inserted replaced
-1:000000000000 0:2c0b66bb786c
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=478398
5 -->
6 <head>
7 <title>Test for Bug 478398</title>
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <script type="text/javascript" src="imgutils.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478398">Mozilla Bug 478398</a>
14 <pre id="test">
15 <script class="testbody" type="text/javascript">
16
17 /** Test for Bug 399925. **/
18 var oldTimeoutPref;
19 var oldDiscardPref;
20 SimpleTest.waitForExplicitFinish();
21 window.onload = stage1;
22 var imageFilename = "bug478398_ONLY.png";
23
24 function stage1()
25 {
26 // Get the current pref values
27 oldTimeoutPref = getImagePref(DISCARD_TIMEOUT_PREF);
28 oldDiscardPref = getImagePref(DISCARD_ENABLED_PREF);
29
30 // We're testing discarding here
31 setImagePref(DISCARD_ENABLED_PREF, true);
32
33 // Sets the discard timer to 500 ms (max timeout = 2*500ms = 1s)
34 setImagePref(DISCARD_TIMEOUT_PREF, 500);
35
36 // Create the image _after_ setting the discard timer pref
37 // This image was carefully constructed to make it a "big win" for discarding,
38 // so any reasonable heuristic should still discard it.
39 var image = new Image();
40 image.setAttribute("id", "testimage");
41 image.style.display = "none";
42 image.src = imageFilename;
43
44 // Put the image into the document
45 document.body.appendChild(image);
46
47 // Wait for load, then do stage2
48 image.onload = stage2;
49 }
50
51 function stage2()
52 {
53 // Make sure we're loaded
54 ok(isImageLoaded("testimage"), "image should be loaded");
55
56 // We're loaded - force a synchronous decode
57 forceDecode("testimage");
58
59 // We should be decoded
60 ok(isFrameDecoded("testimage"), "image should be decoded");
61
62 // Wait 1.5 seconds, then finish the test
63 setTimeout("finishTest();", 1500);
64
65 }
66
67 function finishTest()
68 {
69 // The image should be discarded by now
70 ok(!isFrameDecoded("testimage"), "image should have been discarded!");
71
72 // Reset the prefs
73 setImagePref(DISCARD_TIMEOUT_PREF, oldTimeoutPref);
74 setImagePref(DISCARD_ENABLED_PREF, oldDiscardPref);
75
76 // Finish the test
77 SimpleTest.finish();
78 }
79
80
81 </script>
82 </pre>
83 </body>
84 </html>
85

mercurial