Bug 1334690 - Test that AlternateService is isolated by origin attributes. r=mcmanus
authorJonathan Hao <jhao@mozilla.com>
Thu, 16 Feb 2017 17:50:55 +0800
changeset 343264 19cbf2e84f80b008832e4b17705aaa60e417b00f
parent 343263 b64ce70deb6f56bd2812791252b77ffdc68b9b24
child 343265 43e48c2dde488bbfe437289164265a9a7c5300fa
push id31374
push userkwierso@gmail.com
push dateThu, 16 Feb 2017 17:26:30 +0000
treeherdermozilla-central@4158b1d8bb2a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus
bugs1334690
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1334690 - Test that AlternateService is isolated by origin attributes. r=mcmanus MozReview-Commit-ID: 3e6eiB5roVt
netwerk/test/unit/test_altsvc.js
--- a/netwerk/test/unit/test_altsvc.js
+++ b/netwerk/test/unit/test_altsvc.js
@@ -140,16 +140,17 @@ function makeChan(origin) {
 
 var origin;
 var xaltsvc;
 var retryCounter = 0;
 var loadWithoutClearingMappings = false;
 var nextTest;
 var expectPass = true;
 var waitFor = 0;
+var originAttributes = {};
 
 var Listener = function() {};
 Listener.prototype = {
   onStartRequest: function testOnStartRequest(request, ctx) {
     do_check_true(request instanceof Components.interfaces.nsIHttpChannel);
 
     if (expectPass) {
       if (!Components.isSuccessCode(request.status)) {
@@ -217,16 +218,17 @@ function doTest()
   }
   if (loadWithoutClearingMappings) {
     chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
   } else {
     chan.loadFlags = Ci.nsIRequest.LOAD_FRESH_CONNECTION |
                      Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
   }
   loadWithoutClearingMappings = false;
+  chan.loadInfo.originAttributes = originAttributes;
   chan.asyncOpen2(listener);
 }
 
 // xaltsvc is overloaded to do two things..
 // 1] it is sent in the x-altsvc request header, and the response uses the value in the Alt-Svc response header
 // 2] the test polls until necko sets Alt-Used to that value (i.e. it uses that route)
 //
 // When xaltsvc is set to h2Route (i.e. :port with the implied hostname) it doesn't match the alt-used,
@@ -362,13 +364,80 @@ function doTest10()
 // is served
 function doTest11()
 {
   dump("doTest11()\n");
   origin = httpBarOrigin;
   xaltsvc = h2FooRoute;
   expectPass = true;
   waitFor = 500;
-  nextTest = testsDone;
+  nextTest = doTest12;
   do_test_pending();
   doTest();
 }
 
+// Test 12-15:
+// Insert a cache of http://foo served from h2=:port with origin attributes.
+function doTest12()
+{
+  dump("doTest12()\n");
+  origin = httpFooOrigin;
+  xaltsvc = h2Route;
+  originAttributes = {
+    userContextId: 1,
+    firstPartyDomain: "a.com",
+  };
+  nextTest = doTest13;
+  do_test_pending();
+  doTest();
+  xaltsvc = h2FooRoute;
+}
+
+// Make sure we get a cache miss with a different userContextId.
+function doTest13()
+{
+  dump("doTest13()\n");
+  origin = httpFooOrigin;
+  xaltsvc = 'NA';
+  originAttributes = {
+    userContextId: 2,
+    firstPartyDomain: "a.com",
+  };
+  loadWithoutClearingMappings = true;
+  nextTest = doTest14;
+  do_test_pending();
+  doTest();
+}
+
+// Make sure we get a cache miss with a different firstPartyDomain.
+function doTest14()
+{
+  dump("doTest14()\n");
+  origin = httpFooOrigin;
+  xaltsvc = 'NA';
+  originAttributes = {
+    userContextId: 1,
+    firstPartyDomain: "b.com",
+  };
+  loadWithoutClearingMappings = true;
+  nextTest = doTest15;
+  do_test_pending();
+  doTest();
+}
+//
+// Make sure we get a cache hit with the same origin attributes.
+function doTest15()
+{
+  dump("doTest15()\n");
+  origin = httpFooOrigin;
+  xaltsvc = 'NA';
+  originAttributes = {
+    userContextId: 1,
+    firstPartyDomain: "a.com",
+  };
+  loadWithoutClearingMappings = true;
+  nextTest = testsDone;
+  do_test_pending();
+  doTest();
+  // This ensures a cache hit.
+  xaltsvc = h2FooRoute;
+}
+