Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: chrome/android/junit/src/org/chromium/chrome/browser/payments/AndroidPaymentAppFinderTest.java

Issue 2802043002: Use web-app manifest format for Android payment apps. (Closed)
Patch Set: Address comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.payments; 5 package org.chromium.chrome.browser.payments;
6 6
7 import android.content.Intent; 7 import android.content.Intent;
8 import android.content.pm.ActivityInfo; 8 import android.content.pm.ActivityInfo;
9 import android.content.pm.ApplicationInfo; 9 import android.content.pm.ApplicationInfo;
10 import android.content.pm.PackageInfo; 10 import android.content.pm.PackageInfo;
11 import android.content.pm.ResolveInfo; 11 import android.content.pm.ResolveInfo;
12 import android.content.pm.ServiceInfo; 12 import android.content.pm.ServiceInfo;
13 import android.content.pm.Signature; 13 import android.content.pm.Signature;
14 import android.content.res.Resources; 14 import android.content.res.Resources;
15 import android.os.Bundle; 15 import android.os.Bundle;
16 16
17 import org.junit.Test; 17 import org.junit.Test;
18 import org.junit.runner.RunWith; 18 import org.junit.runner.RunWith;
19 import org.mockito.ArgumentMatcher; 19 import org.mockito.ArgumentMatcher;
20 import org.mockito.ArgumentMatchers; 20 import org.mockito.ArgumentMatchers;
21 import org.mockito.Mockito; 21 import org.mockito.Mockito;
22 import org.robolectric.RobolectricTestRunner; 22 import org.robolectric.RobolectricTestRunner;
23 import org.robolectric.annotation.Config; 23 import org.robolectric.annotation.Config;
24 24
25 import org.chromium.chrome.browser.payments.PaymentAppFactory.PaymentAppCreatedC allback; 25 import org.chromium.chrome.browser.payments.PaymentAppFactory.PaymentAppCreatedC allback;
26 import org.chromium.components.payments.PaymentManifestDownloader; 26 import org.chromium.components.payments.PaymentManifestDownloader;
27 import org.chromium.components.payments.PaymentManifestParser; 27 import org.chromium.components.payments.PaymentManifestParser;
28 import org.chromium.content_public.browser.WebContents; 28 import org.chromium.content_public.browser.WebContents;
29 import org.chromium.payments.mojom.PaymentManifestSection; 29 import org.chromium.payments.mojom.WebAppManifestSection;
30 30
31 import java.net.URI; 31 import java.net.URI;
32 import java.net.URISyntaxException;
32 import java.util.ArrayList; 33 import java.util.ArrayList;
33 import java.util.HashSet; 34 import java.util.HashSet;
34 import java.util.List; 35 import java.util.List;
35 import java.util.Set; 36 import java.util.Set;
36 37
37 /** Tests for the native Android payment app finder. */ 38 /** Tests for the native Android payment app finder. */
38 @RunWith(RobolectricTestRunner.class) 39 @RunWith(RobolectricTestRunner.class)
39 @Config(sdk = 21, manifest = Config.NONE) 40 @Config(sdk = 21, manifest = Config.NONE)
40 public class AndroidPaymentAppFinderTest { 41 public class AndroidPaymentAppFinderTest {
41 private static final IntentArgumentMatcher sPayIntentArgumentMatcher = 42 private static final IntentArgumentMatcher sPayIntentArgumentMatcher =
42 new IntentArgumentMatcher(new Intent("org.chromium.intent.action.PAY ")); 43 new IntentArgumentMatcher(new Intent("org.chromium.intent.action.PAY "));
43 44
44 public AndroidPaymentAppFinderTest() {} 45 public AndroidPaymentAppFinderTest() {}
45 46
46 /** 47 /**
47 * Argument matcher that matches Intents using |filterEquals| method. 48 * Argument matcher that matches Intents using |filterEquals| method.
48 */ 49 */
49 private static class IntentArgumentMatcher implements ArgumentMatcher<Intent > { 50 private static class IntentArgumentMatcher implements ArgumentMatcher<Intent > {
50
51 private final Intent mIntent; 51 private final Intent mIntent;
52 52
53 public IntentArgumentMatcher(Intent intent) { 53 public IntentArgumentMatcher(Intent intent) {
54 mIntent = intent; 54 mIntent = intent;
55 } 55 }
56 56
57 @Override 57 @Override
58 public boolean matches(Intent other) { 58 public boolean matches(Intent other) {
59 return mIntent.filterEquals(other); 59 return mIntent.filterEquals(other);
60 } 60 }
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 ArgumentMatchers.eq(bobPay.activityInfo.application Info))) 269 ArgumentMatchers.eq(bobPay.activityInfo.application Info)))
270 .thenReturn(resouces); 270 .thenReturn(resouces);
271 271
272 List<ResolveInfo> services = new ArrayList<>(); 272 List<ResolveInfo> services = new ArrayList<>();
273 ResolveInfo isBobPayReadyToPay = new ResolveInfo(); 273 ResolveInfo isBobPayReadyToPay = new ResolveInfo();
274 isBobPayReadyToPay.serviceInfo = new ServiceInfo(); 274 isBobPayReadyToPay.serviceInfo = new ServiceInfo();
275 isBobPayReadyToPay.serviceInfo.packageName = "com.bobpay.app"; 275 isBobPayReadyToPay.serviceInfo.packageName = "com.bobpay.app";
276 isBobPayReadyToPay.serviceInfo.name = "com.bobpay.app.IsReadyToWebPay"; 276 isBobPayReadyToPay.serviceInfo.name = "com.bobpay.app.IsReadyToWebPay";
277 services.add(isBobPayReadyToPay); 277 services.add(isBobPayReadyToPay);
278 Intent isReadyToPayIntent = new Intent(AndroidPaymentAppFinder.ACTION_IS _READY_TO_PAY); 278 Intent isReadyToPayIntent = new Intent(AndroidPaymentAppFinder.ACTION_IS _READY_TO_PAY);
279 Mockito.when(packageManagerDelegate.getServicesThatCanRespondToIntent( 279 Mockito
280 .when(packageManagerDelegate.getServicesThatCanRespondToIntent(
gogerald1 2017/04/07 19:36:16 Mockito.when could be in single line
please use gerrit instead 2017/04/08 18:54:48 Done.
280 ArgumentMatchers.argThat(new IntentArgumentMatcher(isRea dyToPayIntent)))) 281 ArgumentMatchers.argThat(new IntentArgumentMatcher(isRea dyToPayIntent))))
281 .thenReturn(services); 282 .thenReturn(services);
282 283
283 PackageInfo bobPayPackageInfo = new PackageInfo(); 284 PackageInfo bobPayPackageInfo = new PackageInfo();
284 bobPayPackageInfo.versionCode = 10; 285 bobPayPackageInfo.versionCode = 10;
285 bobPayPackageInfo.signatures = new Signature[1]; 286 bobPayPackageInfo.signatures = new Signature[1];
286 bobPayPackageInfo.signatures[0] = new Signature("01020304050607080900"); 287 bobPayPackageInfo.signatures[0] = new Signature("01020304050607080900");
287 Mockito.when(packageManagerDelegate.getPackageInfoWithSignatures("com.bo bpay.app")) 288 Mockito.when(packageManagerDelegate.getPackageInfoWithSignatures("com.bo bpay.app"))
288 .thenReturn(bobPayPackageInfo); 289 .thenReturn(bobPayPackageInfo);
289 290
290 PaymentManifestDownloader downloader = new PaymentManifestDownloader(nul l) { 291 PaymentManifestDownloader downloader = new PaymentManifestDownloader(nul l) {
291 @Override 292 @Override
292 public void download(URI uri, ManifestDownloadCallback callback) { 293 public void downloadPaymentMethodManifest(URI uri, ManifestDownloadC allback callback) {
293 callback.onManifestDownloadSuccess("some content here"); 294 callback.onPaymentMethodManifestDownloadSuccess("some content he re");
295 }
296
297 @Override
298 public void downloadWebAppManifest(URI uri, ManifestDownloadCallback callback) {
299 callback.onWebAppManifestDownloadSuccess("some content here");
294 } 300 }
295 }; 301 };
296 302
297 PaymentManifestParser parser = new PaymentManifestParser() { 303 PaymentManifestParser parser = new PaymentManifestParser() {
298 @Override 304 @Override
299 public void parse(String content, ManifestParseCallback callback) { 305 public void parsePaymentMethodManifest(String content, ManifestParse Callback callback) {
300 PaymentManifestSection[] manifest = new PaymentManifestSection[1 ]; 306 try {
301 manifest[0] = new PaymentManifestSection(); 307 callback.onPaymentMethodManifestParseSuccess(
302 manifest[0].packageName = "com.bobpay.app"; 308 new URI[] {new URI("https://bobpay.com/app.json")});
303 manifest[0].version = 10; 309 } catch (URISyntaxException e) {
304 // SHA256("01020304050607080900"): 310 assert false;
305 manifest[0].sha256CertFingerprints = new byte[][] {{(byte) 0x9A, (byte) 0x89, 311 }
306 (byte) 0xC6, (byte) 0x8C, (byte) 0x4C, (byte) 0x5E, (byt e) 0x28,
307 (byte) 0xB8, (byte) 0xC4, (byte) 0xA5, (byte) 0x56, (byt e) 0x76,
308 (byte) 0x73, (byte) 0xD4, (byte) 0x62, (byte) 0xFF, (byt e) 0xF5,
309 (byte) 0x15, (byte) 0xDB, (byte) 0x46, (byte) 0x11, (byt e) 0x6F,
310 (byte) 0x99, (byte) 0x00, (byte) 0x62, (byte) 0x4D, (byt e) 0x09,
311 (byte) 0xC4, (byte) 0x74, (byte) 0xF5, (byte) 0x93, (byt e) 0xFB}};
312 callback.onManifestParseSuccess(manifest);
313 } 312 }
314 313
315 @Override 314 @Override
315 public void parseWebAppManifest(String content, ManifestParseCallbac k callback) {
316 WebAppManifestSection[] manifest = new WebAppManifestSection[1];
317 manifest[0] = new WebAppManifestSection();
318 manifest[0].id = "com.bobpay.app";
319 manifest[0].minVersion = 10;
320 // SHA256("01020304050607080900"):
321 manifest[0].fingerprints = new byte[][] {{(byte) 0x9A, (byte) 0x 89, (byte) 0xC6,
322 (byte) 0x8C, (byte) 0x4C, (byte) 0x5E, (byte) 0x28, (byt e) 0xB8,
323 (byte) 0xC4, (byte) 0xA5, (byte) 0x56, (byte) 0x76, (byt e) 0x73,
324 (byte) 0xD4, (byte) 0x62, (byte) 0xFF, (byte) 0xF5, (byt e) 0x15,
325 (byte) 0xDB, (byte) 0x46, (byte) 0x11, (byte) 0x6F, (byt e) 0x99,
326 (byte) 0x00, (byte) 0x62, (byte) 0x4D, (byte) 0x09, (byt e) 0xC4,
327 (byte) 0x74, (byte) 0xF5, (byte) 0x93, (byte) 0xFB}};
328 callback.onWebAppManifestParseSuccess(manifest);
329 }
330
331 @Override
316 public void startUtilityProcess() {} 332 public void startUtilityProcess() {}
317 333
318 @Override 334 @Override
319 public void stopUtilityProcess() {} 335 public void stopUtilityProcess() {}
320 }; 336 };
321 337
322 Set<String> methodNames = new HashSet<>(); 338 Set<String> methodNames = new HashSet<>();
323 methodNames.add("https://bobpay.com"); 339 methodNames.add("https://bobpay.com");
324 PaymentAppCreatedCallback callback = Mockito.mock(PaymentAppCreatedCallb ack.class); 340 PaymentAppCreatedCallback callback = Mockito.mock(PaymentAppCreatedCallb ack.class);
325 341
(...skipping 22 matching lines...) Expand all
348 String expectedAppIdentifier) { 364 String expectedAppIdentifier) {
349 return new Matches(expectedAppIdentifier); 365 return new Matches(expectedAppIdentifier);
350 } 366 }
351 367
352 @Override 368 @Override
353 public boolean matches(PaymentApp app) { 369 public boolean matches(PaymentApp app) {
354 return app.getAppIdentifier().equals(mExpectedAppIdentifier); 370 return app.getAppIdentifier().equals(mExpectedAppIdentifier);
355 } 371 }
356 } 372 }
357 } 373 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698