browser/devtools/debugger/test/browser_dbg_sources-cache.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Tests if the sources cache knows how to cache sources when prompted.
michael@0 6 */
michael@0 7
michael@0 8 const TAB_URL = EXAMPLE_URL + "doc_function-search.html";
michael@0 9 const TOTAL_SOURCES = 4;
michael@0 10
michael@0 11 let gTab, gDebuggee, gPanel, gDebugger;
michael@0 12 let gEditor, gSources, gControllerSources;
michael@0 13 let gPrevLabelsCache, gPrevGroupsCache;
michael@0 14
michael@0 15 function test() {
michael@0 16 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 17 gTab = aTab;
michael@0 18 gDebuggee = aDebuggee;
michael@0 19 gPanel = aPanel;
michael@0 20 gDebugger = gPanel.panelWin;
michael@0 21 gEditor = gDebugger.DebuggerView.editor;
michael@0 22 gSources = gDebugger.DebuggerView.Sources;
michael@0 23 gControllerSources = gDebugger.DebuggerController.SourceScripts;
michael@0 24 gPrevLabelsCache = gDebugger.SourceUtils._labelsCache;
michael@0 25 gPrevGroupsCache = gDebugger.SourceUtils._groupsCache;
michael@0 26
michael@0 27 waitForSourceShown(gPanel, "-01.js")
michael@0 28 .then(initialChecks)
michael@0 29 .then(getTextForSourcesAndCheckIntegrity)
michael@0 30 .then(performReloadAndTestState)
michael@0 31 .then(() => closeDebuggerAndFinish(gPanel))
michael@0 32 .then(null, aError => {
michael@0 33 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
michael@0 34 });
michael@0 35 });
michael@0 36 }
michael@0 37
michael@0 38 function initialChecks() {
michael@0 39 ok(gEditor.getText().contains("First source!"),
michael@0 40 "Editor text contents appears to be correct.");
michael@0 41 is(gSources.selectedItem.attachment.label, "code_function-search-01.js",
michael@0 42 "The currently selected label in the sources container is correct.");
michael@0 43 ok(gSources.selectedValue.contains("code_function-search-01.js"),
michael@0 44 "The currently selected value in the sources container appears to be correct.");
michael@0 45
michael@0 46 is(gSources.itemCount, TOTAL_SOURCES,
michael@0 47 "There should be " + TOTAL_SOURCES + " sources present in the sources list.");
michael@0 48 is(gSources.visibleItems.length, TOTAL_SOURCES,
michael@0 49 "There should be " + TOTAL_SOURCES + " sources visible in the sources list.");
michael@0 50 is(gSources.attachments.length, TOTAL_SOURCES,
michael@0 51 "There should be " + TOTAL_SOURCES + " attachments stored in the sources container model.")
michael@0 52 is(gSources.values.length, TOTAL_SOURCES,
michael@0 53 "There should be " + TOTAL_SOURCES + " values stored in the sources container model.")
michael@0 54
michael@0 55 info("Source labels: " + gSources.attachments.toSource());
michael@0 56 info("Source values: " + gSources.values.toSource());
michael@0 57
michael@0 58 is(gSources.attachments[0].label, "code_function-search-01.js",
michael@0 59 "The first source label is correct.");
michael@0 60 ok(gSources.values[0].contains("code_function-search-01.js"),
michael@0 61 "The first source value appears to be correct.");
michael@0 62
michael@0 63 is(gSources.attachments[1].label, "code_function-search-02.js",
michael@0 64 "The second source label is correct.");
michael@0 65 ok(gSources.values[1].contains("code_function-search-02.js"),
michael@0 66 "The second source value appears to be correct.");
michael@0 67
michael@0 68 is(gSources.attachments[2].label, "code_function-search-03.js",
michael@0 69 "The third source label is correct.");
michael@0 70 ok(gSources.values[2].contains("code_function-search-03.js"),
michael@0 71 "The third source value appears to be correct.");
michael@0 72
michael@0 73 is(gSources.attachments[3].label, "doc_function-search.html",
michael@0 74 "The third source label is correct.");
michael@0 75 ok(gSources.values[3].contains("doc_function-search.html"),
michael@0 76 "The third source value appears to be correct.");
michael@0 77
michael@0 78 is(gDebugger.SourceUtils._labelsCache.size, TOTAL_SOURCES,
michael@0 79 "There should be " + TOTAL_SOURCES + " labels cached.");
michael@0 80 is(gDebugger.SourceUtils._groupsCache.size, TOTAL_SOURCES,
michael@0 81 "There should be " + TOTAL_SOURCES + " groups cached.");
michael@0 82 }
michael@0 83
michael@0 84 function getTextForSourcesAndCheckIntegrity() {
michael@0 85 return gControllerSources.getTextForSources(gSources.values).then(testCacheIntegrity);
michael@0 86 }
michael@0 87
michael@0 88 function performReloadAndTestState() {
michael@0 89 gDebugger.gTarget.once("will-navigate", testStateBeforeReload);
michael@0 90 gDebugger.gTarget.once("navigate", testStateAfterReload);
michael@0 91 return reloadActiveTab(gPanel, gDebugger.EVENTS.SOURCE_SHOWN);
michael@0 92 }
michael@0 93
michael@0 94 function testCacheIntegrity(aSources) {
michael@0 95 for (let [url, contents] of aSources) {
michael@0 96 // Sources of a debugee don't always finish fetching consecutively. D'uh.
michael@0 97 let index = gSources.values.indexOf(url);
michael@0 98
michael@0 99 ok(index >= 0 && index <= TOTAL_SOURCES,
michael@0 100 "Found a source url cached correctly (" + index + ").");
michael@0 101 ok(contents.contains(
michael@0 102 ["First source!", "Second source!", "Third source!", "Peanut butter jelly time!"][index]),
michael@0 103 "Found a source's text contents cached correctly (" + index + ").");
michael@0 104
michael@0 105 info("Cached source url at " + index + ": " + url);
michael@0 106 info("Cached source text at " + index + ": " + contents);
michael@0 107 }
michael@0 108 }
michael@0 109
michael@0 110 function testStateBeforeReload() {
michael@0 111 is(gSources.itemCount, 0,
michael@0 112 "There should be no sources present in the sources list during reload.");
michael@0 113 is(gDebugger.SourceUtils._labelsCache, gPrevLabelsCache,
michael@0 114 "The labels cache has been refreshed during reload and no new objects were created.");
michael@0 115 is(gDebugger.SourceUtils._groupsCache, gPrevGroupsCache,
michael@0 116 "The groups cache has been refreshed during reload and no new objects were created.");
michael@0 117 is(gDebugger.SourceUtils._labelsCache.size, 0,
michael@0 118 "There should be no labels cached during reload");
michael@0 119 is(gDebugger.SourceUtils._groupsCache.size, 0,
michael@0 120 "There should be no groups cached during reload");
michael@0 121 }
michael@0 122
michael@0 123 function testStateAfterReload() {
michael@0 124 is(gSources.itemCount, TOTAL_SOURCES,
michael@0 125 "There should be " + TOTAL_SOURCES + " sources present in the sources list.");
michael@0 126 is(gDebugger.SourceUtils._labelsCache.size, TOTAL_SOURCES,
michael@0 127 "There should be " + TOTAL_SOURCES + " labels cached after reload.");
michael@0 128 is(gDebugger.SourceUtils._groupsCache.size, TOTAL_SOURCES,
michael@0 129 "There should be " + TOTAL_SOURCES + " groups cached after reload.");
michael@0 130 }
michael@0 131
michael@0 132 registerCleanupFunction(function() {
michael@0 133 gTab = null;
michael@0 134 gDebuggee = null;
michael@0 135 gPanel = null;
michael@0 136 gDebugger = null;
michael@0 137 gEditor = null;
michael@0 138 gSources = null;
michael@0 139 gControllerSources = null;
michael@0 140 gPrevLabelsCache = null;
michael@0 141 gPrevGroupsCache = null;
michael@0 142 });

mercurial