1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/scratchpad/test/browser_scratchpad_open.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 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 + 1.8 +// only finish() when correct number of tests are done 1.9 +const expected = 3; 1.10 +var count = 0; 1.11 +var lastUniqueName = null; 1.12 + 1.13 +function done() 1.14 +{ 1.15 + if (++count == expected) { 1.16 + finish(); 1.17 + } 1.18 +} 1.19 + 1.20 +function test() 1.21 +{ 1.22 + waitForExplicitFinish(); 1.23 + testOpen(); 1.24 + testOpenWithState(); 1.25 + testOpenInvalidState(); 1.26 +} 1.27 + 1.28 +function testUniqueName(name) 1.29 +{ 1.30 + ok(name, "Scratchpad has a uniqueName"); 1.31 + 1.32 + if (lastUniqueName === null) { 1.33 + lastUniqueName = name; 1.34 + return; 1.35 + } 1.36 + 1.37 + ok(name !== lastUniqueName, 1.38 + "Unique name for this instance differs from the last one."); 1.39 +} 1.40 + 1.41 +function testOpen() 1.42 +{ 1.43 + openScratchpad(function(win) { 1.44 + is(win.Scratchpad.filename, undefined, "Default filename is undefined"); 1.45 + isnot(win.Scratchpad.getText(), null, "Default text should not be null"); 1.46 + is(win.Scratchpad.executionContext, win.SCRATCHPAD_CONTEXT_CONTENT, 1.47 + "Default execution context is content"); 1.48 + testUniqueName(win.Scratchpad.uniqueName); 1.49 + 1.50 + win.close(); 1.51 + done(); 1.52 + }, {noFocus: true}); 1.53 +} 1.54 + 1.55 +function testOpenWithState() 1.56 +{ 1.57 + let state = { 1.58 + filename: "testfile", 1.59 + executionContext: 2, 1.60 + text: "test text" 1.61 + }; 1.62 + 1.63 + openScratchpad(function(win) { 1.64 + is(win.Scratchpad.filename, state.filename, "Filename loaded from state"); 1.65 + is(win.Scratchpad.executionContext, state.executionContext, "Execution context loaded from state"); 1.66 + is(win.Scratchpad.getText(), state.text, "Content loaded from state"); 1.67 + testUniqueName(win.Scratchpad.uniqueName); 1.68 + 1.69 + win.close(); 1.70 + done(); 1.71 + }, {state: state, noFocus: true}); 1.72 +} 1.73 + 1.74 +function testOpenInvalidState() 1.75 +{ 1.76 + let win = openScratchpad(null, {state: 7}); 1.77 + ok(!win, "no scratchpad opened if state is not an object"); 1.78 + done(); 1.79 +}