Backed out 2 changesets (bug 1687635) for causing bc failures on browser_967000_button_charEncoding.js. CLOSED TREE

Backed out changeset b0b7678a6781 (bug 1687635)
Backed out changeset 9f57ec83cdc6 (bug 1687635)
This commit is contained in:
Iulian Moraru 2021-05-26 20:41:20 +03:00
Родитель 07568f46e3
Коммит 8ed6c3137b
16 изменённых файлов: 293 добавлений и 118 удалений

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

@ -201,10 +201,12 @@
<menuseparator/>
</menupopup>
</menu>
<menuitem id="repair-text-encoding"
disabled="true"
oncommand="BrowserSetForcedCharacterSet('_autodetect_all')"
data-l10n-id="menu-view-repair-text-encoding"/>
<menu id="charsetMenu"
oncommand="BrowserSetForcedCharacterSet(event.target.getAttribute('charset'));"
onpopupshowing="CharsetMenu.build(event.target); UpdateCurrentCharset(this);" data-l10n-id="menu-view-charset">
<menupopup>
</menupopup>
</menu>
<menuseparator/>
#ifdef XP_MACOSX
<menuitem id="enterFullScreenItem"

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

@ -4989,12 +4989,6 @@ var XULBrowserWindow = {
document.getElementById("View:PageSource"),
]);
},
get _menuItemForRepairTextEncoding() {
delete this._menuItemForRepairTextEncoding;
return (this._menuItemForRepairTextEncoding = document.getElementById(
"repair-text-encoding"
));
},
setDefaultStatus(status) {
this.defaultStatus = status;
@ -5143,18 +5137,6 @@ var XULBrowserWindow = {
}
this._updateElementsForContentType();
// Update Override Text Encoding state.
// Can't cache the button, because the presence of the element in the DOM
// may change over time.
let button = document.getElementById("characterencoding-button");
if (browser.mayEnableCharacterEncodingMenu) {
this._menuItemForRepairTextEncoding.removeAttribute("disabled");
button?.removeAttribute("disabled");
} else {
this._menuItemForRepairTextEncoding.setAttribute("disabled", "true");
button?.setAttribute("disabled", "true");
}
}
this.isBusy = false;
@ -5272,15 +5254,6 @@ var XULBrowserWindow = {
this._updateElementsForContentType();
// Unconditionally disable the Text Encoding button during load to
// keep the UI calm when navigating from one modern page to another and
// the toolbar button is visible.
// Can't cache the button, because the presence of the element in the DOM
// may change over time.
let button = document.getElementById("characterencoding-button");
this._menuItemForRepairTextEncoding.setAttribute("disabled", "true");
button?.setAttribute("disabled", "true");
// Try not to instantiate gCustomizeMode as much as possible,
// so don't use CustomizeMode.jsm to check for URI or customizing.
if (

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

@ -37,7 +37,7 @@ function nonBrowserWindowStartup() {
"Browser:Reload",
"viewFullZoomMenu",
"pageStyleMenu",
"repair-text-encoding",
"charsetMenu",
"View:PageSource",
"View:FullScreen",
"enterFullScreenItem",

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

@ -21,6 +21,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
RecentlyClosedTabsAndWindowsMenuUtils:
"resource:///modules/sessionstore/RecentlyClosedTabsAndWindowsMenuUtils.jsm",
ShortcutUtils: "resource://gre/modules/ShortcutUtils.jsm",
CharsetMenu: "resource://gre/modules/CharsetMenu.jsm",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
Sanitizer: "resource:///modules/Sanitizer.jsm",
SessionStore: "resource:///modules/sessionstore/SessionStore.jsm",
@ -437,9 +438,174 @@ const CustomizableWidgets = [
},
{
id: "characterencoding-button",
l10nId: "repair-text-encoding-button",
label: "characterencoding-button2.label",
type: "view",
viewId: "PanelUI-characterEncodingView",
tooltiptext: "characterencoding-button2.tooltiptext",
maybeDisableMenu(aDocument) {
let window = aDocument.defaultView;
return !(
window.gBrowser &&
window.gBrowser.selectedBrowser.mayEnableCharacterEncodingMenu
);
},
populateList(aDocument, aContainerId, aSection) {
let containerElem = aDocument.getElementById(aContainerId);
containerElem.addEventListener("command", this.onCommand);
let list = this.charsetInfo[aSection];
for (let item of list) {
let elem = aDocument.createXULElement("toolbarbutton");
elem.setAttribute("label", item.label);
elem.setAttribute("type", "checkbox");
elem.section = aSection;
elem.value = item.value;
elem.setAttribute("class", "subviewbutton");
containerElem.appendChild(elem);
}
},
updateCurrentCharset(aDocument) {
let currentCharset =
aDocument.defaultView.gBrowser.selectedBrowser.characterSet;
let {
charsetAutodetected,
} = aDocument.defaultView.gBrowser.selectedBrowser;
currentCharset = CharsetMenu.foldCharset(
currentCharset,
charsetAutodetected
);
let pinnedContainer = aDocument.getElementById(
"PanelUI-characterEncodingView-pinned"
);
let charsetContainer = aDocument.getElementById(
"PanelUI-characterEncodingView-charsets"
);
let elements = [
...pinnedContainer.children,
...charsetContainer.children,
];
this._updateElements(elements, currentCharset);
},
_updateElements(aElements, aCurrentItem) {
if (!aElements.length) {
return;
}
let disabled = this.maybeDisableMenu(aElements[0].ownerDocument);
for (let elem of aElements) {
if (disabled) {
elem.setAttribute("disabled", "true");
} else {
elem.removeAttribute("disabled");
}
if (elem.value.toLowerCase() == aCurrentItem.toLowerCase()) {
elem.setAttribute("checked", "true");
} else {
elem.removeAttribute("checked");
}
}
},
onViewShowing(aEvent) {
if (!this._inited) {
this.onInit();
}
let document = aEvent.target.ownerDocument;
if (
!document.getElementById("PanelUI-characterEncodingView-pinned")
.firstChild
) {
this.populateList(
document,
"PanelUI-characterEncodingView-pinned",
"pinnedCharsets"
);
this.populateList(
document,
"PanelUI-characterEncodingView-charsets",
"otherCharsets"
);
}
this.updateCurrentCharset(document);
},
onCommand(aEvent) {
aEvent.view.BrowserSetForcedCharacterSet("_autodetect_all");
let node = aEvent.target;
if (!node.hasAttribute || !node.section) {
return;
}
let window = node.ownerGlobal;
let value = node.value;
window.BrowserSetForcedCharacterSet(value);
},
onCreated(aNode) {
let document = aNode.ownerDocument;
let updateButton = () => {
if (this.maybeDisableMenu(document)) {
aNode.setAttribute("disabled", "true");
} else {
aNode.removeAttribute("disabled");
}
};
let getPanel = () => {
let { PanelUI } = document.ownerGlobal;
return PanelUI.overflowPanel;
};
if (
CustomizableUI.getAreaType(this.currentArea) ==
CustomizableUI.TYPE_MENU_PANEL
) {
getPanel().addEventListener("popupshowing", updateButton);
}
let listener = {
onWidgetAdded: (aWidgetId, aArea) => {
if (aWidgetId != this.id) {
return;
}
if (
CustomizableUI.getAreaType(aArea) == CustomizableUI.TYPE_MENU_PANEL
) {
getPanel().addEventListener("popupshowing", updateButton);
}
},
onWidgetRemoved: (aWidgetId, aPrevArea) => {
if (aWidgetId != this.id) {
return;
}
aNode.removeAttribute("disabled");
if (
CustomizableUI.getAreaType(aPrevArea) ==
CustomizableUI.TYPE_MENU_PANEL
) {
getPanel().removeEventListener("popupshowing", updateButton);
}
},
onWidgetInstanceRemoved: (aWidgetId, aDoc) => {
if (aWidgetId != this.id || aDoc != document) {
return;
}
CustomizableUI.removeListener(listener);
getPanel().removeEventListener("popupshowing", updateButton);
},
};
CustomizableUI.addListener(listener);
this.onInit();
},
onInit() {
this._inited = true;
if (!this.charsetInfo) {
this.charsetInfo = CharsetMenu.getData();
}
},
},
{

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

@ -139,6 +139,7 @@ skip-if = verify
[browser_bookmarks_toolbar_collapsed_restore_default.js]
[browser_bookmarks_toolbar_shown_newtab.js]
[browser_bootstrapped_custom_toolbar.js]
[browser_character_encoding_ctrl_click.js]
[browser_ctrl_click_panel_opening.js]
[browser_currentset_post_reset.js]
[browser_customizemode_contextmenu_menubuttonstate.js]

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

@ -38,6 +38,11 @@ add_task(async function() {
"The Character encoding button is initially disabled"
);
let panelHidePromise = promiseOverflowHidden(window);
document.getElementById("nav-bar").overflowable._panel.hidePopup();
await panelHidePromise;
info("Panel hidden");
let newTab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
TEST_PAGE,
@ -50,6 +55,42 @@ add_task(async function() {
!charEncodingButton.hasAttribute("disabled"),
"The Character encoding button gets enabled"
);
charEncodingButton.click();
let characterEncodingView = document.getElementById(
"PanelUI-characterEncodingView"
);
let subviewShownPromise = subviewShown(characterEncodingView);
await subviewShownPromise;
ok(
characterEncodingView.hasAttribute("visible"),
"The Character encoding panel is displayed"
);
let pinnedEncodings = document.getElementById(
"PanelUI-characterEncodingView-pinned"
);
let charsetsList = document.getElementById(
"PanelUI-characterEncodingView-charsets"
);
ok(pinnedEncodings, "Pinned charsets are available");
ok(charsetsList, "Charsets list is available");
let checkedButtons = characterEncodingView.querySelectorAll(
"toolbarbutton[checked='true']"
);
is(checkedButtons.length, 1, "There should be 1 checked item.");
is(
checkedButtons[0].getAttribute("label"),
"Western",
"The western encoding is correctly selected"
);
panelHidePromise = promiseOverflowHidden(window);
document.getElementById("nav-bar").overflowable._panel.hidePopup();
await panelHidePromise;
info("Panel hidden");
BrowserTestUtils.removeTab(newTab);
});

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

@ -5,8 +5,7 @@
"use strict";
// Adding the character encoding menu to the panel, exiting customize mode,
// and moving it to the nav-bar should have it disabled if the page in the
// content area isn't eligible to have its encoding overridden.
// and moving it to the nav-bar should have it enabled, not disabled.
add_task(async function() {
await startCustomizing();
CustomizableUI.addWidgetToArea(
@ -20,7 +19,7 @@ add_task(async function() {
await panelHiddenPromise;
CustomizableUI.addWidgetToArea("characterencoding-button", "nav-bar");
let button = document.getElementById("characterencoding-button");
ok(button.hasAttribute("disabled"), "Button should be disabled");
ok(!button.hasAttribute("disabled"), "Button shouldn't be disabled");
});
add_task(function asyncCleanup() {

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

@ -27,14 +27,32 @@ add_task(async function() {
await document.getElementById("nav-bar").overflowable.show();
let charEncodingButton = document.getElementById("characterencoding-button");
charEncodingButton.click();
let characterEncodingView = document.getElementById(
"PanelUI-characterEncodingView"
);
let subviewShownPromise = subviewShown(characterEncodingView);
await subviewShownPromise;
ok(
!charEncodingButton.hasAttribute("disabled"),
"The encoding button should be enabled"
let checkedButtons = characterEncodingView.querySelectorAll(
"toolbarbutton[checked='true']"
);
let initialEncoding = checkedButtons[0];
is(
initialEncoding.getAttribute("label"),
"Western",
"The western encoding is initially selected"
);
// change the encoding
let encodings = characterEncodingView.querySelectorAll(
"toolbarbutton:not(.subviewbutton-back)"
);
let newEncoding = encodings[1].hasAttribute("checked")
? encodings[2]
: encodings[1];
let browserStopPromise = BrowserTestUtils.browserStopped(gBrowser, TEST_PAGE);
charEncodingButton.click();
newEncoding.click();
await browserStopPromise;
is(
gBrowser.selectedBrowser.characterSet,
@ -46,10 +64,16 @@ add_task(async function() {
"The encoding menu should be disabled"
);
is(
charEncodingButton.getAttribute("disabled"),
"true",
"We should disable the encoding button in toolbar"
// check that the new encodng is applied
await document.getElementById("nav-bar").overflowable.show();
charEncodingButton.click();
checkedButtons = characterEncodingView.querySelectorAll(
"toolbarbutton[checked='true']"
);
let selectedEncodingName = checkedButtons[0].getAttribute("label");
ok(
selectedEncodingName == "Unicode",
"The encoding was changed to " + selectedEncodingName
);
CustomizableUI.removeWidgetFromArea("characterencoding-button");
@ -65,7 +89,7 @@ add_task(async function() {
is(
charEncodingButton.getAttribute("disabled"),
"true",
"We should disable the encoding button in overflow menu"
"We should disable the encoding menu"
);
BrowserTestUtils.removeTab(newTab);

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

@ -0,0 +1,27 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function test_character_encoding_menu() {
CustomizableUI.addWidgetToArea(
"characterencoding-button",
CustomizableUI.AREA_NAVBAR,
4
);
const button = document.getElementById("characterencoding-button");
EventUtils.synthesizeMouseAtCenter(button, { ctrlKey: true });
const view = document.getElementById("PanelUI-characterEncodingView");
let shownPromise = subviewShown(view);
await shownPromise;
ok(true, "Character encoding menu shown after button pressed");
// Close character encoding popup.
let hiddenPromise = subviewHidden(view);
view.closest("panel").hidePopup();
await hiddenPromise;
CustomizableUI.reset();
});

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

@ -680,12 +680,6 @@ save-to-pocket-button =
.label = Save to { -pocket-brand-name }
.tooltiptext = Save to { -pocket-brand-name }
## Repair text encoding toolbar button
repair-text-encoding-button =
.label = Repair text encoding
.tooltiptext = Guess correct text encoding from page content
## Customize Toolbar Buttons
# Variables:

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

@ -166,8 +166,8 @@ menu-view-page-style-no-style =
menu-view-page-basic-style =
.label = Basic Page Style
.accesskey = B
menu-view-repair-text-encoding =
.label = Repair Text Encoding
menu-view-charset =
.label = Text Encoding
.accesskey = c
## These should match what Safari and other Apple applications

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

@ -64,6 +64,12 @@ paste-button.label = Paste
# LOCALIZATION NOTE(paste-button.tooltiptext2): %S is the keyboard shortcut.
paste-button.tooltiptext2 = Paste (%S)
# LOCALIZATION NOTE (characterencoding-button2.label): The \u00ad text at the beginning
# of the string is used to disable auto hyphenation on the button text when it is displayed
# in the menu panel.
characterencoding-button2.label = \u00adText Encoding
characterencoding-button2.tooltiptext = Show text encoding options
email-link-button.label = Email Link
email-link-button.tooltiptext3 = Email a link to this page

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

@ -689,41 +689,7 @@ bool nsHTMLDocument::WillIgnoreCharsetOverride() {
return true;
}
}
switch (mCharacterSetSource) {
case kCharsetUninitialized:
case kCharsetFromFallback:
case kCharsetFromTopLevelDomain:
case kCharsetFromDocTypeDefault:
case kCharsetFromInitialAutoDetectionWouldHaveBeenUTF8:
case kCharsetFromInitialAutoDetectionWouldNotHaveBeenUTF8DependedOnTLD:
case kCharsetFromFinalJapaneseAutoDetection:
case kCharsetFromFinalAutoDetectionWouldHaveBeenUTF8:
case kCharsetFromFinalAutoDetectionWouldNotHaveBeenUTF8DependedOnTLD:
case kCharsetFromParentFrame:
case kCharsetFromXmlDeclaration:
case kCharsetFromMetaPrescan:
case kCharsetFromMetaTag:
case kCharsetFromChannel:
case kCharsetFromUserForced:
case kCharsetFromUserForcedJapaneseAutoDetection:
return false;
}
bool potentialEffect = false;
nsIPrincipal* parentPrincipal = NodePrincipal();
auto subDoc = [&potentialEffect, parentPrincipal](Document& aSubDoc) {
if (parentPrincipal->Equals(aSubDoc.NodePrincipal()) &&
!aSubDoc.WillIgnoreCharsetOverride()) {
potentialEffect = true;
return CallState::Stop;
}
return CallState::Continue;
};
EnumerateSubDocuments(subDoc);
return !potentialEffect;
return false;
}
void nsHTMLDocument::GetFormsAndFormControls(nsContentList** aFormList,

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

@ -63,7 +63,6 @@ skip-if = true # bug 1399845 tracks re-enabling this test.
[browser_bug1693577.js]
[browser_cancel_starting_autoscrolling_requested_by_background_tab.js]
[browser_charsetMenu_swapBrowsers.js]
[browser_charsetMenu_disable_on_ascii.js]
[browser_click_event_during_autoscrolling.js]
skip-if = !e10s
[browser_content_url_annotation.js]

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

@ -1,18 +0,0 @@
/* Test that the charset menu is properly enabled when swapping browsers. */
add_task(async function test() {
function charsetMenuEnabled() {
return !document
.getElementById("repair-text-encoding")
.hasAttribute("disabled");
}
const PAGE = "data:text/html,<!DOCTYPE html><body>ASCII-only";
let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
url: PAGE,
waitForStateStop: true,
});
ok(!charsetMenuEnabled(), "should have a charset menu here");
BrowserTestUtils.removeTab(tab);
});

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

@ -1,22 +1,17 @@
/* Test that the charset menu is properly enabled when swapping browsers. */
add_task(async function test() {
// NB: This test cheats and calls updateCharacterEncodingMenuState directly
// instead of opening the "View" menu.
function charsetMenuEnabled() {
return !document
.getElementById("repair-text-encoding")
.hasAttribute("disabled");
updateCharacterEncodingMenuState();
return !document.getElementById("charsetMenu").hasAttribute("disabled");
}
const PAGE =
"data:text/html;charset=windows-1252,<!DOCTYPE html><body>hello %e4";
const PAGE = "data:text/html,<!DOCTYPE html><body>hello";
let tab1 = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
url: PAGE,
});
await BrowserTestUtils.waitForMutationCondition(
document.getElementById("repair-text-encoding"),
{ attributes: true },
charsetMenuEnabled
);
ok(charsetMenuEnabled(), "should have a charset menu here");
let tab2 = await BrowserTestUtils.openNewForegroundTab({ gBrowser });