content/base/test/test_bug475156.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=475156
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 475156</title>
michael@0 8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 10 </head>
michael@0 11 <body onload="drive(tests.shift());">
michael@0 12 <script class="testbody" type="text/javascript">
michael@0 13
michael@0 14 SimpleTest.waitForExplicitFinish();
michael@0 15
michael@0 16 var path = "http://mochi.test:8888/tests/content/base/test/";
michael@0 17
michael@0 18 function fromCache(xhr)
michael@0 19 {
michael@0 20 var ch = SpecialPowers.wrap(xhr).channel.QueryInterface(SpecialPowers.Ci.nsICacheInfoChannel);
michael@0 21 return ch.isFromCache();
michael@0 22 }
michael@0 23
michael@0 24 var tests = [
michael@0 25 // First just init the file with an ETag
michael@0 26 {
michael@0 27 init: function(xhr)
michael@0 28 {
michael@0 29 xhr.open("GET", path + "bug475156.sjs?etag=a1");
michael@0 30 },
michael@0 31
michael@0 32 loading: function(xhr)
michael@0 33 {
michael@0 34 },
michael@0 35
michael@0 36 done: function(xhr)
michael@0 37 {
michael@0 38 },
michael@0 39 },
michael@0 40
michael@0 41 // Try to load the file the first time regularly, we have to get 200 OK
michael@0 42 {
michael@0 43 init: function(xhr)
michael@0 44 {
michael@0 45 xhr.open("GET", path + "bug475156.sjs");
michael@0 46 },
michael@0 47
michael@0 48 loading: function(xhr)
michael@0 49 {
michael@0 50 is(fromCache(xhr), false, "Not coming from the cache");
michael@0 51 },
michael@0 52
michael@0 53 done: function(xhr)
michael@0 54 {
michael@0 55 is(xhr.status, 200, "We get a fresh version of the file");
michael@0 56 is(xhr.getResponseHeader("Etag"), "a1", "We got correct ETag");
michael@0 57 is(xhr.responseText, "a1", "We got the expected file body");
michael@0 58 },
michael@0 59 },
michael@0 60
michael@0 61 // Try to load the file the second time regularly, we have to get 304 Not Modified
michael@0 62 {
michael@0 63 init: function(xhr)
michael@0 64 {
michael@0 65 xhr.open("GET", path + "bug475156.sjs");
michael@0 66 xhr.setRequestHeader("If-Match", "a1");
michael@0 67 },
michael@0 68
michael@0 69 loading: function(xhr)
michael@0 70 {
michael@0 71 is(fromCache(xhr), true, "Coming from the cache");
michael@0 72 },
michael@0 73
michael@0 74 done: function(xhr)
michael@0 75 {
michael@0 76 is(xhr.status, 200, "We got cached version");
michael@0 77 is(xhr.getResponseHeader("Etag"), "a1", "We got correct ETag");
michael@0 78 is(xhr.responseText, "a1", "We got the expected file body");
michael@0 79 },
michael@0 80 },
michael@0 81
michael@0 82 // Try to load the file the third time regularly, we have to get 304 Not Modified
michael@0 83 {
michael@0 84 init: function(xhr)
michael@0 85 {
michael@0 86 xhr.open("GET", path + "bug475156.sjs");
michael@0 87 xhr.setRequestHeader("If-Match", "a1");
michael@0 88 },
michael@0 89
michael@0 90 loading: function(xhr)
michael@0 91 {
michael@0 92 is(fromCache(xhr), true, "Coming from the cache");
michael@0 93 },
michael@0 94
michael@0 95 done: function(xhr)
michael@0 96 {
michael@0 97 is(xhr.status, 200, "We got cached version");
michael@0 98 is(xhr.getResponseHeader("Etag"), "a1", "We got correct ETag");
michael@0 99 is(xhr.responseText, "a1", "We got the expected file body");
michael@0 100 },
michael@0 101 },
michael@0 102
michael@0 103 // Now modify the ETag
michael@0 104 {
michael@0 105 init: function(xhr)
michael@0 106 {
michael@0 107 xhr.open("GET", path + "bug475156.sjs?etag=a2");
michael@0 108 },
michael@0 109
michael@0 110 loading: function(xhr)
michael@0 111 {
michael@0 112 },
michael@0 113
michael@0 114 done: function(xhr)
michael@0 115 {
michael@0 116 },
michael@0 117 },
michael@0 118
michael@0 119 // Try to load the file, we have to get 200 OK with the new content
michael@0 120 {
michael@0 121 init: function(xhr)
michael@0 122 {
michael@0 123 xhr.open("GET", path + "bug475156.sjs");
michael@0 124 xhr.setRequestHeader("If-Match", "a2");
michael@0 125 },
michael@0 126
michael@0 127 loading: function(xhr)
michael@0 128 {
michael@0 129 is(fromCache(xhr), false, "Not coming from the cache");
michael@0 130 },
michael@0 131
michael@0 132 done: function(xhr)
michael@0 133 {
michael@0 134 is(xhr.status, 200, "We get a fresh version of the file");
michael@0 135 is(xhr.getResponseHeader("Etag"), "a2", "We got correct ETag");
michael@0 136 is(xhr.responseText, "a2", "We got the expected file body");
michael@0 137 },
michael@0 138 },
michael@0 139
michael@0 140 // Try to load the file the second time regularly, we have to get 304 Not Modified
michael@0 141 {
michael@0 142 init: function(xhr)
michael@0 143 {
michael@0 144 xhr.open("GET", path + "bug475156.sjs");
michael@0 145 xhr.setRequestHeader("If-Match", "a2");
michael@0 146 },
michael@0 147
michael@0 148 loading: function(xhr)
michael@0 149 {
michael@0 150 is(fromCache(xhr), true, "Coming from the cache");
michael@0 151 },
michael@0 152
michael@0 153 done: function(xhr)
michael@0 154 {
michael@0 155 is(xhr.status, 200, "We got cached version");
michael@0 156 is(xhr.getResponseHeader("Etag"), "a2", "We got correct ETag");
michael@0 157 is(xhr.responseText, "a2", "We got the expected file body");
michael@0 158 },
michael@0 159 },
michael@0 160
michael@0 161 // Try to load the file the third time regularly, we have to get 304 Not Modified
michael@0 162 {
michael@0 163 init: function(xhr)
michael@0 164 {
michael@0 165 xhr.open("GET", path + "bug475156.sjs");
michael@0 166 xhr.setRequestHeader("If-Match", "a2");
michael@0 167 },
michael@0 168
michael@0 169 loading: function(xhr)
michael@0 170 {
michael@0 171 is(fromCache(xhr), true, "Coming from the cache");
michael@0 172 },
michael@0 173
michael@0 174 done: function(xhr)
michael@0 175 {
michael@0 176 is(xhr.status, 200, "We got cached version");
michael@0 177 is(xhr.getResponseHeader("Etag"), "a2", "We got correct ETag");
michael@0 178 is(xhr.responseText, "a2", "We got the expected file body");
michael@0 179 },
michael@0 180 },
michael@0 181
michael@0 182 // Now modify the ETag ones more
michael@0 183 {
michael@0 184 init: function(xhr)
michael@0 185 {
michael@0 186 xhr.open("GET", path + "bug475156.sjs?etag=a3");
michael@0 187 },
michael@0 188
michael@0 189 loading: function(xhr)
michael@0 190 {
michael@0 191 },
michael@0 192
michael@0 193 done: function(xhr)
michael@0 194 {
michael@0 195 },
michael@0 196 },
michael@0 197
michael@0 198 // Try to load the file, we have to get 200 OK with the new content
michael@0 199 {
michael@0 200 init: function(xhr)
michael@0 201 {
michael@0 202 xhr.open("GET", path + "bug475156.sjs");
michael@0 203 xhr.setRequestHeader("If-Match", "a3");
michael@0 204 },
michael@0 205
michael@0 206 loading: function(xhr)
michael@0 207 {
michael@0 208 is(fromCache(xhr), false, "Not coming from the cache");
michael@0 209 },
michael@0 210
michael@0 211 done: function(xhr)
michael@0 212 {
michael@0 213 is(xhr.status, 200, "We get a fresh version of the file");
michael@0 214 is(xhr.getResponseHeader("Etag"), "a3", "We got correct ETag");
michael@0 215 is(xhr.responseText, "a3", "We got the expected file body");
michael@0 216 },
michael@0 217 },
michael@0 218
michael@0 219 // Try to load the file the second time regularly, we have to get 304 Not Modified
michael@0 220 {
michael@0 221 init: function(xhr)
michael@0 222 {
michael@0 223 xhr.open("GET", path + "bug475156.sjs");
michael@0 224 xhr.setRequestHeader("If-Match", "a3");
michael@0 225 },
michael@0 226
michael@0 227 loading: function(xhr)
michael@0 228 {
michael@0 229 is(fromCache(xhr), true, "Coming from the cache");
michael@0 230 },
michael@0 231
michael@0 232 done: function(xhr)
michael@0 233 {
michael@0 234 is(xhr.status, 200, "We got cached version");
michael@0 235 is(xhr.getResponseHeader("Etag"), "a3", "We got correct ETag");
michael@0 236 is(xhr.responseText, "a3", "We got the expected file body");
michael@0 237 },
michael@0 238 },
michael@0 239
michael@0 240 // Try to load the file the third time regularly, we have to get 304 Not Modified
michael@0 241 {
michael@0 242 init: function(xhr)
michael@0 243 {
michael@0 244 xhr.open("GET", path + "bug475156.sjs");
michael@0 245 xhr.setRequestHeader("If-Match", "a3");
michael@0 246 },
michael@0 247
michael@0 248 loading: function(xhr)
michael@0 249 {
michael@0 250 is(fromCache(xhr), true, "Coming from the cache");
michael@0 251 },
michael@0 252
michael@0 253 done: function(xhr)
michael@0 254 {
michael@0 255 is(xhr.status, 200, "We got cached version");
michael@0 256 is(xhr.getResponseHeader("Etag"), "a3", "We got correct ETag");
michael@0 257 is(xhr.responseText, "a3", "We got the expected file body");
michael@0 258 },
michael@0 259 },
michael@0 260 ]
michael@0 261
michael@0 262
michael@0 263 function drive(test)
michael@0 264 {
michael@0 265 var xhr = new XMLHttpRequest();
michael@0 266 test.init(xhr);
michael@0 267 xhr.onreadystatechange = function() {
michael@0 268 if (this.readyState == 3) {
michael@0 269 test.loading(this);
michael@0 270 }
michael@0 271 if (this.readyState == 4) {
michael@0 272 test.done(this);
michael@0 273 if (tests.length == 0)
michael@0 274 SimpleTest.finish();
michael@0 275 else
michael@0 276 drive(tests.shift());
michael@0 277 }
michael@0 278 }
michael@0 279 xhr.send();
michael@0 280 }
michael@0 281
michael@0 282 </script>
michael@0 283 </pre>
michael@0 284 </body>
michael@0 285 </html>
michael@0 286

mercurial