summaryrefslogtreecommitdiffstats
path: root/devtools/client/scratchpad/test/browser_scratchpad_unsaved.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/client/scratchpad/test/browser_scratchpad_unsaved.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/scratchpad/test/browser_scratchpad_unsaved.js')
-rw-r--r--devtools/client/scratchpad/test/browser_scratchpad_unsaved.js119
1 files changed, 119 insertions, 0 deletions
diff --git a/devtools/client/scratchpad/test/browser_scratchpad_unsaved.js b/devtools/client/scratchpad/test/browser_scratchpad_unsaved.js
new file mode 100644
index 000000000..54b97b75b
--- /dev/null
+++ b/devtools/client/scratchpad/test/browser_scratchpad_unsaved.js
@@ -0,0 +1,119 @@
+/* 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 669612 */
+
+// only finish() when correct number of tests are done
+const expected = 4;
+var count = 0;
+function done()
+{
+ if (++count == expected) {
+ finish();
+ }
+}
+
+
+function test()
+{
+ waitForExplicitFinish();
+
+ testListeners();
+ testRestoreNotFromFile();
+ testRestoreFromFileSaved();
+ testRestoreFromFileUnsaved();
+
+ gBrowser.selectedTab = gBrowser.addTab();
+ content.location = "data:text/html,<p>test star* UI for unsaved file changes";
+}
+
+function testListeners()
+{
+ openScratchpad(function (aWin, aScratchpad) {
+ aScratchpad.setText("new text");
+ ok(isStar(aWin), "show star if scratchpad text changes");
+
+ aScratchpad.dirty = false;
+ ok(!isStar(aWin), "no star before changing text");
+
+ aScratchpad.setFilename("foo.js");
+ aScratchpad.setText("new text2");
+ ok(isStar(aWin), "shows star if scratchpad text changes");
+
+ aScratchpad.dirty = false;
+ ok(!isStar(aWin), "no star if scratchpad was just saved");
+
+ aScratchpad.setText("new text3");
+ ok(isStar(aWin), "shows star if scratchpad has more changes");
+
+ aScratchpad.undo();
+ ok(!isStar(aWin), "no star if scratchpad undo to save point");
+
+ aScratchpad.undo();
+ ok(isStar(aWin), "star if scratchpad undo past save point");
+
+ aWin.close();
+ done();
+ }, {noFocus: true});
+}
+
+function testRestoreNotFromFile()
+{
+ let session = [{
+ text: "test1",
+ executionContext: 1
+ }];
+
+ let [win] = ScratchpadManager.restoreSession(session);
+ openScratchpad(function (aWin, aScratchpad) {
+ aScratchpad.setText("new text");
+ ok(isStar(win), "show star if restored scratchpad isn't from a file");
+
+ win.close();
+ done();
+ }, {window: win, noFocus: true});
+}
+
+function testRestoreFromFileSaved()
+{
+ let session = [{
+ filename: "test.js",
+ text: "test1",
+ executionContext: 1,
+ saved: true
+ }];
+
+ let [win] = ScratchpadManager.restoreSession(session);
+ openScratchpad(function (aWin, aScratchpad) {
+ ok(!isStar(win), "no star before changing text in scratchpad restored from file");
+
+ aScratchpad.setText("new text");
+ ok(isStar(win), "star when text changed from scratchpad restored from file");
+
+ win.close();
+ done();
+ }, {window: win, noFocus: true});
+}
+
+function testRestoreFromFileUnsaved()
+{
+ let session = [{
+ filename: "test.js",
+ text: "test1",
+ executionContext: 1,
+ saved: false
+ }];
+
+ let [win] = ScratchpadManager.restoreSession(session);
+ openScratchpad(function () {
+ ok(isStar(win), "star with scratchpad restored with unsaved text");
+
+ win.close();
+ done();
+ }, {window: win, noFocus: true});
+}
+
+function isStar(win)
+{
+ return win.document.title.match(/^\*[^\*]/);
+}