зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1464990 - Allow easier testing Switchboard experiments; r=jchen,sebastian
Based on Sebastian's addon - https://github.com/pocmo/Addon-Switchboard-Experiments, this will allow to easily enable / disable Switchboard experiments, process that after Firefox 57 and the obsolescence of the addon was too cumbersome. MozReview-Commit-ID: 2EkYQ42Bd8B --HG-- extra : rebase_source : 7024c1d68897bea9d80f3fc857c5b204f77c8725
This commit is contained in:
Родитель
9910034e6c
Коммит
e943f78fb5
|
@ -0,0 +1,113 @@
|
|||
/* 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";
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
AndroidLog: "resource://gre/modules/AndroidLog.jsm",
|
||||
EventDispatcher: "resource://gre/modules/Messaging.jsm",
|
||||
});
|
||||
|
||||
const LOGTAG = "Experiments";
|
||||
const EXPERIMENTS_CONFIGURATION = "https://firefox.settings.services.mozilla.com/v1/buckets/fennec/collections/experiments/records";
|
||||
const Experiments = Services.wm.getMostRecentWindow("navigator:browser").Experiments;
|
||||
|
||||
document.addEventListener("DOMContentLoaded", initList);
|
||||
|
||||
function log(msg) {
|
||||
AndroidLog.d(LOGTAG, msg);
|
||||
}
|
||||
|
||||
function initList() {
|
||||
const list = document.getElementById("list");
|
||||
list.addEventListener("click", toggleOverride);
|
||||
|
||||
Promise.all([promiseEnabledExperiments(), promiseExperimentsConfiguration()]).then(values => {
|
||||
const enabledExperiments = values[0];
|
||||
const serverConfiguration = values[1];
|
||||
|
||||
serverConfiguration.data.forEach(function(experiment) {
|
||||
try {
|
||||
let item = document.createElement("li");
|
||||
item.textContent = experiment.name;
|
||||
item.setAttribute("name", experiment.name);
|
||||
item.setAttribute("isEnabled", enabledExperiments.includes(experiment.name));
|
||||
list.appendChild(item);
|
||||
} catch (e) {
|
||||
log(`Error while setting experiments list: ${e.error}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function toggleOverride(experiment) {
|
||||
const item = experiment.originalTarget;
|
||||
const name = item.getAttribute("name");
|
||||
const isEnabled = item.getAttribute("isEnabled") === "true";
|
||||
|
||||
log(`toggleOverride: ${name}`);
|
||||
|
||||
Experiments.setOverride(name, !isEnabled);
|
||||
item.setAttribute("isEnabled", !isEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of locally enabled experiments.
|
||||
*/
|
||||
function promiseEnabledExperiments() {
|
||||
log("Getting the locally enabled experiments");
|
||||
|
||||
return EventDispatcher.instance.sendRequestForResult({
|
||||
type: "Experiments:GetActive"
|
||||
}).then(experiments => {
|
||||
log("List of locally enabled experiments ready");
|
||||
return experiments;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the list of experiments from server configuration.
|
||||
*/
|
||||
function promiseExperimentsConfiguration() {
|
||||
log("Fetching server experiments");
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
||||
try {
|
||||
xhr.open("GET", EXPERIMENTS_CONFIGURATION, true);
|
||||
} catch (e) {
|
||||
reject(`Error opening request: ${e}`);
|
||||
return;
|
||||
}
|
||||
|
||||
xhr.onerror = function(e) {
|
||||
reject(`Error making request: ${e.error}`);
|
||||
};
|
||||
|
||||
xhr.onload = function(event) {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
try {
|
||||
resolve(JSON.parse(xhr.responseText));
|
||||
} catch (e) {
|
||||
const errorMessage = `Error while parsing request: ${e}`;
|
||||
log(errorMessage);
|
||||
reject(errorMessage);
|
||||
}
|
||||
} else {
|
||||
const errorMessage = `Request to ${url} returned status ${xhr.status}`;
|
||||
log(errorMessage);
|
||||
reject(errorMessage);
|
||||
}
|
||||
}
|
||||
log("Finished fetching server experiments");
|
||||
};
|
||||
|
||||
xhr.send(null);
|
||||
});
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- 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/. -->
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>Switchboard Experiments</title>
|
||||
<meta name="viewport" content="width=device-width; user-scalable=0" />
|
||||
<link rel="stylesheet" href="chrome://browser/skin/aboutBase.css" type="text/css"/>
|
||||
<link rel="stylesheet" href="chrome://browser/skin/aboutExperiments.css" type="text/css"/>
|
||||
<script type="application/javascript" src="chrome://browser/content/aboutExperiments.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<ul id="list"/>
|
||||
</body>
|
||||
</html>
|
|
@ -5628,7 +5628,7 @@ var IdentityHandler = {
|
|||
return this.IDENTITY_MODE_IDENTIFIED;
|
||||
}
|
||||
|
||||
let whitelist = /^about:(about|accounts|addons|buildconfig|cache|config|crashes|devices|downloads|fennec|firefox|feedback|home|license|logins|logo|memory|mozilla|networking|privatebrowsing|rights|serviceworkers|support|telemetry|webrtc)($|\?)/i;
|
||||
let whitelist = /^about:(about|accounts|addons|buildconfig|cache|config|crashes|devices|downloads|experiments|fennec|firefox|feedback|home|license|logins|logo|memory|mozilla|networking|privatebrowsing|rights|serviceworkers|support|telemetry|webrtc)($|\?)/i;
|
||||
if (uri.schemeIs("about") && whitelist.test(uri.spec)) {
|
||||
return this.IDENTITY_MODE_CHROMEUI;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ chrome.jar:
|
|||
content/RemoteDebugger.js (content/RemoteDebugger.js)
|
||||
content/aboutAccounts.xhtml (content/aboutAccounts.xhtml)
|
||||
content/aboutAccounts.js (content/aboutAccounts.js)
|
||||
content/aboutExperiments.xhtml (content/aboutExperiments.xhtml)
|
||||
content/aboutExperiments.js (content/aboutExperiments.js)
|
||||
content/aboutLogins.xhtml (content/aboutLogins.xhtml)
|
||||
content/aboutLogins.js (content/aboutLogins.js)
|
||||
#ifndef RELEASE_OR_BETA
|
||||
|
|
|
@ -67,6 +67,11 @@ var modules = {
|
|||
uri: "chrome://browser/content/aboutAccounts.xhtml",
|
||||
privileged: true
|
||||
},
|
||||
experiments: {
|
||||
uri: "chrome://browser/content/aboutExperiments.xhtml",
|
||||
privileged: true,
|
||||
hide: true
|
||||
},
|
||||
};
|
||||
|
||||
function AboutRedirector() {}
|
||||
|
|
|
@ -14,6 +14,7 @@ contract @mozilla.org/network/protocol/about;1?what=privatebrowsing {322ba47e-70
|
|||
contract @mozilla.org/network/protocol/about;1?what=blocked {322ba47e-7047-4f71-aebf-cb7d69325cd9}
|
||||
contract @mozilla.org/network/protocol/about;1?what=accounts {322ba47e-7047-4f71-aebf-cb7d69325cd9}
|
||||
contract @mozilla.org/network/protocol/about;1?what=logins {322ba47e-7047-4f71-aebf-cb7d69325cd9}
|
||||
contract @mozilla.org/network/protocol/about;1?what=experiments {322ba47e-7047-4f71-aebf-cb7d69325cd9}
|
||||
|
||||
# DirectoryProvider.js
|
||||
component {ef0f7a87-c1ee-45a8-8d67-26f586e46a4b} DirectoryProvider.js
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/* 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/. */
|
||||
|
||||
ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
li {
|
||||
padding: 25px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
li[isEnabled="true"] {
|
||||
background-color: #c5e1a5;
|
||||
}
|
||||
li[isEnabled="false"] {
|
||||
background-color: #ef9a9a;
|
||||
}
|
|
@ -12,6 +12,7 @@ chrome.jar:
|
|||
skin/aboutAddons.css (aboutAddons.css)
|
||||
skin/aboutBase.css (aboutBase.css)
|
||||
skin/aboutDownloads.css (aboutDownloads.css)
|
||||
skin/aboutExperiments.css (aboutExperiments.css)
|
||||
skin/aboutMemory.css (aboutMemory.css)
|
||||
skin/aboutPrivateBrowsing.css (aboutPrivateBrowsing.css)
|
||||
skin/aboutReader.css (aboutReader.css)
|
||||
|
|
Загрузка…
Ссылка в новой задаче