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

Side by Side Diff: test/GlobalJsObject.cpp

Issue 29500602: Issue 5450 - introduce the Platform class (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: rebase Created July 31, 2017, 12:53 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include "BaseJsTest.h" 18 #include "BaseJsTest.h"
19 #include "../src/Thread.h" 19 #include "../src/Thread.h"
20 20
21 namespace 21 namespace
22 { 22 {
23 class GlobalJsObjectTest : public ::testing::Test 23 class GlobalJsObjectTest : public ::testing::Test
24 { 24 {
25 protected: 25 protected:
26 std::unique_ptr<AdblockPlus::Platform> platform;
26 AdblockPlus::JsEnginePtr jsEngine; 27 AdblockPlus::JsEnginePtr jsEngine;
27 28
28 void SetUp() override 29 void SetUp() override
29 { 30 {
30 JsEngineCreationParameters jsEngineParams; 31 ThrowingPlatformCreationParameters params;
31 jsEngineParams.timer = AdblockPlus::CreateDefaultTimer(); 32 params.timer = AdblockPlus::CreateDefaultTimer();
32 jsEngine = CreateJsEngine(std::move(jsEngineParams)); 33 platform.reset(new AdblockPlus::Platform(std::move(params)));
34 jsEngine = platform->GetJsEngine();
33 } 35 }
34 }; 36 };
35 } 37 }
36 38
37 TEST_F(GlobalJsObjectTest, SetTimeout) 39 TEST_F(GlobalJsObjectTest, SetTimeout)
38 { 40 {
39 jsEngine->Evaluate("setTimeout(function() {foo = 'bar';}, 100)"); 41 jsEngine->Evaluate("setTimeout(function() {foo = 'bar';}, 100)");
40 ASSERT_TRUE(jsEngine->Evaluate("this.foo").IsUndefined()); 42 ASSERT_TRUE(jsEngine->Evaluate("this.foo").IsUndefined());
41 AdblockPlus::Sleep(200); 43 AdblockPlus::Sleep(200);
42 ASSERT_EQ("bar", jsEngine->Evaluate("this.foo").AsString()); 44 ASSERT_EQ("bar", jsEngine->Evaluate("this.foo").AsString());
(...skipping 18 matching lines...) Expand all
61 jsEngine->Evaluate("foo = []"); 63 jsEngine->Evaluate("foo = []");
62 jsEngine->Evaluate("setTimeout(function(s) {foo.push('1');}, 100)"); 64 jsEngine->Evaluate("setTimeout(function(s) {foo.push('1');}, 100)");
63 jsEngine->Evaluate("setTimeout(function(s) {foo.push('2');}, 150)"); 65 jsEngine->Evaluate("setTimeout(function(s) {foo.push('2');}, 150)");
64 AdblockPlus::Sleep(200); 66 AdblockPlus::Sleep(200);
65 ASSERT_EQ("1,2", jsEngine->Evaluate("this.foo").AsString()); 67 ASSERT_EQ("1,2", jsEngine->Evaluate("this.foo").AsString());
66 } 68 }
67 69
68 TEST_F(GlobalJsObjectTest, TimeoutDoesNotKeepJsEngine) 70 TEST_F(GlobalJsObjectTest, TimeoutDoesNotKeepJsEngine)
69 { 71 {
70 jsEngine->Evaluate("setTimeout(function() {}, 50000)"); 72 jsEngine->Evaluate("setTimeout(function() {}, 50000)");
71 EXPECT_EQ(1u, jsEngine.use_count()); // check that counter is still 1 73 // 1 reference is held by platform and yet one by the test fixture class.
74 EXPECT_EQ(2u, jsEngine.use_count());
72 AdblockPlus::Sleep(200); 75 AdblockPlus::Sleep(200);
73 std::weak_ptr<AdblockPlus::JsEngine> weakJsEngine = jsEngine; 76 std::weak_ptr<AdblockPlus::JsEngine> weakJsEngine = jsEngine;
74 jsEngine.reset(); 77 jsEngine.reset();
78 platform.reset();
75 EXPECT_FALSE(weakJsEngine.lock()); 79 EXPECT_FALSE(weakJsEngine.lock());
76 } 80 }
OLDNEW
« include/AdblockPlus/Platform.h ('K') | « test/FilterEngine.cpp ('k') | test/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld