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-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 "BaseJsTest.h" | 19 #include "BaseJsTest.h" |
19 | 20 |
20 namespace | 21 namespace |
21 { | 22 { |
22 class JsEngineTest : public BaseJsTest | 23 class JsEngineTest : public BaseJsTest |
23 { | 24 { |
24 }; | 25 }; |
25 | 26 |
26 bool callbackCalled = false; | 27 bool callbackCalled = false; |
27 void Callback() | 28 void Callback() |
28 { | 29 { |
29 callbackCalled = true; | 30 callbackCalled = true; |
30 } | 31 } |
31 } | 32 } |
32 | 33 |
33 TEST_F(JsEngineTest, Evaluate) | 34 TEST_F(JsEngineTest, Evaluate) |
34 { | 35 { |
35 jsEngine->Evaluate("function hello() { return 'Hello'; }"); | 36 jsEngine->Evaluate("function hello() { return 'Hello'; }"); |
36 AdblockPlus::JsValuePtr result = jsEngine->Evaluate("hello()"); | 37 AdblockPlus::JsValuePtr result = jsEngine->Evaluate("hello()"); |
37 ASSERT_TRUE(result->IsString()); | 38 ASSERT_TRUE(result->IsString()); |
38 ASSERT_EQ("Hello", result->AsString()); | 39 ASSERT_EQ("Hello", result->AsString()); |
39 } | 40 } |
40 | 41 |
41 TEST_F(JsEngineTest, RuntimeExceptionIsThrown) | 42 TEST_F(JsEngineTest, RuntimeExceptionIsThrown) |
42 { | 43 { |
43 ASSERT_THROW(jsEngine->Evaluate("doesnotexist()"), AdblockPlus::JsError); | 44 ASSERT_THROW(jsEngine->Evaluate("doesnotexist()"), std::runtime_error); |
44 } | 45 } |
45 | 46 |
46 TEST_F(JsEngineTest, CompileTimeExceptionIsThrown) | 47 TEST_F(JsEngineTest, CompileTimeExceptionIsThrown) |
47 { | 48 { |
48 ASSERT_THROW(jsEngine->Evaluate("'foo'bar'"), AdblockPlus::JsError); | 49 ASSERT_THROW(jsEngine->Evaluate("'foo'bar'"), std::runtime_error); |
49 } | 50 } |
50 | 51 |
51 TEST_F(JsEngineTest, ValueCreation) | 52 TEST_F(JsEngineTest, ValueCreation) |
52 { | 53 { |
53 AdblockPlus::JsValuePtr value; | 54 AdblockPlus::JsValuePtr value; |
54 | 55 |
55 value = jsEngine->NewValue("foo"); | 56 value = jsEngine->NewValue("foo"); |
56 ASSERT_TRUE(value->IsString()); | 57 ASSERT_TRUE(value->IsString()); |
57 ASSERT_EQ("foo", value->AsString()); | 58 ASSERT_EQ("foo", value->AsString()); |
58 | 59 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 AdblockPlus::FileSystemPtr fileSystem(new AdblockPlus::DefaultFileSystem()); | 110 AdblockPlus::FileSystemPtr fileSystem(new AdblockPlus::DefaultFileSystem()); |
110 jsEngine->SetFileSystem(fileSystem); | 111 jsEngine->SetFileSystem(fileSystem); |
111 ASSERT_EQ(fileSystem, jsEngine->GetFileSystem()); | 112 ASSERT_EQ(fileSystem, jsEngine->GetFileSystem()); |
112 | 113 |
113 ASSERT_TRUE(jsEngine->GetWebRequest()); | 114 ASSERT_TRUE(jsEngine->GetWebRequest()); |
114 ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr())); | 115 ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr())); |
115 AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest()); | 116 AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest()); |
116 jsEngine->SetWebRequest(webRequest); | 117 jsEngine->SetWebRequest(webRequest); |
117 ASSERT_EQ(webRequest, jsEngine->GetWebRequest()); | 118 ASSERT_EQ(webRequest, jsEngine->GetWebRequest()); |
118 } | 119 } |
OLD | NEW |