gecko/browser/devtools/scratchpad/test/browser_scratchpad_modeline.js
Peiyong Lin 3e5987353c Bug 937953 - Remove bug numbers from all Scratchpad test file names and update browser.ini. r=benvie
--HG--
rename : browser/devtools/scratchpad/test/browser_scratchpad_bug807924_cannot_convert_to_string.js => browser/devtools/scratchpad/test/browser_scratchpad_cannot_convert_to_string.js
rename : browser/devtools/scratchpad/test/browser_scratchpad_bug_646070_chrome_context_pref.js => browser/devtools/scratchpad/test/browser_scratchpad_chrome_context_pref.js
rename : browser/devtools/scratchpad/test/browser_scratchpad_bug_653427_confirm_close.js => browser/devtools/scratchpad/test/browser_scratchpad_confirm_close.js
rename : browser/devtools/scratchpad/test/browser_scratchpad_bug756681_display_non_error_exceptions.js => browser/devtools/scratchpad/test/browser_scratchpad_display_non_error_exceptions.js
rename : browser/devtools/scratchpad/test/browser_scratchpad_bug690552_display_outputs_errors.js => browser/devtools/scratchpad/test/browser_scratchpad_display_outputs_errors.js
rename : browser/devtools/scratchpad/test/browser_scratchpad_bug_699130_edit_ui_updates.js => browser/devtools/scratchpad/test/browser_scratchpad_edit_ui_updates.js
rename : browser/devtools/scratchpad/test/browser_scratchpad_bug_679467_falsy.js => browser/devtools/scratchpad/test/browser_scratchpad_falsy.js
rename : browser/devtools/scratchpad/test/browser_scratchpad_bug714942_goto_line_ui.js => browser/devtools/scratchpad/test/browser_scratchpad_goto_line_ui.js
rename : browser/devtools/scratchpad/test/browser_scratchpad_bug_650760_help_key.js => browser/devtools/scratchpad/test/browser_scratchpad_help_key.js
rename : browser/devtools/scratchpad/test/browser_scratchpad_bug_644413_modeline.js => browser/devtools/scratchpad/test/browser_scratchpad_modeline.js
rename : browser/devtools/scratchpad/test/browser_scratchpad_bug_651942_recent_files.js => browser/devtools/scratchpad/test/browser_scratchpad_recent_files.js
rename : browser/devtools/scratchpad/test/browser_scratchpad_bug740948_reload_and_run.js => browser/devtools/scratchpad/test/browser_scratchpad_reload_and_run.js
rename : browser/devtools/scratchpad/test/browser_scratchpad_bug684546_reset_undo.js => browser/devtools/scratchpad/test/browser_scratchpad_reset_undo.js
rename : browser/devtools/scratchpad/test/browser_scratchpad_bug_751744_revert_to_saved.js => browser/devtools/scratchpad/test/browser_scratchpad_revert_to_saved.js
rename : browser/devtools/scratchpad/test/browser_scratchpad_bug_660560_tab.js => browser/devtools/scratchpad/test/browser_scratchpad_tab.js
rename : browser/devtools/scratchpad/test/browser_scratchpad_bug_669612_unsaved.js => browser/devtools/scratchpad/test/browser_scratchpad_unsaved.js
rename : browser/devtools/scratchpad/test/browser_scratchpad_bug_661762_wrong_window_focus.js => browser/devtools/scratchpad/test/browser_scratchpad_wrong_window_focus.js
2013-11-15 21:47:02 -05:00

94 lines
3.2 KiB
JavaScript

/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* Bug 644413 */
let tempScope = {};
Cu.import("resource://gre/modules/NetUtil.jsm", tempScope);
Cu.import("resource://gre/modules/FileUtils.jsm", tempScope);
let NetUtil = tempScope.NetUtil;
let FileUtils = tempScope.FileUtils;
let gScratchpad; // Reference to the Scratchpad object.
let gFile; // Reference to the temporary nsIFile we will work with.
let DEVTOOLS_CHROME_ENABLED = "devtools.chrome.enabled";
// The temporary file content.
let gFileContent = "function main() { return 0; }";
function test() {
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
openScratchpad(runTests);
}, true);
content.location = "data:text/html,<p>test file open and save in Scratchpad";
}
function runTests() {
gScratchpad = gScratchpadWindow.Scratchpad;
function size(obj) { return Object.keys(obj).length; }
// Test Scratchpad._scanModeLine method.
let obj = gScratchpad._scanModeLine();
is(size(obj), 0, "Mode-line object has no properties");
obj = gScratchpad._scanModeLine("/* This is not a mode-line comment */");
is(size(obj), 0, "Mode-line object has no properties");
obj = gScratchpad._scanModeLine("/* -sp-context:browser */");
is(size(obj), 1, "Mode-line object has one property");
is(obj["-sp-context"], "browser");
obj = gScratchpad._scanModeLine("/* -sp-context: browser */");
is(size(obj), 1, "Mode-line object has one property");
is(obj["-sp-context"], "browser");
obj = gScratchpad._scanModeLine("// -sp-context: browser");
is(size(obj), 1, "Mode-line object has one property");
is(obj["-sp-context"], "browser");
obj = gScratchpad._scanModeLine("/* -sp-context:browser, other:true */");
is(size(obj), 2, "Mode-line object has two properties");
is(obj["-sp-context"], "browser");
is(obj["other"], "true");
// Test importing files with a mode-line in them.
let content = "/* -sp-context:browser */\n" + gFileContent;
createTempFile("fileForBug644413.tmp", content, function(aStatus, aFile) {
ok(Components.isSuccessCode(aStatus), "File was saved successfully");
gFile = aFile;
gScratchpad.importFromFile(gFile.QueryInterface(Ci.nsILocalFile), true, fileImported);
});
}
function fileImported(status, content) {
ok(Components.isSuccessCode(status), "File was imported successfully");
// Since devtools.chrome.enabled is off, Scratchpad should still be in
// the content context.
is(gScratchpad.executionContext, gScratchpadWindow.SCRATCHPAD_CONTEXT_CONTENT);
// Set the pref and try again.
Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, true);
gScratchpad.importFromFile(gFile.QueryInterface(Ci.nsILocalFile), true, function(status, content) {
ok(Components.isSuccessCode(status), "File was imported successfully");
is(gScratchpad.executionContext, gScratchpadWindow.SCRATCHPAD_CONTEXT_BROWSER);
gFile.remove(false);
gFile = null;
gScratchpad = null;
finish();
});
}
registerCleanupFunction(function () {
Services.prefs.clearUserPref(DEVTOOLS_CHROME_ENABLED);
});