diff --git a/netwerk/test/unit/test_http2.js b/netwerk/test/unit/test_http2.js index 4a57deed08c9..6ce6ea9e19b6 100644 --- a/netwerk/test/unit/test_http2.js +++ b/netwerk/test/unit/test_http2.js @@ -148,7 +148,9 @@ Http2HeaderListener.prototype.onDataAvailable = function(request, ctx, stream, o read_stream(stream, cnt); }; -var Http2PushListener = function() {}; +var Http2PushListener = function(shouldBePushed) { + this.shouldBePushed = shouldBePushed; +}; Http2PushListener.prototype = new Http2CheckListener(); @@ -158,7 +160,7 @@ Http2PushListener.prototype.onDataAvailable = function(request, ctx, stream, off if (request.originalURI.spec == "https://localhost:" + serverPort + "/push.js" || request.originalURI.spec == "https://localhost:" + serverPort + "/push2.js" || request.originalURI.spec == "https://localhost:" + serverPort + "/push5.js") { - do_check_eq(request.getResponseHeader("pushed"), "yes"); + do_check_eq(request.getResponseHeader("pushed"), this.shouldBePushed ? "yes" : "no"); } read_stream(stream, cnt); }; @@ -492,42 +494,42 @@ function test_http2_cookie_crumbling() { function test_http2_push1() { var chan = makeChan("https://localhost:" + serverPort + "/push"); chan.loadGroup = loadGroup; - var listener = new Http2PushListener(); + var listener = new Http2PushListener(true); chan.asyncOpen2(listener); } function test_http2_push2() { var chan = makeChan("https://localhost:" + serverPort + "/push.js"); chan.loadGroup = loadGroup; - var listener = new Http2PushListener(); + var listener = new Http2PushListener(true); chan.asyncOpen2(listener); } function test_http2_push3() { var chan = makeChan("https://localhost:" + serverPort + "/push2"); chan.loadGroup = loadGroup; - var listener = new Http2PushListener(); + var listener = new Http2PushListener(true); chan.asyncOpen2(listener); } function test_http2_push4() { var chan = makeChan("https://localhost:" + serverPort + "/push2.js"); chan.loadGroup = loadGroup; - var listener = new Http2PushListener(); + var listener = new Http2PushListener(true); chan.asyncOpen2(listener); } function test_http2_push5() { var chan = makeChan("https://localhost:" + serverPort + "/push5"); chan.loadGroup = loadGroup; - var listener = new Http2PushListener(); + var listener = new Http2PushListener(true); chan.asyncOpen2(listener); } function test_http2_push6() { var chan = makeChan("https://localhost:" + serverPort + "/push5.js"); chan.loadGroup = loadGroup; - var listener = new Http2PushListener(); + var listener = new Http2PushListener(true); chan.asyncOpen2(listener); } @@ -899,6 +901,54 @@ function test_http2_empty_data() { chan.asyncOpen2(listener); } +function test_http2_push_firstparty1() { + var chan = makeChan("https://localhost:" + serverPort + "/push"); + chan.loadGroup = loadGroup; + chan.loadInfo.originAttributes = { firstPartyDomain: "foo.com" }; + var listener = new Http2PushListener(true); + chan.asyncOpen2(listener); +} + +function test_http2_push_firstparty2() { + var chan = makeChan("https://localhost:" + serverPort + "/push.js"); + chan.loadGroup = loadGroup; + chan.loadInfo.originAttributes = { firstPartyDomain: "bar.com" }; + var listener = new Http2PushListener(false); + chan.asyncOpen2(listener); +} + +function test_http2_push_firstparty3() { + var chan = makeChan("https://localhost:" + serverPort + "/push.js"); + chan.loadGroup = loadGroup; + chan.loadInfo.originAttributes = { firstPartyDomain: "foo.com" }; + var listener = new Http2PushListener(true); + chan.asyncOpen2(listener); +} + +function test_http2_push_userContext1() { + var chan = makeChan("https://localhost:" + serverPort + "/push"); + chan.loadGroup = loadGroup; + chan.loadInfo.originAttributes = { userContextId: 1 }; + var listener = new Http2PushListener(true); + chan.asyncOpen2(listener); +} + +function test_http2_push_userContext2() { + var chan = makeChan("https://localhost:" + serverPort + "/push.js"); + chan.loadGroup = loadGroup; + chan.loadInfo.originAttributes = { userContextId: 2 }; + var listener = new Http2PushListener(false); + chan.asyncOpen2(listener); +} + +function test_http2_push_userContext3() { + var chan = makeChan("https://localhost:" + serverPort + "/push.js"); + chan.loadGroup = loadGroup; + chan.loadInfo.originAttributes = { userContextId: 1 }; + var listener = new Http2PushListener(true); + chan.asyncOpen2(listener); +} + function test_complete() { resetPrefs(); do_test_pending(); @@ -951,6 +1001,12 @@ var tests = [ test_http2_post_big , test_http2_h11required_session , test_http2_retry_rst , test_http2_wrongsuite + , test_http2_push_firstparty1 + , test_http2_push_firstparty2 + , test_http2_push_firstparty3 + , test_http2_push_userContext1 + , test_http2_push_userContext2 + , test_http2_push_userContext3 // cleanup , test_complete diff --git a/testing/xpcshell/moz-http2/moz-http2.js b/testing/xpcshell/moz-http2/moz-http2.js index 760fef1ef37c..2759560836ff 100644 --- a/testing/xpcshell/moz-http2/moz-http2.js +++ b/testing/xpcshell/moz-http2/moz-http2.js @@ -277,6 +277,11 @@ function handleRequest(req, res) { content = '
body text'; } + else if (u.pathname === "/push.js") { + content = '// comments'; + res.setHeader("pushed", "no"); + } + else if (u.pathname === "/push2") { push = res.push('/push2.js'); push.writeHead(200, {