1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_break-on-dom-03.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,89 @@ 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 properly displayed in the view. 1.9 + */ 1.10 + 1.11 +const TAB_URL = EXAMPLE_URL + "doc_event-listeners-02.html"; 1.12 + 1.13 +function test() { 1.14 + initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 1.15 + let gDebugger = aPanel.panelWin; 1.16 + let gView = gDebugger.DebuggerView; 1.17 + let gEvents = gView.EventListeners; 1.18 + 1.19 + Task.spawn(function() { 1.20 + yield waitForSourceShown(aPanel, ".html"); 1.21 + 1.22 + let fetched = waitForDebuggerEvents(aPanel, gDebugger.EVENTS.EVENT_LISTENERS_FETCHED); 1.23 + gView.toggleInstrumentsPane({ visible: true, animated: false }, 1); 1.24 + yield fetched; 1.25 + 1.26 + is(gEvents.widget._parent.querySelectorAll(".side-menu-widget-group").length, 3, 1.27 + "There should be 3 groups shown in the view."); 1.28 + is(gEvents.widget._parent.querySelectorAll(".side-menu-widget-group-checkbox").length, 3, 1.29 + "There should be a checkbox for each group shown in the view."); 1.30 + 1.31 + is(gEvents.widget._parent.querySelectorAll(".side-menu-widget-item").length, 4, 1.32 + "There should be 4 items shown in the view."); 1.33 + is(gEvents.widget._parent.querySelectorAll(".side-menu-widget-item-checkbox").length, 4, 1.34 + "There should be a checkbox for each item shown in the view."); 1.35 + 1.36 + testEventItem(0, "doc_event-listeners-02.html", "keydown", ["window", "body"], false); 1.37 + testEventItem(1, "doc_event-listeners-02.html", "click", ["body > button:nth-child(1)"], false); 1.38 + testEventItem(2, "doc_event-listeners-02.html", "change", ["body > input:nth-child(2)"], false); 1.39 + testEventItem(3, "doc_event-listeners-02.html", "keyup", ["body > input:nth-child(2)"], false); 1.40 + 1.41 + testEventGroup("interactionEvents", false); 1.42 + testEventGroup("keyboardEvents", false); 1.43 + testEventGroup("mouseEvents", false); 1.44 + 1.45 + is(gEvents.getAllEvents().toString(), "keydown,click,change,keyup", 1.46 + "The getAllEvents() method returns the correct stuff."); 1.47 + is(gEvents.getCheckedEvents().toString(), "", 1.48 + "The getCheckedEvents() method returns the correct stuff."); 1.49 + 1.50 + yield ensureThreadClientState(aPanel, "resumed"); 1.51 + yield closeDebuggerAndFinish(aPanel); 1.52 + }); 1.53 + 1.54 + function testEventItem(index, label, type, selectors, checked) { 1.55 + let item = gEvents.items[index]; 1.56 + let node = item.target; 1.57 + 1.58 + ok(item.attachment.url.contains(label), 1.59 + "The event at index " + index + " has the correct url."); 1.60 + is(item.attachment.type, type, 1.61 + "The event at index " + index + " has the correct type."); 1.62 + is(item.attachment.selectors.toString(), selectors, 1.63 + "The event at index " + index + " has the correct selectors."); 1.64 + is(item.attachment.checkboxState, checked, 1.65 + "The event at index " + index + " has the correct checkbox state."); 1.66 + 1.67 + let targets = selectors.length > 1 1.68 + ? gDebugger.L10N.getFormatStr("eventNodes", selectors.length) 1.69 + : selectors.toString(); 1.70 + 1.71 + is(node.querySelector(".dbg-event-listener-type").getAttribute("value"), type, 1.72 + "The correct type is shown for this event."); 1.73 + is(node.querySelector(".dbg-event-listener-targets").getAttribute("value"), targets, 1.74 + "The correct target is shown for this event."); 1.75 + is(node.querySelector(".dbg-event-listener-location").getAttribute("value"), label, 1.76 + "The correct location is shown for this event."); 1.77 + is(node.parentNode.querySelector(".side-menu-widget-item-checkbox").checked, checked, 1.78 + "The correct checkbox state is shown for this event."); 1.79 + } 1.80 + 1.81 + function testEventGroup(string, checked) { 1.82 + let name = gDebugger.L10N.getStr(string); 1.83 + let group = gEvents.widget._parent 1.84 + .querySelector(".side-menu-widget-group[name=" + name + "]"); 1.85 + 1.86 + is(group.querySelector(".side-menu-widget-group-title > .name").value, name, 1.87 + "The correct label is shown for the group named " + name + "."); 1.88 + is(group.querySelector(".side-menu-widget-group-checkbox").checked, checked, 1.89 + "The correct checkbox state is shown for the group named " + name + "."); 1.90 + } 1.91 + }); 1.92 +}