diff options
Diffstat (limited to 'tests')
13 files changed, 213 insertions, 37 deletions
diff --git a/tests/CoreTests/android/AndroidManifest.xml b/tests/CoreTests/android/AndroidManifest.xml index f02673c..8331f0c 100644 --- a/tests/CoreTests/android/AndroidManifest.xml +++ b/tests/CoreTests/android/AndroidManifest.xml @@ -24,6 +24,7 @@ <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" /> <uses-permission android:name="android.permission.WRITE_APN_SETTINGS" /> <uses-permission android:name="android.permission.BROADCAST_STICKY" /> + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- location test permissions --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> diff --git a/tests/CoreTests/android/core/HttpHeaderTest.java b/tests/CoreTests/android/core/HttpHeaderTest.java new file mode 100644 index 0000000..a5d4857 --- /dev/null +++ b/tests/CoreTests/android/core/HttpHeaderTest.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2010 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.core; + +import android.test.AndroidTestCase; +import org.apache.http.util.CharArrayBuffer; + +import android.net.http.Headers; + +public class HttpHeaderTest extends AndroidTestCase { + + static final String LAST_MODIFIED = "Last-Modified: Fri, 18 Jun 2010 09:56:47 GMT"; + static final String CACHE_CONTROL_MAX_AGE = "Cache-Control:max-age=15"; + static final String CACHE_CONTROL_PRIVATE = "Cache-Control: private"; + + /** + * Tests that cache control header supports multiple instances of the header, + * according to HTTP specification. + * + * The HTTP specification states the following about the fields: + * Multiple message-header fields with the same field-name MAY be present + * in a message if and only if the entire field-value for that header field + * is defined as a comma-separated list [i.e., #(values)]. It MUST be + * possible to combine the multiple header fields into one "field-name: + * field-value" pair, without changing the semantics of the message, by + * appending each subsequent field-value to the first, each separated by a + * comma. The order in which header fields with the same field-name are + * received is therefore significant to the interpretation of the combined + * field value, and thus a proxy MUST NOT change the order of these field + * values when a message is forwarded. + */ + public void testCacheControl() throws Exception { + Headers h = new Headers(); + CharArrayBuffer buffer = new CharArrayBuffer(64); + + buffer.append(CACHE_CONTROL_MAX_AGE); + h.parseHeader(buffer); + + buffer.clear(); + buffer.append(LAST_MODIFIED); + h.parseHeader(buffer); + assertEquals("max-age=15", h.getCacheControl()); + + buffer.clear(); + buffer.append(CACHE_CONTROL_PRIVATE); + h.parseHeader(buffer); + assertEquals("max-age=15,private", h.getCacheControl()); + } +} diff --git a/tests/CoreTests/android/core/ProxyTest.java b/tests/CoreTests/android/core/ProxyTest.java new file mode 100644 index 0000000..12acfe8 --- /dev/null +++ b/tests/CoreTests/android/core/ProxyTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2010 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.core; + +import org.apache.http.HttpHost; + +import android.content.Context; +import android.net.Proxy; +import android.test.AndroidTestCase; + +/** + * Proxy tests + */ +public class ProxyTest extends AndroidTestCase { + private Context mContext; + private HttpHost mHttpHost; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + mContext = getContext(); + mHttpHost = null; + String proxyHost = Proxy.getHost(mContext); + int proxyPort = Proxy.getPort(mContext); + if (proxyHost != null) { + mHttpHost = new HttpHost(proxyHost, proxyPort, "http"); + } + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Bad url parameter should not cause any exception. + */ + public void testProxyGetPreferredHttpHost_UrlBad() throws Exception { + assertEquals(mHttpHost, Proxy.getPreferredHttpHost(mContext, null)); + assertEquals(mHttpHost, Proxy.getPreferredHttpHost(mContext, "")); + assertEquals(mHttpHost, Proxy.getPreferredHttpHost(mContext, "bad:")); + assertEquals(mHttpHost, Proxy.getPreferredHttpHost(mContext, "bad")); + assertEquals(mHttpHost, Proxy.getPreferredHttpHost(mContext, "bad:\\")); + assertEquals(mHttpHost, Proxy.getPreferredHttpHost(mContext, "bad://#")); + assertEquals(mHttpHost, Proxy.getPreferredHttpHost(mContext, "://#")); + } + + /** + * Proxy (if available) should be returned when url parameter is not localhost. + */ + public void testProxyGetPreferredHttpHost_UrlNotlLocalhost() throws Exception { + assertEquals(mHttpHost, Proxy.getPreferredHttpHost(mContext, "http://")); + assertEquals(mHttpHost, Proxy.getPreferredHttpHost(mContext, "http://example.com")); + assertEquals(mHttpHost, Proxy.getPreferredHttpHost(mContext, "http://example.com/")); + assertEquals(mHttpHost, Proxy.getPreferredHttpHost(mContext, "http://192.168.0.1/")); + assertEquals(mHttpHost, Proxy.getPreferredHttpHost(mContext, "file:///foo/bar")); + assertEquals(mHttpHost, Proxy.getPreferredHttpHost(mContext, "rtsp://example.com")); + assertEquals(mHttpHost, Proxy.getPreferredHttpHost(mContext, "rtsp://example.com/")); + assertEquals(mHttpHost, Proxy.getPreferredHttpHost(mContext, "javascript:alert(1)")); + } + + /** + * No proxy should be returned when url parameter is localhost. + */ + public void testProxyGetPreferredHttpHost_UrlLocalhost() throws Exception { + assertNull(Proxy.getPreferredHttpHost(mContext, "http://localhost")); + assertNull(Proxy.getPreferredHttpHost(mContext, "http://localhost/")); + assertNull(Proxy.getPreferredHttpHost(mContext, "http://localhost/hej.html")); + assertNull(Proxy.getPreferredHttpHost(mContext, "http://127.0.0.1")); + assertNull(Proxy.getPreferredHttpHost(mContext, "http://127.0.0.1/")); + assertNull(Proxy.getPreferredHttpHost(mContext, "http://127.0.0.1/hej.html")); + assertNull(Proxy.getPreferredHttpHost(mContext, "http://127.0.0.1:80/")); + assertNull(Proxy.getPreferredHttpHost(mContext, "http://127.0.0.1:8080/")); + assertNull(Proxy.getPreferredHttpHost(mContext, "rtsp://127.0.0.1/")); + assertNull(Proxy.getPreferredHttpHost(mContext, "rtsp://localhost/")); + assertNull(Proxy.getPreferredHttpHost(mContext, "https://localhost/")); + } +} diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/FileList.java b/tests/DumpRenderTree/src/com/android/dumprendertree/FileList.java index e741177..73d7363 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/FileList.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/FileList.java @@ -31,6 +31,7 @@ import android.view.View; import android.widget.ListView; import android.widget.SimpleAdapter; import android.os.Bundle; +import android.os.Environment; public abstract class FileList extends ListActivity @@ -179,10 +180,9 @@ public abstract class FileList extends ListActivity getListView().setSelection(mFocusIndex); } - protected void setupPath() - { - mPath = "/sdcard/android/layout_tests"; - mBaseLength = mPath.length(); + protected void setupPath() { + mPath = Environment.getExternalStorageDirectory() + "/android/layout_tests"; + mBaseLength = mPath.length(); } protected String mPath; diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/FsUtils.java b/tests/DumpRenderTree/src/com/android/dumprendertree/FsUtils.java index 322b0d2..6cfce41 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/FsUtils.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/FsUtils.java @@ -18,6 +18,7 @@ package com.android.dumprendertree; import com.android.dumprendertree.forwarder.ForwardService; +import android.os.Environment; import android.util.Log; import java.io.BufferedOutputStream; @@ -32,11 +33,17 @@ import java.util.regex.Pattern; public class FsUtils { private static final String LOGTAG = "FsUtils"; - static final String HTTP_TESTS_PREFIX = "/sdcard/android/layout_tests/http/tests/"; - static final String HTTPS_TESTS_PREFIX = "/sdcard/android/layout_tests/http/tests/ssl/"; - static final String HTTP_LOCAL_TESTS_PREFIX = "/sdcard/android/layout_tests/http/tests/local/"; - static final String HTTP_MEDIA_TESTS_PREFIX = "/sdcard/android/layout_tests/http/tests/media/"; - static final String HTTP_WML_TESTS_PREFIX = "/sdcard/android/layout_tests/http/tests/wml/"; + static final String EXTERNAL_DIR = Environment.getExternalStorageDirectory().toString(); + static final String HTTP_TESTS_PREFIX = + EXTERNAL_DIR + "/android/layout_tests/http/tests/"; + static final String HTTPS_TESTS_PREFIX = + EXTERNAL_DIR + "/android/layout_tests/http/tests/ssl/"; + static final String HTTP_LOCAL_TESTS_PREFIX = + EXTERNAL_DIR + "/android/layout_tests/http/tests/local/"; + static final String HTTP_MEDIA_TESTS_PREFIX = + EXTERNAL_DIR + "/android/layout_tests/http/tests/media/"; + static final String HTTP_WML_TESTS_PREFIX = + EXTERNAL_DIR + "/android/layout_tests/http/tests/wml/"; private FsUtils() { //no creation of instances diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java b/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java index 042158a..9ccf549 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java @@ -18,12 +18,12 @@ package com.android.dumprendertree; import com.android.dumprendertree.TestShellActivity.DumpDataType; import com.android.dumprendertree.forwarder.AdbUtils; -import com.android.dumprendertree.forwarder.ForwardServer; import com.android.dumprendertree.forwarder.ForwardService; import android.app.Instrumentation; import android.content.Intent; import android.os.Bundle; +import android.os.Environment; import android.test.ActivityInstrumentationTestCase2; import android.util.Log; @@ -92,10 +92,11 @@ class MyTestRecorder { public MyTestRecorder(boolean resume) { try { - File resultsPassedFile = new File("/sdcard/layout_tests_passed.txt"); - File resultsFailedFile = new File("/sdcard/layout_tests_failed.txt"); - File resultsIgnoreResultFile = new File("/sdcard/layout_tests_ignored.txt"); - File noExpectedResultFile = new File("/sdcard/layout_tests_nontext.txt"); + File externalDir = Environment.getExternalStorageDirectory(); + File resultsPassedFile = new File(externalDir, "layout_tests_passed.txt"); + File resultsFailedFile = new File(externalDir, "layout_tests_failed.txt"); + File resultsIgnoreResultFile = new File(externalDir, "layout_tests_ignored.txt"); + File noExpectedResultFile = new File(externalDir, "layout_tests_nontext.txt"); mBufferedOutputPassedStream = new BufferedOutputStream(new FileOutputStream(resultsPassedFile, resume)); @@ -128,11 +129,12 @@ public class LayoutTestsAutoTest extends ActivityInstrumentationTestCase2<TestSh private static final String LOGTAG = "LayoutTests"; static final int DEFAULT_TIMEOUT_IN_MILLIS = 5000; - static final String LAYOUT_TESTS_ROOT = "/sdcard/android/layout_tests/"; - static final String LAYOUT_TESTS_RESULT_DIR = "/sdcard/android/layout_tests_results/"; - static final String ANDROID_EXPECTED_RESULT_DIR = "/sdcard/android/expected_results/"; - static final String LAYOUT_TESTS_LIST_FILE = "/sdcard/android/layout_tests_list.txt"; - static final String TEST_STATUS_FILE = "/sdcard/android/running_test.txt"; + static final String EXTERNAL_DIR = Environment.getExternalStorageDirectory().toString(); + static final String LAYOUT_TESTS_ROOT = EXTERNAL_DIR + "/android/layout_tests/"; + static final String LAYOUT_TESTS_RESULT_DIR = EXTERNAL_DIR + "/android/layout_tests_results/"; + static final String ANDROID_EXPECTED_RESULT_DIR = EXTERNAL_DIR + "/android/expected_results/"; + static final String LAYOUT_TESTS_LIST_FILE = EXTERNAL_DIR + "/android/layout_tests_list.txt"; + static final String TEST_STATUS_FILE = EXTERNAL_DIR + "/android/running_test.txt"; static final String LAYOUT_TESTS_RESULTS_REFERENCE_FILES[] = { "results/layout_tests_passed.txt", "results/layout_tests_failed.txt", diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java b/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java index 2ef342f..9352f39 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java @@ -22,6 +22,7 @@ import android.app.Instrumentation; import android.content.Intent; import android.os.Bundle; import android.os.Debug; +import android.os.Environment; import android.os.Process; import android.test.ActivityInstrumentationTestCase2; import android.util.Log; @@ -35,7 +36,8 @@ import java.io.PrintStream; public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShellActivity> { private final static String LOGTAG = "LoadTest"; - private final static String LOAD_TEST_RESULT = "/sdcard/load_test_result.txt"; + private final static String LOAD_TEST_RESULT = + Environment.getExternalStorageDirectory() + "/load_test_result.txt"; private boolean mFinished; static final String LOAD_TEST_RUNNER_FILES[] = { "run_page_cycler.py" diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/Menu.java b/tests/DumpRenderTree/src/com/android/dumprendertree/Menu.java index 82671eb..9c4b572 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/Menu.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/Menu.java @@ -18,6 +18,7 @@ package com.android.dumprendertree; import android.content.Intent; import android.os.Bundle; +import android.os.Environment; import android.util.Log; import java.io.BufferedOutputStream; @@ -28,7 +29,8 @@ public class Menu extends FileList { private static final int MENU_START = 0x01; private static String LOGTAG = "MenuActivity"; - static final String LAYOUT_TESTS_LIST_FILE = "/sdcard/android/layout_tests_list.txt"; + static final String LAYOUT_TESTS_LIST_FILE = + Environment.getExternalStorageDirectory() + "/android/layout_tests_list.txt"; public void onCreate(Bundle icicle) { super.onCreate(icicle); diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTest.java b/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTest.java index 9bc0962..d146fc7 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTest.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTest.java @@ -18,6 +18,7 @@ package com.android.dumprendertree; import android.app.Activity; import android.content.Intent; +import android.os.Environment; import android.os.Handler; import android.os.Message; import android.test.ActivityInstrumentationTestCase2; @@ -37,10 +38,16 @@ public class ReliabilityTest extends ActivityInstrumentationTestCase2<Reliabilit private static final String LOGTAG = "ReliabilityTest"; private static final String PKG_NAME = "com.android.dumprendertree"; - private static final String TEST_LIST_FILE = "/sdcard/android/reliability_tests_list.txt"; - private static final String TEST_STATUS_FILE = "/sdcard/android/reliability_running_test.txt"; - private static final String TEST_TIMEOUT_FILE = "/sdcard/android/reliability_timeout_test.txt"; - private static final String TEST_LOAD_TIME_FILE = "/sdcard/android/reliability_load_time.txt"; + private static final String EXTERNAL_DIR = + Environment.getExternalStorageDirectory().toString(); + private static final String TEST_LIST_FILE = EXTERNAL_DIR + + "/android/reliability_tests_list.txt"; + private static final String TEST_STATUS_FILE = EXTERNAL_DIR + + "/android/reliability_running_test.txt"; + private static final String TEST_TIMEOUT_FILE = EXTERNAL_DIR + + "/android/reliability_timeout_test.txt"; + private static final String TEST_LOAD_TIME_FILE = EXTERNAL_DIR + + "/android/reliability_load_time.txt"; private static final String TEST_DONE = "#DONE"; static final String RELIABILITY_TEST_RUNNER_FILES[] = { "run_reliability_tests.py" diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java index 81d5b08..7475719 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java @@ -30,6 +30,7 @@ import android.graphics.Bitmap.CompressFormat; import android.graphics.Bitmap.Config; import android.net.http.SslError; import android.os.Bundle; +import android.os.Environment; import android.os.Handler; import android.os.Message; import android.util.Log; @@ -862,7 +863,8 @@ public class TestShellActivity extends Activity implements LayoutTestController static final String SAVE_IMAGE = "SaveImage"; static final int DRAW_RUNS = 5; - static final String DRAW_TIME_LOG = "/sdcard/android/page_draw_time.txt"; + static final String DRAW_TIME_LOG = Environment.getExternalStorageDirectory() + + "/android/page_draw_time.txt"; private boolean mGeolocationPermissionSet; private boolean mGeolocationPermission; diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/forwarder/ForwardService.java b/tests/DumpRenderTree/src/com/android/dumprendertree/forwarder/ForwardService.java index 8b7de6e..25dd04fd 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/forwarder/ForwardService.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/forwarder/ForwardService.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; +import android.os.Environment; import android.util.Log; public class ForwardService { @@ -33,7 +34,8 @@ public class ForwardService { private static final String DEFAULT_TEST_HOST = "android-browser-test.mtv.corp.google.com"; - private static final String FORWARD_HOST_CONF = "/sdcard/drt_forward_host.txt"; + private static final String FORWARD_HOST_CONF = + Environment.getExternalStorageDirectory() + "/drt_forward_host.txt"; private ForwardService() { int addr = getForwardHostAddr(); diff --git a/tests/LocationTracker/src/com/android/locationtracker/TrackerActivity.java b/tests/LocationTracker/src/com/android/locationtracker/TrackerActivity.java index 98d0a50..4cfdf6c 100644 --- a/tests/LocationTracker/src/com/android/locationtracker/TrackerActivity.java +++ b/tests/LocationTracker/src/com/android/locationtracker/TrackerActivity.java @@ -28,6 +28,7 @@ import android.content.Intent; import android.database.Cursor; import android.location.LocationManager; import android.os.Bundle; +import android.os.Environment; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; @@ -210,12 +211,11 @@ public class TrackerActivity extends ListActivity { } private String getUniqueFileName(String ext) { - File dir = new File("/sdcard/locationtracker"); + File dir = new File(Environment.getExternalStorageDirectory() + "/locationtracker"); if (!dir.exists()) { dir.mkdir(); } - return "/sdcard/locationtracker/tracking-" + - DateUtils.getCurrentTimestamp() + "." + ext; + return dir + "/tracking-" + DateUtils.getCurrentTimestamp() + "." + ext; } private void launchSettings() { diff --git a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java index 21f3be4..37976ee 100644 --- a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java +++ b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java @@ -16,24 +16,19 @@ package com.android.statusbartest; -import android.app.ListActivity; import android.app.PendingIntent; -import android.widget.ArrayAdapter; -import android.view.View; -import android.widget.ListView; import android.content.Context; import android.content.ContentResolver; import android.content.Intent; import android.app.Notification; import android.app.NotificationManager; +import android.os.Environment; import android.os.Vibrator; -import android.os.Bundle; import android.os.Handler; import android.util.Log; import android.net.Uri; import android.os.SystemClock; import android.widget.RemoteViews; -import android.widget.TextView; import android.os.PowerManager; public class NotificationTestList extends TestActivity @@ -70,7 +65,8 @@ public class NotificationTestList extends TestActivity pm.goToSleep(SystemClock.uptimeMillis()); Notification n = new Notification(); - n.sound = Uri.parse("file:///sdcard/virtual-void.mp3"); + n.sound = Uri.parse("file://" + Environment.getExternalStorageDirectory() + + "/virtual-void.mp3"); Log.d(TAG, "n.sound=" + n.sound); mNM.notify(1, n); |