Skip to content

Commit 7235a2d

Browse files
committed
fix test
1 parent e0d69e4 commit 7235a2d

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/ace_test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ module.exports = {
8989
"test: useStrictCSP": function() {
9090
ace.config.set("useStrictCSP", undefined);
9191
function getStyleNode() {
92-
return document.getElementById("test.css");
92+
return document.adoptedStyleSheets ?
93+
document.adoptedStyleSheets.find(sheet => sheet.$id === "test.css") :
94+
document.getElementById("test.css");
9395
}
9496
assert.ok(!getStyleNode());
9597
dom.importCssString("test{}", "test.css", false);
@@ -170,6 +172,26 @@ module.exports = {
170172
var editor = ace.edit(el);
171173
assert.equal(editor.container, el);
172174
editor.destroy();
175+
},
176+
"test: use adoptedStyleSheets": function() {
177+
dom.$resetCssModeForTests();
178+
var div = document.createElement("div");
179+
div.adoptedStyleSheets = [];
180+
div.getRootNode = function() {
181+
return div;
182+
};
183+
if (!window.CSSStyleSheet) {
184+
window.CSSStyleSheet = function() {
185+
this.cssRules = [];
186+
this.replaceSync = function() {};
187+
};
188+
}
189+
190+
var editor = ace.edit(div);
191+
console.log(div.adoptedStyleSheets);
192+
193+
editor.destroy();
194+
dom.$resetCssModeForTests();
173195
}
174196
};
175197

src/lib/dom.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ function importCssString(cssText, id, target) {
276276
var stylesheet = styles[id];
277277
if (!stylesheet) {
278278
stylesheet = styles[id] = new CSSStyleSheet();
279+
stylesheet.$id = id;
279280
stylesheet.replaceSync(cssText);
280281
}
281282
container.adoptedStyleSheets.push(stylesheet);
@@ -305,6 +306,13 @@ var styles = Object.create(null);
305306

306307
exports.importCssString = importCssString;
307308

309+
exports.$resetCssModeForTests = function(useStyleTag) {
310+
USE_STYLE_TAG = useStyleTag == undefined ? null : useStyleTag;
311+
styles = Object.create(null);
312+
strictCSP = undefined;
313+
cssCache = [];
314+
};
315+
308316
/**
309317
* @param {string} uri
310318
* @param {Document} [doc]

0 commit comments

Comments
 (0)