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

Side by Side Diff: LayoutTests/imported/web-platform-tests/html/semantics/embedded-content/the-img-element/img.complete.html

Issue 1144143009: W3C Test: Import web-platform-tests/html/semantics (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE HTML>
2 <title>DOM img complete Test</title>
3 <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
4 <link rel="author" title="Anselm Hannemann" href="http://anselm-hannemann.com/" />
5 <link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-img-complete" />
6 <meta name="assert" content="Tests the complete status of the img-element">
7 <script src="../../../../../../resources/testharness.js"></script>
8 <script src="../../../../../../resources/testharnessreport.js"></script>
9
10 <img id="imgTestTag">
11 <img src="" id="imgTestTag2">
12 <img id="imgTestTag3" style="width: 80px; height:auto;">
13 <img id="imgTestTag4">
14
15 <script>
16 var imageInstance = document.createElement('img');
17 imageInstance.style.display = 'none';
18
19 document.body.appendChild(imageInstance);
20 </script>
21
22 <div id="log"></div>
23 <script>
24 test(function() {
25 assert_true(document.getElementById("imgTestTag").complete);
26 }, "img src omitted");
27
28 test(function() {
29 assert_true(document.getElementById("imgTestTag2").complete);
30 }, "img src empty");
31
32 // test if set to true after img is completely available
33 var t = async_test("async src complete test");
34
35 t.step(function(){
36 document.getElementById("imgTestTag3").src = '3.jpg?nocache=' + Math.random( );
37
38 //test if img.complete is set to false if src is changed
39 assert_false(document.getElementById("imgTestTag3").complete, "src changed, should be set to false")
40 });
41
42 document.getElementById("imgTestTag3").onload = t.step_func(function(){
43 assert_true(document.getElementById("imgTestTag3").complete);
44 t.done();
45 });
46
47 // https://html.spec.whatwg.org/multipage/multipage/embedded-content-1.html#up date-the-image-data
48 // says to "await a stable state" before fetching so we use a separate <script >
49 imageInstance.src = 'image-1.jpg?pipe=trickle(d1)&nocache=' + Math.random(); / / make sure the image isn't in cache
50 </script>
51 <script>
52 // test: The final task that is queued by the networking task source once the resource has been fetched has been queued, but has not yet been run, and the img element is not in the broken state
53 async_test(function(t) {
54 assert_false(imageInstance.complete, "imageInstance.complete should be false ");
55 var startTime = Date.now();
56 while (true) {
57 if (Date.now() - startTime > 2000)
58 assert_unreached('.complete didn\'t change to true');
59 if (imageInstance.complete === true) break;
60 }
61 t.done();
62 },
63 'IDL attribute complete returns true when image resource has been fetched but not run yet & image is not in broken state');
64
65 // test if broken img does not pass
66 var t2 = async_test("async src broken test");
67 var img4 = document.getElementById("imgTestTag4");
68
69 t2.step(
70 function(){
71 img4.src = 'brokenimg.jpg';
72
73 //test if img.complete is set to false if src is changed
74 assert_false(img4.complete, "src changed to broken img, should be set to fal se");
75 });
76
77 img4.onload = img4.onerror = t2.step_func(function(event){
78 assert_equals(event.type, "error");
79 assert_true(img4.complete);
80 t2.done();
81 });
82 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698