Bug 1234179 - Use DTU.fetch() to load test-actor source in Markup View and Inspector tests. r?ochameau
The current request() method in test-actor-registry.js uses a
deprecated API to fetch the source for the test actor which leads to
failed assertions in debug tests. Since the DevToolsUtils module already
contains a fetch method that doesn't use the deprecated APIs, there's
no reason to duplicate the functionality in test-actor-registry.js.
This changeset replaces the old source fetching code from test-actor-
registry.js with a call to DevToolsUtils.fetch() that uses the NetUtil
APIs in an up-to-date fashion.
--- a/devtools/client/shared/test/test-actor-registry.js
+++ b/devtools/client/shared/test/test-actor-registry.js
@@ -7,16 +7,17 @@
var Cu = Components.utils;
var Ci = Components.interfaces;
var Cc = Components.classes;
var CC = Components.Constructor;
var { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
var { NetUtil } = Cu.import("resource://gre/modules/NetUtil.jsm", {});
+var { fetch } = require("devtools/shared/DevToolsUtils");
var promise = require("promise");
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
exports.registerTestActor = Task.async(function* (client) {
// First, instanciate ActorRegistryFront to be able to dynamically
@@ -81,37 +82,17 @@ exports.getTestActorWithoutToolbox = Tas
client.connect(deferred.resolve);
yield deferred.promise;
return getTestActor(client, tab);
});
// Fetch the content of a URI
var request = function (uri) {
- let deferred = promise.defer();
- try {
- uri = Services.io.newURI(uri, null, null);
- } catch (e) {
- deferred.reject(e);
- }
-
- NetUtil.asyncFetch(uri, (stream, status, req) => {
- if (!Components.isSuccessCode(status)) {
- deferred.reject(new Error("Request failed with status code = "
- + status
- + " after NetUtil.asyncFetch for url = "
- + uri.spec));
- return;
- }
-
- let source = NetUtil.readInputStreamToString(stream, stream.available());
- stream.close();
- deferred.resolve(source);
- });
- return deferred.promise;
+ return fetch(uri).then(({ content }) => content);
}
var getTestActor = Task.async(function* (client, tab, toolbox) {
// We may have to update the form in order to get the dynamically registered
// test actor.
let form = yield getUpdatedForm(client, tab);
let { TestActorFront } = yield loadFront();