gecko/browser/devtools/scratchpad/test/browser_scratchpad_revert_to_saved.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

142 lines
4.4 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 751744 */
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;
// Reference to the Scratchpad object.
let gScratchpad;
// Reference to the temporary nsIFiles.
let gFile;
// Temporary file name.
let gFileName = "testFileForBug751744.tmp"
// Content for the temporary file.
let gFileContent = "/* this file is already saved */\n" +
"function foo() { alert('bar') }";
let gLength = gFileContent.length;
// Reference to the menu entry.
let menu;
function startTest()
{
gScratchpad = gScratchpadWindow.Scratchpad;
menu = gScratchpadWindow.document.getElementById("sp-cmd-revert");
createAndLoadTemporaryFile();
}
function testAfterSaved() {
// Check if the revert menu is disabled as the file is at saved state.
ok(menu.hasAttribute("disabled"), "The revert menu entry is disabled.");
// chancging the text in the file
gScratchpad.setText(gScratchpad.getText() + "\nfoo();");
// Checking the text got changed
is(gScratchpad.getText(), gFileContent + "\nfoo();",
"The text changed the first time.");
// Revert menu now should be enabled.
ok(!menu.hasAttribute("disabled"),
"The revert menu entry is enabled after changing text first time");
// reverting back to last saved state.
gScratchpad.revertFile(testAfterRevert);
}
function testAfterRevert() {
// Check if the file's text got reverted
is(gScratchpad.getText(), gFileContent,
"The text reverted back to original text.");
// The revert menu should be disabled again.
ok(menu.hasAttribute("disabled"),
"The revert menu entry is disabled after reverting.");
// chancging the text in the file again
gScratchpad.setText(gScratchpad.getText() + "\nalert(foo.toSource());");
// Saving the file.
gScratchpad.saveFile(testAfterSecondSave);
}
function testAfterSecondSave() {
// revert menu entry should be disabled.
ok(menu.hasAttribute("disabled"),
"The revert menu entry is disabled after saving.");
// changing the text.
gScratchpad.setText(gScratchpad.getText() + "\nfoo();");
// revert menu entry should get enabled yet again.
ok(!menu.hasAttribute("disabled"),
"The revert menu entry is enabled after changing text third time");
// reverting back to last saved state.
gScratchpad.revertFile(testAfterSecondRevert);
}
function testAfterSecondRevert() {
// Check if the file's text got reverted
is(gScratchpad.getText(), gFileContent + "\nalert(foo.toSource());",
"The text reverted back to the changed saved text.");
// The revert menu should be disabled again.
ok(menu.hasAttribute("disabled"),
"Revert menu entry is disabled after reverting to changed saved state.");
gFile.remove(false);
gFile = null;
gScratchpad = null;
finish();
}
function createAndLoadTemporaryFile()
{
// Create a temporary file.
gFile = FileUtils.getFile("TmpD", [gFileName]);
gFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
// Write the temporary file.
let fout = Cc["@mozilla.org/network/file-output-stream;1"].
createInstance(Ci.nsIFileOutputStream);
fout.init(gFile.QueryInterface(Ci.nsILocalFile), 0x02 | 0x08 | 0x20,
0644, fout.DEFER_OPEN);
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
createInstance(Ci.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8";
let fileContentStream = converter.convertToInputStream(gFileContent);
NetUtil.asyncCopy(fileContentStream, fout, tempFileSaved);
}
function tempFileSaved(aStatus)
{
ok(Components.isSuccessCode(aStatus),
"the temporary file was saved successfully");
// Import the file into Scratchpad.
gScratchpad.setFilename(gFile.path);
gScratchpad.importFromFile(gFile.QueryInterface(Ci.nsILocalFile), true,
testAfterSaved);
}
function test()
{
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
openScratchpad(startTest);
}, true);
content.location = "data:text/html,<p>test reverting to last saved state of" +
" a file </p>";
}