JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_setAcceptableAdsEnabled(JNIEnv *pEnv, jobject, jboolean enabled)
{
    D(D_WARN, "setAcceptableAdsEnabled()");
    try
    {
        const std::string surl = filterEngine->GetPref("subscriptions_exceptionsurl")->AsString();
        AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription(surl);
        if (enabled == JNI_TRUE)
        {
            subscription->AddToList();
        }
        else if (subscription->IsListed())
        {
            subscription->RemoveFromList();
        }
    }
    catch (const std::exception& e)
    {
        ThrowJavaException(pEnv, e);
    }
    catch (...)
    {
        ThrowJavaException(pEnv);
    }
}
Пример #2
0
TEST_F(FilterEngineTest, AddRemoveSubscriptions)
{
  ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
  AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo");
  ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
  ASSERT_FALSE(subscription->IsListed());
  subscription->AddToList();
  ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
  ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[0]);
  ASSERT_TRUE(subscription->IsListed());
  subscription->AddToList();
  ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
  ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[0]);
  ASSERT_TRUE(subscription->IsListed());
  subscription->RemoveFromList();
  ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
  ASSERT_FALSE(subscription->IsListed());
  subscription->RemoveFromList();
  ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
  ASSERT_FALSE(subscription->IsListed());
}
Пример #3
0
TEST_F(FilterEngineTest, AddRemoveSubscriptions)
{
  // There should be only the default subscription initially
  ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
  AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo");
  ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
  ASSERT_FALSE(subscription->IsListed());
  subscription->AddToList();
  ASSERT_EQ(2u, filterEngine->GetListedSubscriptions().size());
  ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[1]);
  ASSERT_TRUE(subscription->IsListed());
  subscription->AddToList();
  ASSERT_EQ(2u, filterEngine->GetListedSubscriptions().size());
  ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[1]);
  ASSERT_TRUE(subscription->IsListed());
  subscription->RemoveFromList();
  ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
  ASSERT_FALSE(subscription->IsListed());
  subscription->RemoveFromList();
  ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
  ASSERT_FALSE(subscription->IsListed());
}
JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_removeSubscription(JNIEnv *pEnv, jobject, jstring url)
{
    D(D_WARN, "removeSubscription()");
    try
    {
        const std::string surl = GetString(pEnv, url);
        AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription(surl);
        if (subscription->IsListed())
        {
            subscription->RemoveFromList();
        }
    }
    catch (const std::exception& e)
    {
        ThrowJavaException(pEnv, e);
    }
    catch (...)
    {
        ThrowJavaException(pEnv);
    }
}