Bug 1443640: Fix race when validating applied CSS. r?mixedpuppy
MozReview-Commit-ID: B3l71jeKnDw
--- a/toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js
@@ -49,32 +49,44 @@ let extensionData = {
"applications": {
"gecko": {
"id": "i18n_css@mochi.test",
},
},
"web_accessible_resources": ["foo.css", "foo.txt", "locale.css"],
- "content_scripts": [{
- "matches": ["http://*/*/file_sample.html"],
- "css": ["foo.css"],
- }],
+ "content_scripts": [
+ {
+ "matches": ["http://*/*/file_sample.html"],
+ "css": ["foo.css"],
+ "run_at": "document_start",
+ },
+ {
+ "matches": ["http://*/*/file_sample.html"],
+ "js": ["content.js"],
+ },
+ ],
"default_locale": "en",
},
files: {
"_locales/en/messages.json": JSON.stringify({
"foo": {
"message": "max-width: 42px",
"description": "foo",
},
}),
+ "content.js": function() {
+ let style = getComputedStyle(document.body);
+ browser.test.sendMessage("content-maxWidth", style.maxWidth);
+ },
+
"foo.css": "body { __MSG_foo__; }",
"bar.CsS": "body { __MSG_foo__; }",
"foo.txt": "body { __MSG_foo__; }",
"locale.css": '* { content: "__MSG_@@ui_locale__ __MSG_@@bidi_dir__ __MSG_@@bidi_reversed_dir__ __MSG_@@bidi_start_edge__ __MSG_@@bidi_end_edge__" }',
},
};
async function test_i18n_css(options = {}) {
@@ -96,25 +108,17 @@ async function test_i18n_css(options = {
}
let css = await fetch(cssURL);
equal(css, "body { max-width: 42px; }", "CSS file localized in mochitest scope");
let contentPage = await ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`);
- // workaround for extension may not be ready for applying foo.css
- await new Promise(executeSoon);
-
- let maxWidth = await ContentTask.spawn(contentPage.browser, {}, async function() {
- /* globals content */
- let style = content.getComputedStyle(content.document.body);
-
- return style.maxWidth;
- });
+ let maxWidth = await extension.awaitMessage("content-maxWidth");
equal(maxWidth, "42px", "stylesheet correctly applied");
await contentPage.close();
cssURL = cssURL.replace(/foo.css$/, "locale.css");
css = await fetch(cssURL);