Bug 628458 - Fix for intermittent browser_webconsole_bug_603750_websocket.js | Test timed out followed by 2969 others; r=me

This commit is contained in:
Mihai Sucan 2013-06-07 15:36:55 +03:00
parent cc66e06834
commit cfae5fe3bc
2 changed files with 40 additions and 61 deletions

View File

@ -9,68 +9,31 @@
* ***** END LICENSE BLOCK ***** */
const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-bug-603750-websocket.html";
const pref_ws = "network.websocket.enabled";
const pref_block = "network.websocket.override-security-block";
let errors = 0;
let lastWindowId = 0;
let oldPref_ws;
let TestObserver = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
observe: function test_observe(aSubject)
{
if (!(aSubject instanceof Ci.nsIScriptError)) {
return;
}
is(aSubject.category, "Web Socket", "received a Web Socket error");
isnot(aSubject.sourceName.indexOf("test-bug-603750-websocket.js"), -1,
"sourceName is correct");
if (++errors == 2) {
executeSoon(performTest);
}
else {
lastWindowId = aSubject.outerWindowID;
}
}
};
function tabLoad(aEvent) {
browser.removeEventListener(aEvent.type, tabLoad, true);
openConsole(null, function(aHud) {
hud = aHud;
Services.console.registerListener(TestObserver);
content.location = TEST_URI;
});
}
function performTest() {
Services.console.unregisterListener(TestObserver);
Services.prefs.setBoolPref(pref_ws, oldPref_ws);
waitForSuccess({
name: "websocket error messages displayed",
validatorFn: function()
{
let textContent = hud.outputNode.textContent;
return textContent.indexOf("ws://0.0.0.0:81") > -1 &&
textContent.indexOf("ws://0.0.0.0:82") > -1;
},
successFn: finishTest,
failureFn: finishTest,
});
}
function test() {
oldPref_ws = Services.prefs.getBoolPref(pref_ws);
Services.prefs.setBoolPref(pref_ws, true);
addTab("data:text/html;charset=utf-8,Web Console test for bug 603750: Web Socket errors");
browser.addEventListener("load", tabLoad, true);
browser.addEventListener("load", function tabLoad() {
browser.removeEventListener("load", tabLoad, true);
openConsole(null, (hud) => {
content.location = TEST_URI;
info("waiting for websocket errors");
waitForMessages({
webconsole: hud,
messages: [
{
text: "ws://0.0.0.0:81",
source: { url: "test-bug-603750-websocket.js" },
category: CATEGORY_JS,
severity: SEVERITY_ERROR,
},
{
text: "ws://0.0.0.0:82",
source: { url: "test-bug-603750-websocket.js" },
category: CATEGORY_JS,
severity: SEVERITY_ERROR,
},
]}).then(finishTest);
});
}, true);
}

View File

@ -881,6 +881,8 @@ function getMessageElementText(aElement)
* message.
* - objects: boolean, set to |true| if you expect inspectable
* objects in the message.
* - source: object that can hold one property: url. This is used to
* match the source URL of the message.
* @return object
* A Promise object is returned once the messages you want are found.
* The promise is resolved with the array of rule objects you give in
@ -981,7 +983,7 @@ function waitForMessages(aOptions)
{
let elemText = getMessageElementText(aElement);
let time = aRule.consoleTimeEnd;
let regex = new RegExp(time + ": \\d+ms");
let regex = new RegExp(time + ": -?\\d+ms");
if (!checkText(regex, elemText)) {
return false;
@ -1013,6 +1015,16 @@ function waitForMessages(aOptions)
return true;
}
function checkSource(aRule, aElement)
{
let location = aElement.querySelector(".webconsole-location");
if (!location) {
return false;
}
return checkText(aRule.source.url, location.getAttribute("title"));
}
function checkMessage(aRule, aElement)
{
let elemText = getMessageElementText(aElement);
@ -1041,6 +1053,10 @@ function waitForMessages(aOptions)
return false;
}
if (aRule.source && !checkSource(aRule, aElement)) {
return false;
}
let partialMatch = !!(aRule.consoleTrace || aRule.consoleTime ||
aRule.consoleTimeEnd);