Merge "Add tests for the RS debug context." into jb-mr2-dev
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 5e86080..662693e 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -476,7 +476,8 @@
         </activity>
 
         <activity android:name="android.webkit.cts.CookieSyncManagerStubActivity"
-            android:label="CookieSyncManagerStubActivity">
+            android:label="CookieSyncManagerStubActivity"
+            android:screenOrientation="nosensor">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
@@ -666,7 +667,8 @@
         </activity>
 
         <activity android:name="android.webkit.cts.WebViewStubActivity"
-            android:label="WebViewStubActivity">
+            android:label="WebViewStubActivity"
+            android:screenOrientation="nosensor">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
diff --git a/tests/src/android/webkit/cts/WebViewOnUiThread.java b/tests/src/android/webkit/cts/WebViewOnUiThread.java
index cbda733..aef4374 100644
--- a/tests/src/android/webkit/cts/WebViewOnUiThread.java
+++ b/tests/src/android/webkit/cts/WebViewOnUiThread.java
@@ -182,6 +182,15 @@
         });
     }
 
+    public void setNetworkAvailable(final boolean available) {
+        runOnUiThread(new Runnable() {
+            @Override
+            public void run() {
+                mWebView.setNetworkAvailable(available);
+            }
+        });
+    }
+
     public void setDownloadListener(final DownloadListener listener) {
         runOnUiThread(new Runnable() {
             @Override
diff --git a/tests/tests/media/src/android/media/cts/MediaDrmMockTest.java b/tests/tests/media/src/android/media/cts/MediaDrmMockTest.java
index 277b165..4074e70 100644
--- a/tests/tests/media/src/android/media/cts/MediaDrmMockTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaDrmMockTest.java
@@ -25,6 +25,8 @@
 import android.util.Log;
 import java.util.HashMap;
 import java.util.Arrays;
+import java.util.List;
+import java.util.Iterator;
 import java.util.UUID;
 import java.lang.Thread;
 import java.lang.Object;
@@ -219,10 +221,10 @@
 
         String mimeType = "video/iso.segment";
         KeyRequest request = md.getKeyRequest(sessionId, initData, mimeType,
-                                                      MediaDrm.MEDIA_DRM_KEY_TYPE_STREAMING,
+                                                      MediaDrm.KEY_TYPE_STREAMING,
                                                       optionalParameters);
-        assertTrue(Arrays.equals(request.data, testRequest));
-        assertTrue(request.defaultUrl.equals(testDefaultUrl));
+        assertTrue(Arrays.equals(request.getData(), testRequest));
+        assertTrue(request.getDefaultUrl().equals(testDefaultUrl));
 
         assertTrue(Arrays.equals(initData, md.getPropertyByteArray("mock-initdata")));
         assertTrue(mimeType.equals(md.getPropertyString("mock-mimetype")));
@@ -250,10 +252,10 @@
 
         String mimeType = "video/iso.segment";
         KeyRequest request = md.getKeyRequest(sessionId, initData, mimeType,
-                                                      MediaDrm.MEDIA_DRM_KEY_TYPE_STREAMING,
+                                                      MediaDrm.KEY_TYPE_STREAMING,
                                                       null);
-        assertTrue(Arrays.equals(request.data, testRequest));
-        assertTrue(request.defaultUrl.equals(testDefaultUrl));
+        assertTrue(Arrays.equals(request.getData(), testRequest));
+        assertTrue(request.getDefaultUrl().equals(testDefaultUrl));
 
         assertTrue(Arrays.equals(initData, md.getPropertyByteArray("mock-initdata")));
         assertTrue(mimeType.equals(md.getPropertyString("mock-mimetype")));
@@ -262,6 +264,63 @@
         md.closeSession(sessionId);
     }
 
+    public void testGetKeyRequestOffline() throws Exception {
+        if (!isMockPluginInstalled()) {
+            return;
+        }
+
+        MediaDrm md = new MediaDrm(mockScheme);
+        byte[] sessionId = md.openSession();
+
+        // Set up mock expected responses using properties
+        byte testRequest[] = {0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x10, 0x11, 0x12};
+        md.setPropertyByteArray("mock-request", testRequest);
+        String testDefaultUrl = "http://1.2.3.4:8080/blah";
+        md.setPropertyString("mock-defaultUrl", testDefaultUrl);
+
+        byte[] initData = {0x0a, 0x0b, 0x0c, 0x0d};
+
+        String mimeType = "video/iso.segment";
+        KeyRequest request = md.getKeyRequest(sessionId, initData, mimeType,
+                                              MediaDrm.KEY_TYPE_OFFLINE,
+                                              null);
+        assertTrue(Arrays.equals(request.getData(), testRequest));
+        assertTrue(request.getDefaultUrl().equals(testDefaultUrl));
+
+        assertTrue(Arrays.equals(initData, md.getPropertyByteArray("mock-initdata")));
+        assertTrue(mimeType.equals(md.getPropertyString("mock-mimetype")));
+        assertTrue(md.getPropertyString("mock-keytype").equals("2"));
+
+        md.closeSession(sessionId);
+    }
+
+    public void testGetKeyRequestRelease() throws Exception {
+        if (!isMockPluginInstalled()) {
+            return;
+        }
+
+        MediaDrm md = new MediaDrm(mockScheme);
+        byte[] sessionId = md.openSession();
+
+        // Set up mock expected responses using properties
+        byte testRequest[] = {0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x10, 0x11, 0x12};
+        md.setPropertyByteArray("mock-request", testRequest);
+        String testDefaultUrl = "http://1.2.3.4:8080/blah";
+        md.setPropertyString("mock-defaultUrl", testDefaultUrl);
+
+        String mimeType = "video/iso.segment";
+        KeyRequest request = md.getKeyRequest(sessionId, null, mimeType,
+                                              MediaDrm.KEY_TYPE_RELEASE,
+                                              null);
+        assertTrue(Arrays.equals(request.getData(), testRequest));
+        assertTrue(request.getDefaultUrl().equals(testDefaultUrl));
+
+        assertTrue(mimeType.equals(md.getPropertyString("mock-mimetype")));
+        assertTrue(md.getPropertyString("mock-keytype").equals("3"));
+
+        md.closeSession(sessionId);
+    }
+
     public void testProvideKeyResponse() throws Exception {
         if (!isMockPluginInstalled()) {
             return;
@@ -343,8 +402,8 @@
         md.setPropertyString("mock-defaultUrl", testDefaultUrl);
 
         ProvisionRequest request = md.getProvisionRequest();
-        assertTrue(Arrays.equals(request.data, testRequest));
-        assertTrue(request.defaultUrl.equals(testDefaultUrl));
+        assertTrue(Arrays.equals(request.getData(), testRequest));
+        assertTrue(request.getDefaultUrl().equals(testDefaultUrl));
     }
 
     public void testProvideProvisionResponse() throws Exception {
@@ -361,6 +420,45 @@
         assertTrue(Arrays.equals(testResponse, md.getPropertyByteArray("mock-response")));
     }
 
+    public void testGetSecureStops() throws Exception {
+        if (!isMockPluginInstalled()) {
+            return;
+        }
+
+        MediaDrm md = new MediaDrm(mockScheme);
+
+        // Set up mock expected responses using properties
+        byte ss1[] = {0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20};
+        byte ss2[] = {0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30};
+
+        md.setPropertyByteArray("mock-secure-stop1", ss1);
+        md.setPropertyByteArray("mock-secure-stop2", ss2);
+
+        List<byte[]> secureStopList = md.getSecureStops();
+        assertTrue(secureStopList != null);
+
+        Iterator<byte[]> iter = secureStopList.iterator();
+        assertTrue(iter.hasNext());
+        assertTrue(Arrays.equals(iter.next(), ss1));
+        assertTrue(iter.hasNext());
+        assertTrue(Arrays.equals(iter.next(), ss2));
+        assertFalse(iter.hasNext());
+    }
+
+    public void testReleaseSecureStops() throws Exception {
+        if (!isMockPluginInstalled()) {
+            return;
+        }
+
+        MediaDrm md = new MediaDrm(mockScheme);
+
+        // Set up mock expected responses using properties
+        byte ssrelease[] = {0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40};
+
+        md.releaseSecureStops(ssrelease);
+        assertTrue(Arrays.equals(ssrelease, md.getPropertyByteArray("mock-ssrelease")));
+    }
+
     public void testMultipleSessions() throws Exception {
         if (!isMockPluginInstalled()) {
             return;
@@ -534,31 +632,31 @@
 
                 try {
                     mMediaDrm = new MediaDrm(mockScheme);
-
-                    synchronized(mLock) {
-                        mLock.notify();
-                        mMediaDrm.setOnEventListener(new MediaDrm.OnEventListener() {
-                                @Override
-                                public void onEvent(MediaDrm md, byte[] sessionId, int event,
-                                                    int extra, byte[] data) {
-                                    synchronized(mLock) {
-                                        Log.d(TAG,"testEventNoSessionNoData.onEvent");
-                                        assertTrue(md == mMediaDrm);
-                                        assertTrue(event == 2);
-                                        assertTrue(extra == 456);
-                                        assertTrue(sessionId == null);
-                                        assertTrue(data == null);
-                                        mGotEvent = true;
-                                        mLock.notify();
-                                    }
-                                }
-                            });
-                    }
                 } catch (MediaDrmException e) {
                     e.printStackTrace();
                     fail();
                 }
 
+                synchronized(mLock) {
+                    mLock.notify();
+                    mMediaDrm.setOnEventListener(new MediaDrm.OnEventListener() {
+                            @Override
+                            public void onEvent(MediaDrm md, byte[] sessionId, int event,
+                                                int extra, byte[] data) {
+                                synchronized(mLock) {
+                                    Log.d(TAG,"testEventNoSessionNoData.onEvent");
+                                    assertTrue(md == mMediaDrm);
+                                    assertTrue(event == 2);
+                                    assertTrue(extra == 456);
+                                    assertTrue(sessionId == null);
+                                    assertTrue(data == null);
+                                    mGotEvent = true;
+                                    mLock.notify();
+                                }
+                            }
+                        });
+                }
+
                 Looper.loop();  // Blocks forever until Looper.quit() is called.
             }
         }.start();
@@ -604,39 +702,39 @@
 
                 try {
                     mMediaDrm = new MediaDrm(mockScheme);
-
-                    final byte[] expected_sessionId = mMediaDrm.openSession();
-                    final byte[] expected_data = {0x10, 0x11, 0x12, 0x13, 0x14,
-                                                  0x15, 0x16, 0x17, 0x18, 0x19};
-
-                    mMediaDrm.setPropertyByteArray("mock-event-session-id", expected_sessionId);
-                    mMediaDrm.setPropertyByteArray("mock-event-data", expected_data);
-
-                    synchronized(mLock) {
-                        mLock.notify();
-
-                        mMediaDrm.setOnEventListener(new MediaDrm.OnEventListener() {
-                                @Override
-                                public void onEvent(MediaDrm md, byte[] sessionId, int event,
-                                                    int extra, byte[] data) {
-                                    synchronized(mLock) {
-                                        Log.d(TAG,"testEventWithSessoinAndData.onEvent");
-                                        assertTrue(md == mMediaDrm);
-                                        assertTrue(event == 1);
-                                        assertTrue(extra == 123);
-                                        assertTrue(Arrays.equals(sessionId, expected_sessionId));
-                                        assertTrue(Arrays.equals(data, expected_data));
-                                        mGotEvent = true;
-                                        mLock.notify();
-                                    }
-                                }
-                            });
-                    }
                 } catch (MediaDrmException e) {
                     e.printStackTrace();
                     fail();
                 }
 
+
+                final byte[] expected_sessionId = mMediaDrm.openSession();
+                final byte[] expected_data = {0x10, 0x11, 0x12, 0x13, 0x14,
+                                              0x15, 0x16, 0x17, 0x18, 0x19};
+
+                mMediaDrm.setPropertyByteArray("mock-event-session-id", expected_sessionId);
+                mMediaDrm.setPropertyByteArray("mock-event-data", expected_data);
+
+                synchronized(mLock) {
+                    mLock.notify();
+
+                    mMediaDrm.setOnEventListener(new MediaDrm.OnEventListener() {
+                            @Override
+                            public void onEvent(MediaDrm md, byte[] sessionId, int event,
+                                                int extra, byte[] data) {
+                                synchronized(mLock) {
+                                    Log.d(TAG,"testEventWithSessoinAndData.onEvent");
+                                    assertTrue(md == mMediaDrm);
+                                    assertTrue(event == 1);
+                                    assertTrue(extra == 123);
+                                    assertTrue(Arrays.equals(sessionId, expected_sessionId));
+                                    assertTrue(Arrays.equals(data, expected_data));
+                                    mGotEvent = true;
+                                    mLock.notify();
+                                }
+                            }
+                        });
+                }
                 Looper.loop();  // Blocks forever until Looper.quit() is called.
             }
         }.start();
diff --git a/tests/tests/net/src/android/net/wifi/cts/WifiEnterpriseConfigTest.java b/tests/tests/net/src/android/net/wifi/cts/WifiEnterpriseConfigTest.java
new file mode 100644
index 0000000..58298d5
--- /dev/null
+++ b/tests/tests/net/src/android/net/wifi/cts/WifiEnterpriseConfigTest.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2013 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.wifi.cts;
+
+import android.content.Context;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiEnterpriseConfig;
+import android.net.wifi.WifiEnterpriseConfig.Eap;
+import android.net.wifi.WifiEnterpriseConfig.Phase2;
+import android.net.wifi.WifiManager;
+import android.test.AndroidTestCase;
+
+public class WifiEnterpriseConfigTest extends AndroidTestCase {
+    private  WifiManager mWifiManager;
+
+    private static final String SSID = "\"TestSSID\"";
+    private static final String IDENTITY = "identity";
+    private static final String PASSWORD = "password";
+    private static final String SUBJECT_MATCH = "subjectmatch";
+    private static final String ANON_IDENTITY = "anonidentity";
+    private static final int ENABLE_DELAY = 10000;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mWifiManager = (WifiManager) mContext
+                .getSystemService(Context.WIFI_SERVICE);
+        assertNotNull(mWifiManager);
+        mWifiManager.setWifiEnabled(true);
+        Thread.sleep(ENABLE_DELAY);
+        assertTrue(mWifiManager.isWifiEnabled());
+    }
+
+    public void testSettersAndGetters() {
+        WifiEnterpriseConfig config = new WifiEnterpriseConfig();
+        assertTrue(config.getEapMethod() == Eap.NONE);
+        config.setEapMethod(Eap.PEAP);
+        assertTrue(config.getEapMethod() == Eap.PEAP);
+        config.setEapMethod(Eap.PWD);
+        assertTrue(config.getEapMethod() == Eap.PWD);
+        config.setEapMethod(Eap.TLS);
+        assertTrue(config.getEapMethod() == Eap.TLS);
+        config.setEapMethod(Eap.TTLS);
+        assertTrue(config.getEapMethod() == Eap.TTLS);
+        assertTrue(config.getPhase2Method() == Phase2.NONE);
+        config.setPhase2Method(Phase2.PAP);
+        assertTrue(config.getPhase2Method() == Phase2.PAP);
+        config.setPhase2Method(Phase2.MSCHAP);
+        assertTrue(config.getPhase2Method() == Phase2.MSCHAP);
+        config.setPhase2Method(Phase2.MSCHAPV2);
+        assertTrue(config.getPhase2Method() == Phase2.MSCHAPV2);
+        config.setPhase2Method(Phase2.GTC);
+        assertTrue(config.getPhase2Method() == Phase2.GTC);
+        config.setIdentity(IDENTITY);
+        assertTrue(config.getIdentity().equals(IDENTITY));
+        config.setAnonymousIdentity(ANON_IDENTITY);
+        assertTrue(config.getAnonymousIdentity().equals(ANON_IDENTITY));
+        config.setPassword(PASSWORD);
+        assertTrue(config.getPassword().equals(PASSWORD));
+        config.setCaCertificate(null);
+        config.setClientKeyEntry(null, null);
+        config.setSubjectMatch(SUBJECT_MATCH);
+        assertTrue(config.getSubjectMatch().equals(SUBJECT_MATCH));
+    }
+
+    public void testAddEapNetwork() {
+        WifiConfiguration config = new WifiConfiguration();
+        WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig();
+        enterpriseConfig.setEapMethod(Eap.PWD);
+        enterpriseConfig.setIdentity(IDENTITY);
+        enterpriseConfig.setPassword(PASSWORD);
+        config.SSID = SSID;
+        config.enterpriseConfig = enterpriseConfig;
+
+        int netId = mWifiManager.addNetwork(config);
+        assertTrue(doesSsidExist(SSID));
+        mWifiManager.removeNetwork(netId);
+        assertFalse(doesSsidExist(SSID));
+    }
+
+    private boolean doesSsidExist(String ssid) {
+        for (final WifiConfiguration w : mWifiManager.getConfiguredNetworks()) {
+            if (w.SSID.equals(ssid))
+                return true;
+        }
+        return false;
+    }
+}
diff --git a/tests/tests/os/src/android/os/cts/StatFsTest.java b/tests/tests/os/src/android/os/cts/StatFsTest.java
index 2396e26..67afde9 100644
--- a/tests/tests/os/src/android/os/cts/StatFsTest.java
+++ b/tests/tests/os/src/android/os/cts/StatFsTest.java
@@ -22,29 +22,39 @@
 import android.os.StatFs;
 
 public class StatFsTest extends TestCase {
-    public void testStatFs(){
+    public void testStatFs() {
         File path = Environment.getDataDirectory();
         StatFs stat = new StatFs(path.getPath());
-        int blockSize = stat.getBlockSize();
-        int totalBlocks = stat.getBlockCount();
-        int freeBlocks = stat.getFreeBlocks();
-        int availableBlocks = stat.getAvailableBlocks();
 
-        assertTrue(blockSize > 0);
-        assertTrue(totalBlocks > 0);
-        assertTrue(freeBlocks >= availableBlocks);
-        assertTrue(availableBlocks > 0);
+        assertTrue(stat.getBlockSize() > 0);
+        assertTrue(stat.getBlockCount() > 0);
+        assertTrue(stat.getFreeBlocks() >= stat.getAvailableBlocks());
+        assertTrue(stat.getAvailableBlocks() > 0);
+
+        assertTrue(stat.getBlockSizeLong() > 0);
+        assertTrue(stat.getBlockCountLong() > 0);
+        assertTrue(stat.getFreeBlocksLong() >= stat.getAvailableBlocksLong());
+        assertTrue(stat.getAvailableBlocksLong() > 0);
+
+        assertTrue(stat.getFreeBytes() > 0);
+        assertTrue(stat.getAvailableBytes() > 0);
+        assertTrue(stat.getTotalBytes() > 0);
 
         path = Environment.getRootDirectory();
         stat.restat(path.getPath());
-        blockSize = stat.getBlockSize();
-        totalBlocks = stat.getBlockCount();
-        freeBlocks = stat.getFreeBlocks();
-        availableBlocks = stat.getAvailableBlocks();
 
-        assertTrue(blockSize > 0);
-        assertTrue(totalBlocks > 0);
-        assertTrue(freeBlocks >= availableBlocks);
-        assertTrue(availableBlocks > 0);
+        assertTrue(stat.getBlockSize() > 0);
+        assertTrue(stat.getBlockCount() > 0);
+        assertTrue(stat.getFreeBlocks() >= stat.getAvailableBlocks());
+        assertTrue(stat.getAvailableBlocks() > 0);
+
+        assertTrue(stat.getBlockSizeLong() > 0);
+        assertTrue(stat.getBlockCountLong() > 0);
+        assertTrue(stat.getFreeBlocksLong() >= stat.getAvailableBlocksLong());
+        assertTrue(stat.getAvailableBlocksLong() > 0);
+
+        assertTrue(stat.getFreeBytes() > 0);
+        assertTrue(stat.getAvailableBytes() > 0);
+        assertTrue(stat.getTotalBytes() > 0);
     }
 }
diff --git a/tests/tests/text/src/android/text/bidi/cts/BidiFormatterTest.java b/tests/tests/text/src/android/text/bidi/cts/BidiFormatterTest.java
deleted file mode 100644
index 198a52f..0000000
--- a/tests/tests/text/src/android/text/bidi/cts/BidiFormatterTest.java
+++ /dev/null
@@ -1,422 +0,0 @@
-/*
- * Copyright (C) 2013 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.bidi.cts;
-
-import android.test.AndroidTestCase;
-import android.text.TextDirectionHeuristics;
-import android.text.bidi.BidiFormatter;
-
-import java.util.Locale;
-
-public class BidiFormatterTest extends AndroidTestCase {
-
-    private static final BidiFormatter LTR_FMT = BidiFormatter.getInstance(false /* LTR context */);
-    private static final BidiFormatter RTL_FMT = BidiFormatter.getInstance(true /* RTL context */);
-
-    private static final BidiFormatter LTR_FMT_EXIT_RESET =
-            new BidiFormatter.Builder(false /* LTR context */).stereoReset(false).build();
-    private static final BidiFormatter RTL_FMT_EXIT_RESET =
-            new BidiFormatter.Builder(true /* RTL context */).stereoReset(false).build();
-
-    private static final String EN = "abba";
-    private static final String HE = "\u05e0\u05e1";
-
-    private static final String LRM = "\u200E";
-    private static final String RLM = "\u200F";
-    private static final String LRE = "\u202A";
-    private static final String RLE = "\u202B";
-    private static final String PDF = "\u202C";
-
-    private static final String LEFT = "left";
-    private static final String RIGHT = "right";
-
-
-    public void testIsRtlContext() {
-        assertEquals(false, LTR_FMT.isRtlContext());
-        assertEquals(true, RTL_FMT.isRtlContext());
-
-        assertEquals(false, BidiFormatter.getInstance(Locale.ENGLISH).isRtlContext());
-        assertEquals(true, BidiFormatter.getInstance(true).isRtlContext());
-    }
-
-    public void testBuilderIsRtlContext() {
-        assertEquals(false, new BidiFormatter.Builder(false).build().isRtlContext());
-        assertEquals(true, new BidiFormatter.Builder(true).build().isRtlContext());
-    }
-
-    public void testIsRtl() {
-        assertEquals(true, BidiFormatter.getInstance(true).isRtl(HE));
-        assertEquals(true, BidiFormatter.getInstance(false).isRtl(HE));
-
-        assertEquals(false, BidiFormatter.getInstance(true).isRtl(EN));
-        assertEquals(false, BidiFormatter.getInstance(false).isRtl(EN));
-    }
-
-    public void testDirAttrValue() {
-        assertEquals("ltr", LTR_FMT.dirAttrValue(EN));
-        assertEquals("ltr", RTL_FMT.dirAttrValue(EN));
-
-        assertEquals("rtl", LTR_FMT.dirAttrValue(HE));
-        assertEquals("rtl", RTL_FMT.dirAttrValue(HE));
-
-        assertEquals("ltr", LTR_FMT.dirAttrValue(EN, TextDirectionHeuristics.LTR));
-        assertEquals("rtl", LTR_FMT.dirAttrValue(EN, TextDirectionHeuristics.RTL));
-
-        assertEquals("ltr", RTL_FMT.dirAttrValue(EN, TextDirectionHeuristics.LTR));
-        assertEquals("rtl", RTL_FMT.dirAttrValue(EN, TextDirectionHeuristics.RTL));
-
-        assertEquals("ltr", LTR_FMT.dirAttrValue(HE, TextDirectionHeuristics.LTR));
-        assertEquals("rtl", LTR_FMT.dirAttrValue(HE, TextDirectionHeuristics.RTL));
-
-        assertEquals("ltr", RTL_FMT.dirAttrValue(HE, TextDirectionHeuristics.LTR));
-        assertEquals("rtl", RTL_FMT.dirAttrValue(HE, TextDirectionHeuristics.RTL));
-
-        assertEquals("ltr", LTR_FMT.dirAttrValue("", TextDirectionHeuristics.LTR));
-        assertEquals("rtl", LTR_FMT.dirAttrValue("", TextDirectionHeuristics.RTL));
-
-        assertEquals("ltr", RTL_FMT.dirAttrValue("", TextDirectionHeuristics.LTR));
-        assertEquals("rtl", RTL_FMT.dirAttrValue("", TextDirectionHeuristics.RTL));
-    }
-
-    public void testDirAttr() {
-        assertEquals("", LTR_FMT.dirAttr(EN));
-        assertEquals("dir=\"ltr\"", RTL_FMT.dirAttr(EN));
-
-        assertEquals("dir=\"rtl\"", LTR_FMT.dirAttr(HE));
-        assertEquals("", RTL_FMT.dirAttr(HE));
-
-        assertEquals("", LTR_FMT.dirAttr(".", TextDirectionHeuristics.LTR));
-        assertEquals("dir=\"ltr\"", RTL_FMT.dirAttr(".", TextDirectionHeuristics.LTR));
-
-        assertEquals("dir=\"rtl\"", LTR_FMT.dirAttr(".", TextDirectionHeuristics.RTL));
-        assertEquals("", RTL_FMT.dirAttr(".", TextDirectionHeuristics.RTL));
-    }
-
-    public void testMarkAfter() {
-        assertEquals("uniform dir matches LTR context",
-                "", LTR_FMT.markAfter(EN));
-        assertEquals("uniform dir matches RTL context",
-                "", RTL_FMT.markAfter(HE));
-
-        assertEquals("exit dir opposite to LTR context",
-                LRM, LTR_FMT.markAfter(EN + HE, TextDirectionHeuristics.LTR));
-        assertEquals("exit dir opposite to RTL context",
-                RLM, RTL_FMT.markAfter(HE + EN, TextDirectionHeuristics.RTL));
-
-        assertEquals("overall dir (but not exit dir) opposite to LTR context",
-                LRM, LTR_FMT.markAfter(HE + EN, TextDirectionHeuristics.RTL));
-        assertEquals("overall dir (but not exit dir) opposite to RTL context",
-                RLM, RTL_FMT.markAfter(EN + HE, TextDirectionHeuristics.LTR));
-
-        assertEquals("exit dir neutral, overall dir matches LTR context",
-                "", LTR_FMT.markAfter(".", TextDirectionHeuristics.LTR));
-        assertEquals("exit dir neutral, overall dir matches RTL context",
-                "", RTL_FMT.markAfter(".", TextDirectionHeuristics.RTL));
-    }
-
-    public void testMarkBefore() {
-        assertEquals("uniform dir matches LTR context",
-                "", LTR_FMT.markBefore(EN));
-        assertEquals("uniform dir matches RTL context",
-                "", RTL_FMT.markBefore(HE));
-
-        assertEquals("entry dir opposite to LTR context",
-                LRM, LTR_FMT.markBefore(HE + EN, TextDirectionHeuristics.LTR));
-        assertEquals("entry dir opposite to RTL context",
-                RLM, RTL_FMT.markBefore(EN + HE, TextDirectionHeuristics.RTL));
-
-        assertEquals("overall dir (but not entry dir) opposite to LTR context",
-                LRM, LTR_FMT.markBefore(EN + HE, TextDirectionHeuristics.RTL));
-        assertEquals("overall dir (but not entry dir) opposite to RTL context",
-                RLM, RTL_FMT.markBefore(HE + EN, TextDirectionHeuristics.LTR));
-
-        assertEquals("exit dir neutral, overall dir matches LTR context",
-                "", LTR_FMT.markBefore(".", TextDirectionHeuristics.LTR));
-        assertEquals("exit dir neutral, overall dir matches RTL context",
-                "", RTL_FMT.markBefore(".", TextDirectionHeuristics.RTL));
-    }
-
-
-    public void testMark() {
-        assertEquals(LRM, LTR_FMT.mark());
-        assertEquals(RLM, RTL_FMT.mark());
-    }
-
-    public void testStartEdge() {
-        assertEquals(LEFT, LTR_FMT.startEdge());
-        assertEquals(RIGHT, RTL_FMT.startEdge());
-    }
-
-    public void testEndEdge() {
-        assertEquals(RIGHT, LTR_FMT.endEdge());
-        assertEquals(LEFT, RTL_FMT.endEdge());
-    }
-
-    public void testUnicodeWrap() {
-        // Uniform directionality in opposite context.
-        assertEquals("uniform dir opposite to LTR context",
-                RLE + "." + HE + "." + PDF + LRM,
-                LTR_FMT_EXIT_RESET.unicodeWrap("." + HE + "."));
-        assertEquals("uniform dir opposite to LTR context, stereo reset",
-                LRM + RLE + "." + HE + "." + PDF + LRM,
-                LTR_FMT.unicodeWrap("." + HE + "."));
-        assertEquals("uniform dir opposite to LTR context, stereo reset, no isolation",
-                RLE + "." + HE + "." + PDF,
-                LTR_FMT.unicodeWrap("." + HE + ".", false));
-        assertEquals("neutral treated as opposite to LTR context",
-                RLE + "." + PDF + LRM,
-                LTR_FMT_EXIT_RESET.unicodeWrap(".", TextDirectionHeuristics.RTL));
-        assertEquals("uniform dir opposite to RTL context",
-                LRE + "." + EN + "." + PDF + RLM,
-                RTL_FMT_EXIT_RESET.unicodeWrap("." + EN + "."));
-        assertEquals("uniform dir opposite to RTL context, stereo reset",
-                RLM + LRE + "." + EN + "." + PDF + RLM,
-                RTL_FMT.unicodeWrap("." + EN + "."));
-        assertEquals("uniform dir opposite to RTL context, stereo reset, no isolation",
-                LRE + "." + EN + "." + PDF,
-                RTL_FMT.unicodeWrap("." + EN + ".", false));
-        assertEquals("neutral treated as opposite to RTL context",
-                LRE + "." + PDF + RLM,
-                RTL_FMT_EXIT_RESET.unicodeWrap(".", TextDirectionHeuristics.LTR));
-
-        // We test mixed-directionality cases only with an explicit overall directionality parameter
-        // because the estimation logic is outside the sphere of BidiFormatter, and different
-        // estimators will treat them differently.
-
-        // Overall directionality matching context, but with opposite exit directionality.
-        assertEquals("exit dir opposite to LTR context",
-                EN + HE + LRM,
-                LTR_FMT_EXIT_RESET.unicodeWrap(EN + HE, TextDirectionHeuristics.LTR));
-        assertEquals("exit dir opposite to LTR context, stereo reset",
-                EN + HE + LRM,
-                LTR_FMT.unicodeWrap(EN + HE, TextDirectionHeuristics.LTR));
-        assertEquals("exit dir opposite to LTR context, stereo reset, no isolation",
-                EN + HE,
-                LTR_FMT.unicodeWrap(EN + HE, TextDirectionHeuristics.LTR, false));
-
-        assertEquals("exit dir opposite to RTL context",
-                HE + EN + RLM,
-                RTL_FMT_EXIT_RESET.unicodeWrap(HE + EN, TextDirectionHeuristics.RTL));
-        assertEquals("exit dir opposite to RTL context, stereo reset",
-                HE + EN + RLM,
-                RTL_FMT.unicodeWrap(HE + EN, TextDirectionHeuristics.RTL));
-        assertEquals("exit dir opposite to RTL context, stereo reset, no isolation",
-                HE + EN,
-                RTL_FMT.unicodeWrap(HE + EN, TextDirectionHeuristics.RTL, false));
-
-        // Overall directionality matching context, but with opposite entry directionality.
-        assertEquals("entry dir opposite to LTR context",
-                HE + EN,
-                LTR_FMT_EXIT_RESET.unicodeWrap(HE + EN, TextDirectionHeuristics.LTR));
-        assertEquals("entry dir opposite to LTR context, stereo reset",
-                LRM + HE + EN,
-                LTR_FMT.unicodeWrap(HE + EN, TextDirectionHeuristics.LTR));
-        assertEquals("entry dir opposite to LTR context, stereo reset, no isolation",
-                HE + EN,
-                LTR_FMT.unicodeWrap(HE + EN, TextDirectionHeuristics.LTR, false));
-
-        assertEquals("entry dir opposite to RTL context",
-                EN + HE,
-                RTL_FMT_EXIT_RESET.unicodeWrap(EN + HE, TextDirectionHeuristics.RTL));
-        assertEquals("entry dir opposite to RTL context, stereo reset",
-                RLM + EN + HE,
-                RTL_FMT.unicodeWrap(EN + HE, TextDirectionHeuristics.RTL));
-        assertEquals("entry dir opposite to RTL context, stereo reset, no isolation",
-                EN + HE,
-                RTL_FMT.unicodeWrap(EN + HE, TextDirectionHeuristics.RTL, false));
-
-        // Overall directionality matching context, but with opposite entry and exit directionality.
-        assertEquals("entry and exit dir opposite to LTR context",
-                HE + EN + HE + LRM,
-                LTR_FMT_EXIT_RESET.unicodeWrap(HE + EN + HE, TextDirectionHeuristics.LTR));
-        assertEquals("entry and exit dir opposite to LTR context, stereo reset",
-                LRM + HE + EN + HE + LRM,
-                LTR_FMT.unicodeWrap(HE + EN + HE, TextDirectionHeuristics.LTR));
-        assertEquals("entry and exit dir opposite to LTR context, no isolation",
-                HE + EN + HE,
-                LTR_FMT_EXIT_RESET.unicodeWrap(HE + EN + HE, TextDirectionHeuristics.LTR, false));
-
-        assertEquals("entry and exit dir opposite to RTL context",
-                EN + HE + EN + RLM,
-                RTL_FMT_EXIT_RESET.unicodeWrap(EN + HE + EN, TextDirectionHeuristics.RTL));
-        assertEquals("entry and exit dir opposite to RTL context, no isolation",
-                EN + HE + EN,
-                RTL_FMT_EXIT_RESET.unicodeWrap(EN + HE + EN, TextDirectionHeuristics.RTL, false));
-
-        // Entry and exit directionality matching context, but with opposite overall directionality.
-        assertEquals("overall dir (but not entry or exit dir) opposite to LTR context",
-                RLE + EN + HE + EN + PDF + LRM,
-                LTR_FMT_EXIT_RESET.unicodeWrap(EN + HE + EN, TextDirectionHeuristics.RTL));
-        assertEquals("overall dir (but not entry or exit dir) opposite to LTR context, stereo reset",
-                LRM + RLE + EN + HE + EN + PDF + LRM,
-                LTR_FMT.unicodeWrap(EN + HE + EN, TextDirectionHeuristics.RTL));
-        assertEquals("overall dir (but not entry or exit dir) opposite to LTR context, no isolation",
-                RLE + EN + HE + EN + PDF,
-                LTR_FMT_EXIT_RESET.unicodeWrap(EN + HE + EN, TextDirectionHeuristics.RTL, false));
-
-        assertEquals("overall dir (but not entry or exit dir) opposite to RTL context",
-                LRE + HE + EN + HE + PDF + RLM,
-                RTL_FMT_EXIT_RESET.unicodeWrap(HE + EN + HE, TextDirectionHeuristics.LTR));
-        assertEquals("overall dir (but not entry or exit dir) opposite to RTL context, stereo reset",
-                RLM + LRE + HE + EN + HE + PDF + RLM,
-                RTL_FMT.unicodeWrap(HE + EN + HE, TextDirectionHeuristics.LTR));
-        assertEquals("overall dir (but not entry or exit dir) opposite to RTL context, no isolation",
-                LRE + HE + EN + HE + PDF,
-                RTL_FMT_EXIT_RESET.unicodeWrap(HE + EN + HE, TextDirectionHeuristics.LTR, false));
-    }
-
-
-    public void testSpanWrap() {
-        // Uniform directionality in matching context.
-        assertEquals("uniform dir matches LTR context",
-                "&amp; " + EN + "&lt;", LTR_FMT.spanWrap("& " + EN + "<"));
-        assertEquals("neutral treated as matching LTR context",
-                ".", LTR_FMT.spanWrap(".", TextDirectionHeuristics.LTR));
-        assertEquals("uniform dir matches RTL context",
-                "&amp; " + HE + "&lt;", RTL_FMT.spanWrap("& " + HE + "<"));
-        assertEquals("neutral treated as matching RTL context",
-                ".", RTL_FMT.spanWrap(".", TextDirectionHeuristics.RTL));
-
-        // Uniform directionality in opposite context.
-        assertEquals("uniform dir opposite to LTR context",
-                "<span dir=\"rtl\">." + HE + ".</span>" + LRM,
-                LTR_FMT_EXIT_RESET.spanWrap("." + HE + "."));
-        assertEquals("uniform dir opposite to LTR context, stereo reset",
-                LRM + "<span dir=\"rtl\">." + HE + ".</span>" + LRM,
-                LTR_FMT.spanWrap("." + HE + "."));
-        assertEquals("uniform dir opposite to LTR context, no isolation",
-                "<span dir=\"rtl\">." + HE + ".</span>",
-                LTR_FMT_EXIT_RESET.spanWrap("." + HE + ".", false));
-        assertEquals("uniform dir opposite to LTR context, stereo reset, no isolation",
-                "<span dir=\"rtl\">." + HE + ".</span>",
-                LTR_FMT.spanWrap("." + HE + ".", false));
-        assertEquals("neutral treated as opposite to LTR context",
-                "<span dir=\"rtl\">" + "." + "</span>" + LRM,
-                LTR_FMT_EXIT_RESET.spanWrap(".", TextDirectionHeuristics.RTL));
-        assertEquals("uniform dir opposite to RTL context",
-                "<span dir=\"ltr\">." + EN + ".</span>" + RLM,
-                RTL_FMT_EXIT_RESET.spanWrap("." + EN + "."));
-        assertEquals("uniform dir opposite to RTL context, stereo reset",
-                RLM + "<span dir=\"ltr\">." + EN + ".</span>" + RLM,
-                RTL_FMT.spanWrap("." + EN + "."));
-        assertEquals("uniform dir opposite to RTL context, no isolation",
-                "<span dir=\"ltr\">." + EN + ".</span>",
-                RTL_FMT_EXIT_RESET.spanWrap("." + EN + ".", false));
-        assertEquals("uniform dir opposite to RTL context, stereo reset, no isolation",
-                "<span dir=\"ltr\">." + EN + ".</span>",
-                RTL_FMT.spanWrap("." + EN + ".", false));
-        assertEquals("neutral treated as opposite to RTL context",
-                "<span dir=\"ltr\">" + "." + "</span>" + RLM,
-                RTL_FMT_EXIT_RESET.spanWrap(".", TextDirectionHeuristics.LTR));
-
-        // We test mixed-directionality cases only with an explicit overall directionality parameter
-        // because the estimation logic is outside the sphere of BidiFormatter, and different
-        // estimators will treat them differently.
-
-        // Overall directionality matching context, but with opposite exit directionality.
-        assertEquals("exit dir opposite to LTR context",
-                EN + HE + LRM,
-                LTR_FMT_EXIT_RESET.spanWrap(EN + HE, TextDirectionHeuristics.LTR));
-        assertEquals("exit dir opposite to LTR context, stereo reset",
-                EN + HE + LRM,
-                LTR_FMT.spanWrap(EN + HE, TextDirectionHeuristics.LTR));
-        assertEquals("exit dir opposite to LTR context, no isolation",
-                EN + HE,
-                LTR_FMT_EXIT_RESET.spanWrap(EN + HE, TextDirectionHeuristics.LTR, false));
-        assertEquals("exit dir opposite to LTR context, stereo reset, no isolation",
-                EN + HE,
-                LTR_FMT.spanWrap(EN + HE, TextDirectionHeuristics.LTR, false));
-        assertEquals("exit dir opposite to RTL context",
-                HE + EN + RLM,
-                RTL_FMT_EXIT_RESET.spanWrap(HE + EN, TextDirectionHeuristics.RTL));
-        assertEquals("exit dir opposite to RTL context, stereo reset",
-                HE + EN + RLM,
-                RTL_FMT.spanWrap(HE + EN, TextDirectionHeuristics.RTL));
-        assertEquals("exit dir opposite to RTL context, no isolation",
-                HE + EN,
-                RTL_FMT_EXIT_RESET.spanWrap(HE + EN, TextDirectionHeuristics.RTL, false));
-        assertEquals("exit dir opposite to RTL context, stereo reset, no isolation",
-                HE + EN,
-                RTL_FMT.spanWrap( HE + EN, TextDirectionHeuristics.RTL, false));
-
-        // Overall directionality matching context, but with opposite entry directionality.
-        assertEquals("entry dir opposite to LTR context",
-                HE + EN,
-                LTR_FMT_EXIT_RESET.spanWrap(HE + EN, TextDirectionHeuristics.LTR));
-        assertEquals("entry dir opposite to LTR context, stereo reset",
-                LRM + HE + EN,
-                LTR_FMT.spanWrap(HE + EN, TextDirectionHeuristics.LTR));
-        assertEquals("entry dir opposite to LTR context, no isolation",
-                HE + EN,
-                LTR_FMT_EXIT_RESET.spanWrap(HE + EN, TextDirectionHeuristics.LTR, false));
-        assertEquals("entry dir opposite to LTR context, stereo reset, no isolation",
-                HE + EN,
-                LTR_FMT.spanWrap(HE + EN, TextDirectionHeuristics.LTR, false));
-        assertEquals("entry dir opposite to RTL context",
-                EN + HE,
-                RTL_FMT_EXIT_RESET.spanWrap(EN + HE, TextDirectionHeuristics.RTL));
-        assertEquals("entry dir opposite to RTL context, stereo reset",
-                RLM + EN + HE,
-                RTL_FMT.spanWrap(EN + HE, TextDirectionHeuristics.RTL));
-        assertEquals("entry dir opposite to RTL context, no isolation",
-                EN + HE,
-                RTL_FMT_EXIT_RESET.spanWrap(EN + HE, TextDirectionHeuristics.RTL, false));
-        assertEquals("entry dir opposite to RTL context, stereo reset, no isolation",
-                EN + HE,
-                RTL_FMT.spanWrap(EN + HE, TextDirectionHeuristics.RTL, false));
-
-        // Overall directionality matching context, but with opposite entry and exit directionality.
-        assertEquals("entry and exit dir opposite to LTR context",
-                HE + EN + HE + LRM,
-                LTR_FMT_EXIT_RESET.spanWrap(HE + EN + HE, TextDirectionHeuristics.LTR));
-        assertEquals("entry and exit dir opposite to LTR context, stereo reset",
-                LRM + HE + EN + HE + LRM,
-                LTR_FMT.spanWrap(HE + EN + HE, TextDirectionHeuristics.LTR));
-        assertEquals("entry and exit dir opposite to LTR context, no isolation",
-                HE + EN + HE,
-                LTR_FMT_EXIT_RESET.spanWrap(HE + EN + HE, TextDirectionHeuristics.LTR, false));
-        assertEquals("entry and exit dir opposite to RTL context",
-                EN + HE + EN + RLM,
-                RTL_FMT_EXIT_RESET.spanWrap(EN + HE + EN, TextDirectionHeuristics.RTL));
-        assertEquals("entry and exit dir opposite to RTL context, stereo reset",
-                RLM + EN + HE + EN + RLM,
-                RTL_FMT.spanWrap(EN + HE + EN, TextDirectionHeuristics.RTL));
-        assertEquals("entry and exit dir opposite to RTL context, no isolation",
-                EN + HE + EN,
-                RTL_FMT_EXIT_RESET.spanWrap(EN + HE + EN, TextDirectionHeuristics.RTL, false));
-
-        // Entry and exit directionality matching context, but with opposite overall directionality.
-        assertEquals("overall dir (but not entry or exit dir) opposite to LTR context",
-                "<span dir=\"rtl\">" + EN + HE + EN + "</span>" + LRM,
-                LTR_FMT_EXIT_RESET.spanWrap(EN + HE + EN, TextDirectionHeuristics.RTL));
-        assertEquals("overall dir (but not entry or exit dir) opposite to LTR context, stereo reset",
-                LRM + "<span dir=\"rtl\">" + EN + HE + EN + "</span>" + LRM,
-                LTR_FMT.spanWrap(EN + HE + EN, TextDirectionHeuristics.RTL));
-        assertEquals("overall dir (but not entry or exit dir) opposite to LTR context, no isolation",
-                "<span dir=\"rtl\">" + EN + HE + EN + "</span>",
-                LTR_FMT_EXIT_RESET.spanWrap(EN + HE + EN, TextDirectionHeuristics.RTL, false));
-        assertEquals("overall dir (but not entry or exit dir) opposite to RTL context",
-                "<span dir=\"ltr\">" + HE + EN + HE + "</span>" + RLM,
-                RTL_FMT_EXIT_RESET.spanWrap(HE + EN + HE, TextDirectionHeuristics.LTR));
-        assertEquals("overall dir (but not entry or exit dir) opposite to RTL context, stereo reset",
-                RLM + "<span dir=\"ltr\">" + HE + EN + HE + "</span>" + RLM,
-                RTL_FMT.spanWrap(HE + EN + HE, TextDirectionHeuristics.LTR));
-        assertEquals("overall dir (but not entry or exit dir) opposite to RTL context, no isolation",
-                "<span dir=\"ltr\">" + HE + EN + HE + "</span>",
-                RTL_FMT_EXIT_RESET.spanWrap(HE + EN + HE, TextDirectionHeuristics.LTR, false));
-    }
-}
diff --git a/tests/tests/text/src/android/text/cts/BidiFormatterTest.java b/tests/tests/text/src/android/text/cts/BidiFormatterTest.java
new file mode 100644
index 0000000..645ab5b
--- /dev/null
+++ b/tests/tests/text/src/android/text/cts/BidiFormatterTest.java
@@ -0,0 +1,221 @@
+/*
+ * Copyright (C) 2013 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.cts;
+
+import android.test.AndroidTestCase;
+import android.text.BidiFormatter;
+import android.text.TextDirectionHeuristics;
+
+import java.util.Locale;
+
+public class BidiFormatterTest extends AndroidTestCase {
+
+    private static final BidiFormatter LTR_FMT = BidiFormatter.getInstance(false /* LTR context */);
+    private static final BidiFormatter RTL_FMT = BidiFormatter.getInstance(true /* RTL context */);
+
+    private static final BidiFormatter LTR_FMT_EXIT_RESET =
+            new BidiFormatter.Builder(false /* LTR context */).stereoReset(false).build();
+    private static final BidiFormatter RTL_FMT_EXIT_RESET =
+            new BidiFormatter.Builder(true /* RTL context */).stereoReset(false).build();
+
+    private static final String EN = "abba";
+    private static final String HE = "\u05e0\u05e1";
+
+    private static final String LRM = "\u200E";
+    private static final String RLM = "\u200F";
+    private static final String LRE = "\u202A";
+    private static final String RLE = "\u202B";
+    private static final String PDF = "\u202C";
+
+    public void testIsRtlContext() {
+        assertEquals(false, LTR_FMT.isRtlContext());
+        assertEquals(true, RTL_FMT.isRtlContext());
+
+        assertEquals(false, BidiFormatter.getInstance(Locale.ENGLISH).isRtlContext());
+        assertEquals(true, BidiFormatter.getInstance(true).isRtlContext());
+    }
+
+    public void testBuilderIsRtlContext() {
+        assertEquals(false, new BidiFormatter.Builder(false).build().isRtlContext());
+        assertEquals(true, new BidiFormatter.Builder(true).build().isRtlContext());
+    }
+
+    public void testIsRtl() {
+        assertEquals(true, BidiFormatter.getInstance(true).isRtl(HE));
+        assertEquals(true, BidiFormatter.getInstance(false).isRtl(HE));
+
+        assertEquals(false, BidiFormatter.getInstance(true).isRtl(EN));
+        assertEquals(false, BidiFormatter.getInstance(false).isRtl(EN));
+    }
+
+    public void testMarkAfter() {
+        assertEquals("uniform dir matches LTR context",
+                "", LTR_FMT.markAfter(EN, TextDirectionHeuristics.LTR));
+        assertEquals("uniform dir matches RTL context",
+                "", RTL_FMT.markAfter(HE, TextDirectionHeuristics.RTL));
+
+        assertEquals("exit dir opposite to LTR context",
+                LRM, LTR_FMT.markAfter(EN + HE, TextDirectionHeuristics.LTR));
+        assertEquals("exit dir opposite to RTL context",
+                RLM, RTL_FMT.markAfter(HE + EN, TextDirectionHeuristics.RTL));
+
+        assertEquals("overall dir (but not exit dir) opposite to LTR context",
+                LRM, LTR_FMT.markAfter(HE + EN, TextDirectionHeuristics.RTL));
+        assertEquals("overall dir (but not exit dir) opposite to RTL context",
+                RLM, RTL_FMT.markAfter(EN + HE, TextDirectionHeuristics.LTR));
+
+        assertEquals("exit dir neutral, overall dir matches LTR context",
+                "", LTR_FMT.markAfter(".", TextDirectionHeuristics.LTR));
+        assertEquals("exit dir neutral, overall dir matches RTL context",
+                "", RTL_FMT.markAfter(".", TextDirectionHeuristics.RTL));
+    }
+
+    public void testMarkBefore() {
+        assertEquals("uniform dir matches LTR context",
+                "", LTR_FMT.markBefore(EN, TextDirectionHeuristics.LTR));
+        assertEquals("uniform dir matches RTL context",
+                "", RTL_FMT.markBefore(HE, TextDirectionHeuristics.RTL));
+
+        assertEquals("entry dir opposite to LTR context",
+                LRM, LTR_FMT.markBefore(HE + EN, TextDirectionHeuristics.LTR));
+        assertEquals("entry dir opposite to RTL context",
+                RLM, RTL_FMT.markBefore(EN + HE, TextDirectionHeuristics.RTL));
+
+        assertEquals("overall dir (but not entry dir) opposite to LTR context",
+                LRM, LTR_FMT.markBefore(EN + HE, TextDirectionHeuristics.RTL));
+        assertEquals("overall dir (but not entry dir) opposite to RTL context",
+                RLM, RTL_FMT.markBefore(HE + EN, TextDirectionHeuristics.LTR));
+
+        assertEquals("exit dir neutral, overall dir matches LTR context",
+                "", LTR_FMT.markBefore(".", TextDirectionHeuristics.LTR));
+        assertEquals("exit dir neutral, overall dir matches RTL context",
+                "", RTL_FMT.markBefore(".", TextDirectionHeuristics.RTL));
+    }
+
+    public void testUnicodeWrap() {
+        // Uniform directionality in opposite context.
+        assertEquals("uniform dir opposite to LTR context",
+                RLE + "." + HE + "." + PDF + LRM,
+                LTR_FMT_EXIT_RESET.unicodeWrap("." + HE + "."));
+        assertEquals("uniform dir opposite to LTR context, stereo reset",
+                LRM + RLE + "." + HE + "." + PDF + LRM,
+                LTR_FMT.unicodeWrap("." + HE + "."));
+        assertEquals("uniform dir opposite to LTR context, stereo reset, no isolation",
+                RLE + "." + HE + "." + PDF,
+                LTR_FMT.unicodeWrap("." + HE + ".", false));
+        assertEquals("neutral treated as opposite to LTR context",
+                RLE + "." + PDF + LRM,
+                LTR_FMT_EXIT_RESET.unicodeWrap(".", TextDirectionHeuristics.RTL));
+        assertEquals("uniform dir opposite to RTL context",
+                LRE + "." + EN + "." + PDF + RLM,
+                RTL_FMT_EXIT_RESET.unicodeWrap("." + EN + "."));
+        assertEquals("uniform dir opposite to RTL context, stereo reset",
+                RLM + LRE + "." + EN + "." + PDF + RLM,
+                RTL_FMT.unicodeWrap("." + EN + "."));
+        assertEquals("uniform dir opposite to RTL context, stereo reset, no isolation",
+                LRE + "." + EN + "." + PDF,
+                RTL_FMT.unicodeWrap("." + EN + ".", false));
+        assertEquals("neutral treated as opposite to RTL context",
+                LRE + "." + PDF + RLM,
+                RTL_FMT_EXIT_RESET.unicodeWrap(".", TextDirectionHeuristics.LTR));
+
+        // We test mixed-directionality cases only with an explicit overall directionality parameter
+        // because the estimation logic is outside the sphere of BidiFormatter, and different
+        // estimators will treat them differently.
+
+        // Overall directionality matching context, but with opposite exit directionality.
+        assertEquals("exit dir opposite to LTR context",
+                EN + HE + LRM,
+                LTR_FMT_EXIT_RESET.unicodeWrap(EN + HE, TextDirectionHeuristics.LTR));
+        assertEquals("exit dir opposite to LTR context, stereo reset",
+                EN + HE + LRM,
+                LTR_FMT.unicodeWrap(EN + HE, TextDirectionHeuristics.LTR));
+        assertEquals("exit dir opposite to LTR context, stereo reset, no isolation",
+                EN + HE,
+                LTR_FMT.unicodeWrap(EN + HE, TextDirectionHeuristics.LTR, false));
+
+        assertEquals("exit dir opposite to RTL context",
+                HE + EN + RLM,
+                RTL_FMT_EXIT_RESET.unicodeWrap(HE + EN, TextDirectionHeuristics.RTL));
+        assertEquals("exit dir opposite to RTL context, stereo reset",
+                HE + EN + RLM,
+                RTL_FMT.unicodeWrap(HE + EN, TextDirectionHeuristics.RTL));
+        assertEquals("exit dir opposite to RTL context, stereo reset, no isolation",
+                HE + EN,
+                RTL_FMT.unicodeWrap(HE + EN, TextDirectionHeuristics.RTL, false));
+
+        // Overall directionality matching context, but with opposite entry directionality.
+        assertEquals("entry dir opposite to LTR context",
+                HE + EN,
+                LTR_FMT_EXIT_RESET.unicodeWrap(HE + EN, TextDirectionHeuristics.LTR));
+        assertEquals("entry dir opposite to LTR context, stereo reset",
+                LRM + HE + EN,
+                LTR_FMT.unicodeWrap(HE + EN, TextDirectionHeuristics.LTR));
+        assertEquals("entry dir opposite to LTR context, stereo reset, no isolation",
+                HE + EN,
+                LTR_FMT.unicodeWrap(HE + EN, TextDirectionHeuristics.LTR, false));
+
+        assertEquals("entry dir opposite to RTL context",
+                EN + HE,
+                RTL_FMT_EXIT_RESET.unicodeWrap(EN + HE, TextDirectionHeuristics.RTL));
+        assertEquals("entry dir opposite to RTL context, stereo reset",
+                RLM + EN + HE,
+                RTL_FMT.unicodeWrap(EN + HE, TextDirectionHeuristics.RTL));
+        assertEquals("entry dir opposite to RTL context, stereo reset, no isolation",
+                EN + HE,
+                RTL_FMT.unicodeWrap(EN + HE, TextDirectionHeuristics.RTL, false));
+
+        // Overall directionality matching context, but with opposite entry and exit directionality.
+        assertEquals("entry and exit dir opposite to LTR context",
+                HE + EN + HE + LRM,
+                LTR_FMT_EXIT_RESET.unicodeWrap(HE + EN + HE, TextDirectionHeuristics.LTR));
+        assertEquals("entry and exit dir opposite to LTR context, stereo reset",
+                LRM + HE + EN + HE + LRM,
+                LTR_FMT.unicodeWrap(HE + EN + HE, TextDirectionHeuristics.LTR));
+        assertEquals("entry and exit dir opposite to LTR context, no isolation",
+                HE + EN + HE,
+                LTR_FMT_EXIT_RESET.unicodeWrap(HE + EN + HE, TextDirectionHeuristics.LTR, false));
+
+        assertEquals("entry and exit dir opposite to RTL context",
+                EN + HE + EN + RLM,
+                RTL_FMT_EXIT_RESET.unicodeWrap(EN + HE + EN, TextDirectionHeuristics.RTL));
+        assertEquals("entry and exit dir opposite to RTL context, no isolation",
+                EN + HE + EN,
+                RTL_FMT_EXIT_RESET.unicodeWrap(EN + HE + EN, TextDirectionHeuristics.RTL, false));
+
+        // Entry and exit directionality matching context, but with opposite overall directionality.
+        assertEquals("overall dir (but not entry or exit dir) opposite to LTR context",
+                RLE + EN + HE + EN + PDF + LRM,
+                LTR_FMT_EXIT_RESET.unicodeWrap(EN + HE + EN, TextDirectionHeuristics.RTL));
+        assertEquals("overall dir (but not entry or exit dir) opposite to LTR context, stereo reset",
+                LRM + RLE + EN + HE + EN + PDF + LRM,
+                LTR_FMT.unicodeWrap(EN + HE + EN, TextDirectionHeuristics.RTL));
+        assertEquals("overall dir (but not entry or exit dir) opposite to LTR context, no isolation",
+                RLE + EN + HE + EN + PDF,
+                LTR_FMT_EXIT_RESET.unicodeWrap(EN + HE + EN, TextDirectionHeuristics.RTL, false));
+
+        assertEquals("overall dir (but not entry or exit dir) opposite to RTL context",
+                LRE + HE + EN + HE + PDF + RLM,
+                RTL_FMT_EXIT_RESET.unicodeWrap(HE + EN + HE, TextDirectionHeuristics.LTR));
+        assertEquals("overall dir (but not entry or exit dir) opposite to RTL context, stereo reset",
+                RLM + LRE + HE + EN + HE + PDF + RLM,
+                RTL_FMT.unicodeWrap(HE + EN + HE, TextDirectionHeuristics.LTR));
+        assertEquals("overall dir (but not entry or exit dir) opposite to RTL context, no isolation",
+                LRE + HE + EN + HE + PDF,
+                RTL_FMT_EXIT_RESET.unicodeWrap(HE + EN + HE, TextDirectionHeuristics.LTR, false));
+    }
+}
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
index 7acc3cd..0dab28b 100755
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
@@ -1616,7 +1616,7 @@
         // WebViewClient.shouldOverrideUrlLoading() returns false, so
         // the WebView will load the new URL.
         mOnUiThread.setDownloadListener(listener);
