зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1249888 - try/catch SourceMapConsumer to avoid empty rule-view when source map is invalid; r=gl
--HG-- extra : rebase_source : 744840ba5bb668baf761de0ee1af33395a64aeb4 extra : histedit_source : 157aa5a266678390d2244c790fc44869c3a9f7b7%2C5ea5da38fe59c2612c8fcec8790350732837c9fb
This commit is contained in:
Родитель
42d7d55a85
Коммит
4d0651c987
|
@ -14,6 +14,8 @@ support-files =
|
||||||
doc_custom.html
|
doc_custom.html
|
||||||
doc_filter.html
|
doc_filter.html
|
||||||
doc_frame_script.js
|
doc_frame_script.js
|
||||||
|
doc_invalid_sourcemap.css
|
||||||
|
doc_invalid_sourcemap.html
|
||||||
doc_keyframeanimation.css
|
doc_keyframeanimation.css
|
||||||
doc_keyframeanimation.html
|
doc_keyframeanimation.html
|
||||||
doc_keyframeLineNumbers.html
|
doc_keyframeLineNumbers.html
|
||||||
|
@ -119,6 +121,7 @@ skip-if = (os == "win" && debug) # bug 963492: win.
|
||||||
[browser_rules_inherited-properties_01.js]
|
[browser_rules_inherited-properties_01.js]
|
||||||
[browser_rules_inherited-properties_02.js]
|
[browser_rules_inherited-properties_02.js]
|
||||||
[browser_rules_inherited-properties_03.js]
|
[browser_rules_inherited-properties_03.js]
|
||||||
|
[browser_rules_invalid-source-map.js]
|
||||||
[browser_rules_keybindings.js]
|
[browser_rules_keybindings.js]
|
||||||
[browser_rules_keyframes-rule_01.js]
|
[browser_rules_keyframes-rule_01.js]
|
||||||
[browser_rules_keyframes-rule_02.js]
|
[browser_rules_keyframes-rule_02.js]
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// Test that when a source map is missing/invalid, the rule view still loads
|
||||||
|
// correctly.
|
||||||
|
|
||||||
|
const TESTCASE_URI = URL_ROOT + "doc_invalid_sourcemap.html";
|
||||||
|
const PREF = "devtools.styleeditor.source-maps-enabled";
|
||||||
|
const CSS_LOC = "doc_invalid_sourcemap.css:1";
|
||||||
|
|
||||||
|
add_task(function*() {
|
||||||
|
Services.prefs.setBoolPref(PREF, true);
|
||||||
|
|
||||||
|
yield addTab(TESTCASE_URI);
|
||||||
|
let {inspector, view} = yield openRuleView();
|
||||||
|
|
||||||
|
yield selectNode("div", inspector);
|
||||||
|
|
||||||
|
let ruleEl = getRuleViewRule(view, "div");
|
||||||
|
ok(ruleEl, "The 'div' rule exists in the rule-view");
|
||||||
|
|
||||||
|
let prop = getRuleViewProperty(view, "div", "color");
|
||||||
|
ok(prop, "The 'color' property exists in this rule");
|
||||||
|
|
||||||
|
let value = getRuleViewPropertyValue(view, "div", "color");
|
||||||
|
is(value, "gold", "The 'color' property has the right value");
|
||||||
|
|
||||||
|
yield verifyLinkText(view, CSS_LOC);
|
||||||
|
|
||||||
|
Services.prefs.clearUserPref(PREF);
|
||||||
|
});
|
||||||
|
|
||||||
|
function verifyLinkText(view, text) {
|
||||||
|
info("Verifying that the rule-view stylesheet link is " + text);
|
||||||
|
let label = getRuleViewLinkByIndex(view, 1).querySelector("label");
|
||||||
|
return waitForSuccess(
|
||||||
|
() => label.getAttribute("value") == text,
|
||||||
|
"Link text changed to display correct location: " + text
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
div { color: gold; }
|
||||||
|
|
||||||
|
/*# sourceMappingURL=this-source-map-does-not-exist.css.map */
|
|
@ -0,0 +1,11 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Invalid source map</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="doc_invalid_sourcemap.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div>invalid source map</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -734,13 +734,13 @@ var StyleSheetActor = protocol.ActorClass({
|
||||||
_fetchSourceMap: function() {
|
_fetchSourceMap: function() {
|
||||||
let deferred = promise.defer();
|
let deferred = promise.defer();
|
||||||
|
|
||||||
this._getText().then((content) => {
|
this._getText().then(sheetContent => {
|
||||||
let url = this._extractSourceMapUrl(content);
|
let url = this._extractSourceMapUrl(sheetContent);
|
||||||
if (!url) {
|
if (!url) {
|
||||||
// no source map for this stylesheet
|
// no source map for this stylesheet
|
||||||
deferred.resolve(null);
|
deferred.resolve(null);
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
|
|
||||||
url = normalize(url, this.href);
|
url = normalize(url, this.href);
|
||||||
let options = {
|
let options = {
|
||||||
|
@ -748,15 +748,24 @@ var StyleSheetActor = protocol.ActorClass({
|
||||||
policy: Ci.nsIContentPolicy.TYPE_INTERNAL_STYLESHEET,
|
policy: Ci.nsIContentPolicy.TYPE_INTERNAL_STYLESHEET,
|
||||||
window: this.window
|
window: this.window
|
||||||
};
|
};
|
||||||
let map = fetch(url, options)
|
|
||||||
.then(({content}) => {
|
|
||||||
let map = new SourceMapConsumer(content);
|
|
||||||
this._setSourceMapRoot(map, url, this.href);
|
|
||||||
this._sourceMap = promise.resolve(map);
|
|
||||||
|
|
||||||
deferred.resolve(map);
|
let map = fetch(url, options).then(({content}) => {
|
||||||
return map;
|
// Fetching the source map might have failed with a 404 or other. When
|
||||||
}, deferred.reject);
|
// this happens, SourceMapConsumer may fail with a JSON.parse error.
|
||||||
|
let consumer;
|
||||||
|
try {
|
||||||
|
consumer = new SourceMapConsumer(content);
|
||||||
|
} catch (e) {
|
||||||
|
deferred.reject(new Error(
|
||||||
|
`Source map at ${url} not found or invalid`));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
this._setSourceMapRoot(consumer, url, this.href);
|
||||||
|
this._sourceMap = promise.resolve(consumer);
|
||||||
|
|
||||||
|
deferred.resolve(consumer);
|
||||||
|
return consumer;
|
||||||
|
}, deferred.reject);
|
||||||
|
|
||||||
this._sourceMap = map;
|
this._sourceMap = map;
|
||||||
}, deferred.reject);
|
}, deferred.reject);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче