Bug 1443640: Fix race when validating applied CSS. r=mixedpuppy
authorKris Maglione <maglione.k@gmail.com>
Fri, 09 Mar 2018 15:11:33 -0800
changeset 462458 cb4f862e9dd4053089d38347a5222032dd425943
parent 462457 270f423f416617ed31f2ee448c73af100941a6d3
child 462459 d36983c749994d5ed2f1bd67e16bbf72236fef63
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1443640
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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);