browser/devtools/scratchpad/test/browser_scratchpad_open.js

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

mercurial