| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 namespace | 21 namespace |
| 22 { | 22 { |
| 23 class JsEngineTest : public BaseJsTest | 23 class JsEngineTest : public BaseJsTest |
| 24 { | 24 { |
| 25 }; | 25 }; |
| 26 | |
| 27 bool callbackCalled = false; | |
| 28 AdblockPlus::JsValueList callbackParams; | |
| 29 void Callback(AdblockPlus::JsValueList& params) | |
| 30 { | |
| 31 callbackCalled = true; | |
| 32 callbackParams = params; | |
| 33 } | |
| 34 } | 26 } |
| 35 | 27 |
| 36 TEST_F(JsEngineTest, Evaluate) | 28 TEST_F(JsEngineTest, Evaluate) |
| 37 { | 29 { |
| 38 jsEngine->Evaluate("function hello() { return 'Hello'; }"); | 30 jsEngine->Evaluate("function hello() { return 'Hello'; }"); |
| 39 AdblockPlus::JsValuePtr result = jsEngine->Evaluate("hello()"); | 31 AdblockPlus::JsValuePtr result = jsEngine->Evaluate("hello()"); |
| 40 ASSERT_TRUE(result->IsString()); | 32 ASSERT_TRUE(result->IsString()); |
| 41 ASSERT_EQ("Hello", result->AsString()); | 33 ASSERT_EQ("Hello", result->AsString()); |
| 42 } | 34 } |
| 43 | 35 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 67 ASSERT_TRUE(value->IsBool()); | 59 ASSERT_TRUE(value->IsBool()); |
| 68 ASSERT_TRUE(value->AsBool()); | 60 ASSERT_TRUE(value->AsBool()); |
| 69 | 61 |
| 70 value = jsEngine->NewObject(); | 62 value = jsEngine->NewObject(); |
| 71 ASSERT_TRUE(value->IsObject()); | 63 ASSERT_TRUE(value->IsObject()); |
| 72 ASSERT_EQ(0u, value->GetOwnPropertyNames().size()); | 64 ASSERT_EQ(0u, value->GetOwnPropertyNames().size()); |
| 73 } | 65 } |
| 74 | 66 |
| 75 TEST_F(JsEngineTest, EventCallbacks) | 67 TEST_F(JsEngineTest, EventCallbacks) |
| 76 { | 68 { |
| 69 bool callbackCalled = false; |
| 70 AdblockPlus::JsValueList callbackParams; |
| 71 auto Callback = [&callbackCalled, & callbackParams]( |
| 72 const AdblockPlus::JsValueList& params) |
| 73 { |
| 74 callbackCalled = true; |
| 75 callbackParams = params; |
| 76 }; |
| 77 |
| 77 // Trigger event without a callback | 78 // Trigger event without a callback |
| 78 callbackCalled = false; | 79 callbackCalled = false; |
| 79 jsEngine->Evaluate("_triggerEvent('foobar')"); | 80 jsEngine->Evaluate("_triggerEvent('foobar')"); |
| 80 ASSERT_FALSE(callbackCalled); | 81 ASSERT_FALSE(callbackCalled); |
| 81 | 82 |
| 82 // Set callback | 83 // Set callback |
| 83 jsEngine->SetEventCallback("foobar", Callback); | 84 jsEngine->SetEventCallback("foobar", Callback); |
| 84 callbackCalled = false; | 85 callbackCalled = false; |
| 85 jsEngine->Evaluate("_triggerEvent('foobar', 1, 'x', true)"); | 86 jsEngine->Evaluate("_triggerEvent('foobar', 1, 'x', true)"); |
| 86 ASSERT_TRUE(callbackCalled); | 87 ASSERT_TRUE(callbackCalled); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 116 AdblockPlus::FileSystemPtr fileSystem(new AdblockPlus::DefaultFileSystem()); | 117 AdblockPlus::FileSystemPtr fileSystem(new AdblockPlus::DefaultFileSystem()); |
| 117 jsEngine->SetFileSystem(fileSystem); | 118 jsEngine->SetFileSystem(fileSystem); |
| 118 ASSERT_EQ(fileSystem, jsEngine->GetFileSystem()); | 119 ASSERT_EQ(fileSystem, jsEngine->GetFileSystem()); |
| 119 | 120 |
| 120 ASSERT_TRUE(jsEngine->GetWebRequest()); | 121 ASSERT_TRUE(jsEngine->GetWebRequest()); |
| 121 ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr())); | 122 ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr())); |
| 122 AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest()); | 123 AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest()); |
| 123 jsEngine->SetWebRequest(webRequest); | 124 jsEngine->SetWebRequest(webRequest); |
| 124 ASSERT_EQ(webRequest, jsEngine->GetWebRequest()); | 125 ASSERT_EQ(webRequest, jsEngine->GetWebRequest()); |
| 125 } | 126 } |
| OLD | NEW |