Commit 27f9cc06 authored by Krystian Zlomek's avatar Krystian Zlomek

Issue 7035 - Update libadblockplus dependency

Updated libadblockplus dependency to revision
git:f2df538b1d66b982fba18a0bc36cf27c1b3bc716.

Fixed build issues caused by this update and removed
not used Java API for updates.

Dropped libadblockplus mercurial dependency.
Signed-off-by: Krystian Zlomek's avatarKrystian Zlomek <k.zlomek@eyeo.com>
parent d150f08d
/*
* This file is part of Adblock Plus <https://adblockplus.org/>,
* Copyright (C) 2006-present eyeo GmbH
*
* Adblock Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* Adblock Plus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
package org.adblockplus.libadblockplus.tests;
import org.adblockplus.libadblockplus.MockUpdateAvailableCallback;
import org.adblockplus.libadblockplus.NoOpUpdaterCallback;
import org.adblockplus.libadblockplus.ServerResponse;
import org.junit.Test;
public class FilterEngineUpdaterTest extends UpdaterTest
{
@Test
public void testSetRemoveUpdateAvailableCallback() throws InterruptedException
{
mockWebRequest.response.setStatus(ServerResponse.NsStatus.OK);
mockWebRequest.response.setResponseStatus(200);
mockWebRequest.response.setResponse(
"{\n" +
" \"test\": {\n" +
" \"version\": \"1.0.2\",\n" +
" \"url\": \"https://downloads.adblockplus.org/test-1.0.2.tar.gz?update\"\n" +
" }\n" +
"}");
MockUpdateAvailableCallback mockUpdateAvailableCallback =
new MockUpdateAvailableCallback(0);
filterEngine.setUpdateAvailableCallback(mockUpdateAvailableCallback);
filterEngine.forceUpdateCheck(new NoOpUpdaterCallback());
Thread.sleep(1000);
assertEquals(1, mockUpdateAvailableCallback.getTimesCalled());
filterEngine.removeUpdateAvailableCallback();
filterEngine.forceUpdateCheck(new NoOpUpdaterCallback());
Thread.sleep(1000);
assertEquals(1, mockUpdateAvailableCallback.getTimesCalled());
}
}
/*
* This file is part of Adblock Plus <https://adblockplus.org/>,
* Copyright (C) 2006-present eyeo GmbH
*
* Adblock Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* Adblock Plus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
package org.adblockplus.libadblockplus.tests;
import org.adblockplus.libadblockplus.AppInfo;
import org.adblockplus.libadblockplus.EventCallback;
import org.adblockplus.libadblockplus.HeaderEntry;
import org.adblockplus.libadblockplus.JsValue;
import org.adblockplus.libadblockplus.LazyLogSystem;
import org.adblockplus.libadblockplus.LazyWebRequest;
import org.adblockplus.libadblockplus.Platform;
import org.adblockplus.libadblockplus.ServerResponse;
import org.adblockplus.libadblockplus.UpdateCheckDoneCallback;
import org.junit.Test;
import java.util.List;
public class UpdateCheckTest extends BaseFilterEngineTest
{
protected String previousRequestUrl;
public class TestWebRequest extends LazyWebRequest
{
public ServerResponse response = new ServerResponse();
@Override
public ServerResponse httpGET(String url, List<HeaderEntry> headers)
{
if (url.indexOf("easylist") >= 0)
{
return super.httpGET(url, headers);
}
previousRequestUrl = url;
return response;
}
}
protected AppInfo appInfo;
protected TestWebRequest webRequest;
protected boolean eventCallbackCalled;
protected List<JsValue> eventCallbackParams;
protected boolean updateCallbackCalled;
protected String updateError;
private EventCallback eventCallback = new EventCallback()
{
@Override
public void eventCallback(List<JsValue> params)
{
eventCallbackCalled = true;
eventCallbackParams = params;
}
};
private UpdateCheckDoneCallback updateCallback = new UpdateCheckDoneCallback()
{
@Override
public void updateCheckDoneCallback(String error)
{
updateCallbackCalled = true;
updateError = error;
}
};
public void reset() throws InterruptedException
{
disposeFilterEngine();
if (platform != null)
{
platform.dispose();
}
platform = new Platform(new LazyLogSystem(), webRequest,
getContext().getFilesDir().getAbsolutePath());
platform.setUpJsEngine(appInfo);
platform.getJsEngine().setEventCallback("updateAvailable", eventCallback);
filterEngine = platform.getFilterEngine();
}
@Override
protected void setUp() throws Exception
{
appInfo = AppInfo.builder().build();
webRequest = new TestWebRequest();
eventCallbackCalled = false;
updateCallbackCalled = false;
reset();
}
public void forceUpdateCheck()
{
filterEngine.forceUpdateCheck(updateCallback);
}
@Test
public void testRequestFailure() throws InterruptedException
{
webRequest.response.setStatus(ServerResponse.NsStatus.ERROR_FAILURE);
appInfo = AppInfo
.builder()
.setName("1")
.setVersion("3")
.setApplication("4")
.setApplicationVersion("2")
.setDevelopmentBuild(false)
.build();
reset();
forceUpdateCheck();
Thread.sleep(100);
assertFalse(eventCallbackCalled);
assertTrue(updateCallbackCalled);
assertNotNull(updateError);
String expectedUrl = filterEngine.getPref("update_url_release").asString();
String platform = "libadblockplus";
String platformVersion = "1.0";
expectedUrl = expectedUrl
.replaceAll("%NAME%", appInfo.name)
.replaceAll("%TYPE%", "1"); // manual update
expectedUrl +=
"&addonName=" + appInfo.name +
"&addonVersion=" + appInfo.version +
"&application=" + appInfo.application +
"&applicationVersion=" + appInfo.applicationVersion +
"&platform=" + platform +
"&platformVersion=" + platformVersion +
"&lastVersion=0&downloadCount=0";
assertEquals(expectedUrl, previousRequestUrl);
}
@Test
public void testApplicationUpdateAvailable() throws InterruptedException
{
webRequest.response.setStatus(ServerResponse.NsStatus.OK);
webRequest.response.setResponseStatus(200);
webRequest.response.setResponse(
"{\"1/4\": {\"version\":\"3.1\",\"url\":\"https://foo.bar/\"}}");
appInfo = AppInfo
.builder()
.setName("1")
.setVersion("3")
.setApplication("4")
.setApplicationVersion("2")
.setDevelopmentBuild(true)
.build();
reset();
forceUpdateCheck();
Thread.sleep(1000);
assertTrue(eventCallbackCalled);
assertNotNull(eventCallbackParams);
assertEquals(1l, eventCallbackParams.size());
assertEquals("https://foo.bar/", eventCallbackParams.get(0).asString());
assertTrue(updateCallbackCalled);
assertEquals("", updateError);
}
@Test
public void testWrongApplication() throws InterruptedException
{
webRequest.response.setStatus(ServerResponse.NsStatus.OK);
webRequest.response.setResponseStatus(200);
webRequest.response.setResponse(
"{\"1/3\": {\"version\":\"3.1\",\"url\":\"https://foo.bar/\"}}");
appInfo = AppInfo
.builder()
.setName("1")
.setVersion("3")
.setApplication("4")
.setApplicationVersion("2")
.setDevelopmentBuild(true)
.build();
reset();
forceUpdateCheck();
Thread.sleep(1000);
assertFalse(eventCallbackCalled);
assertTrue(updateCallbackCalled);
assertEquals("", updateError);
}
@Test
public void testWrongVersion() throws InterruptedException
{
webRequest.response.setStatus(ServerResponse.NsStatus.OK);
webRequest.response.setResponseStatus(200);
webRequest.response.setResponse(
"{\"1\": {\"version\":\"3\",\"url\":\"https://foo.bar/\"}}");
appInfo = AppInfo
.builder()
.setName("1")
.setVersion("3")
.setApplication("4")
.setApplicationVersion("2")
.setDevelopmentBuild(true)
.build();
reset();
forceUpdateCheck();
Thread.sleep(1000);
assertFalse(eventCallbackCalled);
assertTrue(updateCallbackCalled);
assertEquals("", updateError);
}
@Test
public void testWrongURL() throws InterruptedException
{
webRequest.response.setStatus(ServerResponse.NsStatus.OK);
webRequest.response.setResponseStatus(200);
webRequest.response.setResponse(
"{\"1\": {\"version\":\"3.1\",\"url\":\"http://insecure/\"}}");
appInfo = AppInfo
.builder()
.setName("1")
.setVersion("3")
.setApplication("4")
.setApplicationVersion("2")
.setDevelopmentBuild(true)
.build();
reset();
forceUpdateCheck();
Thread.sleep(1000);
assertFalse(eventCallbackCalled);
assertTrue(updateCallbackCalled);
assertTrue(updateError.length() > 0);
}
}
/*
* This file is part of Adblock Plus <https://adblockplus.org/>,
* Copyright (C) 2006-present eyeo GmbH
*
* Adblock Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* Adblock Plus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
package org.adblockplus.libadblockplus.tests;
import org.adblockplus.libadblockplus.AppInfo;
import org.adblockplus.libadblockplus.MockWebRequest;
import org.adblockplus.libadblockplus.Platform;
public class UpdaterTest extends BaseFilterEngineTest
{
protected MockWebRequest mockWebRequest;
@Override
protected void setUp() throws Exception
{
AppInfo appInfo = AppInfo
.builder()
.setName("test")
.setVersion("1.0.1")
.build();
mockWebRequest = new MockWebRequest();
platform = new Platform(null, mockWebRequest,
getContext().getFilesDir().getAbsolutePath());
platform.setUpJsEngine(appInfo);
filterEngine = platform.getFilterEngine();
}
}
......@@ -103,7 +103,6 @@ LOCAL_SRC_FILES += JniPlatform.cpp
LOCAL_SRC_FILES += JniJsEngine.cpp JniFilterEngine.cpp JniJsValue.cpp
LOCAL_SRC_FILES += JniFilter.cpp JniSubscription.cpp JniEventCallback.cpp
LOCAL_SRC_FILES += JniLogSystem.cpp JniWebRequest.cpp
LOCAL_SRC_FILES += JniUpdateAvailableCallback.cpp JniUpdateCheckDoneCallback.cpp
LOCAL_SRC_FILES += JniFilterChangeCallback.cpp JniCallbacks.cpp Utils.cpp
LOCAL_SRC_FILES += JniNotification.cpp JniShowNotificationCallback.cpp
LOCAL_SRC_FILES += JniIsAllowedConnectionTypeCallback.cpp
......
......@@ -174,34 +174,6 @@ static jobject JNICALL JniFetchAvailableSubscriptions(JNIEnv* env, jclass clazz,
CATCH_THROW_AND_RETURN(env, 0);
}
static void JNICALL JniRemoveUpdateAvailableCallback(JNIEnv* env, jclass clazz,
jlong ptr)
{
AdblockPlus::FilterEngine& engine = GetFilterEngineRef(ptr);
try
{
engine.RemoveUpdateAvailableCallback();
}
CATCH_AND_THROW(env)
}
static void JNICALL JniSetUpdateAvailableCallback(JNIEnv* env, jclass clazz,
jlong ptr, jlong callbackPtr)
{
AdblockPlus::FilterEngine& engine = GetFilterEngineRef(ptr);
JniUpdateAvailableCallback* const callback =
JniLongToTypePtr<JniUpdateAvailableCallback>(callbackPtr);
const AdblockPlus::FilterEngine::UpdateAvailableCallback updateAvailableCallback =
std::bind(&JniUpdateAvailableCallback::Callback, callback,
std::placeholders::_1);
try
{
engine.SetUpdateAvailableCallback(updateAvailableCallback);
}
CATCH_AND_THROW(env)
}
static void JNICALL JniRemoveFilterChangeCallback(JNIEnv* env, jclass clazz, jlong ptr)
{
AdblockPlus::FilterEngine& engine = GetFilterEngineRef(ptr);
......@@ -232,29 +204,6 @@ static void JNICALL JniSetFilterChangeCallback(JNIEnv* env, jclass clazz,
CATCH_AND_THROW(env)
}
static void JNICALL JniForceUpdateCheck(JNIEnv* env, jclass clazz, jlong ptr, jlong updaterPtr)
{
AdblockPlus::FilterEngine& engine = GetFilterEngineRef(ptr);
JniUpdateCheckDoneCallback* callback =
JniLongToTypePtr<JniUpdateCheckDoneCallback>(updaterPtr);
AdblockPlus::FilterEngine::UpdateCheckDoneCallback
updateCheckDoneCallback = 0;
if (updaterPtr)
{
updateCheckDoneCallback =
std::bind(&JniUpdateCheckDoneCallback::Callback, callback,
std::placeholders::_1);
}
try
{
engine.ForceUpdateCheck(updateCheckDoneCallback);
}
CATCH_AND_THROW(env)
}
static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz,
jlong ptr, jstring jDomain)
{
......@@ -520,11 +469,8 @@ static JNINativeMethod methods[] =
{ (char*)"removeShowNotificationCallback", (char*)"(J)V", (void*)JniRemoveShowNotificationCallback },
{ (char*)"getListedSubscriptions", (char*)"(J)Ljava/util/List;", (void*)JniGetListedSubscriptions },
{ (char*)"fetchAvailableSubscriptions", (char*)"(J)Ljava/util/List;", (void*)JniFetchAvailableSubscriptions },
{ (char*)"setUpdateAvailableCallback", (char*)"(JJ)V", (void*)JniSetUpdateAvailableCallback },
{ (char*)"removeUpdateAvailableCallback", (char*)"(J)V", (void*)JniRemoveUpdateAvailableCallback },
{ (char*)"setFilterChangeCallback", (char*)"(JJ)V", (void*)JniSetFilterChangeCallback },
{ (char*)"removeFilterChangeCallback", (char*)"(J)V", (void*)JniRemoveFilterChangeCallback },
{ (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck },
{ (char*)"getElementHidingSelectors", (char*)"(JLjava/lang/String;)Ljava/util/List;", (void*)JniGetElementHidingSelectors },
{ (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentType") "Ljava/lang/String;)" TYP("Filter"), (void*)JniMatches },
{ (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentType") "[Ljava/lang/String;)" TYP("Filter"), (void*)JniMatchesMany },
......
/*
* This file is part of Adblock Plus <https://adblockplus.org/>,
* Copyright (C) 2006-present eyeo GmbH
*
* Adblock Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* Adblock Plus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
#include "JniCallbacks.h"
static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject)
{
try
{
return JniPtrToLong(new JniUpdateAvailableCallback(env, callbackObject));
}
CATCH_THROW_AND_RETURN(env, 0)
}
static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
{
delete JniLongToTypePtr<JniUpdateAvailableCallback>(ptr);
}
JniUpdateAvailableCallback::JniUpdateAvailableCallback(
JNIEnv* env, jobject callbackObject)
: JniCallbackBase(env, callbackObject)
{
}
void JniUpdateAvailableCallback::Callback(const std::string& arg)
{
JNIEnvAcquire env(GetJavaVM());
jmethodID method = env->GetMethodID(
*JniLocalReference<jclass>(*env,
env->GetObjectClass(GetCallbackObject())),
"updateAvailableCallback",
"(Ljava/lang/String;)V");
if (method)
{
JniLocalReference<jstring> jArg(*env, env->NewStringUTF(arg.c_str()));
env->CallVoidMethod(GetCallbackObject(), method, *jArg);
}
CheckAndLogJavaException(*env);
}
static JNINativeMethod methods[] =
{
{ (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor },
{ (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
};
extern "C" JNIEXPORT void JNICALL
Java_org_adblockplus_libadblockplus_UpdateAvailableCallback_registerNatives(
JNIEnv *env, jclass clazz)
{
env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
}
/*
* This file is part of Adblock Plus <https://adblockplus.org/>,
* Copyright (C) 2006-present eyeo GmbH
*
* Adblock Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* Adblock Plus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
#include "JniCallbacks.h"
static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject)
{
try
{
return JniPtrToLong(new JniUpdateCheckDoneCallback(env, callbackObject));
}
CATCH_THROW_AND_RETURN(env, 0)
}
static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
{
delete JniLongToTypePtr<JniUpdateCheckDoneCallback>(ptr);
}
JniUpdateCheckDoneCallback::JniUpdateCheckDoneCallback(
JNIEnv* env, jobject callbackObject)
: JniCallbackBase(env, callbackObject)
{
}
void JniUpdateCheckDoneCallback::Callback(const std::string& arg)
{
JNIEnvAcquire env(GetJavaVM());
jmethodID method = env->GetMethodID(
*JniLocalReference<jclass>(*env,
env->GetObjectClass(GetCallbackObject())),
"updateCheckDoneCallback",
"(Ljava/lang/String;)V");
if (method)
{
JniLocalReference<jstring> jArg(*env, env->NewStringUTF(arg.c_str()));
env->CallVoidMethod(GetCallbackObject(), method, *jArg);
}
CheckAndLogJavaException(*env);
}
static JNINativeMethod methods[] =
{
{ (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor },
{ (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
};
extern "C" JNIEXPORT void JNICALL
Java_org_adblockplus_libadblockplus_UpdateCheckDoneCallback_registerNatives(
JNIEnv *env, jclass clazz)
{
env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
}
......@@ -71,16 +71,6 @@ public final class FilterEngine
return fetchAvailableSubscriptions(this.ptr);
}
public void removeUpdateAvailableCallback()
{
removeUpdateAvailableCallback(this.ptr);
}
public void setUpdateAvailableCallback(final UpdateAvailableCallback callback)
{
setUpdateAvailableCallback(this.ptr, callback.ptr);
}
public void removeFilterChangeCallback()
{
removeFilterChangeCallback(this.ptr);
......@@ -91,16 +81,6 @@ public final class FilterEngine
setFilterChangeCallback(this.ptr, callback.ptr);
}
public void forceUpdateCheck()
{
forceUpdateCheck(this.ptr, 0);
}
public void forceUpdateCheck(final UpdateCheckDoneCallback callback)
{
forceUpdateCheck(this.ptr, callback != null ? callback.ptr : 0);
}
public List<String> getElementHidingSelectors(final String domain)
{
return getElementHidingSelectors(this.ptr, domain);
......@@ -218,16 +198,10 @@ public final class FilterEngine
private final static native List<Subscription> fetchAvailableSubscriptions(long ptr);
private final static native void removeUpdateAvailableCallback(long ptr);
private final static native void setUpdateAvailableCallback(long ptr, long filterPtr);
private final static native void removeFilterChangeCallback(long ptr);
private final static native void setFilterChangeCallback(long ptr, long filterPtr);
private final static native void forceUpdateCheck(long ptr, long updatePtr);
private final static native List<String> getElementHidingSelectors(long ptr, String domain);
private final static native void showNextNotification(long ptr, String url);
......
/*
* This file is part of Adblock Plus <https://adblockplus.org/>,
* Copyright (C) 2006-present eyeo GmbH
*
* Adblock Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* Adblock Plus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
package org.adblockplus.libadblockplus;
public abstract class UpdateAvailableCallback implements Disposable
{
private final Disposer disposer;
protected final long ptr;
static
{
System.loadLibrary("adblockplus-jni");
registerNatives();
}
public UpdateAvailableCallback()
{
this.ptr = ctor(this);
this.disposer = new Disposer(this, new DisposeWrapper(this.ptr));
}
public abstract void updateAvailableCallback(String url);
@Override
public void dispose()
{
this.disposer.dispose();
}