browser/devtools/debugger/test/browser_dbg_break-on-dom-03.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 properly displayed in the view.
michael@0 6 */
michael@0 7
michael@0 8 const TAB_URL = EXAMPLE_URL + "doc_event-listeners-02.html";
michael@0 9
michael@0 10 function test() {
michael@0 11 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 12 let gDebugger = aPanel.panelWin;
michael@0 13 let gView = gDebugger.DebuggerView;
michael@0 14 let gEvents = gView.EventListeners;
michael@0 15
michael@0 16 Task.spawn(function() {
michael@0 17 yield waitForSourceShown(aPanel, ".html");
michael@0 18
michael@0 19 let fetched = waitForDebuggerEvents(aPanel, gDebugger.EVENTS.EVENT_LISTENERS_FETCHED);
michael@0 20 gView.toggleInstrumentsPane({ visible: true, animated: false }, 1);
michael@0 21 yield fetched;
michael@0 22
michael@0 23 is(gEvents.widget._parent.querySelectorAll(".side-menu-widget-group").length, 3,
michael@0 24 "There should be 3 groups shown in the view.");
michael@0 25 is(gEvents.widget._parent.querySelectorAll(".side-menu-widget-group-checkbox").length, 3,
michael@0 26 "There should be a checkbox for each group shown in the view.");
michael@0 27
michael@0 28 is(gEvents.widget._parent.querySelectorAll(".side-menu-widget-item").length, 4,
michael@0 29 "There should be 4 items shown in the view.");
michael@0 30 is(gEvents.widget._parent.querySelectorAll(".side-menu-widget-item-checkbox").length, 4,
michael@0 31 "There should be a checkbox for each item shown in the view.");
michael@0 32
michael@0 33 testEventItem(0, "doc_event-listeners-02.html", "keydown", ["window", "body"], false);
michael@0 34 testEventItem(1, "doc_event-listeners-02.html", "click", ["body > button:nth-child(1)"], false);
michael@0 35 testEventItem(2, "doc_event-listeners-02.html", "change", ["body > input:nth-child(2)"], false);
michael@0 36 testEventItem(3, "doc_event-listeners-02.html", "keyup", ["body > input:nth-child(2)"], false);
michael@0 37
michael@0 38 testEventGroup("interactionEvents", false);
michael@0 39 testEventGroup("keyboardEvents", false);
michael@0 40 testEventGroup("mouseEvents", false);
michael@0 41
michael@0 42 is(gEvents.getAllEvents().toString(), "keydown,click,change,keyup",
michael@0 43 "The getAllEvents() method returns the correct stuff.");
michael@0 44 is(gEvents.getCheckedEvents().toString(), "",
michael@0 45 "The getCheckedEvents() method returns the correct stuff.");
michael@0 46
michael@0 47 yield ensureThreadClientState(aPanel, "resumed");
michael@0 48 yield closeDebuggerAndFinish(aPanel);
michael@0 49 });
michael@0 50
michael@0 51 function testEventItem(index, label, type, selectors, checked) {
michael@0 52 let item = gEvents.items[index];
michael@0 53 let node = item.target;
michael@0 54
michael@0 55 ok(item.attachment.url.contains(label),
michael@0 56 "The event at index " + index + " has the correct url.");
michael@0 57 is(item.attachment.type, type,
michael@0 58 "The event at index " + index + " has the correct type.");
michael@0 59 is(item.attachment.selectors.toString(), selectors,
michael@0 60 "The event at index " + index + " has the correct selectors.");
michael@0 61 is(item.attachment.checkboxState, checked,
michael@0 62 "The event at index " + index + " has the correct checkbox state.");
michael@0 63
michael@0 64 let targets = selectors.length > 1
michael@0 65 ? gDebugger.L10N.getFormatStr("eventNodes", selectors.length)
michael@0 66 : selectors.toString();
michael@0 67
michael@0 68 is(node.querySelector(".dbg-event-listener-type").getAttribute("value"), type,
michael@0 69 "The correct type is shown for this event.");
michael@0 70 is(node.querySelector(".dbg-event-listener-targets").getAttribute("value"), targets,
michael@0 71 "The correct target is shown for this event.");
michael@0 72 is(node.querySelector(".dbg-event-listener-location").getAttribute("value"), label,
michael@0 73 "The correct location is shown for this event.");
michael@0 74 is(node.parentNode.querySelector(".side-menu-widget-item-checkbox").checked, checked,
michael@0 75 "The correct checkbox state is shown for this event.");
michael@0 76 }
michael@0 77
michael@0 78 function testEventGroup(string, checked) {
michael@0 79 let name = gDebugger.L10N.getStr(string);
michael@0 80 let group = gEvents.widget._parent
michael@0 81 .querySelector(".side-menu-widget-group[name=" + name + "]");
michael@0 82
michael@0 83 is(group.querySelector(".side-menu-widget-group-title > .name").value, name,
michael@0 84 "The correct label is shown for the group named " + name + ".");
michael@0 85 is(group.querySelector(".side-menu-widget-group-checkbox").checked, checked,
michael@0 86 "The correct checkbox state is shown for the group named " + name + ".");
michael@0 87 }
michael@0 88 });
michael@0 89 }

mercurial