summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBrett Chabot <brettchabot@android.com>2010-06-16 14:42:51 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-06-16 14:42:51 -0700
commit83ea9e395e86ca2d12d822609ca2a8b35b78cca9 (patch)
tree87a79d8ed244f02948877596ba511f3af4dd6e06 /tests
parentbd580127fca2797ba1a0f6653fe4cb2fd427ec83 (diff)
parent685fcf364b84d5ac911ae9cbbc4fec99f36cbd48 (diff)
downloadframeworks_base-83ea9e395e86ca2d12d822609ca2a8b35b78cca9.zip
frameworks_base-83ea9e395e86ca2d12d822609ca2a8b35b78cca9.tar.gz
frameworks_base-83ea9e395e86ca2d12d822609ca2a8b35b78cca9.tar.bz2
am 685fcf36: am c95812e6: Merge "Move out all framework-tests classes." into gingerbread
Merge commit '685fcf364b84d5ac911ae9cbbc4fec99f36cbd48' * commit '685fcf364b84d5ac911ae9cbbc4fec99f36cbd48': Move out all framework-tests classes.
Diffstat (limited to 'tests')
-rw-r--r--tests/framework-tests/Android.mk1
-rw-r--r--tests/framework-tests/README5
-rw-r--r--tests/framework-tests/src/Android.mk10
-rw-r--r--tests/framework-tests/src/android/test/FrameworkTests.java40
-rw-r--r--tests/framework-tests/src/android/text/PackedIntVectorTest.java159
-rw-r--r--tests/framework-tests/src/com/android/internal/http/multipart/MultipartTest.java118
-rw-r--r--tests/framework-tests/src/com/android/internal/os/LoggingPrintStreamTest.java184
-rw-r--r--tests/framework-tests/src/com/android/internal/policy/impl/LockPatternKeyguardViewTest.java350
8 files changed, 0 insertions, 867 deletions
diff --git a/tests/framework-tests/Android.mk b/tests/framework-tests/Android.mk
deleted file mode 100644
index 5053e7d..0000000
--- a/tests/framework-tests/Android.mk
+++ /dev/null
@@ -1 +0,0 @@
-include $(call all-subdir-makefiles)
diff --git a/tests/framework-tests/README b/tests/framework-tests/README
deleted file mode 100644
index 7b46b25..0000000
--- a/tests/framework-tests/README
+++ /dev/null
@@ -1,5 +0,0 @@
-This package contains tests which need to access package-private members in the framework code.
-To do this, the tests must be loaded in the same class loader as the classes which they are
-testing. This package is loaded in the boot classpath.
-
-Run these tests via AndroidTests -> FrameworkTests.
diff --git a/tests/framework-tests/src/Android.mk b/tests/framework-tests/src/Android.mk
deleted file mode 100644
index f537b52..0000000
--- a/tests/framework-tests/src/Android.mk
+++ /dev/null
@@ -1,10 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(call all-subdir-java-files)
-
-LOCAL_MODULE := framework-tests
-
-LOCAL_JAVA_LIBRARIES := android.policy android.test.runner
-
-include $(BUILD_JAVA_LIBRARY)
diff --git a/tests/framework-tests/src/android/test/FrameworkTests.java b/tests/framework-tests/src/android/test/FrameworkTests.java
deleted file mode 100644
index cb3f493..0000000
--- a/tests/framework-tests/src/android/test/FrameworkTests.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2007 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 android.test;
-
-import com.android.internal.os.LoggingPrintStreamTest;
-import junit.framework.TestSuite;
-import com.android.internal.http.multipart.MultipartTest;
-import com.android.internal.policy.impl.LockPatternKeyguardViewTest;
-
-/**
- * Tests that are loaded in the boot classpath along with the Android framework
- * classes. This enables you to access package-private members in the framework
- * classes; doing so is not possible when the test classes are loaded in an
- * application classloader.
- */
-public class FrameworkTests {
- public static TestSuite suite() {
- TestSuite suite = new TestSuite(FrameworkTests.class.getName());
-
- suite.addTestSuite(MultipartTest.class);
- suite.addTestSuite(LoggingPrintStreamTest.class);
- suite.addTestSuite(LockPatternKeyguardViewTest.class);
-
- return suite;
- }
-}
diff --git a/tests/framework-tests/src/android/text/PackedIntVectorTest.java b/tests/framework-tests/src/android/text/PackedIntVectorTest.java
deleted file mode 100644
index 78cdee9..0000000
--- a/tests/framework-tests/src/android/text/PackedIntVectorTest.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright (C) 2007 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 android.text;
-
-import android.text.PackedIntVector;
-import junit.framework.TestCase;
-
-/**
- * PackedIntVectorTest tests the features of android.util.PackedIntVector.
- */
-public class PackedIntVectorTest extends TestCase {
-
- public void testBasic() throws Exception {
- for (int width = 0; width < 10; width++) {
- PackedIntVector p = new PackedIntVector(width);
- int[] ins = new int[width];
-
- for (int height = width * 2; height < width * 4; height++) {
- assertEquals(p.width(), width);
-
- // Test adding rows.
-
- for (int i = 0; i < height; i++) {
- int at;
-
- if (i % 2 == 0) {
- at = i;
- } else {
- at = p.size() - i;
- }
-
- for (int j = 0; j < width; j++) {
- ins[j] = i + j;
- }
-
- if (i == height / 2) {
- p.insertAt(at, null);
- } else {
- p.insertAt(at, ins);
- }
-
- assertEquals(p.size(), i + 1);
-
- for (int j = 0; j < width; j++) {
- if (i == height / 2) {
- assertEquals(0, p.getValue(at, j));
- } else {
- assertEquals(p.getValue(at, j), i + j);
- }
- }
- }
-
- // Test setting values.
-
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- p.setValue(i, j, i * j);
-
- assertEquals(p.getValue(i, j), i * j);
- }
- }
-
- // Test offsetting values.
-
- for (int j = 0; j < width; j++) {
- p.adjustValuesBelow(j * 2, j, j + 27);
- }
-
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- int expect = i * j;
-
- if (i >= j * 2) {
- expect += j + 27;
- }
-
- assertEquals(p.getValue(i, j), expect);
- }
- }
-
- for (int j = 0; j < width; j++) {
- p.adjustValuesBelow(j, j, j * j + 14);
- }
-
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- int expect = i * j;
-
- if (i >= j * 2) {
- expect += j + 27;
- }
- if (i >= j) {
- expect += j * j + 14;
- }
-
- assertEquals(p.getValue(i, j), expect);
- }
- }
-
- // Test undoing offsets.
-
- for (int j = 0; j < width; j++) {
- p.adjustValuesBelow(j * 2, j, -(j + 27));
- p.adjustValuesBelow(j, j, -(j * j + 14));
- }
-
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- assertEquals(p.getValue(i, j), i * j);
- }
- }
-
- // Test deleting rows.
-
- while (p.size() > 0) {
- int osize = p.size();
- int del = osize / 3;
-
- if (del == 0) {
- del = 1;
- }
-
- int at = (osize - del) / 2;
- p.deleteAt(at, del);
-
- assertEquals(p.size(), osize - del);
-
- for (int i = 0; i < at; i++) {
- for (int j = 0; j < width; j++) {
- assertEquals(p.getValue(i, j), i * j);
- }
- }
-
- for (int i = at; i < p.size(); i++) {
- for (int j = 0; j < width; j++) {
- assertEquals(p.getValue(i, j), (i + height - p.size()) * j);
- }
- }
- }
-
- assertEquals(0, p.size());
- }
- }
- }
-}
diff --git a/tests/framework-tests/src/com/android/internal/http/multipart/MultipartTest.java b/tests/framework-tests/src/com/android/internal/http/multipart/MultipartTest.java
deleted file mode 100644
index 32e13a7..0000000
--- a/tests/framework-tests/src/com/android/internal/http/multipart/MultipartTest.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (C) 2008 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.internal.http.multipart;
-
-import junit.framework.TestCase;
-import org.apache.http.Header;
-import org.apache.http.util.EncodingUtils;
-
-import java.io.BufferedWriter;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileWriter;
-
-public class MultipartTest extends TestCase {
-
- public void testParts() throws Exception {
- StringBuffer filebuffer = new StringBuffer();
- String filepartStr = "this is file part";
- filebuffer.append(filepartStr);
- File upload = File.createTempFile("Multipart", "test");
-
- FileWriter outFile = new FileWriter(upload);
- BufferedWriter out = new BufferedWriter(outFile);
- try {
- out.write(filebuffer.toString());
- out.flush();
- } finally {
- out.close();
- }
-
- Part[] parts = new Part[3];
- parts[0] = new StringPart("stringpart", "PART1!!");
- parts[1] = new FilePart(upload.getName(), upload);
- parts[2] = new StringPart("stringpart", "PART2!!");
-
- MultipartEntity me = new MultipartEntity(parts);
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- me.writeTo(os);
- Header h = me.getContentType();
- String boundry = EncodingUtils.getAsciiString(me.getMultipartBoundary());
- StringBuffer contentType = new StringBuffer("multipart/form-data");
- contentType.append("; boundary=");
- contentType.append(boundry);
- assertEquals("Multipart content type error", contentType.toString(), h.getValue());
- final String CRLF = "\r\n";
- StringBuffer output = new StringBuffer();
-
- output.append("--");
- output.append(boundry);
- output.append(CRLF);
-
- output.append("Content-Disposition: form-data; name=\"stringpart\"");
- output.append(CRLF);
- output.append("Content-Type: text/plain; charset=US-ASCII");
- output.append(CRLF);
- output.append("Content-Transfer-Encoding: 8bit");
- output.append(CRLF);
- output.append(CRLF);
- output.append("PART1!!");
- output.append(CRLF);
-
- output.append("--");
- output.append(boundry);
- output.append(CRLF);
-
- output.append("Content-Disposition: form-data; name=\"");
- output.append(upload.getName());
- output.append("\"; filename=\"");
- output.append(upload.getName());
- output.append("\"");
-
- output.append(CRLF);
- output.append("Content-Type: application/octet-stream; charset=ISO-8859-1");
- output.append(CRLF);
- output.append("Content-Transfer-Encoding: binary");
- output.append(CRLF);
- output.append(CRLF);
- output.append(filepartStr);
- output.append(CRLF);
-
- output.append("--");
- output.append(boundry);
- output.append(CRLF);
-
- output.append("Content-Disposition: form-data; name=\"stringpart\"");
- output.append(CRLF);
- output.append("Content-Type: text/plain; charset=US-ASCII");
- output.append(CRLF);
- output.append("Content-Transfer-Encoding: 8bit");
- output.append(CRLF);
- output.append(CRLF);
- output.append("PART2!!");
- output.append(CRLF);
-
- output.append("--");
- output.append(boundry);
- output.append("--");
- output.append(CRLF);
- // System.out.print(output.toString());
- assertEquals("Multipart content error", output.toString(), os.toString());
-
- // System.out.print(os.toString());
- }
-}
diff --git a/tests/framework-tests/src/com/android/internal/os/LoggingPrintStreamTest.java b/tests/framework-tests/src/com/android/internal/os/LoggingPrintStreamTest.java
deleted file mode 100644
index 4d016d1..0000000
--- a/tests/framework-tests/src/com/android/internal/os/LoggingPrintStreamTest.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Copyright (C) 2008 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.internal.os;
-
-import junit.framework.TestCase;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-public class LoggingPrintStreamTest extends TestCase {
-
- TestPrintStream out = new TestPrintStream();
-
- public void testPrintException() {
- @SuppressWarnings("ThrowableInstanceNeverThrown")
- Throwable t = new Throwable("Ignore me.");
-
- StringWriter sout = new StringWriter();
- t.printStackTrace(new PrintWriter(sout));
-
- t.printStackTrace(out);
- // t.printStackTrace();
-
- String[] lines = sout.toString().split("\\n");
- assertEquals(Arrays.asList(lines), out.lines);
- }
-
- public void testPrintObject() {
- Object o = new Object();
- out.print(4);
- out.print(o);
- out.print(2);
- out.flush();
- assertEquals(Arrays.asList("4" + o + "2"), out.lines);
- }
-
- public void testPrintlnObject() {
- Object o = new Object();
- out.print(4);
- out.println(o);
- out.print(2);
- out.flush();
- assertEquals(Arrays.asList("4" + o, "2"), out.lines);
- }
-
- public void testPrintf() {
- out.printf("Name: %s\nEmployer: %s", "Bob", "Google");
- assertEquals(Arrays.asList("Name: Bob"), out.lines);
- out.flush();
- assertEquals(Arrays.asList("Name: Bob", "Employer: Google"), out.lines);
- }
-
- public void testPrintInt() {
- out.print(4);
- out.print(2);
- assertTrue(out.lines.isEmpty());
- out.flush();
- assertEquals(Collections.singletonList("42"), out.lines);
- }
-
- public void testPrintlnInt() {
- out.println(4);
- out.println(2);
- assertEquals(Arrays.asList("4", "2"), out.lines);
- }
-
- public void testPrintCharArray() {
- out.print("Foo\nBar\nTee".toCharArray());
- assertEquals(Arrays.asList("Foo", "Bar"), out.lines);
- out.flush();
- assertEquals(Arrays.asList("Foo", "Bar", "Tee"), out.lines);
- }
-
- public void testPrintString() {
- out.print("Foo\nBar\nTee");
- assertEquals(Arrays.asList("Foo", "Bar"), out.lines);
- out.flush();
- assertEquals(Arrays.asList("Foo", "Bar", "Tee"), out.lines);
- }
-
- public void testPrintlnCharArray() {
- out.println("Foo\nBar\nTee".toCharArray());
- assertEquals(Arrays.asList("Foo", "Bar", "Tee"), out.lines);
- }
-
- public void testPrintlnString() {
- out.println("Foo\nBar\nTee");
- assertEquals(Arrays.asList("Foo", "Bar", "Tee"), out.lines);
- }
-
- public void testPrintlnStringWithBufferedData() {
- out.print(5);
- out.println("Foo\nBar\nTee");
- assertEquals(Arrays.asList("5Foo", "Bar", "Tee"), out.lines);
- }
-
- public void testAppend() {
- out.append("Foo\n")
- .append('4')
- .append('\n')
- .append("Bar", 1, 2)
- .append('\n');
- assertEquals(Arrays.asList("Foo", "4", "a"), out.lines);
- }
-
- public void testMultiByteCharactersSpanningBuffers() throws Exception {
- // assume 3*1000 bytes won't fit in LoggingPrintStream's internal buffer
- StringBuilder builder = new StringBuilder();
- for (int i = 0; i < 1000; i++) {
- builder.append("\u20AC"); // a Euro character; 3 bytes in UTF-8
- }
- String expected = builder.toString();
-
- out.write(expected.getBytes("UTF-8"));
- out.flush();
- assertEquals(Arrays.asList(expected), out.lines);
- }
-
- public void testWriteOneByteAtATimeMultibyteCharacters() throws Exception {
- String expected = " \u20AC \u20AC \u20AC \u20AC ";
- for (byte b : expected.getBytes()) {
- out.write(b);
- }
- out.flush();
- assertEquals(Arrays.asList(expected), out.lines);
- }
-
- public void testWriteByteArrayAtATimeMultibyteCharacters() throws Exception {
- String expected = " \u20AC \u20AC \u20AC \u20AC ";
- out.write(expected.getBytes());
- out.flush();
- assertEquals(Arrays.asList(expected), out.lines);
- }
-
- public void testWriteWithOffsetsMultibyteCharacters() throws Exception {
- String expected = " \u20AC \u20AC \u20AC \u20AC ";
- byte[] bytes = expected.getBytes();
- int i = 0;
- while (i < bytes.length - 5) {
- out.write(bytes, i, 5);
- i += 5;
- }
- out.write(bytes, i, bytes.length - i);
- out.flush();
- assertEquals(Arrays.asList(expected), out.lines);
- }
-
- public void testWriteFlushesOnNewlines() throws Exception {
- String a = " \u20AC \u20AC ";
- String b = " \u20AC \u20AC ";
- String c = " ";
- String toWrite = a + "\n" + b + "\n" + c;
- out.write(toWrite.getBytes());
- out.flush();
- assertEquals(Arrays.asList(a, b, c), out.lines);
- }
-
- static class TestPrintStream extends LoggingPrintStream {
-
- final List<String> lines = new ArrayList<String>();
-
- protected void log(String line) {
- lines.add(line);
- }
- }
-}
diff --git a/tests/framework-tests/src/com/android/internal/policy/impl/LockPatternKeyguardViewTest.java b/tests/framework-tests/src/com/android/internal/policy/impl/LockPatternKeyguardViewTest.java
deleted file mode 100644
index 1e57bd2..0000000
--- a/tests/framework-tests/src/com/android/internal/policy/impl/LockPatternKeyguardViewTest.java
+++ /dev/null
@@ -1,350 +0,0 @@
-/*
- * Copyright (C) 2008 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.internal.policy.impl;
-
-import android.content.Context;
-import com.android.internal.telephony.IccCard;
-import android.content.res.Configuration;
-import android.test.AndroidTestCase;
-import android.view.View;
-import android.view.KeyEvent;
-import com.android.internal.widget.LockPatternUtils;
-import com.google.android.collect.Lists;
-
-import java.util.List;
-
-/**
- * Tests for {@link com.android.internal.policy.impl.LockPatternKeyguardView},
- * which handles the management of screens while the keyguard is showing.
- */
-public class LockPatternKeyguardViewTest extends AndroidTestCase {
- private MockUpdateMonitor mUpdateMonitor;
- private LockPatternUtils mLockPatternUtils;
- private TestableLockPatternKeyguardView mLPKV;
- private MockKeyguardCallback mKeyguardViewCallback;
-
- private static class MockUpdateMonitor extends KeyguardUpdateMonitor {
-
- public IccCard.State simState = IccCard.State.READY;
-
- private MockUpdateMonitor(Context context) {
- super(context);
- }
-
- @Override
- public IccCard.State getSimState() {
- return simState;
- }
- }
-
- private static class MockLockPatternUtils extends LockPatternUtils {
- boolean isLockPatternEnabled = true;
- public boolean isPermanentlyLocked = false;
-
- public MockLockPatternUtils() {
- super(null);
- }
-
- @Override
- public boolean isLockPatternEnabled() {
- return isLockPatternEnabled;
- }
-
- @Override
- public void setLockPatternEnabled(boolean lockPatternEnabled) {
- isLockPatternEnabled = lockPatternEnabled;
- }
-
- @Override
- public boolean isPermanentlyLocked() {
- return isPermanentlyLocked;
- }
-
- public void setPermanentlyLocked(boolean permanentlyLocked) {
- isPermanentlyLocked = permanentlyLocked;
- }
- }
-
- private static class MockKeyguardScreen extends View implements KeyguardScreen {
-
- private int mOnPauseCount = 0;
- private int mOnResumeCount = 0;
- private int mCleanupCount = 0;
-
- private MockKeyguardScreen(Context context) {
- super(context);
- setFocusable(true);
- }
-
- /** {@inheritDoc} */
- public boolean needsInput() {
- return false;
- }
-
- /** {@inheritDoc} */
- public void onPause() {
- mOnPauseCount++;
- }
-
- /** {@inheritDoc} */
- public void onResume() {
- mOnResumeCount++;
- }
-
- /** {@inheritDoc} */
- public void cleanUp() {
- mCleanupCount++;
- }
-
- public int getOnPauseCount() {
- return mOnPauseCount;
- }
-
- public int getOnResumeCount() {
- return mOnResumeCount;
- }
-
- public int getCleanupCount() {
- return mCleanupCount;
- }
- }
-
- /**
- * Allows us to inject the lock and unlock views to simulate their behavior
- * and detect their creation.
- */
- private static class TestableLockPatternKeyguardView extends LockPatternKeyguardView {
- private List<MockKeyguardScreen> mInjectedLockScreens;
- private List<MockKeyguardScreen> mInjectedUnlockScreens;
-
-
-
- private TestableLockPatternKeyguardView(Context context, KeyguardUpdateMonitor updateMonitor,
- LockPatternUtils lockPatternUtils, KeyguardWindowController controller) {
- super(context, updateMonitor, lockPatternUtils, controller);
- }
-
- @Override
- View createLockScreen() {
- final MockKeyguardScreen newView = new MockKeyguardScreen(getContext());
- if (mInjectedLockScreens == null) mInjectedLockScreens = Lists.newArrayList();
- mInjectedLockScreens.add(newView);
- return newView;
- }
-
- @Override
- View createUnlockScreenFor(UnlockMode unlockMode) {
- final MockKeyguardScreen newView = new MockKeyguardScreen(getContext());
- if (mInjectedUnlockScreens == null) mInjectedUnlockScreens = Lists.newArrayList();
- mInjectedUnlockScreens.add(newView);
- return newView;
- }
-
- public List<MockKeyguardScreen> getInjectedLockScreens() {
- return mInjectedLockScreens;
- }
-
- public List<MockKeyguardScreen> getInjectedUnlockScreens() {
- return mInjectedUnlockScreens;
- }
- }
-
- private static class MockKeyguardCallback implements KeyguardViewCallback {
-
- private int mPokeWakelockCount = 0;
- private int mKeyguardDoneCount = 0;
-
- public void pokeWakelock() {
- mPokeWakelockCount++;
- }
-
- public void pokeWakelock(int millis) {
- mPokeWakelockCount++;
- }
-
- public void keyguardDone(boolean authenticated) {
- mKeyguardDoneCount++;
- }
-
- public void keyguardDoneDrawing() {
-
- }
-
- public int getPokeWakelockCount() {
- return mPokeWakelockCount;
- }
-
- public int getKeyguardDoneCount() {
- return mKeyguardDoneCount;
- }
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mUpdateMonitor = new MockUpdateMonitor(getContext());
- mLockPatternUtils = new MockLockPatternUtils();
-
- mLPKV = new TestableLockPatternKeyguardView(getContext(), mUpdateMonitor,
- mLockPatternUtils, new KeyguardWindowController() {
- public void setNeedsInput(boolean needsInput) {
- }
- });
- mKeyguardViewCallback = new MockKeyguardCallback();
- mLPKV.setCallback(mKeyguardViewCallback);
- }
-
- public void testStateAfterCreatedWhileScreenOff() {
-
- assertEquals(1, mLPKV.getInjectedLockScreens().size());
- assertEquals(1, mLPKV.getInjectedUnlockScreens().size());
-
- MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0);
- MockKeyguardScreen unlockScreen = mLPKV.getInjectedUnlockScreens().get(0);
-
- assertEquals(0, lockScreen.getOnPauseCount());
- assertEquals(0, lockScreen.getOnResumeCount());
- assertEquals(0, lockScreen.getCleanupCount());
-
- assertEquals(0, unlockScreen.getOnPauseCount());
- assertEquals(0, unlockScreen.getOnResumeCount());
- assertEquals(0, unlockScreen.getCleanupCount());
-
- assertEquals(0, mKeyguardViewCallback.getPokeWakelockCount());
- assertEquals(0, mKeyguardViewCallback.getKeyguardDoneCount());
- }
-
- public void testWokenByNonMenuKey() {
- mLPKV.wakeWhenReadyTq(0);
-
- // should have poked the wakelock to turn on the screen
- assertEquals(1, mKeyguardViewCallback.getPokeWakelockCount());
-
- // shouldn't be any additional views created
- assertEquals(1, mLPKV.getInjectedLockScreens().size());
- assertEquals(1, mLPKV.getInjectedUnlockScreens().size());
- MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0);
- MockKeyguardScreen unlockScreen = mLPKV.getInjectedUnlockScreens().get(0);
-
- // lock screen should be only visible one
- assertEquals(View.VISIBLE, lockScreen.getVisibility());
- assertEquals(View.GONE, unlockScreen.getVisibility());
-
- // on resume not called until screen turns on
- assertEquals(0, lockScreen.getOnPauseCount());
- assertEquals(0, lockScreen.getOnResumeCount());
- assertEquals(0, lockScreen.getCleanupCount());
-
- assertEquals(0, unlockScreen.getOnPauseCount());
- assertEquals(0, unlockScreen.getOnResumeCount());
- assertEquals(0, unlockScreen.getCleanupCount());
-
- // simulate screen turning on
- mLPKV.onScreenTurnedOn();
-
- assertEquals(0, lockScreen.getOnPauseCount());
- assertEquals(1, lockScreen.getOnResumeCount());
- assertEquals(0, lockScreen.getCleanupCount());
-
- assertEquals(0, unlockScreen.getOnPauseCount());
- assertEquals(0, unlockScreen.getOnResumeCount());
- assertEquals(0, unlockScreen.getCleanupCount());
- }
-
- public void testWokenByMenuKeyWhenPatternSet() {
- assertEquals(true, mLockPatternUtils.isLockPatternEnabled());
-
- mLPKV.wakeWhenReadyTq(KeyEvent.KEYCODE_MENU);
-
- // should have poked the wakelock to turn on the screen
- assertEquals(1, mKeyguardViewCallback.getPokeWakelockCount());
-
- // shouldn't be any additional views created
- assertEquals(1, mLPKV.getInjectedLockScreens().size());
- assertEquals(1, mLPKV.getInjectedUnlockScreens().size());
- MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0);
- MockKeyguardScreen unlockScreen = mLPKV.getInjectedUnlockScreens().get(0);
-
- // unlock screen should be only visible one
- assertEquals(View.GONE, lockScreen.getVisibility());
- assertEquals(View.VISIBLE, unlockScreen.getVisibility());
- }
-
- public void testScreenRequestsRecreation() {
- mLPKV.wakeWhenReadyTq(0);
- mLPKV.onScreenTurnedOn();
-
- assertEquals(1, mLPKV.getInjectedLockScreens().size());
- assertEquals(1, mLPKV.getInjectedUnlockScreens().size());
- MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0);
-
- assertEquals(0, lockScreen.getOnPauseCount());
- assertEquals(1, lockScreen.getOnResumeCount());
-
- // simulate screen asking to be recreated
- mLPKV.mKeyguardScreenCallback.recreateMe(new Configuration());
-
- // should have been recreated
- assertEquals(2, mLPKV.getInjectedLockScreens().size());
- assertEquals(2, mLPKV.getInjectedUnlockScreens().size());
-
- // both old screens should have been cleaned up
- assertEquals(1, mLPKV.getInjectedLockScreens().get(0).getCleanupCount());
- assertEquals(1, mLPKV.getInjectedUnlockScreens().get(0).getCleanupCount());
-
- // old lock screen should have been paused
- assertEquals(1, mLPKV.getInjectedLockScreens().get(0).getOnPauseCount());
- assertEquals(0, mLPKV.getInjectedUnlockScreens().get(0).getOnPauseCount());
-
- // new lock screen should have been resumed
- assertEquals(1, mLPKV.getInjectedLockScreens().get(1).getOnResumeCount());
- assertEquals(0, mLPKV.getInjectedUnlockScreens().get(1).getOnResumeCount());
- }
-
- public void testMenuDoesntGoToUnlockScreenOnWakeWhenPukLocked() {
- // PUK locked
- mUpdateMonitor.simState = IccCard.State.PUK_REQUIRED;
-
- // wake by menu
- mLPKV.wakeWhenReadyTq(KeyEvent.KEYCODE_MENU);
-
- assertEquals(1, mLPKV.getInjectedLockScreens().size());
- assertEquals(1, mLPKV.getInjectedUnlockScreens().size());
- MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0);
- MockKeyguardScreen unlockScreen = mLPKV.getInjectedUnlockScreens().get(0);
-
- // lock screen should be only visible one
- assertEquals(View.VISIBLE, lockScreen.getVisibility());
- assertEquals(View.GONE, unlockScreen.getVisibility());
- }
-
- public void testMenuGoesToLockScreenWhenDeviceNotSecure() {
- mLockPatternUtils.setLockPatternEnabled(false);
-
- // wake by menu
- mLPKV.wakeWhenReadyTq(KeyEvent.KEYCODE_MENU);
-
- assertEquals(1, mLPKV.getInjectedLockScreens().size());
- assertEquals(1, mLPKV.getInjectedUnlockScreens().size());
- MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0);
- MockKeyguardScreen unlockScreen = mLPKV.getInjectedUnlockScreens().get(0);
-
- // lock screen should be only visible one
- assertEquals(View.VISIBLE, lockScreen.getVisibility());
- assertEquals(View.GONE, unlockScreen.getVisibility());
- }
-}