Commit 3b2cc815 authored by Peter E Conn's avatar Peter E Conn Committed by Commit Bot

💸 Change ListPurchases constants and variable name.

This CL changes the keys for Purchase fields in the ListPurchases
result to be preceded by "purchaseDetails" instead of "listPurchases".
Since we're still in development, there are no users of the old values.

It also changes a key name to spell out MICROSECONDS since MS is
misleading.

Change-Id: I4a29cf367e20469dab9d69ea38215361ea69b84f
Bug: 1139795
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2529550
Commit-Queue: Peter Conn <peconn@chromium.org>
Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Reviewed-by: default avatarJeevan Shikaram <jshikaram@chromium.org>
Reviewed-by: default avatarGlen Robertson <glenrob@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826263}
parent 6e7d5466
...@@ -60,12 +60,7 @@ public class DigitalGoodsConverter { ...@@ -60,12 +60,7 @@ public class DigitalGoodsConverter {
return BillingResponseCode.ERROR; return BillingResponseCode.ERROR;
} }
/** Convenience method for legacy callers. */ static int playBillingToMojoResponseCode(int responseCode) {
static int convertResponseCodeV0(int responseCode) {
return convertResponseCode(responseCode, new Bundle());
}
private static int playBillingToMojoResponseCode(int responseCode) {
switch (responseCode) { switch (responseCode) {
case PLAY_BILLING_OK: case PLAY_BILLING_OK:
return BillingResponseCode.OK; return BillingResponseCode.OK;
......
...@@ -33,12 +33,13 @@ class ListPurchasesConverter { ...@@ -33,12 +33,13 @@ class ListPurchasesConverter {
static final String KEY_PURCHASES_LIST = "listPurchases.purchasesList"; static final String KEY_PURCHASES_LIST = "listPurchases.purchasesList";
static final String KEY_RESPONSE_CODE = "listPurchases.responseCode"; static final String KEY_RESPONSE_CODE = "listPurchases.responseCode";
static final String KEY_ITEM_ID = "listPurchases.itemId"; static final String KEY_ITEM_ID = "purchaseDetails.itemId";
static final String KEY_PURCHASE_TOKEN = "listPurchases.purchaseToken"; static final String KEY_PURCHASE_TOKEN = "purchaseDetails.purchaseToken";
static final String KEY_ACKNOWLEDGED = "listPurchases.acknowledged"; static final String KEY_ACKNOWLEDGED = "purchaseDetails.acknowledged";
static final String KEY_PURCHASE_STATE = "listPurchases.purchaseState"; static final String KEY_PURCHASE_STATE = "purchaseDetails.purchaseState";
static final String KEY_PURCHASE_TIME_MS_PAST_UNIX_EPOCH = "listPurchases.purchaseTime"; static final String KEY_PURCHASE_TIME_MICROSECONDS_PAST_UNIX_EPOCH =
static final String KEY_WILL_AUTO_RENEW = "listPurchases.willAutoRenew"; "purchaseDetails.purchaseTimeMicrosecondsPastUnixEpoch";
static final String KEY_WILL_AUTO_RENEW = "purchaseDetails.willAutoRenew";
// These values are copied from the Play Billing library since Chrome cannot depend on it. // These values are copied from the Play Billing library since Chrome cannot depend on it.
// https://developer.android.com/reference/com/android/billingclient/api/Purchase.PurchaseState // https://developer.android.com/reference/com/android/billingclient/api/Purchase.PurchaseState
...@@ -88,11 +89,14 @@ class ListPurchasesConverter { ...@@ -88,11 +89,14 @@ class ListPurchasesConverter {
if (!checkField(purchase, KEY_PURCHASE_TOKEN, String.class)) return null; if (!checkField(purchase, KEY_PURCHASE_TOKEN, String.class)) return null;
if (!checkField(purchase, KEY_ACKNOWLEDGED, Boolean.class)) return null; if (!checkField(purchase, KEY_ACKNOWLEDGED, Boolean.class)) return null;
if (!checkField(purchase, KEY_PURCHASE_STATE, Integer.class)) return null; if (!checkField(purchase, KEY_PURCHASE_STATE, Integer.class)) return null;
if (!checkField(purchase, KEY_PURCHASE_TIME_MS_PAST_UNIX_EPOCH, Long.class)) return null; if (!checkField(purchase, KEY_PURCHASE_TIME_MICROSECONDS_PAST_UNIX_EPOCH, Long.class)) {
return null;
}
if (!checkField(purchase, KEY_WILL_AUTO_RENEW, Boolean.class)) return null; if (!checkField(purchase, KEY_WILL_AUTO_RENEW, Boolean.class)) return null;
TimeDelta purchaseTime = new TimeDelta(); TimeDelta purchaseTime = new TimeDelta();
purchaseTime.microseconds = purchase.getLong(KEY_PURCHASE_TIME_MS_PAST_UNIX_EPOCH); purchaseTime.microseconds =
purchase.getLong(KEY_PURCHASE_TIME_MICROSECONDS_PAST_UNIX_EPOCH);
PurchaseDetails result = new PurchaseDetails(); PurchaseDetails result = new PurchaseDetails();
...@@ -127,7 +131,7 @@ class ListPurchasesConverter { ...@@ -127,7 +131,7 @@ class ListPurchasesConverter {
@VisibleForTesting @VisibleForTesting
static Bundle createPurchaseDetailsBundle(String itemId, String purchaseToken, static Bundle createPurchaseDetailsBundle(String itemId, String purchaseToken,
boolean acknowledged, int purchaseState, long purchaseTimeMsPastUnixEpoch, boolean acknowledged, int purchaseState, long purchaseTimeMicrosecondsPastUnixEpoch,
boolean willAutoRenew) { boolean willAutoRenew) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
...@@ -135,7 +139,8 @@ class ListPurchasesConverter { ...@@ -135,7 +139,8 @@ class ListPurchasesConverter {
bundle.putString(KEY_PURCHASE_TOKEN, purchaseToken); bundle.putString(KEY_PURCHASE_TOKEN, purchaseToken);
bundle.putBoolean(KEY_ACKNOWLEDGED, acknowledged); bundle.putBoolean(KEY_ACKNOWLEDGED, acknowledged);
bundle.putInt(KEY_PURCHASE_STATE, purchaseState); bundle.putInt(KEY_PURCHASE_STATE, purchaseState);
bundle.putLong(KEY_PURCHASE_TIME_MS_PAST_UNIX_EPOCH, purchaseTimeMsPastUnixEpoch); bundle.putLong(KEY_PURCHASE_TIME_MICROSECONDS_PAST_UNIX_EPOCH,
purchaseTimeMicrosecondsPastUnixEpoch);
bundle.putBoolean(KEY_WILL_AUTO_RENEW, willAutoRenew); bundle.putBoolean(KEY_WILL_AUTO_RENEW, willAutoRenew);
return bundle; return bundle;
......
...@@ -116,7 +116,8 @@ public class DigitalGoodsConverterTest { ...@@ -116,7 +116,8 @@ public class DigitalGoodsConverterTest {
convertedCallback.onExtraCallback(GetDetailsConverter.RESPONSE_COMMAND, args); convertedCallback.onExtraCallback(GetDetailsConverter.RESPONSE_COMMAND, args);
assertEquals(DigitalGoodsConverter.convertResponseCodeV0(responseCode), state.responseCode); assertEquals(DigitalGoodsConverter.convertResponseCode(responseCode, Bundle.EMPTY),
state.responseCode);
assertItemDetails(state.results[0], "1", "t1", "d1", "c1", "v1"); assertItemDetails(state.results[0], "1", "t1", "d1", "c1", "v1");
assertSubsItemDetails(state.results[0], null, null, null, null, null); assertSubsItemDetails(state.results[0], null, null, null, null, null);
assertItemDetails(state.results[1], "2", "t2", "d2", "c2", "v2"); assertItemDetails(state.results[1], "2", "t2", "d2", "c2", "v2");
...@@ -240,7 +241,7 @@ public class DigitalGoodsConverterTest { ...@@ -240,7 +241,7 @@ public class DigitalGoodsConverterTest {
{ {
Bundle bundle = validBundle.deepCopy(); Bundle bundle = validBundle.deepCopy();
bundle.putInt(ListPurchasesConverter.KEY_PURCHASE_TIME_MS_PAST_UNIX_EPOCH, 5); bundle.putInt(ListPurchasesConverter.KEY_PURCHASE_TIME_MICROSECONDS_PAST_UNIX_EPOCH, 5);
assertNull(ListPurchasesConverter.convertPurchaseDetails(bundle)); assertNull(ListPurchasesConverter.convertPurchaseDetails(bundle));
} }
...@@ -269,30 +270,35 @@ public class DigitalGoodsConverterTest { ...@@ -269,30 +270,35 @@ public class DigitalGoodsConverterTest {
convertedCallback.onExtraCallback(ListPurchasesConverter.RESPONSE_COMMAND, args); convertedCallback.onExtraCallback(ListPurchasesConverter.RESPONSE_COMMAND, args);
assertEquals(DigitalGoodsConverter.convertResponseCodeV0(responseCode), state.responseCode); assertEquals(DigitalGoodsConverter.convertResponseCode(responseCode, Bundle.EMPTY),
state.responseCode);
assertPurchaseDetails(state.results[0], "1", "t1", true, 1, 1L, true); assertPurchaseDetails(state.results[0], "1", "t1", true, 1, 1L, true);
assertPurchaseDetails(state.results[1], "2", "t2", false, 2, 2L, false); assertPurchaseDetails(state.results[1], "2", "t2", false, 2, 2L, false);
} }
@Test @Test
public void convertResponseCodes() { public void convertResponseCodes_v0() {
Bundle args = Bundle.EMPTY;
assertEquals(BillingResponseCode.OK, assertEquals(BillingResponseCode.OK,
DigitalGoodsConverter.convertResponseCodeV0(PLAY_BILLING_OK)); DigitalGoodsConverter.convertResponseCode(PLAY_BILLING_OK, args));
assertEquals(BillingResponseCode.ITEM_ALREADY_OWNED, assertEquals(BillingResponseCode.ITEM_ALREADY_OWNED,
DigitalGoodsConverter.convertResponseCodeV0(PLAY_BILLING_ITEM_ALREADY_OWNED)); DigitalGoodsConverter.convertResponseCode(PLAY_BILLING_ITEM_ALREADY_OWNED, args));
assertEquals(BillingResponseCode.ITEM_NOT_OWNED, assertEquals(BillingResponseCode.ITEM_NOT_OWNED,
DigitalGoodsConverter.convertResponseCodeV0(PLAY_BILLING_ITEM_NOT_OWNED)); DigitalGoodsConverter.convertResponseCode(PLAY_BILLING_ITEM_NOT_OWNED, args));
assertEquals(BillingResponseCode.ITEM_UNAVAILABLE, assertEquals(BillingResponseCode.ITEM_UNAVAILABLE,
DigitalGoodsConverter.convertResponseCodeV0(PLAY_BILLING_ITEM_UNAVAILABLE)); DigitalGoodsConverter.convertResponseCode(PLAY_BILLING_ITEM_UNAVAILABLE, args));
// Check that other numbers get set to ERROR. // Check that other numbers get set to ERROR.
assertEquals(BillingResponseCode.ERROR, DigitalGoodsConverter.convertResponseCodeV0(2)); assertEquals(BillingResponseCode.ERROR, DigitalGoodsConverter.convertResponseCode(2, args));
assertEquals(BillingResponseCode.ERROR, DigitalGoodsConverter.convertResponseCodeV0(-1)); assertEquals(
assertEquals(BillingResponseCode.ERROR, DigitalGoodsConverter.convertResponseCodeV0(10)); BillingResponseCode.ERROR, DigitalGoodsConverter.convertResponseCode(-1, args));
assertEquals(
BillingResponseCode.ERROR, DigitalGoodsConverter.convertResponseCode(10, args));
} }
@Test @Test
public void convertResponseCodes_v2() { public void convertResponseCodes_v1() {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putInt(DigitalGoodsConverter.KEY_VERSION, 1); args.putInt(DigitalGoodsConverter.KEY_VERSION, 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment