Bug 1343442 - Refactored DecDoc browser tests for extensibility - r=Gijs
authorGerald Squelart <gsquelart@mozilla.com>
Mon, 10 Apr 2017 16:31:44 +1200
changeset 352563 c586bc55ed72169e02f0e201664c145a98f7c5a9
parent 352562 33e712fad10cc571d52ca8ddc1f22c6906f0a91b
child 352564 c61b9b0d946ebbdbbf97bccc25659594a8ebbd7a
push id40580
push usergsquelart@mozilla.com
push dateWed, 12 Apr 2017 10:36:38 +0000
treeherderautoland@ef27dccaf311 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1343442
milestone55.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 1343442 - Refactored DecDoc browser tests for extensibility - r=Gijs Mostly moved things around to make future tests (using different parameter sets) easier to write. Also, all tests are now run on all platforms, but we're expecting nothing to happen in those cases that were previously skipped. It will be useful when we add tests that actually need to run on all platforms. MozReview-Commit-ID: AZTz9lr2eIJ
browser/base/content/test/general/browser_decoderDoctor.js
--- a/browser/base/content/test/general/browser_decoderDoctor.js
+++ b/browser/base/content/test/general/browser_decoderDoctor.js
@@ -1,85 +1,129 @@
 "use strict";
 
