|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Make sure that the debugger is updated with the correct sources when moving |
|
6 * back and forward in the tab. |
|
7 */ |
|
8 |
|
9 const TAB_URL_1 = EXAMPLE_URL + "doc_script-switching-01.html"; |
|
10 const TAB_URL_2 = EXAMPLE_URL + "doc_recursion-stack.html"; |
|
11 |
|
12 let gTab, gDebuggee, gPanel, gDebugger; |
|
13 let gSources; |
|
14 |
|
15 function test() { |
|
16 initDebugger(TAB_URL_1).then(([aTab, aDebuggee, aPanel]) => { |
|
17 gTab = aTab; |
|
18 gDebuggee = aDebuggee; |
|
19 gPanel = aPanel; |
|
20 gDebugger = gPanel.panelWin; |
|
21 gSources = gDebugger.DebuggerView.Sources; |
|
22 |
|
23 testFirstPage() |
|
24 .then(testLocationChange) |
|
25 .then(testBack) |
|
26 .then(testForward) |
|
27 .then(() => closeDebuggerAndFinish(gPanel)) |
|
28 .then(null, aError => { |
|
29 ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
|
30 }); |
|
31 }); |
|
32 } |
|
33 |
|
34 function testFirstPage() { |
|
35 info("Testing first page."); |
|
36 |
|
37 // Spin the event loop before causing the debuggee to pause, to allow |
|
38 // this function to return first. |
|
39 executeSoon(() => gDebuggee.firstCall()); |
|
40 |
|
41 return waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1).then(() => { |
|
42 validateFirstPage(); |
|
43 }); |
|
44 } |
|
45 |
|
46 function testLocationChange() { |
|
47 info("Navigating to a different page."); |
|
48 |
|
49 return navigateActiveTabTo(gPanel, TAB_URL_2, gDebugger.EVENTS.SOURCES_ADDED).then(() => { |
|
50 validateSecondPage(); |
|
51 }); |
|
52 } |
|
53 |
|
54 function testBack() { |
|
55 info("Going back."); |
|
56 |
|
57 return navigateActiveTabInHistory(gPanel, "back", gDebugger.EVENTS.SOURCES_ADDED).then(() => { |
|
58 validateFirstPage(); |
|
59 }); |
|
60 } |
|
61 |
|
62 function testForward() { |
|
63 info("Going forward."); |
|
64 |
|
65 return navigateActiveTabInHistory(gPanel, "forward", gDebugger.EVENTS.SOURCES_ADDED).then(() => { |
|
66 validateSecondPage(); |
|
67 }); |
|
68 } |
|
69 |
|
70 function validateFirstPage() { |
|
71 is(gSources.itemCount, 2, |
|
72 "Found the expected number of sources."); |
|
73 ok(gSources.getItemForAttachment(e => e.label == "code_script-switching-01.js"), |
|
74 "Found the first source label."); |
|
75 ok(gSources.getItemForAttachment(e => e.label == "code_script-switching-02.js"), |
|
76 "Found the second source label."); |
|
77 } |
|
78 |
|
79 function validateSecondPage() { |
|
80 is(gSources.itemCount, 1, |
|
81 "Found the expected number of sources."); |
|
82 ok(gSources.getItemForAttachment(e => e.label == "doc_recursion-stack.html"), |
|
83 "Found the single source label."); |
|
84 } |
|
85 |
|
86 registerCleanupFunction(function() { |
|
87 gTab = null; |
|
88 gDebuggee = null; |
|
89 gPanel = null; |
|
90 gDebugger = null; |
|
91 gSources = null; |
|
92 }); |