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

Side by Side Diff: test/JsEngine.cpp

Issue 10862008: Automatically add default filter subscription when necessary. (Closed)
Patch Set: Created May 27, 2013, 2:12 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/FilterEngine.cpp ('k') | no next file » | 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-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 <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 26
27 bool callbackCalled = false; 27 bool callbackCalled = false;
28 void Callback() 28 AdblockPlus::JsValueList callbackParams;
29 void Callback(AdblockPlus::JsValueList& params)
29 { 30 {
30 callbackCalled = true; 31 callbackCalled = true;
32 callbackParams = params;
31 } 33 }
32 } 34 }
33 35
34 TEST_F(JsEngineTest, Evaluate) 36 TEST_F(JsEngineTest, Evaluate)
35 { 37 {
36 jsEngine->Evaluate("function hello() { return 'Hello'; }"); 38 jsEngine->Evaluate("function hello() { return 'Hello'; }");
37 AdblockPlus::JsValuePtr result = jsEngine->Evaluate("hello()"); 39 AdblockPlus::JsValuePtr result = jsEngine->Evaluate("hello()");
38 ASSERT_TRUE(result->IsString()); 40 ASSERT_TRUE(result->IsString());
39 ASSERT_EQ("Hello", result->AsString()); 41 ASSERT_EQ("Hello", result->AsString());
40 } 42 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 TEST_F(JsEngineTest, EventCallbacks) 75 TEST_F(JsEngineTest, EventCallbacks)
74 { 76 {
75 // Trigger event without a callback 77 // Trigger event without a callback
76 callbackCalled = false; 78 callbackCalled = false;
77 jsEngine->Evaluate("_triggerEvent('foobar')"); 79 jsEngine->Evaluate("_triggerEvent('foobar')");
78 ASSERT_FALSE(callbackCalled); 80 ASSERT_FALSE(callbackCalled);
79 81
80 // Set callback 82 // Set callback
81 jsEngine->SetEventCallback("foobar", Callback); 83 jsEngine->SetEventCallback("foobar", Callback);
82 callbackCalled = false; 84 callbackCalled = false;
83 jsEngine->Evaluate("_triggerEvent('foobar')"); 85 jsEngine->Evaluate("_triggerEvent('foobar', 1, 'x', true)");
84 ASSERT_TRUE(callbackCalled); 86 ASSERT_TRUE(callbackCalled);
87 ASSERT_EQ(callbackParams.size(), 3u);
88 ASSERT_EQ(callbackParams[0]->AsInt(), 1);
89 ASSERT_EQ(callbackParams[1]->AsString(), "x");
90 ASSERT_TRUE(callbackParams[2]->AsBool());
85 91
86 // Trigger a different event 92 // Trigger a different event
87 callbackCalled = false; 93 callbackCalled = false;
88 jsEngine->Evaluate("_triggerEvent('barfoo')"); 94 jsEngine->Evaluate("_triggerEvent('barfoo')");
89 ASSERT_FALSE(callbackCalled); 95 ASSERT_FALSE(callbackCalled);
90 96
91 // Remove callback 97 // Remove callback
92 jsEngine->RemoveEventCallback("foobar"); 98 jsEngine->RemoveEventCallback("foobar");
93 callbackCalled = false; 99 callbackCalled = false;
94 jsEngine->Evaluate("_triggerEvent('foobar')"); 100 jsEngine->Evaluate("_triggerEvent('foobar')");
(...skipping 15 matching lines...) Expand all
110 AdblockPlus::FileSystemPtr fileSystem(new AdblockPlus::DefaultFileSystem()); 116 AdblockPlus::FileSystemPtr fileSystem(new AdblockPlus::DefaultFileSystem());
111 jsEngine->SetFileSystem(fileSystem); 117 jsEngine->SetFileSystem(fileSystem);
112 ASSERT_EQ(fileSystem, jsEngine->GetFileSystem()); 118 ASSERT_EQ(fileSystem, jsEngine->GetFileSystem());
113 119
114 ASSERT_TRUE(jsEngine->GetWebRequest()); 120 ASSERT_TRUE(jsEngine->GetWebRequest());
115 ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr())); 121 ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr()));
116 AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest()); 122 AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest());
117 jsEngine->SetWebRequest(webRequest); 123 jsEngine->SetWebRequest(webRequest);
118 ASSERT_EQ(webRequest, jsEngine->GetWebRequest()); 124 ASSERT_EQ(webRequest, jsEngine->GetWebRequest());
119 } 125 }
OLDNEW
« no previous file with comments | « test/FilterEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld