Bug 1012223 - make opening about:preferences faster, r=jaws

--HG--
extra : rebase_source : 23ef8bb84ae55f81bef21b822febf3482f827a92
This commit is contained in:
Gijs Kruitbosch 2015-01-19 17:40:12 +00:00
parent 8a3b02de53
commit 88c0a1cddd
14 changed files with 90 additions and 113 deletions

View File

@ -7,7 +7,7 @@
<script type="application/javascript"
src="chrome://browser/content/preferences/in-content/advanced.js"/>
<preferences id="advancedPreferences">
<preferences id="advancedPreferences" hidden="true" data-category="paneAdvanced">
<preference id="browser.preferences.advanced.selectedTabIndex"
name="browser.preferences.advanced.selectedTabIndex"
type="int"/>

View File

@ -7,7 +7,7 @@
<script type="application/javascript"
src="chrome://browser/content/preferences/in-content/applications.js"/>
<preferences id="feedsPreferences">
<preferences id="feedsPreferences" hidden="true" data-category="paneApplications">
<preference id="browser.feeds.handler"
name="browser.feeds.handler"
type="string"/>

View File

@ -122,6 +122,10 @@ var gContentPane = {
element : "defaultFontSize",
fonttype : null }];
var preferences = document.getElementById("contentPreferences");
// Ensure preferences are "visible" to ensure bindings work.
preferences.hidden = false;
// Force flush:
preferences.clientHeight;
for (var i = 0; i < prefs.length; ++i) {
var preference = document.getElementById(prefs[i].format.replace(/%LANG%/, aLanguageGroup));
if (!preference) {

View File

@ -4,7 +4,7 @@
<!-- Content panel -->
<preferences id="contentPreferences">
<preferences id="contentPreferences" hidden="true" data-category="paneContent">
<!-- Popups -->
<preference id="dom.disable_open_during_load"

View File

@ -7,7 +7,7 @@
<script type="application/javascript"
src="chrome://browser/content/preferences/in-content/main.js"/>
<preferences id="mainPreferences">
<preferences id="mainPreferences" hidden="true" data-category="paneGeneral">
#ifdef E10S_TESTING_ONLY
<preference id="browser.tabs.remote.autostart"

View File

@ -14,6 +14,28 @@ Cu.import("resource://gre/modules/Services.jsm");
let gLastHash = "";
let gCategoryInits = new Map();
function init_category_if_required(category) {
let categoryInfo = gCategoryInits.get(category);
if (!categoryInfo) {
throw "Unknown in-content prefs category! Can't init " + category;
}
if (categoryInfo.inited) {
return;
}
categoryInfo.init();
}
function register_module(categoryName, categoryObject) {
gCategoryInits.set(categoryName, {
inited: false,
init: function() {
categoryObject.init();
this.inited = true;
}
});
}
addEventListener("DOMContentLoaded", function onLoad() {
removeEventListener("DOMContentLoaded", onLoad);
init_all();
@ -23,20 +45,14 @@ function init_all() {
document.documentElement.instantApply = true;
gSubDialog.init();
gMainPane.init();
gSearchPane.init();
gPrivacyPane.init();
gAdvancedPane.init();
gApplicationsPane.init();
gContentPane.init();
gSyncPane.init();
gSecurityPane.init();
var initFinished = new CustomEvent("Initialized", {
'bubbles': true,
'cancelable': true
});
document.dispatchEvent(initFinished);
register_module("paneGeneral", gMainPane);
register_module("paneSearch", gSearchPane);
register_module("panePrivacy", gPrivacyPane);
register_module("paneAdvanced", gAdvancedPane);
register_module("paneApplications", gApplicationsPane);
register_module("paneContent", gContentPane);
register_module("paneSync", gSyncPane);
register_module("paneSecurity", gSecurityPane);
let categories = document.getElementById("categories");
categories.addEventListener("select", event => gotoPref(event.target.value));
@ -53,6 +69,12 @@ function init_all() {
window.addEventListener("hashchange", onHashChange);
gotoPref();
var initFinished = new CustomEvent("Initialized", {
'bubbles': true,
'cancelable': true
});
document.dispatchEvent(initFinished);
let helpCmd = document.getElementById("help-button");
helpCmd.addEventListener("command", helpButtonCommand);
@ -86,6 +108,13 @@ function gotoPref(aCategory) {
item = categories.querySelector(".category[value=" + category + "]");
}
try {
init_category_if_required(category);
} catch (ex) {
Cu.reportError("Error initializing preference category " + category + ": " + ex);
throw ex;
}
let newHash = internalPrefCategoryNameToFriendlyName(category);
if (gLastHash || category != kDefaultCategoryInternalName) {
document.location.hash = newHash;

View File

@ -7,7 +7,7 @@
<script type="application/javascript"
src="chrome://browser/content/preferences/in-content/privacy.js"/>
<preferences id="privacyPreferences">
<preferences id="privacyPreferences" hidden="true" data-category="panePrivacy">
<!-- Tracking -->
<preference id="privacy.donottrackheader.enabled"

View File

@ -1,4 +1,4 @@
<preferences id="searchPreferences">
<preferences id="searchPreferences" hidden="true" data-category="paneSearch">
<!-- Suggest -->
<preference id="browser.search.suggest.enabled"

View File

@ -7,7 +7,7 @@
<script type="application/javascript"
src="chrome://browser/content/preferences/in-content/security.js"/>
<preferences id="securityPreferences">
<preferences id="securityPreferences" hidden="true" data-category="paneSecurity">
<!-- XXX buttons -->
<preference id="pref.privacy.disable_button.view_passwords"
name="pref.privacy.disable_button.view_passwords"

View File

@ -2,9 +2,9 @@
# 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/.
<!-- Synch panel -->
<!-- Sync panel -->
<preferences>
<preferences hidden="true" data-category="paneSync">
<preference id="engine.addons"
name="services.sync.engine.addons"
type="bool"/>

View File

@ -22,23 +22,12 @@ function test() {
getService(Ci.nsIHandlerService);
hserv.store(info);
function observer(win, topic, data) {
if (topic != "app-handler-pane-loaded")
return;
Services.obs.removeObserver(observer, "app-handler-pane-loaded");
runTest(win);
}
Services.obs.addObserver(observer, "app-handler-pane-loaded", false);
gBrowser.selectedTab = gBrowser.addTab("about:preferences");
openPreferencesViaOpenPreferencesAPI("applications", null, {leaveOpen: true}).then(
() => runTest(gBrowser.selectedBrowser.contentWindow)
);
}
function runTest(win) {
win.gotoPref("applications");
var sel = win.history.state;
is(sel, "paneApplications", "Specified pane was opened");
var rbox = win.document.getElementById("handlersView");
ok(rbox, "handlersView is present");
@ -53,6 +42,5 @@ function runTest(win) {
ok(handlerAdded, "apppanetest protocol handler was successfully added");
gBrowser.removeCurrentTab();
win.close();
finish();
}

View File

@ -9,87 +9,37 @@ function test() {
open_preferences(runTest);
}
let gElements;
function checkElements(expectedPane) {
for (let element of gElements) {
// preferences elements fail is_element_visible checks because they are never visible.
if (element.nodeName == "preferences") {
continue;
}
let attributeValue = element.getAttribute("data-category");
if (attributeValue == "pane" + expectedPane) {
is_element_visible(element, expectedPane + " elements should be visible");
} else {
is_element_hidden(element, "Elements not in " + expectedPane + " should be hidden");
}
}
}
function runTest(win) {
is(gBrowser.currentURI.spec, "about:preferences", "about:preferences loaded");
let tab = win.document;
let elements = tab.getElementById("mainPrefPane").children;
gElements = tab.getElementById("mainPrefPane").children;
//Test if general pane is opened correctly
win.gotoPref("paneGeneral");
for (let element of elements) {
let attributeValue = element.getAttribute("data-category");
if (attributeValue == "paneGeneral") {
is_element_visible(element, "General elements should be visible");
} else {
is_element_hidden(element, "Non-General elements should be hidden");
}
}
let panes = [
"General", "Search", "Content", "Applications",
"Privacy", "Security", "Sync", "Advanced",
];
//Test if content pane is opened correctly
win.gotoPref("paneContent");
for (let element of elements) {
let attributeValue = element.getAttribute("data-category");
if (attributeValue == "paneContent") {
is_element_visible(element, "Content elements should be visible");
} else {
is_element_hidden(element, "Non-Content elements should be hidden");
}
}
//Test if applications pane is opened correctly
win.gotoPref("paneApplications");
for (let element of elements) {
let attributeValue = element.getAttribute("data-category");
if (attributeValue == "paneApplications") {
is_element_visible(element, "Application elements should be visible");
} else {
is_element_hidden(element, "Non-Application elements should be hidden");
}
}
//Test if privacy pane is opened correctly
win.gotoPref("panePrivacy");
for (let element of elements) {
let attributeValue = element.getAttribute("data-category");
if (attributeValue == "panePrivacy") {
is_element_visible(element, "Privacy elements should be visible");
} else {
is_element_hidden(element, "Non-Privacy elements should be hidden");
}
}
//Test if security pane is opened correctly
win.gotoPref("paneSecurity");
for (let element of elements) {
let attributeValue = element.getAttribute("data-category");
if (attributeValue == "paneSecurity") {
is_element_visible(element, "Security elements should be visible");
} else {
is_element_hidden(element, "Non-Security elements should be hidden");
}
}
//Test if sync pane is opened correctly
win.gotoPref("paneSync");
for (let element of elements) {
let attributeValue = element.getAttribute("data-category");
if (attributeValue == "paneSync") {
is_element_visible(element, "Sync elements should be visible");
} else {
is_element_hidden(element, "Non-Sync elements should be hidden");
}
}
//Test if advanced pane is opened correctly
win.gotoPref("paneAdvanced");
for (let element of elements) {
let attributeValue = element.getAttribute("data-category");
if (attributeValue == "paneAdvanced") {
is_element_visible(element, "Advanced elements should be visible");
} else {
is_element_hidden(element, "Non-Advanced elements should be hidden");
}
for (let pane of panes) {
win.gotoPref("pane" + pane);
checkElements(pane);
}
gBrowser.removeCurrentTab();

View File

@ -35,6 +35,9 @@ function runTest(win) {
// Test if advanced pane is opened correctly
win.gotoPref("paneAdvanced");
for (let element of elements) {
if (element.nodeName == "preferences") {
continue;
}
let attributeValue = element.getAttribute("data-category");
if (attributeValue == "paneAdvanced") {
is_element_visible(element, "Advanced elements should be visible");

View File

@ -9,6 +9,7 @@ function runTestOnPrivacyPrefPane(testFunc) {
browser.addEventListener("Initialized", function(aEvent) {
browser.removeEventListener("Initialized", arguments.callee, true);
is(browser.contentWindow.location.href, "about:preferences", "Checking if the preferences tab was opened");
browser.contentWindow.gotoPref("panePrivacy");
testFunc(browser.contentWindow);
gBrowser.removeCurrentTab();
testRunner.runNext();
@ -39,6 +40,8 @@ function test_pane_visibility(win) {
controlChanged(historymode);
is(historypane.selectedPanel, win.document.getElementById(modes[mode]),
"The correct pane should be selected for the " + mode + " mode");
is_element_visible(historypane.selectedPanel,
"Correct pane should be visible for the " + mode + " mode");
}
}