OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.test.suitebuilder.annotation.SmallTest; | 7 import android.test.suitebuilder.annotation.SmallTest; |
8 | 8 |
9 import org.chromium.base.test.util.Feature; | 9 import org.chromium.base.test.util.Feature; |
10 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; | 10 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 165 } |
166 }); | 166 }); |
167 assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof te
stObject")); | 167 assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof te
stObject")); |
168 synchronousPageReload(); | 168 synchronousPageReload(); |
169 assertEquals("object", executeJavaScriptAndGetStringResult("typeof testO
bject")); | 169 assertEquals("object", executeJavaScriptAndGetStringResult("typeof testO
bject")); |
170 } | 170 } |
171 | 171 |
172 @SmallTest | 172 @SmallTest |
173 @Feature({"AndroidWebView", "Android-JavaBridge"}) | 173 @Feature({"AndroidWebView", "Android-JavaBridge"}) |
174 public void testRemovalNotReflectedUntilReload() throws Throwable { | 174 public void testRemovalNotReflectedUntilReload() throws Throwable { |
175 injectObjectAndReload(new Object(), "testObject"); | 175 injectObjectAndReload(new Object() { |
| 176 public void method() { |
| 177 mTestController.setStringValue("I'm here"); |
| 178 } |
| 179 }, "testObject"); |
176 assertEquals("object", executeJavaScriptAndGetStringResult("typeof testO
bject")); | 180 assertEquals("object", executeJavaScriptAndGetStringResult("typeof testO
bject")); |
| 181 executeJavaScript("testObject.method()"); |
| 182 assertEquals("I'm here", mTestController.waitForStringValue()); |
177 runTestOnUiThread(new Runnable() { | 183 runTestOnUiThread(new Runnable() { |
178 @Override | 184 @Override |
179 public void run() { | 185 public void run() { |
180 getContentViewCore().removeJavascriptInterface("testObject"); | 186 getContentViewCore().removeJavascriptInterface("testObject"); |
181 } | 187 } |
182 }); | 188 }); |
| 189 // Check that the Java object is being held by the Java bridge, thus it'
s not |
| 190 // collected. Note that despite that what JavaDoc says about invoking "g
c()", both Dalvik |
| 191 // and ART actually run the collector if called via Runtime. |
| 192 Runtime.getRuntime().gc(); |
183 assertEquals("object", executeJavaScriptAndGetStringResult("typeof testO
bject")); | 193 assertEquals("object", executeJavaScriptAndGetStringResult("typeof testO
bject")); |
| 194 executeJavaScript("testObject.method()"); |
| 195 assertEquals("I'm here", mTestController.waitForStringValue()); |
184 synchronousPageReload(); | 196 synchronousPageReload(); |
185 assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof te
stObject")); | 197 assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof te
stObject")); |
186 } | 198 } |
187 | 199 |
188 @SmallTest | 200 @SmallTest |
189 @Feature({"AndroidWebView", "Android-JavaBridge"}) | 201 @Feature({"AndroidWebView", "Android-JavaBridge"}) |
190 public void testRemoveObjectNotAdded() throws Throwable { | 202 public void testRemoveObjectNotAdded() throws Throwable { |
191 TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = | 203 TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = |
192 mTestCallbackHelperContainer.getOnPageFinishedHelper(); | 204 mTestCallbackHelperContainer.getOnPageFinishedHelper(); |
193 int currentCallCount = onPageFinishedHelper.getCallCount(); | 205 int currentCallCount = onPageFinishedHelper.getCallCount(); |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 } | 937 } |
926 injectObjectAndReload(new Test(13), "testObject"); | 938 injectObjectAndReload(new Test(13), "testObject"); |
927 assertEquals("13", executeJavaScriptAndGetStringResult("testObject.getVa
lue()")); | 939 assertEquals("13", executeJavaScriptAndGetStringResult("testObject.getVa
lue()")); |
928 // The documentation doesn't specify, what happens if the embedder is tr
ying | 940 // The documentation doesn't specify, what happens if the embedder is tr
ying |
929 // to inject a different object under the same name. The current impleme
ntation | 941 // to inject a different object under the same name. The current impleme
ntation |
930 // simply replaces the old object with the new one. | 942 // simply replaces the old object with the new one. |
931 injectObjectAndReload(new Test(42), "testObject"); | 943 injectObjectAndReload(new Test(42), "testObject"); |
932 assertEquals("42", executeJavaScriptAndGetStringResult("testObject.getVa
lue()")); | 944 assertEquals("42", executeJavaScriptAndGetStringResult("testObject.getVa
lue()")); |
933 } | 945 } |
934 } | 946 } |
OLD | NEW |