| 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 <stdexcept> | 18 #include <stdexcept> |
| 19 #include "BaseJsTest.h" | 19 #include "BaseJsTest.h" |
| 20 | 20 |
| 21 using namespace AdblockPlus; |
| 22 |
| 21 namespace | 23 namespace |
| 22 { | 24 { |
| 23 class JsEngineTest : public BaseJsTest | 25 class JsEngineTest : public BaseJsTest |
| 24 { | 26 { |
| 25 }; | 27 }; |
| 26 } | 28 } |
| 27 | 29 |
| 28 TEST_F(JsEngineTest, Evaluate) | 30 TEST_F(JsEngineTest, Evaluate) |
| 29 { | 31 { |
| 30 jsEngine->Evaluate("function hello() { return 'Hello'; }"); | 32 jsEngine->Evaluate("function hello() { return 'Hello'; }"); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 ASSERT_EQ(0u, value2.GetOwnPropertyNames().size()); | 122 ASSERT_EQ(0u, value2.GetOwnPropertyNames().size()); |
| 121 | 123 |
| 122 ASSERT_TRUE(IsSame(*jsEngine, value, value2)); | 124 ASSERT_TRUE(IsSame(*jsEngine, value, value2)); |
| 123 } | 125 } |
| 124 } | 126 } |
| 125 | 127 |
| 126 TEST_F(JsEngineTest, EventCallbacks) | 128 TEST_F(JsEngineTest, EventCallbacks) |
| 127 { | 129 { |
| 128 bool callbackCalled = false; | 130 bool callbackCalled = false; |
| 129 AdblockPlus::JsValueList callbackParams; | 131 AdblockPlus::JsValueList callbackParams; |
| 130 auto Callback = [&callbackCalled, & callbackParams]( | 132 auto Callback = [&callbackCalled, &callbackParams](JsValueList&& params) |
| 131 const AdblockPlus::JsValueList& params) | |
| 132 { | 133 { |
| 133 callbackCalled = true; | 134 callbackCalled = true; |
| 134 callbackParams = params; | 135 callbackParams = move(params); |
| 135 }; | 136 }; |
| 136 | 137 |
| 137 // Trigger event without a callback | 138 // Trigger event without a callback |
| 138 callbackCalled = false; | 139 callbackCalled = false; |
| 139 jsEngine->Evaluate("_triggerEvent('foobar')"); | 140 jsEngine->Evaluate("_triggerEvent('foobar')"); |
| 140 ASSERT_FALSE(callbackCalled); | 141 ASSERT_FALSE(callbackCalled); |
| 141 | 142 |
| 142 // Set callback | 143 // Set callback |
| 143 jsEngine->SetEventCallback("foobar", Callback); | 144 jsEngine->SetEventCallback("foobar", Callback); |
| 144 callbackCalled = false; | 145 callbackCalled = false; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 187 |
| 187 TEST(NewJsEngineTest, GlobalPropertyTest) | 188 TEST(NewJsEngineTest, GlobalPropertyTest) |
| 188 { | 189 { |
| 189 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); | 190 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); |
| 190 jsEngine->SetGlobalProperty("foo", jsEngine->NewValue("bar")); | 191 jsEngine->SetGlobalProperty("foo", jsEngine->NewValue("bar")); |
| 191 auto foo = jsEngine->Evaluate("foo"); | 192 auto foo = jsEngine->Evaluate("foo"); |
| 192 ASSERT_TRUE(foo.IsString()); | 193 ASSERT_TRUE(foo.IsString()); |
| 193 ASSERT_EQ(foo.AsString(), "bar"); | 194 ASSERT_EQ(foo.AsString(), "bar"); |
| 194 } | 195 } |
| 195 | 196 |
| OLD | NEW |