From 17ee2456010236bb2116720c132dab671cd1aa0f Mon Sep 17 00:00:00 2001 From: MahakBansal Date: Wed, 8 Apr 2020 19:24:26 +0000 Subject: [PATCH] Bug 1603819 - Wrap cache_storage.exists calls in a syncWithCacheIOThread block.r=valentin,michal Differential Revision: https://phabricator.services.mozilla.com/D70236 --- netwerk/test/unit/test_bug482934.js | 88 ++++++++++++++++------------- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/netwerk/test/unit/test_bug482934.js b/netwerk/test/unit/test_bug482934.js index e84584236cccc..2827e4c87511c 100644 --- a/netwerk/test/unit/test_bug482934.js +++ b/netwerk/test/unit/test_bug482934.js @@ -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) ); }); @@ -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) ); }); @@ -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) ); }); @@ -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) ); });