Bug 1260160 - Refactor 2 debugger tests to use Task.spawn. r=jlong a=kwierso

* browser_dbg_search-sources-01.js
* browser_dbg_auto-pretty-print-02.js

MozReview-Commit-ID: KtUbMYU3pt9

--HG--
extra : histedit_source : 5e0eebb5ba0673994720dc5a88292ec37f31043d
This commit is contained in:
Jason Laster 2016-03-31 16:18:12 -07:00
Родитель b1411d1862
Коммит ff953effdf
2 изменённых файлов: 302 добавлений и 303 удалений

Просмотреть файл

@ -22,98 +22,102 @@ Services.prefs.setBoolPref("devtools.debugger.auto-pretty-print", true);
function test(){
initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
gTab = aTab;
gDebuggee = aDebuggee;
gPanel = aPanel;
gDebugger = gPanel.panelWin;
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gPrefs = gDebugger.Prefs;
gOptions = gDebugger.DebuggerView.Options;
gView = gDebugger.DebuggerView;
const gTab = aTab;
const gDebuggee = aDebuggee;
const gPanel = aPanel;
const gDebugger = gPanel.panelWin;
const gEditor = gDebugger.DebuggerView.editor;
const gSources = gDebugger.DebuggerView.Sources;
const gPrefs = gDebugger.Prefs;
const gOptions = gDebugger.DebuggerView.Options;
const gView = gDebugger.DebuggerView;
// Should be on by default.
testAutoPrettyPrintOn();
waitForSourceShown(gPanel, gFirstSourceLabel)
.then(testSourceIsUgly)
.then(() => waitForSourceShown(gPanel, gFirstSourceLabel))
.then(testSourceIsPretty)
.then(testPrettyPrintButtonOn)
.then(() => {
// Switch to the second source.
let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN, 2);
gSources.selectedIndex = 1;
return finished;
})
.then(testSecondSourceLabel)
.then(() => {
// Switch back to first source.
let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN);
gSources.selectedIndex = 0;
return finished;
})
.then(testFirstSourceLabel)
.then(testPrettyPrintButtonOn)
Task.spawn(function*() {
yield waitForSourceShown(gPanel, gFirstSourceLabel);
testSourceIsUgly();
yield waitForSourceShown(gPanel, gFirstSourceLabel);
testSourceIsPretty();
testPrettyPrintButtonOn();
// select second source
yield selectSecondSource();
testSecondSourceLabel();
// select first source
yield selectFirstSource();
testFirstSourceLabel();
testPrettyPrintButtonOn();
// Disable auto pretty printing so it does not affect the following tests.
.then(disableAutoPrettyPrint)
.then(() => closeDebuggerAndFinish(gPanel))
.then(null, aError => {
ok(false, "Got an error: " + DevToolsUtils.safeErrorString(aError));
})
yield disableAutoPrettyPrint();
closeDebuggerAndFinish(gPanel)
.then(null, aError => {
ok(false, "Got an error: " + DevToolsUtils.safeErrorString(aError));
})
});
function selectSecondSource() {
let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN, 2);
gSources.selectedIndex = 1;
return finished;
}
function selectFirstSource() {
let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN);
gSources.selectedIndex = 0;
return finished;
}
function testSourceIsUgly() {
ok(!gEditor.getText().includes("\n "),
"The source shouldn't be pretty printed yet.");
}
function testFirstSourceLabel(){
let source = gSources.selectedItem.attachment.source;
ok(source.url === EXAMPLE_URL + gFirstSourceLabel,
"First source url is correct.");
}
function testSecondSourceLabel(){
let source = gSources.selectedItem.attachment.source;
ok(source.url === EXAMPLE_URL + gSecondSourceLabel,
"Second source url is correct.");
}
function testAutoPrettyPrintOn(){
is(gPrefs.autoPrettyPrint, true,
"The auto-pretty-print pref should be on.");
is(gOptions._autoPrettyPrint.getAttribute("checked"), "true",
"The Auto pretty print menu item should be checked.");
}
function testPrettyPrintButtonOn(){
is(gDebugger.document.getElementById("pretty-print").checked, true,
"The button should be checked when the source is selected.");
}
function disableAutoPrettyPrint(){
gOptions._autoPrettyPrint.setAttribute("checked", "false");
gOptions._toggleAutoPrettyPrint();
gOptions._onPopupHidden();
info("Disabled auto pretty printing.");
}
function testSourceIsPretty() {
ok(gEditor.getText().includes("\n "),
"The source should be pretty printed.")
}
registerCleanupFunction(function() {
Services.prefs.setBoolPref("devtools.debugger.auto-pretty-print", gOriginalPref);
});
});
}
function testSourceIsUgly() {
ok(!gEditor.getText().includes("\n "),
"The source shouldn't be pretty printed yet.");
}
function testFirstSourceLabel(){
let source = gSources.selectedItem.attachment.source;
ok(source.url === EXAMPLE_URL + gFirstSourceLabel,
"First source url is correct.");
}
function testSecondSourceLabel(){
let source = gSources.selectedItem.attachment.source;
ok(source.url === EXAMPLE_URL + gSecondSourceLabel,
"Second source url is correct.");
}
function testAutoPrettyPrintOn(){
is(gPrefs.autoPrettyPrint, true,
"The auto-pretty-print pref should be on.");
is(gOptions._autoPrettyPrint.getAttribute("checked"), "true",
"The Auto pretty print menu item should be checked.");
}
function testPrettyPrintButtonOn(){
is(gDebugger.document.getElementById("pretty-print").checked, true,
"The button should be checked when the source is selected.");
}
function disableAutoPrettyPrint(){
gOptions._autoPrettyPrint.setAttribute("checked", "false");
gOptions._toggleAutoPrettyPrint();
gOptions._onPopupHidden();
info("Disabled auto pretty printing.");
}
function testSourceIsPretty() {
ok(gEditor.getText().includes("\n "),
"The source should be pretty printed.")
}
registerCleanupFunction(function() {
gTab = null;
gDebuggee = null;
gPanel = null;
gDebugger = null;
gEditor = null;
gSources = null;
gOptions = null;
gPrefs = null;
gView = null;
Services.prefs.setBoolPref("devtools.debugger.auto-pretty-print", gOriginalPref);
});

