Bug 1382388 - add test for manual abort. r=mattn draft
authorJonathan Guillotte-Blouin <jguillotteblouin@mozilla.com>
Mon, 31 Jul 2017 17:36:02 -0700
changeset 645206 6b67e54e8908dcf6d6c3bbd88ced8719c57949ac
parent 645205 848ea9b4a025d98def8902c73cd0344c6ced38d9
child 645212 1b3443cb8b53ba355b8502badaac286185ab08a9
push id73695
push userbmo:jguillotteblouin@mozilla.com
push dateFri, 11 Aug 2017 23:28:15 +0000
reviewersmattn
bugs1382388
milestone57.0a1
Bug 1382388 - add test for manual abort. r=mattn MozReview-Commit-ID: Lu7VWVg3qN8
toolkit/components/payments/test/browser/browser_show_dialog.js
toolkit/components/payments/test/browser/head.js
--- a/toolkit/components/payments/test/browser/browser_show_dialog.js
+++ b/toolkit/components/payments/test/browser/browser_show_dialog.js
@@ -24,8 +24,30 @@ add_task(async function test_show_abort_
     ok(requestId, "requestId should be defined");
     ok(!win.closed, "dialog should not be closed");
 
     // abort the payment request
     await ContentTask.spawn(browser, null, async() => content.rq.abort());
     ok(win.closed, "dialog should be closed");
   });
 });
+
+add_task(async function test_show_manualAbort_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}, ContentTasks.createAndShowRequest);
+
+    // get a reference to the UI dialog and the requestId
+    let win = await getDialogWindow();
+    let requestId = paymentUISrv.requestIdForWindow(win);
+    ok(requestId, "requestId should be defined");
+    ok(!win.closed, "dialog should not be closed");
+
+    // abort the payment request manually
+    let frameLoader = win.document.getElementById("paymentRequestFrame").frameLoader;
+    await ContentTask.spawn(frameLoader, null, ContentTasks.manuallyClickCancel);
+
+    ok(win.closed, "dialog should be closed");
+  });
+});
--- a/toolkit/components/payments/test/browser/head.js
+++ b/toolkit/components/payments/test/browser/head.js
@@ -29,14 +29,18 @@ async function getDialogWindow() {
  * Common content tasks functions to be used with ContentTask.spawn.
  */
 let ContentTasks = {
   createAndShowRequest: async ({methodData, details, options}) => {
     let rq = new content.PaymentRequest(methodData, details, options);
     content.rq = rq; // assign it so we can retrieve it later
     rq.show();
   },
+
+  manuallyClickCancel: async () => {
+    content.document.getElementById("cancel").click();
+  },
 };
 
 
 add_task(async function setup_head() {
   await SpecialPowers.pushPrefEnv({set: [[PREF_PAYMENT_ENABLED, true]]});
 });