Bug 1440530 - Move dialog setup code out to a helper function for the webpayments mochitest-browser tests. r=mattn
authorJared Wein <jwein@mozilla.com>
Thu, 22 Feb 2018 17:24:59 -0800
changeset 405114 624ce4190bce840d294a467917fe2032d486d1f5
parent 405113 b281723b73dd7f9f7bef2f36056e2fdecc13e445
child 405115 cc27f207449530ba6aa3e20ee10d82499ec2571f
push id33502
push userarchaeopteryx@coole-files.de
push dateSat, 24 Feb 2018 00:59:26 +0000
treeherdermozilla-central@1056e048072c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattn
bugs1440530
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 1440530 - Move dialog setup code out to a helper function for the webpayments mochitest-browser tests. r=mattn MozReview-Commit-ID: 9rpN1lIjOCG
toolkit/components/payments/test/browser/browser_change_shipping.js
toolkit/components/payments/test/browser/browser_profile_storage.js
toolkit/components/payments/test/browser/browser_request_shipping.js
toolkit/components/payments/test/browser/browser_shippingaddresschange_error.js
toolkit/components/payments/test/browser/browser_show_dialog.js
toolkit/components/payments/test/browser/head.js
--- a/toolkit/components/payments/test/browser/browser_change_shipping.js
+++ b/toolkit/components/payments/test/browser/browser_change_shipping.js
@@ -49,35 +49,24 @@ add_task(async function test_show_comple
 
   profileStorage.creditCards.add(card);
   await onChanged;
 
   await BrowserTestUtils.withNewTab({
     gBrowser,
     url: BLANK_PAGE_URL,
   }, async browser => {
-    let dialogReadyPromise = waitForWidgetReady();
-    // start by creating a PaymentRequest, and show it
-    await ContentTask.spawn(browser,
-                            {
-                              methodData: [PTU.MethodData.basicCard],
-                              details: PTU.Details.twoShippingOptions,
-                              options: PTU.Options.requestShippingOption,
-                            },
-                            PTU.ContentTasks.createAndShowRequest);
-
-    // get a reference to the UI dialog and the requestId
-    let [win] = await Promise.all([getPaymentWidget(), dialogReadyPromise]);
-    ok(win, "Got payment widget");
-    let requestId = paymentUISrv.requestIdForWindow(win);
-    ok(requestId, "requestId should be defined");
-    is(win.closed, false, "dialog should not be closed");
-
-    let frame = await getPaymentFrame(win);
-    ok(frame, "Got payment frame");
+    let {win, frame} =
+      await setupPaymentDialog(browser, {
+        methodData: [PTU.MethodData.basicCard],
+        details: PTU.Details.twoShippingOptions,
+        options: PTU.Options.requestShippingOption,
+        merchantTaskFn: PTU.ContentTasks.createAndShowRequest,
+      }
+    );
 
     let shippingOptions =
       await spawnPaymentDialogTask(frame, PTU.DialogContentTasks.getShippingOptions);
     is(shippingOptions.selectedOptionCurrency, "USD", "Shipping options should be in USD");
     is(shippingOptions.optionCount, 2, "there should be two shipping options");
     is(shippingOptions.selectedOptionValue, "2", "default selected should be '2'");
 
     await spawnPaymentDialogTask(frame,
--- a/toolkit/components/payments/test/browser/browser_profile_storage.js
+++ b/toolkit/components/payments/test/browser/browser_profile_storage.js
@@ -33,30 +33,23 @@ add_task(async function test_initial_sta
     "cc-exp-year": 2028,
   });
   await onChanged;
 
   await BrowserTestUtils.withNewTab({
     gBrowser,
     url: BLANK_PAGE_URL,
   }, async browser => {
-    let dialogReadyPromise = waitForWidgetReady();
-    // start by creating a PaymentRequest, and show it
-    await ContentTask.spawn(browser, {methodData, details}, PTU.ContentTasks.createAndShowRequest);
-
-    // get a reference to the UI dialog and the requestId
-    let win = await getPaymentWidget();
-    let requestId = paymentUISrv.requestIdForWindow(win);
-    ok(requestId, "requestId should be defined");
-    is(win.closed, false, "dialog should not be closed");
-
-    let frame = await getPaymentFrame(win);
-    ok(frame, "Got payment frame");
-    await dialogReadyPromise;
-    info("dialog ready");
+    let {win, frame} =
+      await setupPaymentDialog(browser, {
+        methodData,
+        details,
+        merchantTaskFn: PTU.ContentTasks.createAndShowRequest,
+      }
+    );
 
     await spawnPaymentDialogTask(frame, async function checkInitialStore({
       address1GUID,
       card1GUID,
     }) {
       info("checkInitialStore");
       let contentWin = Components.utils.waiveXrays(content);
       let {
--- a/toolkit/components/payments/test/browser/browser_request_shipping.js
+++ b/toolkit/components/payments/test/browser/browser_request_shipping.js
@@ -15,35 +15,24 @@ add_task(async function setup() {
   await onChanged;
 });
 
 add_task(async function test_request_shipping_present() {
   await BrowserTestUtils.withNewTab({
     gBrowser,
     url: BLANK_PAGE_URL,
   }, async browser => {
-    let dialogReadyPromise = waitForWidgetReady();
-    // start by creating a PaymentRequest, and show it
-    await ContentTask.spawn(browser,
-                            {
-                              methodData: [PTU.MethodData.basicCard],
-                              details: PTU.Details.twoShippingOptions,
-                              options: PTU.Options.requestShippingOption,
-                            },
-                            PTU.ContentTasks.createAndShowRequest);
-
-    // get a reference to the UI dialog and the requestId
-    let [win] = await Promise.all([getPaymentWidget(), dialogReadyPromise]);
-    ok(win, "Got payment widget");
-    let requestId = paymentUISrv.requestIdForWindow(win);
-    ok(requestId, "requestId should be defined");
-    is(win.closed, false, "dialog should not be closed");
-
-    let frame = await getPaymentFrame(win);
-    ok(frame, "Got payment frame");
+    let {win, frame} =
+      await setupPaymentDialog(browser, {
+        methodData: [PTU.MethodData.basicCard],
+        details: PTU.Details.twoShippingOptions,
+        options: PTU.Options.requestShippingOption,
+        merchantTaskFn: PTU.ContentTasks.createAndShowRequest,
+      }
+    );
 
     let isShippingOptionsVisible =
       await spawnPaymentDialogTask(frame,
                                    PTU.DialogContentTasks.isElementVisible,
                                    "shipping-option-picker");
     ok(isShippingOptionsVisible, "shipping-option-picker should be visible");
     let isShippingAddressVisible =
       await spawnPaymentDialogTask(frame, PTU.DialogContentTasks.isElementVisible,
@@ -55,34 +44,23 @@ add_task(async function test_request_shi
   });
 });
 
 add_task(async function test_request_shipping_not_present() {
   await BrowserTestUtils.withNewTab({
     gBrowser,
     url: BLANK_PAGE_URL,
   }, async browser => {
-    let dialogReadyPromise = waitForWidgetReady();
-    // start by creating a PaymentRequest, and show it
-    await ContentTask.spawn(browser,
-                            {
-                              methodData: [PTU.MethodData.basicCard],
-                              details: PTU.Details.twoShippingOptions,
-                            },
-                            PTU.ContentTasks.createAndShowRequest);
-
-    // get a reference to the UI dialog and the requestId
-    let [win] = await Promise.all([getPaymentWidget(), dialogReadyPromise]);
-    ok(win, "Got payment widget");
-    let requestId = paymentUISrv.requestIdForWindow(win);
-    ok(requestId, "requestId should be defined");
-    is(win.closed, false, "dialog should not be closed");
-
-    let frame = await getPaymentFrame(win);
-    ok(frame, "Got payment frame");
+    let {win, frame} =
+      await setupPaymentDialog(browser, {
+        methodData: [PTU.MethodData.basicCard],
+        details: PTU.Details.twoShippingOptions,
+        merchantTaskFn: PTU.ContentTasks.createAndShowRequest,
+      }
+    );
 
     let isShippingOptionsVisible =
       await spawnPaymentDialogTask(frame,
                                    PTU.DialogContentTasks.isElementVisible,
                                    "shipping-option-picker");
     ok(!isShippingOptionsVisible, "shipping-option-picker should not be visible");
     let isShippingAddressVisible =
       await spawnPaymentDialogTask(frame, PTU.DialogContentTasks.isElementVisible,
--- a/toolkit/components/payments/test/browser/browser_shippingaddresschange_error.js
+++ b/toolkit/components/payments/test/browser/browser_shippingaddresschange_error.js
@@ -2,35 +2,24 @@
 
 add_task(addSampleAddressesAndBasicCard);
 
 add_task(async function test_show_error_on_addresschange() {
   await BrowserTestUtils.withNewTab({
     gBrowser,
     url: BLANK_PAGE_URL,
   }, async browser => {
-    let dialogReadyPromise = waitForWidgetReady();
-    // start by creating a PaymentRequest, and show it
-    await ContentTask.spawn(browser,
-                            {
-                              methodData: [PTU.MethodData.basicCard],
-                              details: PTU.Details.twoShippingOptions,
-                              options: PTU.Options.requestShippingOption,
-                            },
-                            PTU.ContentTasks.createAndShowRequest);
-
-    // get a reference to the UI dialog and the requestId
-    let [win] = await Promise.all([getPaymentWidget(), dialogReadyPromise]);
-    ok(win, "Got payment widget");
-    let requestId = paymentUISrv.requestIdForWindow(win);
-    ok(requestId, "requestId should be defined");
-    is(win.closed, false, "dialog should not be closed");
-
-    let frame = await getPaymentFrame(win);
-    ok(frame, "Got payment frame");
+    let {win, frame} =
+      await setupPaymentDialog(browser, {
+        methodData: [PTU.MethodData.basicCard],
+        details: PTU.Details.twoShippingOptions,
+        options: PTU.Options.requestShippingOption,
+        merchantTaskFn: PTU.ContentTasks.createAndShowRequest,
+      }
+    );
 
     info("setting up the event handler for shippingoptionchange");
     let EXPECTED_ERROR_TEXT = "Cannot ship with option 1 on days that end with Y";
     await ContentTask.spawn(browser, {
       eventName: "shippingoptionchange",
       details: {
         error: EXPECTED_ERROR_TEXT,
         shippingOptions: [],
--- a/toolkit/components/payments/test/browser/browser_show_dialog.js
+++ b/toolkit/components/payments/test/browser/browser_show_dialog.js
@@ -3,50 +3,43 @@
 const methodData = [PTU.MethodData.basicCard];
 const details = PTU.Details.twoShippingOptions;
 
 add_task(async function test_show_abort_dialog() {
   await BrowserTestUtils.withNewTab({
     gBrowser,
     url: BLANK_PAGE_URL,
   }, async browser => {
-    // start by creating a PaymentRequest, and show it
-    await ContentTask.spawn(browser, {methodData, details}, PTU.ContentTasks.createAndShowRequest);
-
-    // get a reference to the UI dialog and the requestId
-    let win = await getPaymentWidget();
-    let requestId = paymentUISrv.requestIdForWindow(win);
-    ok(requestId, "requestId should be defined");
-    is(win.closed, false, "dialog should not be closed");
+    let {win} =
+      await setupPaymentDialog(browser, {
+        methodData,
+        details,
+        merchantTaskFn: PTU.ContentTasks.createAndShowRequest,
+      }
+    );
 
     // abort the payment request
     ContentTask.spawn(browser, null, async () => content.rq.abort());
     await BrowserTestUtils.waitForCondition(() => win.closed, "dialog should be closed");
   });
 });
 
 add_task(async function test_show_manualAbort_dialog() {
   await BrowserTestUtils.withNewTab({
     gBrowser,
     url: BLANK_PAGE_URL,
   }, async browser => {
-    let dialogReadyPromise = waitForWidgetReady();
-    // start by creating a PaymentRequest, and show it
-    await ContentTask.spawn(browser, {methodData, details}, PTU.ContentTasks.createAndShowRequest);
+    let {win, frame} =
+      await setupPaymentDialog(browser, {
+        methodData,
+        details,
+        merchantTaskFn: PTU.ContentTasks.createAndShowRequest,
+      }
+    );
 
-    // get a reference to the UI dialog and the requestId
-    let [win] = await Promise.all([getPaymentWidget(), dialogReadyPromise]);
-    ok(win, "Got payment widget");
-    let requestId = paymentUISrv.requestIdForWindow(win);
-    ok(requestId, "requestId should be defined");
-    is(win.closed, false, "dialog should not be closed");
-
-    // abort the payment request manually
-    let frame = await getPaymentFrame(win);
-    ok(frame, "Got payment frame");
     spawnPaymentDialogTask(frame, PTU.DialogContentTasks.manuallyClickCancel);
     await BrowserTestUtils.waitForCondition(() => win.closed, "dialog should be closed");
   });
 });
 
 add_task(async function test_show_completePayment() {
   let onChanged = TestUtils.topicObserved("formautofill-storage-changed",
                                           (subject, data) => data == "add");
@@ -77,29 +70,24 @@ add_task(async function test_show_comple
 
   profileStorage.creditCards.add(card);
   await onChanged;
 
   await BrowserTestUtils.withNewTab({
     gBrowser,
     url: BLANK_PAGE_URL,
   }, async browser => {
-    let dialogReadyPromise = waitForWidgetReady();
-    // start by creating a PaymentRequest, and show it
-    await ContentTask.spawn(browser, {methodData, details}, PTU.ContentTasks.createAndShowRequest);
+    let {win, frame} =
+      await setupPaymentDialog(browser, {
+        methodData,
+        details,
+        merchantTaskFn: PTU.ContentTasks.createAndShowRequest,
+      }
+    );
 
-    // get a reference to the UI dialog and the requestId
-    let [win] = await Promise.all([getPaymentWidget(), dialogReadyPromise]);
-    ok(win, "Got payment widget");
-    let requestId = paymentUISrv.requestIdForWindow(win);
-    ok(requestId, "requestId should be defined");
-    is(win.closed, false, "dialog should not be closed");
-
-    let frame = await getPaymentFrame(win);
-    ok(frame, "Got payment frame");
     info("entering CSC");
     await spawnPaymentDialogTask(frame, PTU.DialogContentTasks.setSecurityCode, {
       securityCode: "999",
     });
     info("clicking pay");
     spawnPaymentDialogTask(frame, PTU.DialogContentTasks.completePayment);
 
     // Add a handler to complete the payment above.
@@ -135,28 +123,23 @@ add_task(async function test_show_comple
   });
 });
 
 add_task(async function test_show_completePayment() {
   await BrowserTestUtils.withNewTab({
     gBrowser,
     url: BLANK_PAGE_URL,
   }, async browser => {
-    let dialogReadyPromise = waitForWidgetReady();
-    // start by creating a PaymentRequest, and show it
-    await ContentTask.spawn(browser, {methodData, details}, PTU.ContentTasks.createAndShowRequest);
-
-    // get a reference to the UI dialog and the requestId
-    let [win] = await Promise.all([getPaymentWidget(), dialogReadyPromise]);
-    ok(win, "Got payment widget");
-    let requestId = paymentUISrv.requestIdForWindow(win);
-    ok(requestId, "requestId should be defined");
-    is(win.closed, false, "dialog should not be closed");
-
-    let frame = await getPaymentFrame(win);
+    let {win, frame} =
+      await setupPaymentDialog(browser, {
+        methodData,
+        details,
+        merchantTaskFn: PTU.ContentTasks.createAndShowRequest,
+      }
+    );
 
     await ContentTask.spawn(browser, {
       eventName: "shippingoptionchange",
     }, PTU.ContentTasks.promisePaymentRequestEvent);
 
     info("changing shipping option to '1' from default selected option of '2'");
     spawnPaymentDialogTask(frame, PTU.DialogContentTasks.selectShippingOptionById, "1");
 
--- a/toolkit/components/payments/test/browser/head.js
+++ b/toolkit/components/payments/test/browser/head.js
@@ -145,16 +145,54 @@ async function addSampleAddressesAndBasi
 
   onChanged = TestUtils.topicObserved("formautofill-storage-changed",
                                       (subject, data) => data == "add");
   profileStorage.creditCards.add(PTU.BasicCards.JohnDoe);
   await onChanged;
 }
 
 /**
+ * Create a PaymentRequest object with the given parameters, then
+ * run the given merchantTaskFn.
+ *
+ * @param {Object} browser
+ * @param {Object} options
+ * @param {Object} options.methodData
+ * @param {Object} options.details
+ * @param {Object} options.options
+ * @param {Function} options.merchantTaskFn
+ * @returns {Object} References to the window, requestId, and frame
+ */
+async function setupPaymentDialog(browser, {methodData, details, options, merchantTaskFn}) {
+  let dialogReadyPromise = waitForWidgetReady();
+  await ContentTask.spawn(browser,
+                          {
+                            methodData,
+                            details,
+                            options,
+                          },
+                          merchantTaskFn);
+
+  // get a reference to the UI dialog and the requestId
+  let [win] = await Promise.all([getPaymentWidget(), dialogReadyPromise]);
+  ok(win, "Got payment widget");
+  let requestId = paymentUISrv.requestIdForWindow(win);
+  ok(requestId, "requestId should be defined");
+  is(win.closed, false, "dialog should not be closed");
+
+  let frame = await getPaymentFrame(win);
+  ok(frame, "Got payment frame");
+
+  await dialogReadyPromise;
+  info("dialog ready");
+
+  return {win, requestId, frame};
+}
+
+/**
  * Open a merchant tab with the given merchantTaskFn to create a PaymentRequest
  * and then open the associated PaymentRequest dialog in a new tab and run the
  * associated dialogTaskFn. The same taskArgs are passed to both functions.
  *
  * @param {Function} merchantTaskFn
  * @param {Function} dialogTaskFn
  * @param {Object} taskArgs
  * @param {Object} options