browser/devtools/scratchpad/test/browser_scratchpad_execute_print.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/scratchpad/test/browser_scratchpad_execute_print.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,110 @@
     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 +function test()
     1.9 +{
    1.10 +  waitForExplicitFinish();
    1.11 +
    1.12 +  gBrowser.selectedTab = gBrowser.addTab();
    1.13 +  gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() {
    1.14 +    gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true);
    1.15 +    openScratchpad(runTests);
    1.16 +  }, true);
    1.17 +
    1.18 +  content.location = "data:text/html,<p>test run() and display() in Scratchpad";
    1.19 +}
    1.20 +
    1.21 +
    1.22 +function runTests()
    1.23 +{
    1.24 +  let sp = gScratchpadWindow.Scratchpad;
    1.25 +  let tests = [{
    1.26 +    method: "run",
    1.27 +    prepare: function() {
    1.28 +      content.wrappedJSObject.foobarBug636725 = 1;
    1.29 +      sp.editor.setText("++window.foobarBug636725");
    1.30 +    },
    1.31 +    then: function([code, , result]) {
    1.32 +      is(code, sp.getText(), "code is correct");
    1.33 +      is(result, content.wrappedJSObject.foobarBug636725,
    1.34 +         "result is correct");
    1.35 +
    1.36 +      is(sp.getText(), "++window.foobarBug636725",
    1.37 +         "run() does not change the editor content");
    1.38 +
    1.39 +      is(content.wrappedJSObject.foobarBug636725, 2,
    1.40 +         "run() updated window.foobarBug636725");
    1.41 +    }
    1.42 +  },
    1.43 +  {
    1.44 +    method: "display",
    1.45 +    prepare: function() {},
    1.46 +    then: function() {
    1.47 +      is(content.wrappedJSObject.foobarBug636725, 3,
    1.48 +         "display() updated window.foobarBug636725");
    1.49 +
    1.50 +      is(sp.getText(), "++window.foobarBug636725\n/*\n3\n*/",
    1.51 +         "display() shows evaluation result in the textbox");
    1.52 +
    1.53 +      is(sp.editor.getSelection(), "\n/*\n3\n*/", "getSelection is correct");
    1.54 +    }
    1.55 +  },
    1.56 +  {
    1.57 +    method: "run",
    1.58 +    prepare: function() {
    1.59 +      sp.editor.setText("window.foobarBug636725 = 'a';\n" +
    1.60 +        "window.foobarBug636725 = 'b';");
    1.61 +      sp.editor.setSelection({ line: 0, ch: 0 }, { line: 0, ch: 29 });
    1.62 +    },
    1.63 +    then: function([code, , result]) {
    1.64 +      is(code, "window.foobarBug636725 = 'a';", "code is correct");
    1.65 +      is(result, "a", "result is correct");
    1.66 +
    1.67 +      is(sp.getText(), "window.foobarBug636725 = 'a';\n" +
    1.68 +                       "window.foobarBug636725 = 'b';",
    1.69 +         "run() does not change the textbox value");
    1.70 +
    1.71 +      is(content.wrappedJSObject.foobarBug636725, "a",
    1.72 +         "run() worked for the selected range");
    1.73 +    }
    1.74 +  },
    1.75 +  {
    1.76 +    method: "display",
    1.77 +    prepare: function() {
    1.78 +      sp.editor.setText("window.foobarBug636725 = 'c';\n" +
    1.79 +                 "window.foobarBug636725 = 'b';");
    1.80 +      sp.editor.setSelection({ line: 0, ch: 0 }, { line: 0, ch: 22 });
    1.81 +    },
    1.82 +    then: function() {
    1.83 +      is(content.wrappedJSObject.foobarBug636725, "a",
    1.84 +         "display() worked for the selected range");
    1.85 +
    1.86 +      is(sp.getText(), "window.foobarBug636725" +
    1.87 +                       "\n/*\na\n*/" +
    1.88 +                       " = 'c';\n" +
    1.89 +                       "window.foobarBug636725 = 'b';",
    1.90 +         "display() shows evaluation result in the textbox");
    1.91 +
    1.92 +      is(sp.editor.getSelection(), "\n/*\na\n*/", "getSelection is correct");
    1.93 +    }
    1.94 +  }];
    1.95 +
    1.96 +  runAsyncCallbackTests(sp, tests).then(function() {
    1.97 +    ok(sp.editor.somethingSelected(), "something is selected");
    1.98 +    sp.editor.dropSelection();
    1.99 +    ok(!sp.editor.somethingSelected(), "something is no longer selected");
   1.100 +    ok(!sp.editor.getSelection(), "getSelection is empty");
   1.101 +
   1.102 +    // Test undo/redo.
   1.103 +    sp.editor.setText("foo1");
   1.104 +    sp.editor.setText("foo2");
   1.105 +    is(sp.getText(), "foo2", "editor content updated");
   1.106 +    sp.undo();
   1.107 +    is(sp.getText(), "foo1", "undo() works");
   1.108 +    sp.redo();
   1.109 +    is(sp.getText(), "foo2", "redo() works");
   1.110 +
   1.111 +    finish();
   1.112 +  });
   1.113 +}

mercurial