Просмотреть файл

@ -9,227 +9,222 @@
const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
var gTab, gPanel, gDebugger;
var gSources, gSearchView, gSearchBox;
function test() {
// Debug test slaves are a bit slow at this test.
requestLongerTimeout(3);
initDebugger(TAB_URL).then(([aTab,, aPanel]) => {
gTab = aTab;
gPanel = aPanel;
gDebugger = gPanel.panelWin;
gSources = gDebugger.DebuggerView.Sources;
gSearchView = gDebugger.DebuggerView.Filtering.FilteredSources;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
const gTab = aTab;
const gPanel = aPanel;
const gDebugger = gPanel.panelWin;
const gSources = gDebugger.DebuggerView.Sources;
const gSearchView = gDebugger.DebuggerView.Filtering.FilteredSources;
const gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
waitForSourceShown(gPanel, "-01.js")
.then(bogusSearch)
.then(firstSearch)
.then(secondSearch)
.then(thirdSearch)
.then(fourthSearch)
.then(fifthSearch)
.then(sixthSearch)
.then(seventhSearch)
.then(() => closeDebuggerAndFinish(gPanel))
.then(null, aError => {
ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
Task.spawn(function*() {
// move searches to yields
// not sure what to do with the error...
yield waitForSourceShown(gPanel, "-01.js");
yield bogusSearch();
yield firstSearch();
yield secondSearch();
yield thirdSearch();
yield fourthSearch();
yield fifthSearch();
yield sixthSearch();
yield seventhSearch();
return closeDebuggerAndFinish(gPanel)
.then(null, aError => {
ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
});
});
function bogusSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_NOT_FOUND)
]);
setText(gSearchBox, "BOGUS");
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
verifyContents({ itemCount: 0, hidden: true })
]));
}
function firstSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-02.js")
]);
setText(gSearchBox, "-02.js");
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 1),
verifyContents({ itemCount: 1, hidden: false })
]));
}
function secondSearch() {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-01.js")
])
.then(() => {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForCaretUpdated(gPanel, 5)
])
.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 5),
verifyContents({ itemCount: 1, hidden: false })
]));
typeText(gSearchBox, ":5");
return finished;
});
setText(gSearchBox, ".*-01\.js");
return finished;
}
function thirdSearch() {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-02.js")
])
.then(() => {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForCaretUpdated(gPanel, 6, 6)
])
.then(() => promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 6, 6),
verifyContents({ itemCount: 1, hidden: false })
]));
typeText(gSearchBox, "#deb");
return finished;
});
setText(gSearchBox, ".*-02\.js");
return finished;
}
function fourthSearch() {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-01.js")
])
.then(() => {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForCaretUpdated(gPanel, 2, 9),
])
.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 2, 9),
verifyContents({ itemCount: 1, hidden: false })
// ...because we simply searched for ":" in the current file.
]));
typeText(gSearchBox, "#:"); // # has precedence.
return finished;
});
setText(gSearchBox, ".*-01\.js");
return finished;
}
function fifthSearch() {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-02.js")
])
.then(() => {
let finished = promise.all([
once(gDebugger, "popuphidden"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_NOT_FOUND),
waitForCaretUpdated(gPanel, 1, 3)
])
.then(() => promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 1, 3),
verifyContents({ itemCount: 0, hidden: true })
// ...because the searched label includes ":5", so nothing is found.
]));
typeText(gSearchBox, ":5#*"); // # has precedence.
return finished;
});
setText(gSearchBox, ".*-02\.js");
return finished;
}
function sixthSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 1, 3),
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForCaretUpdated(gPanel, 5)
]);
backspaceText(gSearchBox, 2);
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 5),
verifyContents({ itemCount: 1, hidden: false })
]));
}
function seventhSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 5),
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-01.js"),
]);
backspaceText(gSearchBox, 6);
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
verifyContents({ itemCount: 2, hidden: false })
]));
}
function verifyContents(aArgs) {
is(gSources.visibleItems.length, 2,
"The unmatched sources in the widget should not be hidden.");
is(gSearchView.itemCount, aArgs.itemCount,
"No sources should be displayed in the sources container after a bogus search.");
is(gSearchView.hidden, aArgs.hidden,
"No sources should be displayed in the sources container after a bogus search.");
}
});
}
function bogusSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_NOT_FOUND)
]);
setText(gSearchBox, "BOGUS");
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
verifyContents({ itemCount: 0, hidden: true })
]));
}
function firstSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-02.js")
]);
setText(gSearchBox, "-02.js");
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 1),
verifyContents({ itemCount: 1, hidden: false })
]));
}
function secondSearch() {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-01.js")
])
.then(() => {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForCaretUpdated(gPanel, 5)
])
.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 5),
verifyContents({ itemCount: 1, hidden: false })
]));
typeText(gSearchBox, ":5");
return finished;
});
setText(gSearchBox, ".*-01\.js");
return finished;
}
function thirdSearch() {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-02.js")
])
.then(() => {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForCaretUpdated(gPanel, 6, 6)
])
.then(() => promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 6, 6),
verifyContents({ itemCount: 1, hidden: false })
]));
typeText(gSearchBox, "#deb");
return finished;
});
setText(gSearchBox, ".*-02\.js");
return finished;
}
function fourthSearch() {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-01.js")
])
.then(() => {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForCaretUpdated(gPanel, 2, 9),
])
.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 2, 9),
verifyContents({ itemCount: 1, hidden: false })
// ...because we simply searched for ":" in the current file.
]));
typeText(gSearchBox, "#:"); // # has precedence.
return finished;
});
setText(gSearchBox, ".*-01\.js");
return finished;
}
function fifthSearch() {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-02.js")
])
.then(() => {
let finished = promise.all([
once(gDebugger, "popuphidden"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_NOT_FOUND),
waitForCaretUpdated(gPanel, 1, 3)
])
.then(() => promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 1, 3),
verifyContents({ itemCount: 0, hidden: true })
// ...because the searched label includes ":5", so nothing is found.
]));
typeText(gSearchBox, ":5#*"); // # has precedence.
return finished;
});
setText(gSearchBox, ".*-02\.js");
return finished;
}
function sixthSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 1, 3),
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForCaretUpdated(gPanel, 5)
]);
backspaceText(gSearchBox, 2);
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 5),
verifyContents({ itemCount: 1, hidden: false })
]));
}
function seventhSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 5),
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-01.js"),
]);
backspaceText(gSearchBox, 6);
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
verifyContents({ itemCount: 2, hidden: false })
]));
}
function verifyContents(aArgs) {
is(gSources.visibleItems.length, 2,
"The unmatched sources in the widget should not be hidden.");
is(gSearchView.itemCount, aArgs.itemCount,
"No sources should be displayed in the sources container after a bogus search.");
is(gSearchView.hidden, aArgs.hidden,
"No sources should be displayed in the sources container after a bogus search.");
}
registerCleanupFunction(function() {
gTab = null;
gPanel = null;
gDebugger = null;
gSources = null;
gSearchView = null;
gSearchBox = null;
});