Bug 1334693 - Test http2 push and origin attributes. r=mcmanus
MozReview-Commit-ID: 8qrhjyyV6Uc
--- a/netwerk/test/unit/test_http2.js
+++ b/netwerk/test/unit/test_http2.js
@@ -143,27 +143,29 @@ Http2HeaderListener.prototype.onDataAvai
this.onDataAvailableFired = true;
this.isHttp2Connection = checkIsHttp2(request);
var hvalue = request.getResponseHeader(this.name);
do_check_neq(hvalue, "");
this.callback(hvalue);
read_stream(stream, cnt);
};
-var Http2PushListener = function() {};
+var Http2PushListener = function(shouldBePushed) {
+ this.shouldBePushed = shouldBePushed;
+};
Http2PushListener.prototype = new Http2CheckListener();
Http2PushListener.prototype.onDataAvailable = function(request, ctx, stream, off, cnt) {
this.onDataAvailableFired = true;
this.isHttp2Connection = checkIsHttp2(request);
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);
};
const pushHdrTxt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
const pullHdrTxt = pushHdrTxt.split('').reverse().join('');
function checkContinuedHeaders(getHeader, headerPrefix, headerText) {
@@ -487,52 +489,52 @@ function test_http2_cookie_crumbling() {
});
});
chan.asyncOpen2(listener);
}
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);
}
// this is a basic test where the server sends a simple document with 2 header
// blocks. bug 1027364
function test_http2_doubleheader() {
var chan = makeChan("https://localhost:" + serverPort + "/doubleheader");
var listener = new Http2CheckListener();
@@ -894,16 +896,64 @@ function test_http2_folded_header() {
}
function test_http2_empty_data() {
var chan = makeChan("https://localhost:" + serverPort + "/emptydata");
var listener = new Http2CheckListener();
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();
httpserv.stop(do_test_finished);
do_test_pending();
httpserv2.stop(do_test_finished);
do_test_finished();
@@ -946,16 +996,22 @@ var tests = [ test_http2_post_big
, test_http2_empty_data
// Add new tests above here - best to add new tests before h1
// streams get too involved
// These next two must always come in this order
, test_http2_h11required_stream
, 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
];
var current_test = 0;
function run_next_test() {
if (current_test < tests.length) {
--- a/testing/xpcshell/moz-http2/moz-http2.js
+++ b/testing/xpcshell/moz-http2/moz-http2.js
@@ -272,16 +272,21 @@ function handleRequest(req, res) {
'pushed' : 'yes',
'content-length' : 11,
'X-Connection-Http2': 'yes'
});
push.end('// comments');
content = '<head> <script src="push.js"/></head>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, {
'content-type': 'application/javascript',
'pushed' : 'yes',
// no content-length
'X-Connection-Http2': 'yes'
});