| OLD | NEW |
| 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 BaseJsTest | 23 class GlobalJsObjectTest : public ::testing::Test |
| 24 { | 24 { |
| 25 protected: |
| 26 AdblockPlus::JsEnginePtr jsEngine; |
| 27 |
| 28 void SetUp() override |
| 29 { |
| 30 JsEngineCreationParameters jsEngineParams; |
| 31 jsEngineParams.timer = AdblockPlus::CreateDefaultTimer(); |
| 32 jsEngine = CreateJsEngine(std::move(jsEngineParams)); |
| 33 } |
| 25 }; | 34 }; |
| 26 } | 35 } |
| 27 | 36 |
| 28 TEST_F(GlobalJsObjectTest, SetTimeout) | 37 TEST_F(GlobalJsObjectTest, SetTimeout) |
| 29 { | 38 { |
| 30 jsEngine->Evaluate("setTimeout(function() {foo = 'bar';}, 100)"); | 39 jsEngine->Evaluate("setTimeout(function() {foo = 'bar';}, 100)"); |
| 31 ASSERT_TRUE(jsEngine->Evaluate("this.foo").IsUndefined()); | 40 ASSERT_TRUE(jsEngine->Evaluate("this.foo").IsUndefined()); |
| 32 AdblockPlus::Sleep(200); | 41 AdblockPlus::Sleep(200); |
| 33 ASSERT_EQ("bar", jsEngine->Evaluate("this.foo").AsString()); | 42 ASSERT_EQ("bar", jsEngine->Evaluate("this.foo").AsString()); |
| 34 } | 43 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 58 | 67 |
| 59 TEST_F(GlobalJsObjectTest, TimeoutDoesNotKeepJsEngine) | 68 TEST_F(GlobalJsObjectTest, TimeoutDoesNotKeepJsEngine) |
| 60 { | 69 { |
| 61 jsEngine->Evaluate("setTimeout(function() {}, 50000)"); | 70 jsEngine->Evaluate("setTimeout(function() {}, 50000)"); |
| 62 EXPECT_EQ(1u, jsEngine.use_count()); // check that counter is still 1 | 71 EXPECT_EQ(1u, jsEngine.use_count()); // check that counter is still 1 |
| 63 AdblockPlus::Sleep(200); | 72 AdblockPlus::Sleep(200); |
| 64 std::weak_ptr<AdblockPlus::JsEngine> weakJsEngine = jsEngine; | 73 std::weak_ptr<AdblockPlus::JsEngine> weakJsEngine = jsEngine; |
| 65 jsEngine.reset(); | 74 jsEngine.reset(); |
| 66 EXPECT_FALSE(weakJsEngine.lock()); | 75 EXPECT_FALSE(weakJsEngine.lock()); |
| 67 } | 76 } |
| OLD | NEW |