Backed out 2 changesets (bug 1447991) for android leaks on a CLOSED TREE

Backed out changeset 804b4708aae5 (bug 1447991)
Backed out changeset 18ba4d610e5d

--HG--
rename : mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/PanZoomController.java => mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/NativePanZoomController.java
This commit is contained in:
Andreea Pavel 2018-03-22 16:51:01 +02:00
Родитель 693fb3050c
Коммит e202e32f40
7 изменённых файлов: 30 добавлений и 82 удалений

Просмотреть файл

@ -4,7 +4,6 @@
package org.mozilla.geckoview.test package org.mozilla.geckoview.test
import android.os.Parcel import android.os.Parcel
import android.support.test.InstrumentationRegistry
import org.mozilla.geckoview.GeckoSession import org.mozilla.geckoview.GeckoSession
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule import org.mozilla.geckoview.test.rule.GeckoSessionTestRule
@ -39,10 +38,6 @@ open class BaseSessionTest(noErrorCollector: Boolean = false) {
} }
} }
fun GeckoSession.getTestBytes(path: String) =
InstrumentationRegistry.getTargetContext().resources.assets
.open(path.removePrefix("/assets/")).readBytes()
fun GeckoSession.loadTestPath(path: String) = fun GeckoSession.loadTestPath(path: String) =
this.loadUri(GeckoSessionTestRule.APK_URI_PREFIX + path.removePrefix("/")) this.loadUri(GeckoSessionTestRule.APK_URI_PREFIX + path.removePrefix("/"))

Просмотреть файл

