WebKit Bugzilla
Attachment 359146 Details for
Bug 193226
: Web Inspector: Audit: provide a way to determine whether a give node has event listeners
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-193226-20190115010954.patch (text/plain), 11.25 KB, created by
Devin Rousso
on 2019-01-15 01:09:55 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Devin Rousso
Created:
2019-01-15 01:09:55 PST
Size:
11.25 KB
patch
obsolete
>diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 7df1688a0e9beb1d10452ea5a3e0c3f79c18c8b8..034e3c902be3df7c66864b740eb61a2928f314f3 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,18 @@ >+2019-01-15 Devin Rousso <drousso@apple.com> >+ >+ Web Inspector: Audit: provide a way to determine whether a give node has event listeners >+ https://bugs.webkit.org/show_bug.cgi?id=193226 >+ <rdar://problem/46800005> >+ >+ Reviewed by Joseph Pecoraro. >+ >+ Test: inspector/audit/run-dom.html >+ >+ * inspector/InspectorAuditDOMObject.idl: >+ * inspector/InspectorAuditDOMObject.h: >+ * inspector/InspectorAuditDOMObject.cpp: >+ (WebCore::InspectorAuditDOMObject::hasEventListeners): Added. >+ > 2019-01-11 Antoine Quint <graouts@apple.com> > > Support parsing of additional values for the touch-action property >diff --git a/Source/WebCore/inspector/InspectorAuditDOMObject.cpp b/Source/WebCore/inspector/InspectorAuditDOMObject.cpp >index 99ea1332f689490c3bfa750e6beb558560f96a96..923287d3d2fc14a7c64590636ff4f1305574eb42 100644 >--- a/Source/WebCore/inspector/InspectorAuditDOMObject.cpp >+++ b/Source/WebCore/inspector/InspectorAuditDOMObject.cpp >@@ -27,12 +27,43 @@ > #include "config.h" > #include "InspectorAuditDOMObject.h" > >+#include "Node.h" >+#include <wtf/text/AtomicString.h> >+#include <wtf/text/WTFString.h> >+ > namespace WebCore { > > using namespace Inspector; > >-InspectorAuditDOMObject::InspectorAuditDOMObject() >+#define ERROR_IF_NO_ACTIVE_AUDIT() \ >+ if (!m_auditAgent.hasActiveAudit()) \ >+ return Exception { NotAllowedError, "Cannot be called outside of a Web Inspector Audit"_s }; >+ >+InspectorAuditDOMObject::InspectorAuditDOMObject(InspectorAuditAgent& auditAgent) >+ : m_auditAgent(auditAgent) > { > } > >+ExceptionOr<bool> InspectorAuditDOMObject::hasEventListeners(Node& node, const String& type) >+{ >+ ERROR_IF_NO_ACTIVE_AUDIT(); >+ >+ if (EventTargetData* eventTargetData = node.eventTargetData()) { >+ Vector<AtomicString> eventTypes; >+ if (type.isNull()) >+ eventTypes = eventTargetData->eventListenerMap.eventTypes(); >+ else >+ eventTypes.append(type); >+ >+ for (AtomicString& type : eventTypes) { >+ for (const RefPtr<RegisteredEventListener>& listener : node.eventListeners(type)) { >+ if (listener->callback().type() == EventListener::JSEventListenerType) >+ return true; >+ } >+ } >+ } >+ >+ return false; >+} >+ > } // namespace WebCore >diff --git a/Source/WebCore/inspector/InspectorAuditDOMObject.h b/Source/WebCore/inspector/InspectorAuditDOMObject.h >index d76252d61b9db6e4b58b04e6eede436a249ebe28..8cbc56a246a9ae94a6f492c9329c58bf8180e77b 100644 >--- a/Source/WebCore/inspector/InspectorAuditDOMObject.h >+++ b/Source/WebCore/inspector/InspectorAuditDOMObject.h >@@ -25,21 +25,28 @@ > > #pragma once > >+#include "ExceptionOr.h" > #include <JavaScriptCore/InspectorAuditAgent.h> > #include <wtf/Ref.h> > #include <wtf/RefCounted.h> > > namespace WebCore { > >+class Node; >+ > class InspectorAuditDOMObject : public RefCounted<InspectorAuditDOMObject> { > public: >- static Ref<InspectorAuditDOMObject> create(Inspector::InspectorAuditAgent&) >+ static Ref<InspectorAuditDOMObject> create(Inspector::InspectorAuditAgent& auditAgent) > { >- return adoptRef(*new InspectorAuditDOMObject()); >+ return adoptRef(*new InspectorAuditDOMObject(auditAgent)); > } > >+ ExceptionOr<bool> hasEventListeners(Node&, const String& type); >+ > private: >- explicit InspectorAuditDOMObject(); >+ explicit InspectorAuditDOMObject(Inspector::InspectorAuditAgent&); >+ >+ Inspector::InspectorAuditAgent& m_auditAgent; > }; > > } // namespace WebCore >diff --git a/Source/WebCore/inspector/InspectorAuditDOMObject.idl b/Source/WebCore/inspector/InspectorAuditDOMObject.idl >index e6e383b94e6b538900b6ac78eee582e4dd84a9a1..74d29c184b1512a93640e739d435c54a29cffcd2 100644 >--- a/Source/WebCore/inspector/InspectorAuditDOMObject.idl >+++ b/Source/WebCore/inspector/InspectorAuditDOMObject.idl >@@ -28,4 +28,5 @@ > JSGenerateToJSObject, > NoInterfaceObject, > ] interface InspectorAuditDOMObject { >+ [MayThrowException] boolean hasEventListeners(Node node, optional DOMString type); > }; >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index d0d13a9cd5282c985717cb7857ef83014e54b443..63ffbdb2bd8813a37b82f283b45302c6d7d63e07 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,14 @@ >+2019-01-15 Devin Rousso <drousso@apple.com> >+ >+ Web Inspector: Audit: provide a way to determine whether a give node has event listeners >+ https://bugs.webkit.org/show_bug.cgi?id=193226 >+ <rdar://problem/46800005> >+ >+ Reviewed by Joseph Pecoraro. >+ >+ * inspector/audit/run-dom.html: Added. >+ * inspector/audit/run-dom-expected.txt: Added. >+ > 2019-01-15 Devin Rousso <drousso@apple.com> > > Web Inspector: Audit: create new IDL type for exposing special functionality in test context >diff --git a/LayoutTests/inspector/audit/run-dom-expected.txt b/LayoutTests/inspector/audit/run-dom-expected.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..4984ca491475519ba9ead04145c97bcf504f587c >--- /dev/null >+++ b/LayoutTests/inspector/audit/run-dom-expected.txt >@@ -0,0 +1,61 @@ >+Tests for the injected WebInspectorAudit.DOM functions. >+ >+ >+ >+== Running test suite: Audit.run.DOM >+-- Running test case: Audit.run.DOM.hasEventListeners.noListeners >+Audit setup... >+Audit run `WebInspectorAudit.DOM.hasEventListeners(document.querySelector("#noListeners"))`... >+Result: false >+Audit teardown... >+ >+-- Running test case: Audit.run.DOM.hasEventListeners.noListeners.WithArgs >+Audit setup... >+Audit run `WebInspectorAudit.DOM.hasEventListeners(document.querySelector("#noListeners"), ["FakeEvent"])`... >+Result: false >+Audit teardown... >+ >+-- Running test case: Audit.run.DOM.hasEventListeners.attributeListener >+Audit setup... >+Audit run `WebInspectorAudit.DOM.hasEventListeners(document.querySelector("#attributeListener"))`... >+Result: true >+Audit teardown... >+ >+-- Running test case: Audit.run.DOM.hasEventListeners.attributeListener.WithArgs >+Audit setup... >+Audit run `WebInspectorAudit.DOM.hasEventListeners(document.querySelector("#attributeListener"), ["FakeEvent"])`... >+Result: false >+Audit teardown... >+ >+-- Running test case: Audit.run.DOM.hasEventListeners.javascriptListener >+Audit setup... >+Audit run `WebInspectorAudit.DOM.hasEventListeners(document.querySelector("#javascriptListener"))`... >+Result: true >+Audit teardown... >+ >+-- Running test case: Audit.run.DOM.hasEventListeners.javascriptListener.WithArgs >+Audit setup... >+Audit run `WebInspectorAudit.DOM.hasEventListeners(document.querySelector("#javascriptListener"), ["FakeEvent"])`... >+Result: false >+Audit teardown... >+ >+-- Running test case: Audit.run.DOM.hasEventListeners.builtinListener >+Audit setup... >+Audit run `WebInspectorAudit.DOM.hasEventListeners(document.querySelector("#builtinListener"))`... >+Result: false >+Audit teardown... >+ >+-- Running test case: Audit.run.DOM.hasEventListeners.builtinListener.WithArgs >+Audit setup... >+Audit run `WebInspectorAudit.DOM.hasEventListeners(document.querySelector("#builtinListener"), ["FakeEvent"])`... >+Result: false >+Audit teardown... >+ >+-- Running test case: Audit.run.DOM.InvalidCopiedFunctionCall >+Audit setup... >+Copying WebInspectorAudit to window... >+Audit teardown... >+Testing copied hasEventListeners... >+PASS: Should produce an exception. >+Error: NotAllowedError: Cannot be called outside of a Web Inspector Audit >+ >diff --git a/LayoutTests/inspector/audit/run-dom.html b/LayoutTests/inspector/audit/run-dom.html >new file mode 100644 >index 0000000000000000000000000000000000000000..fa37283c3b8da562cbc2e9da2636149a478da5d8 >--- /dev/null >+++ b/LayoutTests/inspector/audit/run-dom.html >@@ -0,0 +1,81 @@ >+<!DOCTYPE html> >+<html> >+<head> >+<script src="../../http/tests/inspector/resources/inspector-test.js"></script> >+<script src="resources/audit-utilities.js"></script> >+<script> >+function test() >+{ >+ let suite = InspectorTest.Audit.createSuite("Audit.run.DOM"); >+ >+ function evaluateStringForTest(func, target, args) { >+ return `WebInspectorAudit.DOM.${func}(document.querySelector("#${target}")${args ? ", " + JSON.stringify(args) : ""})`; >+ } >+ >+ const tests = [ >+ { func: "hasEventListeners", target: "noListeners" }, >+ { func: "hasEventListeners", target: "noListeners", args: ["FakeEvent"] }, >+ { func: "hasEventListeners", target: "attributeListener" }, >+ { func: "hasEventListeners", target: "attributeListener", args: ["FakeEvent"] }, >+ { func: "hasEventListeners", target: "javascriptListener" }, >+ { func: "hasEventListeners", target: "javascriptListener", args: ["FakeEvent"] }, >+ { func: "hasEventListeners", target: "builtinListener" }, >+ { func: "hasEventListeners", target: "builtinListener", args: ["FakeEvent"] }, >+ ]; >+ >+ for (let {func, target, args} of tests) { >+ suite.addTestCase({ >+ name: "Audit.run.DOM." + func + "." + target + (args ? ".WithArgs" : ""), >+ async test() { >+ let functionString = evaluateStringForTest(func, target, args); >+ >+ await InspectorTest.Audit.setupAudit(); >+ >+ InspectorTest.log(`Audit run \`${functionString}\`...`); >+ let {result, wasThrown} = await AuditAgent.run(`function() { return ${functionString}; }`); >+ InspectorTest.assert(!wasThrown, "Should not throw an exception."); >+ if (!wasThrown) >+ InspectorTest.log("Result: " + result.value); >+ else >+ InspectorTest.log(result.description); >+ >+ await InspectorTest.Audit.teardownAudit(); >+ }, >+ }); >+ } >+ >+ suite.addTestCase({ >+ name: "Audit.run.DOM.InvalidCopiedFunctionCall", >+ description: "Check that WebInspectorAudit.DOM functions throw an error when called outside of an audit.", >+ async test() { >+ let functions = new Map; >+ for (let test of tests) >+ functions.set(test.func, test); >+ >+ await InspectorTest.Audit.setupAudit(); >+ InspectorTest.log(`Copying WebInspectorAudit to window...`); >+ let {wasThrown} = await AuditAgent.run(`function() { window.CopiedWebInspectorAudit = WebInspectorAudit; }`); >+ InspectorTest.assert(!wasThrown, "Should not throw an exception."); >+ await InspectorTest.Audit.teardownAudit(); >+ >+ for (let {func, target, args} of functions.values()) { >+ InspectorTest.log(`Testing copied ${func}...`); >+ await InspectorTest.expectException(async function() { >+ await InspectorTest.evaluateInPage("window.Copied" + evaluateStringForTest(func, target, args)); >+ }); >+ } >+ }, >+ }); >+ >+ suite.runTestCasesAndFinish(); >+} >+</script> >+</head> >+<body onload="runTest()"> >+ <p>Tests for the injected WebInspectorAudit.DOM functions.</p> >+ <div id="noListeners"></div> >+ <div id="attributeListener" onclick="void(0);"></div> >+ <div id="javascriptListener"><script>document.querySelector("#javascriptListener").addEventListener("click", () => {});</script></div> >+ <video id="builtinListener"></video> >+</body> >+</html>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 193226
:
358566
|
358849
|
359145
| 359146 |
359150