mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 855180 - Intermittent browser_toolbar_webconsole_errors_count.js | Timed out while waiting for: web console shows the page errors followed by other timeouts, failures, leaks; r=jwalker
This commit is contained in:
parent
6b3cffaec9
commit
e3b75889e6
@ -36,6 +36,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "devtools",
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "require",
|
||||
"resource://gre/modules/devtools/Require.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "EventEmitter",
|
||||
"resource:///modules/devtools/shared/event-emitter.js");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "prefBranch", function() {
|
||||
let prefService = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefService);
|
||||
@ -215,6 +218,8 @@ this.DeveloperToolbar = function DeveloperToolbar(aChromeWindow, aToolbarElement
|
||||
this._errorCounterButton._defaultTooltipText =
|
||||
this._errorCounterButton.getAttribute("tooltiptext");
|
||||
|
||||
EventEmitter.decorate(this);
|
||||
|
||||
try {
|
||||
CmdCommands.refreshAutoCommands(aChromeWindow);
|
||||
}
|
||||
@ -675,6 +680,8 @@ function DT__updateErrorsCount(aChangedTabId)
|
||||
btn.removeAttribute("error-count");
|
||||
btn.setAttribute("tooltiptext", btn._defaultTooltipText);
|
||||
}
|
||||
|
||||
this.emit("errors-counter-updated");
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -7,18 +7,23 @@ function test() {
|
||||
const TEST_URI = "http://example.com/browser/browser/devtools/shared/test/" +
|
||||
"browser_toolbar_webconsole_errors_count.html";
|
||||
|
||||
let imported = {};
|
||||
Components.utils.import("resource:///modules/HUDService.jsm", imported);
|
||||
let HUDService = imported.HUDService;
|
||||
|
||||
Components.utils.import("resource:///modules/devtools/gDevTools.jsm", imported);
|
||||
let gDevTools = imported.gDevTools;
|
||||
let HUDService = Cu.import("resource:///modules/HUDService.jsm",
|
||||
{}).HUDService;
|
||||
let gDevTools = Cu.import("resource:///modules/devtools/gDevTools.jsm",
|
||||
{}).gDevTools;
|
||||
|
||||
let webconsole = document.getElementById("developer-toolbar-toolbox-button");
|
||||
let tab1, tab2;
|
||||
|
||||
Services.prefs.setBoolPref("javascript.options.strict", true);
|
||||
|
||||
registerCleanupFunction(() => {
|
||||
Services.prefs.clearUserPref("javascript.options.strict");
|
||||
});
|
||||
|
||||
ignoreAllUncaughtExceptions();
|
||||
addTab(TEST_URI, openToolbar);
|
||||
|
||||
function openToolbar(browser, tab) {
|
||||
tab1 = tab;
|
||||
ignoreAllUncaughtExceptions(false);
|
||||
@ -33,47 +38,6 @@ function test() {
|
||||
}
|
||||
}
|
||||
|
||||
ignoreAllUncaughtExceptions();
|
||||
addTab(TEST_URI, openToolbar);
|
||||
|
||||
function getErrorsCount() {
|
||||
let count = webconsole.getAttribute("error-count");
|
||||
return count ? count : "0";
|
||||
}
|
||||
|
||||
function getTooltipValues() {
|
||||
let matches = webconsole.getAttribute("tooltiptext")
|
||||
.match(/(\d+) errors?, (\d+) warnings?/);
|
||||
return matches ? [matches[1], matches[2]] : [0, 0];
|
||||
}
|
||||
|
||||
function waitForButtonUpdate(aOptions)
|
||||
{
|
||||
aOptions.validator = function() {
|
||||
let errors = getErrorsCount();
|
||||
let tooltip = getTooltipValues();
|
||||
let result = errors == aOptions.errors &&
|
||||
tooltip[1] == aOptions.warnings;
|
||||
if (result) {
|
||||
is(errors, tooltip[0], "button error-count is the same as in the tooltip");
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
let originalFailure = aOptions.failure;
|
||||
aOptions.failure = function() {
|
||||
let tooltip = getTooltipValues();
|
||||
|
||||
info("expected " + aOptions.errors + " errors, " +
|
||||
aOptions.warnings + " warnings");
|
||||
info("got " + tooltip[0] + " errors, " + tooltip[1] + " warnings");
|
||||
|
||||
originalFailure();
|
||||
};
|
||||
|
||||
waitForValue(aOptions);
|
||||
}
|
||||
|
||||
function onOpenToolbar() {
|
||||
ok(DeveloperToolbar.visible, "DeveloperToolbar is visible");
|
||||
|
||||
@ -81,8 +45,7 @@ function test() {
|
||||
name: "web console button shows page errors",
|
||||
errors: 3,
|
||||
warnings: 0,
|
||||
success: addErrors,
|
||||
failure: finish,
|
||||
callback: addErrors,
|
||||
});
|
||||
}
|
||||
|
||||
@ -100,11 +63,10 @@ function test() {
|
||||
name: "button shows one more error after click in page",
|
||||
errors: 4,
|
||||
warnings: 1,
|
||||
success: function() {
|
||||
callback: () => {
|
||||
ignoreAllUncaughtExceptions();
|
||||
addTab(TEST_URI, onOpenSecondTab);
|
||||
},
|
||||
failure: finish,
|
||||
});
|
||||
}
|
||||
|
||||
@ -118,8 +80,7 @@ function test() {
|
||||
name: "button shows correct number of errors after new tab is open",
|
||||
errors: 3,
|
||||
warnings: 0,
|
||||
success: switchToTab1,
|
||||
failure: finish,
|
||||
callback: switchToTab1,
|
||||
});
|
||||
}
|
||||
|
||||
@ -129,28 +90,10 @@ function test() {
|
||||
name: "button shows the page errors from tab 1",
|
||||
errors: 4,
|
||||
warnings: 1,
|
||||
success: function() {
|
||||
openWebConsole(tab1, onWebConsoleOpen);
|
||||
},
|
||||
failure: finish,
|
||||
callback: openWebConsole.bind(null, tab1, onWebConsoleOpen),
|
||||
});
|
||||
}
|
||||
|
||||
function openWebConsole(tab, callback)
|
||||
{
|
||||
function _onWebConsoleOpen(subject)
|
||||
{
|
||||
subject.QueryInterface(Ci.nsISupportsString);
|
||||
let hud = HUDService.getHudReferenceById(subject.data);
|
||||
executeSoon(callback.bind(null, hud));
|
||||
}
|
||||
|
||||
oneTimeObserve("web-console-created", _onWebConsoleOpen);
|
||||
|
||||
let target = TargetFactory.forTab(tab);
|
||||
gDevTools.showToolbox(target, "webconsole");
|
||||
}
|
||||
|
||||
function onWebConsoleOpen(hud) {
|
||||
waitForValue({
|
||||
name: "web console shows the page errors",
|
||||
@ -185,10 +128,7 @@ function test() {
|
||||
name: "button shows one more error after another click in page",
|
||||
errors: 5,
|
||||
warnings: 1, // warnings are not repeated by the js engine
|
||||
success: function() {
|
||||
waitForValue(waitForNewError);
|
||||
},
|
||||
failure: finish,
|
||||
callback: () => waitForValue(waitForNewError),
|
||||
});
|
||||
|
||||
let waitForNewError = {
|
||||
@ -216,24 +156,23 @@ function test() {
|
||||
}
|
||||
|
||||
function doPageReload(hud) {
|
||||
tab1.linkedBrowser.addEventListener("load", function _onReload() {
|
||||
tab1.linkedBrowser.removeEventListener("load", _onReload, true);
|
||||
ignoreAllUncaughtExceptions(false);
|
||||
expectUncaughtException();
|
||||
}, true);
|
||||
tab1.linkedBrowser.addEventListener("load", onReload, true);
|
||||
|
||||
ignoreAllUncaughtExceptions();
|
||||
content.location.reload();
|
||||
|
||||
waitForButtonUpdate({
|
||||
name: "the Web Console button count has been reset after page reload",
|
||||
errors: 3,
|
||||
warnings: 0,
|
||||
success: function() {
|
||||
waitForValue(waitForConsoleOutputAfterReload);
|
||||
},
|
||||
failure: finish,
|
||||
});
|
||||
function onReload() {
|
||||
tab1.linkedBrowser.removeEventListener("load", onReload, true);
|
||||
ignoreAllUncaughtExceptions(false);
|
||||
expectUncaughtException();
|
||||
|
||||
waitForButtonUpdate({
|
||||
name: "the Web Console button count has been reset after page reload",
|
||||
errors: 3,
|
||||
warnings: 0,
|
||||
callback: waitForValue.bind(null, waitForConsoleOutputAfterReload),
|
||||
});
|
||||
}
|
||||
|
||||
let waitForConsoleOutputAfterReload = {
|
||||
name: "the Web Console displays the correct number of errors after reload",
|
||||
@ -256,16 +195,51 @@ function test() {
|
||||
gDevTools.closeToolbox(target1);
|
||||
gBrowser.removeTab(tab1);
|
||||
gBrowser.removeTab(tab2);
|
||||
Services.prefs.clearUserPref("javascript.options.strict");
|
||||
finish();
|
||||
}
|
||||
|
||||
function oneTimeObserve(name, callback) {
|
||||
function _onObserve(aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(_onObserve, name);
|
||||
callback(aSubject, aTopic, aData);
|
||||
};
|
||||
Services.obs.addObserver(_onObserve, name, false);
|
||||
// Utility functions
|
||||
|
||||
function getErrorsCount() {
|
||||
let count = webconsole.getAttribute("error-count");
|
||||
return count ? count : "0";
|
||||
}
|
||||
|
||||
function getTooltipValues() {
|
||||
let matches = webconsole.getAttribute("tooltiptext")
|
||||
.match(/(\d+) errors?, (\d+) warnings?/);
|
||||
return matches ? [matches[1], matches[2]] : [0, 0];
|
||||
}
|
||||
|
||||
function waitForButtonUpdate(options) {
|
||||
function check() {
|
||||
let errors = getErrorsCount();
|
||||
let tooltip = getTooltipValues();
|
||||
let result = errors == options.errors && tooltip[1] == options.warnings;
|
||||
if (result) {
|
||||
ok(true, options.name);
|
||||
is(errors, tooltip[0], "button error-count is the same as in the tooltip");
|
||||
|
||||
// Get out of the toolbar event execution loop.
|
||||
executeSoon(options.callback);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!check()) {
|
||||
info("wait for: " + options.name);
|
||||
DeveloperToolbar.on("errors-counter-updated", function onUpdate(event) {
|
||||
if (check()) {
|
||||
DeveloperToolbar.off(event, onUpdate);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function openWebConsole(tab, callback)
|
||||
{
|
||||
let target = TargetFactory.forTab(tab);
|
||||
gDevTools.showToolbox(target, "webconsole").then((toolbox) =>
|
||||
callback(toolbox.getCurrentPanel().hud));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user