-        mWebView.getSettings().setJavaScriptEnabled(true);
+        mOnUiThread.getSettings().setJavaScriptEnabled(true);
         mOnUiThread.loadDataAndWaitForCompletion(
                 "<html><body onload=\"window.location = \'" + url + "\'\"></body></html>",
                 "text/html", null);
@@ -1657,7 +1657,7 @@
         mOnUiThread.loadUrlAndWaitForCompletion(url);
         assertEquals("ONLINE", mOnUiThread.getTitle());
 
-        mWebView.setNetworkAvailable(false);
+        mOnUiThread.setNetworkAvailable(false);
 
         // Wait for the DOM to receive notification of the network state change.
         new PollingCheck(TEST_TIMEOUT) {
@@ -1667,7 +1667,7 @@
             }
         }.run();
 
-        mWebView.setNetworkAvailable(true);
+        mOnUiThread.setNetworkAvailable(true);
 
         // Wait for the DOM to receive notification of the network state change.
         new PollingCheck(TEST_TIMEOUT) {
diff --git a/tests/tests/widget/src/android/widget/cts/TextViewTest.java b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
index 18f573b..8255897 100755
--- a/tests/tests/widget/src/android/widget/cts/TextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
@@ -1422,8 +1422,13 @@
         mInstrumentation.waitForIdleSync();
         mTextView.getFocusedRect(rc);
         assertNotNull(mTextView.getLayout());
-        assertEquals(mTextView.getLayout().getPrimaryHorizontal(3), (float) rc.left);
-        assertEquals(mTextView.getLayout().getPrimaryHorizontal(13), (float) rc.right);
+        /* Cursor coordinates from getPrimaryHorizontal() may have a fractional
+         * component, while the result of getFocusedRect is in int coordinates.
+         * It's not practical for these to match exactly, so we compare that the
+         * integer components match - there can be a fractional pixel
+         * discrepancy, which should be okay for all practical applications. */
+        assertEquals((int) mTextView.getLayout().getPrimaryHorizontal(3), rc.left);
+        assertEquals((int) mTextView.getLayout().getPrimaryHorizontal(13), rc.right);
         assertEquals(mTextView.getLayout().getLineTop(0), rc.top);
         assertEquals(mTextView.getLayout().getLineBottom(0), rc.bottom);
 
@@ -1438,8 +1443,8 @@
         mInstrumentation.waitForIdleSync();
         mTextView.getFocusedRect(rc);
         assertNotNull(mTextView.getLayout());
-        assertEquals(mTextView.getLayout().getPrimaryHorizontal(3) - 2, (float) rc.left);
-        assertEquals(mTextView.getLayout().getPrimaryHorizontal(3) + 2, (float) rc.right);
+        assertEquals((int) mTextView.getLayout().getPrimaryHorizontal(3) - 2, rc.left);
+        assertEquals((int) mTextView.getLayout().getPrimaryHorizontal(3) + 2, rc.right);
         assertEquals(mTextView.getLayout().getLineTop(0), rc.top);
         assertEquals(mTextView.getLayout().getLineBottom(0), rc.bottom);
 
@@ -1462,8 +1467,8 @@
         mInstrumentation.waitForIdleSync();
         mTextView.getFocusedRect(rc);
         assertNotNull(mTextView.getLayout());
-        assertEquals(mTextView.getLayout().getPrimaryHorizontal(2), (float) rc.left);
-        assertEquals(mTextView.getLayout().getPrimaryHorizontal(4), (float) rc.right);
+        assertEquals((int) mTextView.getLayout().getPrimaryHorizontal(2), rc.left);
+        assertEquals((int) mTextView.getLayout().getPrimaryHorizontal(4), rc.right);
         assertEquals(mTextView.getLayout().getLineTop(0), rc.top);
         assertEquals(mTextView.getLayout().getLineBottom(0), rc.bottom);