diff options
Diffstat (limited to 'tests')
19 files changed, 223 insertions, 2673 deletions
diff --git a/tests/VectorDrawableTest/res/anim/animation_favorite.xml b/tests/VectorDrawableTest/res/anim/animation_favorite.xml index 2e2d9bb..13bd6f5 100644 --- a/tests/VectorDrawableTest/res/anim/animation_favorite.xml +++ b/tests/VectorDrawableTest/res/anim/animation_favorite.xml @@ -45,12 +45,6 @@ android:valueTo="#FF00FF00" /> <objectAnimator android:duration="8000" - android:propertyName="strokeWidth" - android:repeatCount="-1" - android:valueFrom="5" - android:valueTo="20" /> - <objectAnimator - android:duration="8000" android:propertyName="fillColor" android:repeatCount="-1" android:valueFrom="#FFFF0000" diff --git a/tests/VectorDrawableTest/res/drawable/vector_drawable_favorite.xml b/tests/VectorDrawableTest/res/drawable/vector_drawable_favorite.xml index 7be49a9..f93486e 100644 --- a/tests/VectorDrawableTest/res/drawable/vector_drawable_favorite.xml +++ b/tests/VectorDrawableTest/res/drawable/vector_drawable_favorite.xml @@ -26,6 +26,7 @@ <path android:name="favorite" android:fillColor="#ff000000" + android:strokeWidth="2" android:pathData="M2.100006104,-6 C0.1449127197,-6,1.600006104,-5.975006104,0,-5.975006104 C-1.574996948,-5.975006104,0.00309753418,-6-1.949996948-6 diff --git a/tests/VoiceInteraction/res/layout/voice_interaction_session.xml b/tests/VoiceInteraction/res/layout/voice_interaction_session.xml index d44afb0..610f30b 100644 --- a/tests/VoiceInteraction/res/layout/voice_interaction_session.xml +++ b/tests/VoiceInteraction/res/layout/voice_interaction_session.xml @@ -18,6 +18,11 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + <ImageView android:id="@+id/full_screenshot" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:visibility="invisible"/> + <com.android.test.voiceinteraction.AssistVisualizer android:id="@+id/assist_visualizer" android:layout_width="match_parent" android:layout_height="match_parent" /> @@ -30,19 +35,29 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" - android:orientation="vertical" + android:orientation="horizontal" android:background="#ffffffff" android:elevation="8dp" > - <Button android:id="@+id/start" + <ImageView android:id="@+id/screenshot" + android:layout_width="wrap_content" + android:layout_height="46dp" + android:adjustViewBounds="true" /> + <View android:layout_width="0dp" + android:layout_height="0dp" + android:layout_weight="1" /> + <Button android:id="@+id/do_tree" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_gravity="top|right" - android:text="@string/start" - /> - <ImageView android:id="@+id/screenshot" + android:text="@string/tree" /> + <Button android:id="@+id/do_text" android:layout_width="wrap_content" - android:layout_height="wrap_content"/> + android:layout_height="wrap_content" + android:text="@string/text" /> + <Button android:id="@+id/start" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/start" /> </LinearLayout> <LinearLayout android:id="@+id/bottom_content" @@ -58,26 +73,22 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" - android:textAppearance="?android:attr/textAppearanceMedium" - /> + android:textAppearance="?android:attr/textAppearanceMedium" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/confirm" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/confirm" - /> + android:text="@string/confirm" /> <Button android:id="@+id/complete" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/complete" - /> + android:text="@string/complete" /> <Button android:id="@+id/abort" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/abort" - /> + android:text="@string/abort" /> </LinearLayout> </LinearLayout> diff --git a/tests/VoiceInteraction/res/values/strings.xml b/tests/VoiceInteraction/res/values/strings.xml index 6289929..4cf4104 100644 --- a/tests/VoiceInteraction/res/values/strings.xml +++ b/tests/VoiceInteraction/res/values/strings.xml @@ -17,6 +17,8 @@ <resources> <string name="start">Start</string> + <string name="tree">Tree</string> + <string name="text">Text</string> <string name="asyncStructure">(Async structure goes here)</string> <string name="confirm">Confirm</string> <string name="abort">Abort</string> diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java index 8a72341..339755f 100644 --- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java @@ -17,9 +17,10 @@ package com.android.test.voiceinteraction; import android.annotation.Nullable; -import android.app.AssistStructure; +import android.app.assist.AssistStructure; import android.content.Context; import android.graphics.Canvas; +import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Rect; import android.util.AttributeSet; @@ -31,10 +32,32 @@ import java.util.ArrayList; public class AssistVisualizer extends View { static final String TAG = "AssistVisualizer"; + static class TextEntry { + final Rect bounds; + final int parentLeft, parentTop; + final Matrix matrix; + final String className; + final CharSequence text; + + TextEntry(AssistStructure.ViewNode node, int parentLeft, int parentTop, Matrix matrix) { + int left = parentLeft+node.getLeft(); + int top = parentTop+node.getTop(); + bounds = new Rect(left, top, left+node.getWidth(), top+node.getHeight()); + this.parentLeft = parentLeft; + this.parentTop = parentTop; + this.matrix = new Matrix(matrix); + this.className = node.getClassName(); + this.text = node.getText() != null ? node.getText() : node.getContentDescription(); + } + } + AssistStructure mAssistStructure; final Paint mFramePaint = new Paint(); - final ArrayList<Rect> mTextRects = new ArrayList<>(); + final Paint mFrameNoTransformPaint = new Paint(); + final ArrayList<Matrix> mMatrixStack = new ArrayList<>(); + final ArrayList<TextEntry> mTextRects = new ArrayList<>(); final int[] mTmpLocation = new int[2]; + final float[] mTmpMatrixPoint = new float[2]; public AssistVisualizer(Context context, @Nullable AttributeSet attrs) { super(context, attrs); @@ -42,17 +65,26 @@ public class AssistVisualizer extends View { mFramePaint.setColor(0xffff0000); mFramePaint.setStyle(Paint.Style.STROKE); mFramePaint.setStrokeWidth(0); + float density = getResources().getDisplayMetrics().density; + mFramePaint.setShadowLayer(density, density, density, 0xff000000); + mFrameNoTransformPaint.setColor(0xff0000ff); + mFrameNoTransformPaint.setStyle(Paint.Style.STROKE); + mFrameNoTransformPaint.setStrokeWidth(0); + mFrameNoTransformPaint.setShadowLayer(density, density, density, 0xff000000); } public void setAssistStructure(AssistStructure as) { mAssistStructure = as; - mAssistStructure.dump(); mTextRects.clear(); final int N = as.getWindowNodeCount(); if (N > 0) { for (int i=0; i<N; i++) { AssistStructure.WindowNode windowNode = as.getWindowNodeAt(i); - buildTextRects(windowNode.getRootViewNode(), windowNode.getLeft(), + mMatrixStack.clear(); + Matrix matrix = new Matrix(); + matrix.setTranslate(windowNode.getLeft(), windowNode.getTop()); + mMatrixStack.add(matrix); + buildTextRects(windowNode.getRootViewNode(), 0, windowNode.getLeft(), windowNode.getTop()); } } @@ -60,31 +92,62 @@ public class AssistVisualizer extends View { invalidate(); } + public void logTree() { + if (mAssistStructure != null) { + mAssistStructure.dump(); + } + } + + public void logText() { + final int N = mTextRects.size(); + for (int i=0; i<N; i++) { + TextEntry te = mTextRects.get(i); + Log.d(TAG, "View " + te.className + " " + te.bounds.toShortString() + + " in " + te.parentLeft + "," + te.parentTop + + " matrix=" + te.matrix.toShortString() + ": " + + te.text); + } + } + public void clearAssistData() { mAssistStructure = null; mTextRects.clear(); } - void buildTextRects(AssistStructure.ViewNode root, int parentLeft, int parentTop) { + void buildTextRects(AssistStructure.ViewNode root, int matrixStackIndex, + int parentLeft, int parentTop) { if (root.getVisibility() != View.VISIBLE) { return; } - int left = parentLeft+root.getLeft(); - int top = parentTop+root.getTop(); + Matrix parentMatrix = mMatrixStack.get(matrixStackIndex); + matrixStackIndex++; + Matrix matrix; + if (mMatrixStack.size() > matrixStackIndex) { + matrix = mMatrixStack.get(matrixStackIndex); + matrix.set(parentMatrix); + } else { + matrix = new Matrix(parentMatrix); + mMatrixStack.add(matrix); + } + matrix.preTranslate(root.getLeft(), root.getTop()); + int left = parentLeft + root.getLeft(); + int top = parentTop + root.getTop(); + Matrix transform = root.getTransformation(); + if (transform != null) { + matrix.preConcat(transform); + } if (root.getText() != null || root.getContentDescription() != null) { - Rect r = new Rect(left, top, left+root.getWidth(), top+root.getHeight()); - Log.d(TAG, "View " + root.getClassName() + " " + left + "," + top + " tr " - + r.toShortString() + ": " - + (root.getText() != null ? root.getText() : root.getContentDescription())); - mTextRects.add(r); + TextEntry te = new TextEntry(root, parentLeft, parentTop, matrix); + mTextRects.add(te); } final int N = root.getChildCount(); if (N > 0) { left -= root.getScrollX(); top -= root.getScrollY(); + matrix.preTranslate(-root.getScrollX(), -root.getScrollY()); for (int i=0; i<N; i++) { AssistStructure.ViewNode child = root.getChildAt(i); - buildTextRects(child, left, top); + buildTextRects(child, matrixStackIndex, left, top); } } } @@ -96,9 +159,19 @@ public class AssistVisualizer extends View { final int N = mTextRects.size(); Log.d(TAG, "Drawing text rects in " + this + ": found " + mTextRects.size()); for (int i=0; i<N; i++) { - Rect r = mTextRects.get(i); - canvas.drawRect(r.left-mTmpLocation[0], r.top-mTmpLocation[1], - r.right-mTmpLocation[0], r.bottom-mTmpLocation[1], mFramePaint); + TextEntry te = mTextRects.get(i); + canvas.drawRect(te.bounds.left - mTmpLocation[0], te.bounds.top - mTmpLocation[1], + te.bounds.right - mTmpLocation[0], te.bounds.bottom - mTmpLocation[1], + mFrameNoTransformPaint); + } + for (int i=0; i<N; i++) { + TextEntry te = mTextRects.get(i); + canvas.save(); + canvas.translate(-mTmpLocation[0], -mTmpLocation[1]); + canvas.concat(te.matrix); + canvas.drawRect(0, 0, te.bounds.right - te.bounds.left, te.bounds.bottom - te.bounds.top, + mFramePaint); + canvas.restore(); } } } diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java index 3090a11..97c1e85 100644 --- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java @@ -18,8 +18,8 @@ package com.android.test.voiceinteraction; import android.app.ActivityManager; import android.app.VoiceInteractor; -import android.app.AssistContent; -import android.app.AssistStructure; +import android.app.assist.AssistContent; +import android.app.assist.AssistStructure; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; @@ -42,8 +42,11 @@ public class MainInteractionSession extends VoiceInteractionSession View mTopContent; View mBottomContent; TextView mText; + Button mTreeButton; + Button mTextButton; Button mStartButton; ImageView mScreenshot; + ImageView mFullScreenshot; Button mConfirmButton; Button mCompleteButton; Button mAbortButton; @@ -110,9 +113,15 @@ public class MainInteractionSession extends VoiceInteractionSession mTopContent = mContentView.findViewById(R.id.top_content); mBottomContent = mContentView.findViewById(R.id.bottom_content); mText = (TextView)mContentView.findViewById(R.id.text); + mTreeButton = (Button)mContentView.findViewById(R.id.do_tree); + mTreeButton.setOnClickListener(this); + mTextButton = (Button)mContentView.findViewById(R.id.do_text); + mTextButton.setOnClickListener(this); mStartButton = (Button)mContentView.findViewById(R.id.start); mStartButton.setOnClickListener(this); mScreenshot = (ImageView)mContentView.findViewById(R.id.screenshot); + mScreenshot.setOnClickListener(this); + mFullScreenshot = (ImageView)mContentView.findViewById(R.id.full_screenshot); mConfirmButton = (Button)mContentView.findViewById(R.id.confirm); mConfirmButton.setOnClickListener(this); mCompleteButton = (Button)mContentView.findViewById(R.id.complete); @@ -123,34 +132,8 @@ public class MainInteractionSession extends VoiceInteractionSession } public void onHandleAssist(Bundle assistBundle) { - boolean hasStructure = false; - if (assistBundle != null) { - Bundle assistContext = assistBundle.getBundle(Intent.EXTRA_ASSIST_CONTEXT); - if (assistContext != null) { - mAssistStructure = AssistStructure.getAssistStructure(assistContext); - if (mAssistStructure != null) { - if (mAssistVisualizer != null) { - mAssistVisualizer.setAssistStructure(mAssistStructure); - hasStructure = true; - } - } - AssistContent content = AssistContent.getAssistContent(assistContext); - if (content != null) { - Log.i(TAG, "Assist intent: " + content.getIntent()); - Log.i(TAG, "Assist clipdata: " + content.getClipData()); - } - } - Uri referrer = assistBundle.getParcelable(Intent.EXTRA_REFERRER); - if (referrer != null) { - Log.i(TAG, "Referrer: " + referrer); - } - } - if (!hasStructure && mAssistVisualizer != null) { - mAssistVisualizer.clearAssistData(); - } } - /* @Override public void onHandleAssist(Bundle data, AssistStructure structure, AssistContent content) { mAssistStructure = structure; @@ -158,13 +141,22 @@ public class MainInteractionSession extends VoiceInteractionSession if (mAssistVisualizer != null) { mAssistVisualizer.setAssistStructure(mAssistStructure); } + } else { + if (mAssistVisualizer != null) { + mAssistVisualizer.clearAssistData(); + } } if (content != null) { Log.i(TAG, "Assist intent: " + content.getIntent()); Log.i(TAG, "Assist clipdata: " + content.getClipData()); } + if (data != null) { + Uri referrer = data.getParcelable(Intent.EXTRA_REFERRER); + if (referrer != null) { + Log.i(TAG, "Referrer: " + referrer); + } + } } - */ @Override public void onHandleScreenshot(Bitmap screenshot) { @@ -173,8 +165,10 @@ public class MainInteractionSession extends VoiceInteractionSession mScreenshot.setAdjustViewBounds(true); mScreenshot.setMaxWidth(screenshot.getWidth()/3); mScreenshot.setMaxHeight(screenshot.getHeight()/3); + mFullScreenshot.setImageBitmap(screenshot); } else { mScreenshot.setImageDrawable(null); + mFullScreenshot.setImageDrawable(null); } } @@ -200,7 +194,15 @@ public class MainInteractionSession extends VoiceInteractionSession } public void onClick(View v) { - if (v == mStartButton) { + if (v == mTreeButton) { + if (mAssistVisualizer != null) { + mAssistVisualizer.logTree(); + } + } else if (v == mTextButton) { + if (mAssistVisualizer != null) { + mAssistVisualizer.logText(); + } + } else if (v == mStartButton) { mState = STATE_LAUNCHING; updateState(); startVoiceActivity(mStartIntent); @@ -236,9 +238,15 @@ public class MainInteractionSession extends VoiceInteractionSession } else if (v == mAbortButton) { mPendingRequest.sendAbortVoiceResult(null); mPendingRequest = null; - } else if (v== mCompleteButton) { + } else if (v == mCompleteButton) { mPendingRequest.sendCompleteVoiceResult(null); mPendingRequest = null; + } else if (v == mScreenshot) { + if (mFullScreenshot.getVisibility() != View.VISIBLE) { + mFullScreenshot.setVisibility(View.VISIBLE); + } else { + mFullScreenshot.setVisibility(View.INVISIBLE); + } } updateState(); } diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java index c038414..943c647 100644 --- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java @@ -16,6 +16,7 @@ package com.android.test.voiceinteraction; +import android.annotation.Nullable; import android.app.Activity; import android.app.VoiceInteractor; import android.content.ComponentName; @@ -111,38 +112,10 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis @Override public void onClick(View v) { if (v == mAbortButton) { - VoiceInteractor.AbortVoiceRequest req = new VoiceInteractor.AbortVoiceRequest( - new VoiceInteractor.Prompt("Dammit, we suck :("), null) { - @Override - public void onCancel() { - Log.i(TAG, "Canceled!"); - mLog.append("Canceled abort\n"); - } - - @Override - public void onAbortResult(Bundle result) { - Log.i(TAG, "Abort result: result=" + result); - mLog.append("Abort: result=" + result + "\n"); - getActivity().finish(); - } - }; + VoiceInteractor.AbortVoiceRequest req = new TestAbortVoice(); mInteractor.submitRequest(req, REQUEST_ABORT); } else if (v == mCompleteButton) { - VoiceInteractor.CompleteVoiceRequest req = new VoiceInteractor.CompleteVoiceRequest( - new VoiceInteractor.Prompt("Woohoo, completed!"), null) { - @Override - public void onCancel() { - Log.i(TAG, "Canceled!"); - mLog.append("Canceled complete\n"); - } - - @Override - public void onCompleteResult(Bundle result) { - Log.i(TAG, "Complete result: result=" + result); - mLog.append("Complete: result=" + result + "\n"); - getActivity().finish(); - } - }; + VoiceInteractor.CompleteVoiceRequest req = new TestCompleteVoice(); mInteractor.submitRequest(req, REQUEST_COMPLETE); } else if (v == mPickButton) { VoiceInteractor.PickOptionRequest.Option[] options = @@ -152,36 +125,7 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis options[2] = new VoiceInteractor.PickOptionRequest.Option("Three"); options[3] = new VoiceInteractor.PickOptionRequest.Option("Four"); options[4] = new VoiceInteractor.PickOptionRequest.Option("Five"); - VoiceInteractor.PickOptionRequest req = new VoiceInteractor.PickOptionRequest( - new VoiceInteractor.Prompt("Need to pick something"), options, null) { - @Override - public void onCancel() { - Log.i(TAG, "Canceled!"); - mLog.append("Canceled pick\n"); - } - - @Override - public void onPickOptionResult(boolean finished, Option[] selections, Bundle result) { - Log.i(TAG, "Pick result: finished=" + finished + " selections=" + selections - + " result=" + result); - StringBuilder sb = new StringBuilder(); - if (finished) { - sb.append("Pick final result: "); - } else { - sb.append("Pick intermediate result: "); - } - for (int i=0; i<selections.length; i++) { - if (i >= 1) { - sb.append(", "); - } - sb.append(selections[i].getLabel()); - } - mLog.append(sb.toString()); - if (finished) { - getActivity().finish(); - } - } - }; + VoiceInteractor.PickOptionRequest req = new TestPickOption(options); mInteractor.submitRequest(req, REQUEST_PICK); } else if (v == mJumpOutButton) { Log.i(TAG, "Jump out"); @@ -200,4 +144,66 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis public void onDestroy() { super.onDestroy(); } + + static class TestAbortVoice extends VoiceInteractor.AbortVoiceRequest { + public TestAbortVoice() { + super(new VoiceInteractor.Prompt("Dammit, we suck :("), null); + } + @Override public void onCancel() { + Log.i(TAG, "Canceled!"); + ((TestInteractionActivity)getActivity()).mLog.append("Canceled abort\n"); + } + @Override public void onAbortResult(Bundle result) { + Log.i(TAG, "Abort result: result=" + result); + ((TestInteractionActivity)getActivity()).mLog.append("Abort: result=" + result + "\n"); + getActivity().finish(); + } + } + + static class TestCompleteVoice extends VoiceInteractor.CompleteVoiceRequest { + public TestCompleteVoice() { + super(new VoiceInteractor.Prompt("Woohoo, completed!"), null); + } + @Override public void onCancel() { + Log.i(TAG, "Canceled!"); + ((TestInteractionActivity)getActivity()).mLog.append("Canceled complete\n"); + } + @Override public void onCompleteResult(Bundle result) { + Log.i(TAG, "Complete result: result=" + result); + ((TestInteractionActivity)getActivity()).mLog.append("Complete: result=" + + result + "\n"); + getActivity().finish(); + } + } + + static class TestPickOption extends VoiceInteractor.PickOptionRequest { + public TestPickOption(Option[] options) { + super(new VoiceInteractor.Prompt("Need to pick something"), options, null); + } + @Override public void onCancel() { + Log.i(TAG, "Canceled!"); + ((TestInteractionActivity)getActivity()).mLog.append("Canceled pick\n"); + } + @Override + public void onPickOptionResult(boolean finished, Option[] selections, Bundle result) { + Log.i(TAG, "Pick result: finished=" + finished + " selections=" + selections + + " result=" + result); + StringBuilder sb = new StringBuilder(); + if (finished) { + sb.append("Pick final result: "); + } else { + sb.append("Pick intermediate result: "); + } + for (int i=0; i<selections.length; i++) { + if (i >= 1) { + sb.append(", "); + } + sb.append(selections[i].getLabel()); + } + ((TestInteractionActivity)getActivity()).mLog.append(sb.toString()); + if (finished) { + getActivity().finish(); + } + } + } } diff --git a/tests/WebViewTests/Android.mk b/tests/WebViewTests/Android.mk deleted file mode 100644 index b118845..0000000 --- a/tests/WebViewTests/Android.mk +++ /dev/null @@ -1,27 +0,0 @@ -# -# Copyright (C) 2011 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. -# -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_SRC_FILES := $(call all-subdir-java-files) - -LOCAL_JAVA_LIBRARIES := android.test.runner - -LOCAL_PACKAGE_NAME := WebViewTests - -include $(BUILD_PACKAGE) diff --git a/tests/WebViewTests/AndroidManifest.xml b/tests/WebViewTests/AndroidManifest.xml deleted file mode 100644 index 8b080c1..0000000 --- a/tests/WebViewTests/AndroidManifest.xml +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- -Copyright (C) 2011 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. ---> - -<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.webviewtests"> - <application> - <uses-library android:name="android.test.runner" /> - <activity android:name="WebViewStubActivity" android:label="WebViewStubActivity"> - <intent-filter> - <action android:name="android.intent.action.MAIN" /> - <category android:name="android.intent.category.TEST" /> - </intent-filter> - </activity> - </application> - - <instrumentation android:name="android.test.InstrumentationTestRunner" - android:targetPackage="com.android.webviewtests" - android:label="Tests for android.webkit.WebView" /> -</manifest> diff --git a/tests/WebViewTests/res/layout/webview_layout.xml b/tests/WebViewTests/res/layout/webview_layout.xml deleted file mode 100644 index d266d21..0000000 --- a/tests/WebViewTests/res/layout/webview_layout.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - --> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" - android:layout_width="match_parent" - android:layout_height="match_parent"> - - <WebView android:id="@+id/web_page" - android:layout_width="match_parent" - android:layout_height="match_parent" /> -</LinearLayout> diff --git a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayCoercionTest.java b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayCoercionTest.java deleted file mode 100644 index c2bbdf5..0000000 --- a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayCoercionTest.java +++ /dev/null @@ -1,625 +0,0 @@ -/* - * Copyright (C) 2011 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. - */ - -/** - * Part of the test suite for the WebView's Java Bridge. This class tests that - * we correctly convert JavaScript arrays to Java arrays when passing them to - * the methods of injected Java objects. - * - * The conversions should follow - * http://jdk6.java.net/plugin2/liveconnect/#JS_JAVA_CONVERSIONS. Places in - * which the implementation differs from the spec are marked with - * LIVECONNECT_COMPLIANCE. - * FIXME: Consider making our implementation more compliant, if it will not - * break backwards-compatibility. See b/4408210. - * - * To run this test ... - * adb shell am instrument -w -e class com.android.webviewtests.JavaBridgeArrayCoercionTest \ - * com.android.webviewtests/android.test.InstrumentationTestRunner - */ - -package com.android.webviewtests; - -public class JavaBridgeArrayCoercionTest extends JavaBridgeTestBase { - private class TestObject extends Controller { - private Object mObjectInstance; - private CustomType mCustomTypeInstance; - - private boolean[] mBooleanArray; - private byte[] mByteArray; - private char[] mCharArray; - private short[] mShortArray; - private int[] mIntArray; - private long[] mLongArray; - private float[] mFloatArray; - private double[] mDoubleArray; - private String[] mStringArray; - private Object[] mObjectArray; - private CustomType[] mCustomTypeArray; - - public TestObject() { - mObjectInstance = new Object(); - mCustomTypeInstance = new CustomType(); - } - - public Object getObjectInstance() { - return mObjectInstance; - } - public CustomType getCustomTypeInstance() { - return mCustomTypeInstance; - } - - public synchronized void setBooleanArray(boolean[] x) { - mBooleanArray = x; - notifyResultIsReady(); - } - public synchronized void setByteArray(byte[] x) { - mByteArray = x; - notifyResultIsReady(); - } - public synchronized void setCharArray(char[] x) { - mCharArray = x; - notifyResultIsReady(); - } - public synchronized void setShortArray(short[] x) { - mShortArray = x; - notifyResultIsReady(); - } - public synchronized void setIntArray(int[] x) { - mIntArray = x; - notifyResultIsReady(); - } - public synchronized void setLongArray(long[] x) { - mLongArray = x; - notifyResultIsReady(); - } - public synchronized void setFloatArray(float[] x) { - mFloatArray = x; - notifyResultIsReady(); - } - public synchronized void setDoubleArray(double[] x) { - mDoubleArray = x; - notifyResultIsReady(); - } - public synchronized void setStringArray(String[] x) { - mStringArray = x; - notifyResultIsReady(); - } - public synchronized void setObjectArray(Object[] x) { - mObjectArray = x; - notifyResultIsReady(); - } - public synchronized void setCustomTypeArray(CustomType[] x) { - mCustomTypeArray = x; - notifyResultIsReady(); - } - - public synchronized boolean[] waitForBooleanArray() { - waitForResult(); - return mBooleanArray; - } - public synchronized byte[] waitForByteArray() { - waitForResult(); - return mByteArray; - } - public synchronized char[] waitForCharArray() { - waitForResult(); - return mCharArray; - } - public synchronized short[] waitForShortArray() { - waitForResult(); - return mShortArray; - } - public synchronized int[] waitForIntArray() { - waitForResult(); - return mIntArray; - } - public synchronized long[] waitForLongArray() { - waitForResult(); - return mLongArray; - } - public synchronized float[] waitForFloatArray() { - waitForResult(); - return mFloatArray; - } - public synchronized double[] waitForDoubleArray() { - waitForResult(); - return mDoubleArray; - } - public synchronized String[] waitForStringArray() { - waitForResult(); - return mStringArray; - } - public synchronized Object[] waitForObjectArray() { - waitForResult(); - return mObjectArray; - } - public synchronized CustomType[] waitForCustomTypeArray() { - waitForResult(); - return mCustomTypeArray; - } - } - - // Two custom types used when testing passing objects. - private class CustomType { - } - - private TestObject mTestObject; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mTestObject = new TestObject(); - setUpWebView(mTestObject, "testObject"); - } - - // Note that all tests use a single element array for simplicity. We test - // multiple elements elsewhere. - - // Test passing an array of JavaScript numbers in the int32 range to a - // method which takes a Java array. - public void testPassNumberInt32() throws Throwable { - executeJavaScript("testObject.setBooleanArray([0]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - // LIVECONNECT_COMPLIANCE: Should convert to boolean. - executeJavaScript("testObject.setBooleanArray([42]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - executeJavaScript("testObject.setByteArray([42]);"); - assertEquals(42, mTestObject.waitForByteArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should convert to numeric char value. - executeJavaScript("testObject.setCharArray([42]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - - executeJavaScript("testObject.setShortArray([42]);"); - assertEquals(42, mTestObject.waitForShortArray()[0]); - - executeJavaScript("testObject.setIntArray([42]);"); - assertEquals(42, mTestObject.waitForIntArray()[0]); - - executeJavaScript("testObject.setLongArray([42]);"); - assertEquals(42L, mTestObject.waitForLongArray()[0]); - - executeJavaScript("testObject.setFloatArray([42]);"); - assertEquals(42.0f, mTestObject.waitForFloatArray()[0]); - - executeJavaScript("testObject.setDoubleArray([42]);"); - assertEquals(42.0, mTestObject.waitForDoubleArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number. - executeJavaScript("testObject.setObjectArray([42]);"); - assertNull(mTestObject.waitForObjectArray()); - - // LIVECONNECT_COMPLIANCE: Should create instances of java.lang.String. - executeJavaScript("testObject.setStringArray([42]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeArray([42]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of JavaScript numbers in the double range to a - // method which takes a Java array. - public void testPassNumberDouble() throws Throwable { - // LIVECONNECT_COMPLIANCE: Should convert to boolean. - executeJavaScript("testObject.setBooleanArray([42.1]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - executeJavaScript("testObject.setByteArray([42.1]);"); - assertEquals(42, mTestObject.waitForByteArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should convert to numeric char value. - executeJavaScript("testObject.setCharArray([42.1]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - - executeJavaScript("testObject.setShortArray([42.1]);"); - assertEquals(42, mTestObject.waitForShortArray()[0]); - - executeJavaScript("testObject.setIntArray([42.1]);"); - assertEquals(42, mTestObject.waitForIntArray()[0]); - - executeJavaScript("testObject.setLongArray([42.1]);"); - assertEquals(42L, mTestObject.waitForLongArray()[0]); - - executeJavaScript("testObject.setFloatArray([42.1]);"); - assertEquals(42.1f, mTestObject.waitForFloatArray()[0]); - - executeJavaScript("testObject.setDoubleArray([42.1]);"); - assertEquals(42.1, mTestObject.waitForDoubleArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number. - executeJavaScript("testObject.setObjectArray([42.1]);"); - assertNull(mTestObject.waitForObjectArray()); - - // LIVECONNECT_COMPLIANCE: Should create instances of java.lang.String. - executeJavaScript("testObject.setStringArray([42.1]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeArray([42.1]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of JavaScript NaN values to a method which takes a - // Java array. - public void testPassNumberNaN() throws Throwable { - executeJavaScript("testObject.setBooleanArray([Number.NaN]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - executeJavaScript("testObject.setByteArray([Number.NaN]);"); - assertEquals(0, mTestObject.waitForByteArray()[0]); - - executeJavaScript("testObject.setCharArray([Number.NaN]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - - executeJavaScript("testObject.setShortArray([Number.NaN]);"); - assertEquals(0, mTestObject.waitForShortArray()[0]); - - executeJavaScript("testObject.setIntArray([Number.NaN]);"); - assertEquals(0, mTestObject.waitForIntArray()[0]); - - executeJavaScript("testObject.setLongArray([Number.NaN]);"); - assertEquals(0L, mTestObject.waitForLongArray()[0]); - - executeJavaScript("testObject.setFloatArray([Number.NaN]);"); - assertEquals(Float.NaN, mTestObject.waitForFloatArray()[0]); - - executeJavaScript("testObject.setDoubleArray([Number.NaN]);"); - assertEquals(Double.NaN, mTestObject.waitForDoubleArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number. - executeJavaScript("testObject.setObjectArray([Number.NaN]);"); - assertNull(mTestObject.waitForObjectArray()); - - // LIVECONNECT_COMPLIANCE: Should create instances of java.lang.String. - executeJavaScript("testObject.setStringArray([Number.NaN]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeArray([Number.NaN]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of JavaScript infinity values to a method which - // takes a Java array. - public void testPassNumberInfinity() throws Throwable { - executeJavaScript("testObject.setBooleanArray([Infinity]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - executeJavaScript("testObject.setByteArray([Infinity]);"); - assertEquals(-1, mTestObject.waitForByteArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should convert to maximum numeric char value. - executeJavaScript("testObject.setCharArray([Infinity]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - - executeJavaScript("testObject.setShortArray([Infinity]);"); - assertEquals(-1, mTestObject.waitForShortArray()[0]); - - executeJavaScript("testObject.setIntArray([Infinity]);"); - assertEquals(Integer.MAX_VALUE, mTestObject.waitForIntArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should be Long.MAX_VALUE. - executeJavaScript("testObject.setLongArray([Infinity]);"); - assertEquals(-1L, mTestObject.waitForLongArray()[0]); - - executeJavaScript("testObject.setFloatArray([Infinity]);"); - assertEquals(Float.POSITIVE_INFINITY, mTestObject.waitForFloatArray()[0]); - - executeJavaScript("testObject.setDoubleArray([Infinity]);"); - assertEquals(Double.POSITIVE_INFINITY, mTestObject.waitForDoubleArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number. - executeJavaScript("testObject.setObjectArray([Infinity]);"); - assertNull(mTestObject.waitForObjectArray()); - - // LIVECONNECT_COMPLIANCE: Should create instances of java.lang.String. - executeJavaScript("testObject.setStringArray([Infinity]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeArray([Infinity]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of JavaScript boolean values to a method which - // takes a Java array. - public void testPassBoolean() throws Throwable { - executeJavaScript("testObject.setBooleanArray([true]);"); - assertTrue(mTestObject.waitForBooleanArray()[0]); - executeJavaScript("testObject.setBooleanArray([false]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should be 1. - executeJavaScript("testObject.setByteArray([true]);"); - assertEquals(0, mTestObject.waitForByteArray()[0]); - executeJavaScript("testObject.setByteArray([false]);"); - assertEquals(0, mTestObject.waitForByteArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should convert to numeric char value 1. - executeJavaScript("testObject.setCharArray([true]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - executeJavaScript("testObject.setCharArray([false]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should be 1. - executeJavaScript("testObject.setShortArray([true]);"); - assertEquals(0, mTestObject.waitForShortArray()[0]); - executeJavaScript("testObject.setShortArray([false]);"); - assertEquals(0, mTestObject.waitForShortArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should be 1. - executeJavaScript("testObject.setIntArray([true]);"); - assertEquals(0, mTestObject.waitForIntArray()[0]); - executeJavaScript("testObject.setIntArray([false]);"); - assertEquals(0, mTestObject.waitForIntArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should be 1. - executeJavaScript("testObject.setLongArray([true]);"); - assertEquals(0L, mTestObject.waitForLongArray()[0]); - executeJavaScript("testObject.setLongArray([false]);"); - assertEquals(0L, mTestObject.waitForLongArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should be 1.0. - executeJavaScript("testObject.setFloatArray([true]);"); - assertEquals(0.0f, mTestObject.waitForFloatArray()[0]); - executeJavaScript("testObject.setFloatArray([false]);"); - assertEquals(0.0f, mTestObject.waitForFloatArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should be 1.0. - executeJavaScript("testObject.setDoubleArray([true]);"); - assertEquals(0.0, mTestObject.waitForDoubleArray()[0]); - executeJavaScript("testObject.setDoubleArray([false]);"); - assertEquals(0.0, mTestObject.waitForDoubleArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number. - executeJavaScript("testObject.setObjectArray([true]);"); - assertNull(mTestObject.waitForObjectArray()); - - // LIVECONNECT_COMPLIANCE: Should create instances of java.lang.String. - executeJavaScript("testObject.setStringArray([true]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeArray([true]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of JavaScript strings to a method which takes a - // Java array. - public void testPassString() throws Throwable { - // LIVECONNECT_COMPLIANCE: Non-empty string should convert to true. - executeJavaScript("testObject.setBooleanArray([\"+042.10\"]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setByteArray([\"+042.10\"]);"); - assertEquals(0, mTestObject.waitForByteArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should decode and convert to numeric char value. - executeJavaScript("testObject.setCharArray([\"+042.10\"]);"); - assertEquals(0, mTestObject.waitForCharArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setShortArray([\"+042.10\"]);"); - assertEquals(0, mTestObject.waitForShortArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setIntArray([\"+042.10\"]);"); - assertEquals(0, mTestObject.waitForIntArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setLongArray([\"+042.10\"]);"); - assertEquals(0L, mTestObject.waitForLongArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setFloatArray([\"+042.10\"]);"); - assertEquals(0.0f, mTestObject.waitForFloatArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setDoubleArray([\"+042.10\"]);"); - assertEquals(0.0, mTestObject.waitForDoubleArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number. - executeJavaScript("testObject.setObjectArray([\"+042.10\"]);"); - assertNull(mTestObject.waitForObjectArray()); - - executeJavaScript("testObject.setStringArray([\"+042.10\"]);"); - assertEquals("+042.10", mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeArray([\"+042.10\"]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of JavaScript objects to a method which takes a - // Java array. - public void testPassJavaScriptObject() throws Throwable { - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setBooleanArray([{foo: 42}]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setByteArray([{foo: 42}]);"); - assertEquals(0, mTestObject.waitForByteArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCharArray([{foo: 42}]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setShortArray([{foo: 42}]);"); - assertEquals(0, mTestObject.waitForShortArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setIntArray([{foo: 42}]);"); - assertEquals(0, mTestObject.waitForIntArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setLongArray([{foo: 42}]);"); - assertEquals(0L, mTestObject.waitForLongArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setFloatArray([{foo: 42}]);"); - assertEquals(0.0f, mTestObject.waitForFloatArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setDoubleArray([{foo: 42}]);"); - assertEquals(0.0, mTestObject.waitForDoubleArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setObjectArray([{foo: 42}]);"); - assertNull(mTestObject.waitForObjectArray()); - - // LIVECONNECT_COMPLIANCE: Should call toString() on object. - executeJavaScript("testObject.setStringArray([{foo: 42}]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeArray([{foo: 42}]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of Java objects to a method which takes a Java - // array. - public void testPassJavaObject() throws Throwable { - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setBooleanArray([testObject.getObjectInstance()]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setByteArray([testObject.getObjectInstance()]);"); - assertEquals(0, mTestObject.waitForByteArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCharArray([testObject.getObjectInstance()]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setShortArray([testObject.getObjectInstance()]);"); - assertEquals(0, mTestObject.waitForShortArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setIntArray([testObject.getObjectInstance()]);"); - assertEquals(0, mTestObject.waitForIntArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setLongArray([testObject.getObjectInstance()]);"); - assertEquals(0L, mTestObject.waitForLongArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setFloatArray([testObject.getObjectInstance()]);"); - assertEquals(0.0f, mTestObject.waitForFloatArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setDoubleArray([testObject.getObjectInstance()]);"); - assertEquals(0.0, mTestObject.waitForDoubleArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create an array and pass Java object. - executeJavaScript("testObject.setObjectArray([testObject.getObjectInstance()]);"); - assertNull(mTestObject.waitForObjectArray()); - - // LIVECONNECT_COMPLIANCE: Should call toString() on object. - executeJavaScript("testObject.setStringArray([testObject.getObjectInstance()]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and pass Java object. - executeJavaScript("testObject.setCustomTypeArray([testObject.getObjectInstance()]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - executeJavaScript("testObject.setCustomTypeArray([testObject.getCustomTypeInstance()]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of JavaScript null values to a method which takes - // a Java array. - public void testPassNull() throws Throwable { - executeJavaScript("testObject.setByteArray([null]);"); - assertEquals(0, mTestObject.waitForByteArray()[0]); - - executeJavaScript("testObject.setCharArray([null]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - - executeJavaScript("testObject.setShortArray([null]);"); - assertEquals(0, mTestObject.waitForShortArray()[0]); - - executeJavaScript("testObject.setIntArray([null]);"); - assertEquals(0, mTestObject.waitForIntArray()[0]); - - executeJavaScript("testObject.setLongArray([null]);"); - assertEquals(0L, mTestObject.waitForLongArray()[0]); - - executeJavaScript("testObject.setFloatArray([null]);"); - assertEquals(0.0f, mTestObject.waitForFloatArray()[0]); - - executeJavaScript("testObject.setDoubleArray([null]);"); - assertEquals(0.0, mTestObject.waitForDoubleArray()[0]); - - executeJavaScript("testObject.setBooleanArray([null]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and pass null. - executeJavaScript("testObject.setObjectArray([null]);"); - assertNull(mTestObject.waitForObjectArray()); - - executeJavaScript("testObject.setStringArray([null]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and pass null. - executeJavaScript("testObject.setCustomTypeArray([null]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of JavaScript undefined values to a method which - // takes a Java array. - public void testPassUndefined() throws Throwable { - executeJavaScript("testObject.setByteArray([undefined]);"); - assertEquals(0, mTestObject.waitForByteArray()[0]); - - executeJavaScript("testObject.setCharArray([undefined]);"); - assertEquals(0, mTestObject.waitForCharArray()[0]); - - executeJavaScript("testObject.setShortArray([undefined]);"); - assertEquals(0, mTestObject.waitForShortArray()[0]); - - executeJavaScript("testObject.setIntArray([undefined]);"); - assertEquals(0, mTestObject.waitForIntArray()[0]); - - executeJavaScript("testObject.setLongArray([undefined]);"); - assertEquals(0L, mTestObject.waitForLongArray()[0]); - - executeJavaScript("testObject.setFloatArray([undefined]);"); - assertEquals(0.0f, mTestObject.waitForFloatArray()[0]); - - executeJavaScript("testObject.setDoubleArray([undefined]);"); - assertEquals(0.0, mTestObject.waitForDoubleArray()[0]); - - executeJavaScript("testObject.setBooleanArray([undefined]);"); - assertEquals(false, mTestObject.waitForBooleanArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and pass null. - executeJavaScript("testObject.setObjectArray([undefined]);"); - assertNull(mTestObject.waitForObjectArray()); - - executeJavaScript("testObject.setStringArray([undefined]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and pass null. - executeJavaScript("testObject.setCustomTypeArray([undefined]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } -} diff --git a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayTest.java b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayTest.java deleted file mode 100644 index 2fd42a7..0000000 --- a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayTest.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (C) 2011 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. - */ - -/** - * Part of the test suite for the WebView's Java Bridge. This class tests the - * general use of arrays. - * - * The conversions should follow - * http://jdk6.java.net/plugin2/liveconnect/#JS_JAVA_CONVERSIONS. Places in - * which the implementation differs from the spec are marked with - * LIVECONNECT_COMPLIANCE. - * FIXME: Consider making our implementation more compliant, if it will not - * break backwards-compatibility. See b/4408210. - * - * To run this test ... - * adb shell am instrument -w -e class com.android.webviewtests.JavaBridgeArrayTest \ - * com.android.webviewtests/android.test.InstrumentationTestRunner - */ - -package com.android.webviewtests; - -public class JavaBridgeArrayTest extends JavaBridgeTestBase { - private class TestObject extends Controller { - private boolean mBooleanValue; - private int mIntValue; - private String mStringValue; - - private int[] mIntArray; - private int[][] mIntIntArray; - - private boolean mWasArrayMethodCalled; - - public synchronized void setBooleanValue(boolean x) { - mBooleanValue = x; - notifyResultIsReady(); - } - public synchronized void setIntValue(int x) { - mIntValue = x; - notifyResultIsReady(); - } - public synchronized void setStringValue(String x) { - mStringValue = x; - notifyResultIsReady(); - } - - public synchronized boolean waitForBooleanValue() { - waitForResult(); - return mBooleanValue; - } - public synchronized int waitForIntValue() { - waitForResult(); - return mIntValue; - } - public synchronized String waitForStringValue() { - waitForResult(); - return mStringValue; - } - - public synchronized void setIntArray(int[] x) { - mIntArray = x; - notifyResultIsReady(); - } - public synchronized void setIntIntArray(int[][] x) { - mIntIntArray = x; - notifyResultIsReady(); - } - - public synchronized int[] waitForIntArray() { - waitForResult(); - return mIntArray; - } - public synchronized int[][] waitForIntIntArray() { - waitForResult(); - return mIntIntArray; - } - - public synchronized int[] arrayMethod() { - mWasArrayMethodCalled = true; - return new int[] {42, 43, 44}; - } - - public synchronized boolean wasArrayMethodCalled() { - return mWasArrayMethodCalled; - } - } - - private TestObject mTestObject; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mTestObject = new TestObject(); - setUpWebView(mTestObject, "testObject"); - } - - public void testArrayLength() throws Throwable { - executeJavaScript("testObject.setIntArray([42, 43, 44]);"); - int[] result = mTestObject.waitForIntArray(); - assertEquals(3, result.length); - assertEquals(42, result[0]); - assertEquals(43, result[1]); - assertEquals(44, result[2]); - } - - public void testPassNull() throws Throwable { - executeJavaScript("testObject.setIntArray(null);"); - assertNull(mTestObject.waitForIntArray()); - } - - public void testPassUndefined() throws Throwable { - executeJavaScript("testObject.setIntArray(undefined);"); - assertNull(mTestObject.waitForIntArray()); - } - - public void testPassEmptyArray() throws Throwable { - executeJavaScript("testObject.setIntArray([]);"); - assertEquals(0, mTestObject.waitForIntArray().length); - } - - // Note that this requires being able to pass a string from JavaScript to - // Java. - public void testPassArrayToStringMethod() throws Throwable { - // LIVECONNECT_COMPLIANCE: Should call toString() on array. - executeJavaScript("testObject.setStringValue([42, 42, 42]);"); - assertEquals("undefined", mTestObject.waitForStringValue()); - } - - // Note that this requires being able to pass an integer from JavaScript to - // Java. - public void testPassArrayToNonStringNonArrayMethod() throws Throwable { - // LIVECONNECT_COMPLIANCE: Should raise JavaScript exception. - executeJavaScript("testObject.setIntValue([42, 42, 42]);"); - assertEquals(0, mTestObject.waitForIntValue()); - } - - public void testPassNonArrayToArrayMethod() throws Throwable { - // LIVECONNECT_COMPLIANCE: Should raise JavaScript exception. - executeJavaScript("testObject.setIntArray(42);"); - assertNull(mTestObject.waitForIntArray()); - } - - public void testObjectWithLengthProperty() throws Throwable { - executeJavaScript("testObject.setIntArray({length: 3, 1: 42});"); - int[] result = mTestObject.waitForIntArray(); - assertEquals(3, result.length); - assertEquals(0, result[0]); - assertEquals(42, result[1]); - assertEquals(0, result[2]); - } - - public void testNonNumericLengthProperty() throws Throwable { - // LIVECONNECT_COMPLIANCE: This should not count as an array, so we - // should raise a JavaScript exception. - executeJavaScript("testObject.setIntArray({length: \"foo\"});"); - assertNull(mTestObject.waitForIntArray()); - } - - public void testLengthOutOfBounds() throws Throwable { - // LIVECONNECT_COMPLIANCE: This should not count as an array, so we - // should raise a JavaScript exception. - executeJavaScript("testObject.setIntArray({length: -1});"); - assertNull(mTestObject.waitForIntArray()); - - // LIVECONNECT_COMPLIANCE: This should not count as an array, so we - // should raise a JavaScript exception. - long length = (long)Integer.MAX_VALUE + 1L; - executeJavaScript("testObject.setIntArray({length: " + length + "});"); - assertNull(mTestObject.waitForIntArray()); - - // LIVECONNECT_COMPLIANCE: This should not count as an array, so we - // should raise a JavaScript exception. - length = (long)Integer.MAX_VALUE + 1L - (long)Integer.MIN_VALUE + 1L; - executeJavaScript("testObject.setIntArray({length: " + length + "});"); - assertNull(mTestObject.waitForIntArray()); - } - - public void testSparseArray() throws Throwable { - executeJavaScript("var x = [42, 43]; x[3] = 45; testObject.setIntArray(x);"); - int[] result = mTestObject.waitForIntArray(); - assertEquals(4, result.length); - assertEquals(42, result[0]); - assertEquals(43, result[1]); - assertEquals(0, result[2]); - assertEquals(45, result[3]); - } - - // Note that this requires being able to pass a boolean from JavaScript to - // Java. - public void testMethodReturningArrayNotCalled() throws Throwable { - // We don't invoke methods which return arrays, but note that no - // exception is raised. - // LIVECONNECT_COMPLIANCE: Should call method and convert result to - // JavaScript array. - executeJavaScript("testObject.setBooleanValue(undefined === testObject.arrayMethod())"); - assertTrue(mTestObject.waitForBooleanValue()); - assertFalse(mTestObject.wasArrayMethodCalled()); - } - - public void testMultiDimensionalArrayMethod() throws Throwable { - // LIVECONNECT_COMPLIANCE: Should handle multi-dimensional arrays. - executeJavaScript("testObject.setIntIntArray([ [42, 43], [44, 45] ]);"); - assertNull(mTestObject.waitForIntIntArray()); - } - - public void testPassMultiDimensionalArray() throws Throwable { - // LIVECONNECT_COMPLIANCE: Should handle multi-dimensional arrays. - executeJavaScript("testObject.setIntArray([ [42, 43], [44, 45] ]);"); - int[] result = mTestObject.waitForIntArray(); - assertEquals(2, result.length); - assertEquals(0, result[0]); - assertEquals(0, result[1]); - } -} diff --git a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java deleted file mode 100644 index 1ecccf6..0000000 --- a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java +++ /dev/null @@ -1,442 +0,0 @@ -/* - * Copyright (C) 2011 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. - */ - -/** - * Part of the test suite for the WebView's Java Bridge. Tests a number of features including ... - * - The type of injected objects - * - The type of their methods - * - Replacing objects - * - Removing objects - * - Access control - * - Calling methods on returned objects - * - Multiply injected objects - * - Threading - * - Inheritance - * - * To run this test ... - * adb shell am instrument -w -e class com.android.webviewtests.JavaBridgeBasicsTest \ - * com.android.webviewtests/android.test.InstrumentationTestRunner - */ - -package com.android.webviewtests; - -public class JavaBridgeBasicsTest extends JavaBridgeTestBase { - private class TestController extends Controller { - private int mIntValue; - private long mLongValue; - private String mStringValue; - private boolean mBooleanValue; - - public synchronized void setIntValue(int x) { - mIntValue = x; - notifyResultIsReady(); - } - public synchronized void setLongValue(long x) { - mLongValue = x; - notifyResultIsReady(); - } - public synchronized void setStringValue(String x) { - mStringValue = x; - notifyResultIsReady(); - } - public synchronized void setBooleanValue(boolean x) { - mBooleanValue = x; - notifyResultIsReady(); - } - - public synchronized int waitForIntValue() { - waitForResult(); - return mIntValue; - } - public synchronized long waitForLongValue() { - waitForResult(); - return mLongValue; - } - public synchronized String waitForStringValue() { - waitForResult(); - return mStringValue; - } - public synchronized boolean waitForBooleanValue() { - waitForResult(); - return mBooleanValue; - } - } - - private static class ObjectWithStaticMethod { - public static String staticMethod() { - return "foo"; - } - } - - TestController mTestController; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mTestController = new TestController(); - setUpWebView(mTestController, "testController"); - } - - // Note that this requires that we can pass a JavaScript string to Java. - protected String executeJavaScriptAndGetStringResult(String script) throws Throwable { - executeJavaScript("testController.setStringValue(" + script + ");"); - return mTestController.waitForStringValue(); - } - - protected void injectObjectAndReload(final Object object, final String name) throws Throwable { - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().addJavascriptInterface(object, name); - getWebView().reload(); - } - }); - mWebViewClient.waitForOnPageFinished(); - } - - // Note that this requires that we can pass a JavaScript boolean to Java. - private void assertRaisesException(String script) throws Throwable { - executeJavaScript("try {" + - script + ";" + - " testController.setBooleanValue(false);" + - "} catch (exception) {" + - " testController.setBooleanValue(true);" + - "}"); - assertTrue(mTestController.waitForBooleanValue()); - } - - public void testTypeOfInjectedObject() throws Throwable { - assertEquals("object", executeJavaScriptAndGetStringResult("typeof testController")); - } - - public void testAdditionNotReflectedUntilReload() throws Throwable { - assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof testObject")); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().addJavascriptInterface(new Object(), "testObject"); - } - }); - assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof testObject")); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().reload(); - } - }); - mWebViewClient.waitForOnPageFinished(); - assertEquals("object", executeJavaScriptAndGetStringResult("typeof testObject")); - } - - public void testRemovalNotReflectedUntilReload() throws Throwable { - injectObjectAndReload(new Object(), "testObject"); - assertEquals("object", executeJavaScriptAndGetStringResult("typeof testObject")); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().removeJavascriptInterface("testObject"); - } - }); - assertEquals("object", executeJavaScriptAndGetStringResult("typeof testObject")); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().reload(); - } - }); - mWebViewClient.waitForOnPageFinished(); - assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof testObject")); - } - - public void testRemoveObjectNotAdded() throws Throwable { - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().removeJavascriptInterface("foo"); - getWebView().reload(); - } - }); - mWebViewClient.waitForOnPageFinished(); - assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof foo")); - } - - public void testTypeOfMethod() throws Throwable { - assertEquals("function", - executeJavaScriptAndGetStringResult("typeof testController.setStringValue")); - } - - public void testTypeOfInvalidMethod() throws Throwable { - assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof testController.foo")); - } - - public void testCallingInvalidMethodRaisesException() throws Throwable { - assertRaisesException("testController.foo()"); - } - - public void testUncaughtJavaExceptionRaisesJavaException() throws Throwable { - injectObjectAndReload(new Object() { - public void method() { throw new RuntimeException("foo"); } - }, "testObject"); - assertRaisesException("testObject.method()"); - } - - // Note that this requires that we can pass a JavaScript string to Java. - public void testTypeOfStaticMethod() throws Throwable { - injectObjectAndReload(new ObjectWithStaticMethod(), "testObject"); - executeJavaScript("testController.setStringValue(typeof testObject.staticMethod)"); - assertEquals("function", mTestController.waitForStringValue()); - } - - // Note that this requires that we can pass a JavaScript string to Java. - public void testCallStaticMethod() throws Throwable { - injectObjectAndReload(new ObjectWithStaticMethod(), "testObject"); - executeJavaScript("testController.setStringValue(testObject.staticMethod())"); - assertEquals("foo", mTestController.waitForStringValue()); - } - - public void testPrivateMethodNotExposed() throws Throwable { - injectObjectAndReload(new Object() { - private void method() {} - }, "testObject"); - assertEquals("undefined", - executeJavaScriptAndGetStringResult("typeof testObject.method")); - } - - public void testReplaceInjectedObject() throws Throwable { - injectObjectAndReload(new Object() { - public void method() { mTestController.setStringValue("object 1"); } - }, "testObject"); - executeJavaScript("testObject.method()"); - assertEquals("object 1", mTestController.waitForStringValue()); - - injectObjectAndReload(new Object() { - public void method() { mTestController.setStringValue("object 2"); } - }, "testObject"); - executeJavaScript("testObject.method()"); - assertEquals("object 2", mTestController.waitForStringValue()); - } - - public void testInjectNullObjectIsIgnored() throws Throwable { - injectObjectAndReload(null, "testObject"); - assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof testObject")); - } - - public void testReplaceInjectedObjectWithNullObjectIsIgnored() throws Throwable { - injectObjectAndReload(new Object(), "testObject"); - assertEquals("object", executeJavaScriptAndGetStringResult("typeof testObject")); - injectObjectAndReload(null, "testObject"); - assertEquals("object", executeJavaScriptAndGetStringResult("typeof testObject")); - } - - public void testCallOverloadedMethodWithDifferentNumberOfArguments() throws Throwable { - injectObjectAndReload(new Object() { - public void method() { mTestController.setStringValue("0 args"); } - public void method(int x) { mTestController.setStringValue("1 arg"); } - public void method(int x, int y) { mTestController.setStringValue("2 args"); } - }, "testObject"); - executeJavaScript("testObject.method()"); - assertEquals("0 args", mTestController.waitForStringValue()); - executeJavaScript("testObject.method(42)"); - assertEquals("1 arg", mTestController.waitForStringValue()); - executeJavaScript("testObject.method(null)"); - assertEquals("1 arg", mTestController.waitForStringValue()); - executeJavaScript("testObject.method(undefined)"); - assertEquals("1 arg", mTestController.waitForStringValue()); - executeJavaScript("testObject.method(42, 42)"); - assertEquals("2 args", mTestController.waitForStringValue()); - } - - public void testCallMethodWithWrongNumberOfArgumentsRaisesException() throws Throwable { - assertRaisesException("testController.setIntValue()"); - assertRaisesException("testController.setIntValue(42, 42)"); - } - - public void testObjectPersistsAcrossPageLoads() throws Throwable { - assertEquals("object", executeJavaScriptAndGetStringResult("typeof testController")); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().reload(); - } - }); - mWebViewClient.waitForOnPageFinished(); - assertEquals("object", executeJavaScriptAndGetStringResult("typeof testController")); - } - - public void testSameObjectInjectedMultipleTimes() throws Throwable { - class TestObject { - private int mNumMethodInvocations; - public void method() { mTestController.setIntValue(++mNumMethodInvocations); } - } - final TestObject testObject = new TestObject(); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().addJavascriptInterface(testObject, "testObject1"); - getWebView().addJavascriptInterface(testObject, "testObject2"); - getWebView().reload(); - } - }); - mWebViewClient.waitForOnPageFinished(); - executeJavaScript("testObject1.method()"); - assertEquals(1, mTestController.waitForIntValue()); - executeJavaScript("testObject2.method()"); - assertEquals(2, mTestController.waitForIntValue()); - } - - public void testCallMethodOnReturnedObject() throws Throwable { - injectObjectAndReload(new Object() { - public Object getInnerObject() { - return new Object() { - public void method(int x) { mTestController.setIntValue(x); } - }; - } - }, "testObject"); - executeJavaScript("testObject.getInnerObject().method(42)"); - assertEquals(42, mTestController.waitForIntValue()); - } - - public void testReturnedObjectInjectedElsewhere() throws Throwable { - class InnerObject { - private int mNumMethodInvocations; - public void method() { mTestController.setIntValue(++mNumMethodInvocations); } - } - final InnerObject innerObject = new InnerObject(); - final Object object = new Object() { - public InnerObject getInnerObject() { - return innerObject; - } - }; - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().addJavascriptInterface(object, "testObject"); - getWebView().addJavascriptInterface(innerObject, "innerObject"); - getWebView().reload(); - } - }); - mWebViewClient.waitForOnPageFinished(); - executeJavaScript("testObject.getInnerObject().method()"); - assertEquals(1, mTestController.waitForIntValue()); - executeJavaScript("innerObject.method()"); - assertEquals(2, mTestController.waitForIntValue()); - } - - public void testMethodInvokedOnBackgroundThread() throws Throwable { - injectObjectAndReload(new Object() { - public void captureThreadId() { - mTestController.setLongValue(Thread.currentThread().getId()); - } - }, "testObject"); - executeJavaScript("testObject.captureThreadId()"); - final long threadId = mTestController.waitForLongValue(); - assertFalse(threadId == Thread.currentThread().getId()); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - assertFalse(threadId == Thread.currentThread().getId()); - } - }); - } - - public void testPublicInheritedMethod() throws Throwable { - class Base { - public void method(int x) { mTestController.setIntValue(x); } - } - class Derived extends Base { - } - injectObjectAndReload(new Derived(), "testObject"); - assertEquals("function", executeJavaScriptAndGetStringResult("typeof testObject.method")); - executeJavaScript("testObject.method(42)"); - assertEquals(42, mTestController.waitForIntValue()); - } - - public void testPrivateInheritedMethod() throws Throwable { - class Base { - private void method() {} - } - class Derived extends Base { - } - injectObjectAndReload(new Derived(), "testObject"); - assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof testObject.method")); - } - - public void testOverriddenMethod() throws Throwable { - class Base { - public void method() { mTestController.setStringValue("base"); } - } - class Derived extends Base { - public void method() { mTestController.setStringValue("derived"); } - } - injectObjectAndReload(new Derived(), "testObject"); - executeJavaScript("testObject.method()"); - assertEquals("derived", mTestController.waitForStringValue()); - } - - public void testEnumerateMembers() throws Throwable { - injectObjectAndReload(new Object() { - public void method() {} - private void privateMethod() {} - public int field; - private int privateField; - }, "testObject"); - executeJavaScript( - "var result = \"\"; " + - "for (x in testObject) { result += \" \" + x } " + - "testController.setStringValue(result);"); - // LIVECONNECT_COMPLIANCE: Should be able to enumerate members. - assertEquals("", mTestController.waitForStringValue()); - } - - public void testReflectPublicMethod() throws Throwable { - injectObjectAndReload(new Object() { - public String method() { return "foo"; } - }, "testObject"); - assertEquals("foo", executeJavaScriptAndGetStringResult( - "testObject.getClass().getMethod('method', null).invoke(testObject, null)" + - ".toString()")); - } - - public void testReflectPublicField() throws Throwable { - injectObjectAndReload(new Object() { - public String field = "foo"; - }, "testObject"); - assertEquals("foo", executeJavaScriptAndGetStringResult( - "testObject.getClass().getField('field').get(testObject).toString()")); - } - - public void testReflectPrivateMethodRaisesException() throws Throwable { - injectObjectAndReload(new Object() { - private void method() {}; - }, "testObject"); - assertRaisesException("testObject.getClass().getMethod('method', null)"); - // getDeclaredMethod() is able to access a private method, but invoke() - // throws a Java exception. - assertRaisesException( - "testObject.getClass().getDeclaredMethod('method', null).invoke(testObject, null)"); - } - - public void testReflectPrivateFieldRaisesException() throws Throwable { - injectObjectAndReload(new Object() { - private int field; - }, "testObject"); - assertRaisesException("testObject.getClass().getField('field')"); - // getDeclaredField() is able to access a private field, but getInt() - // throws a Java exception. - assertRaisesException( - "testObject.getClass().getDeclaredField('field').getInt(testObject)"); - } -} diff --git a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeChildFrameTest.java b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeChildFrameTest.java deleted file mode 100644 index 3f0e2b3..0000000 --- a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeChildFrameTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2012 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. - */ - -/** - * Part of the test suite for the WebView's Java Bridge. - * - * Ensures that injected objects are exposed to child frames as well as the - * main frame. - * - * To run this test ... - * adb shell am instrument -w -e class com.android.webviewtests.JavaBridgeChildFrameTest \ - * com.android.webviewtests/android.test.InstrumentationTestRunner - */ - -package com.android.webviewtests; - -public class JavaBridgeChildFrameTest extends JavaBridgeTestBase { - private class TestController extends Controller { - private String mStringValue; - - public synchronized void setStringValue(String x) { - mStringValue = x; - notifyResultIsReady(); - } - public synchronized String waitForStringValue() { - waitForResult(); - return mStringValue; - } - } - - TestController mTestController; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mTestController = new TestController(); - setUpWebView(mTestController, "testController"); - } - - public void testInjectedObjectPresentInChildFrame() throws Throwable { - // In the case that the test fails (i.e. the child frame doesn't get the injected object, - // the call to testController.setStringValue in the child frame's onload handler will - // not be made. - getActivity().getWebView().loadData( - "<html><head></head><body>" + - "<iframe id=\"childFrame\" onload=\"testController.setStringValue('PASS');\" />" + - "</body></html>", "text/html", null); - assertEquals("PASS", mTestController.waitForStringValue()); - } -} diff --git a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeCoercionTest.java b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeCoercionTest.java deleted file mode 100644 index a0f78a4..0000000 --- a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeCoercionTest.java +++ /dev/null @@ -1,646 +0,0 @@ -/* - * Copyright (C) 2011 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. - */ - -/** - * Part of the test suite for the WebView's Java Bridge. This class tests that - * we correctly convert JavaScript values to Java values when passing them to - * the methods of injected Java objects. - * - * The conversions should follow - * http://jdk6.java.net/plugin2/liveconnect/#JS_JAVA_CONVERSIONS. Places in - * which the implementation differs from the spec are marked with - * LIVECONNECT_COMPLIANCE. - * FIXME: Consider making our implementation more compliant, if it will not - * break backwards-compatibility. See b/4408210. - * - * To run this test ... - * adb shell am instrument -w -e class com.android.webviewtests.JavaBridgeCoercionTest \ - * com.android.webviewtests/android.test.InstrumentationTestRunner - */ - -package com.android.webviewtests; - -public class JavaBridgeCoercionTest extends JavaBridgeTestBase { - private class TestObject extends Controller { - private Object objectInstance; - private CustomType customTypeInstance; - private CustomType2 customType2Instance; - - private boolean mBooleanValue; - private byte mByteValue; - private char mCharValue; - private short mShortValue; - private int mIntValue; - private long mLongValue; - private float mFloatValue; - private double mDoubleValue; - private String mStringValue; - private Object mObjectValue; - private CustomType mCustomTypeValue; - - public TestObject() { - objectInstance = new Object(); - customTypeInstance = new CustomType(); - customType2Instance = new CustomType2(); - } - - public Object getObjectInstance() { - return objectInstance; - } - public CustomType getCustomTypeInstance() { - return customTypeInstance; - } - public CustomType2 getCustomType2Instance() { - return customType2Instance; - } - - public synchronized void setBooleanValue(boolean x) { - mBooleanValue = x; - notifyResultIsReady(); - } - public synchronized void setByteValue(byte x) { - mByteValue = x; - notifyResultIsReady(); - } - public synchronized void setCharValue(char x) { - mCharValue = x; - notifyResultIsReady(); - } - public synchronized void setShortValue(short x) { - mShortValue = x; - notifyResultIsReady(); - } - public synchronized void setIntValue(int x) { - mIntValue = x; - notifyResultIsReady(); - } - public synchronized void setLongValue(long x) { - mLongValue = x; - notifyResultIsReady(); - } - public synchronized void setFloatValue(float x) { - mFloatValue = x; - notifyResultIsReady(); - } - public synchronized void setDoubleValue(double x) { - mDoubleValue = x; - notifyResultIsReady(); - } - public synchronized void setStringValue(String x) { - mStringValue = x; - notifyResultIsReady(); - } - public synchronized void setObjectValue(Object x) { - mObjectValue = x; - notifyResultIsReady(); - } - public synchronized void setCustomTypeValue(CustomType x) { - mCustomTypeValue = x; - notifyResultIsReady(); - } - - public synchronized boolean waitForBooleanValue() { - waitForResult(); - return mBooleanValue; - } - public synchronized byte waitForByteValue() { - waitForResult(); - return mByteValue; - } - public synchronized char waitForCharValue() { - waitForResult(); - return mCharValue; - } - public synchronized short waitForShortValue() { - waitForResult(); - return mShortValue; - } - public synchronized int waitForIntValue() { - waitForResult(); - return mIntValue; - } - public synchronized long waitForLongValue() { - waitForResult(); - return mLongValue; - } - public synchronized float waitForFloatValue() { - waitForResult(); - return mFloatValue; - } - public synchronized double waitForDoubleValue() { - waitForResult(); - return mDoubleValue; - } - public synchronized String waitForStringValue() { - waitForResult(); - return mStringValue; - } - public synchronized Object waitForObjectValue() { - waitForResult(); - return mObjectValue; - } - public synchronized CustomType waitForCustomTypeValue() { - waitForResult(); - return mCustomTypeValue; - } - } - - // Two custom types used when testing passing objects. - private static class CustomType { - } - private static class CustomType2 { - } - - private TestObject mTestObject; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mTestObject = new TestObject(); - setUpWebView(mTestObject, "testObject"); - } - - // Test passing a JavaScript number in the int32 range to a method of an - // injected object. - public void testPassNumberInt32() throws Throwable { - executeJavaScript("testObject.setByteValue(42);"); - assertEquals(42, mTestObject.waitForByteValue()); - executeJavaScript("testObject.setByteValue(" + Byte.MAX_VALUE + " + 42);"); - assertEquals(Byte.MIN_VALUE + 42 - 1, mTestObject.waitForByteValue()); - - // LIVECONNECT_COMPLIANCE: Should convert to numeric char value. - executeJavaScript("testObject.setCharValue(42);"); - assertEquals('\u0000', mTestObject.waitForCharValue()); - - executeJavaScript("testObject.setShortValue(42);"); - assertEquals(42, mTestObject.waitForShortValue()); - executeJavaScript("testObject.setShortValue(" + Short.MAX_VALUE + " + 42);"); - assertEquals(Short.MIN_VALUE + 42 - 1, mTestObject.waitForShortValue()); - - executeJavaScript("testObject.setIntValue(42);"); - assertEquals(42, mTestObject.waitForIntValue()); - - executeJavaScript("testObject.setLongValue(42);"); - assertEquals(42L, mTestObject.waitForLongValue()); - - executeJavaScript("testObject.setFloatValue(42);"); - assertEquals(42.0f, mTestObject.waitForFloatValue()); - - executeJavaScript("testObject.setDoubleValue(42);"); - assertEquals(42.0, mTestObject.waitForDoubleValue()); - - // LIVECONNECT_COMPLIANCE: Should create an instance of java.lang.Number. - executeJavaScript("testObject.setObjectValue(42);"); - assertNull(mTestObject.waitForObjectValue()); - - // The spec allows the JS engine flexibility in how to format the number. - executeJavaScript("testObject.setStringValue(42);"); - String str = mTestObject.waitForStringValue(); - assertTrue("42".equals(str) || "42.0".equals(str)); - - executeJavaScript("testObject.setBooleanValue(0);"); - assertFalse(mTestObject.waitForBooleanValue()); - // LIVECONNECT_COMPLIANCE: Should be true; - executeJavaScript("testObject.setBooleanValue(42);"); - assertFalse(mTestObject.waitForBooleanValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeValue(42);"); - assertNull(mTestObject.waitForCustomTypeValue()); - } - - // Test passing a JavaScript number in the double range to a method of an - // injected object. - public void testPassNumberDouble() throws Throwable { - executeJavaScript("testObject.setByteValue(42.1);"); - assertEquals(42, mTestObject.waitForByteValue()); - executeJavaScript("testObject.setByteValue(" + Byte.MAX_VALUE + " + 42.1);"); - assertEquals(Byte.MIN_VALUE + 42 - 1, mTestObject.waitForByteValue()); - executeJavaScript("testObject.setByteValue(" + Integer.MAX_VALUE + " + 42.1);"); - assertEquals(-1, mTestObject.waitForByteValue()); - - // LIVECONNECT_COMPLIANCE: Should convert to numeric char value. - executeJavaScript("testObject.setCharValue(42.1);"); - assertEquals('\u0000', mTestObject.waitForCharValue()); - - executeJavaScript("testObject.setShortValue(42.1);"); - assertEquals(42, mTestObject.waitForShortValue()); - executeJavaScript("testObject.setShortValue(" + Short.MAX_VALUE + " + 42.1);"); - assertEquals(Short.MIN_VALUE + 42 - 1, mTestObject.waitForShortValue()); - executeJavaScript("testObject.setShortValue(" + Integer.MAX_VALUE + " + 42.1);"); - assertEquals(-1, mTestObject.waitForShortValue()); - - executeJavaScript("testObject.setIntValue(42.1);"); - assertEquals(42, mTestObject.waitForIntValue()); - executeJavaScript("testObject.setIntValue(" + Integer.MAX_VALUE + " + 42.1);"); - assertEquals(Integer.MAX_VALUE, mTestObject.waitForIntValue()); - - executeJavaScript("testObject.setLongValue(42.1);"); - assertEquals(42L, mTestObject.waitForLongValue()); - // LIVECONNECT_COMPLIANCE: Should be Long.MAX_VALUE. - executeJavaScript("testObject.setLongValue(" + Long.MAX_VALUE + " + 42.1);"); - assertEquals(Long.MIN_VALUE, mTestObject.waitForLongValue()); - - executeJavaScript("testObject.setFloatValue(42.1);"); - assertEquals(42.1f, mTestObject.waitForFloatValue()); - - executeJavaScript("testObject.setDoubleValue(42.1);"); - assertEquals(42.1, mTestObject.waitForDoubleValue()); - - // LIVECONNECT_COMPLIANCE: Should create an instance of java.lang.Number. - executeJavaScript("testObject.setObjectValue(42.1);"); - assertNull(mTestObject.waitForObjectValue()); - - executeJavaScript("testObject.setStringValue(42.1);"); - assertEquals("42.1", mTestObject.waitForStringValue()); - - executeJavaScript("testObject.setBooleanValue(0.0);"); - assertFalse(mTestObject.waitForBooleanValue()); - // LIVECONNECT_COMPLIANCE: Should be true. - executeJavaScript("testObject.setBooleanValue(42.1);"); - assertFalse(mTestObject.waitForBooleanValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeValue(42.1);"); - assertNull(mTestObject.waitForCustomTypeValue()); - } - - // Test passing JavaScript NaN to a method of an injected object. - public void testPassNumberNaN() throws Throwable { - executeJavaScript("testObject.setByteValue(Number.NaN);"); - assertEquals(0, mTestObject.waitForByteValue()); - - executeJavaScript("testObject.setCharValue(Number.NaN);"); - assertEquals('\u0000', mTestObject.waitForCharValue()); - - executeJavaScript("testObject.setShortValue(Number.NaN);"); - assertEquals(0, mTestObject.waitForShortValue()); - - executeJavaScript("testObject.setIntValue(Number.NaN);"); - assertEquals(0, mTestObject.waitForIntValue()); - - executeJavaScript("testObject.setLongValue(Number.NaN);"); - assertEquals(0L, mTestObject.waitForLongValue()); - - executeJavaScript("testObject.setFloatValue(Number.NaN);"); - assertEquals(Float.NaN, mTestObject.waitForFloatValue()); - - executeJavaScript("testObject.setDoubleValue(Number.NaN);"); - assertEquals(Double.NaN, mTestObject.waitForDoubleValue()); - - // LIVECONNECT_COMPLIANCE: Should create an instance of java.lang.Number. - executeJavaScript("testObject.setObjectValue(Number.NaN);"); - assertNull(mTestObject.waitForObjectValue()); - - executeJavaScript("testObject.setStringValue(Number.NaN);"); - assertEquals("NaN", mTestObject.waitForStringValue()); - - executeJavaScript("testObject.setBooleanValue(Number.NaN);"); - assertFalse(mTestObject.waitForBooleanValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeValue(Number.NaN);"); - assertNull(mTestObject.waitForCustomTypeValue()); - } - - // Test passing JavaScript infinity to a method of an injected object. - public void testPassNumberInfinity() throws Throwable { - executeJavaScript("testObject.setByteValue(Infinity);"); - assertEquals(-1, mTestObject.waitForByteValue()); - - // LIVECONNECT_COMPLIANCE: Should convert to maximum numeric char value. - executeJavaScript("testObject.setCharValue(Infinity);"); - assertEquals('\u0000', mTestObject.waitForCharValue()); - - executeJavaScript("testObject.setShortValue(Infinity);"); - assertEquals(-1, mTestObject.waitForShortValue()); - - executeJavaScript("testObject.setIntValue(Infinity);"); - assertEquals(Integer.MAX_VALUE, mTestObject.waitForIntValue()); - - // LIVECONNECT_COMPLIANCE: Should be Long.MAX_VALUE. - executeJavaScript("testObject.setLongValue(Infinity);"); - assertEquals(-1L, mTestObject.waitForLongValue()); - - executeJavaScript("testObject.setFloatValue(Infinity);"); - assertEquals(Float.POSITIVE_INFINITY, mTestObject.waitForFloatValue()); - - executeJavaScript("testObject.setDoubleValue(Infinity);"); - assertEquals(Double.POSITIVE_INFINITY, mTestObject.waitForDoubleValue()); - - // LIVECONNECT_COMPLIANCE: Should create an instance of java.lang.Number. - executeJavaScript("testObject.setObjectValue(Infinity);"); - assertNull(mTestObject.waitForObjectValue()); - - executeJavaScript("testObject.setStringValue(Infinity);"); - assertEquals("Inf", mTestObject.waitForStringValue()); - - executeJavaScript("testObject.setBooleanValue(Infinity);"); - assertFalse(mTestObject.waitForBooleanValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeValue(Infinity);"); - assertNull(mTestObject.waitForCustomTypeValue()); - } - - // Test passing a JavaScript boolean to a method of an injected object. - public void testPassBoolean() throws Throwable { - executeJavaScript("testObject.setBooleanValue(true);"); - assertTrue(mTestObject.waitForBooleanValue()); - executeJavaScript("testObject.setBooleanValue(false);"); - assertFalse(mTestObject.waitForBooleanValue()); - - // LIVECONNECT_COMPLIANCE: Should create an instance of java.lang.Boolean. - executeJavaScript("testObject.setObjectValue(true);"); - assertNull(mTestObject.waitForObjectValue()); - - executeJavaScript("testObject.setStringValue(false);"); - assertEquals("false", mTestObject.waitForStringValue()); - executeJavaScript("testObject.setStringValue(true);"); - assertEquals("true", mTestObject.waitForStringValue()); - - // LIVECONNECT_COMPLIANCE: Should be 1. - executeJavaScript("testObject.setByteValue(true);"); - assertEquals(0, mTestObject.waitForByteValue()); - executeJavaScript("testObject.setByteValue(false);"); - assertEquals(0, mTestObject.waitForByteValue()); - - // LIVECONNECT_COMPLIANCE: Should convert to numeric char value 1. - executeJavaScript("testObject.setCharValue(true);"); - assertEquals('\u0000', mTestObject.waitForCharValue()); - executeJavaScript("testObject.setCharValue(false);"); - assertEquals('\u0000', mTestObject.waitForCharValue()); - - // LIVECONNECT_COMPLIANCE: Should be 1. - executeJavaScript("testObject.setShortValue(true);"); - assertEquals(0, mTestObject.waitForShortValue()); - executeJavaScript("testObject.setShortValue(false);"); - assertEquals(0, mTestObject.waitForShortValue()); - - // LIVECONNECT_COMPLIANCE: Should be 1. - executeJavaScript("testObject.setIntValue(true);"); - assertEquals(0, mTestObject.waitForIntValue()); - executeJavaScript("testObject.setIntValue(false);"); - assertEquals(0, mTestObject.waitForIntValue()); - - // LIVECONNECT_COMPLIANCE: Should be 1. - executeJavaScript("testObject.setLongValue(true);"); - assertEquals(0L, mTestObject.waitForLongValue()); - executeJavaScript("testObject.setLongValue(false);"); - assertEquals(0L, mTestObject.waitForLongValue()); - - // LIVECONNECT_COMPLIANCE: Should be 1.0. - executeJavaScript("testObject.setFloatValue(true);"); - assertEquals(0.0f, mTestObject.waitForFloatValue()); - executeJavaScript("testObject.setFloatValue(false);"); - assertEquals(0.0f, mTestObject.waitForFloatValue()); - - // LIVECONNECT_COMPLIANCE: Should be 1.0. - executeJavaScript("testObject.setDoubleValue(true);"); - assertEquals(0.0, mTestObject.waitForDoubleValue()); - executeJavaScript("testObject.setDoubleValue(false);"); - assertEquals(0.0, mTestObject.waitForDoubleValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeValue(true);"); - assertNull(mTestObject.waitForCustomTypeValue()); - } - - // Test passing a JavaScript string to a method of an injected object. - public void testPassString() throws Throwable { - executeJavaScript("testObject.setStringValue(\"+042.10\");"); - assertEquals("+042.10", mTestObject.waitForStringValue()); - - // Make sure that we distinguish between the empty string and NULL. - executeJavaScript("testObject.setStringValue(\"\");"); - assertEquals("", mTestObject.waitForStringValue()); - - // LIVECONNECT_COMPLIANCE: Should create an instance of java.lang.String. - executeJavaScript("testObject.setObjectValue(\"+042.10\");"); - assertNull(mTestObject.waitForObjectValue()); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setByteValue(\"+042.10\");"); - assertEquals(0, mTestObject.waitForByteValue()); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setShortValue(\"+042.10\");"); - assertEquals(0, mTestObject.waitForShortValue()); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setIntValue(\"+042.10\");"); - assertEquals(0, mTestObject.waitForIntValue()); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setLongValue(\"+042.10\");"); - assertEquals(0L, mTestObject.waitForLongValue()); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setFloatValue(\"+042.10\");"); - assertEquals(0.0f, mTestObject.waitForFloatValue()); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setDoubleValue(\"+042.10\");"); - assertEquals(0.0, mTestObject.waitForDoubleValue()); - - // LIVECONNECT_COMPLIANCE: Should decode and convert to numeric char value. - executeJavaScript("testObject.setCharValue(\"+042.10\");"); - assertEquals('\u0000', mTestObject.waitForCharValue()); - - // LIVECONNECT_COMPLIANCE: Non-empty string should convert to true. - executeJavaScript("testObject.setBooleanValue(\"+042.10\");"); - assertFalse(mTestObject.waitForBooleanValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeValue(\"+042.10\");"); - assertNull(mTestObject.waitForCustomTypeValue()); - } - - // Test passing a JavaScript object to a method of an injected object. - public void testPassJavaScriptObject() throws Throwable { - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setObjectValue({foo: 42});"); - assertNull(mTestObject.waitForObjectValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeValue({foo: 42});"); - assertNull(mTestObject.waitForCustomTypeValue()); - - // LIVECONNECT_COMPLIANCE: Should call toString() on object. - executeJavaScript("testObject.setStringValue({foo: 42});"); - assertEquals("undefined", mTestObject.waitForStringValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setByteValue({foo: 42});"); - assertEquals(0, mTestObject.waitForByteValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCharValue({foo: 42});"); - assertEquals('\u0000', mTestObject.waitForCharValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setShortValue({foo: 42});"); - assertEquals(0, mTestObject.waitForShortValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setIntValue({foo: 42});"); - assertEquals(0, mTestObject.waitForIntValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setLongValue({foo: 42});"); - assertEquals(0L, mTestObject.waitForLongValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setFloatValue({foo: 42});"); - assertEquals(0.0f, mTestObject.waitForFloatValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setDoubleValue({foo: 42});"); - assertEquals(0.0, mTestObject.waitForDoubleValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setBooleanValue({foo: 42});"); - assertFalse(mTestObject.waitForBooleanValue()); - } - - // Test passing a Java object to a method of an injected object. Note that - // this test requires being able to return objects from the methods of - // injected objects. This is tested elsewhere. - public void testPassJavaObject() throws Throwable { - executeJavaScript("testObject.setObjectValue(testObject.getObjectInstance());"); - assertTrue(mTestObject.getObjectInstance() == mTestObject.waitForObjectValue()); - executeJavaScript("testObject.setObjectValue(testObject.getCustomTypeInstance());"); - assertTrue(mTestObject.getCustomTypeInstance() == mTestObject.waitForObjectValue()); - - executeJavaScript("testObject.setCustomTypeValue(testObject.getObjectInstance());"); - assertTrue(mTestObject.getObjectInstance() == mTestObject.waitForCustomTypeValue()); - executeJavaScript("testObject.setCustomTypeValue(testObject.getCustomTypeInstance());"); - assertTrue(mTestObject.getCustomTypeInstance() == mTestObject.waitForCustomTypeValue()); - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception, as the types are unrelated. - executeJavaScript("testObject.setCustomTypeValue(testObject.getCustomType2Instance());"); - assertTrue(mTestObject.getCustomType2Instance() == - (Object)mTestObject.waitForCustomTypeValue()); - - // LIVECONNECT_COMPLIANCE: Should call toString() on object. - executeJavaScript("testObject.setStringValue(testObject.getObjectInstance());"); - assertEquals("undefined", mTestObject.waitForStringValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setByteValue(testObject.getObjectInstance());"); - assertEquals(0, mTestObject.waitForByteValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCharValue(testObject.getObjectInstance());"); - assertEquals('\u0000', mTestObject.waitForCharValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setShortValue(testObject.getObjectInstance());"); - assertEquals(0, mTestObject.waitForShortValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setIntValue(testObject.getObjectInstance());"); - assertEquals(0, mTestObject.waitForIntValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setLongValue(testObject.getObjectInstance());"); - assertEquals(0L, mTestObject.waitForLongValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setFloatValue(testObject.getObjectInstance());"); - assertEquals(0.0f, mTestObject.waitForFloatValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setDoubleValue(testObject.getObjectInstance());"); - assertEquals(0.0, mTestObject.waitForDoubleValue()); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setBooleanValue(testObject.getObjectInstance());"); - assertFalse(mTestObject.waitForBooleanValue()); - } - - // Test passing JavaScript null to a method of an injected object. - public void testPassNull() throws Throwable { - executeJavaScript("testObject.setObjectValue(null);"); - assertNull(mTestObject.waitForObjectValue()); - - executeJavaScript("testObject.setCustomTypeValue(null);"); - assertNull(mTestObject.waitForCustomTypeValue()); - - executeJavaScript("testObject.setStringValue(null);"); - assertNull(mTestObject.waitForStringValue()); - - executeJavaScript("testObject.setByteValue(null);"); - assertEquals(0, mTestObject.waitForByteValue()); - - executeJavaScript("testObject.setCharValue(null);"); - assertEquals('\u0000', mTestObject.waitForCharValue()); - - executeJavaScript("testObject.setShortValue(null);"); - assertEquals(0, mTestObject.waitForShortValue()); - - executeJavaScript("testObject.setIntValue(null);"); - assertEquals(0, mTestObject.waitForIntValue()); - - executeJavaScript("testObject.setLongValue(null);"); - assertEquals(0L, mTestObject.waitForLongValue()); - - executeJavaScript("testObject.setFloatValue(null);"); - assertEquals(0.0f, mTestObject.waitForFloatValue()); - - executeJavaScript("testObject.setDoubleValue(null);"); - assertEquals(0.0, mTestObject.waitForDoubleValue()); - - executeJavaScript("testObject.setBooleanValue(null);"); - assertFalse(mTestObject.waitForBooleanValue()); - } - - // Test passing JavaScript undefined to a method of an injected object. - public void testPassUndefined() throws Throwable { - executeJavaScript("testObject.setObjectValue(undefined);"); - assertNull(mTestObject.waitForObjectValue()); - - executeJavaScript("testObject.setCustomTypeValue(undefined);"); - assertNull(mTestObject.waitForCustomTypeValue()); - - // LIVECONNECT_COMPLIANCE: Should be NULL. - executeJavaScript("testObject.setStringValue(undefined);"); - assertEquals("undefined", mTestObject.waitForStringValue()); - - executeJavaScript("testObject.setByteValue(undefined);"); - assertEquals(0, mTestObject.waitForByteValue()); - - executeJavaScript("testObject.setCharValue(undefined);"); - assertEquals('\u0000', mTestObject.waitForCharValue()); - - executeJavaScript("testObject.setShortValue(undefined);"); - assertEquals(0, mTestObject.waitForShortValue()); - - executeJavaScript("testObject.setIntValue(undefined);"); - assertEquals(0, mTestObject.waitForIntValue()); - - executeJavaScript("testObject.setLongValue(undefined);"); - assertEquals(0L, mTestObject.waitForLongValue()); - - executeJavaScript("testObject.setFloatValue(undefined);"); - assertEquals(0.0f, mTestObject.waitForFloatValue()); - - executeJavaScript("testObject.setDoubleValue(undefined);"); - assertEquals(0.0, mTestObject.waitForDoubleValue()); - - executeJavaScript("testObject.setBooleanValue(undefined);"); - assertFalse(mTestObject.waitForBooleanValue()); - } -} diff --git a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeFieldsTest.java b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeFieldsTest.java deleted file mode 100644 index 0ccd175..0000000 --- a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeFieldsTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2011 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. - */ - -/** - * Part of the test suite for the WebView's Java Bridge. This test tests the - * use of fields. - * - * To run this test ... - * adb shell am instrument -w -e class com.android.webviewtests.JavaBridgeFieldsTest \ - * com.android.webviewtests/android.test.InstrumentationTestRunner - */ - -package com.android.webviewtests; - -public class JavaBridgeFieldsTest extends JavaBridgeTestBase { - private class TestObject extends Controller { - private String mStringValue; - - // These methods are used to control the test. - public synchronized void setStringValue(String x) { - mStringValue = x; - notifyResultIsReady(); - } - public synchronized String waitForStringValue() { - waitForResult(); - return mStringValue; - } - - public boolean booleanField = true; - public byte byteField = 42; - public char charField = '\u002A'; - public short shortField = 42; - public int intField = 42; - public long longField = 42L; - public float floatField = 42.0f; - public double doubleField = 42.0; - public String stringField = "foo"; - public Object objectField = new Object(); - public CustomType customTypeField = new CustomType(); - } - - // A custom type used when testing passing objects. - private class CustomType { - } - - TestObject mTestObject; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mTestObject = new TestObject(); - setUpWebView(mTestObject, "testObject"); - } - - // Note that this requires that we can pass a JavaScript string to Java. - protected String executeJavaScriptAndGetStringResult(String script) throws Throwable { - executeJavaScript("testObject.setStringValue(" + script + ");"); - return mTestObject.waitForStringValue(); - } - - // The Java bridge does not provide access to fields. - // FIXME: Consider providing support for this. See See b/4408210. - public void testFieldTypes() throws Throwable { - assertEquals("undefined", - executeJavaScriptAndGetStringResult("typeof testObject.booleanField")); - assertEquals("undefined", - executeJavaScriptAndGetStringResult("typeof testObject.byteField")); - assertEquals("undefined", - executeJavaScriptAndGetStringResult("typeof testObject.charField")); - assertEquals("undefined", - executeJavaScriptAndGetStringResult("typeof testObject.shortField")); - assertEquals("undefined", - executeJavaScriptAndGetStringResult("typeof testObject.intField")); - assertEquals("undefined", - executeJavaScriptAndGetStringResult("typeof testObject.longField")); - assertEquals("undefined", - executeJavaScriptAndGetStringResult("typeof testObject.floatField")); - assertEquals("undefined", - executeJavaScriptAndGetStringResult("typeof testObject.doubleField")); - assertEquals("undefined", - executeJavaScriptAndGetStringResult("typeof testObject.objectField")); - assertEquals("undefined", - executeJavaScriptAndGetStringResult("typeof testObject.stringField")); - assertEquals("undefined", - executeJavaScriptAndGetStringResult("typeof testObject.customTypeField")); - } -} diff --git a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeReturnValuesTest.java b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeReturnValuesTest.java deleted file mode 100644 index 44d5cc6..0000000 --- a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeReturnValuesTest.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) 2011 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. - */ - -/** - * Part of the test suite for the WebView's Java Bridge. This test checks that - * we correctly convert Java values to JavaScript values when returning them - * from the methods of injected Java objects. - * - * The conversions should follow - * http://jdk6.java.net/plugin2/liveconnect/#JS_JAVA_CONVERSIONS. Places in - * which the implementation differs from the spec are marked with - * LIVECONNECT_COMPLIANCE. - * FIXME: Consider making our implementation more compliant, if it will not - * break backwards-compatibility. See b/4408210. - * - * To run this test ... - * adb shell am instrument -w -e class com.android.webviewtests.JavaBridgeReturnValuesTest \ - * com.android.webviewtests/android.test.InstrumentationTestRunner - */ - -package com.android.webviewtests; - -public class JavaBridgeReturnValuesTest extends JavaBridgeTestBase { - // An instance of this class is injected into the page to test returning - // Java values to JavaScript. - private class TestObject extends Controller { - private String mStringValue; - private boolean mBooleanValue; - - // These four methods are used to control the test. - public synchronized void setStringValue(String x) { - mStringValue = x; - notifyResultIsReady(); - } - public synchronized String waitForStringValue() { - waitForResult(); - return mStringValue; - } - public synchronized void setBooleanValue(boolean x) { - mBooleanValue = x; - notifyResultIsReady(); - } - public synchronized boolean waitForBooleanValue() { - waitForResult(); - return mBooleanValue; - } - - public boolean getBooleanValue() { - return true; - } - public byte getByteValue() { - return 42; - } - public char getCharValue() { - return '\u002A'; - } - public short getShortValue() { - return 42; - } - public int getIntValue() { - return 42; - } - public long getLongValue() { - return 42L; - } - public float getFloatValue() { - return 42.1f; - } - public float getFloatValueNoDecimal() { - return 42.0f; - } - public double getDoubleValue() { - return 42.1; - } - public double getDoubleValueNoDecimal() { - return 42.0; - } - public String getStringValue() { - return "foo"; - } - public String getEmptyStringValue() { - return ""; - } - public String getNullStringValue() { - return null; - } - public Object getObjectValue() { - return new Object(); - } - public Object getNullObjectValue() { - return null; - } - public CustomType getCustomTypeValue() { - return new CustomType(); - } - public void getVoidValue() { - } - } - - // A custom type used when testing passing objects. - private class CustomType { - } - - TestObject mTestObject; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mTestObject = new TestObject(); - setUpWebView(mTestObject, "testObject"); - } - - // Note that this requires that we can pass a JavaScript string to Java. - protected String executeJavaScriptAndGetStringResult(String script) throws Throwable { - executeJavaScript("testObject.setStringValue(" + script + ");"); - return mTestObject.waitForStringValue(); - } - - // Note that this requires that we can pass a JavaScript boolean to Java. - private boolean executeJavaScriptAndGetBooleanResult(String script) throws Throwable { - executeJavaScript("testObject.setBooleanValue(" + script + ");"); - return mTestObject.waitForBooleanValue(); - } - - public void testMethodReturnTypes() throws Throwable { - assertEquals("boolean", - executeJavaScriptAndGetStringResult("typeof testObject.getBooleanValue()")); - assertEquals("number", - executeJavaScriptAndGetStringResult("typeof testObject.getByteValue()")); - // char values are returned to JavaScript as numbers. - assertEquals("number", - executeJavaScriptAndGetStringResult("typeof testObject.getCharValue()")); - assertEquals("number", - executeJavaScriptAndGetStringResult("typeof testObject.getShortValue()")); - assertEquals("number", - executeJavaScriptAndGetStringResult("typeof testObject.getIntValue()")); - assertEquals("number", - executeJavaScriptAndGetStringResult("typeof testObject.getLongValue()")); - assertEquals("number", - executeJavaScriptAndGetStringResult("typeof testObject.getFloatValue()")); - assertEquals("number", - executeJavaScriptAndGetStringResult("typeof testObject.getFloatValueNoDecimal()")); - assertEquals("number", - executeJavaScriptAndGetStringResult("typeof testObject.getDoubleValue()")); - assertEquals("number", - executeJavaScriptAndGetStringResult("typeof testObject.getDoubleValueNoDecimal()")); - assertEquals("string", - executeJavaScriptAndGetStringResult("typeof testObject.getStringValue()")); - assertEquals("string", - executeJavaScriptAndGetStringResult("typeof testObject.getEmptyStringValue()")); - // LIVECONNECT_COMPLIANCE: This should have type object. - assertEquals("undefined", - executeJavaScriptAndGetStringResult("typeof testObject.getNullStringValue()")); - assertEquals("object", - executeJavaScriptAndGetStringResult("typeof testObject.getObjectValue()")); - assertEquals("object", - executeJavaScriptAndGetStringResult("typeof testObject.getNullObjectValue()")); - assertEquals("object", - executeJavaScriptAndGetStringResult("typeof testObject.getCustomTypeValue()")); - assertEquals("undefined", - executeJavaScriptAndGetStringResult("typeof testObject.getVoidValue()")); - } - - public void testMethodReturnValues() throws Throwable { - // We do the string comparison in JavaScript, to avoid relying on the - // coercion algorithm from JavaScript to Java. - assertTrue(executeJavaScriptAndGetBooleanResult("testObject.getBooleanValue()")); - assertTrue(executeJavaScriptAndGetBooleanResult("42 === testObject.getByteValue()")); - // char values are returned to JavaScript as numbers. - assertTrue(executeJavaScriptAndGetBooleanResult("42 === testObject.getCharValue()")); - assertTrue(executeJavaScriptAndGetBooleanResult("42 === testObject.getShortValue()")); - assertTrue(executeJavaScriptAndGetBooleanResult("42 === testObject.getIntValue()")); - assertTrue(executeJavaScriptAndGetBooleanResult("42 === testObject.getLongValue()")); - assertTrue(executeJavaScriptAndGetBooleanResult( - "Math.abs(42.1 - testObject.getFloatValue()) < 0.001")); - assertTrue(executeJavaScriptAndGetBooleanResult( - "42.0 === testObject.getFloatValueNoDecimal()")); - assertTrue(executeJavaScriptAndGetBooleanResult( - "Math.abs(42.1 - testObject.getDoubleValue()) < 0.001")); - assertTrue(executeJavaScriptAndGetBooleanResult( - "42.0 === testObject.getDoubleValueNoDecimal()")); - assertEquals("foo", executeJavaScriptAndGetStringResult("testObject.getStringValue()")); - assertEquals("", executeJavaScriptAndGetStringResult("testObject.getEmptyStringValue()")); - assertTrue(executeJavaScriptAndGetBooleanResult("undefined === testObject.getVoidValue()")); - } -} diff --git a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeTestBase.java b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeTestBase.java deleted file mode 100644 index a451015..0000000 --- a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeTestBase.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2011 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. - */ - -/** - * Common functionality for testing the WebView's Java Bridge. - */ - -package com.android.webviewtests; - -import android.test.ActivityInstrumentationTestCase2; -import android.util.Log; -import android.webkit.WebView; -import android.webkit.WebViewClient; - -import junit.framework.Assert; - -public class JavaBridgeTestBase extends ActivityInstrumentationTestCase2<WebViewStubActivity> { - protected class TestWebViewClient extends WebViewClient { - private boolean mIsPageFinished; - @Override - public synchronized void onPageFinished(WebView webView, String url) { - mIsPageFinished = true; - notify(); - } - public synchronized void waitForOnPageFinished() throws RuntimeException { - while (!mIsPageFinished) { - try { - wait(5000); - } catch (Exception e) { - continue; - } - if (!mIsPageFinished) { - throw new RuntimeException("Timed out waiting for onPageFinished()"); - } - } - mIsPageFinished = false; - } - } - - protected class Controller { - private boolean mIsResultReady; - - protected synchronized void notifyResultIsReady() { - mIsResultReady = true; - notify(); - } - protected synchronized void waitForResult() { - while (!mIsResultReady) { - try { - wait(5000); - } catch (Exception e) { - continue; - } - if (!mIsResultReady) { - Assert.fail("Wait timed out"); - } - } - mIsResultReady = false; - } - } - - protected TestWebViewClient mWebViewClient; - - public JavaBridgeTestBase() { - super(WebViewStubActivity.class); - } - - // Sets up the WebView and injects the supplied object. Intended to be called from setUp(). - protected void setUpWebView(final Object object, final String name) throws Exception { - mWebViewClient = new TestWebViewClient(); - // This starts the activity, so must be called on the test thread. - final WebViewStubActivity activity = getActivity(); - // On the UI thread, load an empty page and wait for it to finish - // loading so that the Java object is injected. - try { - runTestOnUiThread(new Runnable() { - @Override - public void run() { - WebView webView = activity.getWebView(); - webView.addJavascriptInterface(object, name); - webView.getSettings().setJavaScriptEnabled(true); - webView.setWebViewClient(mWebViewClient); - webView.loadData("<!DOCTYPE html><title></title>", "text/html", null); - } - }); - mWebViewClient.waitForOnPageFinished(); - } catch (Throwable e) { - throw new RuntimeException("Failed to set up WebView: " + Log.getStackTraceString(e)); - } - } - - protected void executeJavaScript(final String script) throws Throwable { - runTestOnUiThread(new Runnable() { - @Override - public void run() { - // When a JavaScript URL is executed, if the value of the last - // expression evaluated is not 'undefined', this value is - // converted to a string and used as the new document for the - // frame. We don't want this behaviour, so wrap the script in - // an anonymous function. - getWebView().loadUrl("javascript:(function() { " + script + " })()"); - } - }); - } - - protected WebView getWebView() { - return getActivity().getWebView(); - } -} diff --git a/tests/WebViewTests/src/com/android/webviewtests/WebViewStubActivity.java b/tests/WebViewTests/src/com/android/webviewtests/WebViewStubActivity.java deleted file mode 100644 index ccfd3d5..0000000 --- a/tests/WebViewTests/src/com/android/webviewtests/WebViewStubActivity.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.webviewtests; - -import com.android.webviewtests.R; - -import android.app.Activity; -import android.os.Bundle; -import android.webkit.WebView; - -public class WebViewStubActivity extends Activity { - private WebView mWebView; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.webview_layout); - mWebView = (WebView) findViewById(R.id.web_page); - } - - public WebView getWebView() { - return mWebView; - } -} |