browser/devtools/styleeditor/test/browser_styleeditor_reload.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/styleeditor/test/browser_styleeditor_reload.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     1.4 +/* vim: set ts=2 et sw=2 tw=80: */
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +
     1.8 +const TESTCASE_URI = TEST_BASE_HTTPS + "simple.html";
     1.9 +const NEW_URI = TEST_BASE_HTTPS + "media.html";
    1.10 +
    1.11 +const LINE_NO = 5;
    1.12 +const COL_NO = 3;
    1.13 +
    1.14 +let gContentWin;
    1.15 +let gUI;
    1.16 +
    1.17 +function test()
    1.18 +{
    1.19 +  waitForExplicitFinish();
    1.20 +
    1.21 +  addTabAndOpenStyleEditors(2, function(panel) {
    1.22 +    gContentWin = gBrowser.selectedTab.linkedBrowser.contentWindow.wrappedJSObject;
    1.23 +    gUI = panel.UI;
    1.24 +    gUI.editors[0].getSourceEditor().then(runTests);
    1.25 +  });
    1.26 +
    1.27 +  content.location = TESTCASE_URI;
    1.28 +}
    1.29 +
    1.30 +function runTests()
    1.31 +{
    1.32 +  let count = 0;
    1.33 +  gUI.once("editor-selected", (event, editor) => {
    1.34 +    editor.getSourceEditor().then(() => {
    1.35 +      info("selected second editor, about to reload page");
    1.36 +      reloadPage();
    1.37 +
    1.38 +      gUI.on("editor-added", function editorAdded(event, editor) {
    1.39 +        if (++count == 2) {
    1.40 +          info("all editors added after reload");
    1.41 +          gUI.off("editor-added", editorAdded);
    1.42 +          gUI.editors[1].getSourceEditor().then(testRemembered);
    1.43 +        }
    1.44 +      })
    1.45 +    });
    1.46 +  });
    1.47 +  gUI.selectStyleSheet(gUI.editors[1].styleSheet.href, LINE_NO, COL_NO);
    1.48 +}
    1.49 +
    1.50 +function testRemembered()
    1.51 +{
    1.52 +  is(gUI.selectedEditor, gUI.editors[1], "second editor is selected");
    1.53 +
    1.54 +  let {line, ch} = gUI.selectedEditor.sourceEditor.getCursor();
    1.55 +  is(line, LINE_NO, "correct line selected");
    1.56 +  is(ch, COL_NO, "correct column selected");
    1.57 +
    1.58 +  testNewPage();
    1.59 +}
    1.60 +
    1.61 +function testNewPage()
    1.62 +{
    1.63 +  let count = 0;
    1.64 +  gUI.on("editor-added", function editorAdded(event, editor) {
    1.65 +    info("editor added here")
    1.66 +    if (++count == 2) {
    1.67 +      info("all editors added after navigating page");
    1.68 +      gUI.off("editor-added", editorAdded);
    1.69 +      gUI.editors[0].getSourceEditor().then(testNotRemembered);
    1.70 +    }
    1.71 +  })
    1.72 +
    1.73 +  info("navigating to a different page");
    1.74 +  navigatePage();
    1.75 +}
    1.76 +
    1.77 +function testNotRemembered()
    1.78 +{
    1.79 +  is(gUI.selectedEditor, gUI.editors[0], "first editor is selected");
    1.80 +
    1.81 +  let {line, ch} = gUI.selectedEditor.sourceEditor.getCursor();
    1.82 +  is(line, 0, "first line is selected");
    1.83 +  is(ch, 0, "first column is selected");
    1.84 +
    1.85 +  gUI = null;
    1.86 +  finish();
    1.87 +}
    1.88 +
    1.89 +function reloadPage()
    1.90 +{
    1.91 +  gContentWin.location.reload();
    1.92 +}
    1.93 +
    1.94 +function navigatePage()
    1.95 +{
    1.96 +  gContentWin.location = NEW_URI;
    1.97 +}

mercurial