Bug 1480872 - paymentDetails attributes should default to an empty arrays. r=edenchuang
☠☠ backed out by 6c9806cf666e ☠ ☠
authorMarcos Cáceres <marcos@marcosc.com>
Mon, 13 Aug 2018 17:45:00 +0300
changeset 431938 5a77e82d273ef9dec5752614f0bb4fd35bca45d2
parent 431876 57e568a7f9334e4b0610199a3fec7fce79e786bb
child 431939 417967cf69de08d624ccbc85886ce8f0e224fdd4
push id34456
push usertoros@mozilla.com
push dateThu, 16 Aug 2018 21:33:21 +0000
treeherdermozilla-central@72442cf86f54 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedenchuang
bugs1480872
milestone63.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 1480872 - paymentDetails attributes should default to an empty arrays. r=edenchuang
dom/payments/PaymentRequestData.cpp
dom/payments/PaymentRequestManager.cpp
dom/payments/ipc/PPaymentRequest.ipdl
dom/payments/test/ConstructorChromeScript.js
dom/payments/test/head.js
--- a/dom/payments/PaymentRequestData.cpp
+++ b/dom/payments/PaymentRequestData.cpp
@@ -360,68 +360,62 @@ PaymentDetails::Create(const IPCPaymentD
 
   nsCOMPtr<nsIPaymentItem> total;
   nsresult rv = PaymentItem::Create(aIPCDetails.total(), getter_AddRefs(total));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   nsCOMPtr<nsIArray> displayItems;
-  if (aIPCDetails.displayItemsPassed()) {
-    nsCOMPtr<nsIMutableArray> items = do_CreateInstance(NS_ARRAY_CONTRACTID);
-    MOZ_ASSERT(items);
-    for (const IPCPaymentItem& displayItem : aIPCDetails.displayItems()) {
-      nsCOMPtr<nsIPaymentItem> item;
-      rv = PaymentItem::Create(displayItem, getter_AddRefs(item));
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
-      rv = items->AppendElement(item);
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
+  nsCOMPtr<nsIMutableArray> items = do_CreateInstance(NS_ARRAY_CONTRACTID);
+  MOZ_ASSERT(items);
+  for (const IPCPaymentItem& displayItem : aIPCDetails.displayItems()) {
+    nsCOMPtr<nsIPaymentItem> item;
+    rv = PaymentItem::Create(displayItem, getter_AddRefs(item));
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
     }
-    displayItems = items.forget();
+    rv = items->AppendElement(item);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
   }
+  displayItems = items.forget();
 
   nsCOMPtr<nsIArray> shippingOptions;
-  if (aIPCDetails.shippingOptionsPassed()) {
-    nsCOMPtr<nsIMutableArray> options = do_CreateInstance(NS_ARRAY_CONTRACTID);
-    MOZ_ASSERT(options);
-    for (const IPCPaymentShippingOption& shippingOption : aIPCDetails.shippingOptions()) {
-      nsCOMPtr<nsIPaymentShippingOption> option;
-      rv = PaymentShippingOption::Create(shippingOption, getter_AddRefs(option));
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
-      rv = options->AppendElement(option);
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
+  nsCOMPtr<nsIMutableArray> options = do_CreateInstance(NS_ARRAY_CONTRACTID);
+  MOZ_ASSERT(options);
+  for (const IPCPaymentShippingOption& shippingOption : aIPCDetails.shippingOptions()) {
+    nsCOMPtr<nsIPaymentShippingOption> option;
+    rv = PaymentShippingOption::Create(shippingOption, getter_AddRefs(option));
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
     }
-    shippingOptions = options.forget();
+    rv = options->AppendElement(option);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
   }
+  shippingOptions = options.forget();
 
   nsCOMPtr<nsIArray> modifiers;
-  if (aIPCDetails.modifiersPassed()) {
-    nsCOMPtr<nsIMutableArray> detailsModifiers = do_CreateInstance(NS_ARRAY_CONTRACTID);
-    MOZ_ASSERT(detailsModifiers);
-    for (const IPCPaymentDetailsModifier& modifier : aIPCDetails.modifiers()) {
-      nsCOMPtr<nsIPaymentDetailsModifier> detailsModifier;
-      rv = PaymentDetailsModifier::Create(modifier, getter_AddRefs(detailsModifier));
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
-      rv = detailsModifiers->AppendElement(detailsModifier);
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
+  nsCOMPtr<nsIMutableArray> detailsModifiers = do_CreateInstance(NS_ARRAY_CONTRACTID);
+  MOZ_ASSERT(detailsModifiers);
+  for (const IPCPaymentDetailsModifier& modifier : aIPCDetails.modifiers()) {
+    nsCOMPtr<nsIPaymentDetailsModifier> detailsModifier;
+    rv = PaymentDetailsModifier::Create(modifier, getter_AddRefs(detailsModifier));
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
     }
-    modifiers = detailsModifiers.forget();
+    rv = detailsModifiers->AppendElement(detailsModifier);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
   }
+  modifiers = detailsModifiers.forget();
 
   nsCOMPtr<nsIPaymentDetails> details =
     new PaymentDetails(aIPCDetails.id(), total, displayItems, shippingOptions,
                        modifiers, aIPCDetails.error(),
                        aIPCDetails.shippingAddressErrors());
 
   details.forget(aDetails);
   return NS_OK;
--- a/dom/payments/PaymentRequestManager.cpp
+++ b/dom/payments/PaymentRequestManager.cpp
@@ -173,20 +173,17 @@ ConvertDetailsInit(JSContext* aCx,
   ConvertItem(aDetails.mTotal, total);
 
   aIPCDetails = IPCPaymentDetails(id,
                                   total,
                                   displayItems,
                                   shippingOptions,
                                   modifiers,
                                   EmptyString(), // error message
-                                  EmptyString(), // shippingAddressErrors
-                                  aDetails.mDisplayItems.WasPassed(),
-                                  aDetails.mShippingOptions.WasPassed(),
-                                  aDetails.mModifiers.WasPassed());
+                                  EmptyString()); // shippingAddressErrors
   return NS_OK;
 }
 
 nsresult
 ConvertDetailsUpdate(JSContext* aCx,
                      const PaymentDetailsUpdate& aDetails,
                      IPCPaymentDetails& aIPCDetails,
                      bool aRequestShipping)
@@ -218,20 +215,17 @@ ConvertDetailsUpdate(JSContext* aCx,
   }
 
   aIPCDetails = IPCPaymentDetails(EmptyString(), // id
                                   total,
                                   displayItems,
                                   shippingOptions,
                                   modifiers,
                                   error,
-                                  shippingAddressErrors,
-                                  aDetails.mDisplayItems.WasPassed(),
-                                  aDetails.mShippingOptions.WasPassed(),
-                                  aDetails.mModifiers.WasPassed());
+                                  shippingAddressErrors);
   return NS_OK;
 }
 
 void
 ConvertOptions(const PaymentOptions& aOptions,
                IPCPaymentOptions& aIPCOption)
 {
   uint8_t shippingTypeIndex = static_cast<uint8_t>(aOptions.mShippingType);
--- a/dom/payments/ipc/PPaymentRequest.ipdl
+++ b/dom/payments/ipc/PPaymentRequest.ipdl
@@ -51,19 +51,16 @@ struct IPCPaymentDetails
 {
   nsString id;
   IPCPaymentItem total;
   IPCPaymentItem[] displayItems;
   IPCPaymentShippingOption[] shippingOptions;
   IPCPaymentDetailsModifier[] modifiers;
   nsString error;
   nsString shippingAddressErrors;
-  bool displayItemsPassed;
-  bool shippingOptionsPassed;
-  bool modifiersPassed;
 };
 
 struct IPCPaymentOptions
 {
   bool requestPayerName;
   bool requestPayerEmail;
   bool requestPayerPhone;
   bool requestShipping;
--- a/dom/payments/test/ConstructorChromeScript.js
+++ b/dom/payments/test/ConstructorChromeScript.js
@@ -40,24 +40,24 @@ function checkSimplestRequest(payRequest
   }
   if (details.totalItem.amount.currency != "USD") {
     emitTestFail("total item's currency should be 'USD'.");
   }
   if (details.totalItem.amount.value != "1.00") {
     emitTestFail("total item's value should be '1.00'.");
   }
 
-  if (details.displayItems) {
-    emitTestFail("details.displayItems should be undefined.");
+  if (details.displayItems.length !== 0) {
+    emitTestFail("details.displayItems should be an empty array.");
   }
-  if (details.modifiers) {
-    emitTestFail("details.displayItems should be undefined.");
+  if (details.modifiers.length !== 0) {
+    emitTestFail("details.modifiers should be an empty array.");
   }
-  if (details.shippingOptions) {
-    emitTestFail("details.shippingOptions should be undefined.");
+  if (details.shippingOptions.length !== 0) {
+    emitTestFail("details.shippingOptions should be an empty array.");
   }
 
   // checking the default generated PaymentOptions parameter
   const paymentOptions = payRequest.paymentOptions;
   if (paymentOptions.requestPayerName) {
     emitTestFail("requestPayerName option should be false.");
   }
   if (paymentOptions.requestPayerEmail) {
@@ -314,24 +314,24 @@ function checkNonBasicCardRequest(payReq
   }
   if (details.totalItem.amount.currency != "USD") {
     emitTestFail("total item's currency should be 'USD'.");
   }
   if (details.totalItem.amount.value != "1.00") {
     emitTestFail("total item's value should be '1.00'.");
   }
 
-  if (details.displayItems) {
-    emitTestFail("details.displayItems should be undefined.");
+  if (details.displayItems.length !== 0) {
+    emitTestFail("details.displayItems should be an zero length array.");
   }
-  if (details.modifiers) {
-    emitTestFail("details.displayItems should be undefined.");
+  if (details.displayItems.length !== 0) {
+    emitTestFail("details.modifiers should be an zero length array.");
   }
-  if (details.shippingOptions) {
-    emitTestFail("details.shippingOptions should be undefined.");
+  if (details.displayItems.length !== 0) {
+    emitTestFail("details.shippingOptions should be an zero length array.");
   }
 
   // checking the default generated PaymentOptions parameter
   const paymentOptions = payRequest.paymentOptions;
   if (paymentOptions.requestPayerName) {
     emitTestFail("requestPayerName option should be false.");
   }
   if (paymentOptions.requestPayerEmail) {
--- a/dom/payments/test/head.js
+++ b/dom/payments/test/head.js
@@ -12,19 +12,19 @@ function checkSimplePayment(aSimplePayme
 
   // checking the passed PaymentDetails parameter
   const details = aSimplePayment.paymentDetails;
   is(details.id, "simple details", "details.id should be 'simple details'.");
   is(details.totalItem.label, "Donation", "total item's label should be 'Donation'.");
   is(details.totalItem.amount.currency, "USD", "total item's currency should be 'USD'.");
   is(details.totalItem.amount.value, "55.00", "total item's value should be '55.00'.");
 
-  ok(!details.displayItems, "details.displayItems should be undefined.");
-  ok(!details.modifiers, "details.modifiers should be undefined.");
-  ok(!details.shippingOptions, "details.shippingOptions should be undefined.");
+  ok(details.displayItems.length, 0, "details.displayItems should be a zero length array.");
+  ok(details.modifiers.length, 0, "details.modifiers should be a zero length array.");
+  ok(details.shippingOptions.length, 0, "details.shippingOptions should be a zero length array.");
 
   // checking the default generated PaymentOptions parameter
   const paymentOptions = aSimplePayment.paymentOptions;
   ok(!paymentOptions.requestPayerName, "payerName option should be false");
   ok(!paymentOptions.requestPayerEmail, "payerEmail option should be false");
   ok(!paymentOptions.requestPayerPhone, "payerPhone option should be false");
   ok(!paymentOptions.requestShipping, "requestShipping option should be false");
   is(paymentOptions.shippingType, "shipping", "shippingType option should be 'shipping'");