browser/devtools/debugger/test/browser_dbg_break-on-dom-02.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/debugger/test/browser_dbg_break-on-dom-02.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,126 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Tests that event listeners are fetched when the events tab is selected
     1.9 + * or while sources are fetched and the events tab is focused.
    1.10 + */
    1.11 +
    1.12 +const TAB_URL = EXAMPLE_URL + "doc_event-listeners-02.html";
    1.13 +
    1.14 +function test() {
    1.15 +  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    1.16 +    let gDebugger = aPanel.panelWin;
    1.17 +    let gView = gDebugger.DebuggerView;
    1.18 +    let gEvents = gView.EventListeners;
    1.19 +
    1.20 +    Task.spawn(function() {
    1.21 +      yield waitForSourceShown(aPanel, ".html");
    1.22 +      yield testFetchOnFocus();
    1.23 +      yield testFetchOnReloadWhenFocused();
    1.24 +      yield testFetchOnReloadWhenNotFocused();
    1.25 +      yield closeDebuggerAndFinish(aPanel);
    1.26 +    });
    1.27 +
    1.28 +    function testFetchOnFocus() {
    1.29 +      return Task.spawn(function() {
    1.30 +        let fetched = waitForDebuggerEvents(aPanel, gDebugger.EVENTS.EVENT_LISTENERS_FETCHED);
    1.31 +
    1.32 +        gView.toggleInstrumentsPane({ visible: true, animated: false }, 1);
    1.33 +        is(gView.instrumentsPaneHidden, false,
    1.34 +          "The instruments pane should be visible now.");
    1.35 +        is(gView.instrumentsPaneTab, "events-tab",
    1.36 +          "The events tab should be selected.");
    1.37 +
    1.38 +        yield fetched;
    1.39 +
    1.40 +        ok(true,
    1.41 +          "Event listeners were fetched when the events tab was selected");
    1.42 +        is(gEvents.itemCount, 4,
    1.43 +          "There should be 4 events displayed in the view.");
    1.44 +      });
    1.45 +    }
    1.46 +
    1.47 +    function testFetchOnReloadWhenFocused() {
    1.48 +      return Task.spawn(function() {
    1.49 +        let fetched = waitForDebuggerEvents(aPanel, gDebugger.EVENTS.EVENT_LISTENERS_FETCHED);
    1.50 +
    1.51 +        let reloading = once(gDebugger.gTarget, "will-navigate");
    1.52 +        let reloaded = waitForSourcesAfterReload();
    1.53 +        gDebugger.DebuggerController._target.activeTab.reload();
    1.54 +
    1.55 +        yield reloading;
    1.56 +
    1.57 +        is(gEvents.itemCount, 0,
    1.58 +          "There should be no events displayed in the view while reloading.");
    1.59 +        ok(true,
    1.60 +          "Event listeners were removed when the target started navigating.");
    1.61 +
    1.62 +        yield reloaded;
    1.63 +
    1.64 +        is(gView.instrumentsPaneHidden, false,
    1.65 +          "The instruments pane should still be visible.");
    1.66 +        is(gView.instrumentsPaneTab, "events-tab",
    1.67 +          "The events tab should still be selected.");
    1.68 +
    1.69 +        yield fetched;
    1.70 +
    1.71 +        is(gEvents.itemCount, 4,
    1.72 +          "There should be 4 events displayed in the view after reloading.");
    1.73 +        ok(true,
    1.74 +          "Event listeners were added back after the target finished navigating.");
    1.75 +      });
    1.76 +    }
    1.77 +
    1.78 +    function testFetchOnReloadWhenNotFocused() {
    1.79 +      return Task.spawn(function() {
    1.80 +        gDebugger.on(gDebugger.EVENTS.EVENT_LISTENERS_FETCHED, () => {
    1.81 +          ok(false, "Shouldn't have fetched any event listeners.");
    1.82 +        });
    1.83 +        gDebugger.on(gDebugger.EVENTS.EVENT_BREAKPOINTS_UPDATED, () => {
    1.84 +          ok(false, "Shouldn't have updated any event breakpoints.");
    1.85 +        });
    1.86 +
    1.87 +        gView.toggleInstrumentsPane({ visible: true, animated: false }, 0);
    1.88 +        is(gView.instrumentsPaneHidden, false,
    1.89 +          "The instruments pane should still be visible.");
    1.90 +        is(gView.instrumentsPaneTab, "variables-tab",
    1.91 +          "The variables tab should be selected.");
    1.92 +
    1.93 +        let reloading = once(gDebugger.gTarget, "will-navigate");
    1.94 +        let reloaded = waitForSourcesAfterReload();
    1.95 +        gDebugger.DebuggerController._target.activeTab.reload();
    1.96 +
    1.97 +        yield reloading;
    1.98 +
    1.99 +        is(gEvents.itemCount, 0,
   1.100 +          "There should be no events displayed in the view while reloading.");
   1.101 +        ok(true,
   1.102 +          "Event listeners were removed when the target started navigating.");
   1.103 +
   1.104 +        yield reloaded;
   1.105 +
   1.106 +        is(gView.instrumentsPaneHidden, false,
   1.107 +          "The instruments pane should still be visible.");
   1.108 +        is(gView.instrumentsPaneTab, "variables-tab",
   1.109 +          "The variables tab should still be selected.");
   1.110 +
   1.111 +        // Just to be really sure that the events will never ever fire.
   1.112 +        yield waitForTime(1000);
   1.113 +
   1.114 +        is(gEvents.itemCount, 0,
   1.115 +          "There should be no events displayed in the view after reloading.");
   1.116 +        ok(true,
   1.117 +          "Event listeners were not added after the target finished navigating.");
   1.118 +      });
   1.119 +    }
   1.120 +
   1.121 +    function waitForSourcesAfterReload() {
   1.122 +      return promise.all([
   1.123 +        waitForDebuggerEvents(aPanel, gDebugger.EVENTS.NEW_SOURCE),
   1.124 +        waitForDebuggerEvents(aPanel, gDebugger.EVENTS.SOURCES_ADDED),
   1.125 +        waitForDebuggerEvents(aPanel, gDebugger.EVENTS.SOURCE_SHOWN)
   1.126 +      ]);
   1.127 +    }
   1.128 +  });
   1.129 +}

mercurial