Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java

Issue 767453003: [Android] Fix a subtle issue in Java Bridge regarding interfaces removal (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/android/java/gin_java_bridge_dispatcher_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « content/browser/android/java/gin_java_bridge_dispatcher_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698