Bug 1335454 - Add the ability to open the "Data Choices" options section through UITour, r=jaws

This patch does:
- Update UITour.jsm to make websites able to open to the old Prefernces advanced pane > dataChoicesTab by calling `Mozilla.UITour.openPreferences("privacy-reports")`.
- Update the comments of `Mozilla.UITour.openPreferences` to explain the old and new Preference to api users.

MozReview-Commit-ID: IdNDKiqfxKo

--HG--
extra : rebase_source : 520d3df019f37f8f6f581774b0b315a958d5246f
This commit is contained in:
Fischer.json 2017-04-23 16:27:26 +08:00
Родитель 69f2bbaf90
Коммит 49a442f2dd
4 изменённых файлов: 74 добавлений и 5 удалений

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

@ -724,8 +724,13 @@ function openPreferences(paneID, extraArgs) {
}
function switchToAdvancedSubPane(doc) {
if (extraArgs && extraArgs["advancedTab"]) {
// After the Preferences reorg works in Bug 1335907, no more advancedPrefs element.
// The old Preference is pref-off behind `browser.preferences.useOldOrganization` on Nightly.
// During the transition between the old and new Preferences, should do checking before proceeding.
let advancedPaneTabs = doc.getElementById("advancedPrefs");
advancedPaneTabs.selectedTab = doc.getElementById(extraArgs["advancedTab"]);
if (advancedPaneTabs) {
advancedPaneTabs.selectedTab = doc.getElementById(extraArgs["advancedTab"]);
}
}
}

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

@ -42,8 +42,8 @@ if (typeof Mozilla == "undefined") {
var event = new CustomEvent("mozUITour", {
bubbles: true,
detail: {
action,
data: data || {}
action,
data: data || {}
}
});
@ -746,7 +746,9 @@ if (typeof Mozilla == "undefined") {
/**
* @param {String} pane - Pane to open/switch the preferences to.
* Valid values match fragments on about:preferences and are subject to change e.g.:<ul>
* Valid values match fragments on about:preferences and are subject to change e.g.:
* <ul>
* For the old Preferences
* <li>general
* <li>search
* <li>content
@ -756,6 +758,22 @@ if (typeof Mozilla == "undefined") {
* <li>sync
* <li>advanced
* </ul>
*
* <ul>
* For the new Preferences
* <li>general
* <li>applications
* <li>sync
* <li>privacy
* <li>advanced
* </ul>
*
* The mapping between the old and the new Preferences:
* To open to the options of sending telemetry, health report, crach reports,
* that is, the advanced pane > dataChoicesTab on the old and the privcacy pane > reports on the new.
* Please call `Mozilla.UITour.openPreferences("privacy-reports")`.
* UITour would do route mapping automatically.
*
* @since 42
*/
Mozilla.UITour.openPreferences = function(pane) {

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

@ -536,7 +536,21 @@ this.UITour = {
return false;
}
window.openPreferences(data.pane, { origin: "UITour" });
let paneID = data.pane;
let extraArgs = { origin: "UITour" };
if (Services.prefs.getBoolPref("browser.preferences.useOldOrganization", true)) {
// We are heading to the old Preferences so
// let's map the new one to the old one if the `paneID` was for the new Preferences.
// Currently only the old advanced pane > dataChoicesTab has the mapping need,
// so here only do mapping for it right now.
// We could add another mapping when there is need.
if (paneID == "privacy-reports") {
paneID = "advanced";
extraArgs.advancedTab = "dataChoicesTab";
}
}
window.openPreferences(paneID, extraArgs);
break;
}

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

@ -34,3 +34,35 @@ add_UITour_task(async function test_openPrivacyPreferences() {
let tab = await promiseTabOpened;
await BrowserTestUtils.removeTab(tab);
});
add_UITour_task(async function test_openOldDataChoicesTab() {
if (!AppConstants.MOZ_DATA_REPORTING) {
return;
}
await SpecialPowers.pushPrefEnv({set: [["browser.preferences.useOldOrganization", true]]});
let promiseTabOpened = BrowserTestUtils.waitForNewTab(gBrowser, "about:preferences#advanced");
await gContentAPI.openPreferences("privacy-reports");
let tab = await promiseTabOpened;
await BrowserTestUtils.waitForEvent(gBrowser.selectedBrowser, "Initialized");
let doc = gBrowser.selectedBrowser.contentDocument;
let selectedTab = doc.getElementById("advancedPrefs").selectedTab;
is(selectedTab.id, "dataChoicesTab", "Should open to the dataChoicesTab in the old Preferences");
await BrowserTestUtils.removeTab(tab);
});
add_UITour_task(async function test_openPrivacyReports() {
if (!AppConstants.MOZ_TELEMETRY_REPORTING &&
!(AppConstants.MOZ_DATA_REPORTING && AppConstants.MOZ_CRASHREPORTER)) {
return;
}
await SpecialPowers.pushPrefEnv({set: [["browser.preferences.useOldOrganization", false]]});
let promiseTabOpened = BrowserTestUtils.waitForNewTab(gBrowser, "about:preferences#privacy-reports");
await gContentAPI.openPreferences("privacy-reports");
let tab = await promiseTabOpened;
await BrowserTestUtils.waitForEvent(gBrowser.selectedBrowser, "Initialized");
let doc = gBrowser.selectedBrowser.contentDocument;
let reports = doc.querySelector("groupbox[data-subcategory='reports']");
is(doc.location.hash, "#privacy", "Should not display the reports subcategory in the location hash.");
is(reports.hidden, false, "Should open to the reports subcategory in the privacy pane in the new Preferences.");
await BrowserTestUtils.removeTab(tab);
});