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

Side by Side Diff: chrome/android/webapk/libs/client/junit/src/org/chromium/webapk/lib/client/WebApkValidatorTest.java

Issue 2896273005: Fix bug in one conditional. Add more apk test files. (Closed)
Patch Set: Fix error in conditional. Add more test files. Created 3 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.webapk.lib.client; 5 package org.chromium.webapk.lib.client;
6 6
7 import static org.junit.Assert.assertEquals; 7 import static org.junit.Assert.assertEquals;
8 import static org.junit.Assert.assertFalse; 8 import static org.junit.Assert.assertFalse;
9 import static org.junit.Assert.assertNull; 9 import static org.junit.Assert.assertNull;
10 import static org.junit.Assert.assertTrue; 10 import static org.junit.Assert.assertTrue;
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 mPackageManager.addPackage(newPackageInfo(WEBAPK_PACKAGE_NAME, signature s, null)); 198 mPackageManager.addPackage(newPackageInfo(WEBAPK_PACKAGE_NAME, signature s, null));
199 199
200 assertNull(WebApkValidator.findWebApkPackage(RuntimeEnvironment.applicat ion, infos)); 200 assertNull(WebApkValidator.findWebApkPackage(RuntimeEnvironment.applicat ion, infos));
201 } 201 }
202 202
203 /** 203 /**
204 * Tests {@link WebApkValidator#isValidWebApk()} for valid comment signed we bapks. 204 * Tests {@link WebApkValidator#isValidWebApk()} for valid comment signed we bapks.
205 */ 205 */
206 @Test 206 @Test
207 public void testIsValidWebApkCommentSigned() { 207 public void testIsValidWebApkCommentSigned() {
208 String[] filenames = {"example.apk", "java-example.apk"}; 208 String[] filenames = {"example.apk", "java-example.apk", "v2-signed-ok.a pk"};
209 String packageName = "com.webapk.a9c419502bb98fcb7"; 209 String packageName = "com.webapk.a9c419502bb98fcb7";
210 Signature[] signature = new Signature[] {new Signature(SIGNATURE_1)}; 210 Signature[] signature = new Signature[] {new Signature(SIGNATURE_1)};
211 211
212 for (String filename : filenames) { 212 for (String filename : filenames) {
213 mPackageManager.removePackage(packageName); 213 mPackageManager.removePackage(packageName);
214 mPackageManager.addPackage( 214 mPackageManager.addPackage(
215 newPackageInfo(packageName, signature, testFilePath(filename ))); 215 newPackageInfo(packageName, signature, testFilePath(filename )));
216 assertTrue(filename + " did not verify", 216 assertTrue(filename + " did not verify",
217 WebApkValidator.isValidWebApk(RuntimeEnvironment.application , packageName)); 217 WebApkValidator.isValidWebApk(RuntimeEnvironment.application , packageName));
218 } 218 }
219 } 219 }
220 220
221 /** 221 /**
222 * Tests {@link WebApkValidator#isValidWebApk()} for failing comment signed webapks. 222 * Tests {@link WebApkValidator#isValidWebApk()} for failing comment signed webapks.
223 * These WebAPKs were modified to fail in specific ways. 223 * These WebAPKs were modified to fail in specific ways.
224 */ 224 */
225 @Test 225 @Test
226 public void testIsValidWebApkCommentSignedFailures() { 226 public void testIsValidWebApkCommentSignedFailures() {
227 String[] filenames = { 227 String[] filenames = {
228 "bad-sig.apk", "bad-utf8-fname.apk", "empty.apk", "extra-len-too -large.apk", 228 "bad-sig.apk", "bad-utf8-fname.apk", "empty.apk", "extra-field-t oo-large.apk",
229 "fcomment-too-large.apk", "no-cd.apk", "no-comment.apk", "no-eoc d.apk", 229 "extra-len-too-large.apk", "fcomment-too-large.apk", "no-cd.apk" , "no-comment.apk",
230 "no-lfh.apk", "not-an.apk", "too-many-metainf.apk", "truncated.a pk", "zeros.apk", 230 "no-eocd.apk", "no-lfh.apk", "not-an.apk", "too-many-metainf.apk ", "truncated.apk",
231 "zeros-at-end.apk", "block-before-first.apk", "block-at-end.apk" , 231 "zeros.apk", "zeros-at-end.apk", "block-before-first.apk", "bloc k-at-end.apk",
232 "block-before-eocd.apk", "block-before-cd.apk", 232 "block-before-eocd.apk", "block-before-cd.apk", "v2-signed-too-l arge.apk",
233 }; 233 };
234 String packageName = "com.webapk.a9c419502bb98fcb7"; 234 String packageName = "com.webapk.a9c419502bb98fcb7";
235 Signature[] signature = new Signature[] {new Signature(SIGNATURE_1)}; 235 Signature[] signature = new Signature[] {new Signature(SIGNATURE_1)};
236 236
237 for (String filename : filenames) { 237 for (String filename : filenames) {
238 mPackageManager.removePackage(packageName); 238 mPackageManager.removePackage(packageName);
239 mPackageManager.addPackage( 239 mPackageManager.addPackage(
240 newPackageInfo(packageName, signature, testFilePath(filename ))); 240 newPackageInfo(packageName, signature, testFilePath(filename )));
241 assertFalse(filename, 241 assertFalse(filename,
242 WebApkValidator.isValidWebApk(RuntimeEnvironment.application , packageName)); 242 WebApkValidator.isValidWebApk(RuntimeEnvironment.application , packageName));
(...skipping 25 matching lines...) Expand all
268 return packageInfo; 268 return packageInfo;
269 } 269 }
270 270
271 // The browser signature is expected to always be the second signature - the first (and any 271 // The browser signature is expected to always be the second signature - the first (and any
272 // additional ones after the second) are ignored. 272 // additional ones after the second) are ignored.
273 private static PackageInfo newPackageInfoWithBrowserSignature( 273 private static PackageInfo newPackageInfoWithBrowserSignature(
274 String packageName, Signature signature) { 274 String packageName, Signature signature) {
275 return newPackageInfo(packageName, new Signature[] {new Signature(""), s ignature}, null); 275 return newPackageInfo(packageName, new Signature[] {new Signature(""), s ignature}, null);
276 } 276 }
277 } 277 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698