Bug 1312954 - Part 7: Updating the tests of network predictor. r?nwgh draft
authorTim Huang <tihuang@mozilla.com>
Thu, 19 Jan 2017 16:03:14 +0800
changeset 466001 3ee0792aff15c78ab6182ff2b054e3f6cf357e65
parent 466000 f6af67709bfe253fe1e6458525508005bb246559
child 466002 30516e772f3cf5d9fc0258cf7f9de204443dbb92
push id42767
push userbmo:tihuang@mozilla.com
push dateWed, 25 Jan 2017 04:18:41 +0000
reviewersnwgh
bugs1312954
milestone54.0a1
Bug 1312954 - Part 7: Updating the tests of network predictor. r?nwgh
netwerk/test/unit/test_predictor.js
--- a/netwerk/test/unit/test_predictor.js
+++ b/netwerk/test/unit/test_predictor.js
@@ -19,39 +19,17 @@ function is_child_process() {
 function extract_origin(uri) {
   var o = uri.scheme + "://" + uri.asciiHost;
   if (uri.port !== -1) {
     o = o + ":" + uri.port;
   }
   return o;
 }
 
-var LoadContext = function _loadContext() {
-};
-
-LoadContext.prototype = {
-  usePrivateBrowsing: false,
-
-  getInterface: function loadContext_getInterface(iid) {
-    return this.QueryInterface(iid);
-  },
-
-  QueryInterface: function loadContext_QueryInterface(iid) {
-    if (iid.equals(Ci.nsINetworkPredictorVerifier) ||
-        iid.equals(Ci.nsILoadContext)) {
-      return this;
-    }
-
-    throw Cr.NS_ERROR_NO_INTERFACE;
-  },
-
-  originAttributes: {}
-};
-
-var load_context = new LoadContext();
+var origin_attributes = {};
 
 var ValidityChecker = function(verifier, httpStatus) {
   this.verifier = verifier;
   this.httpStatus = httpStatus;
 };
 
 ValidityChecker.prototype = {
   verifier: null,
@@ -218,39 +196,39 @@ function test_link_hover() {
     return;
   }
 
   var uri = newURI("http://localhost:4444/foo/bar");
   var referrer = newURI("http://localhost:4444/foo");
   var preconns = ["http://localhost:4444"];
 
   var verifier = new Verifier("hover", [], preconns, []);
-  predictor.predict(uri, referrer, predictor.PREDICT_LINK, load_context, verifier);
+  predictor.predict(uri, referrer, predictor.PREDICT_LINK, origin_attributes, verifier);
 }
 
 const pageload_toplevel = newURI("http://localhost:4444/index.html");
 
 function continue_test_pageload() {
   var subresources = [
     "http://localhost:4444/style.css",
     "http://localhost:4443/jquery.js",
     "http://localhost:4444/image.png"
   ];
 
   // This is necessary to learn the origin stuff
-  predictor.learn(pageload_toplevel, null, predictor.LEARN_LOAD_TOPLEVEL, load_context);
+  predictor.learn(pageload_toplevel, null, predictor.LEARN_LOAD_TOPLEVEL, origin_attributes);
   var preconns = [];
   for (var i = 0; i < subresources.length; i++) {
     var sruri = newURI(subresources[i]);
-    predictor.learn(sruri, pageload_toplevel, predictor.LEARN_LOAD_SUBRESOURCE, load_context);
+    predictor.learn(sruri, pageload_toplevel, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);
     preconns.push(extract_origin(sruri));
   }
 
   var verifier = new Verifier("pageload", [], preconns, []);
-  predictor.predict(pageload_toplevel, null, predictor.PREDICT_LOAD, load_context, verifier);
+  predictor.predict(pageload_toplevel, null, predictor.PREDICT_LOAD, origin_attributes, verifier);
 }
 
 function test_pageload() {
   open_and_continue([pageload_toplevel], function () {
     if (running_single_process) {
       continue_test_pageload();
     } else {
       sendCommand("continue_test_pageload();");
@@ -263,30 +241,30 @@ const redirect_targeturi = newURI("http:
 
 function continue_test_redrect() {
   var subresources = [
     "http://localhost:4444/style.css",
     "http://localhost:4443/jquery.js",
     "http://localhost:4444/image.png"
   ];
 
-  predictor.learn(redirect_inituri, null, predictor.LEARN_LOAD_TOPLEVEL, load_context);
-  predictor.learn(redirect_targeturi, null, predictor.LEARN_LOAD_TOPLEVEL, load_context);
-  predictor.learn(redirect_targeturi, redirect_inituri, predictor.LEARN_LOAD_REDIRECT, load_context);
+  predictor.learn(redirect_inituri, null, predictor.LEARN_LOAD_TOPLEVEL, origin_attributes);
+  predictor.learn(redirect_targeturi, null, predictor.LEARN_LOAD_TOPLEVEL, origin_attributes);
+  predictor.learn(redirect_targeturi, redirect_inituri, predictor.LEARN_LOAD_REDIRECT, origin_attributes);
 
   var preconns = [];
   preconns.push(extract_origin(redirect_targeturi));
   for (var i = 0; i < subresources.length; i++) {
     var sruri = newURI(subresources[i]);
-    predictor.learn(sruri, redirect_targeturi, predictor.LEARN_LOAD_SUBRESOURCE, load_context);
+    predictor.learn(sruri, redirect_targeturi, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);
     preconns.push(extract_origin(sruri));
   }
 
   var verifier = new Verifier("redirect", [], preconns, []);
-  predictor.predict(redirect_inituri, null, predictor.PREDICT_LOAD, load_context, verifier);
+  predictor.predict(redirect_inituri, null, predictor.PREDICT_LOAD, origin_attributes, verifier);
 }
 
 function test_redirect() {
   open_and_continue([redirect_inituri, redirect_targeturi], function () {
     if (running_single_process) {
       continue_test_redirect();
     } else {
       sendCommand("continue_test_redirect();");
@@ -304,36 +282,36 @@ function test_startup() {
 
   var uris = [
     "http://localhost:4444/startup",
     "http://localhost:4443/startup"
   ];
   var preconns = [];
   for (var i = 0; i < uris.length; i++) {
     var uri = newURI(uris[i]);
-    predictor.learn(uri, null, predictor.LEARN_STARTUP, load_context);
+    predictor.learn(uri, null, predictor.LEARN_STARTUP, origin_attributes);
     preconns.push(extract_origin(uri));
   }
 
   var verifier = new Verifier("startup", [], preconns, []);
-  predictor.predict(null, null, predictor.PREDICT_STARTUP, load_context, verifier);
+  predictor.predict(null, null, predictor.PREDICT_STARTUP, origin_attributes, verifier);
 }
 
 const dns_toplevel = newURI("http://localhost:4444/index.html");
 
 function continue_test_dns() {
   var subresource = "http://localhost:4443/jquery.js";
 
-  predictor.learn(dns_toplevel, null, predictor.LEARN_LOAD_TOPLEVEL, load_context);
+  predictor.learn(dns_toplevel, null, predictor.LEARN_LOAD_TOPLEVEL, origin_attributes);
   var sruri = newURI(subresource);
-  predictor.learn(sruri, dns_toplevel, predictor.LEARN_LOAD_SUBRESOURCE, load_context);
+  predictor.learn(sruri, dns_toplevel, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);
 
   var preresolves = [extract_origin(sruri)];
   var verifier = new Verifier("dns", [], [], preresolves);
-  predictor.predict(dns_toplevel, null, predictor.PREDICT_LOAD, load_context, verifier);
+  predictor.predict(dns_toplevel, null, predictor.PREDICT_LOAD, origin_attributes, verifier);
 }
 
 function test_dns() {
   open_and_continue([dns_toplevel], function () {
     // Ensure that this will do preresolves
     Services.prefs.setIntPref("network.predictor.preconnect-min-confidence", 101);
     if (running_single_process) {
       continue_test_dns();
@@ -346,30 +324,30 @@ function test_dns() {
 const origin_toplevel = newURI("http://localhost:4444/index.html");
 
 function continue_test_origin() {
   var subresources = [
     "http://localhost:4444/style.css",
     "http://localhost:4443/jquery.js",
     "http://localhost:4444/image.png"
   ];
-  predictor.learn(origin_toplevel, null, predictor.LEARN_LOAD_TOPLEVEL, load_context);
+  predictor.learn(origin_toplevel, null, predictor.LEARN_LOAD_TOPLEVEL, origin_attributes);
   var preconns = [];
   for (var i = 0; i < subresources.length; i++) {
     var sruri = newURI(subresources[i]);
-    predictor.learn(sruri, origin_toplevel, predictor.LEARN_LOAD_SUBRESOURCE, load_context);
+    predictor.learn(sruri, origin_toplevel, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);
     var origin = extract_origin(sruri);
     if (preconns.indexOf(origin) === -1) {
       preconns.push(origin);
     }
   }
 
   var loaduri = newURI("http://localhost:4444/anotherpage.html");
   var verifier = new Verifier("origin", [], preconns, []);
-  predictor.predict(loaduri, null, predictor.PREDICT_LOAD, load_context, verifier);
+  predictor.predict(loaduri, null, predictor.PREDICT_LOAD, origin_attributes, verifier);
 }
 
 function test_origin() {
   open_and_continue([origin_toplevel], function () {
     if (running_single_process) {
       continue_test_origin();
     } else {
       sendCommand("continue_test_origin();");
@@ -448,21 +426,21 @@ function test_prefetch_prime() {
   if (!running_single_process) {
     dump("skipping test_prefetch_prime due to e10s\n");
     run_next_test();
     return;
   }
 
   open_and_continue([prefetch_tluri], function() {
     if (running_single_process) {
-      predictor.learn(prefetch_tluri, null, predictor.LEARN_LOAD_TOPLEVEL, load_context);
-      predictor.learn(prefetch_sruri, prefetch_tluri, predictor.LEARN_LOAD_SUBRESOURCE, load_context);
+      predictor.learn(prefetch_tluri, null, predictor.LEARN_LOAD_TOPLEVEL, origin_attributes);
+      predictor.learn(prefetch_sruri, prefetch_tluri, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);
     } else {
-      sendCommand("predictor.learn(prefetch_tluri, null, predictor.LEARN_LOAD_TOPLEVEL, load_context);");
-      sendCommand("predictor.learn(prefetch_sruri, prefetch_tluri, predictor.LEARN_LOAD_SUBRESOURCE, load_context);");
+      sendCommand("predictor.learn(prefetch_tluri, null, predictor.LEARN_LOAD_TOPLEVEL, origin_attributes);");
+      sendCommand("predictor.learn(prefetch_sruri, prefetch_tluri, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);");
     }
 
     // This runs in the parent or only process
     var channel = NetUtil.newChannel({
       uri: prefetch_sruri.asciiSpec,
       loadUsingSystemPrincipal: true
     }).QueryInterface(Ci.nsIHttpChannel);
     channel.requestMethod = "GET";
@@ -488,17 +466,17 @@ function test_prefetch() {
   } else {
     sendCommand("continue_test_prefetch();");
   }
 }
 
 function continue_test_prefetch() {
   var prefetches = [prefetch_sruri.asciiSpec];
   var verifier = new Verifier("prefetch", prefetches, [], []);
-  predictor.predict(prefetch_tluri, null, predictor.PREDICT_LOAD, load_context, verifier);
+  predictor.predict(prefetch_tluri, null, predictor.PREDICT_LOAD, origin_attributes, verifier);
 }
 
 function cleanup() {
   observer.cleaningUp = true;
   if (running_single_process) {
     // The http server is required (and started) by the prefetch test, which
     // only runs in single-process mode, so don't try to shut it down if we're
     // in e10s mode.