-function* test_decoder_doctor_notification(type, notificationMessage, options) {
+// 'data' contains the notification data object:
+// - data.type must be provided.
+// - data.isSolved and data.decoderDoctorReportId will be added if not provided
+//   (false and "testReportId" resp.)
+// - Other fields (e.g.: data.formats) may be provided as needed.
+// 'notificationMessage': Expected message in the notification bar.
+//   Falsy if nothing is expected after the notification is sent, in which case
+//   we won't have further checks, so the following parameters are not needed.
+// 'label': Expected button label. Falsy if no button is expected, in which case
+//   we won't have further checks, so the following parameters are not needed.
+// 'accessKey': Expected access key for the button.
+// 'tabChecker': function(openedTab) called with the opened tab that resulted
+//   from clicking the button.
+function* test_decoder_doctor_notification(data, notificationMessage,
+                                           label, accessKey, tabChecker) {
+  if (typeof data.type === "undefined") {
+    ok(false, "Test implementation error: data.type must be provided");
+    return;
+  }
+  data.isSolved = data.isSolved || false;
+  if (typeof data.decoderDoctorReportId === "undefined") {
+    data.decoderDoctorReportId = "testReportId";
+  }
   yield BrowserTestUtils.withNewTab({ gBrowser }, function*(browser) {
     let awaitNotificationBar =
       BrowserTestUtils.waitForNotificationBar(gBrowser, browser, "decoder-doctor-notification");
 
-    yield ContentTask.spawn(browser, type, function*(aType) {
+    yield ContentTask.spawn(browser, data, function*(aData) {
       Services.obs.notifyObservers(content.window,
                                    "decoder-doctor-notification",
-                                   JSON.stringify({type: aType,
-                                                   isSolved: false,
-                                                   decoderDoctorReportId: "test",
-                                                   formats: "test"}));
+                                   JSON.stringify(aData));
     });
 
+    if (!notificationMessage) {
+      ok(true, "Tested notifying observers with a nonsensical message, no effects expected");
+      return;
+    }
+
     let notification;
     try {
       notification = yield awaitNotificationBar;
     } catch (ex) {
       ok(false, ex);
       return;
     }
     ok(notification, "Got decoder-doctor-notification notification");
 
     is(notification.getAttribute("label"), notificationMessage,
-      "notification message should match expectation");
+       "notification message should match expectation");
+
     let button = notification.childNodes[0];
-    if (options && options.noLearnMoreButton) {
-      ok(!button, "There should not be a Learn More button");
+    if (!label) {
+      ok(!button, "There should not be button");
       return;
     }
 
-    is(button.getAttribute("label"), gNavigatorBundle.getString("decoder.noCodecs.button"),
-      "notification button should be 'Learn more'");
-    is(button.getAttribute("accesskey"), gNavigatorBundle.getString("decoder.noCodecs.accesskey"),
-      "notification button should have accesskey");
+    is(button.getAttribute("label"),
+       label,
+       `notification button should be '${label}'`);
+    is(button.getAttribute("accesskey"),
+       accessKey,
+       "notification button should have accesskey");
 
-    let baseURL = Services.urlFormatter.formatURLPref("app.support.baseURL");
-    let url = baseURL + ((options && options.sumo) ||
-                         "fix-video-audio-problems-firefox-windows");
-    let awaitNewTab = BrowserTestUtils.waitForNewTab(gBrowser, url);
+    if (!tabChecker) {
+      ok(false, "Test implementation error: Missing tabChecker");
+      return;
+    }
+    let awaitNewTab = BrowserTestUtils.waitForNewTab(gBrowser);
     button.click();
-    let sumoTab = yield awaitNewTab;
-    yield BrowserTestUtils.removeTab(sumoTab);
+    let openedTab = yield awaitNewTab;
+    tabChecker(openedTab);
+    yield BrowserTestUtils.removeTab(openedTab);
   });
 }
 
+function tab_checker_for_sumo(expectedPath) {
+  return function(openedTab) {
+    let baseURL = Services.urlFormatter.formatURLPref("app.support.baseURL");
+    let url = baseURL + expectedPath;
+    is(openedTab.linkedBrowser.currentURI.spec, url,
+       `Expected '${url}' in new tab`);
+  };
+}
+
 add_task(function* test_platform_decoder_not_found() {
-  let message;
+  let message = "";
   let isLinux = AppConstants.platform == "linux";
   if (isLinux) {
     message = gNavigatorBundle.getString("decoder.noCodecsLinux.message");
-  } else {
+  } else if (AppConstants.platform == "win") {
     message = gNavigatorBundle.getString("decoder.noHWAcceleration.message");
   }
 
-  yield test_decoder_doctor_notification("platform-decoder-not-found",
-                                         message,
-                                         {noLearnMoreButton: isLinux});
+  yield test_decoder_doctor_notification(
+    {type: "platform-decoder-not-found", formats: "testFormat"},
+    message,
+    isLinux ? "" : gNavigatorBundle.getString("decoder.noCodecs.button"),
+    isLinux ? "" : gNavigatorBundle.getString("decoder.noCodecs.accesskey"),
+    tab_checker_for_sumo("fix-video-audio-problems-firefox-windows"));
 });
 
 add_task(function* test_cannot_initialize_pulseaudio() {
+  let message = "";
   // This is only sent on Linux.
-  if (AppConstants.platform != "linux") {
-    return;
+  if (AppConstants.platform == "linux") {
+    message = gNavigatorBundle.getString("decoder.noPulseAudio.message");
   }
 
-  let message = gNavigatorBundle.getString("decoder.noPulseAudio.message");
-  yield test_decoder_doctor_notification("cannot-initialize-pulseaudio",
-                                         message,
-                                         {sumo: "fix-common-audio-and-video-issues"});
+  yield test_decoder_doctor_notification(
+    {type: "cannot-initialize-pulseaudio", formats: "testFormat"},
+    message,
+    gNavigatorBundle.getString("decoder.noCodecs.button"),
+    gNavigatorBundle.getString("decoder.noCodecs.accesskey"),
+    tab_checker_for_sumo("fix-common-audio-and-video-issues"));
 });
 
 add_task(function* test_unsupported_libavcodec() {
+  let message = "";
   // This is only sent on Linux.
-  if (AppConstants.platform != "linux") {
-    return;
+  if (AppConstants.platform == "linux") {
+    message =
+      gNavigatorBundle.getString("decoder.unsupportedLibavcodec.message");
   }
 
-  let message = gNavigatorBundle.getString("decoder.unsupportedLibavcodec.message");
-  yield test_decoder_doctor_notification("unsupported-libavcodec",
-                                         message,
-                                         {noLearnMoreButton: true});
+  yield test_decoder_doctor_notification(
+    {type: "unsupported-libavcodec", formats: "testFormat"}, message);
 });