Skip to content
Permalink
Browse files
Web Inspector: URL breakpoints should also pause when HTML attributes…
… that trigger loads are set

https://bugs.webkit.org/show_bug.cgi?id=218140
<rdar://problem/70636814>

Reviewed by Patrick Angle.

This will give developers even more power over understanding the cause of network requests.

It's still the case that by the time the URL breakpoint pauses, we've already configured the network
request (i.e. it cannot be changed), but at least this way a developer can pause when the request is
made, rather than inferring that by looking at the backtrace afterwards.

* Source/WebCore/inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::willSendRequestImpl):
(WebCore::InspectorInstrumentation::willSendRequestOfTypeImpl):
* Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.h:
* Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.cpp:
(WebCore::InspectorDOMDebuggerAgent::willSendRequest): Added.
(WebCore::InspectorDOMDebuggerAgent::willSendRequestOfType): Added.
(WebCore::InspectorDOMDebuggerAgent::breakOnURLIfNeeded):
(WebCore::InspectorDOMDebuggerAgent::willSendXMLHttpRequest):
(WebCore::InspectorDOMDebuggerAgent::willFetch):
Leverage existing instrumentation to notify the `DOMDebugger` whenever a new network request is made,
at which point the it can check for any existing URL breakpoints and pause if one is found.

* Source/JavaScriptCore/inspector/protocol/Debugger.json:
* Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js:
(WI.DebuggerManager.pauseReasonFromPayload):
* Source/WebInspectorUI/UserInterface/Views/SourcesNavigationSidebarPanel.js:
(WI.SourcesNavigationSidebarPanel.prototype._updatePauseReasonSection):
Merge the `"XHR"` and `"Fetch"` pause reasons into a single `"URL"` since URL breakpoints can now be
triggered by more than just those two APIs (i.e. DOM APIs too).

* Source/WebCore/loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::shouldContinueAfterNotifyingLoadedFromMemoryCache):
Make sure to also copy over the `ResourceRequest::Requester`.

* Source/WebCore/dom/ScriptDisallowedScope.h:
(WebCore::ScriptDisallowedScope::isScriptAllowedInMainThread): Renamed from `isEventAllowedInMainThread`.
* Source/WebCore/dom/EventTarget.cpp:
(WebCore::EventTarget::fireEventListeners):
Drive-by: Rename to make it less specific to events, as the same logic can be useful elsewhere.

* LayoutTests/inspector/dom-debugger/resources/dataDOM.json: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-dom-all-requests.html: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-dom-all-requests-expected.txt: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-dom-containing.html: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-dom-containing-expected.txt: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-dom-matching.html: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-dom-matching-expected.txt: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-dom.html: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-dom-expected.txt: Added.

* LayoutTests/inspector/dom-debugger/url-breakpoints-fetch-all-requests.html: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-fetch-all-requests-expected.txt: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-fetch-containing.html: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-fetch-containing-expected.txt: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-fetch-matching.html: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-fetch-matching-expected.txt: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-fetch.html: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-fetch-expected.txt: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-xhr-all-requests.html: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-xhr-all-requests-expected.txt: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-xhr-containing.html: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-xhr-containing-expected.txt: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-xhr-matching.html: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-xhr-matching-expected.txt: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-xhr.html: Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-xhr-expected.txt: Added.
* LayoutTests/inspector/worker/dom-debugger-url-breakpoints-fetch.html: Added.
* LayoutTests/inspector/worker/dom-debugger-url-breakpoints-fetch-expected.txt: Added.
* LayoutTests/inspector/worker/dom-debugger-url-breakpoints-xhr.html: Added.
* LayoutTests/inspector/worker/dom-debugger-url-breakpoints-xhr-expected.txt: Added.
* LayoutTests/inspector/worker/resources/dataDOM.json: Added.
* LayoutTests/inspector/worker/resources/resource-utilities.js:
(loadResourceDOM): Added.
* LayoutTests/inspector/worker/resources/worker-dom-debugger.js:
(const.functions.triggerXHRRequest): Renamed from `triggerXHR`.
(const.functions.triggerFetchRequest): Renamed from `triggerFetch`.
(const.functions.triggerDOMRequest): Added.
* LayoutTests/inspector/dom-debugger/url-breakpoints-all-requests.html: Removed.
* LayoutTests/inspector/dom-debugger/url-breakpoints-all-requests-expected.txt: Removed.
* LayoutTests/inspector/dom-debugger/url-breakpoints-containing.html: Removed.
* LayoutTests/inspector/dom-debugger/url-breakpoints-containing-expected.txt: Removed.
* LayoutTests/inspector/dom-debugger/url-breakpoints-matching.html: Removed.
* LayoutTests/inspector/dom-debugger/url-breakpoints-matching-expected.txt: Removed.
* LayoutTests/inspector/dom-debugger/url-breakpoints.html: Removed.
* LayoutTests/inspector/dom-debugger/url-breakpoints-expected.txt: Removed.
* LayoutTests/inspector/worker/dom-debugger-url-breakpoints.html: Removed.
* LayoutTests/inspector/worker/dom-debugger-url-breakpoints-expected.txt: Removed.
Split URL breakpoint tests into separate files for each API (i.e. one for XHR, one for `fetch`, etc.).

Canonical link: https://commits.webkit.org/254488@main
  • Loading branch information
dcrousso committed Sep 14, 2022
1 parent bf06122 commit 7ad0216f7c41bea64fd4d315e9df4d020c9f0830
Show file tree
Hide file tree
Showing 46 changed files with 2,220 additions and 975 deletions.
@@ -0,0 +1 @@
{"webkit":true, "type":"DOM"}

