зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1338262 - Remove legacy generator from netwerk/test/. r=mayhemer
This commit is contained in:
Родитель
2431d460d2
Коммит
8f6cb3e9d7
|
@ -77,7 +77,7 @@ function fileContents(file)
|
|||
* an Iterator which returns each line from data in turn; note that this
|
||||
* includes a final empty line if data ended with a CRLF
|
||||
*/
|
||||
function LineIterator(data)
|
||||
function* LineIterator(data)
|
||||
{
|
||||
var start = 0, index = 0;
|
||||
do
|
||||
|
@ -107,7 +107,7 @@ function LineIterator(data)
|
|||
function expectLines(iter, expectedLines)
|
||||
{
|
||||
var index = 0;
|
||||
for (var line in iter)
|
||||
for (var line of iter)
|
||||
{
|
||||
if (expectedLines.length == index)
|
||||
throw "Error: got more than " + expectedLines.length + " expected lines!";
|
||||
|
@ -155,9 +155,9 @@ function writeDetails(request, response)
|
|||
*/
|
||||
function skipHeaders(iter)
|
||||
{
|
||||
var line = iter.next();
|
||||
var line = iter.next().value;
|
||||
while (line !== "")
|
||||
line = iter.next();
|
||||
line = iter.next().value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -267,7 +267,7 @@ function check400(data)
|
|||
var iter = LineIterator(data);
|
||||
|
||||
// Status-Line
|
||||
var firstLine = iter.next();
|
||||
var { value: firstLine } = iter.next();
|
||||
do_check_eq(firstLine.substring(0, HTTP_400_LEADER_LENGTH), HTTP_400_LEADER);
|
||||
}
|
||||
|
||||
|
@ -296,7 +296,7 @@ function check10(data)
|
|||
var iter = LineIterator(data);
|
||||
|
||||
// Status-Line
|
||||
do_check_eq(iter.next(), "HTTP/1.0 200 TEST PASSED");
|
||||
do_check_eq(iter.next().value, "HTTP/1.0 200 TEST PASSED");
|
||||
|
||||
skipHeaders(iter);
|
||||
|
||||
|
@ -395,7 +395,7 @@ function check11goodHost(data)
|
|||
var iter = LineIterator(data);
|
||||
|
||||
// Status-Line
|
||||
do_check_eq(iter.next(), "HTTP/1.1 200 TEST PASSED");
|
||||
do_check_eq(iter.next().value, "HTTP/1.1 200 TEST PASSED");
|
||||
|
||||
skipHeaders(iter);
|
||||
|
||||
|
@ -432,7 +432,7 @@ function check11ipHost(data)
|
|||
var iter = LineIterator(data);
|
||||
|
||||
// Status-Line
|
||||
do_check_eq(iter.next(), "HTTP/1.1 200 TEST PASSED");
|
||||
do_check_eq(iter.next().value, "HTTP/1.1 200 TEST PASSED");
|
||||
|
||||
skipHeaders(iter);
|
||||
|
||||
|
@ -517,7 +517,7 @@ function check10ip(data)
|
|||
var iter = LineIterator(data);
|
||||
|
||||
// Status-Line
|
||||
do_check_eq(iter.next(), "HTTP/1.0 200 TEST PASSED");
|
||||
do_check_eq(iter.next().value, "HTTP/1.0 200 TEST PASSED");
|
||||
|
||||
skipHeaders(iter);
|
||||
|
||||
|
@ -554,7 +554,7 @@ function check11goodHostWackyPort(data)
|
|||
var iter = LineIterator(data);
|
||||
|
||||
// Status-Line
|
||||
do_check_eq(iter.next(), "HTTP/1.1 200 TEST PASSED");
|
||||
do_check_eq(iter.next().value, "HTTP/1.1 200 TEST PASSED");
|
||||
|
||||
skipHeaders(iter);
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ function checkVeryLongRequestLine(data)
|
|||
print("iter object: " + iter);
|
||||
|
||||
// Status-Line
|
||||
do_check_eq(iter.next(), "HTTP/1.1 200 TEST PASSED");
|
||||
do_check_eq(iter.next().value, "HTTP/1.1 200 TEST PASSED");
|
||||
|
||||
skipHeaders(iter);
|
||||
|
||||
|
@ -112,7 +112,7 @@ function checkLotsOfLeadingBlankLines(data)
|
|||
print("data length: " + data.length);
|
||||
print("iter object: " + iter);
|
||||
|
||||
do_check_eq(iter.next(), "HTTP/1.1 200 TEST PASSED");
|
||||
do_check_eq(iter.next().value, "HTTP/1.1 200 TEST PASSED");
|
||||
|
||||
skipHeaders(iter);
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ var data1 = "GET /called-too-late HTTP/1.0\r\n" +
|
|||
"\r\n";
|
||||
function checkTooLate(data)
|
||||
{
|
||||
do_check_eq(LineIterator(data).next(), "too-late passed");
|
||||
do_check_eq(LineIterator(data).next().value, "too-late passed");
|
||||
}
|
||||
|
||||
var data2 = "GET /exceptions HTTP/1.0\r\n" +
|
||||
|
@ -178,5 +178,5 @@ var data4 = "GET /seize-after-async HTTP/1.0\r\n" +
|
|||
"\r\n";
|
||||
function checkSeizeAfterAsync(data)
|
||||
{
|
||||
do_check_eq(LineIterator(data).next(), "HTTP/1.0 200 async seizure pass");
|
||||
do_check_eq(LineIterator(data).next().value, "HTTP/1.0 200 async seizure pass");
|
||||
}
|
||||
|
|
|
@ -262,7 +262,7 @@ add_task(function test_setup()
|
|||
})
|
||||
});
|
||||
|
||||
add_task(function test_normal()
|
||||
add_task(function* test_normal()
|
||||
{
|
||||
// This test demonstrates the most basic use case.
|
||||
let destFile = getTempFile(TEST_FILE_NAME_1);
|
||||
|
@ -296,7 +296,7 @@ add_task(function test_normal()
|
|||
destFile.remove(false);
|
||||
});
|
||||
|
||||
add_task(function test_combinations()
|
||||
add_task(function* test_combinations()
|
||||
{
|
||||
let initialFile = getTempFile(TEST_FILE_NAME_1);
|
||||
let renamedFile = getTempFile(TEST_FILE_NAME_2);
|
||||
|
@ -403,7 +403,7 @@ add_task(function test_combinations()
|
|||
}
|
||||
});
|
||||
|
||||
add_task(function test_setTarget_after_close_stream()
|
||||
add_task(function* test_setTarget_after_close_stream()
|
||||
{
|
||||
// This test checks the case where we close the output stream before we call
|
||||
// the setTarget method. All the data should be buffered and written anyway.
|
||||
|
@ -437,7 +437,7 @@ add_task(function test_setTarget_after_close_stream()
|
|||
destFile.remove(false);
|
||||
});
|
||||
|
||||
add_task(function test_setTarget_fast()
|
||||
add_task(function* test_setTarget_fast()
|
||||
{
|
||||
// This test checks a fast rename of the target file.
|
||||
let destFile1 = getTempFile(TEST_FILE_NAME_1);
|
||||
|
@ -460,7 +460,7 @@ add_task(function test_setTarget_fast()
|
|||
destFile2.remove(false);
|
||||
});
|
||||
|
||||
add_task(function test_setTarget_multiple()
|
||||
add_task(function* test_setTarget_multiple()
|
||||
{
|
||||
// This test checks multiple renames of the target file.
|
||||
let destFile = getTempFile(TEST_FILE_NAME_1);
|
||||
|
@ -485,7 +485,7 @@ add_task(function test_setTarget_multiple()
|
|||
destFile.remove(false);
|
||||
});
|
||||
|
||||
add_task(function test_enableAppend()
|
||||
add_task(function* test_enableAppend()
|
||||
{
|
||||
// This test checks append mode with hashing disabled.
|
||||
let destFile = getTempFile(TEST_FILE_NAME_1);
|
||||
|
@ -513,7 +513,7 @@ add_task(function test_enableAppend()
|
|||
destFile.remove(false);
|
||||
});
|
||||
|
||||
add_task(function test_enableAppend_setTarget_fast()
|
||||
add_task(function* test_enableAppend_setTarget_fast()
|
||||
{
|
||||
// This test checks a fast rename of the target file in append mode.
|
||||
let destFile1 = getTempFile(TEST_FILE_NAME_1);
|
||||
|
@ -550,7 +550,7 @@ add_task(function test_enableAppend_setTarget_fast()
|
|||
destFile1.remove(false);
|
||||
});
|
||||
|
||||
add_task(function test_enableAppend_hash()
|
||||
add_task(function* test_enableAppend_hash()
|
||||
{
|
||||
// This test checks append mode, also verifying that the computed hash
|
||||
// includes the contents of the existing data.
|
||||
|
@ -582,7 +582,7 @@ add_task(function test_enableAppend_hash()
|
|||
destFile.remove(false);
|
||||
});
|
||||
|
||||
add_task(function test_finish_only()
|
||||
add_task(function* test_finish_only()
|
||||
{
|
||||
// This test checks creating the object and doing nothing.
|
||||
let destFile = getTempFile(TEST_FILE_NAME_1);
|
||||
|
@ -595,7 +595,7 @@ add_task(function test_finish_only()
|
|||
yield completionPromise;
|
||||
});
|
||||
|
||||
add_task(function test_empty()
|
||||
add_task(function* test_empty()
|
||||
{
|
||||
// This test checks we still create an empty file when no data is fed.
|
||||
let destFile = getTempFile(TEST_FILE_NAME_1);
|
||||
|
@ -617,7 +617,7 @@ add_task(function test_empty()
|
|||
destFile.remove(false);
|
||||
});
|
||||
|
||||
add_task(function test_empty_hash()
|
||||
add_task(function* test_empty_hash()
|
||||
{
|
||||
// This test checks the hash of an empty file, both in normal and append mode.
|
||||
let destFile = getTempFile(TEST_FILE_NAME_1);
|
||||
|
@ -646,7 +646,7 @@ add_task(function test_empty_hash()
|
|||
destFile.remove(false);
|
||||
});
|
||||
|
||||
add_task(function test_invalid_hash()
|
||||
add_task(function* test_invalid_hash()
|
||||
{
|
||||
let saver = new BackgroundFileSaverStreamListener();
|
||||
let completionPromise = promiseSaverComplete(saver);
|
||||
|
@ -676,7 +676,7 @@ add_task(function test_invalid_hash()
|
|||
} catch (ex if ex.result == Cr.NS_ERROR_FAILURE) { }
|
||||
});
|
||||
|
||||
add_task(function test_signature()
|
||||
add_task(function* test_signature()
|
||||
{
|
||||
// Check that we get a signature if the saver is finished.
|
||||
let destFile = getTempFile(TEST_FILE_NAME_1);
|
||||
|
@ -704,7 +704,7 @@ add_task(function test_signature()
|
|||
destFile.remove(false);
|
||||
});
|
||||
|
||||
add_task(function test_signature_not_enabled()
|
||||
add_task(function* test_signature_not_enabled()
|
||||
{
|
||||
// Check that we get a signature if the saver is finished on Windows.
|
||||
let destFile = getTempFile(TEST_FILE_NAME_1);
|
||||
|
|
|
@ -25,7 +25,7 @@ LoadContext.prototype = {
|
|||
getInterface: XPCOMUtils.generateQI([Ci.nsILoadContext])
|
||||
};
|
||||
|
||||
function getChannels() {
|
||||
function* getChannels() {
|
||||
for (let u of URIs) {
|
||||
yield NetUtil.newChannel({
|
||||
uri: u,
|
||||
|
|
|
@ -47,12 +47,10 @@ var fourthTests = [
|
|||
[0, false, 1, 1], [0, true, 1, 0], [1, false, 1, 0], [1, true, 1, 0]
|
||||
];
|
||||
|
||||
function run_all_tests() {
|
||||
async function run_all_tests() {
|
||||
for (let test of firstTests) {
|
||||
handlers_called = 0;
|
||||
var chan = makeChan(URL, test[0], test[1], test[2]);
|
||||
chan.asyncOpen2(new ChannelListener(doneFirstLoad, test[3]));
|
||||
yield undefined;
|
||||
await test_channel(...test);
|
||||
}
|
||||
|
||||
// We can't easily cause webapp data to be cleared from the child process, so skip
|
||||
|
@ -68,9 +66,7 @@ function run_all_tests() {
|
|||
|
||||
for (let test of secondTests) {
|
||||
handlers_called = 0;
|
||||
var chan = makeChan(URL, test[0], test[1], test[2]);
|
||||
chan.asyncOpen2(new ChannelListener(doneFirstLoad, test[3]));
|
||||
yield undefined;
|
||||
await test_channel(...test);
|
||||
}
|
||||
|
||||
Services.obs.notifyObservers(null, "clear-origin-attributes-data", attrs_notInBrowser);
|
||||
|
@ -78,9 +74,7 @@ function run_all_tests() {
|
|||
|
||||
for (let test of thirdTests) {
|
||||
handlers_called = 0;
|
||||
var chan = makeChan(URL, test[0], test[1], test[2]);
|
||||
chan.asyncOpen2(new ChannelListener(doneFirstLoad, test[3]));
|
||||
yield undefined;
|
||||
await test_channel(...test);
|
||||
}
|
||||
|
||||
let attrs_userContextId = JSON.stringify({ userContextId: 1 });
|
||||
|
@ -88,13 +82,10 @@ function run_all_tests() {
|
|||
|
||||
for (let test of fourthTests) {
|
||||
handlers_called = 0;
|
||||
var chan = makeChan(URL, test[0], test[1], test[2]);
|
||||
chan.asyncOpen2(new ChannelListener(doneFirstLoad, test[3]));
|
||||
yield undefined;
|
||||
await test_channel(...test);
|
||||
}
|
||||
}
|
||||
|
||||
var gTests;
|
||||
function run_test() {
|
||||
do_get_profile();
|
||||
if (!newCacheBackEndUsed()) {
|
||||
|
@ -105,22 +96,26 @@ function run_test() {
|
|||
httpserv = new HttpServer();
|
||||
httpserv.registerPathHandler("/cached", cached_handler);
|
||||
httpserv.start(-1);
|
||||
gTests = run_all_tests();
|
||||
gTests.next();
|
||||
run_all_tests().then(() => {
|
||||
do_test_finished();
|
||||
});
|
||||
}
|
||||
|
||||
function doneFirstLoad(req, buffer, expected) {
|
||||
function test_channel(appId, inIsolatedMozBrowser, userContextId, expected) {
|
||||
return new Promise(resolve => {
|
||||
var chan = makeChan(URL, appId, inIsolatedMozBrowser, userContextId);
|
||||
chan.asyncOpen2(new ChannelListener(doneFirstLoad.bind(null, resolve), expected));
|
||||
});
|
||||
}
|
||||
|
||||
function doneFirstLoad(resolve, req, buffer, expected) {
|
||||
// Load it again, make sure it hits the cache
|
||||
var oa = req.loadInfo.originAttributes;
|
||||
var chan = makeChan(URL, oa.appId, oa.isInIsolatedMozBrowserElement, oa.userContextId);
|
||||
chan.asyncOpen2(new ChannelListener(doneSecondLoad, expected));
|
||||
chan.asyncOpen2(new ChannelListener(doneSecondLoad.bind(null, resolve), expected));
|
||||
}
|
||||
|
||||
function doneSecondLoad(req, buffer, expected) {
|
||||
function doneSecondLoad(resolve, req, buffer, expected) {
|
||||
do_check_eq(handlers_called, expected);
|
||||
try {
|
||||
gTests.next();
|
||||
} catch (x) {
|
||||
do_test_finished();
|
||||
}
|
||||
resolve();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче