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: michael@0: // only finish() when correct number of tests are done michael@0: const expected = 3; michael@0: var count = 0; michael@0: var lastUniqueName = null; michael@0: michael@0: function done() michael@0: { michael@0: if (++count == expected) { michael@0: finish(); michael@0: } michael@0: } michael@0: michael@0: function test() michael@0: { michael@0: waitForExplicitFinish(); michael@0: testOpen(); michael@0: testOpenWithState(); michael@0: testOpenInvalidState(); michael@0: } michael@0: michael@0: function testUniqueName(name) michael@0: { michael@0: ok(name, "Scratchpad has a uniqueName"); michael@0: michael@0: if (lastUniqueName === null) { michael@0: lastUniqueName = name; michael@0: return; michael@0: } michael@0: michael@0: ok(name !== lastUniqueName, michael@0: "Unique name for this instance differs from the last one."); michael@0: } michael@0: michael@0: function testOpen() michael@0: { michael@0: openScratchpad(function(win) { michael@0: is(win.Scratchpad.filename, undefined, "Default filename is undefined"); michael@0: isnot(win.Scratchpad.getText(), null, "Default text should not be null"); michael@0: is(win.Scratchpad.executionContext, win.SCRATCHPAD_CONTEXT_CONTENT, michael@0: "Default execution context is content"); michael@0: testUniqueName(win.Scratchpad.uniqueName); michael@0: michael@0: win.close(); michael@0: done(); michael@0: }, {noFocus: true}); michael@0: } michael@0: michael@0: function testOpenWithState() michael@0: { michael@0: let state = { michael@0: filename: "testfile", michael@0: executionContext: 2, michael@0: text: "test text" michael@0: }; michael@0: michael@0: openScratchpad(function(win) { michael@0: is(win.Scratchpad.filename, state.filename, "Filename loaded from state"); michael@0: is(win.Scratchpad.executionContext, state.executionContext, "Execution context loaded from state"); michael@0: is(win.Scratchpad.getText(), state.text, "Content loaded from state"); michael@0: testUniqueName(win.Scratchpad.uniqueName); michael@0: michael@0: win.close(); michael@0: done(); michael@0: }, {state: state, noFocus: true}); michael@0: } michael@0: michael@0: function testOpenInvalidState() michael@0: { michael@0: let win = openScratchpad(null, {state: 7}); michael@0: ok(!win, "no scratchpad opened if state is not an object"); michael@0: done(); michael@0: }