This file was deleted.

This file was deleted.

@@ -0,0 +1,188 @@
CONSOLE MESSAGE: BREAKPOINT ACTION LOG 1
CONSOLE MESSAGE: BREAKPOINT ACTION LOG 2
CONSOLE MESSAGE: BREAKPOINT ACTION LOG 3
CONSOLE MESSAGE: BREAKPOINT ACTION LOG 4
Tests for All Requests URL breakpoint.


== Running test suite: URLBreakpoint.BreakOnAll
-- Running test case: URLBreakpoint.BreakOnAll.DOM
Adding All Requests URL Breakpoint...
Request DOM "resources/dataDOM.json"...
PAUSED:
PASS: Pause reason should be URL.
PASS: Pause data URL should be empty.
CALL STACK:
0: [F] loadResourceDOM
1: [P] Global Code
-- Running test teardown.

-- Running test case: URLBreakpoint.BreakOnAll.DOM.Options.Condition
Adding All Requests URL Breakpoint...

Setting condition to 'false'...

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should not pause.

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should not pause.

Setting condition to 'true'...

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should pause.

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should pause.

-- Running test case: URLBreakpoint.BreakOnAll.DOM.Options.Condition.ConsoleCommandLineAPI
Adding saved console value 'false'...
Adding All Requests URL Breakpoint...

Setting condition to saved console value...

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should not pause.

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should not pause.

Adding saved console value 'true'...
Setting condition to saved console value...

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should pause.

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should pause.

-- Running test case: URLBreakpoint.BreakOnAll.DOM.Options.IgnoreCount
Adding All Requests URL Breakpoint...

Setting ignoreCount to '2'...

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should not pause.

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should not pause.

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should pause.

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should pause.

-- Running test case: URLBreakpoint.BreakOnAll.DOM.Options.Action.Log
Adding All Requests URL Breakpoint...

Adding log action...

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should execute breakpoint action.
PASS: Should pause.

Editing log action...

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should execute breakpoint action.
PASS: Should pause.

Editing log action...
Enabling auto-continue...

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should execute breakpoint action.
PASS: Should not pause.

Editing log action...

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should execute breakpoint action.
PASS: Should not pause.

-- Running test case: URLBreakpoint.BreakOnAll.DOM.Options.Actions.Evaluate
Adding All Requests URL Breakpoint...

Adding evaluate action...

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should execute breakpoint action.
PASS: Should pause.

Editing evaluate action...

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should execute breakpoint action.
PASS: Should pause.

Editing evaluate action...
Enabling auto-continue...

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should execute breakpoint action.
PASS: Should not pause.

Editing evaluate action...

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should execute breakpoint action.
PASS: Should not pause.

-- Running test case: URLBreakpoint.BreakOnAll.DOM.Options.Actions.Evaluate.ConsoleCommandLineAPI
Adding saved console value '1'...
Adding All Requests URL Breakpoint...

Adding evaluate action using saved console value...

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should execute breakpoint action.
PASS: Should pause.

Adding saved console value '2'...
Editing evaluate action using saved console value...

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should execute breakpoint action.
PASS: Should pause.

Adding saved console value '3'...
Editing evaluate action using saved console value...
Enabling auto-continue...

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should execute breakpoint action.
PASS: Should not pause.

Adding saved console value '4'...
Editing evaluate action using saved console value...

Triggering breakpoint...
Request DOM "resources/dataDOM.json"...
PASS: Should execute breakpoint action.
PASS: Should not pause.

@@ -0,0 +1,55 @@
<!doctype html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script src="../debugger/resources/breakpoint-options-utilities.js"></script>
<script src="../debugger/resources/log-active-stack-trace.js"></script>
<script src="../worker/resources/resource-utilities.js"></script>
<script src="resources/url-breakpoint-utilities.js"></script>
<script>
function test()
{
const type = WI.URLBreakpoint.Type.Text;
const url = "";

let suite = InspectorTest.createAsyncSuite("URLBreakpoint.BreakOnAll");

suite.addTestCase({
name: "URLBreakpoint.BreakOnAll.DOM",
description: "Check that debugger pauses for all requests.",
async test() {
await InspectorTest.URLBreakpoint.createBreakpoint(type, url);

InspectorTest.URLBreakpoint.request("DOM");
await WI.debuggerManager.awaitEvent(WI.DebuggerManager.Event.Paused);

let targetData = WI.debuggerManager.dataForTarget(WI.debuggerManager.activeCallFrame.target);
InspectorTest.log("PAUSED:");
InspectorTest.expectEqual(targetData.pauseReason, WI.DebuggerManager.PauseReason.URL, `Pause reason should be URL.`);
InspectorTest.expectFalse(targetData.pauseData.breakpointURL, "Pause data URL should be empty.");

logActiveStackTrace();

await WI.debuggerManager.resume();
},
teardown: InspectorTest.URLBreakpoint.teardown,
});

InspectorTest.BreakpointOptions.addTestCases(suite, {
testCaseNamePrefix: "DOM.",
createBreakpoint() {
return InspectorTest.URLBreakpoint.createBreakpoint(type, url);
},
triggerBreakpoint() {
return InspectorTest.URLBreakpoint.request("DOM");
},
});

suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Tests for All Requests URL breakpoint.</p>
</body>
</html>

0 comments on commit 7ad0216

Please sign in to comment.