Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: test/FilterEngine.cpp

Issue 29424648: Issue 5123 - add Subscription::IsDisabled (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created April 28, 2017, 9:44 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/FilterEngine.cpp ('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 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 ASSERT_TRUE(subscription.GetProperty("boolFoo").IsUndefined()); 323 ASSERT_TRUE(subscription.GetProperty("boolFoo").IsUndefined());
324 324
325 subscription.SetProperty("stringFoo", "y"); 325 subscription.SetProperty("stringFoo", "y");
326 subscription.SetProperty("intFoo", 24); 326 subscription.SetProperty("intFoo", 24);
327 subscription.SetProperty("boolFoo", true); 327 subscription.SetProperty("boolFoo", true);
328 ASSERT_EQ("y", subscription.GetProperty("stringFoo").AsString()); 328 ASSERT_EQ("y", subscription.GetProperty("stringFoo").AsString());
329 ASSERT_EQ(24, subscription.GetProperty("intFoo").AsInt()); 329 ASSERT_EQ(24, subscription.GetProperty("intFoo").AsInt());
330 ASSERT_TRUE(subscription.GetProperty("boolFoo").AsBool()); 330 ASSERT_TRUE(subscription.GetProperty("boolFoo").AsBool());
331 } 331 }
332 332
333 TEST_F(FilterEngineTest, AddedSubscriptionIsEnabled)
334 {
335 AdblockPlus::Subscription subscription = filterEngine->GetSubscription("foo");
336 EXPECT_FALSE(subscription.IsDisabled());
337 }
338
339 TEST_F(FilterEngineTest, DisablingSubscriptionDisablesItAndFiresEvent)
340 {
341 AdblockPlus::Subscription subscription = filterEngine->GetSubscription("foo");
342 int eventFiredCounter = 0;
343 filterEngine->SetFilterChangeCallback([&eventFiredCounter](const std::string& eventName, JsValue&& subscriptionObject)
344 {
345 if (eventName != "subscription.disabled" || subscriptionObject.GetProperty(" url").AsString() != "foo")
346 return;
347 ++eventFiredCounter;
348 });
349 EXPECT_FALSE(subscription.IsDisabled());
350 subscription.SetDisabled(true);
351 EXPECT_EQ(1, eventFiredCounter);
352 EXPECT_TRUE(subscription.IsDisabled());
353 }
354
355 TEST_F(FilterEngineTest, EnablingSubscriptionEnablesItAndFiresEvent)
356 {
357 AdblockPlus::Subscription subscription = filterEngine->GetSubscription("foo");
358 EXPECT_FALSE(subscription.IsDisabled());
359 subscription.SetDisabled(true);
360 EXPECT_TRUE(subscription.IsDisabled());
361
362 int eventFiredCounter = 0;
363 filterEngine->SetFilterChangeCallback([&eventFiredCounter](const std::string& eventName, JsValue&& subscriptionObject)
364 {
365 if (eventName != "subscription.disabled" || subscriptionObject.GetProperty(" url").AsString() != "foo")
366 return;
367 ++eventFiredCounter;
368 });
369 subscription.SetDisabled(false);
370 EXPECT_EQ(1, eventFiredCounter);
371 EXPECT_FALSE(subscription.IsDisabled());
372 }
373
333 TEST_F(FilterEngineTest, AddRemoveSubscriptions) 374 TEST_F(FilterEngineTest, AddRemoveSubscriptions)
334 { 375 {
335 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); 376 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
336 AdblockPlus::Subscription subscription = filterEngine->GetSubscription("foo"); 377 AdblockPlus::Subscription subscription = filterEngine->GetSubscription("foo");
337 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); 378 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
338 ASSERT_FALSE(subscription.IsListed()); 379 ASSERT_FALSE(subscription.IsListed());
339 subscription.AddToList(); 380 subscription.AddToList();
340 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); 381 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
341 ASSERT_EQ(subscription, filterEngine->GetListedSubscriptions()[0]); 382 ASSERT_EQ(subscription, filterEngine->GetListedSubscriptions()[0]);
342 ASSERT_TRUE(subscription.IsListed()); 383 ASSERT_TRUE(subscription.IsListed());
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 filterEngine->SetAllowedConnectionType(&testConnection); 1118 filterEngine->SetAllowedConnectionType(&testConnection);
1078 auto subscription = EnsureExampleSubscriptionAndForceUpdate("subB"); 1119 auto subscription = EnsureExampleSubscriptionAndForceUpdate("subB");
1079 EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStr ing()); 1120 EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStr ing());
1080 EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); 1121 EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size());
1081 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); 1122 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings();
1082 ASSERT_EQ(1u, capturedConnectionTypes.size()); 1123 ASSERT_EQ(1u, capturedConnectionTypes.size());
1083 EXPECT_TRUE(capturedConnectionTypes[0].first); 1124 EXPECT_TRUE(capturedConnectionTypes[0].first);
1084 EXPECT_EQ(testConnection, capturedConnectionTypes[0].second); 1125 EXPECT_EQ(testConnection, capturedConnectionTypes[0].second);
1085 } 1126 }
1086 } 1127 }
OLDNEW
« no previous file with comments | « src/FilterEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld