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
import android.os.Parcel
import android.support.test.InstrumentationRegistry
import org.mozilla.geckoview.GeckoSession
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) =
this.loadUri(GeckoSessionTestRule.APK_URI_PREFIX + path.removePrefix("/"))

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

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

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

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

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

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

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

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

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

@ -7,6 +7,7 @@
package org.mozilla.geckoview;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.UUID;
@ -908,25 +909,11 @@ public class GeckoSession extends LayerSession
* which case the type is guessed.
*/
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) {
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
*/
public static String createDataUri(@NonNull final byte[] bytes, @Nullable final String mimeType) {
return String.format("data:%s;base64,%s", mimeType != null ? mimeType : "",
Base64.encodeToString(bytes, Base64.NO_WRAP));
return String.format("data:%s,%s", mimeType != null ? mimeType : "",
Base64.encodeToString(bytes, Base64.URL_SAFE | Base64.NO_WRAP));
}
/**
@ -975,7 +962,7 @@ public class GeckoSession extends LayerSession
* @return a URI String
*/
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);
}
/**