Source/WebCore/ChangeLog

 12011-11-29 Hans Muller <hmuller@adobe.com>
 2
 3 XHR 'progress' event code assumes wrongly that expectedLength >= 0
 4 https://bugs.webkit.org/show_bug.cgi?id=36156
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Avoid passing a negative value as the dispatchProgressEvent's total parameter and always use 0 when lengthComputable is false.
 9
 10 Test: http/tests/xmlhttprequest/chunked-progress-event-expectedLength.html
 11
 12 * xml/XMLHttpRequest.cpp:
 13 (WebCore::XMLHttpRequest::didReceiveData):
 14
1152011-11-29 Oliver Hunt <oliver@apple.com>
216
317 Revert that last change, apparently it destroys everything in the world.

Source/WebCore/xml/XMLHttpRequest.cpp

@@void XMLHttpRequest::didReceiveData(const char* data, int len)
10801080 m_receivedLength += len;
10811081
10821082 if (m_async) {
1083  bool lengthComputable = expectedLength && m_receivedLength <= expectedLength;
1084  m_progressEventThrottle.dispatchProgressEvent(lengthComputable, m_receivedLength, expectedLength);
 1083 bool lengthComputable = expectedLength > 0 && m_receivedLength <= expectedLength;
 1084 unsigned long long total = lengthComputable ? expectedLength : 0;
 1085 m_progressEventThrottle.dispatchProgressEvent(lengthComputable, m_receivedLength, total);
10851086 }
1086 
 1087
10871088 if (m_state != LOADING)
10881089 changeState(LOADING);
10891090 else

LayoutTests/ChangeLog

 12011-11-29 Hans Muller <hmuller@adobe.com>
 2
 3 XHR 'progress' event code assumes wrongly that expectedLength >= 0
 4 https://bugs.webkit.org/show_bug.cgi?id=36156
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Verify that XMLHttpRequest ProgressEvent's total is zero when the expectedLength of the
 9 (chunked transfer mode) response can't be computed.
 10
 11 * http/tests/xmlhttprequest/chunked-progress-event-expectedLength-expected.txt: Added.
 12 * http/tests/xmlhttprequest/chunked-progress-event-expectedLength.html: Added.
 13 * http/tests/xmlhttprequest/resources/chunked-transfer.php: Added.
 14
1152011-11-29 Xiaomei Ji <xji@chromium.org>
216
317 Rebase after r100819.

LayoutTests/http/tests/xmlhttprequest/chunked-progress-event-expectedLength-expected.txt

 1CONSOLE MESSAGE: line 26: 4, 0, false
 2Test case for bug 36156: XHR 'progress' event code assumes wrongly that expectedLength >= 0
 3
 4Verify that the progress event total property is 0 when the expected overall length can't be computed.
 5
 6PASS should appear below:
 7
 8PASS

LayoutTests/http/tests/xmlhttprequest/chunked-progress-event-expectedLength.html

 1<html>
 2<head>
 3<title>Test case for bug 36156</title>
 4</head>
 5<body>
 6<p> Test case for <a href="https://bugs.webkit.org/show_bug.cgi?id=36156"> bug 36156</a>: XHR 'progress' event code assumes wrongly that expectedLength >= 0</p>
 7<p> Verify that the progress event total property is 0 when the expected overall length can't be computed.<p>
 8<p>PASS should appear below:</p>
 9<p id=console></p>
 10<script type="text/javascript">
 11if (window.layoutTestController) {
 12 layoutTestController.dumpAsText();
 13 layoutTestController.waitUntilDone();
 14}
 15
 16function log(message)
 17{
 18 document.getElementById('console').appendChild(document.createTextNode(message + '\n'));
 19}
 20
 21function test()
 22{
 23 var xhr = new XMLHttpRequest();
 24 xhr.open("GET", "resources/chunked-transfer.php", true);
 25 xhr.onprogress = function(e) {
 26 console.log(e.loaded + ", " + e.total + ", " + e.lengthComputable);
 27 if (e.loaded == 4 && e.total == 0 && !e.lengthComputable)
 28 {
 29 log("PASS");
 30 if (window.layoutTestController)
 31 layoutTestController.notifyDone();
 32 }
 33 }
 34 xhr.send();
 35}
 36
 37test();
 38</script>
 39</body>

LayoutTests/http/tests/xmlhttprequest/resources/chunked-transfer.php

 1<?php
 2header("Transfer-encoding: chunked");
 3flush();
 4sleep(0.5);
 5printf("4\r\n<a/>\r\n");
 6flush();
 7sleep(0.5);
 8printf("0\r\n\r\n");
 9?>