diff options
author | Adam Connors <adamconnors@google.com> | 2014-01-09 10:42:56 +0000 |
---|---|---|
committer | Adam Connors <adamconnors@google.com> | 2014-02-06 10:07:19 +0000 |
commit | 776c555d954d9494069f786785877c08add27327 (patch) | |
tree | 1cad8070340a8e2924efd9ca371d6c5098cfcfdc /services/tests | |
parent | cb1b23b5e600abe542e3374b66c2be7976fccd72 (diff) | |
download | frameworks_base-776c555d954d9494069f786785877c08add27327.zip frameworks_base-776c555d954d9494069f786785877c08add27327.tar.gz frameworks_base-776c555d954d9494069f786785877c08add27327.tar.bz2 |
Extend DeviceOwner concept to accommodate ProfileOwners
ProfileOwners, like DeviceOwners, are Device Admins that have
additional priviledges. ProfileOwners however are scoped per
user.
Change-Id: I1e22c85878e0672121e6ebbe97fca38591f992b2
Diffstat (limited to 'services/tests')
-rw-r--r-- | services/tests/servicestests/src/com/android/server/devicepolicy/DeviceOwnerTest.java | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DeviceOwnerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DeviceOwnerTest.java new file mode 100644 index 0000000..f913b97 --- /dev/null +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DeviceOwnerTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.devicepolicy; + +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +/** + * Tests for the DeviceOwner object that saves & loads device and policy owner information. + * run this test with: + * make -j FrameworksServicesTests + * runtest --path frameworks/base/services/tests/servicestests/ \ + * src/com/android/server/devicepolicy/DeviceOwnerTest.java + */ +public class DeviceOwnerTest extends AndroidTestCase { + + private ByteArrayInputStream mInputStreamForTest; + private ByteArrayOutputStream mOutputStreamForTest = new ByteArrayOutputStream(); + + @SmallTest + public void testDeviceOwnerOnly() throws Exception { + DeviceOwner out = new DeviceOwner(null, mOutputStreamForTest); + out.setDeviceOwner("some.device.owner.package", "owner"); + out.writeOwnerFile(); + + mInputStreamForTest = new ByteArrayInputStream(mOutputStreamForTest.toByteArray()); + DeviceOwner in = new DeviceOwner(mInputStreamForTest, null); + in.readOwnerFile(); + + assertEquals("some.device.owner.package", in.getDeviceOwnerPackageName()); + assertEquals("owner", in.getDeviceOwnerName()); + assertNull(in.getProfileOwnerPackageName(1)); + } + + @SmallTest + public void testProfileOwnerOnly() throws Exception { + DeviceOwner out = new DeviceOwner(null, mOutputStreamForTest); + out.setProfileOwner("some.profile.owner.package", "some-company", 1); + out.writeOwnerFile(); + + mInputStreamForTest = new ByteArrayInputStream(mOutputStreamForTest.toByteArray()); + DeviceOwner in = new DeviceOwner(mInputStreamForTest, null); + in.readOwnerFile(); + + assertNull(in.getDeviceOwnerPackageName()); + assertNull(in.getDeviceOwnerName()); + assertEquals("some.profile.owner.package", in.getProfileOwnerPackageName(1)); + assertEquals("some-company", in.getProfileOwnerName(1)); + } + + @SmallTest + public void testDeviceAndProfileOwners() throws Exception { + DeviceOwner out = new DeviceOwner(null, mOutputStreamForTest); + out.setDeviceOwner("some.device.owner.package", "owner"); + out.setProfileOwner("some.profile.owner.package", "some-company", 1); + out.setProfileOwner("some.other.profile.owner", "some-other-company", 2); + out.writeOwnerFile(); + + mInputStreamForTest = new ByteArrayInputStream(mOutputStreamForTest.toByteArray()); + + DeviceOwner in = new DeviceOwner(mInputStreamForTest, null); + in.readOwnerFile(); + + assertEquals("some.device.owner.package", in.getDeviceOwnerPackageName()); + assertEquals("owner", in.getDeviceOwnerName()); + assertEquals("some.profile.owner.package", in.getProfileOwnerPackageName(1)); + assertEquals("some-company", in.getProfileOwnerName(1)); + assertEquals("some.other.profile.owner", in.getProfileOwnerPackageName(2)); + assertEquals("some-other-company", in.getProfileOwnerName(2)); + } +}
\ No newline at end of file |