Skip to content

Commit

Permalink
Bug 1603819 - Wrap cache_storage.exists calls in a syncWithCacheIOThr…
Browse files Browse the repository at this point in the history
…ead block.r=valentin,michal

Differential Revision: https://phabricator.services.mozilla.com/D70236
  • Loading branch information
mahakbansal2019 committed Apr 8, 2020
1 parent ea4d72f commit 17ee245
Showing 1 changed file with 48 additions and 40 deletions.
88 changes: 48 additions & 40 deletions netwerk/test/unit/test_bug482934.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,17 @@ add_test(() => {
var ch = make_channel(resource_url);
ch.asyncOpen(
new ChannelListener(function(aRequest, aData) {
Assert.ok(hit_server);
Assert.equal(
aRequest.QueryInterface(Ci.nsIHttpChannel).responseStatus,
304
);
Assert.ok(!cache_storage.exists(make_uri(resource_url), ""));
Assert.equal(aRequest.getResponseHeader("Returned-From-Handler"), "1");

run_next_test();
syncWithCacheIOThread(() => {
Assert.ok(hit_server);
Assert.equal(
aRequest.QueryInterface(Ci.nsIHttpChannel).responseStatus,
304
);
Assert.ok(!cache_storage.exists(make_uri(resource_url), ""));
Assert.equal(aRequest.getResponseHeader("Returned-From-Handler"), "1");

run_next_test();
}, true);
}, null)
);
});
Expand All @@ -115,14 +117,16 @@ add_test(() => {
var ch = make_channel(resource_url);
ch.asyncOpen(
new ChannelListener(function(aRequest, aData) {
Assert.ok(hit_server);
Assert.equal(
aRequest.QueryInterface(Ci.nsIHttpChannel).responseStatus,
200
);
Assert.ok(cache_storage.exists(make_uri(resource_url), ""));

check_cached_data(response_body, run_next_test);
syncWithCacheIOThread(() => {
Assert.ok(hit_server);
Assert.equal(
aRequest.QueryInterface(Ci.nsIHttpChannel).responseStatus,
200
);
Assert.ok(cache_storage.exists(make_uri(resource_url), ""));

check_cached_data(response_body, run_next_test);
}, true);
}, null)
);
});
Expand All @@ -139,17 +143,19 @@ add_test(() => {
var ch = make_channel(resource_url);
ch.asyncOpen(
new ChannelListener(function(aRequest, aData) {
Assert.ok(hit_server);
Assert.equal(
aRequest.QueryInterface(Ci.nsIHttpChannel).responseStatus,
304
);
Assert.ok(cache_storage.exists(make_uri(resource_url), ""));
Assert.equal(aRequest.getResponseHeader("Returned-From-Handler"), "1");
Assert.equal(aData, "");

// Check the cache data is not changed
check_cached_data(cached_body, run_next_test);
syncWithCacheIOThread(() => {
Assert.ok(hit_server);
Assert.equal(
aRequest.QueryInterface(Ci.nsIHttpChannel).responseStatus,
304
);
Assert.ok(cache_storage.exists(make_uri(resource_url), ""));
Assert.equal(aRequest.getResponseHeader("Returned-From-Handler"), "1");
Assert.equal(aData, "");

// Check the cache data is not changed
check_cached_data(cached_body, run_next_test);
}, true);
}, null)
);
});
Expand All @@ -164,18 +170,20 @@ add_test(() => {
var ch = make_channel(resource_url);
ch.asyncOpen(
new ChannelListener(function(aRequest, aData) {
Assert.ok(hit_server);
Assert.equal(
aRequest.QueryInterface(Ci.nsIHttpChannel).responseStatus,
200
);
Assert.ok(cache_storage.exists(make_uri(resource_url), ""));

// Check the cache data is updated
check_cached_data(response_body, () => {
run_next_test();
httpserver.stop(do_test_finished);
});
syncWithCacheIOThread(() => {
Assert.ok(hit_server);
Assert.equal(
aRequest.QueryInterface(Ci.nsIHttpChannel).responseStatus,
200
);
Assert.ok(cache_storage.exists(make_uri(resource_url), ""));

// Check the cache data is updated
check_cached_data(response_body, () => {
run_next_test();
httpserver.stop(do_test_finished);
});
}, true);
}, null)
);
});

0 comments on commit 17ee245

Please sign in to comment.