Bug 1429181 - Fix PaymentTestUtil.DialogContentTasks.select* to work with repeated calls. r=sfoster
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Wed, 19 Sep 2018 17:05:09 +0000
changeset 437276 eec81649e2cfbb1ab4bebf6a8630bae352cb4f8c
parent 437275 90201e199fea722a9255b82d0add65c6cf298caf
child 437277 f410e48228a944f16d9d17b5a1bbdadccb5f78d9
push id34674
push userbtara@mozilla.com
push dateWed, 19 Sep 2018 21:57:43 +0000
treeherdermozilla-central@e04795eb82f2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfoster
bugs1429181
milestone64.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 1429181 - Fix PaymentTestUtil.DialogContentTasks.select* to work with repeated calls. r=sfoster Also fix test_basic_card_form.html and browser_show_dialog.js Differential Revision: https://phabricator.services.mozilla.com/D6230
browser/components/payments/test/PaymentTestUtils.jsm
browser/components/payments/test/browser/browser_show_dialog.js
browser/components/payments/test/mochitest/test_basic_card_form.html
--- a/browser/components/payments/test/PaymentTestUtils.jsm
+++ b/browser/components/payments/test/PaymentTestUtils.jsm
@@ -149,48 +149,72 @@ var PaymentTestUtils = {
     },
 
     selectShippingAddressByCountry: (country) => {
       let doc = content.document;
       let addressPicker =
         doc.querySelector("address-picker[selected-state-key='selectedShippingAddress']");
       let select = Cu.waiveXrays(addressPicker).dropdown.popupBox;
       let option = select.querySelector(`[country="${country}"]`);
+      if (Cu.waiveXrays(doc.activeElement) == select) {
+        // If the <select> is already focused, blur and re-focus to reset the
+        // filter-as-you-type timer so that the synthesizeKey below will work
+        // correctly if this method was called recently.
+        select.blur();
+      }
       select.focus();
       // eslint-disable-next-line no-undef
       EventUtils.synthesizeKey(option.label, {}, content.window);
     },
 
     selectShippingAddressByGuid: guid => {
       let doc = content.document;
       let addressPicker =
         doc.querySelector("address-picker[selected-state-key='selectedShippingAddress']");
       let select = Cu.waiveXrays(addressPicker).dropdown.popupBox;
       let option = select.querySelector(`[guid="${guid}"]`);
+      if (Cu.waiveXrays(doc.activeElement) == select) {
+        // If the <select> is already focused, blur and re-focus to reset the
+        // filter-as-you-type timer so that the synthesizeKey below will work
+        // correctly if this method was called recently.
+        select.blur();
+      }
       select.focus();
       // eslint-disable-next-line no-undef
       EventUtils.synthesizeKey(option.label, {}, content.window);
     },
 
     selectShippingOptionById: value => {
       let doc = content.document;
       let optionPicker =
         doc.querySelector("shipping-option-picker");
       let select = Cu.waiveXrays(optionPicker).dropdown.popupBox;
       let option = select.querySelector(`[value="${value}"]`);
+      if (Cu.waiveXrays(doc.activeElement) == select) {
+        // If the <select> is already focused, blur and re-focus to reset the
+        // filter-as-you-type timer so that the synthesizeKey below will work
+        // correctly if this method was called recently.
+        select.blur();
+      }
       select.focus();
       // eslint-disable-next-line no-undef
       EventUtils.synthesizeKey(option.textContent, {}, content.window);
     },
 
     selectPaymentOptionByGuid: guid => {
       let doc = content.document;
       let methodPicker = doc.querySelector("payment-method-picker");
       let select = Cu.waiveXrays(methodPicker).dropdown.popupBox;
-      let option = select.querySelector(`[guid="${guid}"]`);
+      let option = select.querySelector(`[value="${guid}"]`);
+      if (Cu.waiveXrays(doc.activeElement) == select) {
+        // If the <select> is already focused, blur and re-focus to reset the
+        // filter-as-you-type timer so that the synthesizeKey below will work
+        // correctly if this method was called recently.
+        select.blur();
+      }
       select.focus();
       // just type the first few characters to select the right option
       // eslint-disable-next-line no-undef
       EventUtils.synthesizeKey(option.textContent.substring(0, 4), {}, content.window);
     },
 
     /**
      * Click the primary button for the current page
--- a/browser/components/payments/test/browser/browser_show_dialog.js
+++ b/browser/components/payments/test/browser/browser_show_dialog.js
@@ -257,13 +257,12 @@ add_task(async function test_supportedNe
                                  PTU.DialogContentTasks.selectPaymentOptionByGuid,
                                  visaCardGUID);
 
     info("spawn task to check pay button");
     await spawnPaymentDialogTask(frame, async () => {
       ok(!content.document.getElementById("pay").disabled, "pay button should not be disabled");
     });
 
-    info("call manuallyClickCancel");
     spawnPaymentDialogTask(frame, PTU.DialogContentTasks.manuallyClickCancel);
     await BrowserTestUtils.waitForCondition(() => win.closed, "dialog should be closed");
   });
 });
--- a/browser/components/payments/test/mochitest/test_basic_card_form.html
+++ b/browser/components/payments/test/mochitest/test_basic_card_form.html
@@ -12,16 +12,17 @@ Test the basic-card-form element
   <script src="sinon-2.3.2.js"></script>
   <script src="payments_common.js"></script>
   <script src="../../res/vendor/custom-elements.min.js"></script>
   <script src="../../res/unprivileged-fallbacks.js"></script>
   <script src="autofillEditForms.js"></script>
 
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <link rel="stylesheet" type="text/css" href="../../res/paymentRequest.css"/>
+  <link rel="stylesheet" type="text/css" href="../../res/components/accepted-cards.css"/>
 </head>
 <body>
   <p id="display">
   </p>
 <div id="content" style="display: none">
 
 </div>
 <pre id="test">
@@ -81,16 +82,17 @@ add_task(async function test_backButton(
   });
   await form.promiseReady;
   display.appendChild(form);
   await asyncElementRendered();
 
   let stateChangePromise = promiseStateChange(form.requestStore);
   is(form.pageTitleHeading.textContent, "Sample page title 2", "Check title");
   is(form.backButton.textContent, "Back", "Check label");
+  form.backButton.scrollIntoView();
   synthesizeMouseAtCenter(form.backButton, {});
 
   let {page} = await stateChangePromise;
   is(page.id, "payment-summary", "Check initial page after appending");
 
   form.remove();
 });