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

Commit

Permalink
Revert "Merge pull request #622 from erikvold/803065"
Browse files Browse the repository at this point in the history
This reverts commit f4291b6, reversing
changes made to 6f3344b.
  • Loading branch information
erikvold committed Oct 24, 2012
1 parent feb2a01 commit 062444b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 24 deletions.
57 changes: 41 additions & 16 deletions lib/sdk/test/runner.js
Expand Up @@ -10,13 +10,26 @@ var cfxArgs = require("@test/options");
var { Cc, Ci} = require("chrome");

function runTests(findAndRunTests) {
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Ci.nsIWindowWatcher);

let ns = 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul';
let msg = 'Running tests...';
let markup = '<?xml version="1.0"?><window xmlns="' + ns +
'" windowtype="test:runner"><label>' + msg + '</label></window>';
let url = "data:application/vnd.mozilla.xul+xml;charset=utf-8," + escape(markup);


var window = ww.openWindow(null, url, "harness", "centerscreen", null);

var harness = require("./harness");

function onDone(tests) {
stdout.write("\n");
var total = tests.passed + tests.failed;
stdout.write(tests.passed + " of " + total + " tests passed.\n");

window.close();
if (tests.failed == 0) {
if (tests.passed === 0)
stdout.write("No tests were run\n");
Expand All @@ -27,22 +40,34 @@ function runTests(findAndRunTests) {
}
};

// We may have to run test on next cycle, otherwise XPCOM components
// are not correctly updated.
// For ex: nsIFocusManager.getFocusedElementForWindow may throw
// NS_ERROR_ILLEGAL_VALUE exception.
require("../timers").setTimeout(function () {
harness.runTests({
findAndRunTests: findAndRunTests,
iterations: cfxArgs.iterations || 1,
filter: cfxArgs.filter,
profileMemory: cfxArgs.profileMemory,
stopOnError: cfxArgs.stopOnError,
verbose: cfxArgs.verbose,
print: stdout.write,
onDone: onDone
});
}, 0);
// We have to wait for this window to be fully loaded *and* focused
// in order to avoid it to mess with our various window/focus tests.
// We are first waiting for our window to be fully loaded before ensuring
// that it will take the focus, and then we wait for it to be focused.
window.addEventListener("load", function onload() {
window.removeEventListener("load", onload, true);

window.addEventListener("focus", function onfocus() {
window.removeEventListener("focus", onfocus, true);
// Finally, we have to run test on next cycle, otherwise XPCOM components
// are not correctly updated.
// For ex: nsIFocusManager.getFocusedElementForWindow may throw
// NS_ERROR_ILLEGAL_VALUE exception.
require("../timers").setTimeout(function () {
harness.runTests({
findAndRunTests: findAndRunTests,
iterations: cfxArgs.iterations || 1,
filter: cfxArgs.filter,
profileMemory: cfxArgs.profileMemory,
stopOnError: cfxArgs.stopOnError,
verbose: cfxArgs.verbose,
print: stdout.write,
onDone: onDone
});
}, 0);
}, true);
window.focus();
}, true);
}

function printFailedTests(tests, verbose, print) {
Expand Down
19 changes: 14 additions & 5 deletions test/test-window-utils.js
Expand Up @@ -236,6 +236,9 @@ exports['test window watcher without untracker'] = function(assert, done) {
};

exports['test active window'] = function(assert, done) {
let testRunnerWindow = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator)
.getMostRecentWindow("test:runner");
let browserWindow = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator)
.getMostRecentWindow("navigator:browser");
Expand All @@ -252,21 +255,26 @@ exports['test active window'] = function(assert, done) {
function() {
assert.equal(windowUtils.activeWindow, browserWindow,
"Correct active window [1]");
nextTest();
continueAfterFocus(windowUtils.activeWindow = testRunnerWindow);
},
function() {
assert.equal(windowUtils.activeWindow, testRunnerWindow,
"Correct active window [2]");
assert.equal(windowUtils.activeBrowserWindow, browserWindow,
"Correct active browser window [2]");
"Correct active browser window [3]");
continueAfterFocus(windowUtils.activeWindow = browserWindow);
},
function() {
assert.equal(windowUtils.activeWindow, browserWindow,
"Correct active window [3]");
nextTest();
"Correct active window [4]");
continueAfterFocus(windowUtils.activeWindow = testRunnerWindow);
},
function() {
assert.equal(windowUtils.activeWindow, testRunnerWindow,
"Correct active window [5]");
assert.equal(windowUtils.activeBrowserWindow, browserWindow,
"Correct active browser window [4]");
"Correct active browser window [6]");
testRunnerWindow = null;
browserWindow = null;
done();
}
Expand All @@ -280,6 +288,7 @@ exports['test active window'] = function(assert, done) {
}

function continueAfterFocus(targetWindow) {

// Based on SimpleTest.waitForFocus
var fm = Cc["@mozilla.org/focus-manager;1"].
getService(Ci.nsIFocusManager);
Expand Down
12 changes: 9 additions & 3 deletions test/windows/test-firefox-windows.js
Expand Up @@ -10,6 +10,8 @@ const wm = Cc['@mozilla.org/appshell/window-mediator;1'].
getService(Ci.nsIWindowMediator);
let browserWindows;

function getTestRunnerWindow() wm.getMostRecentWindow("test:runner");

// TEST: open & close window
exports.testOpenAndCloseWindow = function(test) {
test.waitUntilDone();
Expand Down Expand Up @@ -178,7 +180,7 @@ exports.testActiveWindow = function(test) {
let window2, window3;

// Raw window objects
let rawWindow2, rawWindow3;
let nonBrowserWindow = getTestRunnerWindow(), rawWindow2, rawWindow3;

test.waitUntilDone();

Expand All @@ -194,7 +196,8 @@ exports.testActiveWindow = function(test) {
continueAfterFocus(rawWindow2);
},
function() {
nextStep();
nonBrowserWindow.focus();
continueAfterFocus(nonBrowserWindow);
},
function() {
/**
Expand All @@ -220,6 +223,7 @@ exports.testActiveWindow = function(test) {
},
function() {
test.assertEqual(windows.activeWindow.title, window3.title, "Correct active window - 3");
nonBrowserWindow.focus();
finishTest();
}
];
Expand Down Expand Up @@ -249,6 +253,7 @@ exports.testActiveWindow = function(test) {
}

function continueAfterFocus(targetWindow) {

// Based on SimpleTest.waitForFocus
var fm = Cc["@mozilla.org/focus-manager;1"].
getService(Ci.nsIFocusManager);
Expand Down Expand Up @@ -331,12 +336,13 @@ exports.testTrackWindows = function(test) {

browserWindows.on("activate", function (window) {
let index = windows.indexOf(window);

actions.push("global activate " + index)
})

browserWindows.on("deactivate", function (window) {
let index = windows.indexOf(window);
if (index < 0) return;

actions.push("global deactivate " + index)
})

Expand Down

0 comments on commit 062444b

Please sign in to comment.