@ -26,15 +26,14 @@ class NavigationDelegateTest : BaseSessionTest() {
sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate {
@AssertCalled(count = 1, order = intArrayOf(1)) @AssertCalled(count = 1, order = intArrayOf(1))
override fun onLoadRequest(session: GeckoSession, uri: String, override fun onLoadRequest(session: GeckoSession, uri: String,
where: Int, where: Int): Boolean {
response: GeckoSession.Response<Boolean>) {
assertThat("Session should not be null", session, notNullValue()) assertThat("Session should not be null", session, notNullValue())
assertThat("URI should not be null", uri, notNullValue()) assertThat("URI should not be null", uri, notNullValue())
assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH)) assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH))
assertThat("Where should not be null", where, notNullValue()) assertThat("Where should not be null", where, notNullValue())
assertThat("Where should match", where, assertThat("Where should match", where,
equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT)) equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT))
response.respond(false) return false
} }
@AssertCalled(count = 1, order = intArrayOf(2)) @AssertCalled(count = 1, order = intArrayOf(2))
@ -82,17 +81,12 @@ class NavigationDelegateTest : BaseSessionTest() {
} }
@Test fun loadString() { @Test fun loadString() {
val dataString = "<html><head><title>TheTitle</title></head><body>TheBody</body></html>" val dataString = "Hello, World!"
val mimeType = "text/html" val mimeType = "text/plain;charset=us-ascii"
sessionRule.session.loadString(dataString, mimeType) sessionRule.session.loadString(dataString, mimeType)
sessionRule.waitForPageStop(); sessionRule.waitForPageStop();
sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate, Callbacks.ProgressDelegate, Callbacks.ContentDelegate { sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate, Callbacks.ProgressDelegate {
@AssertCalled
override fun onTitleChange(session: GeckoSession, title: String) {
assertThat("Title should match", title, equalTo("TheTitle"));
}
@AssertCalled(count = 1) @AssertCalled(count = 1)
override fun onLocationChange(session: GeckoSession, url: String) { override fun onLocationChange(session: GeckoSession, url: String) {
assertThat("URL should be a data URL", url, assertThat("URL should be a data URL", url,
@ -123,34 +117,13 @@ class NavigationDelegateTest : BaseSessionTest() {
}) })
} }
@Test fun loadData_html() { @Test(expected = IllegalArgumentException::class) fun loadString_null() {
var bytes = sessionRule.session.getTestBytes(HELLO_HTML_PATH) sessionRule.session.loadString(null, "text/plain")
assertThat("test html should have data", bytes.size, greaterThan(0))
sessionRule.session.loadData(bytes, "text/html");
sessionRule.waitForPageStop();
sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate, Callbacks.ProgressDelegate, Callbacks.ContentDelegate {
@AssertCalled(count = 1)
override fun onTitleChange(session: GeckoSession, title: String) {
assertThat("Title should match", title, equalTo("Hello, world!"))
}
@AssertCalled(count = 1)
override fun onLocationChange(session: GeckoSession, url: String) {
assertThat("URL should match", url, equalTo(GeckoSession.createDataUri(bytes, "text/html")))
}
@AssertCalled(count = 1)
override fun onPageStop(session: GeckoSession, success: Boolean) {
assertThat("Page should load successfully", success, equalTo(true))
}
})
} }
fun loadDataHelper(assetPath: String, mimeType: String? = null, baseUri: String? = null) { fun loadDataHelper(assetPath: String, mimeType: String? = null, baseUri: String? = null) {
var bytes = sessionRule.session.getTestBytes(assetPath) var bytes = InstrumentationRegistry.getTargetContext().resources.assets.open(assetPath).readBytes()
assertThat("test data should have bytes", bytes.size, greaterThan(0)) assertThat("test gif should have data", bytes.size, greaterThan(0))
sessionRule.session.loadData(bytes, mimeType, baseUri); sessionRule.session.loadData(bytes, mimeType, baseUri);
sessionRule.waitForPageStop(); sessionRule.waitForPageStop();
@ -168,13 +141,12 @@ class NavigationDelegateTest : BaseSessionTest() {
}) })
} }
@Test fun loadData() { @Test fun loadData() {
loadDataHelper("/assets/www/images/test.gif", "image/gif") loadDataHelper("www/images/test.gif", "image/gif")
} }
@Test fun loadData_noMimeType() { @Test fun loadData_noMimeType() {
loadDataHelper("/assets/www/images/test.gif") loadDataHelper("www/images/test.gif")
} }
@Test fun reload() { @Test fun reload() {
@ -187,12 +159,11 @@ class NavigationDelegateTest : BaseSessionTest() {
sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate {
@AssertCalled(count = 1, order = intArrayOf(1)) @AssertCalled(count = 1, order = intArrayOf(1))
override fun onLoadRequest(session: GeckoSession, uri: String, override fun onLoadRequest(session: GeckoSession, uri: String,
where: Int, where: Int): Boolean {
response: GeckoSession.Response<Boolean>) {
assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH)) assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH))
assertThat("Where should match", where, assertThat("Where should match", where,
equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT)) equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT))
response.respond(false) return false
} }
@AssertCalled(count = 1, order = intArrayOf(2)) @AssertCalled(count = 1, order = intArrayOf(2))
@ -237,12 +208,11 @@ class NavigationDelegateTest : BaseSessionTest() {
sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate {
@AssertCalled(count = 1, order = intArrayOf(1)) @AssertCalled(count = 1, order = intArrayOf(1))
override fun onLoadRequest(session: GeckoSession, uri: String, override fun onLoadRequest(session: GeckoSession, uri: String,
where: Int, where: Int): Boolean {
response: GeckoSession.Response<Boolean>) {
assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH)) assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH))
assertThat("Where should match", where, assertThat("Where should match", where,
equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT)) equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT))
response.respond(false) return false
} }
@AssertCalled(count = 1, order = intArrayOf(2)) @AssertCalled(count = 1, order = intArrayOf(2))
@ -272,12 +242,11 @@ class NavigationDelegateTest : BaseSessionTest() {
sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate {
@AssertCalled(count = 1, order = intArrayOf(1)) @AssertCalled(count = 1, order = intArrayOf(1))
override fun onLoadRequest(session: GeckoSession, uri: String, override fun onLoadRequest(session: GeckoSession, uri: String,
where: Int, where: Int): Boolean {
response: GeckoSession.Response<Boolean>) {
assertThat("URI should match", uri, endsWith(HELLO2_HTML_PATH)) assertThat("URI should match", uri, endsWith(HELLO2_HTML_PATH))
assertThat("Where should match", where, assertThat("Where should match", where,
equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT)) equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT))
response.respond(false) return false
} }
@AssertCalled(count = 1, order = intArrayOf(2)) @AssertCalled(count = 1, order = intArrayOf(2))
@ -306,9 +275,8 @@ class NavigationDelegateTest : BaseSessionTest() {
sessionRule.delegateDuringNextWait(object : Callbacks.NavigationDelegate { sessionRule.delegateDuringNextWait(object : Callbacks.NavigationDelegate {
@AssertCalled(count = 2) @AssertCalled(count = 2)
override fun onLoadRequest(session: GeckoSession, uri: String, override fun onLoadRequest(session: GeckoSession, uri: String,
where: Int, where: Int): Boolean {
response: GeckoSession.Response<Boolean>) { return uri.endsWith(HELLO_HTML_PATH)
response.respond(uri.endsWith(HELLO_HTML_PATH))
} }
}) })

Просмотреть файл

@ -57,14 +57,13 @@ class ProgressDelegateTest : BaseSessionTest() {
sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate, Callbacks.NavigationDelegate { sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate, Callbacks.NavigationDelegate {
@AssertCalled(count = 2) @AssertCalled(count = 2)
override fun onLoadRequest(session: GeckoSession, uri: String, override fun onLoadRequest(session: GeckoSession, uri: String, where: Int): Boolean {
where: Int, response: GeckoSession.Response<Boolean>) {
if (sessionRule.currentCall.counter == 1) { if (sessionRule.currentCall.counter == 1) {
assertThat("URI should be " + testUri, uri, equalTo(testUri)); assertThat("URI should be " + testUri, uri, equalTo(testUri));
} else { } else {
assertThat("URI should be about:neterror", uri, startsWith("about:neterror")); assertThat("URI should be about:neterror", uri, startsWith("about:neterror"));
} }
response.respond(false) return false
} }
@AssertCalled(count = 1) @AssertCalled(count = 1)

Просмотреть файл

@ -34,10 +34,9 @@ public class TestRunnerActivity extends Activity {
} }
@Override @Override
public void onLoadRequest(GeckoSession session, String uri, public boolean onLoadRequest(GeckoSession session, String uri, int target) {
int target, GeckoSession.Response<Boolean> response) {
// Allow Gecko to load all URIs // Allow Gecko to load all URIs
response.respond(false); return false;
} }
@Override @Override

Просмотреть файл

@ -40,8 +40,8 @@ class Callbacks private constructor() {
override fun onCanGoForward(session: GeckoSession, canGoForward: Boolean) { override fun onCanGoForward(session: GeckoSession, canGoForward: Boolean) {
} }
override fun onLoadRequest(session: GeckoSession, uri: String, where: Int, response: GeckoSession.Response<Boolean>) { override fun onLoadRequest(session: GeckoSession, uri: String, where: Int): Boolean {
response.respond(false) return false;
} }
override fun onNewSession(session: GeckoSession, uri: String, response: GeckoSession.Response<GeckoSession>) { override fun onNewSession(session: GeckoSession, uri: String, response: GeckoSession.Response<GeckoSession>) {

Просмотреть файл

@ -7,6 +7,7 @@
package org.mozilla.geckoview; package org.mozilla.geckoview;
import java.net.URLConnection; import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.UUID; import java.util.UUID;
@ -908,25 +909,11 @@ public class GeckoSession extends LayerSession
* which case the type is guessed. * which case the type is guessed.
*/ */
public void loadString(@NonNull final String data, @Nullable final String mimeType) { public void loadString(@NonNull final String data, @Nullable final String mimeType) {
loadString(data, mimeType, null);
}
/**
* Load the specified String data. Internally this is converted to a data URI.
*
* @param data a String representing the data
* @param mimeType the mime type of the data, e.g. "text/plain". Maybe be null, in
* which case the type is guessed.
* @param baseUri the base URI of the document. Relative paths will be resolved from here.
*
*/
public void loadString(@NonNull final String data, @Nullable final String mimeType,
@Nullable final String baseUri) {
if (data == null) { if (data == null) {
throw new IllegalArgumentException("data cannot be null"); throw new IllegalArgumentException("data cannot be null");
} }
loadUri(createDataUri(data, mimeType), null, baseUri, LOAD_FLAGS_NONE); loadData(data.getBytes(Charset.forName("utf-8")), mimeType);
} }
/** /**
@ -964,8 +951,8 @@ public class GeckoSession extends LayerSession
* @return a URI String * @return a URI String
*/ */
public static String createDataUri(@NonNull final byte[] bytes, @Nullable final String mimeType) { public static String createDataUri(@NonNull final byte[] bytes, @Nullable final String mimeType) {
return String.format("data:%s;base64,%s", mimeType != null ? mimeType : "", return String.format("data:%s,%s", mimeType != null ? mimeType : "",
Base64.encodeToString(bytes, Base64.NO_WRAP)); Base64.encodeToString(bytes, Base64.URL_SAFE | Base64.NO_WRAP));
} }
/** /**
@ -975,7 +962,7 @@ public class GeckoSession extends LayerSession
* @return a URI String * @return a URI String
*/ */
public static String createDataUri(@NonNull final String data, @Nullable final String mimeType) { public static String createDataUri(@NonNull final String data, @Nullable final String mimeType) {
return String.format("data:%s,%s", mimeType != null ? mimeType : "", data); return createDataUri(data.getBytes(Charset.forName("utf-8")), mimeType);
} }
/** /**