|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests if the same source is shown after a page is reloaded. |
|
6 */ |
|
7 |
|
8 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; |
|
9 const FIRST_URL = EXAMPLE_URL + "code_script-switching-01.js"; |
|
10 const SECOND_URL = EXAMPLE_URL + "code_script-switching-02.js"; |
|
11 |
|
12 function test() { |
|
13 // Debug test slaves are a bit slow at this test. |
|
14 requestLongerTimeout(2); |
|
15 |
|
16 let gTab, gDebuggee, gPanel, gDebugger; |
|
17 let gSources, gStep; |
|
18 |
|
19 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
20 gTab = aTab; |
|
21 gDebuggee = aDebuggee; |
|
22 gPanel = aPanel; |
|
23 gDebugger = aPanel.panelWin; |
|
24 gSources = gDebugger.DebuggerView.Sources; |
|
25 gStep = 0; |
|
26 |
|
27 waitForSourceShown(gPanel, FIRST_URL).then(performTest); |
|
28 }); |
|
29 |
|
30 function performTest() { |
|
31 switch (gStep++) { |
|
32 case 0: |
|
33 testCurrentSource(FIRST_URL, ""); |
|
34 reload().then(performTest); |
|
35 break; |
|
36 case 1: |
|
37 testCurrentSource(FIRST_URL); |
|
38 reload().then(performTest); |
|
39 break; |
|
40 case 2: |
|
41 testCurrentSource(FIRST_URL); |
|
42 switchAndReload(SECOND_URL).then(performTest); |
|
43 break; |
|
44 case 3: |
|
45 testCurrentSource(SECOND_URL); |
|
46 reload().then(performTest); |
|
47 break; |
|
48 case 4: |
|
49 testCurrentSource(SECOND_URL); |
|
50 reload().then(performTest); |
|
51 break; |
|
52 case 5: |
|
53 testCurrentSource(SECOND_URL); |
|
54 closeDebuggerAndFinish(gPanel); |
|
55 break; |
|
56 } |
|
57 } |
|
58 |
|
59 function reload() { |
|
60 return reloadActiveTab(gPanel, gDebugger.EVENTS.SOURCES_ADDED); |
|
61 } |
|
62 |
|
63 function switchAndReload(aUrl) { |
|
64 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(reload); |
|
65 gSources.selectedValue = aUrl; |
|
66 return finished; |
|
67 } |
|
68 |
|
69 function testCurrentSource(aUrl, aExpectedUrl = aUrl) { |
|
70 info("Currently preferred source: '" + gSources.preferredValue + "'."); |
|
71 info("Currently selected source: '" + gSources.selectedValue + "'."); |
|
72 |
|
73 is(gSources.preferredValue, aExpectedUrl, |
|
74 "The preferred source url wasn't set correctly (" + gStep + ")."); |
|
75 is(gSources.selectedValue, aUrl, |
|
76 "The selected source isn't the correct one (" + gStep + ")."); |
|
77 } |
|
78 } |