Bug 1686194 - Fire pagetitlechanged when initialized with an empty string r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D102054
This commit is contained in:
Kagami Sascha Rosylight 2021-01-28 17:24:09 +00:00
Родитель f105a0c763
Коммит a267a9ea0c
4 изменённых файлов: 55 добавлений и 4 удалений

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

@ -364,11 +364,11 @@ IPCResult WindowGlobalParent::RecvUpdateDocumentPrincipal(
}
mozilla::ipc::IPCResult WindowGlobalParent::RecvUpdateDocumentTitle(
const nsString& aTitle) {
if (mDocumentTitle == aTitle) {
if (mDocumentTitle.isSome() && mDocumentTitle.value() == aTitle) {
return IPC_OK();
}
mDocumentTitle = aTitle;
mDocumentTitle = Some(aTitle);
// Send a pagetitlechanged event only for changes to the title
// for top-level frames.

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

@ -119,7 +119,9 @@ class WindowGlobalParent final : public WindowContext,
// The current URI which loaded in the document.
nsIURI* GetDocumentURI() override { return mDocumentURI; }
void GetDocumentTitle(nsAString& aTitle) const { aTitle = mDocumentTitle; }
void GetDocumentTitle(nsAString& aTitle) const {
aTitle = mDocumentTitle.valueOr(nsString());
}
nsIPrincipal* GetContentBlockingAllowListPrincipal() const {
return mDocContentBlockingAllowListPrincipal;
@ -284,7 +286,7 @@ class WindowGlobalParent final : public WindowContext,
// The principal to use for the content blocking allow list.
nsCOMPtr<nsIPrincipal> mDocContentBlockingAllowListPrincipal;
nsCOMPtr<nsIURI> mDocumentURI;
nsString mDocumentTitle;
Maybe<nsString> mDocumentTitle;
bool mIsInitialDocument;

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

@ -20,3 +20,5 @@ skip-if = !e10s
[browser_bug1646088.js]
support-files = file_dummy.html
skip-if = !e10s
[browser_bug1686194.js]
support-files = file_dummy.html

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

@ -0,0 +1,47 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const TEST_PAGE =
"http://mochi.test:8888/browser/dom/ipc/tests/file_dummy.html";
function untilPageTitleChanged() {
return new Promise(resolve =>
gBrowser.addEventListener("pagetitlechanged", resolve, { once: true })
);
}
add_task(async () => {
const tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
opening: TEST_PAGE,
});
const { linkedBrowser } = tab;
ok(
tab.getAttribute("label").includes("file_dummy.html"),
"The title should be the raw path"
);
await Promise.all([
SpecialPowers.spawn(linkedBrowser, [], function() {
content.document.title = "Title";
}),
untilPageTitleChanged(),
]);
is(tab.getAttribute("label"), "Title", "The title should change");
linkedBrowser.reload();
await untilPageTitleChanged();
ok(
tab.getAttribute("label").includes("file_dummy.html"),
"The title should be the raw path again"
);
BrowserTestUtils.removeTab(tab);
});