null); // optionsIn
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
null); // optionsIn
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
null); // optionsIn
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
null); // optionsIn
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
UserHandle.USER_SYSTEM);
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
UserHandle.USER_SYSTEM);
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
AccountManagerServiceTestFixtures.ACCOUNT_STATUS_TOKEN);
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
AccountManagerServiceTestFixtures.ACCOUNT_STATUS_TOKEN);
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
null);
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
"testPackage"); // opPackageName
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
"testPackage"); // opPackageName
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
"testPackage"); // opPackageName
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
-
}
@SmallTest
"testPackage"); // opPackageName
fail("SecurityException expected. But no exception was thrown.");
} catch (SecurityException e) {
- } catch(Exception e){
- fail(String.format("Expect SecurityException, but got %s.", e));
+ // SecurityException is expected.
}
}
UserHandle.USER_SYSTEM);
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
UserHandle.USER_SYSTEM);
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
UserHandle.USER_SYSTEM);
fail("SecurityException expected. But no exception was thrown.");
} catch (SecurityException e) {
- } catch(Exception e){
- fail(String.format("Expect SecurityException, but got %s.", e));
+ // SecurityException is expected.
}
}
"authTokenType");
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
null); // authTokenType
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
createGetAuthTokenOptions());
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
createGetAuthTokenOptions());
fail("SecurityException expected. But no exception was thrown.");
} catch (SecurityException e) {
- } catch(Exception e){
- fail(String.format("Expect SecurityException, but got %s.", e));
+ // SecurityException is expected.
}
}
UserHandle.USER_SYSTEM);
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
UserHandle.USER_SYSTEM);
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
UserHandle.USER_SYSTEM);
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
UserHandle.USER_SYSTEM);
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
new Bundle()); // options
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
new Bundle()); // options
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
false); // expectActivityLaunch
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
false); // expectActivityLaunch
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
- } catch(Exception e){
- fail(String.format("Expect IllegalArgumentException, but got %s.", e));
+ // IllegalArgumentException is expected.
}
}
false); // expectActivityLaunch
fail("SecurityException expected. But no exception was thrown.");
} catch (SecurityException e) {
- } catch(Exception e){
- fail(String.format("Expect SecurityException, but got %s.", e));
+ // SecurityException is expected.
}
}
result.getString(AccountManager.KEY_ACCOUNT_TYPE));
}
+ @SmallTest
+ public void testGetAccountsByFeaturesWithNullResponse() throws Exception {
+ unlockSystemUser();
+ try {
+ mAms.getAccountsByFeatures(
+ null, // response
+ AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1,
+ AccountManagerServiceTestFixtures.ACCOUNT_FEATURES,
+ "testpackage"); // opPackageName
+ fail("IllegalArgumentException expected. But no exception was thrown.");
+ } catch (IllegalArgumentException e) {
+ // IllegalArgumentException is expected.
+ }
+ }
+
+ @SmallTest
+ public void testGetAccountsByFeaturesWithNullAccountType() throws Exception {
+ unlockSystemUser();
+ try {
+ mAms.getAccountsByFeatures(
+ mMockAccountManagerResponse, // response
+ null, // accountType
+ AccountManagerServiceTestFixtures.ACCOUNT_FEATURES,
+ "testpackage"); // opPackageName
+ fail("IllegalArgumentException expected. But no exception was thrown.");
+ } catch (IllegalArgumentException e) {
+ // IllegalArgumentException is expected.
+ }
+ }
+
+ @SmallTest
+ public void testGetAccountsByFeaturesAccountNotVisible() throws Exception {
+ unlockSystemUser();
+
+ when(mMockContext.checkCallingOrSelfPermission(anyString())).thenReturn(
+ PackageManager.PERMISSION_DENIED);
+ when(mMockPackageManager.checkSignatures(anyInt(), anyInt()))
+ .thenReturn(PackageManager.SIGNATURE_NO_MATCH);
+
+ final CountDownLatch latch = new CountDownLatch(1);
+ Response response = new Response(latch, mMockAccountManagerResponse);
+ mAms.getAccountsByFeatures(
+ response, // response
+ AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1, // accountType
+ AccountManagerServiceTestFixtures.ACCOUNT_FEATURES,
+ "testpackage"); // opPackageName
+ waitForLatch(latch);
+
+ verify(mMockAccountManagerResponse).onResult(mBundleCaptor.capture());
+ Bundle result = mBundleCaptor.getValue();
+ Account[] accounts = (Account[]) result.getParcelableArray(AccountManager.KEY_ACCOUNTS);
+ assertTrue(accounts.length == 0);
+ }
+
+ @SmallTest
+ public void testGetAccountsByFeaturesNullFeatureReturnsAllAccounts() throws Exception {
+ unlockSystemUser();
+
+ mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null);
+ mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE, "p12", null);
+
+ final CountDownLatch latch = new CountDownLatch(1);
+ Response response = new Response(latch, mMockAccountManagerResponse);
+ mAms.getAccountsByFeatures(
+ response, // response
+ AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1, // accountType
+ null, // features
+ "testpackage"); // opPackageName
+ waitForLatch(latch);
+
+ verify(mMockAccountManagerResponse).onResult(mBundleCaptor.capture());
+ Bundle result = mBundleCaptor.getValue();
+ Account[] accounts = (Account[]) result.getParcelableArray(AccountManager.KEY_ACCOUNTS);
+ Arrays.sort(accounts, new AccountSorter());
+ assertEquals(2, accounts.length);
+ assertEquals(AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE, accounts[0]);
+ assertEquals(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, accounts[1]);
+ }
+
+ @SmallTest
+ public void testGetAccountsByFeaturesReturnsAccountsWithFeaturesOnly() throws Exception {
+ unlockSystemUser();
+
+ mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null);
+ mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE, "p12", null);
+
+ final CountDownLatch latch = new CountDownLatch(1);
+ Response response = new Response(latch, mMockAccountManagerResponse);
+ mAms.getAccountsByFeatures(
+ response, // response
+ AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1, // accountType
+ AccountManagerServiceTestFixtures.ACCOUNT_FEATURES,
+ "testpackage"); // opPackageName
+ waitForLatch(latch);
+
+ verify(mMockAccountManagerResponse).onResult(mBundleCaptor.capture());
+ Bundle result = mBundleCaptor.getValue();
+ Account[] accounts = (Account[]) result.getParcelableArray(AccountManager.KEY_ACCOUNTS);
+ assertEquals(1, accounts.length);
+ assertEquals(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, accounts[0]);
+ }
+
+ @SmallTest
+ public void testGetAccountsByFeaturesError() throws Exception {
+ unlockSystemUser();
+
+ mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null);
+ mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_ERROR, "p12", null);
+
+ final CountDownLatch latch = new CountDownLatch(1);
+ Response response = new Response(latch, mMockAccountManagerResponse);
+ mAms.getAccountsByFeatures(
+ response, // response
+ AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1, // accountType
+ AccountManagerServiceTestFixtures.ACCOUNT_FEATURES,
+ "testpackage"); // opPackageName
+ waitForLatch(latch);
+
+ verify(mMockAccountManagerResponse).onError(
+ eq(AccountManager.ERROR_CODE_INVALID_RESPONSE), anyString());
+ verify(mMockAccountManagerResponse, never()).onResult(any(Bundle.class));
+ }
+
private void waitForLatch(CountDownLatch latch) {
try {
latch.await(LATCH_TIMEOUT_MS, TimeUnit.MILLISECONDS);