Bug 1240907 - Clean up code style in test-actor-registry.js. r=ochameau

MozReview-Commit-ID: GKAKgnVDimD
This commit is contained in:
J. Ryan Stinnett 2016-07-06 17:23:01 -05:00
Родитель 8d82d10366
Коммит efa881ac27
2 изменённых файлов: 31 добавлений и 38 удалений

Просмотреть файл

@ -99,6 +99,7 @@ devtools/client/shared/developer-toolbar.js
devtools/client/shared/components/test/** devtools/client/shared/components/test/**
devtools/client/shared/redux/middleware/test/** devtools/client/shared/redux/middleware/test/**
devtools/client/shared/test/** devtools/client/shared/test/**
!devtools/client/shared/test/test-actor-registry.js
devtools/client/shared/widgets/*.jsm devtools/client/shared/widgets/*.jsm
devtools/client/sourceeditor/** devtools/client/sourceeditor/**
devtools/client/webaudioeditor/** devtools/client/webaudioeditor/**

Просмотреть файл

@ -4,25 +4,20 @@
"use strict"; "use strict";
(function (exports) { (function (exports) {
const Cu = Components.utils;
const CC = Components.Constructor;
var Cu = Components.utils; const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
var Ci = Components.interfaces; const { fetch } = require("devtools/shared/DevToolsUtils");
var Cc = Components.classes; const defer = require("devtools/shared/defer");
var CC = Components.Constructor; const { Task } = require("devtools/shared/task");
var { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); const TEST_URL_ROOT = "http://example.com/browser/devtools/client/shared/test/";
var { NetUtil } = Cu.import("resource://gre/modules/NetUtil.jsm", {}); const ACTOR_URL = TEST_URL_ROOT + "test-actor.js";
var { fetch } = require("devtools/shared/DevToolsUtils");
var promise = require("promise");
var defer = require("devtools/shared/defer");
var TEST_URL_ROOT = "http://example.com/browser/devtools/client/shared/test/";
var ACTOR_URL = TEST_URL_ROOT + "test-actor.js";
// Register a test actor that can operate on the remote document // Register a test actor that can operate on the remote document
exports.registerTestActor = Task.async(function* (client) { exports.registerTestActor = Task.async(function* (client) {
// First, instanciate ActorRegistryFront to be able to dynamically // First, instanciate ActorRegistryFront to be able to dynamically register an actor
// register an actor
let deferred = defer(); let deferred = defer();
client.listTabs(deferred.resolve); client.listTabs(deferred.resolve);
let response = yield deferred.promise; let response = yield deferred.promise;
@ -39,13 +34,12 @@
return testActorFront; return testActorFront;
}); });
// Load the test actor in a custom sandbox // Load the test actor in a custom sandbox as we can't use SDK module loader with URIs
// as we can't use SDK module loader with URIs let loadFront = Task.async(function* () {
var loadFront = Task.async(function* () {
let sourceText = yield request(ACTOR_URL); let sourceText = yield request(ACTOR_URL);
const principal = CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(); const principal = CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")();
const sandbox = Cu.Sandbox(principal); const sandbox = Cu.Sandbox(principal);
const exports = sandbox.exports = {}; sandbox.exports = {};
sandbox.require = require; sandbox.require = require;
Cu.evalInSandbox(sourceText, sandbox, "1.8", ACTOR_URL, 1); Cu.evalInSandbox(sourceText, sandbox, "1.8", ACTOR_URL, 1);
return sandbox.exports; return sandbox.exports;
@ -53,7 +47,7 @@
// Ensure fetching a live TabActor form for the targeted app // Ensure fetching a live TabActor form for the targeted app
// (helps fetching the test actor registered dynamically) // (helps fetching the test actor registered dynamically)
var getUpdatedForm = function (client, tab) { let getUpdatedForm = function (client, tab) {
return client.getTab({tab: tab}) return client.getTab({tab: tab})
.then(response => response.tab); .then(response => response.tab);
}; };
@ -64,9 +58,8 @@
return getTestActor(client, toolbox.target.tab, toolbox); return getTestActor(client, toolbox.target.tab, toolbox);
}); });
// Sometimes, we need the test actor before opening or without a toolbox then just
// Sometimes, we need the test actor before opening or without a toolbox // create a front for the given `tab`
// then just create a front for the given `tab`
exports.getTestActorWithoutToolbox = Task.async(function* (tab) { exports.getTestActorWithoutToolbox = Task.async(function* (tab) {
let { DebuggerServer } = require("devtools/server/main"); let { DebuggerServer } = require("devtools/server/main");
let { DebuggerClient } = require("devtools/shared/client/main"); let { DebuggerClient } = require("devtools/shared/client/main");
@ -82,17 +75,17 @@
yield client.connect(); yield client.connect();
// We also need to make sure the test actor is registered on the server. // We also need to make sure the test actor is registered on the server.
yield registerTestActor(client); yield exports.registerTestActor(client);
return getTestActor(client, tab); return getTestActor(client, tab);
}); });
// Fetch the content of a URI // Fetch the content of a URI
var request = function (uri) { let request = function (uri) {
return fetch(uri).then(({ content }) => content); return fetch(uri).then(({ content }) => content);
}; };
var getTestActor = Task.async(function* (client, tab, toolbox) { let getTestActor = Task.async(function* (client, tab, toolbox) {
// We may have to update the form in order to get the dynamically registered // We may have to update the form in order to get the dynamically registered
// test actor. // test actor.
let form = yield getUpdatedForm(client, tab); let form = yield getUpdatedForm(client, tab);
@ -101,5 +94,4 @@
return new TestActorFront(client, form, toolbox); return new TestActorFront(client, form, toolbox);
}); });
})(this); })(this);