Advertisement
Guest User

Untitled

a guest
Sep 15th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.05 KB | None | 0 0
  1. diff --git a/XMLHttpRequest/progress-events-response-data-gzip.htm b/XMLHttpRequest/progress-events-response-data-gzip.htm
  2. index dc166a2..0580646 100644
  3. --- a/XMLHttpRequest/progress-events-response-data-gzip.htm
  4. +++ b/XMLHttpRequest/progress-events-response-data-gzip.htm
  5. @@ -36,17 +36,20 @@
  6.  
  7.            * If lengthComputable is true:
  8.                * Event.total must match Content-length header
  9. -              * event.loaded should be a smaller number while resource is loading
  10. -                and match Content-length when loading is finished
  11. -              * Setting event.loaded to equal event.total for each progress event if the
  12. -                resource is not fully downloaded would be cheating
  13. +              * event.loaded must only ever increase in progress events
  14. +                (and may never repeat its value).
  15. +              * event.loaded must never exceed the Content-length.
  16.  
  17.            * If lengthComputable is false:
  18.                * event.total should be 0
  19. +              * event.loaded must only ever increase in progress events
  20. +                (and may never repeat its value).
  21.                * event.loaded should be the length of the decompressed content, i.e.
  22.                  bigger than Content-length header value when finished loading
  23.  
  24.          */
  25. +        var lastTotal;
  26. +        var lastLoaded = -1;
  27.          client.addEventListener('loadend', test.step_func(function(e){
  28.            var len = parseInt(client.getResponseHeader('content-length'), 10)
  29.            if(e.lengthComputable){
  30. @@ -59,14 +62,17 @@
  31.            test.done();
  32.          }), false)
  33.          client.addEventListener('progress', test.step_func(function(e){
  34. -          if(e.lengthComputable && e.total && e.loaded && e.target.readyState < 4){
  35. -            assert_not_equals(e.total, e.loaded, 'total should not equal loaded while download/decode is incomplete')
  36. -            // We should only do this assertation once
  37. -            // it's theoretically possible that all the data would get in
  38. -            // and a progress event fire before the readyState switches from 3 to 4 -
  39. -            // in this case we might report bogus and random failures. Better to remove the event listener again..
  40. -            client.removeEventListener('progress', arguments.callee, false);
  41. +          if(lastTotal === undefined){
  42. +            lastTotal = e.total;
  43.            }
  44. +          if(e.lengthComputable && e.total && e.loaded){
  45. +            assert_equals(e.total, lastTotal, 'event.total should remain invariant')
  46. +            assert_less_than_equal(e.loaded, lastTotal, 'event.loaded should not exceed content-length')
  47. +          }else{
  48. +            assert_equals(e.total, 0, 'event.total should be 0')
  49. +          }
  50. +          assert_greater_than(e.loaded, lastLoaded, 'event.loaded should only ever increase')
  51. +          lastLoaded = e.loaded;
  52.          }), false)
  53.          // image.gif is 165375 bytes compressed. Sending 45000 bytes at a time with 1 second delay will load it in 4 seconds
  54.          client.open("GET", "resources/image.gif?pipe=gzip|trickle(45000:d1:r2)", true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement