browser/devtools/scratchpad/test/browser_scratchpad_open.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/ */
     5 // only finish() when correct number of tests are done
     6 const expected = 3;
     7 var count = 0;
     8 var lastUniqueName = null;
    10 function done()
    11 {
    12   if (++count == expected) {
    13     finish();
    14   }
    15 }
    17 function test()
    18 {
    19   waitForExplicitFinish();
    20   testOpen();
    21   testOpenWithState();
    22   testOpenInvalidState();
    23 }
    25 function testUniqueName(name)
    26 {
    27   ok(name, "Scratchpad has a uniqueName");
    29   if (lastUniqueName === null) {
    30     lastUniqueName = name;
    31     return;
    32   }
    34   ok(name !== lastUniqueName,
    35       "Unique name for this instance differs from the last one.");
    36 }
    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);
    47     win.close();
    48     done();
    49   }, {noFocus: true});
    50 }
    52 function testOpenWithState()
    53 {
    54   let state = {
    55     filename: "testfile",
    56     executionContext: 2,
    57     text: "test text"
    58   };
    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);
    66     win.close();
    67     done();
    68   }, {state: state, noFocus: true});
    69 }
    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