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

Side by Side Diff: test/JsEngine.cpp

Issue 4949583905947648: Issue 1280 - Update v8, the second part (Closed)
Patch Set: Created Oct. 27, 2014, 10:01 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
« no previous file with comments | « test/ConsoleJsObject.cpp ('k') | test/UpdateCheck.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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](AdblockPlus::JsValueList& p arams)
72 {
73 callbackCalled = true;
74 callbackParams = params;
75 };
76
77 // Trigger event without a callback 77 // Trigger event without a callback
78 callbackCalled = false; 78 callbackCalled = false;
79 jsEngine->Evaluate("_triggerEvent('foobar')"); 79 jsEngine->Evaluate("_triggerEvent('foobar')");
80 ASSERT_FALSE(callbackCalled); 80 ASSERT_FALSE(callbackCalled);
81 81
82 // Set callback 82 // Set callback
83 jsEngine->SetEventCallback("foobar", Callback); 83 jsEngine->SetEventCallback("foobar", Callback);
84 callbackCalled = false; 84 callbackCalled = false;
85 jsEngine->Evaluate("_triggerEvent('foobar', 1, 'x', true)"); 85 jsEngine->Evaluate("_triggerEvent('foobar', 1, 'x', true)");
86 ASSERT_TRUE(callbackCalled); 86 ASSERT_TRUE(callbackCalled);
(...skipping 29 matching lines...) Expand all
116 AdblockPlus::FileSystemPtr fileSystem(new AdblockPlus::DefaultFileSystem()); 116 AdblockPlus::FileSystemPtr fileSystem(new AdblockPlus::DefaultFileSystem());
117 jsEngine->SetFileSystem(fileSystem); 117 jsEngine->SetFileSystem(fileSystem);
118 ASSERT_EQ(fileSystem, jsEngine->GetFileSystem()); 118 ASSERT_EQ(fileSystem, jsEngine->GetFileSystem());
119 119
120 ASSERT_TRUE(jsEngine->GetWebRequest()); 120 ASSERT_TRUE(jsEngine->GetWebRequest());
121 ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr())); 121 ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr()));
122 AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest()); 122 AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest());
123 jsEngine->SetWebRequest(webRequest); 123 jsEngine->SetWebRequest(webRequest);
124 ASSERT_EQ(webRequest, jsEngine->GetWebRequest()); 124 ASSERT_EQ(webRequest, jsEngine->GetWebRequest());
125 } 125 }
OLDNEW
« no previous file with comments | « test/ConsoleJsObject.cpp ('k') | test/UpdateCheck.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld