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 | |
michael@0 | 5 | // only finish() when correct number of tests are done |
michael@0 | 6 | const expected = 3; |
michael@0 | 7 | var count = 0; |
michael@0 | 8 | var lastUniqueName = null; |
michael@0 | 9 | |
michael@0 | 10 | function done() |
michael@0 | 11 | { |
michael@0 | 12 | if (++count == expected) { |
michael@0 | 13 | finish(); |
michael@0 | 14 | } |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | function test() |
michael@0 | 18 | { |
michael@0 | 19 | waitForExplicitFinish(); |
michael@0 | 20 | testOpen(); |
michael@0 | 21 | testOpenWithState(); |
michael@0 | 22 | testOpenInvalidState(); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | function testUniqueName(name) |
michael@0 | 26 | { |
michael@0 | 27 | ok(name, "Scratchpad has a uniqueName"); |
michael@0 | 28 | |
michael@0 | 29 | if (lastUniqueName === null) { |
michael@0 | 30 | lastUniqueName = name; |
michael@0 | 31 | return; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | ok(name !== lastUniqueName, |
michael@0 | 35 | "Unique name for this instance differs from the last one."); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | function testOpen() |
michael@0 | 39 | { |
michael@0 | 40 | openScratchpad(function(win) { |
michael@0 | 41 | is(win.Scratchpad.filename, undefined, "Default filename is undefined"); |
michael@0 | 42 | isnot(win.Scratchpad.getText(), null, "Default text should not be null"); |
michael@0 | 43 | is(win.Scratchpad.executionContext, win.SCRATCHPAD_CONTEXT_CONTENT, |
michael@0 | 44 | "Default execution context is content"); |
michael@0 | 45 | testUniqueName(win.Scratchpad.uniqueName); |
michael@0 | 46 | |
michael@0 | 47 | win.close(); |
michael@0 | 48 | done(); |
michael@0 | 49 | }, {noFocus: true}); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | function testOpenWithState() |
michael@0 | 53 | { |
michael@0 | 54 | let state = { |
michael@0 | 55 | filename: "testfile", |
michael@0 | 56 | executionContext: 2, |
michael@0 | 57 | text: "test text" |
michael@0 | 58 | }; |
michael@0 | 59 | |
michael@0 | 60 | openScratchpad(function(win) { |
michael@0 | 61 | is(win.Scratchpad.filename, state.filename, "Filename loaded from state"); |
michael@0 | 62 | is(win.Scratchpad.executionContext, state.executionContext, "Execution context loaded from state"); |
michael@0 | 63 | is(win.Scratchpad.getText(), state.text, "Content loaded from state"); |
michael@0 | 64 | testUniqueName(win.Scratchpad.uniqueName); |
michael@0 | 65 | |
michael@0 | 66 | win.close(); |
michael@0 | 67 | done(); |
michael@0 | 68 | }, {state: state, noFocus: true}); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | function testOpenInvalidState() |
michael@0 | 72 | { |
michael@0 | 73 | let win = openScratchpad(null, {state: 7}); |
michael@0 | 74 | ok(!win, "no scratchpad opened if state is not an object"); |
michael@0 | 75 | done(); |
michael@0 | 76 | } |