Bug 1570279 - Some refactoring for test_objectgrips-17.js. r=ochameau
authorOriol Brufau <oriol-bugzilla@hotmail.com>
Wed, 31 Jul 2019 17:25:30 +0300
changeset 485833 7acf0e8d6a667761882ea445e22cf6e3b4abbb72
parent 485832 09384c51f12729d8daecc67af15453f70d3acce1
child 485834 4748c006ae7b7711a5f0c62459b5ce906b1a47f4
push id36374
push userrmaries@mozilla.com
push dateFri, 02 Aug 2019 03:53:17 +0000
treeherdermozilla-central@4748c006ae7b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1570279
milestone70.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 1570279 - Some refactoring for test_objectgrips-17.js. r=ochameau 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);
   }
 }
 
-// threadFrontTest uses systemPrincipal by default, but let's be explicit here.
-add_task(
-  threadFrontTest(
-    options => {
-      return run_tests_in_principal(options, systemPrincipal, true);
-    },
-    { principal: systemPrincipal, wantXrays: true }
-  )
-);
-add_task(
-  threadFrontTest(
-    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(
-  threadFrontTest(
-    options => {
-      return run_tests_in_principal(options, nullPrincipal, true);
-    },
-    { principal: nullPrincipal, wantXrays: true }
-  )
-);
-add_task(
-  threadFrontTest(
-    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(
+      threadFrontTest(
+        options => run_tests_in_principal(options, principal, wantXrays),
+        { principal, wantXrays }
+      )
+    );
+  }
+}