michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests if the sources cache knows how to cache sources when prompted. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_function-search.html"; michael@0: const TOTAL_SOURCES = 4; michael@0: michael@0: let gTab, gDebuggee, gPanel, gDebugger; michael@0: let gEditor, gSources, gControllerSources; michael@0: let gPrevLabelsCache, gPrevGroupsCache; michael@0: michael@0: function test() { michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: gTab = aTab; michael@0: gDebuggee = aDebuggee; michael@0: gPanel = aPanel; michael@0: gDebugger = gPanel.panelWin; michael@0: gEditor = gDebugger.DebuggerView.editor; michael@0: gSources = gDebugger.DebuggerView.Sources; michael@0: gControllerSources = gDebugger.DebuggerController.SourceScripts; michael@0: gPrevLabelsCache = gDebugger.SourceUtils._labelsCache; michael@0: gPrevGroupsCache = gDebugger.SourceUtils._groupsCache; michael@0: michael@0: waitForSourceShown(gPanel, "-01.js") michael@0: .then(initialChecks) michael@0: .then(getTextForSourcesAndCheckIntegrity) michael@0: .then(performReloadAndTestState) michael@0: .then(() => closeDebuggerAndFinish(gPanel)) michael@0: .then(null, aError => { michael@0: ok(false, "Got an error: " + aError.message + "\n" + aError.stack); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function initialChecks() { michael@0: ok(gEditor.getText().contains("First source!"), michael@0: "Editor text contents appears to be correct."); michael@0: is(gSources.selectedItem.attachment.label, "code_function-search-01.js", michael@0: "The currently selected label in the sources container is correct."); michael@0: ok(gSources.selectedValue.contains("code_function-search-01.js"), michael@0: "The currently selected value in the sources container appears to be correct."); michael@0: michael@0: is(gSources.itemCount, TOTAL_SOURCES, michael@0: "There should be " + TOTAL_SOURCES + " sources present in the sources list."); michael@0: is(gSources.visibleItems.length, TOTAL_SOURCES, michael@0: "There should be " + TOTAL_SOURCES + " sources visible in the sources list."); michael@0: is(gSources.attachments.length, TOTAL_SOURCES, michael@0: "There should be " + TOTAL_SOURCES + " attachments stored in the sources container model.") michael@0: is(gSources.values.length, TOTAL_SOURCES, michael@0: "There should be " + TOTAL_SOURCES + " values stored in the sources container model.") michael@0: michael@0: info("Source labels: " + gSources.attachments.toSource()); michael@0: info("Source values: " + gSources.values.toSource()); michael@0: michael@0: is(gSources.attachments[0].label, "code_function-search-01.js", michael@0: "The first source label is correct."); michael@0: ok(gSources.values[0].contains("code_function-search-01.js"), michael@0: "The first source value appears to be correct."); michael@0: michael@0: is(gSources.attachments[1].label, "code_function-search-02.js", michael@0: "The second source label is correct."); michael@0: ok(gSources.values[1].contains("code_function-search-02.js"), michael@0: "The second source value appears to be correct."); michael@0: michael@0: is(gSources.attachments[2].label, "code_function-search-03.js", michael@0: "The third source label is correct."); michael@0: ok(gSources.values[2].contains("code_function-search-03.js"), michael@0: "The third source value appears to be correct."); michael@0: michael@0: is(gSources.attachments[3].label, "doc_function-search.html", michael@0: "The third source label is correct."); michael@0: ok(gSources.values[3].contains("doc_function-search.html"), michael@0: "The third source value appears to be correct."); michael@0: michael@0: is(gDebugger.SourceUtils._labelsCache.size, TOTAL_SOURCES, michael@0: "There should be " + TOTAL_SOURCES + " labels cached."); michael@0: is(gDebugger.SourceUtils._groupsCache.size, TOTAL_SOURCES, michael@0: "There should be " + TOTAL_SOURCES + " groups cached."); michael@0: } michael@0: michael@0: function getTextForSourcesAndCheckIntegrity() { michael@0: return gControllerSources.getTextForSources(gSources.values).then(testCacheIntegrity); michael@0: } michael@0: michael@0: function performReloadAndTestState() { michael@0: gDebugger.gTarget.once("will-navigate", testStateBeforeReload); michael@0: gDebugger.gTarget.once("navigate", testStateAfterReload); michael@0: return reloadActiveTab(gPanel, gDebugger.EVENTS.SOURCE_SHOWN); michael@0: } michael@0: michael@0: function testCacheIntegrity(aSources) { michael@0: for (let [url, contents] of aSources) { michael@0: // Sources of a debugee don't always finish fetching consecutively. D'uh. michael@0: let index = gSources.values.indexOf(url); michael@0: michael@0: ok(index >= 0 && index <= TOTAL_SOURCES, michael@0: "Found a source url cached correctly (" + index + ")."); michael@0: ok(contents.contains( michael@0: ["First source!", "Second source!", "Third source!", "Peanut butter jelly time!"][index]), michael@0: "Found a source's text contents cached correctly (" + index + ")."); michael@0: michael@0: info("Cached source url at " + index + ": " + url); michael@0: info("Cached source text at " + index + ": " + contents); michael@0: } michael@0: } michael@0: michael@0: function testStateBeforeReload() { michael@0: is(gSources.itemCount, 0, michael@0: "There should be no sources present in the sources list during reload."); michael@0: is(gDebugger.SourceUtils._labelsCache, gPrevLabelsCache, michael@0: "The labels cache has been refreshed during reload and no new objects were created."); michael@0: is(gDebugger.SourceUtils._groupsCache, gPrevGroupsCache, michael@0: "The groups cache has been refreshed during reload and no new objects were created."); michael@0: is(gDebugger.SourceUtils._labelsCache.size, 0, michael@0: "There should be no labels cached during reload"); michael@0: is(gDebugger.SourceUtils._groupsCache.size, 0, michael@0: "There should be no groups cached during reload"); michael@0: } michael@0: michael@0: function testStateAfterReload() { michael@0: is(gSources.itemCount, TOTAL_SOURCES, michael@0: "There should be " + TOTAL_SOURCES + " sources present in the sources list."); michael@0: is(gDebugger.SourceUtils._labelsCache.size, TOTAL_SOURCES, michael@0: "There should be " + TOTAL_SOURCES + " labels cached after reload."); michael@0: is(gDebugger.SourceUtils._groupsCache.size, TOTAL_SOURCES, michael@0: "There should be " + TOTAL_SOURCES + " groups cached after reload."); michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: gTab = null; michael@0: gDebuggee = null; michael@0: gPanel = null; michael@0: gDebugger = null; michael@0: gEditor = null; michael@0: gSources = null; michael@0: gControllerSources = null; michael@0: gPrevLabelsCache = null; michael@0: gPrevGroupsCache = null; michael@0: });