Bug 1443640: Fix race when validating applied CSS. r?mixedpuppy draft
authorKris Maglione <maglione.k@gmail.com>
Fri, 09 Mar 2018 15:11:33 -0800
changeset 765661 8f432dfe6f454183cf0b6ada739fb7a8662e9cdf
parent 765660 39e131181d442409a5df2ed945c02aca2b9baca2
push id102132
push usermaglione.k@gmail.com
push dateFri, 09 Mar 2018 23:12:32 +0000
reviewersmixedpuppy
bugs1443640
milestone60.0a1
Bug 1443640: Fix race when validating applied CSS. r?mixedpuppy MozReview-Commit-ID: B3l71jeKnDw
toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js
--- 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);