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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/appcache/non-html.xhtml

Issue 2540833002: Deflake tests in http/tests/appcache/ when run in random order (Closed)
Patch Set: Rebased Created 4 years 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
1 <html xmlns="http://www.w3.org/1999/xhtml" 1 <html xmlns="http://www.w3.org/1999/xhtml"
2 manifest="/resources/network-simulator.php?path=/appcache/resources/non-ht ml.manifest"> 2 manifest="/resources/network-simulator.php?path=/appcache/resources/non-ht ml.manifest">
3 <head><title/></head> 3 <head><title/></head>
4 <body> 4 <body>
5 <p>Test that non-HTML main resources work with application cache correctly.</p> 5 <p>Test that non-HTML main resources work with application cache correctly.</p>
6 <p>Should say SUCCESS:</p> 6 <p>Should say SUCCESS:</p>
7 <div id="result"></div> 7 <div id="result"></div>
8 <script type="text/javascript"> 8 <script type="text/javascript">
9 if (window.testRunner) { 9 if (window.testRunner) {
10 testRunner.dumpAsText() 10 testRunner.dumpAsText()
11 testRunner.waitUntilDone(); 11 testRunner.waitUntilDone();
12 } 12 }
13 13
14 function log(message) 14 function log(message)
15 { 15 {
16 document.getElementById("result").innerHTML += message + "&lt;br/>"; 16 document.getElementById("result").innerHTML += message + "&lt;br/>";
17 } 17 }
18 18
19 function setNetworkEnabled(state) 19 function setNetworkEnabled(state, callback)
20 { 20 {
21 var req = new XMLHttpRequest; 21 var req = new XMLHttpRequest;
22 req.open("GET", "/resources/network-simulator.php?command=" + (state ? "conn ect" : "disconnect"), false); 22 req.open("GET", "/resources/network-simulator.php?command=" + (state ? "conn ect" : "disconnect"));
23 req.send(""); 23 req.send("");
24 req.onload = callback;
24 } 25 }
25 26
26 function createFrame() 27 function createFrame()
27 { 28 {
28 var ifr = document.createElement("iframe"); 29 var ifr = document.createElement("iframe");
29 ifr.setAttribute("src", "/resources/network-simulator.php?path=/appcache/res ources/abe.png"); 30 ifr.setAttribute("src", "/resources/network-simulator.php?path=/appcache/res ources/abe.png");
30 ifr.onload = frameCreated; 31 ifr.onload = frameCreated;
31 document.body.appendChild(ifr); 32 document.body.appendChild(ifr);
32 } 33 }
33 34
34 function cached() 35 function cached()
35 { 36 {
36 var hadError = false; 37 var hadError = false;
37 38
38 applicationCache.removeEventListener('noupdate', cached, false); 39 applicationCache.removeEventListener('noupdate', cached, false);
39 applicationCache.removeEventListener('cached', cached, false); 40 applicationCache.removeEventListener('cached', cached, false);
40 41
41 setNetworkEnabled(false); 42 setNetworkEnabled(false, () => {
42 43
43 // Load a resource that does not exist in the cache. 44 // Load a resource that does not exist in the cache.
44 try { 45 try {
45 var req = new XMLHttpRequest(); 46 var req = new XMLHttpRequest();
46 req.open("GET", "/resources/network-simulator.php?path=/appcache/resourc es/not-in-cache.txt", false); 47 req.open("GET", "/resources/network-simulator.php?path=/appcache/res ources/not-in-cache.txt", false);
47 req.send(); 48 req.send();
48 } catch (e) { 49 } catch (e) {
49 if (e.code == DOMException.NETWORK_ERR) 50 if (e.code == DOMException.NETWORK_ERR)
50 hadError = true; 51 hadError = true;
51 } 52 }
52 53
53 if (!hadError) { 54 if (!hadError) {
54 document.getElementById('result').innerHTML = "FAILURE: Did not get the right exception" 55 document.getElementById('result').innerHTML = "FAILURE: Did not get the right exception"
55 return; 56 return;
56 } 57 }
57
58 // Load a resource that exists in the cache.
59 try {
60 var req = new XMLHttpRequest();
61 req.open("GET", "/resources/network-simulator.php?path=/appcache/resourc es/simple.txt", false);
62 req.send();
63 } catch (e) {
64 document.getElementById('result').innerHTML = "FAILURE: Could not load d ata from cache"
65 return;
66 }
67
68 if (req.responseText != 'Hello, World!') {
69 document.getElementById('result').innerHTML = "FAILURE: Did not get corr ect data from cached resource"
70 return;
71 }
72 58
73 createFrame(); 59 // Load a resource that exists in the cache.
60 try {
61 var req = new XMLHttpRequest();
62 req.open("GET", "/resources/network-simulator.php?path=/appcache/res ources/simple.txt", false);
63 req.send();
64 } catch (e) {
65 document.getElementById('result').innerHTML = "FAILURE: Could not lo ad data from cache"
66 return;
67 }
68
69 if (req.responseText != 'Hello, World!') {
70 document.getElementById('result').innerHTML = "FAILURE: Did not get correct data from cached resource"
71 return;
72 }
73
74 createFrame();
75 });
74 } 76 }
75 77
76 function frameCreated() 78 function frameCreated()
77 { 79 {
78 setNetworkEnabled(true); 80 setNetworkEnabled(true, () => {
79 81 if (frames[0].document.documentElement.innerHTML.match(/abe\.png/))
80 if (frames[0].document.documentElement.innerHTML.match(/abe\.png/)) 82 log("SUCCESS")
81 log("SUCCESS") 83 else
82 else 84 log("FAIL: Frame.onload was called, but the image doesn't seem to be loaded.");
83 log("FAIL: Frame.onload was called, but the image doesn't seem to be loa ded."); 85
84 86 if (window.testRunner) {
85 if (window.testRunner) { 87 applicationCache.onerror = null;
86 applicationCache.onerror = null; 88 testRunner.notifyDone();
87 testRunner.notifyDone(); 89 }
88 } 90 });
89 } 91 }
90 92
91 function error() 93 function error()
92 { 94 {
93 // The simulator was in a wrong state, reset it. 95 // The simulator was in a wrong state, reset it.
94 setNetworkEnabled(true); 96 setNetworkEnabled(true, () => {
95 window.location.reload(); 97 window.location.reload();
98 });
96 } 99 }
97 100
98 applicationCache.addEventListener('cached', cached, false); 101 applicationCache.addEventListener('cached', cached, false);
99 applicationCache.addEventListener('noupdate', cached, false); 102 applicationCache.addEventListener('noupdate', cached, false);
100 103
101 applicationCache.onerror = error; 104 applicationCache.onerror = error;
102 105
103 </script> 106 </script>
104 </body> 107 </body>
105 </html> 108 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698