|
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 |
|
5 const TESTCASE_URI = TEST_BASE_HTTPS + "simple.html"; |
|
6 const NEW_URI = TEST_BASE_HTTPS + "media.html"; |
|
7 |
|
8 const LINE_NO = 5; |
|
9 const COL_NO = 3; |
|
10 |
|
11 let gContentWin; |
|
12 let gUI; |
|
13 |
|
14 function test() |
|
15 { |
|
16 waitForExplicitFinish(); |
|
17 |
|
18 addTabAndOpenStyleEditors(2, function(panel) { |
|
19 gContentWin = gBrowser.selectedTab.linkedBrowser.contentWindow.wrappedJSObject; |
|
20 gUI = panel.UI; |
|
21 gUI.editors[0].getSourceEditor().then(runTests); |
|
22 }); |
|
23 |
|
24 content.location = TESTCASE_URI; |
|
25 } |
|
26 |
|
27 function runTests() |
|
28 { |
|
29 let count = 0; |
|
30 gUI.once("editor-selected", (event, editor) => { |
|
31 editor.getSourceEditor().then(() => { |
|
32 info("selected second editor, about to reload page"); |
|
33 reloadPage(); |
|
34 |
|
35 gUI.on("editor-added", function editorAdded(event, editor) { |
|
36 if (++count == 2) { |
|
37 info("all editors added after reload"); |
|
38 gUI.off("editor-added", editorAdded); |
|
39 gUI.editors[1].getSourceEditor().then(testRemembered); |
|
40 } |
|
41 }) |
|
42 }); |
|
43 }); |
|
44 gUI.selectStyleSheet(gUI.editors[1].styleSheet.href, LINE_NO, COL_NO); |
|
45 } |
|
46 |
|
47 function testRemembered() |
|
48 { |
|
49 is(gUI.selectedEditor, gUI.editors[1], "second editor is selected"); |
|
50 |
|
51 let {line, ch} = gUI.selectedEditor.sourceEditor.getCursor(); |
|
52 is(line, LINE_NO, "correct line selected"); |
|
53 is(ch, COL_NO, "correct column selected"); |
|
54 |
|
55 testNewPage(); |
|
56 } |
|
57 |
|
58 function testNewPage() |
|
59 { |
|
60 let count = 0; |
|
61 gUI.on("editor-added", function editorAdded(event, editor) { |
|
62 info("editor added here") |
|
63 if (++count == 2) { |
|
64 info("all editors added after navigating page"); |
|
65 gUI.off("editor-added", editorAdded); |
|
66 gUI.editors[0].getSourceEditor().then(testNotRemembered); |
|
67 } |
|
68 }) |
|
69 |
|
70 info("navigating to a different page"); |
|
71 navigatePage(); |
|
72 } |
|
73 |
|
74 function testNotRemembered() |
|
75 { |
|
76 is(gUI.selectedEditor, gUI.editors[0], "first editor is selected"); |
|
77 |
|
78 let {line, ch} = gUI.selectedEditor.sourceEditor.getCursor(); |
|
79 is(line, 0, "first line is selected"); |
|
80 is(ch, 0, "first column is selected"); |
|
81 |
|
82 gUI = null; |
|
83 finish(); |
|
84 } |
|
85 |
|
86 function reloadPage() |
|
87 { |
|
88 gContentWin.location.reload(); |
|
89 } |
|
90 |
|
91 function navigatePage() |
|
92 { |
|
93 gContentWin.location = NEW_URI; |
|
94 } |