Bug 1147765 - Fix test failures caused by async initialization fixes. r=ejpbruel

This commit is contained in:
Sami Jaktholm 2015-03-21 14:12:58 +02:00
parent aa303414a5
commit 085a979136
8 changed files with 141 additions and 203 deletions

View File

@ -1,91 +1,44 @@
"use strict";
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
///////////////////
//
// Whitelisting this test.
// As part of bug 1077403, the leaking uncaught rejection should be fixed.
//
thisTestLeaksUncaughtRejectionsAndShouldBeFixed("TypeError: summary is undefined");
// Checks that style editor contains correct stylesheets after initialization.
const TESTCASE_URI = TEST_BASE_HTTP + "simple.html";
let gUI;
function test()
{
waitForExplicitFinish();
addTabAndCheckOnStyleEditorAdded(panel => gUI = panel.UI, testEditorAdded);
content.location = TESTCASE_URI;
}
let gEditorAddedCount = 0;
function testEditorAdded(aEditor)
{
if (aEditor.styleSheet.styleSheetIndex == 0) {
gEditorAddedCount++;
gUI.editors[0].getSourceEditor().then(testFirstStyleSheetEditor);
}
if (aEditor.styleSheet.styleSheetIndex == 1) {
gEditorAddedCount++;
testSecondStyleSheetEditor(aEditor);
const EXPECTED_SHEETS = [
{
sheetIndex: 0,
name: /^simple.css$/,
rules: 1,
active: true
}, {
sheetIndex: 1,
name: /^<.*>$/,
rules: 3,
active: false
}
];
if (gEditorAddedCount == 2) {
gUI = null;
finish();
}
}
add_task(function* () {
let { ui } = yield openStyleEditorForURL(TESTCASE_URI);
function testFirstStyleSheetEditor(aEditor)
{
// Note: the html <link> contains charset="UTF-8".
ok(aEditor._state.text.indexOf("\u263a") >= 0,
"stylesheet is unicode-aware.");
is(ui.editors.length, 2, "The UI contains two style sheets.");
checkSheet(ui.editors[0], EXPECTED_SHEETS[0]);
checkSheet(ui.editors[1], EXPECTED_SHEETS[1]);
});
//testing TESTCASE's simple.css stylesheet
is(aEditor.styleSheet.styleSheetIndex, 0,
"first stylesheet is at index 0");
is(aEditor, gUI.editors[0],
"first stylesheet corresponds to StyleEditorChrome.editors[0]");
let summary = aEditor.summary;
function checkSheet(editor, expected) {
is(editor.styleSheet.styleSheetIndex, expected.sheetIndex,
"Style sheet has correct index.");
let summary = editor.summary;
let name = summary.querySelector(".stylesheet-name > label").getAttribute("value");
is(name, "simple.css",
"first stylesheet's name is `simple.css`");
ok(expected.name.test(name), "The name '" + name + "' is correct.");
let ruleCount = summary.querySelector(".stylesheet-rule-count").textContent;
is(parseInt(ruleCount), 1,
"first stylesheet UI shows rule count as 1");
is(parseInt(ruleCount), expected.rules, "the rule count is correct");
ok(summary.classList.contains("splitview-active"),
"first stylesheet UI is focused/active");
}
function testSecondStyleSheetEditor(aEditor)
{
//testing TESTCASE's inline stylesheet
is(aEditor.styleSheet.styleSheetIndex, 1,
"second stylesheet is at index 1");
is(aEditor, gUI.editors[1],
"second stylesheet corresponds to StyleEditorChrome.editors[1]");
let summary = aEditor.summary;
let name = summary.querySelector(".stylesheet-name > label").getAttribute("value");
ok(/^<.*>$/.test(name),
"second stylesheet's name is surrounded by `<>`");
let ruleCount = summary.querySelector(".stylesheet-rule-count").textContent;
is(parseInt(ruleCount), 3,
"second stylesheet UI shows rule count as 3");
ok(!summary.classList.contains("splitview-active"),
"second stylesheet UI is NOT focused/active");
is(summary.classList.contains("splitview-active"), expected.active,
"The active status for this sheet is correct.");
}

View File

@ -15,14 +15,14 @@ waitForExplicitFinish();
add_task(function*() {
Services.prefs.setBoolPref(MAP_PREF, true);
let {UI} = yield addTabAndOpenStyleEditors(2, null, TESTCASE_URI);
let { ui } = yield openStyleEditorForURL(TESTCASE_URI);
yield listenForMediaChange(UI);
yield listenForMediaChange(ui);
is(UI.editors.length, 1, "correct number of editors");
is(ui.editors.length, 1, "correct number of editors");
// Test editor with @media rules
let mediaEditor = UI.editors[0];
let mediaEditor = ui.editors[0];
yield openEditor(mediaEditor);
testMediaEditor(mediaEditor);

View File

@ -5,48 +5,69 @@
// This test makes sure that the style editor does not store any
// content CSS files in the permanent cache when opened from PB mode.
function test() {
waitForExplicitFinish();
let gUI;
let testURI = 'http://' + TEST_HOST + '/browser/browser/devtools/styleeditor/test/test_private.html';
const TEST_URL = 'http://' + TEST_HOST + '/browser/browser/devtools/styleeditor/test/test_private.html';
const {LoadContextInfo} = Cu.import("resource://gre/modules/LoadContextInfo.jsm", {});
const cache = Cc["@mozilla.org/netwerk/cache-storage-service;1"]
.getService(Ci.nsICacheStorageService);
add_task(function* () {
info("Opening a new private window");
let win = OpenBrowserWindow({private: true});
win.addEventListener("load", function onLoad() {
win.removeEventListener("load", onLoad, false);
executeSoon(startTest);
}, false);
yield waitForDelayedStartupFinished(win);
function startTest() {
win.gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
win.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
info("Clearing the browser cache");
cache.clear();
info("Clearing the browser cache");
cache.clear();
let { ui } = yield openStyleEditorForURL(TEST_URL, win);
info("Opening the style editor in the private window");
openStyleEditorInWindow(win, function(panel) {
gUI = panel.UI;
gUI.on("editor-added", onEditorAdded);
});
}, true);
is(ui.editors.length, 1, "The style editor contains one sheet.");
let editor = ui.editors[0];
info("Loading the test URL in the new private window");
win.content.location = testURI;
}
yield editor.getSourceEditor();
yield checkDiskCacheFor(TEST_HOST);
win.close();
function onEditorAdded(aEvent, aEditor) {
info("The style editor is ready")
aEditor.getSourceEditor().then(checkCache);
}
});
function checkCache() {
checkDiskCacheFor(TEST_HOST, function() {
gUI.off("editor-added", onEditorAdded);
win.close();
win = null;
gUI = null;
finish();
});
}
function checkDiskCacheFor(host)
{
let foundPrivateData = false;
let deferred = promise.defer();
Visitor.prototype = {
onCacheStorageInfo: function(num, consumption)
{
info("disk storage contains " + num + " entries");
},
onCacheEntryInfo: function(uri)
{
var urispec = uri.asciiSpec;
info(urispec);
foundPrivateData |= urispec.contains(host);
},
onCacheEntryVisitCompleted: function()
{
is(foundPrivateData, false, "web content present in disk cache");
deferred.resolve();
}
};
function Visitor() {}
var storage = cache.diskCacheStorage(LoadContextInfo.default, false);
storage.asyncVisitStorage(new Visitor(), true /* Do walk entries */);
return deferred.promise;
}
function waitForDelayedStartupFinished(aWindow)
{
let deferred = promise.defer();
Services.obs.addObserver(function observer(aSubject, aTopic) {
if (aWindow == aSubject) {
Services.obs.removeObserver(observer, aTopic);
deferred.resolve();
}
}, "browser-delayed-startup-finished", false);
return deferred.promise;
}

View File

@ -10,13 +10,13 @@
const TESTCASE_URI = TEST_BASE_HTTPS + "sourcemaps-large.html";
add_task(function*() {
let {UI} = yield addTabAndOpenStyleEditors(2, null, TESTCASE_URI);
let { ui } = yield openStyleEditorForURL(TESTCASE_URI);
yield openEditor(UI.editors[0]);
let iframes = UI.selectedEditor.details.querySelectorAll("iframe");
yield openEditor(ui.editors[0]);
let iframes = ui.selectedEditor.details.querySelectorAll("iframe");
is (iframes.length, 1, "There is only one editor iframe");
ok (UI.selectedEditor.summary.classList.contains("splitview-active"),
ok (ui.selectedEditor.summary.classList.contains("splitview-active"),
"The editor is selected");
});
@ -28,4 +28,4 @@ function openEditor(editor) {
function getLinkFor(editor) {
return editor.summary.querySelector(".stylesheet-name");
}
}

View File

@ -32,7 +32,7 @@ function test()
Services.prefs.setBoolPref(TRANSITIONS_PREF, false);
Task.spawn(function() {
Task.spawn(function*() {
// copy all our files over so we don't screw them up for other tests
let HTMLFile = yield copy(TESTCASE_URI_HTML, ["sourcemaps.html"]);
let CSSFile = yield copy(TESTCASE_URI_CSS, ["sourcemap-css", "sourcemaps.css"]);
@ -43,7 +43,19 @@ function test()
let uri = Services.io.newFileURI(HTMLFile);
let testcaseURI = uri.resolve("");
let editor = yield openEditor(testcaseURI);
let { ui } = yield openStyleEditorForURL(testcaseURI);
let editor = ui.editors[1];
if (getStylesheetNameFor(editor) != TESTCASE_SCSS_NAME) {
editor = ui.editors[2];
}
is(getStylesheetNameFor(editor), TESTCASE_SCSS_NAME, "found scss editor");
let link = getLinkFor(editor);
link.click();
yield editor.getSourceEditor();
let element = content.document.querySelector("div");
let style = content.getComputedStyle(element, null);
@ -69,31 +81,6 @@ function test()
})
}
function openEditor(testcaseURI) {
let deferred = promise.defer();
addTabAndOpenStyleEditors(3, panel => {
let UI = panel.UI;
// wait for 5 editors - 1 for first style sheet, 2 for the
// generated style sheets, and 2 for original source after it
// loads and replaces the generated style sheets.
let editor = UI.editors[1];
if (getStylesheetNameFor(editor) != TESTCASE_SCSS_NAME) {
editor = UI.editors[2];
}
is(getStylesheetNameFor(editor), TESTCASE_SCSS_NAME, "found scss editor");
let link = getLinkFor(editor);
link.click();
editor.getSourceEditor().then(deferred.resolve);
});
content.location = testcaseURI;
return deferred.promise;
}
function editSCSS(editor) {
let deferred = promise.defer();

View File

@ -69,28 +69,28 @@ const origNames = ["sourcemaps.scss", "contained.scss", "test-stylus.styl"];
waitForExplicitFinish();
add_task(function*() {
let {UI} = yield addTabAndOpenStyleEditors(7, null, TESTCASE_URI);
let {ui} = yield openStyleEditorForURL(TESTCASE_URI);
is(UI.editors.length, 4,
is(ui.editors.length, 4,
"correct number of editors with source maps enabled");
// Test first plain css editor
testFirstEditor(UI.editors[0]);
testFirstEditor(ui.editors[0]);
// Test Scss editors
yield testEditor(UI.editors[1], origNames);
yield testEditor(UI.editors[2], origNames);
yield testEditor(UI.editors[3], origNames);
yield testEditor(ui.editors[1], origNames);
yield testEditor(ui.editors[2], origNames);
yield testEditor(ui.editors[3], origNames);
// Test disabling original sources
yield togglePref(UI);
yield togglePref(ui);
is(UI.editors.length, 4, "correct number of editors after pref toggled");
is(ui.editors.length, 4, "correct number of editors after pref toggled");
// Test CSS editors
yield testEditor(UI.editors[1], cssNames);
yield testEditor(UI.editors[2], cssNames);
yield testEditor(UI.editors[3], cssNames);
yield testEditor(ui.editors[1], cssNames);
yield testEditor(ui.editors[2], cssNames);
yield testEditor(ui.editors[3], cssNames);
Services.prefs.clearUserPref(PREF);
});
@ -116,16 +116,7 @@ function testEditor(editor, possibleNames) {
/* Helpers */
function togglePref(UI) {
let deferred = promise.defer();
let count = 0;
UI.on("editor-added", (event, editor) => {
if (++count == 3) {
deferred.resolve();
}
})
let editorsPromise = deferred.promise;
let editorsPromise = UI.once("stylesheets-reset");
let selectedPromise = UI.once("editor-selected");
Services.prefs.setBoolPref(PREF, false);

View File

@ -14,7 +14,6 @@ add_task(function*() {
let toolbox = yield gDevTools.showToolbox(target, "styleeditor");
let panel = toolbox.getCurrentPanel();
yield panel.UI.once("editor-added");
ok(panel, "The style-editor panel did initialize correctly for the XUL window");
});

View File

@ -8,13 +8,10 @@ const TEST_HOST = 'mochi.test:8888';
let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
let TargetFactory = devtools.TargetFactory;
let {LoadContextInfo} = Cu.import("resource://gre/modules/LoadContextInfo.jsm", {});
let {console} = Cu.import("resource://gre/modules/devtools/Console.jsm", {});
let {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
let gPanelWindow;
let cache = Cc["@mozilla.org/netwerk/cache-storage-service;1"]
.getService(Ci.nsICacheStorageService);
// Import the GCLI test helper
@ -29,19 +26,22 @@ SimpleTest.registerCleanupFunction(() => {
/**
* Add a new test tab in the browser and load the given url.
* @param {String} url The url to be loaded in the new tab
* @param {Window} win The window to add the tab to (default: current window).
* @return a promise that resolves to the tab object when the url is loaded
*/
function addTab(url) {
function addTab(url, win) {
info("Adding a new tab with URL: '" + url + "'");
let def = promise.defer();
let tab = gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function onload() {
gBrowser.selectedBrowser.removeEventListener("load", onload, true);
let targetWindow = win || window;
let targetBrowser = targetWindow.gBrowser;
let tab = targetBrowser.selectedTab = targetBrowser.addTab(url);
targetBrowser.selectedBrowser.addEventListener("load", function onload() {
targetBrowser.selectedBrowser.removeEventListener("load", onload, true);
info("URL '" + url + "' loading complete");
def.resolve(tab);
}, true);
content.location = url;
return def.promise;
}
@ -72,6 +72,20 @@ function* cleanup()
}
}
/**
* Creates a new tab in specified window navigates it to the given URL and
* opens style editor in it.
*/
let openStyleEditorForURL = Task.async(function* (url, win) {
let tab = yield addTab(url, win);
let target = TargetFactory.forTab(tab);
let toolbox = yield gDevTools.showToolbox(target, "styleeditor");
let panel = toolbox.getPanel("styleeditor");
let ui = panel.UI;
return { tab, toolbox, panel, ui };
});
function addTabAndOpenStyleEditors(count, callback, uri) {
let deferred = promise.defer();
let currentCount = 0;
@ -122,31 +136,4 @@ function openStyleEditorInWindow(win, callback) {
});
}
function checkDiskCacheFor(host, done)
{
let foundPrivateData = false;
Visitor.prototype = {
onCacheStorageInfo: function(num, consumption)
{
info("disk storage contains " + num + " entries");
},
onCacheEntryInfo: function(uri)
{
var urispec = uri.asciiSpec;
info(urispec);
foundPrivateData |= urispec.contains(host);
},
onCacheEntryVisitCompleted: function()
{
is(foundPrivateData, false, "web content present in disk cache");
done();
}
};
function Visitor() {}
var storage = cache.diskCacheStorage(LoadContextInfo.default, false);
storage.asyncVisitStorage(new Visitor(), true /* Do walk entries */);
}
registerCleanupFunction(cleanup);