Merge autoland to mozilla-central. a=merge

This commit is contained in:
smolnar 2022-03-28 00:34:46 +03:00
Родитель 0b767d0791 b554ad2947
Коммит b671b6390e
12 изменённых файлов: 187 добавлений и 10 удалений

Просмотреть файл

@ -135,7 +135,7 @@ var TabManager = {
},
/**
* Retrieve a the browser element corresponding to the provided unique id,
* Retrieve the browser element corresponding to the provided unique id,
* previously generated via getIdForBrowser.
*
* TODO: To avoid creating strong references on browser elements and
@ -163,6 +163,23 @@ var TabManager = {
return null;
},
/**
* Retrieve the browsing context corresponding to the provided unique id.
*
* @param {String} id
* A browsing context unique id (created by getIdForBrowsingContext).
* @return {BrowsingContext=}
* The browsing context found for this id, null if none was found.
*/
getBrowsingContextById(id) {
const browser = this.getBrowserById(id);
if (browser) {
return browser.browsingContext;
}
return BrowsingContext.get(id);
},
/**
* Retrieve the unique id for the given xul browser element. The id is a
* dynamically generated uuid associated with the permanentKey property of the

Просмотреть файл

@ -6,6 +6,7 @@ BROWSER_CHROME_MANIFESTS += [
"listeners/test/browser/browser.ini",
"messagehandler/test/browser/broadcast/browser.ini",
"messagehandler/test/browser/browser.ini",
"test/browser/browser.ini",
]
XPCSHELL_TESTS_MANIFESTS += [

Просмотреть файл

@ -0,0 +1,5 @@
[DEFAULT]
tags = remote
subsuite = remote
[browser_TabManager.js]

Просмотреть файл

@ -0,0 +1,35 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { TabManager } = ChromeUtils.import(
"chrome://remote/content/shared/TabManager.jsm"
);
const FRAME_URL = "https://example.com/document-builder.sjs?html=frame";
const FRAME_MARKUP = `<iframe src="${encodeURI(FRAME_URL)}"></iframe>`;
const TEST_URL = `https://example.com/document-builder.sjs?html=${encodeURI(
FRAME_MARKUP
)}`;
add_task(async function test_getBrowsingContextById() {
const browser = gBrowser.selectedBrowser;
is(TabManager.getBrowsingContextById(null), null);
is(TabManager.getBrowsingContextById(undefined), null);
is(TabManager.getBrowsingContextById("wrong-id"), null);
info(`Navigate to ${TEST_URL}`);
const loaded = BrowserTestUtils.browserLoaded(browser);
BrowserTestUtils.loadURI(browser, TEST_URL);
await loaded;
const contexts = browser.browsingContext.getAllBrowsingContextsInSubtree();
is(contexts.length, 2, "Top context has 1 child");
const topContextId = TabManager.getIdForBrowsingContext(contexts[0]);
is(TabManager.getBrowsingContextById(topContextId), contexts[0]);
const childContextId = TabManager.getIdForBrowsingContext(contexts[1]);
is(TabManager.getBrowsingContextById(childContextId), contexts[1]);
});

Просмотреть файл

@ -17,12 +17,17 @@ XPCOMUtils.defineLazyModuleGetters(this, {
ContextDescriptorType:
"chrome://remote/content/shared/messagehandler/MessageHandler.jsm",
error: "chrome://remote/content/shared/webdriver/Errors.jsm",
Log: "chrome://remote/content/shared/Log.jsm",
Module: "chrome://remote/content/shared/messagehandler/Module.jsm",
TabManager: "chrome://remote/content/shared/TabManager.jsm",
waitForInitialNavigationCompleted:
"chrome://remote/content/shared/Navigate.jsm",
});
XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.get(Log.TYPES.WEBDRIVER_BIDI)
);
class BrowsingContextModule extends Module {
#contextListener;
@ -45,6 +50,53 @@ class BrowsingContextModule extends Module {
this.#contextListener.destroy();
}
/**
* Close the provided browsing context.
*
* @param {Object=} options
* @param {string} context
* Id of the browsing context to close.
*
* @throws {NoSuchFrameError}
* If the browsing context cannot be found.
* @throws {InvalidArgumentError}
* If the browsing context is not a top-level one.
*/
close(options = {}) {
const { context: contextId } = options;
assert.string(
contextId,
`Expected "context" to be a string, got ${contextId}`
);
const context = TabManager.getBrowsingContextById(contextId);
if (!context) {
throw new error.NoSuchFrameError(
`Browsing Context with id ${contextId} not found`
);
}
if (context.parent) {
throw new error.InvalidArgumentError(
`Browsing Context with id ${contextId} is not top-level`
);
}
if (TabManager.getTabCount() === 1) {
// The behavior when closing the last tab is currently unspecified.
// Warn the consumer about potential issues
logger.warn(
`Closing the last open tab (Browsing Context id ${contextId}), expect inconsistent behavior across platforms`
);
}
const browser = context.embedderElement;
const tabBrowser = TabManager.getTabBrowser(browser.ownerGlobal);
const tab = tabBrowser.getTabForBrowser(browser);
TabManager.removeTab(tab);
}
/**
* An object that holds the WebDriver Bidi browsing context information.
*
@ -107,13 +159,7 @@ class BrowsingContextModule extends Module {
`Expected "parent" to be a string, got ${parentId}`
);
// If the parent id is for a top-level browsing context get the browsing
// context via the unique id and the related content browser.
const browser = TabManager.getBrowserById(parentId);
contexts =
browser !== null
? [browser.browsingContext]
: [this.#getBrowsingContext(parentId)];
contexts = [this.#getBrowsingContext(parentId)];
} else {
// Return all top-level browsing contexts.
contexts = TabManager.browsers.map(browser => browser.browsingContext);
@ -143,7 +189,7 @@ class BrowsingContextModule extends Module {
return null;
}
const context = BrowsingContext.get(contextId);
const context = TabManager.getBrowsingContextById(contextId);
if (context === null) {
throw new error.NoSuchFrameError(
`Browsing Context with id ${contextId} not found`

Просмотреть файл

@ -0,0 +1,3 @@
[close.py]
disabled:
if release_or_beta: https://bugzilla.mozilla.org/show_bug.cgi?id=1712902

Просмотреть файл

@ -0,0 +1,3 @@
[invalid.py]
disabled:
if release_or_beta: https://bugzilla.mozilla.org/show_bug.cgi?id=1712902

Просмотреть файл

@ -4,6 +4,15 @@ from ._module import BidiModule, command
class BrowsingContext(BidiModule):
@command
def close(self, context: Optional[str] = None) -> Mapping[str, Any]:
params: MutableMapping[str, Any] = {}
if context is not None:
params["context"] = context
return params
@command
def get_tree(self,
max_depth: Optional[int] = None,

Просмотреть файл

Просмотреть файл

@ -0,0 +1,21 @@
import pytest
pytestmark = pytest.mark.asyncio
@pytest.mark.parametrize("type_hint", ["window", "tab"])
async def test_top_level_context(bidi_session, current_session, type_hint):
top_level_context_id = current_session.new_window(type_hint=type_hint)
contexts = await bidi_session.browsing_context.get_tree()
assert len(contexts) == 2
await bidi_session.browsing_context.close(context=top_level_context_id)
contexts = await bidi_session.browsing_context.get_tree()
assert len(contexts) == 1
assert contexts[0]["context"] != top_level_context_id
# TODO: Add a test for closing the last tab once the behavior has been specified
# https://github.com/w3c/webdriver-bidi/issues/187

Просмотреть файл

@ -0,0 +1,31 @@
import pytest
import webdriver.bidi.error as error
pytestmark = pytest.mark.asyncio
@pytest.mark.parametrize("value", [False, 42, {}, []])
async def test_params_context_invalid_type(bidi_session, value):
with pytest.raises(error.InvalidArgumentException):
await bidi_session.browsing_context.close(context=value)
async def test_params_context_invalid_value(bidi_session):
with pytest.raises(error.NoSuchFrameException):
await bidi_session.browsing_context.close(context="foo")
async def test_child_context(
bidi_session, current_session, test_page_same_origin_frame
):
current_session.url = test_page_same_origin_frame
all_contexts = await bidi_session.browsing_context.get_tree()
assert len(all_contexts) == 1
parent_info = all_contexts[0]
assert len(parent_info["children"]) == 1
child_info = parent_info["children"][0]
with pytest.raises(error.InvalidArgumentException):
await bidi_session.browsing_context.close(context=child_info["context"])

Просмотреть файл

@ -12,8 +12,10 @@
#include <gtk/gtk.h>
#include "mozilla/RefPtr.h"
#ifdef MOZ_ENABLE_DBUS
// TODO: Remove this (we should use GDBus instead, which is not deprecated).
#include <dbus/dbus-glib.h>
# include <dbus/dbus-glib.h>
#endif
namespace mozilla {
@ -38,7 +40,9 @@ GOBJECT_TRAITS(GAppInfo)
GOBJECT_TRAITS(GdkDragContext)
GOBJECT_TRAITS(GdkPixbuf)
#ifdef MOZ_ENABLE_DBUS
GOBJECT_TRAITS(DBusGProxy)
#endif
#undef GOBJECT_TRAITS
@ -62,6 +66,7 @@ struct RefPtrTraits<GDBusNodeInfo> {
}
};
#ifdef MOZ_ENABLE_DBUS
template <>
struct RefPtrTraits<DBusGConnection> {
static void AddRef(DBusGConnection* aObject) {
@ -71,6 +76,7 @@ struct RefPtrTraits<DBusGConnection> {
dbus_g_connection_unref(aObject);
}
};
#endif
} // namespace mozilla