Backout 034afcc038c9 (bug 771877) for mochitest-browser-chrome leaks

This commit is contained in:
Ed Morley 2012-07-09 10:09:56 +01:00
parent 1c0f854067
commit 178b2fd16c
8 changed files with 14 additions and 125 deletions

View File

@ -13,7 +13,6 @@ EXTRA_JS_MODULES = \
FrameWorker.jsm \
SocialService.jsm \
SocialProvider.jsm \
WorkerAPI.jsm \
$(NULL)
TEST_DIRS += \

View File

@ -8,7 +8,6 @@ const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/FrameWorker.jsm");
Cu.import("resource://gre/modules/WorkerAPI.jsm");
const EXPORTED_SYMBOLS = ["SocialProvider"];
@ -28,17 +27,13 @@ function SocialProvider(input) {
this.name = input.name;
this.workerURL = input.workerURL;
this.origin = input.origin;
let workerAPIPort = this.getWorkerPort();
if (workerAPIPort)
this.workerAPI = new WorkerAPI(workerAPIPort);
}
SocialProvider.prototype = {
/**
* Terminates the provider's FrameWorker, if it has one.
*/
terminate: function terminate() {
terminate: function shutdown() {
if (this.workerURL) {
try {
getFrameWorkerHandle(this.workerURL, null).terminate();
@ -59,11 +54,6 @@ SocialProvider.prototype = {
getWorkerPort: function getWorkerPort(window) {
if (!this.workerURL)
return null;
try {
return getFrameWorkerHandle(this.workerURL, window).port;
} catch (ex) {
Cu.reportError("SocialProvider: retrieving worker port failed:" + ex);
return null;
}
return getFrameWorkerHandle(this.workerURL, window).port;
}
}

View File

@ -25,10 +25,8 @@ XPCOMUtils.defineLazyGetter(SocialServiceInternal, "providers", function () {
providers[provider.origin] = provider;
}
} catch (err) {
let msg = "SocialService: failed to load provider: " + pref +
", exception: " + err;
Cu.reportError(msg);
dump(msg);
Cu.reportError("SocialService: failed to load provider: " + pref +
", exception: " + err);
}
}, this);

View File

@ -1,48 +0,0 @@
/* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
const EXPORTED_SYMBOLS = ["WorkerAPI"];
function WorkerAPI(port) {
if (!port)
throw new Error("Can't initialize WorkerAPI with a null port");
this._port = port;
this._port.onmessage = this._handleMessage.bind(this);
this.initialized = false;
// Send an "intro" message so the worker knows this is the port
// used for the api.
// later we might even include an API version - version 0 for now!
this._port.postMessage({topic: "social.initialize"});
}
WorkerAPI.prototype = {
_handleMessage: function _handleMessage(event) {
let {topic, data} = event.data;
let handler = this.handlers[topic];
if (!handler) {
Cu.reportError("WorkerAPI: topic doesn't have a handler: '" + topic + "'");
return;
}
try {
handler.call(this, data);
} catch (ex) {
Cu.reportError("WorkerAPI: failed to handle message '" + topic + "': " + ex);
}
},
handlers: {
"social.initialize-response": function (data) {
this.initialized = true;
}
}
}

View File

@ -15,15 +15,13 @@ include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES = \
head.js \
data.json \
worker_xhr.js \
browser_frameworker.js \
worker_relative.js \
relative_import.js \
browser_workerAPI.js \
worker_social.js \
$(NULL)
head.js \
data.json \
worker_xhr.js \
browser_frameworker.js \
worker_relative.js \
relative_import.js \
$(NULL)
libs:: $(_TEST_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)

View File

@ -1,33 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
let SocialProvider = Components.utils.import("resource://gre/modules/SocialProvider.jsm", {}).SocialProvider;
function test() {
waitForExplicitFinish();
// This test creates a SocialProvider object directly - it would be nicer to
// go through the SocialService, but adding a test provider before the service
// has been initialized can be tricky.
let provider = new SocialProvider({
origin: 'http://example.com',
name: "Example Provider",
workerURL: "http://example.com/browser/toolkit/components/social/test/browser/worker_social.js"
});
ok(provider.workerAPI, "provider has a workerAPI");
is(provider.workerAPI.initialized, false, "workerAPI is not yet initialized");
let port = provider.getWorkerPort();
ok(port, "should be able to get a port from the provider");
port.onmessage = function onMessage(event) {
let {topic, data} = event.data;
if (topic == "test-initialization-complete") {
is(provider.workerAPI.initialized, true, "workerAPI is now initialized");
finish();
}
}
port.postMessage({topic: "test-initialization"});
}

View File

@ -1,3 +1,5 @@
Cu.import("resource://gre/modules/Services.jsm");
// A helper to run a suite of tests.
// The "test object" should be an object with function names as keys and a
// function as the value. The functions will be called with a "cbnext" param
@ -46,3 +48,4 @@ function runTests(tests, cbPreTest, cbPostTest) {
}
runNextTest();
}

View File

@ -1,18 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
onconnect = function(e) {
let port = e.ports[0];
port.onmessage = function onMessage(event) {
let {topic, data} = event.data;
switch (topic) {
case "social.initialize":
port.postMessage({topic: "social.initialize-response"});
break;
case "test-initialization":
port.postMessage({topic: "test-initialization-complete"});
break;
}
}
}