Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Bug 863456: Report failures for tests that leave unexpected tabs or w…
Browse files Browse the repository at this point in the history
…indows behind. r=ochameau
  • Loading branch information
Mossop committed Jul 25, 2013
1 parent 5f85500 commit d9d01d1
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 55 deletions.
31 changes: 29 additions & 2 deletions lib/sdk/deprecated/unit-test.js
Expand Up @@ -12,6 +12,8 @@ module.metadata = {
const memory = require('./memory');
var timer = require("../timers");
var cfxArgs = require("@test/options");
const { getTabs, getURI } = require("../tabs/utils");
const { windows, isBrowser } = require("../window/utils");

exports.findAndRunTests = function findAndRunTests(options) {
var TestFinder = require("./unit-test-finder").TestFinder;
Expand Down Expand Up @@ -279,14 +281,39 @@ TestRunner.prototype = {
this.failed++;
this.test.failed++;
}


let wins = windows(null, { includePrivate: true });
let tabs = [];
for (let win of wins.filter(isBrowser)) {
for (let tab of getTabs(win)) {
tabs.push(tab);
}
}

if (wins.length != 1)
this.fail("Should not be any unexpected windows open");
if (tabs.length != 1)
this.fail("Should not be any unexpected tabs open");
if (tabs.length != 1 || wins.length != 1) {
console.log("Windows open:");
for (let win of wins) {
if (isBrowser(win)) {
tabs = getTabs(win);
console.log(win.location + " - " + tabs.map(getURI).join(", "));
}
else {
console.log(win.location);
}
}
}

this.testRunSummary.push({
name: this.test.name,
passed: this.test.passed,
failed: this.test.failed,
errors: [error for (error in this.test.errors)].join(", ")
});

if (this.onDone !== null) {
var onDone = this.onDone;
var self = this;
Expand Down
2 changes: 1 addition & 1 deletion lib/sdk/tabs/utils.js
Expand Up @@ -67,7 +67,7 @@ function getTabs(window) {
return window.BrowserApp.tabs;

// firefox - default
return Array.slice(getTabContainer(window).children);
return Array.filter(getTabContainer(window).children, function(t) !t.closing);
}
exports.getTabs = getTabs;

Expand Down
45 changes: 16 additions & 29 deletions test/addons/private-browsing-supported/test-selection.js
Expand Up @@ -86,25 +86,6 @@ function open(url, options) {
return promise;
};

/**
* Close the Active Tab
*/
function close(window) {
let { promise, resolve } = defer();

if (window && typeof(window.close) === "function") {
closeWindow(window).then(function() resolve());
}
else {
// Here we assuming that the most recent browser window is the one we're
// doing the test, and the active tab is the one we just opened.
closeTab(getActiveTab(getMostRecentBrowserWindow()));
resolve();
}

return promise;
}

/**
* Reload the window given and return a promise, that will be resolved with the
* content window after a small delay.
Expand Down Expand Up @@ -249,7 +230,7 @@ exports["test PWPB Selection Listener"] = function(assert, done) {

assert.equal(selection.text, "fo");

close(window).
closeWindow(window).
then(loader.unload).
then(done, assert.fail);
});
Expand Down Expand Up @@ -278,7 +259,7 @@ exports["test PWPB Textarea OnSelect Listener"] = function(assert, done) {
focus(window).then(function() {
assert.equal(selection.text, "noodles");

close(window).
closeWindow(window).
then(loader.unload).
then(done, assert.fail);
});
Expand All @@ -296,7 +277,7 @@ exports["test PWPB Single DOM Selection"] = function(assert, done) {

open(URL, {private: true, title: "PWPB Single DOM Selection"}).
then(selectFirstDiv).
then(focus).then(function() {
then(focus).then(function(window) {
assert.equal(selection.isContiguous, true,
"selection.isContiguous with single DOM Selection works.");

Expand All @@ -319,7 +300,9 @@ exports["test PWPB Single DOM Selection"] = function(assert, done) {

assert.equal(selectionCount, 1,
"One iterable selection");
}).then(close).then(loader.unload).then(done, assert.fail);

return closeWindow(window);
}).then(loader.unload).then(done, assert.fail);
}

exports["test PWPB Textarea Selection"] = function(assert, done) {
Expand All @@ -329,7 +312,7 @@ exports["test PWPB Textarea Selection"] = function(assert, done) {
open(URL, {private: true, title: "PWPB Textarea Listener"}).
then(selectTextarea).
then(focus).
then(function() {
then(function(window) {

assert.equal(selection.isContiguous, true,
"selection.isContiguous with Textarea Selection works.");
Expand All @@ -354,7 +337,8 @@ exports["test PWPB Textarea Selection"] = function(assert, done) {
assert.equal(selectionCount, 1,
"One iterable selection");

}).then(close).then(loader.unload).then(done, assert.fail);
return closeWindow(window)
}).then(loader.unload).then(done, assert.fail);
};

exports["test PWPB Set HTML in Multiple DOM Selection"] = function(assert, done) {
Expand All @@ -364,7 +348,7 @@ exports["test PWPB Set HTML in Multiple DOM Selection"] = function(assert, done)
open(URL, {private: true, title: "PWPB Set HTML in Multiple DOM Selection"}).
then(selectAllDivs).
then(focus).
then(function() {
then(function(window) {
let html = "<span>b<b>a</b>r</span>";

let expectedText = ["bar", "and"];
Expand Down Expand Up @@ -392,7 +376,9 @@ exports["test PWPB Set HTML in Multiple DOM Selection"] = function(assert, done)

assert.equal(selectionCount, 2,
"Two iterable selections");
}).then(close).then(loader.unload).then(done, assert.fail);

return closeWindow(window);
}).then(loader.unload).then(done, assert.fail);
};

exports["test PWPB Set Text in Textarea Selection"] = function(assert, done) {
Expand All @@ -402,7 +388,7 @@ exports["test PWPB Set Text in Textarea Selection"] = function(assert, done) {
open(URL, {private: true, title: "test PWPB Set Text in Textarea Selection"}).
then(selectTextarea).
then(focus).
then(function() {
then(function(window) {

let text = "bar";

Expand All @@ -428,7 +414,8 @@ exports["test PWPB Set Text in Textarea Selection"] = function(assert, done) {
assert.equal(selectionCount, 1,
"One iterable selection");

}).then(close).then(loader.unload).then(done, assert.fail);
return closeWindow(window);
}).then(loader.unload).then(done, assert.fail);
};

// If the platform doesn't support the PBPW, we're replacing PBPW tests
Expand Down
37 changes: 34 additions & 3 deletions test/tabs/test-firefox-tabs.js
Expand Up @@ -299,6 +299,35 @@ exports.testTabMove = function(test) {
});
};

exports.testIgnoreClosing = function(test) {
test.waitUntilDone();
openBrowserWindow(function(window, browser) {
let tabs = require("sdk/tabs");
let url = "data:text/html;charset=utf-8,foobar";

test.assertEqual(tabs.length, 2, "should be two windows open each with one tab");

tabs.on('ready', function onReady(tab) {
tabs.removeListener('ready', onReady);

let win = tab.window;
test.assertEqual(win.tabs.length, 2, "should be two tabs in the new window");
test.assertEqual(tabs.length, 3, "should be three tabs in total");

tab.close(function() {
test.assertEqual(win.tabs.length, 1, "should be one tab in the new window");
test.assertEqual(tabs.length, 2, "should be two tabs in total");

closeBrowserWindow(window, function() {
test.done()
});
});
});

tabs.open(url);
});
};

// TEST: open tab with default options
exports.testOpen = function(test) {
test.waitUntilDone();
Expand Down Expand Up @@ -890,9 +919,11 @@ exports['test unique tab ids'] = function(test) {
var one = openWindow(), two = openWindow();
all([one, two]).then(function(results) {
test.assertNotEqual(results[0].id, results[1].id, "tab Ids should not be equal.");
results[0].win.close();
results[1].win.close();
test.done();
results[0].win.close(function() {
results[1].win.close(function () {
test.done();
});
});
});
}

Expand Down
3 changes: 1 addition & 2 deletions test/test-clipboard.js
Expand Up @@ -89,8 +89,7 @@ function comparePixelImages(imageA, imageB, callback) {
compared = pixels;
this.emit("draw-image", imageB);
} else {
callback(compared === pixels);
tab.close()
tab.close(callback.bind(null, compared === pixels))
}
});

Expand Down
36 changes: 18 additions & 18 deletions test/test-selection.js
Expand Up @@ -698,13 +698,13 @@ exports["test Selection Listener"] = function(assert, done) {

selection.once("select", function() {
assert.equal(selection.text, "fo");
close();
loader.unload();
done();
});

open(URL).then(selectContentFirstDiv).
then(dispatchSelectionEvent).
then(close).
then(loader.unload, assert.fail);
then(dispatchSelectionEvent, assert.fail);
};

exports["test Textarea OnSelect Listener"] = function(assert, done) {
Expand All @@ -713,13 +713,13 @@ exports["test Textarea OnSelect Listener"] = function(assert, done) {

selection.once("select", function() {
assert.equal(selection.text, "noodles");
close();
loader.unload();
done();
});

open(URL).then(selectTextarea).
then(dispatchOnSelectEvent).
then(close).
then(loader.unload, assert.fail);
then(dispatchOnSelectEvent, assert.fail);
};

exports["test Selection listener removed on unload"] = function(assert, done) {
Expand Down Expand Up @@ -769,14 +769,14 @@ exports["test Selection Listener on existing document"] = function(assert, done)

selection.once("select", function() {
assert.equal(selection.text, "fo");
close();
loader.unload();
done();
});

return window;
}).then(selectContentFirstDiv).
then(dispatchSelectionEvent).
then(close).
then(loader.unload, assert.fail);
then(dispatchSelectionEvent, assert.fail);
};


Expand All @@ -788,14 +788,14 @@ exports["test Textarea OnSelect Listener on existing document"] = function(asser

selection.once("select", function() {
assert.equal(selection.text, "noodles");
close();
loader.unload();
done();
});

return window;
}).then(selectTextarea).
then(dispatchOnSelectEvent).
then(close).
then(loader.unload, assert.fail);
then(dispatchOnSelectEvent, assert.fail);
};

exports["test Selection Listener on document reload"] = function(assert, done) {
Expand All @@ -804,15 +804,15 @@ exports["test Selection Listener on document reload"] = function(assert, done) {

selection.once("select", function() {
assert.equal(selection.text, "fo");
close();
loader.unload();
done();
});

open(URL).
then(reload).
then(selectContentFirstDiv).
then(dispatchSelectionEvent).
then(close).
then(loader.unload, assert.fail);
then(dispatchSelectionEvent, assert.fail);
};

exports["test Textarea OnSelect Listener on document reload"] = function(assert, done) {
Expand All @@ -821,15 +821,15 @@ exports["test Textarea OnSelect Listener on document reload"] = function(assert,

selection.once("select", function() {
assert.equal(selection.text, "noodles");
close();
loader.unload();
done();
});

open(URL).
then(reload).
then(selectTextarea).
then(dispatchOnSelectEvent).
then(close).
then(loader.unload, assert.fail);
then(dispatchOnSelectEvent, assert.fail);
};

exports["test Selection Listener on frame"] = function(assert, done) {
Expand Down

0 comments on commit d9d01d1

Please sign in to comment.