michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: const TESTCASE_URI = TEST_BASE_HTTPS + "simple.html"; michael@0: const NEW_URI = TEST_BASE_HTTPS + "media.html"; michael@0: michael@0: const LINE_NO = 5; michael@0: const COL_NO = 3; michael@0: michael@0: let gContentWin; michael@0: let gUI; michael@0: michael@0: function test() michael@0: { michael@0: waitForExplicitFinish(); michael@0: michael@0: addTabAndOpenStyleEditors(2, function(panel) { michael@0: gContentWin = gBrowser.selectedTab.linkedBrowser.contentWindow.wrappedJSObject; michael@0: gUI = panel.UI; michael@0: gUI.editors[0].getSourceEditor().then(runTests); michael@0: }); michael@0: michael@0: content.location = TESTCASE_URI; michael@0: } michael@0: michael@0: function runTests() michael@0: { michael@0: let count = 0; michael@0: gUI.once("editor-selected", (event, editor) => { michael@0: editor.getSourceEditor().then(() => { michael@0: info("selected second editor, about to reload page"); michael@0: reloadPage(); michael@0: michael@0: gUI.on("editor-added", function editorAdded(event, editor) { michael@0: if (++count == 2) { michael@0: info("all editors added after reload"); michael@0: gUI.off("editor-added", editorAdded); michael@0: gUI.editors[1].getSourceEditor().then(testRemembered); michael@0: } michael@0: }) michael@0: }); michael@0: }); michael@0: gUI.selectStyleSheet(gUI.editors[1].styleSheet.href, LINE_NO, COL_NO); michael@0: } michael@0: michael@0: function testRemembered() michael@0: { michael@0: is(gUI.selectedEditor, gUI.editors[1], "second editor is selected"); michael@0: michael@0: let {line, ch} = gUI.selectedEditor.sourceEditor.getCursor(); michael@0: is(line, LINE_NO, "correct line selected"); michael@0: is(ch, COL_NO, "correct column selected"); michael@0: michael@0: testNewPage(); michael@0: } michael@0: michael@0: function testNewPage() michael@0: { michael@0: let count = 0; michael@0: gUI.on("editor-added", function editorAdded(event, editor) { michael@0: info("editor added here") michael@0: if (++count == 2) { michael@0: info("all editors added after navigating page"); michael@0: gUI.off("editor-added", editorAdded); michael@0: gUI.editors[0].getSourceEditor().then(testNotRemembered); michael@0: } michael@0: }) michael@0: michael@0: info("navigating to a different page"); michael@0: navigatePage(); michael@0: } michael@0: michael@0: function testNotRemembered() michael@0: { michael@0: is(gUI.selectedEditor, gUI.editors[0], "first editor is selected"); michael@0: michael@0: let {line, ch} = gUI.selectedEditor.sourceEditor.getCursor(); michael@0: is(line, 0, "first line is selected"); michael@0: is(ch, 0, "first column is selected"); michael@0: michael@0: gUI = null; michael@0: finish(); michael@0: } michael@0: michael@0: function reloadPage() michael@0: { michael@0: gContentWin.location.reload(); michael@0: } michael@0: michael@0: function navigatePage() michael@0: { michael@0: gContentWin.location = NEW_URI; michael@0: }