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

Side by Side Diff: content/public/android/junit/src/org/chromium/content/browser/installedapp/InstalledAppProviderTest.java

Issue 2810373002: InstalledAppProviderImpl: Assert that code is run off the UI thread. (Closed)
Patch Set: Fix spelling of UI. 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
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/installedapp/InstalledAppProviderImpl.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.content.browser.installedapp; 5 package org.chromium.content.browser.installedapp;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.pm.ApplicationInfo; 8 import android.content.pm.ApplicationInfo;
9 import android.content.pm.PackageManager; 9 import android.content.pm.PackageManager;
10 import android.content.pm.PackageManager.NameNotFoundException; 10 import android.content.pm.PackageManager.NameNotFoundException;
11 import android.content.res.AssetManager; 11 import android.content.res.AssetManager;
12 import android.content.res.Resources; 12 import android.content.res.Resources;
13 import android.os.Bundle; 13 import android.os.Bundle;
14 14
15 import org.junit.After;
15 import org.junit.Assert; 16 import org.junit.Assert;
16 import org.junit.Before; 17 import org.junit.Before;
17 import org.junit.Test; 18 import org.junit.Test;
18 import org.junit.runner.RunWith; 19 import org.junit.runner.RunWith;
19
20 import org.robolectric.RuntimeEnvironment; 20 import org.robolectric.RuntimeEnvironment;
21 import org.robolectric.annotation.Config; 21 import org.robolectric.annotation.Config;
22 import org.robolectric.res.builder.DefaultPackageManager; 22 import org.robolectric.res.builder.DefaultPackageManager;
23 23
24 import org.chromium.base.ThreadUtils;
24 import org.chromium.base.test.util.Feature; 25 import org.chromium.base.test.util.Feature;
25 import org.chromium.installedapp.mojom.InstalledAppProvider; 26 import org.chromium.installedapp.mojom.InstalledAppProvider;
26 import org.chromium.installedapp.mojom.RelatedApplication; 27 import org.chromium.installedapp.mojom.RelatedApplication;
27 import org.chromium.testing.local.CustomShadowAsyncTask; 28 import org.chromium.testing.local.CustomShadowAsyncTask;
28 import org.chromium.testing.local.LocalRobolectricTestRunner; 29 import org.chromium.testing.local.LocalRobolectricTestRunner;
29 30
30 import java.net.URI; 31 import java.net.URI;
31 import java.net.URISyntaxException; 32 import java.net.URISyntaxException;
32 import java.util.HashMap; 33 import java.util.HashMap;
33 34
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 for (int i = 0; i < installedRelatedApps.length; i++) { 288 for (int i = 0; i < installedRelatedApps.length; i++) {
288 Assert.assertEquals( 289 Assert.assertEquals(
289 expectedInstalledRelatedApps[i], installedRe latedApps[i]); 290 expectedInstalledRelatedApps[i], installedRe latedApps[i]);
290 } 291 }
291 } 292 }
292 }); 293 });
293 } 294 }
294 295
295 @Before 296 @Before
296 public void setUp() { 297 public void setUp() {
298 // Avoid triggering asserts in InstalledAppProviderImpl that check they are being run off
299 // the UI thread (since this is a single-threaded test).
300 ThreadUtils.setThreadAssertsDisabledForTesting(true);
297 mPackageManager = new FakePackageManager(); 301 mPackageManager = new FakePackageManager();
298 RuntimeEnvironment.setRobolectricPackageManager(mPackageManager); 302 RuntimeEnvironment.setRobolectricPackageManager(mPackageManager);
299 mFrameUrlDelegate = new FakeFrameUrlDelegate(URL_ON_ORIGIN); 303 mFrameUrlDelegate = new FakeFrameUrlDelegate(URL_ON_ORIGIN);
300 mInstalledAppProvider = 304 mInstalledAppProvider =
301 new InstalledAppProviderTestImpl(mFrameUrlDelegate, RuntimeEnvir onment.application); 305 new InstalledAppProviderTestImpl(mFrameUrlDelegate, RuntimeEnvir onment.application);
302 } 306 }
303 307
308 @After
309 public void tearDown() {
310 ThreadUtils.setThreadAssertsDisabledForTesting(false);
311 }
312
304 /** 313 /**
305 * Origin of the page using the API is missing certain parts of the URI. 314 * Origin of the page using the API is missing certain parts of the URI.
306 */ 315 */
307 @Test 316 @Test
308 @Feature({"InstalledApp"}) 317 @Feature({"InstalledApp"})
309 public void testOriginMissingParts() { 318 public void testOriginMissingParts() {
310 RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { 319 RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
311 createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null) }; 320 createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null) };
312 setAssetStatement(PACKAGE_NAME_1, NAMESPACE_WEB, RELATION_HANDLE_ALL_URL S, ORIGIN); 321 setAssetStatement(PACKAGE_NAME_1, NAMESPACE_WEB, RELATION_HANDLE_ALL_URL S, ORIGIN);
313 RelatedApplication[] expectedInstalledRelatedApps = new RelatedApplicati on[] {}; 322 RelatedApplication[] expectedInstalledRelatedApps = new RelatedApplicati on[] {};
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 // Non-installed app. 842 // Non-installed app.
834 manifestRelatedApps = new RelatedApplication[] { 843 manifestRelatedApps = new RelatedApplication[] {
835 createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_2, null) }; 844 createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_2, null) };
836 expectedInstalledRelatedApps = new RelatedApplication[] {}; 845 expectedInstalledRelatedApps = new RelatedApplication[] {};
837 verifyInstalledApps(manifestRelatedApps, expectedInstalledRelatedApps); 846 verifyInstalledApps(manifestRelatedApps, expectedInstalledRelatedApps);
838 // This expectation is based on HMAC_SHA256(salt, packageName encoded in UTF-8), taking the 847 // This expectation is based on HMAC_SHA256(salt, packageName encoded in UTF-8), taking the
839 // low 10 bits of the first two bytes of the result / 100. 848 // low 10 bits of the first two bytes of the result / 100.
840 Assert.assertEquals(5, mInstalledAppProvider.getLastDelayMillis()); 849 Assert.assertEquals(5, mInstalledAppProvider.getLastDelayMillis());
841 } 850 }
842 } 851 }
OLDNEW
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/installedapp/InstalledAppProviderImpl.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698