Merge change 2960 into donut

* changes:
  CTS: Clean up and fix MemoryFileTest
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index b1d146e..c35205e 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -80,6 +80,8 @@
     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
     <uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" />
     <uses-permission android:name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS" />
+    <uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
+    <uses-permission android:name="android.permission.READ_USER_DICTIONARY" />
 
     <!-- Used for PackageManager test, don't delete this permission-tree -->
     <permission-tree android:name="com.android.cts.stub.permission.TEST_DYNAMIC"
diff --git a/tests/tests/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java b/tests/tests/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java
new file mode 100644
index 0000000..b81dd37
--- /dev/null
+++ b/tests/tests/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java
@@ -0,0 +1,141 @@
+/*
+ * 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 android.net.cts;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+
+import javax.net.SocketFactory;
+
+import android.net.SSLCertificateSocketFactory;
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.ToBeFixed;
+
+@TestTargetClass(SSLCertificateSocketFactory.class)
+public class SSLCertificateSocketFactoryTest extends AndroidTestCase {
+    private SSLCertificateSocketFactory mFactory;
+    private int mTimeout;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mTimeout = 1000;
+        mFactory = (SSLCertificateSocketFactory) SSLCertificateSocketFactory.getDefault(mTimeout);
+    }
+
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.PARTIAL,
+            method = "getSupportedCipherSuites",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "getDefault",
+            args = {int.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.PARTIAL,
+            method = "getDefaultCipherSuites",
+            args = {}
+        )
+    })
+    @ToBeFixed(bug="1695243", explanation="Android API javadocs are incomplete")
+    public void testAccessProperties() throws Exception {
+        mFactory.getSupportedCipherSuites();
+        mFactory.getDefaultCipherSuites();
+        SocketFactory sf = SSLCertificateSocketFactory.getDefault(mTimeout);
+        assertNotNull(sf);
+    }
+
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "createSocket",
+            args = {java.net.InetAddress.class, int.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "createSocket",
+            args = {java.net.Socket.class, java.lang.String.class, int.class, boolean.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "createSocket",
+            args = {java.lang.String.class, int.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.NOT_FEASIBLE,
+            method = "createSocket",
+            args = {java.lang.String.class, int.class, java.net.InetAddress.class, int.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "createSocket",
+            args = {java.net.InetAddress.class, int.class, java.net.InetAddress.class, int.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "SSLCertificateSocketFactory",
+            args = {int.class}
+        )
+    })
+    public void testCreateSocket() throws Exception {
+        new SSLCertificateSocketFactory(100);
+        int port = 443;
+        String host = "www.fortify.net";
+        InetAddress inetAddress = null;
+        inetAddress = InetAddress.getLocalHost();
+        try {
+            mFactory.createSocket(inetAddress, port);
+            fail("should throw exception!");
+        } catch (IOException e) {
+            // expected
+        }
+
+        try {
+            InetAddress inetAddress1 = InetAddress.getLocalHost();
+            InetAddress inetAddress2 = InetAddress.getLocalHost();
+            mFactory.createSocket(inetAddress1, port, inetAddress2, port);
+            fail("should throw exception!");
+        } catch (IOException e) {
+            // expected
+        }
+
+        try {
+            Socket socket = new Socket();
+            mFactory.createSocket(socket, host, port, true);
+            fail("should throw exception!");
+        } catch (IOException e) {
+            // expected
+        }
+        Socket socket = null;
+        socket = mFactory.createSocket(host, port);
+        assertNotNull(socket);
+        assertNotNull(socket.getOutputStream());
+        assertNotNull(socket.getInputStream());
+
+        // it throw exception when calling createSocket(String, int, InetAddress, int)
+        // The socket level is invalid.
+    }
+
+}
diff --git a/tests/tests/provider/src/android/provider/cts/UserDictionary_WordsTest.java b/tests/tests/provider/src/android/provider/cts/UserDictionary_WordsTest.java
new file mode 100644
index 0000000..7f8d66d
--- /dev/null
+++ b/tests/tests/provider/src/android/provider/cts/UserDictionary_WordsTest.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2009 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.provider.cts;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.RemoteException;
+import android.provider.UserDictionary;
+import android.test.AndroidTestCase;
+
+import java.util.ArrayList;
+
+@TestTargetClass(android.provider.UserDictionary.Words.class)
+public class UserDictionary_WordsTest extends AndroidTestCase {
+
+    private Context mContext;
+    private ContentResolver mContentResolver;
+    private ArrayList<Uri> mAddedBackup;
+
+    private static final String[] WORDS_PROJECTION = new String[] {
+            UserDictionary.Words._ID,
+            UserDictionary.Words.WORD,
+            UserDictionary.Words.FREQUENCY,
+            UserDictionary.Words.LOCALE };
+
+    private static final int ID_INDEX = 0;
+    private static final int WORD_INDEX = 1;
+    private static final int FREQUENCY_INDEX = 2;
+    private static final int LOCALE_INDEX = 3;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        mContext = getContext();
+        mContentResolver = mContext.getContentResolver();
+
+        mAddedBackup = new ArrayList<Uri>();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        for (Uri row : mAddedBackup) {
+            mContentResolver.delete(row, null, null);
+        }
+        mAddedBackup.clear();
+
+        super.tearDown();
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        method = "addWord",
+        args = {Context.class, String.class, int.class, int.class}
+    )
+    public void testAddWord() throws RemoteException {
+        Cursor cursor;
+
+        String word = "UserDictionary_WordsTest";
+        int frequency = 1;
+        UserDictionary.Words.addWord(getContext(), word, frequency,
+                UserDictionary.Words.LOCALE_TYPE_ALL);
+        cursor = mContentResolver.query(
+                UserDictionary.Words.CONTENT_URI,
+                WORDS_PROJECTION,
+                UserDictionary.Words.WORD + "='" + word + "'", null, null);
+        assertEquals(1, cursor.getCount());
+        cursor.moveToFirst();
+        assertEquals(word, cursor.getString(WORD_INDEX));
+        assertEquals(frequency, cursor.getInt(FREQUENCY_INDEX));
+        assertNull(cursor.getString(LOCALE_INDEX));
+        mAddedBackup.add(
+                Uri.withAppendedPath(UserDictionary.Words.CONTENT_URI, cursor.getString(ID_INDEX)));
+    }
+}
diff --git a/tests/tests/view/src/android/view/cts/OrientationEventListenerTest.java b/tests/tests/view/src/android/view/cts/OrientationEventListenerTest.java
new file mode 100644
index 0000000..570ef88
--- /dev/null
+++ b/tests/tests/view/src/android/view/cts/OrientationEventListenerTest.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2009 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.view.cts;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.ToBeFixed;
+
+import android.content.Context;
+import android.hardware.Sensor;
+import android.hardware.SensorManager;
+import android.test.AndroidTestCase;
+import android.view.OrientationEventListener;
+
+/**
+ * Test {@link OrientationEventListener}.
+ */
+@TestTargetClass(OrientationEventListener.class)
+public class OrientationEventListenerTest extends AndroidTestCase {
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "OrientationEventListener",
+            args = {Context.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "OrientationEventListener",
+            args = {Context.class, int.class}
+        )
+    })
+    public void testConstructor() {
+        new MockOrientationEventListener(mContext);
+
+        new MockOrientationEventListener(mContext, SensorManager.SENSOR_DELAY_UI);
+    }
+
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.SUFFICIENT,
+            notes = "Test {@link OrientationEventListener#enable()}. "
+                    + "This method is simply called to make sure that no exception is thrown. "
+                    + "The registeration of the listener can not be tested becuase there is "
+                    + "no way to simulate sensor events",
+            method = "enable",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.SUFFICIENT,
+            notes = "Test {@link OrientationEventListener#disable()}. "
+                    + "This method is simply called to make sure that no exception is thrown. "
+                    + "The registeration of the listener can not be tested becuase there is "
+                    + "no way to simulate sensor events",
+            method = "disable",
+            args = {}
+        )
+    })
+    @ToBeFixed(explanation = "Can not simulate sensor events on the emulator.")
+    public void testEnableAndDisable() {
+        MockOrientationEventListener listener = new MockOrientationEventListener(mContext);
+        listener.enable();
+        listener.disable();
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        method = "canDetectOrientation",
+        args = {}
+    )
+    public void testCanDetectOrientation() {
+        SensorManager sm = (SensorManager)mContext.getSystemService(Context.SENSOR_SERVICE);
+        // Orientation can only be detected if there is an accelerometer
+        boolean hasSensor = (sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null);
+        
+        MockOrientationEventListener listener = new MockOrientationEventListener(mContext);
+        assertEquals(hasSensor, listener.canDetectOrientation());
+    }
+
+    private static class MockOrientationEventListener extends OrientationEventListener {
+        public MockOrientationEventListener(Context context) {
+            super(context);
+        }
+
+        public MockOrientationEventListener(Context context, int rate) {
+            super(context, rate);
+        }
+
+        @Override
+        public void onOrientationChanged(int orientation) {
+        }
+    }
+}