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

Delta Between Two Patch Sets: test/JsEngine.cpp

Issue 10420020: Made sure FilterEngine instances are always initialized (Closed)
Left Patch Set: Created May 16, 2013, 2:27 p.m.
Right Patch Set: Using a generic messaging mechanism Created May 23, 2013, 6:35 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « test/FilterEngine.cpp ('k') | third_party/googletest.gyp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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 "BaseJsTest.h" 18 #include "BaseJsTest.h"
19 19
20 namespace 20 namespace
21 { 21 {
22 class JsEngineTest : public BaseJsTest 22 class JsEngineTest : public BaseJsTest
23 { 23 {
24 }; 24 };
25
26 bool callbackCalled = false;
27 void Callback()
28 {
29 callbackCalled = true;
30 }
25 } 31 }
26 32
27 TEST_F(JsEngineTest, Evaluate) 33 TEST_F(JsEngineTest, Evaluate)
28 { 34 {
29 jsEngine->Evaluate("function hello() { return 'Hello'; }"); 35 jsEngine->Evaluate("function hello() { return 'Hello'; }");
30 AdblockPlus::JsValuePtr result = jsEngine->Evaluate("hello()"); 36 AdblockPlus::JsValuePtr result = jsEngine->Evaluate("hello()");
31 ASSERT_TRUE(result->IsString()); 37 ASSERT_TRUE(result->IsString());
32 ASSERT_EQ("Hello", result->AsString()); 38 ASSERT_EQ("Hello", result->AsString());
33 } 39 }
34 40
(...skipping 21 matching lines...) Expand all
56 62
57 value = jsEngine->NewValue(true); 63 value = jsEngine->NewValue(true);
58 ASSERT_TRUE(value->IsBool()); 64 ASSERT_TRUE(value->IsBool());
59 ASSERT_TRUE(value->AsBool()); 65 ASSERT_TRUE(value->AsBool());
60 66
61 value = jsEngine->NewObject(); 67 value = jsEngine->NewObject();
62 ASSERT_TRUE(value->IsObject()); 68 ASSERT_TRUE(value->IsObject());
63 ASSERT_EQ(0u, value->GetOwnPropertyNames().size()); 69 ASSERT_EQ(0u, value->GetOwnPropertyNames().size());
64 } 70 }
65 71
72 TEST_F(JsEngineTest, EventCallbacks)
73 {
74 // Trigger event without a callback
75 callbackCalled = false;
76 jsEngine->Evaluate("_triggerEvent('foobar')");
77 ASSERT_FALSE(callbackCalled);
78
79 // Set callback
80 jsEngine->SetEventCallback("foobar", Callback);
81 callbackCalled = false;
82 jsEngine->Evaluate("_triggerEvent('foobar')");
83 ASSERT_TRUE(callbackCalled);
84
85 // Trigger a different event
86 callbackCalled = false;
87 jsEngine->Evaluate("_triggerEvent('barfoo')");
88 ASSERT_FALSE(callbackCalled);
89
90 // Remove callback
91 jsEngine->RemoveEventCallback("foobar");
92 callbackCalled = false;
93 jsEngine->Evaluate("_triggerEvent('foobar')");
94 ASSERT_FALSE(callbackCalled);
95 }
96
66 TEST(NewJsEngineTest, CallbackGetSet) 97 TEST(NewJsEngineTest, CallbackGetSet)
67 { 98 {
68 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); 99 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
69 100
70 ASSERT_TRUE(jsEngine->GetLogSystem()); 101 ASSERT_TRUE(jsEngine->GetLogSystem());
71 ASSERT_ANY_THROW(jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr())); 102 ASSERT_ANY_THROW(jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr()));
72 AdblockPlus::LogSystemPtr logSystem(new AdblockPlus::DefaultLogSystem()); 103 AdblockPlus::LogSystemPtr logSystem(new AdblockPlus::DefaultLogSystem());
73 jsEngine->SetLogSystem(logSystem); 104 jsEngine->SetLogSystem(logSystem);
74 ASSERT_EQ(logSystem, jsEngine->GetLogSystem()); 105 ASSERT_EQ(logSystem, jsEngine->GetLogSystem());
75 106
76 ASSERT_TRUE(jsEngine->GetFileSystem()); 107 ASSERT_TRUE(jsEngine->GetFileSystem());
77 ASSERT_ANY_THROW(jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr())); 108 ASSERT_ANY_THROW(jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr()));
78 AdblockPlus::FileSystemPtr fileSystem(new AdblockPlus::DefaultFileSystem()); 109 AdblockPlus::FileSystemPtr fileSystem(new AdblockPlus::DefaultFileSystem());
79 jsEngine->SetFileSystem(fileSystem); 110 jsEngine->SetFileSystem(fileSystem);
80 ASSERT_EQ(fileSystem, jsEngine->GetFileSystem()); 111 ASSERT_EQ(fileSystem, jsEngine->GetFileSystem());
81 112
82 ASSERT_TRUE(jsEngine->GetWebRequest()); 113 ASSERT_TRUE(jsEngine->GetWebRequest());
83 ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr())); 114 ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr()));
84 AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest()); 115 AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest());
85 jsEngine->SetWebRequest(webRequest); 116 jsEngine->SetWebRequest(webRequest);
86 ASSERT_EQ(webRequest, jsEngine->GetWebRequest()); 117 ASSERT_EQ(webRequest, jsEngine->GetWebRequest());
87 } 118 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld