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: /* Bug 669612 */ michael@0: michael@0: // only finish() when correct number of tests are done michael@0: const expected = 4; michael@0: var count = 0; michael@0: function done() michael@0: { michael@0: if (++count == expected) { michael@0: finish(); michael@0: } michael@0: } michael@0: michael@0: var ScratchpadManager = Scratchpad.ScratchpadManager; michael@0: michael@0: michael@0: function test() michael@0: { michael@0: waitForExplicitFinish(); michael@0: michael@0: testListeners(); michael@0: testRestoreNotFromFile(); michael@0: testRestoreFromFileSaved(); michael@0: testRestoreFromFileUnsaved(); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: content.location = "data:text/html,
test star* UI for unsaved file changes"; michael@0: } michael@0: michael@0: function testListeners() michael@0: { michael@0: openScratchpad(function(aWin, aScratchpad) { michael@0: aScratchpad.setText("new text"); michael@0: ok(isStar(aWin), "show star if scratchpad text changes"); michael@0: michael@0: aScratchpad.dirty = false; michael@0: ok(!isStar(aWin), "no star before changing text"); michael@0: michael@0: aScratchpad.setFilename("foo.js"); michael@0: aScratchpad.setText("new text2"); michael@0: ok(isStar(aWin), "shows star if scratchpad text changes"); michael@0: michael@0: aScratchpad.dirty = false; michael@0: ok(!isStar(aWin), "no star if scratchpad was just saved"); michael@0: michael@0: aScratchpad.setText("new text3"); michael@0: ok(isStar(aWin), "shows star if scratchpad has more changes"); michael@0: michael@0: aScratchpad.undo(); michael@0: ok(!isStar(aWin), "no star if scratchpad undo to save point"); michael@0: michael@0: aScratchpad.undo(); michael@0: ok(isStar(aWin), "star if scratchpad undo past save point"); michael@0: michael@0: aWin.close(); michael@0: done(); michael@0: }, {noFocus: true}); michael@0: } michael@0: michael@0: function testRestoreNotFromFile() michael@0: { michael@0: let session = [{ michael@0: text: "test1", michael@0: executionContext: 1 michael@0: }]; michael@0: michael@0: let [win] = ScratchpadManager.restoreSession(session); michael@0: openScratchpad(function(aWin, aScratchpad) { michael@0: aScratchpad.setText("new text"); michael@0: ok(isStar(win), "show star if restored scratchpad isn't from a file"); michael@0: michael@0: win.close(); michael@0: done(); michael@0: }, {window: win, noFocus: true}); michael@0: } michael@0: michael@0: function testRestoreFromFileSaved() michael@0: { michael@0: let session = [{ michael@0: filename: "test.js", michael@0: text: "test1", michael@0: executionContext: 1, michael@0: saved: true michael@0: }]; michael@0: michael@0: let [win] = ScratchpadManager.restoreSession(session); michael@0: openScratchpad(function(aWin, aScratchpad) { michael@0: ok(!isStar(win), "no star before changing text in scratchpad restored from file"); michael@0: michael@0: aScratchpad.setText("new text"); michael@0: ok(isStar(win), "star when text changed from scratchpad restored from file"); michael@0: michael@0: win.close(); michael@0: done(); michael@0: }, {window: win, noFocus: true}); michael@0: } michael@0: michael@0: function testRestoreFromFileUnsaved() michael@0: { michael@0: let session = [{ michael@0: filename: "test.js", michael@0: text: "test1", michael@0: executionContext: 1, michael@0: saved: false michael@0: }]; michael@0: michael@0: let [win] = ScratchpadManager.restoreSession(session); michael@0: openScratchpad(function() { michael@0: ok(isStar(win), "star with scratchpad restored with unsaved text"); michael@0: michael@0: win.close(); michael@0: done(); michael@0: }, {window: win, noFocus: true}); michael@0: } michael@0: michael@0: function isStar(win) michael@0: { michael@0: return win.document.title.match(/^\*[^\*]/); michael@0: }