forked from mirrors/gecko-dev
Backed out 3 changesets (bug 1790375) for causing wd failures on fetch_error.py. CLOSED TREE
Backed out changeset 12e0d45fb593 (bug 1790375) Backed out changeset a51daae37008 (bug 1790375) Backed out changeset aaee4331946c (bug 1790375)
This commit is contained in:
parent
b885a6f25d
commit
2a8f474615
9 changed files with 6 additions and 476 deletions
|
|
@ -214,11 +214,7 @@ export class NetworkEventRecord {
|
|||
},
|
||||
};
|
||||
|
||||
if (responseInfo.blockedReason) {
|
||||
this.#emitFetchError();
|
||||
} else {
|
||||
this.#emitResponseCompleted();
|
||||
}
|
||||
this.#emitResponseCompleted();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -279,8 +275,8 @@ export class NetworkEventRecord {
|
|||
authCallbacks,
|
||||
contextId: this.#contextId,
|
||||
isNavigationRequest: this.#isMainDocumentChannel,
|
||||
redirectCount: this.#redirectCount,
|
||||
requestChannel: this.#requestChannel,
|
||||
redirectCount: this.#redirectCount,
|
||||
requestData: this.#requestData,
|
||||
responseChannel: this.#responseChannel,
|
||||
responseData: this.#responseData,
|
||||
|
|
@ -294,23 +290,8 @@ export class NetworkEventRecord {
|
|||
this.#networkListener.emit("before-request-sent", {
|
||||
contextId: this.#contextId,
|
||||
isNavigationRequest: this.#isMainDocumentChannel,
|
||||
redirectCount: this.#redirectCount,
|
||||
requestChannel: this.#requestChannel,
|
||||
requestData: this.#requestData,
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
}
|
||||
|
||||
#emitFetchError() {
|
||||
this.#updateDataFromTimedChannel();
|
||||
|
||||
this.#networkListener.emit("fetch-error", {
|
||||
contextId: this.#contextId,
|
||||
// TODO: Update with a proper error text. Bug 1873037.
|
||||
errorText: ChromeUtils.getXPCOMErrorName(this.#requestChannel.status),
|
||||
isNavigationRequest: this.#isMainDocumentChannel,
|
||||
redirectCount: this.#redirectCount,
|
||||
requestChannel: this.#requestChannel,
|
||||
requestData: this.#requestData,
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -78,22 +78,6 @@ add_task(async function test_beforeRequestSent_newTab() {
|
|||
gBrowser.removeTab(tab);
|
||||
});
|
||||
|
||||
add_task(async function test_fetchError() {
|
||||
const listener = new NetworkListener();
|
||||
const onFetchError = listener.once("fetch-error");
|
||||
listener.startListening();
|
||||
|
||||
info("Check fetchError event when loading a new tab");
|
||||
const tab = BrowserTestUtils.addTab(gBrowser, "https://not_a_valid_url/");
|
||||
BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||
const contextId = TabManager.getIdForBrowser(tab.linkedBrowser);
|
||||
const event = await onFetchError;
|
||||
|
||||
assertNetworkEvent(event, contextId, "https://not_a_valid_url/");
|
||||
is(event.errorText, "NS_ERROR_UNKNOWN_HOST");
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
|
||||
function assertNetworkEvent(event, expectedContextId, expectedUrl) {
|
||||
is(event.contextId, expectedContextId, "Event has the expected context id");
|
||||
is(event.requestData.url, expectedUrl, "Event has the expected url");
|
||||
|
|
|
|||
|
|
@ -1422,13 +1422,12 @@ class BrowsingContextModule extends Module {
|
|||
shouldWaitForNavigationRequest = true;
|
||||
}
|
||||
};
|
||||
const onNetworkRequestCompleted = (name, data) => {
|
||||
const onResponseCompleted = (name, data) => {
|
||||
if (data.navigation) {
|
||||
resolveOnNetworkEvent();
|
||||
}
|
||||
};
|
||||
|
||||
// The network request can either end with _responseCompleted or _fetchError
|
||||
await this.messageHandler.eventsDispatcher.on(
|
||||
"network._beforeRequestSent",
|
||||
contextDescriptor,
|
||||
|
|
@ -1437,12 +1436,7 @@ class BrowsingContextModule extends Module {
|
|||
await this.messageHandler.eventsDispatcher.on(
|
||||
"network._responseCompleted",
|
||||
contextDescriptor,
|
||||
onNetworkRequestCompleted
|
||||
);
|
||||
await this.messageHandler.eventsDispatcher.on(
|
||||
"network._fetchError",
|
||||
contextDescriptor,
|
||||
onNetworkRequestCompleted
|
||||
onResponseCompleted
|
||||
);
|
||||
|
||||
unsubscribeNavigationListeners = async () => {
|
||||
|
|
@ -1451,15 +1445,11 @@ class BrowsingContextModule extends Module {
|
|||
contextDescriptor,
|
||||
onBeforeRequestSent
|
||||
);
|
||||
|
||||
await this.messageHandler.eventsDispatcher.off(
|
||||
"network._responseCompleted",
|
||||
contextDescriptor,
|
||||
onNetworkRequestCompleted
|
||||
);
|
||||
await this.messageHandler.eventsDispatcher.off(
|
||||
"network._fetchError",
|
||||
contextDescriptor,
|
||||
onNetworkRequestCompleted
|
||||
onResponseCompleted
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -281,7 +281,6 @@ class NetworkModule extends Module {
|
|||
this.#networkListener = new lazy.NetworkListener();
|
||||
this.#networkListener.on("auth-required", this.#onAuthRequired);
|
||||
this.#networkListener.on("before-request-sent", this.#onBeforeRequestSent);
|
||||
this.#networkListener.on("fetch-error", this.#onFetchError);
|
||||
this.#networkListener.on("response-completed", this.#onResponseEvent);
|
||||
this.#networkListener.on("response-started", this.#onResponseEvent);
|
||||
}
|
||||
|
|
@ -289,7 +288,6 @@ class NetworkModule extends Module {
|
|||
destroy() {
|
||||
this.#networkListener.off("auth-required", this.#onAuthRequired);
|
||||
this.#networkListener.off("before-request-sent", this.#onBeforeRequestSent);
|
||||
this.#networkListener.off("fetch-error", this.#onFetchError);
|
||||
this.#networkListener.off("response-completed", this.#onResponseEvent);
|
||||
this.#networkListener.off("response-started", this.#onResponseEvent);
|
||||
this.#networkListener.destroy();
|
||||
|
|
@ -789,78 +787,6 @@ class NetworkModule extends Module {
|
|||
}
|
||||
};
|
||||
|
||||
#onFetchError = (name, data) => {
|
||||
const {
|
||||
contextId,
|
||||
errorText,
|
||||
isNavigationRequest,
|
||||
redirectCount,
|
||||
requestData,
|
||||
timestamp,
|
||||
} = data;
|
||||
|
||||
const browsingContext = lazy.TabManager.getBrowsingContextById(contextId);
|
||||
if (!browsingContext) {
|
||||
// Do not emit events if the context id does not match any existing
|
||||
// browsing context.
|
||||
return;
|
||||
}
|
||||
|
||||
const internalEventName = "network._fetchError";
|
||||
const protocolEventName = "network.fetchError";
|
||||
|
||||
// Process the navigation to create potentially missing navigation ids
|
||||
// before the early return below.
|
||||
const navigation = this.#getNavigationId(
|
||||
protocolEventName,
|
||||
isNavigationRequest,
|
||||
browsingContext,
|
||||
requestData.url
|
||||
);
|
||||
|
||||
// Always emit internal events, they are used to support the browsingContext
|
||||
// navigate command.
|
||||
// Bug 1861922: Replace internal events with a Network listener helper
|
||||
// directly using the NetworkObserver.
|
||||
this.emitEvent(
|
||||
internalEventName,
|
||||
{
|
||||
navigation,
|
||||
url: requestData.url,
|
||||
},
|
||||
this.#getContextInfo(browsingContext)
|
||||
);
|
||||
|
||||
const isListening = this.messageHandler.eventsDispatcher.hasListener(
|
||||
protocolEventName,
|
||||
{ contextId }
|
||||
);
|
||||
if (!isListening) {
|
||||
// If there are no listeners subscribed to this event and this context,
|
||||
// bail out.
|
||||
return;
|
||||
}
|
||||
|
||||
const baseParameters = this.#processNetworkEvent(protocolEventName, {
|
||||
contextId,
|
||||
navigation,
|
||||
redirectCount,
|
||||
requestData,
|
||||
timestamp,
|
||||
});
|
||||
|
||||
const fetchErrorEvent = this.#serializeNetworkEvent({
|
||||
...baseParameters,
|
||||
errorText,
|
||||
});
|
||||
|
||||
this.emitEvent(
|
||||
protocolEventName,
|
||||
fetchErrorEvent,
|
||||
this.#getContextInfo(browsingContext)
|
||||
);
|
||||
};
|
||||
|
||||
#onResponseEvent = (name, data) => {
|
||||
const {
|
||||
contextId,
|
||||
|
|
@ -1125,7 +1051,6 @@ class NetworkModule extends Module {
|
|||
return [
|
||||
"network.authRequired",
|
||||
"network.beforeRequestSent",
|
||||
"network.fetchError",
|
||||
"network.responseCompleted",
|
||||
"network.responseStarted",
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
leak-threshold: [tab:358400]
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
[fetch_error.py]
|
||||
[test_subscribe_status]
|
||||
bug: 1873880
|
||||
expected:
|
||||
if (os == "win"): [PASS, FAIL]
|
||||
|
||||
[test_iframe_load]
|
||||
bug: 1873880
|
||||
expected:
|
||||
if (os == "win"): [PASS, FAIL]
|
||||
|
||||
[test_navigation_id]
|
||||
bug: 1873880
|
||||
expected:
|
||||
if (os == "win"): [PASS, FAIL]
|
||||
|
||||
[test_request_method[GET-False\]]
|
||||
bug: 1873880
|
||||
expected:
|
||||
if (os == "win"): [PASS, FAIL]
|
||||
|
||||
[test_request_method[HEAD-False\]]
|
||||
bug: 1873880
|
||||
expected:
|
||||
if (os == "win"): [PASS, FAIL]
|
||||
|
||||
[test_request_method[POST-False\]]
|
||||
bug: 1873880
|
||||
expected:
|
||||
if (os == "win"): [PASS, FAIL]
|
||||
|
||||
[test_request_method[OPTIONS-False\]]
|
||||
bug: 1873880
|
||||
expected:
|
||||
if (os == "win"): [PASS, FAIL]
|
||||
|
||||
[test_request_method[DELETE-True\]]
|
||||
bug: 1873880
|
||||
expected:
|
||||
if (os == "win"): [PASS, FAIL]
|
||||
|
||||
[test_request_method[Patch-True\]]
|
||||
bug: 1873880
|
||||
expected:
|
||||
if (os == "win"): [PASS, FAIL]
|
||||
|
||||
[test_request_method[PUT-True\]]
|
||||
bug: 1873880
|
||||
expected:
|
||||
if (os == "win"): [PASS, FAIL]
|
||||
|
|
@ -172,34 +172,6 @@ def assert_before_request_sent_event(
|
|||
)
|
||||
|
||||
|
||||
def assert_fetch_error_event(
|
||||
event,
|
||||
context=None,
|
||||
errorText=None,
|
||||
intercepts=None,
|
||||
is_blocked=None,
|
||||
navigation=None,
|
||||
redirect_count=None,
|
||||
expected_request=None,
|
||||
):
|
||||
# Assert errorText
|
||||
assert isinstance(event["errorText"], str)
|
||||
|
||||
if errorText is not None:
|
||||
assert event["errorText"] == errorText
|
||||
|
||||
# Assert base parameters
|
||||
assert_base_parameters(
|
||||
event,
|
||||
context=context,
|
||||
intercepts=intercepts,
|
||||
is_blocked=is_blocked,
|
||||
navigation=navigation,
|
||||
redirect_count=redirect_count,
|
||||
expected_request=expected_request,
|
||||
)
|
||||
|
||||
|
||||
def assert_response_data(response_data, expected_response):
|
||||
recursive_compare(
|
||||
{
|
||||
|
|
@ -309,7 +281,6 @@ PAGE_EMPTY_IMAGE = "/webdriver/tests/bidi/network/support/empty.png"
|
|||
PAGE_EMPTY_SCRIPT = "/webdriver/tests/bidi/network/support/empty.js"
|
||||
PAGE_EMPTY_SVG = "/webdriver/tests/bidi/network/support/empty.svg"
|
||||
PAGE_EMPTY_TEXT = "/webdriver/tests/bidi/network/support/empty.txt"
|
||||
PAGE_INVALID_URL = "https://not_a_valid_url/"
|
||||
PAGE_OTHER_TEXT = "/webdriver/tests/bidi/network/support/other.txt"
|
||||
PAGE_REDIRECT_HTTP_EQUIV = (
|
||||
"/webdriver/tests/bidi/network/support/redirect_http_equiv.html"
|
||||
|
|
@ -318,6 +289,5 @@ PAGE_REDIRECTED_HTML = "/webdriver/tests/bidi/network/support/redirected.html"
|
|||
|
||||
AUTH_REQUIRED_EVENT = "network.authRequired"
|
||||
BEFORE_REQUEST_SENT_EVENT = "network.beforeRequestSent"
|
||||
FETCH_ERROR_EVENT = "network.fetchError"
|
||||
RESPONSE_COMPLETED_EVENT = "network.responseCompleted"
|
||||
RESPONSE_STARTED_EVENT = "network.responseStarted"
|
||||
|
|
|
|||
|
|
@ -1,269 +0,0 @@
|
|||
import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
from webdriver.bidi.modules.script import ContextTarget
|
||||
|
||||
from tests.support.sync import AsyncPoll
|
||||
|
||||
from .. import (
|
||||
assert_fetch_error_event,
|
||||
assert_response_event,
|
||||
FETCH_ERROR_EVENT,
|
||||
PAGE_EMPTY_HTML,
|
||||
RESPONSE_COMPLETED_EVENT,
|
||||
PAGE_INVALID_URL,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_subscribe_status(
|
||||
bidi_session,
|
||||
subscribe_events,
|
||||
top_context,
|
||||
wait_for_event,
|
||||
wait_for_future_safe,
|
||||
url,
|
||||
fetch,
|
||||
):
|
||||
await subscribe_events(events=[FETCH_ERROR_EVENT])
|
||||
|
||||
await bidi_session.browsing_context.navigate(
|
||||
context=top_context["context"],
|
||||
url=url(PAGE_EMPTY_HTML),
|
||||
wait="complete",
|
||||
)
|
||||
|
||||
# Track all received network.beforeRequestSent events in the events array
|
||||
events = []
|
||||
|
||||
async def on_event(method, data):
|
||||
events.append(data)
|
||||
|
||||
remove_listener = bidi_session.add_event_listener(FETCH_ERROR_EVENT, on_event)
|
||||
|
||||
on_fetch_error = wait_for_event(FETCH_ERROR_EVENT)
|
||||
asyncio.ensure_future(fetch(PAGE_INVALID_URL))
|
||||
await wait_for_future_safe(on_fetch_error)
|
||||
|
||||
assert len(events) == 1
|
||||
expected_request = {"method": "GET", "url": PAGE_INVALID_URL}
|
||||
assert_fetch_error_event(
|
||||
events[0],
|
||||
expected_request=expected_request,
|
||||
redirect_count=0,
|
||||
)
|
||||
|
||||
await bidi_session.session.unsubscribe(events=[FETCH_ERROR_EVENT])
|
||||
|
||||
# Fetch the invalid url again, with an additional parameter to bypass the
|
||||
# cache and check no new event is received.
|
||||
asyncio.ensure_future(fetch(PAGE_INVALID_URL))
|
||||
await asyncio.sleep(0.5)
|
||||
assert len(events) == 1
|
||||
|
||||
remove_listener()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_iframe_load(
|
||||
bidi_session,
|
||||
top_context,
|
||||
setup_network_test,
|
||||
inline,
|
||||
):
|
||||
network_events = await setup_network_test(events=[FETCH_ERROR_EVENT])
|
||||
events = network_events[FETCH_ERROR_EVENT]
|
||||
|
||||
await bidi_session.browsing_context.navigate(
|
||||
context=top_context["context"],
|
||||
url=inline(f"<iframe src='{PAGE_INVALID_URL}'></iframe>"),
|
||||
)
|
||||
|
||||
wait = AsyncPoll(bidi_session, timeout=2)
|
||||
await wait.until(lambda _: len(events) >= 1)
|
||||
|
||||
contexts = await bidi_session.browsing_context.get_tree(root=top_context["context"])
|
||||
frame_context = contexts[0]["children"][0]
|
||||
|
||||
assert len(events) == 1
|
||||
assert_fetch_error_event(
|
||||
events[0],
|
||||
expected_request={"url": PAGE_INVALID_URL},
|
||||
context=frame_context["context"],
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_navigation_id(
|
||||
bidi_session,
|
||||
top_context,
|
||||
wait_for_event,
|
||||
url,
|
||||
fetch,
|
||||
setup_network_test,
|
||||
wait_for_future_safe,
|
||||
):
|
||||
await setup_network_test(events=[FETCH_ERROR_EVENT])
|
||||
|
||||
on_fetch_error = wait_for_event(FETCH_ERROR_EVENT)
|
||||
asyncio.ensure_future(fetch(PAGE_INVALID_URL))
|
||||
fetch_error_event = await wait_for_future_safe(on_fetch_error)
|
||||
|
||||
expected_request = {"method": "GET", "url": PAGE_INVALID_URL}
|
||||
assert_fetch_error_event(
|
||||
fetch_error_event,
|
||||
expected_request=expected_request,
|
||||
)
|
||||
# Check that requests not related to a navigation have no navigation id.
|
||||
assert fetch_error_event["navigation"] is None
|
||||
|
||||
on_fetch_error = wait_for_event(FETCH_ERROR_EVENT)
|
||||
result = await bidi_session.browsing_context.navigate(
|
||||
context=top_context["context"],
|
||||
url=PAGE_INVALID_URL,
|
||||
)
|
||||
fetch_error_event = await wait_for_future_safe(on_fetch_error)
|
||||
|
||||
expected_request = {"method": "GET", "url": PAGE_INVALID_URL}
|
||||
assert_fetch_error_event(
|
||||
fetch_error_event,
|
||||
expected_request=expected_request,
|
||||
navigation=result["navigation"],
|
||||
)
|
||||
assert fetch_error_event["navigation"] == result["navigation"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"method, has_preflight",
|
||||
[
|
||||
("GET", False),
|
||||
("HEAD", False),
|
||||
("POST", False),
|
||||
("OPTIONS", False),
|
||||
("DELETE", True),
|
||||
("PATCH", True),
|
||||
("PUT", True),
|
||||
],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_request_method(
|
||||
wait_for_event,
|
||||
wait_for_future_safe,
|
||||
fetch,
|
||||
setup_network_test,
|
||||
method,
|
||||
has_preflight,
|
||||
):
|
||||
network_events = await setup_network_test(events=[FETCH_ERROR_EVENT])
|
||||
events = network_events[FETCH_ERROR_EVENT]
|
||||
|
||||
on_fetch_error = wait_for_event(FETCH_ERROR_EVENT)
|
||||
asyncio.ensure_future(fetch(PAGE_INVALID_URL, method=method))
|
||||
await wait_for_future_safe(on_fetch_error)
|
||||
|
||||
assert len(events) == 1
|
||||
|
||||
# Requests which might update the server will fail on the CORS preflight
|
||||
# request which uses the OPTIONS method.
|
||||
if has_preflight:
|
||||
method = "OPTIONS"
|
||||
|
||||
expected_request = {"method": method, "url": PAGE_INVALID_URL}
|
||||
assert_fetch_error_event(
|
||||
events[0],
|
||||
expected_request=expected_request,
|
||||
redirect_count=0,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_redirect_fetch(
|
||||
bidi_session, wait_for_event, url, fetch, setup_network_test
|
||||
):
|
||||
redirect_url = url(
|
||||
f"/webdriver/tests/support/http_handlers/redirect.py?location={PAGE_INVALID_URL}"
|
||||
)
|
||||
|
||||
await setup_network_test(
|
||||
events=[
|
||||
FETCH_ERROR_EVENT,
|
||||
RESPONSE_COMPLETED_EVENT,
|
||||
]
|
||||
)
|
||||
|
||||
on_fetch_error = wait_for_event(FETCH_ERROR_EVENT)
|
||||
on_response_completed = wait_for_event(RESPONSE_COMPLETED_EVENT)
|
||||
asyncio.ensure_future(fetch(redirect_url))
|
||||
|
||||
# Wait until we receive two events, one for the initial request and one for
|
||||
# the redirection.
|
||||
wait = AsyncPoll(bidi_session, timeout=2)
|
||||
fetch_error_event = await on_fetch_error
|
||||
response_completed_event = await on_response_completed
|
||||
|
||||
expected_request = {"method": "GET", "url": redirect_url}
|
||||
assert_response_event(
|
||||
response_completed_event,
|
||||
expected_request=expected_request,
|
||||
redirect_count=0,
|
||||
)
|
||||
expected_request = {"method": "GET", "url": PAGE_INVALID_URL}
|
||||
assert_fetch_error_event(
|
||||
fetch_error_event, expected_request=expected_request, redirect_count=1
|
||||
)
|
||||
|
||||
# Check that both requests share the same requestId
|
||||
assert (
|
||||
fetch_error_event["request"]["request"]
|
||||
== response_completed_event["request"]["request"]
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_redirect_navigation(
|
||||
bidi_session, top_context, wait_for_event, url, setup_network_test
|
||||
):
|
||||
redirect_url = url(
|
||||
f"/webdriver/tests/support/http_handlers/redirect.py?location={PAGE_INVALID_URL}"
|
||||
)
|
||||
|
||||
await setup_network_test(
|
||||
events=[
|
||||
FETCH_ERROR_EVENT,
|
||||
RESPONSE_COMPLETED_EVENT,
|
||||
]
|
||||
)
|
||||
|
||||
on_fetch_error = wait_for_event(FETCH_ERROR_EVENT)
|
||||
on_response_completed = wait_for_event(RESPONSE_COMPLETED_EVENT)
|
||||
|
||||
result = await bidi_session.browsing_context.navigate(
|
||||
context=top_context["context"],
|
||||
url=redirect_url,
|
||||
)
|
||||
|
||||
wait = AsyncPoll(bidi_session, timeout=2)
|
||||
fetch_error_event = await on_fetch_error
|
||||
response_completed_event = await on_response_completed
|
||||
|
||||
expected_request = {"method": "GET", "url": redirect_url}
|
||||
assert_response_event(
|
||||
response_completed_event,
|
||||
expected_request=expected_request,
|
||||
navigation=result["navigation"],
|
||||
redirect_count=0,
|
||||
)
|
||||
expected_request = {"method": "GET", "url": PAGE_INVALID_URL}
|
||||
assert_fetch_error_event(
|
||||
fetch_error_event,
|
||||
expected_request=expected_request,
|
||||
navigation=result["navigation"],
|
||||
redirect_count=1,
|
||||
)
|
||||
|
||||
# Check that all events share the same requestId
|
||||
assert (
|
||||
fetch_error_event["request"]["request"]
|
||||
== response_completed_event["request"]["request"]
|
||||
)
|
||||
Loading…
Reference in a new issue