Backed out 2 changesets (bug 1905083) for causing for causing Bug 1912554. CLOSED TREE

Backed out changeset cc92c2f19204 (bug 1905083)
Backed out changeset 57b35acde62f (bug 1905083)
This commit is contained in:
Butkovits Atila 2024-08-10 05:04:18 +03:00
parent 2f288520d1
commit bad1073922
8 changed files with 18 additions and 349 deletions

View File

@ -12,8 +12,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
Deferred: "chrome://remote/content/shared/Sync.sys.mjs",
Log: "chrome://remote/content/shared/Log.sys.mjs",
NavigationListener:
"chrome://remote/content/shared/listeners/NavigationListener.sys.mjs",
PromptListener:
"chrome://remote/content/shared/listeners/PromptListener.sys.mjs",
truncate: "chrome://remote/content/shared/Format.sys.mjs",
@ -144,8 +142,6 @@ export class ProgressListener {
#deferredNavigation;
#errorName;
#navigationId;
#navigationListener;
#promptListener;
#seenStartFlag;
#targetURI;
@ -162,9 +158,6 @@ export class ProgressListener {
* When set to `true`, the ProgressListener will ignore options.unloadTimeout
* and will only resolve when the expected navigation happens.
* Defaults to `false`.
* @param {NavigationManager=} options.navigationManager
* The NavigationManager where navigations for the current session are
* monitored.
* @param {boolean=} options.resolveWhenStarted
* Flag to indicate that the Promise has to be resolved when the
* page load has been started. Otherwise wait until the page has
@ -185,7 +178,6 @@ export class ProgressListener {
constructor(webProgress, options = {}) {
const {
expectNavigation = false,
navigationManager = null,
resolveWhenStarted = false,
targetURI,
unloadTimeout = DEFAULT_UNLOAD_TIMEOUT,
@ -204,15 +196,6 @@ export class ProgressListener {
this.#targetURI = targetURI;
this.#unloadTimerId = null;
if (navigationManager !== null) {
this.#navigationListener = new lazy.NavigationListener(navigationManager);
this.#navigationListener.on(
"navigation-failed",
this.#onNavigationFailed
);
this.#navigationListener.startListening();
}
this.#promptListener = new lazy.PromptListener();
this.#promptListener.on("opened", this.#onPromptOpened);
this.#promptListener.startListening();
@ -222,15 +205,6 @@ export class ProgressListener {
this.#promptListener.stopListening();
this.#promptListener.off("opened", this.#onPromptOpened);
this.#promptListener.destroy();
if (this.#navigationListener) {
this.#navigationListener.stopListening();
this.#navigationListener.off(
"navigation-failed",
this.#onNavigationFailed
);
this.#navigationListener.destroy();
}
}
get #messagePrefix() {
@ -364,17 +338,6 @@ export class ProgressListener {
return null;
}
#onNavigationFailed = (eventName, data) => {
const { errorName, navigationId } = data;
if (this.#navigationId === navigationId) {
this.#trace(
`Received "navigation-failed" event with error=${errorName}. Stopping the navigation.`
);
this.stop({ error: new Error(errorName) });
}
};
#onPromptOpened = (eventName, data) => {
const { prompt, contentBrowser } = data;
const { promptType } = prompt;
@ -459,14 +422,10 @@ export class ProgressListener {
/**
* Start observing web progress changes.
*
* @param {string=} navigationId
* The UUID for the navigation.
* @returns {Promise}
* A promise that will resolve when the navigation has been finished.
*/
start(navigationId) {
this.#navigationId = navigationId;
start() {
if (this.#deferredNavigation) {
throw new Error(`Progress listener already started`);
}

View File

@ -227,15 +227,13 @@ class NavigationRegistry extends EventEmitter {
* @param {object} data
* @param {BrowsingContextDetails} data.contextDetails
* The details about the browsing context for this navigation.
* @param {string} data.errorName
* The error message.
* @param {string} data.url
* The URL as string for the navigation.
* @returns {NavigationInfo}
* The created navigation or the ongoing navigation, if applicable.
*/
notifyNavigationFailed(data) {
const { contextDetails, errorName, url } = data;
const { contextDetails, url } = data;
const context = this.#getContextFromContextDetails(contextDetails);
const navigableId = lazy.TabManager.getIdForBrowsingContext(context);
@ -264,7 +262,6 @@ class NavigationRegistry extends EventEmitter {
this.emit("navigation-failed", {
contextId: context.id,
errorName,
navigationId: navigation.navigationId,
navigableId,
url,
@ -319,11 +316,7 @@ class NavigationRegistry extends EventEmitter {
// Note: ideally we should monitor this using NS_BINDING_ABORTED,
// but due to intermittent issues, when monitoring this in content processes,
// we can't reliable use it.
notifyNavigationFailed({
contextDetails,
errorName: "A new navigation interrupted an unfinished navigation",
url: navigation.url,
});
notifyNavigationFailed({ contextDetails, url: navigation.url });
}
const navigationId = this.#getOrCreateNavigationId(navigableId);
@ -463,7 +456,6 @@ class NavigationRegistry extends EventEmitter {
contextDetails: {
context: browsingContext,
},
errorName: "Browsing context got discarded",
url: navigation.url,
});
@ -483,7 +475,6 @@ class NavigationRegistry extends EventEmitter {
contextDetails: {
context: browsingContext,
},
errorName: "Beforeunload prompt was rejected",
// Bug 1908952. Add support for the "url" field.
});
}

View File

@ -44,9 +44,7 @@ export class NavigationListenerParent extends JSWindowActorParent {
break;
}
case "NavigationListenerChild:navigationStopped": {
const errorName = ChromeUtils.getXPCOMErrorName(data.status);
if (this.#isContentBlocked(errorName)) {
payload.errorName = errorName;
if (this.#isContentBlocked(data.status)) {
lazy.notifyNavigationFailed(payload);
} else {
lazy.notifyNavigationStopped(payload);
@ -68,7 +66,9 @@ export class NavigationListenerParent extends JSWindowActorParent {
}
}
#isContentBlocked(blockedReason) {
#isContentBlocked(status) {
const blockedReason = ChromeUtils.getXPCOMErrorName(status);
return [
// If content is blocked with e.g. CSP meta tag.
"NS_ERROR_CONTENT_BLOCKED",

View File

@ -1555,7 +1555,6 @@ class BrowsingContextModule extends RootBiDiModule {
const resolveWhenStarted = wait === WaitCondition.None;
const listener = new lazy.ProgressListener(webProgress, {
expectNavigation: true,
navigationManager: this.messageHandler.navigationManager,
resolveWhenStarted,
targetURI,
// In case the webprogress is already navigating, always wait for an
@ -1656,12 +1655,13 @@ class BrowsingContextModule extends RootBiDiModule {
};
}
const navigationId = lazy.registerNavigationId({
contextDetails: { context: webProgress.browsingContext },
});
const navigated = listener.start(navigationId);
const navigated = listener.start();
try {
const navigationId = lazy.registerNavigationId({
contextDetails: { context: webProgress.browsingContext },
});
await startNavigationFn();
await navigated;

View File

@ -2,6 +2,8 @@
[test_beforeunload[capabilities0-False\]]
disabled:
if os == "android": bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1879324
bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1763134
expected: FAIL
[test_beforeunload[capabilities0-True\]]
disabled:

View File

@ -1,4 +1,3 @@
[error.py]
[test_beforeunload_rejected[capabilities0\]]
disabled:
if os == "android": bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1879324
expected:
if (os == "mac") and not debug: [OK, TIMEOUT]

View File

@ -1,14 +1,9 @@
import asyncio
import pytest
from webdriver.bidi.error import UnknownErrorException
from . import navigate_and_assert
pytestmark = pytest.mark.asyncio
NAVIGATION_STARTED_EVENT = "browsingContext.navigationStarted"
USER_PROMPT_OPENED_EVENT = "browsingContext.userPromptOpened"
@pytest.mark.parametrize(
"url",
@ -21,284 +16,7 @@ USER_PROMPT_OPENED_EVENT = "browsingContext.userPromptOpened"
"protocol",
"host",
"port",
],
]
)
async def test_invalid_address(bidi_session, new_tab, url):
await navigate_and_assert(bidi_session, new_tab, url, expected_error=True)
async def test_with_csp_meta_tag(
bidi_session,
inline,
new_tab,
):
same_origin_url = inline("<div>foo</div>")
cross_origin_url = inline("<div>bar</div>", domain="alt")
page_url = inline(
f"""
<!DOCTYPE html>
<html>
<head>
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self'" />
</head>
<body><iframe src="{same_origin_url}"></iframe></body>
</html>
"""
)
await bidi_session.browsing_context.navigate(
context=new_tab["context"], url=page_url, wait="complete"
)
contexts = await bidi_session.browsing_context.get_tree(root=new_tab["context"])
iframe_context = contexts[0]["children"][0]["context"]
# Make sure that cross-origin navigation in iframe failed.
with pytest.raises(UnknownErrorException):
await bidi_session.browsing_context.navigate(
context=iframe_context, url=cross_origin_url, wait="complete"
)
@pytest.mark.parametrize(
"header",
[
"Content-Security-Policy, default-src 'self'",
"Cross-Origin-Embedder-Policy, require-corp",
],
)
async def test_with_content_blocking_header_in_top_context(
bidi_session,
subscribe_events,
inline,
new_tab,
wait_for_event,
wait_for_future_safe,
header,
):
same_origin_url = inline("<div>foo</div>")
cross_origin_url = inline("<div>bar</div>", domain="alt")
page_url = inline(
f"""<iframe src={same_origin_url}></iframe>""",
parameters={"pipe": f"header({header})"},
)
await bidi_session.browsing_context.navigate(
context=new_tab["context"], url=page_url, wait="complete"
)
contexts = await bidi_session.browsing_context.get_tree(root=new_tab["context"])
iframe_context = contexts[0]["children"][0]["context"]
# Make sure that cross-origin navigation in iframe failed.
with pytest.raises(UnknownErrorException):
await bidi_session.browsing_context.navigate(
context=iframe_context, url=cross_origin_url, wait="complete"
)
@pytest.mark.parametrize(
"header_value",
[
"SAMEORIGIN",
"DENY",
],
)
async def test_with_x_frame_options_header(
bidi_session,
subscribe_events,
inline,
new_tab,
wait_for_event,
wait_for_future_safe,
header_value,
):
iframe_url_without_header = inline("<div>bar</div>")
iframe_url_with_header = inline(
"<div>foo</div>",
parameters={"pipe": f"header(X-Frame-Options, {header_value})"},
)
page_url = inline(
f"""<iframe src={iframe_url_without_header}></iframe>""", domain="alt"
)
await bidi_session.browsing_context.navigate(
context=new_tab["context"], url=page_url, wait="complete"
)
contexts = await bidi_session.browsing_context.get_tree(root=new_tab["context"])
iframe_context = contexts[0]["children"][0]["context"]
# Make sure that cross-origin navigation in iframe failed.
with pytest.raises(UnknownErrorException):
await bidi_session.browsing_context.navigate(
context=iframe_context, url=iframe_url_with_header, wait="complete"
)
async def test_with_new_navigation(
bidi_session,
subscribe_events,
inline,
url,
new_tab,
wait_for_event,
wait_for_future_safe,
):
slow_page_url = url(
"/webdriver/tests/bidi/browsing_context/support/empty.html?pipe=trickle(d10)"
)
await subscribe_events(events=[NAVIGATION_STARTED_EVENT])
on_navigation_started = wait_for_event(NAVIGATION_STARTED_EVENT)
task = asyncio.ensure_future(
bidi_session.browsing_context.navigate(
context=new_tab["context"], url=slow_page_url, wait="complete"
)
)
await wait_for_future_safe(on_navigation_started)
second_url = inline("<div>foo</div>")
# Trigger the second navigation which should fail the first one.
await bidi_session.browsing_context.navigate(
context=new_tab["context"], url=second_url, wait="none"
)
# Make sure that the first navigation failed.
with pytest.raises(UnknownErrorException):
await task
async def test_with_new_navigation_inside_page(
bidi_session,
subscribe_events,
inline,
new_tab,
wait_for_event,
wait_for_future_safe,
):
second_url = inline("<div>foo</div>")
slow_page_url = inline(
f"""
<!DOCTYPE html>
<html>
<body>
<img src="/webdriver/tests/bidi/browsing_context/support/empty.svg?pipe=trickle(d10)" />
<script>
location.href = "{second_url}"
</script>
<img src="/webdriver/tests/bidi/browsing_context/support/empty.svg?pipe=trickle(d10)" />
</body>
</html>
"""
)
# Make sure that the navigation failed.
with pytest.raises(UnknownErrorException):
await bidi_session.browsing_context.navigate(
context=new_tab["context"], url=slow_page_url, wait="complete"
)
@pytest.mark.parametrize("type_hint", ["tab", "window"])
async def test_close_context(
bidi_session,
url,
subscribe_events,
wait_for_event,
wait_for_future_safe,
type_hint,
):
await subscribe_events(events=[NAVIGATION_STARTED_EVENT])
new_context = await bidi_session.browsing_context.create(type_hint=type_hint)
slow_page_url = url(
"/webdriver/tests/bidi/browsing_context/support/empty.html?pipe=trickle(d10)"
)
on_navigation_started = wait_for_event(NAVIGATION_STARTED_EVENT)
task = asyncio.ensure_future(
bidi_session.browsing_context.navigate(
context=new_context["context"], url=slow_page_url, wait="complete"
)
)
await wait_for_future_safe(on_navigation_started)
await bidi_session.browsing_context.close(context=new_context["context"])
# Make sure that the navigation failed.
with pytest.raises(UnknownErrorException):
await task
async def test_close_iframe(
bidi_session,
subscribe_events,
inline,
url,
new_tab,
wait_for_event,
wait_for_future_safe,
):
iframe_url = inline("<div>foo</div>")
page_url = inline(f"<iframe src={iframe_url}></iframe")
await bidi_session.browsing_context.navigate(
context=new_tab["context"], url=page_url, wait="complete"
)
contexts = await bidi_session.browsing_context.get_tree(root=new_tab["context"])
iframe_context = contexts[0]["children"][0]["context"]
slow_page_url = url(
"/webdriver/tests/bidi/browsing_context/support/empty.html?pipe=trickle(d10)"
)
await subscribe_events(events=[NAVIGATION_STARTED_EVENT])
on_navigation_started = wait_for_event(NAVIGATION_STARTED_EVENT)
# Navigate in the iframe.
task = asyncio.ensure_future(
bidi_session.browsing_context.navigate(
context=iframe_context, url=slow_page_url, wait="complete"
)
)
await wait_for_future_safe(on_navigation_started)
# Reload the top context to destroy the iframe.
await bidi_session.browsing_context.reload(context=new_tab["context"], wait="none")
# Make sure that the iframe navigation failed.
with pytest.raises(UnknownErrorException):
await task
@pytest.mark.capabilities({"unhandledPromptBehavior": {"beforeUnload": "ignore"}})
async def test_beforeunload_rejected(
bidi_session,
new_tab,
inline,
setup_beforeunload_page,
subscribe_events,
wait_for_event,
wait_for_future_safe,
):
await subscribe_events(events=[USER_PROMPT_OPENED_EVENT])
await setup_beforeunload_page(new_tab)
url_after = inline("<div>foo</div>")
on_prompt_opened = wait_for_event(USER_PROMPT_OPENED_EVENT)
task = asyncio.ensure_future(
bidi_session.browsing_context.navigate(
context=new_tab["context"], url=url_after, wait="complete"
)
)
# Wait for the prompt to open.
await wait_for_future_safe(on_prompt_opened)
# Stay on the page to fail the started navigation.
await bidi_session.browsing_context.handle_user_prompt(
context=new_tab["context"], accept=False
)
with pytest.raises(UnknownErrorException):
await task

View File

@ -282,7 +282,7 @@ async def test_with_new_navigation_inside_page(
</html>
"""
)
await subscribe_events(events=[NAVIGATION_FAILED_EVENT])
await subscribe_events(events=["browsingContext"])
on_navigation_failed = wait_for_event(NAVIGATION_FAILED_EVENT)
result = await bidi_session.browsing_context.navigate(