Bug 1034512 - Part 7: Avoid CPOW usage warnings in templater test with e10s. r=jwalker
authorPatrick Brosset <pbrosset@mozilla.com>
Mon, 26 Jan 2015 02:35:00 -0500
changeset 225651 394aac76bf6155eea3350e3890d5ece12fc14808
parent 225650 d1c55bb95e672872b3c7406abfe0bc3a1bc97096
child 225652 132b8377fb887d7e4025bcadf4fb9a22de841968
push id10991
push userryanvm@gmail.com
push dateMon, 26 Jan 2015 15:05:08 +0000
treeherderfx-team@252f2c47f271 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalker
bugs1034512
milestone38.0a1
Bug 1034512 - Part 7: Avoid CPOW usage warnings in templater test with e10s. r=jwalker
browser/devtools/shared/test/browser_templater_basic.js
--- a/browser/devtools/shared/test/browser_templater_basic.js
+++ b/browser/devtools/shared/test/browser_templater_basic.js
@@ -4,33 +4,33 @@
 // Tests that the DOM Template engine works properly
 
 /*
  * These tests run both in Mozilla/Mochitest and plain browsers (as does
  * domtemplate)
  * We should endevour to keep the source in sync.
  */
 
-var promise = Cu.import("resource://gre/modules/devtools/deprecated-sync-thenables.js", {}).Promise;
-var template = Cu.import("resource://gre/modules/devtools/Templater.jsm", {}).template;
+const template = Cu.import("resource://gre/modules/devtools/Templater.jsm", {}).template;
 
 const TEST_URI = TEST_URI_ROOT + "browser_templater_basic.html";
 
-function test() {
-  addTab(TEST_URI, function() {
-    info("Starting DOM Templater Tests");
-    runTest(0);
-  });
-}
+let test = Task.async(function*() {
+  yield promiseTab("about:blank");
+  let [host, win, doc] = yield createHost("bottom", TEST_URI);
 
-function runTest(index) {
+  info("Starting DOM Templater Tests");
+  runTest(0, host, doc);
+});
+
+function runTest(index, host, doc) {
   var options = tests[index] = tests[index]();
-  var holder = content.document.createElement('div');
+  var holder = doc.createElement('div');
   holder.id = options.name;
-  var body = content.document.body;
+  var body = doc.body;
   body.appendChild(holder);
   holder.innerHTML = options.template;
 
   info('Running ' + options.name);
   template(holder, options.data, options.options);
 
   if (typeof options.result == 'string') {
     is(holder.innerHTML, options.result, options.name);
@@ -42,20 +42,20 @@ function runTest(index) {
 
   if (options.also) {
     options.also(options);
   }
 
   function runNextTest() {
     index++;
     if (index < tests.length) {
-      runTest(index);
+      runTest(index, host, doc);
     }
     else {
-      finished();
+      finished(host);
     }
   }
 
   if (options.later) {
     var ais = is.bind(this);
 
     function createTester(holder, options) {
       return () => {
@@ -66,17 +66,18 @@ function runTest(index) {
 
     executeSoon(createTester(holder, options));
   }
   else {
     runNextTest();
   }
 }
 
-function finished() {
+function finished(host) {
+  host.destroy();
   gBrowser.removeCurrentTab();
   info("Finishing DOM Templater Tests");
   tests = null;
   finish();
 }
 
 /**
  * Why have an array of functions that return data rather than just an array
@@ -275,14 +276,10 @@ var tests = [
     template: '<div><p value="${nullvar}"></p><p value="${undefinedvar1}"></p><p value="${undefinedvar2}"></p></div>',
     data: { nullvar: null, undefinedvar1: undefined },
     options: { blankNullUndefined: true },
     result: '<div><p value=""></p><p value=""></p><p value=""></p></div>'
   };}
 ];
 
 function delayReply(data) {
-  var d = promise.defer();
-  executeSoon(function() {
-    d.resolve(data);
-  });
-  return d.promise;
+  return new Promise(resolve => resolve(data));
 }