Hi all, I am unit testing the search functionality on my application but when I run it on the simulator I get a "java.lang.SecurityException: Injecting to another application requires INJECT_EVENT permission" exception.
I develop the search following this tutorial http://developer.android.com/guide/topics/search/search-dialog.html. My application is a WebView; when I perform the search I call the loadUrl with the corresponding URL. My test case is like follow: public void testSearch() { Log.i(TAG, "Entering testSearch"); final Instrumentation instrumentation = getInstrumentation(); instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_SEARCH); instrumentation.sendCharacterSync(KeyEvent.KEYCODE_S); instrumentation.sendCharacterSync(KeyEvent.KEYCODE_E); instrumentation.sendCharacterSync(KeyEvent.KEYCODE_A); instrumentation.sendCharacterSync(KeyEvent.KEYCODE_R); instrumentation.sendCharacterSync(KeyEvent.KEYCODE_C); instrumentation.sendCharacterSync(KeyEvent.KEYCODE_H); // Assert that the correct page is loaded. } But when I run the test I get the following exception: 05-02 11:43:28.329: INFO/TestRunner(667): failed: testSearch(com.myapp.test.TestWebView) 05-02 11:43:28.329: INFO/TestRunner(667): ----- begin exception ----- 05-02 11:43:28.340: INFO/TestRunner(667): java.lang.SecurityException: Injecting to another application requires INJECT_EVENT permission 05-02 11:43:28.340: INFO/TestRunner(667): at android.os.Parcel.readException(Parcel.java:1218) 05-02 11:43:28.340: INFO/TestRunner(667): at android.os.Parcel.readException(Parcel.java:1206) 05-02 11:43:28.340: INFO/TestRunner(667): at android.view.IWindowManager$Stub $Proxy.injectKeyEvent(IWindowManager.java:754) 05-02 11:43:28.340: INFO/TestRunner(667): at android.app.Instrumentation.sendKeySync(Instrumentation.java:935) 05-02 11:43:28.340: INFO/TestRunner(667): at android.app.Instrumentation.sendCharacterSync(Instrumentation.java: 961) 05-02 11:43:28.340: INFO/TestRunner(667): at com.myapp.test.TestWebView.testSearch(TestWebView.java:234) 05-02 11:43:28.340: INFO/TestRunner(667): at java.lang.reflect.Method.invokeNative(Native Method) 05-02 11:43:28.340: INFO/TestRunner(667): at java.lang.reflect.Method.invoke(Method.java:521) 05-02 11:43:28.340: INFO/TestRunner(667): at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java: 191) 05-02 11:43:28.340: INFO/TestRunner(667): at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java: 181) 05-02 11:43:28.340: INFO/TestRunner(667): at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java: 175) 05-02 11:43:28.340: INFO/TestRunner(667): at junit.framework.TestCase.runBare(TestCase.java:127) 05-02 11:43:28.340: INFO/TestRunner(667): at junit.framework.TestResult$1.protect(TestResult.java:106) 05-02 11:43:28.340: INFO/TestRunner(667): at junit.framework.TestResult.runProtected(TestResult.java:124) 05-02 11:43:28.340: INFO/TestRunner(667): at junit.framework.TestResult.run(TestResult.java:109) 05-02 11:43:28.340: INFO/TestRunner(667): at junit.framework.TestCase.run(TestCase.java:118) 05-02 11:43:28.340: INFO/TestRunner(667): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:164) 05-02 11:43:28.340: INFO/TestRunner(667): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:151) 05-02 11:43:28.340: INFO/TestRunner(667): at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java: 425) 05-02 11:43:28.340: INFO/TestRunner(667): at android.app.Instrumentation $InstrumentationThread.run(Instrumentation.java:1520) 05-02 11:43:28.340: INFO/TestRunner(667): ----- end exception ----- This only happen when I run the test on the simulator, but not when I run it on a real phone. The simulator is running on a Mac OS 1.6 and the phone is a Droid2. Can someone give me some pointers on how to solve this issue? Thanks, Jose Espinosa -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

