browser/devtools/debugger/test/browser_dbg_break-on-dom-02.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 that event listeners are fetched when the events tab is selected
michael@0 6 * or while sources are fetched and the events tab is focused.
michael@0 7 */
michael@0 8
michael@0 9 const TAB_URL = EXAMPLE_URL + "doc_event-listeners-02.html";
michael@0 10
michael@0 11 function test() {
michael@0 12 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 13 let gDebugger = aPanel.panelWin;
michael@0 14 let gView = gDebugger.DebuggerView;
michael@0 15 let gEvents = gView.EventListeners;
michael@0 16
michael@0 17 Task.spawn(function() {
michael@0 18 yield waitForSourceShown(aPanel, ".html");
michael@0 19 yield testFetchOnFocus();
michael@0 20 yield testFetchOnReloadWhenFocused();
michael@0 21 yield testFetchOnReloadWhenNotFocused();
michael@0 22 yield closeDebuggerAndFinish(aPanel);
michael@0 23 });
michael@0 24
michael@0 25 function testFetchOnFocus() {
michael@0 26 return Task.spawn(function() {
michael@0 27 let fetched = waitForDebuggerEvents(aPanel, gDebugger.EVENTS.EVENT_LISTENERS_FETCHED);
michael@0 28
michael@0 29 gView.toggleInstrumentsPane({ visible: true, animated: false }, 1);
michael@0 30 is(gView.instrumentsPaneHidden, false,
michael@0 31 "The instruments pane should be visible now.");
michael@0 32 is(gView.instrumentsPaneTab, "events-tab",
michael@0 33 "The events tab should be selected.");
michael@0 34
michael@0 35 yield fetched;
michael@0 36
michael@0 37 ok(true,
michael@0 38 "Event listeners were fetched when the events tab was selected");
michael@0 39 is(gEvents.itemCount, 4,
michael@0 40 "There should be 4 events displayed in the view.");
michael@0 41 });
michael@0 42 }
michael@0 43
michael@0 44 function testFetchOnReloadWhenFocused() {
michael@0 45 return Task.spawn(function() {
michael@0 46 let fetched = waitForDebuggerEvents(aPanel, gDebugger.EVENTS.EVENT_LISTENERS_FETCHED);
michael@0 47
michael@0 48 let reloading = once(gDebugger.gTarget, "will-navigate");
michael@0 49 let reloaded = waitForSourcesAfterReload();
michael@0 50 gDebugger.DebuggerController._target.activeTab.reload();
michael@0 51
michael@0 52 yield reloading;
michael@0 53
michael@0 54 is(gEvents.itemCount, 0,
michael@0 55 "There should be no events displayed in the view while reloading.");
michael@0 56 ok(true,
michael@0 57 "Event listeners were removed when the target started navigating.");
michael@0 58
michael@0 59 yield reloaded;
michael@0 60
michael@0 61 is(gView.instrumentsPaneHidden, false,
michael@0 62 "The instruments pane should still be visible.");
michael@0 63 is(gView.instrumentsPaneTab, "events-tab",
michael@0 64 "The events tab should still be selected.");
michael@0 65
michael@0 66 yield fetched;
michael@0 67
michael@0 68 is(gEvents.itemCount, 4,
michael@0 69 "There should be 4 events displayed in the view after reloading.");
michael@0 70 ok(true,
michael@0 71 "Event listeners were added back after the target finished navigating.");
michael@0 72 });
michael@0 73 }
michael@0 74
michael@0 75 function testFetchOnReloadWhenNotFocused() {
michael@0 76 return Task.spawn(function() {
michael@0 77 gDebugger.on(gDebugger.EVENTS.EVENT_LISTENERS_FETCHED, () => {
michael@0 78 ok(false, "Shouldn't have fetched any event listeners.");
michael@0 79 });
michael@0 80 gDebugger.on(gDebugger.EVENTS.EVENT_BREAKPOINTS_UPDATED, () => {
michael@0 81 ok(false, "Shouldn't have updated any event breakpoints.");
michael@0 82 });
michael@0 83
michael@0 84 gView.toggleInstrumentsPane({ visible: true, animated: false }, 0);
michael@0 85 is(gView.instrumentsPaneHidden, false,
michael@0 86 "The instruments pane should still be visible.");
michael@0 87 is(gView.instrumentsPaneTab, "variables-tab",
michael@0 88 "The variables tab should be selected.");
michael@0 89
michael@0 90 let reloading = once(gDebugger.gTarget, "will-navigate");
michael@0 91 let reloaded = waitForSourcesAfterReload();
michael@0 92 gDebugger.DebuggerController._target.activeTab.reload();
michael@0 93
michael@0 94 yield reloading;
michael@0 95
michael@0 96 is(gEvents.itemCount, 0,
michael@0 97 "There should be no events displayed in the view while reloading.");
michael@0 98 ok(true,
michael@0 99 "Event listeners were removed when the target started navigating.");
michael@0 100
michael@0 101 yield reloaded;
michael@0 102
michael@0 103 is(gView.instrumentsPaneHidden, false,
michael@0 104 "The instruments pane should still be visible.");
michael@0 105 is(gView.instrumentsPaneTab, "variables-tab",
michael@0 106 "The variables tab should still be selected.");
michael@0 107
michael@0 108 // Just to be really sure that the events will never ever fire.
michael@0 109 yield waitForTime(1000);
michael@0 110
michael@0 111 is(gEvents.itemCount, 0,
michael@0 112 "There should be no events displayed in the view after reloading.");
michael@0 113 ok(true,
michael@0 114 "Event listeners were not added after the target finished navigating.");
michael@0 115 });
michael@0 116 }
michael@0 117
michael@0 118 function waitForSourcesAfterReload() {
michael@0 119 return promise.all([
michael@0 120 waitForDebuggerEvents(aPanel, gDebugger.EVENTS.NEW_SOURCE),
michael@0 121 waitForDebuggerEvents(aPanel, gDebugger.EVENTS.SOURCES_ADDED),
michael@0 122 waitForDebuggerEvents(aPanel, gDebugger.EVENTS.SOURCE_SHOWN)
michael@0 123 ]);
michael@0 124 }
michael@0 125 });
michael@0 126 }

mercurial