browser/devtools/scratchpad/test/browser_scratchpad_unsaved.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/scratchpad/test/browser_scratchpad_unsaved.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,121 @@
     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 +/* Bug 669612 */
     1.8 +
     1.9 +// only finish() when correct number of tests are done
    1.10 +const expected = 4;
    1.11 +var count = 0;
    1.12 +function done()
    1.13 +{
    1.14 +  if (++count == expected) {
    1.15 +    finish();
    1.16 +  }
    1.17 +}
    1.18 +
    1.19 +var ScratchpadManager = Scratchpad.ScratchpadManager;
    1.20 +
    1.21 +
    1.22 +function test()
    1.23 +{
    1.24 +  waitForExplicitFinish();
    1.25 +
    1.26 +  testListeners();
    1.27 +  testRestoreNotFromFile();
    1.28 +  testRestoreFromFileSaved();
    1.29 +  testRestoreFromFileUnsaved();
    1.30 +
    1.31 +  gBrowser.selectedTab = gBrowser.addTab();
    1.32 +  content.location = "data:text/html,<p>test star* UI for unsaved file changes";
    1.33 +}
    1.34 +
    1.35 +function testListeners()
    1.36 +{
    1.37 +  openScratchpad(function(aWin, aScratchpad) {
    1.38 +    aScratchpad.setText("new text");
    1.39 +    ok(isStar(aWin), "show star if scratchpad text changes");
    1.40 +
    1.41 +    aScratchpad.dirty = false;
    1.42 +    ok(!isStar(aWin), "no star before changing text");
    1.43 +
    1.44 +    aScratchpad.setFilename("foo.js");
    1.45 +    aScratchpad.setText("new text2");
    1.46 +    ok(isStar(aWin), "shows star if scratchpad text changes");
    1.47 +
    1.48 +    aScratchpad.dirty = false;
    1.49 +    ok(!isStar(aWin), "no star if scratchpad was just saved");
    1.50 +
    1.51 +    aScratchpad.setText("new text3");
    1.52 +    ok(isStar(aWin), "shows star if scratchpad has more changes");
    1.53 +
    1.54 +    aScratchpad.undo();
    1.55 +    ok(!isStar(aWin), "no star if scratchpad undo to save point");
    1.56 +
    1.57 +    aScratchpad.undo();
    1.58 +    ok(isStar(aWin), "star if scratchpad undo past save point");
    1.59 +
    1.60 +    aWin.close();
    1.61 +    done();
    1.62 +  }, {noFocus: true});
    1.63 +}
    1.64 +
    1.65 +function testRestoreNotFromFile()
    1.66 +{
    1.67 +  let session = [{
    1.68 +    text: "test1",
    1.69 +    executionContext: 1
    1.70 +  }];
    1.71 +
    1.72 +  let [win] = ScratchpadManager.restoreSession(session);
    1.73 +  openScratchpad(function(aWin, aScratchpad) {
    1.74 +    aScratchpad.setText("new text");
    1.75 +    ok(isStar(win), "show star if restored scratchpad isn't from a file");
    1.76 +
    1.77 +    win.close();
    1.78 +    done();
    1.79 +  }, {window: win, noFocus: true});
    1.80 +}
    1.81 +
    1.82 +function testRestoreFromFileSaved()
    1.83 +{
    1.84 +  let session = [{
    1.85 +    filename: "test.js",
    1.86 +    text: "test1",
    1.87 +    executionContext: 1,
    1.88 +    saved: true
    1.89 +  }];
    1.90 +
    1.91 +  let [win] = ScratchpadManager.restoreSession(session);
    1.92 +  openScratchpad(function(aWin, aScratchpad) {
    1.93 +    ok(!isStar(win), "no star before changing text in scratchpad restored from file");
    1.94 +
    1.95 +    aScratchpad.setText("new text");
    1.96 +    ok(isStar(win), "star when text changed from scratchpad restored from file");
    1.97 +
    1.98 +    win.close();
    1.99 +    done();
   1.100 +  }, {window: win, noFocus: true});
   1.101 +}
   1.102 +
   1.103 +function testRestoreFromFileUnsaved()
   1.104 +{
   1.105 +  let session = [{
   1.106 +    filename: "test.js",
   1.107 +    text: "test1",
   1.108 +    executionContext: 1,
   1.109 +    saved: false
   1.110 +  }];
   1.111 +
   1.112 +  let [win] = ScratchpadManager.restoreSession(session);
   1.113 +  openScratchpad(function() {
   1.114 +    ok(isStar(win), "star with scratchpad restored with unsaved text");
   1.115 +
   1.116 +    win.close();
   1.117 +    done();
   1.118 +  }, {window: win, noFocus: true});
   1.119 +}
   1.120 +
   1.121 +function isStar(win)
   1.122 +{
   1.123 +  return win.document.title.match(/^\*[^\*]/);
   1.124 +}

mercurial