Bug 1298082 - Various cleanups to use helpers. r=jryans

MozReview-Commit-ID: EwtA2K00EaM

--HG--
extra : rebase_source : a97a380d413f1a84077ba7bb1250e49af3284825
This commit is contained in:
Alexandre Poirot 2016-08-25 05:50:44 -07:00
Родитель 83b000037d
Коммит 0e07d87062
9 изменённых файлов: 18 добавлений и 30 удалений

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

@ -201,7 +201,7 @@ function destroyToolbox(toolbox) {
toolbox.destroy().then(function () {
let target = TargetFactory.forTab(gBrowser.selectedTab);
ok(gDevTools._toolboxes.get(target) == null, "gDevTools doesn't know about target");
ok(toolbox._target == null, "toolbox doesn't know about target.");
ok(toolbox.target == null, "toolbox doesn't know about target.");
finishUp();
});
}

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

@ -12,8 +12,8 @@ let url = new window.URL(href);
if (url.search.length > 1) {
const Cu = Components.utils;
const Ci = Components.interfaces;
const { gDevTools } = Cu.import("resource://devtools/client/framework/gDevTools.jsm", {});
const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
const { gDevTools } = require("devtools/client/framework/devtools");
const { targetFromURL } = require("devtools/client/framework/target-from-url");
const { Toolbox } = require("devtools/client/framework/toolbox");
const { TargetFactory } = require("devtools/client/framework/target");

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

@ -1803,7 +1803,7 @@ Toolbox.prototype = {
// Handle the case where the previous host happens to match the current
// host. If so, switch to bottom if it's not already used, and side if not.
if (hostType === this._host.type) {
if (hostType === this.hostType) {
if (hostType === Toolbox.HostType.BOTTOM) {
hostType = Toolbox.HostType.SIDE;
} else {
@ -1822,7 +1822,7 @@ Toolbox.prototype = {
* The host type of the new host object
*/
switchHost: function (hostType) {
if (hostType == this._host.type || !this._target.isLocalTab) {
if (hostType == this.hostType || !this._target.isLocalTab) {
return null;
}
@ -2127,7 +2127,7 @@ Toolbox.prototype = {
this._threadClient = null;
// We need to grab a reference to win before this._host is destroyed.
let win = this.frame.ownerDocument.defaultView;
let win = this.win;
if (this._requisition) {
CommandUtils.destroyRequisition(this._requisition, this.target);

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

@ -75,7 +75,7 @@ const TOOLBOX_L10N = new LocalizationHelper("devtools/locale/toolbox.properties"
*/
function InspectorPanel(iframeWindow, toolbox) {
this._toolbox = toolbox;
this._target = toolbox._target;
this._target = toolbox.target;
this.panelDoc = iframeWindow.document;
this.panelWin = iframeWindow;
this.panelWin.inspector = this;

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

@ -512,7 +512,7 @@ CssRuleView.prototype = {
_onAddRule: function () {
let elementStyle = this._elementStyle;
let element = elementStyle.element;
let client = this.inspector.toolbox._target.client;
let client = this.inspector.toolbox.target.client;
let pseudoClasses = element.pseudoClassLocks;
if (!client.traits.addNewRule) {

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

@ -31,7 +31,7 @@ function CssDocsTooltip(toolbox) {
this.widget.on("visitlink", this._onVisitLink);
// Initialize keyboard shortcuts
this.shortcuts = new KeyShortcuts({ window: toolbox.doc.defaultView });
this.shortcuts = new KeyShortcuts({ window: toolbox.win });
this._onShortcut = this._onShortcut.bind(this);
this.shortcuts.on("Escape", this._onShortcut);

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

@ -40,14 +40,17 @@ window.onload = function() {
hasActor: () => useActor,
client: attachmentA.client,
form: attachmentA.tab
}
},
// Fake the window for css-properties.js's getClientBrowserVersion to work
win: window
};
const toolboxMockB = {
target: {
hasActor: () => useActor,
client: attachmentB.client,
form: attachmentB.tab
}
},
win: window
};
yield initCssProperties(toolboxMockA);

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

@ -40,15 +40,7 @@ window.onload = function() {
client: attachmentA.client,
form: attachmentA.tab,
},
_host: { frame: { contentWindow: window } }
};
const toolboxUnknownVersions = {
target: {
hasActor: () => true,
client: attachmentB.client,
form: attachmentB.tab
}
// Don't add a host here.
win: window
};
const toolboxDifferentVersions = {
target: {
@ -56,9 +48,9 @@ window.onload = function() {
client: attachmentB.client,
form: attachmentB.tab
},
_host: { frame: { contentWindow: { navigator: { userAgent:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:49.0) Gecko/20100101 " +
"Firefox/30.0" }}}}
win: { navigator: { userAgent:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:49.0) Gecko/20100101 " +
"Firefox/30.0" }}
};
// Modify a property on the static database, to differentiate between a generated
@ -66,17 +58,13 @@ window.onload = function() {
CSS_PROPERTIES_DB.properties.color.isStatic = true;
yield initCssProperties(toolboxMatchingVersions);
yield initCssProperties(toolboxUnknownVersions);
yield initCssProperties(toolboxDifferentVersions);
const cssPropertiesMatching = getCssProperties(toolboxMatchingVersions);
const cssPropertiesUnknown = getCssProperties(toolboxUnknownVersions);
const cssPropertiesDifferent = getCssProperties(toolboxDifferentVersions);
is(cssPropertiesMatching.properties.color.isStatic, true,
"The static CSS database is used when the client and platform versions match.");
is(cssPropertiesUnknown.properties.color.isStatic, true,
"The static CSS database is used when the client is not a known Firefox.");
isnot(cssPropertiesDifferent.properties.color.isStatic, undefined,
"The generated CSS database is used when the client and platform versions do " +
"not match, but the client is a Firefox.");

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

@ -192,10 +192,7 @@ function getClientCssProperties() {
* @returns {string} The browser version.
*/
function getClientBrowserVersion(toolbox) {
if (!toolbox._host) {
return "0";
}
const regexResult = toolbox._host.frame.contentWindow.navigator
const regexResult = toolbox.win.navigator
.userAgent.match(/Firefox\/(\d+)\.\d/);
return Array.isArray(regexResult) ? regexResult[1] : "0";
}