diff options
author | John Reck <jreck@google.com> | 2010-12-01 12:53:37 -0800 |
---|---|---|
committer | John Reck <jreck@google.com> | 2010-12-02 11:46:27 -0800 |
commit | 4155485914f9e47b8ab22000fe6ef8ddad1f70f4 (patch) | |
tree | 8aae69a540ea177536e4446ed438be842e873abc | |
parent | c8a9fead5139540cdafb7e7dcdfa8d50e98e1b34 (diff) | |
download | packages_apps_Browser-4155485914f9e47b8ab22000fe6ef8ddad1f70f4.zip packages_apps_Browser-4155485914f9e47b8ab22000fe6ef8ddad1f70f4.tar.gz packages_apps_Browser-4155485914f9e47b8ab22000fe6ef8ddad1f70f4.tar.bz2 |
Fixes test errors
Bug: 3248213
Fixes errors in the tests that were caused by missing files, proguard,
and the refactor.
Change-Id: I503dfc7ee42d0173e3a5ad032f58a6f4f310588c
-rw-r--r-- | Android.mk | 3 | ||||
-rw-r--r-- | src/com/android/browser/BrowserActivity.java | 9 | ||||
-rw-r--r-- | tests/assets/popular_urls.txt | 4 | ||||
-rw-r--r-- | tests/src/com/android/browser/JNIBindingsTestApp.java | 6 | ||||
-rw-r--r-- | tests/src/com/android/browser/PopularUrlsTest.java | 63 |
5 files changed, 49 insertions, 36 deletions
@@ -4,7 +4,8 @@ include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_STATIC_JAVA_LIBRARIES := \ - android-common + android-common \ + guava LOCAL_SRC_FILES := \ $(call all-java-files-under, src) \ diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java index 9844547..a8c393a 100644 --- a/src/com/android/browser/BrowserActivity.java +++ b/src/com/android/browser/BrowserActivity.java @@ -16,6 +16,8 @@ package com.android.browser; +import com.google.common.annotations.VisibleForTesting; + import android.app.Activity; import android.content.Intent; import android.content.res.Configuration; @@ -95,16 +97,11 @@ public class BrowserActivity extends Activity { mController.start(icicle, getIntent()); } + @VisibleForTesting Controller getController() { return mController; } - // TODO: this is here for the test classes - // remove once tests are fixed - TabControl getTabControl() { - return mController.getTabControl(); - } - @Override protected void onNewIntent(Intent intent) { mController.handleNewIntent(intent); diff --git a/tests/assets/popular_urls.txt b/tests/assets/popular_urls.txt new file mode 100644 index 0000000..70d0997 --- /dev/null +++ b/tests/assets/popular_urls.txt @@ -0,0 +1,4 @@ +http://google.com +http://nytimes.com +http://slashdot.org + diff --git a/tests/src/com/android/browser/JNIBindingsTestApp.java b/tests/src/com/android/browser/JNIBindingsTestApp.java index 4c8802a..f4efa2c 100644 --- a/tests/src/com/android/browser/JNIBindingsTestApp.java +++ b/tests/src/com/android/browser/JNIBindingsTestApp.java @@ -50,6 +50,7 @@ public class JNIBindingsTestApp extends ActivityInstrumentationTestCase2<Browser private static final int MSG_WEBKIT_DATA_READY = 101; private BrowserActivity mActivity = null; + private Controller mController = null; private Instrumentation mInst = null; private boolean mTestDone = false; @@ -111,6 +112,7 @@ public class JNIBindingsTestApp extends ActivityInstrumentationTestCase2<Browser super.setUp(); mActivity = getActivity(); + mController = mActivity.getController(); mInst = getInstrumentation(); mInst.waitForIdleSync(); @@ -147,7 +149,7 @@ public class JNIBindingsTestApp extends ActivityInstrumentationTestCase2<Browser * and wrapping the WebView's helper clients. */ void setUpBrowser() { - Tab tab = mActivity.getTabControl().getCurrentTab(); + Tab tab = mController.getTabControl().getCurrentTab(); WebView webView = tab.getWebView(); webView.addJavascriptInterface(new JNIBindingsTest(this), "JNIBindingsTest"); @@ -229,7 +231,7 @@ public class JNIBindingsTestApp extends ActivityInstrumentationTestCase2<Browser public void testJNIBindings() { setUpBrowser(); - Tab tab = mActivity.getTabControl().getCurrentTab(); + Tab tab = mController.getTabControl().getCurrentTab(); WebView webView = tab.getWebView(); webView.loadUrl("file://" + SDCARD_BINDINGS_TEST_HTML); synchronized(this) { diff --git a/tests/src/com/android/browser/PopularUrlsTest.java b/tests/src/com/android/browser/PopularUrlsTest.java index 98a0e9f..ad1fe4f 100644 --- a/tests/src/com/android/browser/PopularUrlsTest.java +++ b/tests/src/com/android/browser/PopularUrlsTest.java @@ -17,11 +17,13 @@ package com.android.browser; import android.app.Instrumentation; +import android.content.Context; import android.content.Intent; +import android.content.res.AssetManager; import android.net.Uri; import android.net.http.SslError; -import android.os.Environment; import android.test.ActivityInstrumentationTestCase2; +import android.text.TextUtils; import android.util.Log; import android.webkit.HttpAuthHandler; import android.webkit.JsPromptResult; @@ -35,6 +37,7 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.Iterator; import java.util.LinkedList; @@ -53,13 +56,13 @@ public class PopularUrlsTest extends ActivityInstrumentationTestCase2<BrowserAct private final static String sInputFile = "popular_urls.txt"; private final static String sOutputFile = "test_output.txt"; private final static String sStatusFile = "test_status.txt"; - private final static File sExternalStorage = Environment.getExternalStorageDirectory(); private final static int PERF_LOOPCOUNT = 10; private final static int STABILITY_LOOPCOUNT = 1; private final static int PAGE_LOAD_TIMEOUT = 120000; // 2 minutes private BrowserActivity mActivity = null; + private Controller mController = null; private Instrumentation mInst = null; private CountDownLatch mLatch = new CountDownLatch(1); private RunStatus mStatus; @@ -76,10 +79,11 @@ public class PopularUrlsTest extends ActivityInstrumentationTestCase2<BrowserAct Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("about:blank")); setActivityIntent(i); mActivity = getActivity(); + mController = mActivity.getController(); mInst = getInstrumentation(); mInst.waitForIdleSync(); - mStatus = RunStatus.load(); + mStatus = RunStatus.load(getInstrumentation().getContext()); } @Override @@ -91,16 +95,10 @@ public class PopularUrlsTest extends ActivityInstrumentationTestCase2<BrowserAct super.tearDown(); } - static BufferedReader getInputStream() throws FileNotFoundException { - return getInputStream(sInputFile); - } - - static BufferedReader getInputStream(String inputFile) throws FileNotFoundException { - String path = sExternalStorage + File.separator + inputFile; - FileReader fileReader = new FileReader(path); - BufferedReader bufferedReader = new BufferedReader(fileReader); - - return bufferedReader; + BufferedReader getInputStream() throws IOException { + AssetManager assets = getInstrumentation().getContext().getAssets(); + return new BufferedReader( + new InputStreamReader(assets.open(sInputFile))); } OutputStreamWriter getOutputStream() throws IOException { @@ -108,10 +106,8 @@ public class PopularUrlsTest extends ActivityInstrumentationTestCase2<BrowserAct } OutputStreamWriter getOutputStream(String outputFile) throws IOException { - String path = sExternalStorage + File.separator + outputFile; - - File file = new File(path); - + File file = new File(getInstrumentation().getContext() + .getExternalFilesDir(null), outputFile); return new FileWriter(file, mStatus.getIsRecovery()); } @@ -120,7 +116,16 @@ public class PopularUrlsTest extends ActivityInstrumentationTestCase2<BrowserAct * and wrapping the WebView's helper clients. */ void setUpBrowser() { - Tab tab = mActivity.getTabControl().getCurrentTab(); + mInst.runOnMainSync(new Runnable() { + @Override + public void run() { + setupBrowserInternal(); + } + }); + } + + void setupBrowserInternal() { + Tab tab = mController.getTabControl().getCurrentTab(); WebView webView = tab.getWebView(); webView.setWebChromeClient(new TestWebChromeClient(webView.getWebChromeClient()) { @@ -219,6 +224,7 @@ public class PopularUrlsTest extends ActivityInstrumentationTestCase2<BrowserAct */ @Override public void onPageFinished(WebView view, String url) { + super.onPageFinished(view, url); if (!pageLoadFinishCalled) { pageLoadFinishCalled = true; if (pageProgressFull) { @@ -252,7 +258,7 @@ public class PopularUrlsTest extends ActivityInstrumentationTestCase2<BrowserAct // try to stop page load mInst.runOnMainSync(new Runnable(){ public void run() { - mActivity.getTabControl().getCurrentTab().getWebView().stopLoading(); + mController.getTabControl().getCurrentTab().getWebView().stopLoading(); } }); // try to wait for count down latch again @@ -270,8 +276,8 @@ public class PopularUrlsTest extends ActivityInstrumentationTestCase2<BrowserAct private String url; private boolean isRecovery; - private RunStatus(String file) throws IOException { - mFile = new File(file); + private RunStatus(File file) throws IOException { + mFile = file; FileReader input = null; BufferedReader reader = null; isRecovery = false; @@ -307,12 +313,13 @@ public class PopularUrlsTest extends ActivityInstrumentationTestCase2<BrowserAct } } - public static RunStatus load() throws IOException { - return load(sStatusFile); + public static RunStatus load(Context context) throws IOException { + return load(context, sStatusFile); } - public static RunStatus load(String file) throws IOException { - return new RunStatus(sExternalStorage + File.separator + file); + public static RunStatus load(Context context, String file) throws IOException { + return new RunStatus(new File( + context.getExternalFilesDir(null), file)); } public void write() throws IOException { @@ -380,14 +387,16 @@ public class PopularUrlsTest extends ActivityInstrumentationTestCase2<BrowserAct void loopUrls(BufferedReader input, OutputStreamWriter writer, boolean clearCache, int loopCount) throws IOException, InterruptedException { - Tab tab = mActivity.getTabControl().getCurrentTab(); + Tab tab = mController.getTabControl().getCurrentTab(); WebView webView = tab.getWebView(); List<String> pages = new LinkedList<String>(); String page; while (null != (page = input.readLine())) { - pages.add(page); + if (!TextUtils.isEmpty(page)) { + pages.add(page); + } } Iterator<String> iterator = pages.iterator(); |