browser/devtools/scratchpad/test/browser_scratchpad_modeline.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/ */
     4 /* Bug 644413 */
     6 let tempScope = {};
     7 Cu.import("resource://gre/modules/NetUtil.jsm", tempScope);
     8 Cu.import("resource://gre/modules/FileUtils.jsm", tempScope);
     9 let NetUtil = tempScope.NetUtil;
    10 let FileUtils = tempScope.FileUtils;
    13 let gScratchpad; // Reference to the Scratchpad object.
    14 let gFile; // Reference to the temporary nsIFile we will work with.
    15 let DEVTOOLS_CHROME_ENABLED = "devtools.chrome.enabled";
    17 // The temporary file content.
    18 let gFileContent = "function main() { return 0; }";
    20 function test() {
    21   waitForExplicitFinish();
    23   gBrowser.selectedTab = gBrowser.addTab();
    24   gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
    25     gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
    26     openScratchpad(runTests);
    27   }, true);
    29   content.location = "data:text/html,<p>test file open and save in Scratchpad";
    30 }
    32 function runTests() {
    33   gScratchpad = gScratchpadWindow.Scratchpad;
    34   function size(obj) { return Object.keys(obj).length; }
    36   // Test Scratchpad._scanModeLine method.
    37   let obj = gScratchpad._scanModeLine();
    38   is(size(obj), 0, "Mode-line object has no properties");
    40   obj = gScratchpad._scanModeLine("/* This is not a mode-line comment */");
    41   is(size(obj), 0, "Mode-line object has no properties");
    43   obj = gScratchpad._scanModeLine("/* -sp-context:browser */");
    44   is(size(obj), 1, "Mode-line object has one property");
    45   is(obj["-sp-context"], "browser");
    47   obj = gScratchpad._scanModeLine("/* -sp-context: browser */");
    48   is(size(obj), 1, "Mode-line object has one property");
    49   is(obj["-sp-context"], "browser");
    51   obj = gScratchpad._scanModeLine("// -sp-context: browser");
    52   is(size(obj), 1, "Mode-line object has one property");
    53   is(obj["-sp-context"], "browser");
    55   obj = gScratchpad._scanModeLine("/* -sp-context:browser, other:true */");
    56   is(size(obj), 2, "Mode-line object has two properties");
    57   is(obj["-sp-context"], "browser");
    58   is(obj["other"], "true");
    60   // Test importing files with a mode-line in them.
    61   let content = "/* -sp-context:browser */\n" + gFileContent;
    62   createTempFile("fileForBug644413.tmp", content, function(aStatus, aFile) {
    63     ok(Components.isSuccessCode(aStatus), "File was saved successfully");
    65     gFile = aFile;
    66     gScratchpad.importFromFile(gFile.QueryInterface(Ci.nsILocalFile), true, fileImported);
    67   });
    68 }
    70 function fileImported(status, content) {
    71   ok(Components.isSuccessCode(status), "File was imported successfully");
    73   // Since devtools.chrome.enabled is off, Scratchpad should still be in
    74   // the content context.
    75   is(gScratchpad.executionContext, gScratchpadWindow.SCRATCHPAD_CONTEXT_CONTENT);
    77   // Set the pref and try again.
    78   Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, true);
    80   gScratchpad.importFromFile(gFile.QueryInterface(Ci.nsILocalFile), true, function(status, content) {
    81     ok(Components.isSuccessCode(status), "File was imported successfully");
    82     is(gScratchpad.executionContext, gScratchpadWindow.SCRATCHPAD_CONTEXT_BROWSER);
    84     gFile.remove(false);
    85     gFile = null;
    86     gScratchpad = null;
    87     finish();
    88   });
    89 }
    91 registerCleanupFunction(function () {
    92   Services.prefs.clearUserPref(DEVTOOLS_CHROME_ENABLED);
    93 });

mercurial