WebKit Bugzilla
Attachment 358849 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), 12.45 KB, created by
Devin Rousso
on 2019-01-10 16:37:37 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Devin Rousso
Created:
2019-01-10 16:37:37 PST
Size:
12.45 KB
patch
obsolete
>diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 0b015d8fb20..ca1df1254e2 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,14 @@ >+2019-01-10 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..fd34a51e725 >--- /dev/null >+++ b/LayoutTests/inspector/audit/run-dom-expected.txt >@@ -0,0 +1,61 @@ >+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.noListeners.WithArgs >+Audit setup... >+Audit run `AUDIT.DOM.hasEventListeners(document.querySelector("#noListeners"), ["FakeEvent"])`... >+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.attributeListener.WithArgs >+Audit setup... >+Audit run `AUDIT.DOM.hasEventListeners(document.querySelector("#attributeListener"), ["FakeEvent"])`... >+Result: false >+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.javascriptListener.WithArgs >+Audit setup... >+Audit run `AUDIT.DOM.hasEventListeners(document.querySelector("#javascriptListener"), ["FakeEvent"])`... >+Result: false >+Audit teardown... >+ >+-- Running test case: Audit.run.DOM.hasEventListeners.builtinListener >+Audit setup... >+Audit run `AUDIT.DOM.hasEventListeners(document.querySelector("#builtinListener"))`... >+Result: false >+Audit teardown... >+ >+-- Running test case: Audit.run.DOM.hasEventListeners.builtinListener.WithArgs >+Audit setup... >+Audit run `AUDIT.DOM.hasEventListeners(document.querySelector("#builtinListener"), ["FakeEvent"])`... >+Result: false >+Audit teardown... >+ >+-- Running test case: Audit.run.DOM.InvalidCopiedFunctionCall >+Audit setup... >+Copying AUDIT to window... >+Audit teardown... >+Testing copied hasEventListeners... >+PASS: Should produce an exception. >+Error: NotAllowedError: Unable to run outside of an Inspector Audit >+ >diff --git a/LayoutTests/inspector/audit/run-dom.html b/LayoutTests/inspector/audit/run-dom.html >new file mode 100644 >index 00000000000..c4f7e587d71 >--- /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 `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 = "AUDIT." + 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 AUDIT.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 AUDIT to window...`); >+ let {wasThrown} = await AuditAgent.run(`function() { window.AUDITCopy = AUDIT; }`); >+ 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.AUDITCopy." + evaluateStringForTest(func, target, args)); >+ }); >+ } >+ }, >+ }); >+ >+ 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 c05068dc003..fb4abf0ab29 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,18 @@ >+2019-01-10 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-10 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/InspectorAuditAccessibilityUtilities.h b/Source/WebCore/inspector/InspectorAuditAccessibilityUtilities.h >index 37c67bb1f25..8e63c507405 100644 >--- a/Source/WebCore/inspector/InspectorAuditAccessibilityUtilities.h >+++ b/Source/WebCore/inspector/InspectorAuditAccessibilityUtilities.h >@@ -25,6 +25,7 @@ > > #pragma once > >+#include <JavaScriptCore/InspectorAuditAgent.h> > #include <wtf/Ref.h> > #include <wtf/RefCounted.h> > >@@ -32,7 +33,7 @@ namespace WebCore { > > class InspectorAuditAccessibilityUtilities : public RefCounted<InspectorAuditAccessibilityUtilities> { > public: >- static Ref<InspectorAuditAccessibilityUtilities> create() >+ static Ref<InspectorAuditAccessibilityUtilities> create(Inspector::InspectorAuditAgent&) > { > return adoptRef(*new InspectorAuditAccessibilityUtilities()); > } >diff --git a/Source/WebCore/inspector/InspectorAuditDOMUtilities.cpp b/Source/WebCore/inspector/InspectorAuditDOMUtilities.cpp >index 200947a4dab..598fa6d60f0 100644 >--- a/Source/WebCore/inspector/InspectorAuditDOMUtilities.cpp >+++ b/Source/WebCore/inspector/InspectorAuditDOMUtilities.cpp >@@ -27,12 +27,40 @@ > #include "config.h" > #include "InspectorAuditDOMUtilities.h" > >+#include "Node.h" >+#include <wtf/text/AtomicString.h> >+#include <wtf/text/WTFString.h> >+ > namespace WebCore { > > using namespace Inspector; > >-InspectorAuditDOMUtilities::InspectorAuditDOMUtilities() >+#define ERROR_IF_NO_ACTIVE_AUDIT() if (!m_auditAgent.hasActiveAudit()) return Exception { NotAllowedError, "Unable to run outside of an Inspector Audit"_s }; >+ >+InspectorAuditDOMUtilities::InspectorAuditDOMUtilities(InspectorAuditAgent& auditAgent) >+ : m_auditAgent(auditAgent) > { > } > >+ExceptionOr<bool> InspectorAuditDOMUtilities::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/InspectorAuditDOMUtilities.h b/Source/WebCore/inspector/InspectorAuditDOMUtilities.h >index 3a4af637eff..a64e5e3cfb5 100644 >--- a/Source/WebCore/inspector/InspectorAuditDOMUtilities.h >+++ b/Source/WebCore/inspector/InspectorAuditDOMUtilities.h >@@ -25,20 +25,28 @@ > > #pragma once > >+#include "ExceptionOr.h" >+#include <JavaScriptCore/InspectorAuditAgent.h> > #include <wtf/Ref.h> > #include <wtf/RefCounted.h> > > namespace WebCore { > >+class Node; >+ > class InspectorAuditDOMUtilities : public RefCounted<InspectorAuditDOMUtilities> { > public: >- static Ref<InspectorAuditDOMUtilities> create() >+ static Ref<InspectorAuditDOMUtilities> create(Inspector::InspectorAuditAgent& auditAgent) > { >- return adoptRef(*new InspectorAuditDOMUtilities()); >+ return adoptRef(*new InspectorAuditDOMUtilities(auditAgent)); > } > >+ ExceptionOr<bool> hasEventListeners(Node&, const String& type); >+ > private: >- explicit InspectorAuditDOMUtilities(); >+ explicit InspectorAuditDOMUtilities(Inspector::InspectorAuditAgent&); >+ >+ Inspector::InspectorAuditAgent& m_auditAgent; > }; > > } // namespace WebCore >diff --git a/Source/WebCore/inspector/InspectorAuditDOMUtilities.idl b/Source/WebCore/inspector/InspectorAuditDOMUtilities.idl >index 11588325917..7067db5ccd2 100644 >--- a/Source/WebCore/inspector/InspectorAuditDOMUtilities.idl >+++ b/Source/WebCore/inspector/InspectorAuditDOMUtilities.idl >@@ -28,4 +28,5 @@ > JSGenerateToJSObject, > NoInterfaceObject, > ] interface InspectorAuditDOMUtilities { >+ [MayThrowException] boolean hasEventListeners(Node node, optional DOMString type); > }; >diff --git a/Source/WebCore/inspector/agents/page/PageAuditAgent.cpp b/Source/WebCore/inspector/agents/page/PageAuditAgent.cpp >index dbe1d36f287..e13ba14258c 100644 >--- a/Source/WebCore/inspector/agents/page/PageAuditAgent.cpp >+++ b/Source/WebCore/inspector/agents/page/PageAuditAgent.cpp >@@ -82,7 +82,7 @@ Vector<std::pair<String, JSC::JSValue>> PageAuditAgent::runArguments(const int* > > #define ADD_AUDIT_UTILITIES(name) \ > if (!m_audit##name##Utilities) \ >- m_audit##name##Utilities = InspectorAudit##name##Utilities::create(); \ >+ m_audit##name##Utilities = InspectorAudit##name##Utilities::create(*this); \ > if (JSC::JSValue inspectorAudit##name##Utilities = toJS(execState, globalObject, *m_audit##name##Utilities)) \ > arguments.append(std::make_pair("" #name ""_s, WTFMove(inspectorAudit##name##Utilities))); >
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