Bug 1570279 - Some refactoring for test_objectgrips-17.js. r=ochameau, a=test-only
authorOriol Brufau <oriol-bugzilla@hotmail.com>
Wed, 31 Jul 2019 17:25:30 +0300
changeset 523398 769165a6b1247bd97b0d790aedf27a758a30d0cf
parent 523397 d5c0e2bba0f880676c93c65593d7bed21186568c
child 523399 3391c3a28e1822a4b074e30c5ab2a2d8af4e8fd5
push id221
push userryanvm@gmail.com
push dateWed, 14 Aug 2019 12:28:44 +0000
treeherdermozilla-esr68@c11bf75afd18 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau, test-only
bugs1570279
milestone68.1.0
Bug 1570279 - Some refactoring for test_objectgrips-17.js. r=ochameau, a=test-only Differential Revision: https://phabricator.services.mozilla.com//D40023 Depends on D40022
devtools/server/tests/unit/test_objectgrips-17.js
--- a/devtools/server/tests/unit/test_objectgrips-17.js
+++ b/devtools/server/tests/unit/test_objectgrips-17.js
@@ -7,38 +7,38 @@
 Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
 
 registerCleanupFunction(() => {
   Services.prefs.clearUserPref("security.allow_eval_with_system_principal");
 });
 
 async function testPrincipal(options, globalPrincipal, debuggeeHasXrays) {
   const { debuggee } = options;
-  let global, subsumes, isOpaque, globalIsInvisible;
   // Create a global object with the specified security principal.
   // If none is specified, use the debuggee.
   if (globalPrincipal === undefined) {
-    global = debuggee;
-    subsumes = true;
-    isOpaque = false;
-    globalIsInvisible = false;
-    await test(options, { global, subsumes, isOpaque, globalIsInvisible });
+    await test(options, {
+      global: debuggee,
+      subsumes: true,
+      isOpaque: false,
+      globalIsInvisible: false,
+    });
     return;
   }
 
   const debuggeePrincipal = Cu.getObjectPrincipal(debuggee);
-  const sameOrigin = debuggeePrincipal === globalPrincipal;
-  subsumes = sameOrigin || debuggeePrincipal === systemPrincipal;
+  const sameOrigin = debuggeePrincipal.origin === globalPrincipal.origin;
+  const subsumes = debuggeePrincipal.subsumes(globalPrincipal);
   for (const globalHasXrays of [true, false]) {
-    isOpaque =
+    const isOpaque =
       subsumes &&
       globalPrincipal !== systemPrincipal &&
       ((sameOrigin && debuggeeHasXrays) || globalHasXrays);
-    for (globalIsInvisible of [true, false]) {
-      global = Cu.Sandbox(globalPrincipal, {
+    for (const globalIsInvisible of [true, false]) {
+      let global = Cu.Sandbox(globalPrincipal, {
         wantXrays: globalHasXrays,
         invisibleToDebugger: globalIsInvisible,
       });
       // Previously, the Sandbox constructor would (bizarrely) waive xrays on
       // the return Sandbox if wantXrays was false. This has now been fixed,
       // but we need to mimic that behavior here to make the test continue
       // to pass.
       if (!globalHasXrays) {
@@ -273,16 +273,20 @@ function check_prototype(
       proto
     );
   } else {
     // The debuggee is not allowed to access the object. It sees a null prototype.
     strictEqual(proto.type, "null", "The prototype is null.");
   }
 }
 
+function createNullPrincipal() {
+  return Cc["@mozilla.org/nullprincipal;1"].createInstance(Ci.nsIPrincipal);
+}
+
 async function run_tests_in_principal(
   options,
   debuggeePrincipal,
   debuggeeHasXrays
 ) {
   const { debuggee } = options;
   debuggee.eval(
     function stopMe(arg1, arg2) {
@@ -292,57 +296,26 @@ async function run_tests_in_principal(
 
   // Test objects created in the debuggee.
   await testPrincipal(options, undefined, debuggeeHasXrays);
 
   // Test objects created in a system principal new global.
   await testPrincipal(options, systemPrincipal, debuggeeHasXrays);
 
   // Test objects created in a cross-origin null principal new global.
-  await testPrincipal(options, null, debuggeeHasXrays);
+  await testPrincipal(options, createNullPrincipal(), debuggeeHasXrays);
 
-  if (debuggeePrincipal.isNullPrincipal) {
-    // Test objects created in a same-origin null principal new global.
-    await testPrincipal(
-      options,
-      Cu.getObjectPrincipal(debuggee),
-      debuggeeHasXrays
-    );
+  if (debuggeePrincipal != systemPrincipal) {
+    // Test objects created in a same-origin principal new global.
+    await testPrincipal(options, debuggeePrincipal, debuggeeHasXrays);
   }
 }
 
-// threadClientTest uses systemPrincipal by default, but let's be explicit here.
-add_task(
-  threadClientTest(
-    options => {
-      return run_tests_in_principal(options, systemPrincipal, true);
-    },
-    { principal: systemPrincipal, wantXrays: true }
-  )
-);
-add_task(
-  threadClientTest(
-    options => {
-      return run_tests_in_principal(options, systemPrincipal, false);
-    },
-    { principal: systemPrincipal, wantXrays: false }
-  )
-);
-
-const nullPrincipal = Cc["@mozilla.org/nullprincipal;1"].createInstance(
-  Ci.nsIPrincipal
-);
-add_task(
-  threadClientTest(
-    options => {
-      return run_tests_in_principal(options, nullPrincipal, true);
-    },
-    { principal: nullPrincipal, wantXrays: true }
-  )
-);
-add_task(
-  threadClientTest(
-    options => {
-      return run_tests_in_principal(options, nullPrincipal, false);
-    },
-    { principal: nullPrincipal, wantXrays: false }
-  )
-);
+for (const principal of [systemPrincipal, createNullPrincipal()]) {
+  for (const wantXrays of [true, false]) {
+    add_task(
+      threadClientTest(
+        options => run_tests_in_principal(options, principal, wantXrays),
+        { principal, wantXrays }
+      )
+    );
+  }
+}