WebKit Bugzilla
Attachment 358566 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
193226.diff (text/plain), 7.21 KB, created by
Devin Rousso
on 2019-01-07 19:46:21 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Devin Rousso
Created:
2019-01-07 19:46:21 PST
Size:
7.21 KB
patch
obsolete
>diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 50a6f484396..a40d7425e3f 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,14 @@ >+2019-01-07 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 NOBODY (OOPS!). >+ >+ * inspector/audit/run-dom.html: Added. >+ * inspector/audit/run-dom-expected.txt: Added. >+ > 2019-01-06 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 00000000000..27de0d63731 >--- /dev/null >+++ b/LayoutTests/inspector/audit/run-dom-expected.txt >@@ -0,0 +1,29 @@ >+Tests for the injected AUDIT.DOM functions. >+ >+ >+ >+== Running test suite: Audit.run.DOM >+-- Running test case: Audit.run.DOM.hasEventListeners.noListeners >+Audit setup... >+Audit run `AUDIT.DOM.hasEventListeners(document.querySelector("#noListeners"))`... >+Result: false >+Audit teardown... >+ >+-- Running test case: Audit.run.DOM.hasEventListeners.attributeListener >+Audit setup... >+Audit run `AUDIT.DOM.hasEventListeners(document.querySelector("#attributeListener"))`... >+Result: true >+Audit teardown... >+ >+-- Running test case: Audit.run.DOM.hasEventListeners.javascriptListener >+Audit setup... >+Audit run `AUDIT.DOM.hasEventListeners(document.querySelector("#javascriptListener"))`... >+Result: true >+Audit teardown... >+ >+-- Running test case: Audit.run.DOM.hasEventListeners.builtinListener >+Audit setup... >+Audit run `AUDIT.DOM.hasEventListeners(document.querySelector("#builtinListener"))`... >+Result: false >+Audit teardown... >+ >diff --git a/LayoutTests/inspector/audit/run-dom.html b/LayoutTests/inspector/audit/run-dom.html >new file mode 100644 >index 00000000000..59402b32a1a >--- /dev/null >+++ b/LayoutTests/inspector/audit/run-dom.html >@@ -0,0 +1,50 @@ >+<!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"); >+ >+ const tests = [ >+ { func: "hasEventListeners", target: "noListeners" }, >+ { func: "hasEventListeners", target: "attributeListener" }, >+ { func: "hasEventListeners", target: "javascriptListener" }, >+ { func: "hasEventListeners", target: "builtinListener" }, >+ ]; >+ >+ for (let {func, target} of tests) { >+ suite.addTestCase({ >+ name: "Audit.run.DOM." + func + "." + target, >+ async test() { >+ let functionString = `AUDIT.DOM.${func}(document.querySelector("#${target}"))`; >+ >+ 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.runTestCasesAndFinish(); >+} >+</script> >+</head> >+<body onload="runTest()"> >+ <p>Tests for the injected AUDIT.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> >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 4fd67da18d9..35a5c8ff24a 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,18 @@ >+2019-01-07 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 NOBODY (OOPS!). >+ >+ Test: inspector/audit/run-dom.html >+ >+ * inspector/InspectorAuditDOMUtilities.idl: >+ * inspector/InspectorAuditDOMUtilities.h: >+ * inspector/InspectorAuditDOMUtilities.cpp: >+ (WebCore::InspectorAuditDOMUtilities::hasEventListeners): Added. >+ > 2019-01-06 Devin Rousso <drousso@apple.com> > > Web Inspector: Audit: create new IDL type for exposing special functionality in test context >diff --git a/Source/WebCore/inspector/InspectorAuditDOMUtilities.cpp b/Source/WebCore/inspector/InspectorAuditDOMUtilities.cpp >index bd98acde78a..e6ba4a1fb24 100644 >--- a/Source/WebCore/inspector/InspectorAuditDOMUtilities.cpp >+++ b/Source/WebCore/inspector/InspectorAuditDOMUtilities.cpp >@@ -27,10 +27,33 @@ > #include "config.h" > #include "InspectorAuditDOMUtilities.h" > >+#include "Node.h" >+#include <wtf/text/AtomicString.h> >+#include <wtf/text/WTFString.h> >+ > namespace WebCore { > > InspectorAuditDOMUtilities::InspectorAuditDOMUtilities() > { > } > >+bool InspectorAuditDOMUtilities::hasEventListeners(Node& node, const String& type) >+{ >+ 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/InspectorAuditDOMUtilities.h b/Source/WebCore/inspector/InspectorAuditDOMUtilities.h >index 575cbefc165..792d5d62c09 100644 >--- a/Source/WebCore/inspector/InspectorAuditDOMUtilities.h >+++ b/Source/WebCore/inspector/InspectorAuditDOMUtilities.h >@@ -25,11 +25,14 @@ > > #pragma once > >+#include <wtf/Forward.h> > #include <wtf/Ref.h> > #include <wtf/RefCounted.h> > > namespace WebCore { > >+class Node; >+ > class InspectorAuditDOMUtilities : public RefCounted<InspectorAuditDOMUtilities> { > public: > static Ref<InspectorAuditDOMUtilities> create() >@@ -37,6 +40,8 @@ public: > return adoptRef(*new InspectorAuditDOMUtilities()); > } > >+ bool hasEventListeners(Node&, const String& type); >+ > private: > InspectorAuditDOMUtilities(); > }; >diff --git a/Source/WebCore/inspector/InspectorAuditDOMUtilities.idl b/Source/WebCore/inspector/InspectorAuditDOMUtilities.idl >index 11588325917..748435b4004 100644 >--- a/Source/WebCore/inspector/InspectorAuditDOMUtilities.idl >+++ b/Source/WebCore/inspector/InspectorAuditDOMUtilities.idl >@@ -28,4 +28,5 @@ > JSGenerateToJSObject, > NoInterfaceObject, > ] interface InspectorAuditDOMUtilities { >+ boolean hasEventListeners(Node node, optional DOMString type); > };
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
Flags:
hi
:
commit-queue-
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 193226
:
358566
|
358849
|
359145
|
359146
|
359150