Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 2 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 4 | /* Bug 669612 */ |
michael@0 | 5 | |
michael@0 | 6 | // only finish() when correct number of tests are done |
michael@0 | 7 | const expected = 4; |
michael@0 | 8 | var count = 0; |
michael@0 | 9 | function done() |
michael@0 | 10 | { |
michael@0 | 11 | if (++count == expected) { |
michael@0 | 12 | finish(); |
michael@0 | 13 | } |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | var ScratchpadManager = Scratchpad.ScratchpadManager; |
michael@0 | 17 | |
michael@0 | 18 | |
michael@0 | 19 | function test() |
michael@0 | 20 | { |
michael@0 | 21 | waitForExplicitFinish(); |
michael@0 | 22 | |
michael@0 | 23 | testListeners(); |
michael@0 | 24 | testRestoreNotFromFile(); |
michael@0 | 25 | testRestoreFromFileSaved(); |
michael@0 | 26 | testRestoreFromFileUnsaved(); |
michael@0 | 27 | |
michael@0 | 28 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 29 | content.location = "data:text/html,<p>test star* UI for unsaved file changes"; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | function testListeners() |
michael@0 | 33 | { |
michael@0 | 34 | openScratchpad(function(aWin, aScratchpad) { |
michael@0 | 35 | aScratchpad.setText("new text"); |
michael@0 | 36 | ok(isStar(aWin), "show star if scratchpad text changes"); |
michael@0 | 37 | |
michael@0 | 38 | aScratchpad.dirty = false; |
michael@0 | 39 | ok(!isStar(aWin), "no star before changing text"); |
michael@0 | 40 | |
michael@0 | 41 | aScratchpad.setFilename("foo.js"); |
michael@0 | 42 | aScratchpad.setText("new text2"); |
michael@0 | 43 | ok(isStar(aWin), "shows star if scratchpad text changes"); |
michael@0 | 44 | |
michael@0 | 45 | aScratchpad.dirty = false; |
michael@0 | 46 | ok(!isStar(aWin), "no star if scratchpad was just saved"); |
michael@0 | 47 | |
michael@0 | 48 | aScratchpad.setText("new text3"); |
michael@0 | 49 | ok(isStar(aWin), "shows star if scratchpad has more changes"); |
michael@0 | 50 | |
michael@0 | 51 | aScratchpad.undo(); |
michael@0 | 52 | ok(!isStar(aWin), "no star if scratchpad undo to save point"); |
michael@0 | 53 | |
michael@0 | 54 | aScratchpad.undo(); |
michael@0 | 55 | ok(isStar(aWin), "star if scratchpad undo past save point"); |
michael@0 | 56 | |
michael@0 | 57 | aWin.close(); |
michael@0 | 58 | done(); |
michael@0 | 59 | }, {noFocus: true}); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | function testRestoreNotFromFile() |
michael@0 | 63 | { |
michael@0 | 64 | let session = [{ |
michael@0 | 65 | text: "test1", |
michael@0 | 66 | executionContext: 1 |
michael@0 | 67 | }]; |
michael@0 | 68 | |
michael@0 | 69 | let [win] = ScratchpadManager.restoreSession(session); |
michael@0 | 70 | openScratchpad(function(aWin, aScratchpad) { |
michael@0 | 71 | aScratchpad.setText("new text"); |
michael@0 | 72 | ok(isStar(win), "show star if restored scratchpad isn't from a file"); |
michael@0 | 73 | |
michael@0 | 74 | win.close(); |
michael@0 | 75 | done(); |
michael@0 | 76 | }, {window: win, noFocus: true}); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | function testRestoreFromFileSaved() |
michael@0 | 80 | { |
michael@0 | 81 | let session = [{ |
michael@0 | 82 | filename: "test.js", |
michael@0 | 83 | text: "test1", |
michael@0 | 84 | executionContext: 1, |
michael@0 | 85 | saved: true |
michael@0 | 86 | }]; |
michael@0 | 87 | |
michael@0 | 88 | let [win] = ScratchpadManager.restoreSession(session); |
michael@0 | 89 | openScratchpad(function(aWin, aScratchpad) { |
michael@0 | 90 | ok(!isStar(win), "no star before changing text in scratchpad restored from file"); |
michael@0 | 91 | |
michael@0 | 92 | aScratchpad.setText("new text"); |
michael@0 | 93 | ok(isStar(win), "star when text changed from scratchpad restored from file"); |
michael@0 | 94 | |
michael@0 | 95 | win.close(); |
michael@0 | 96 | done(); |
michael@0 | 97 | }, {window: win, noFocus: true}); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | function testRestoreFromFileUnsaved() |
michael@0 | 101 | { |
michael@0 | 102 | let session = [{ |
michael@0 | 103 | filename: "test.js", |
michael@0 | 104 | text: "test1", |
michael@0 | 105 | executionContext: 1, |
michael@0 | 106 | saved: false |
michael@0 | 107 | }]; |
michael@0 | 108 | |
michael@0 | 109 | let [win] = ScratchpadManager.restoreSession(session); |
michael@0 | 110 | openScratchpad(function() { |
michael@0 | 111 | ok(isStar(win), "star with scratchpad restored with unsaved text"); |
michael@0 | 112 | |
michael@0 | 113 | win.close(); |
michael@0 | 114 | done(); |
michael@0 | 115 | }, {window: win, noFocus: true}); |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | function isStar(win) |
michael@0 | 119 | { |
michael@0 | 120 | return win.document.title.match(/^\*[^\*]/); |
michael@0 | 121 | } |