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

Unified Diff: test/JsEngine.cpp

Issue 10420020: Made sure FilterEngine instances are always initialized (Closed)
Patch Set: Using a generic messaging mechanism Created May 23, 2013, 6:35 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/FilterEngine.cpp ('k') | third_party/googletest.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/JsEngine.cpp
===================================================================
--- a/test/JsEngine.cpp
+++ b/test/JsEngine.cpp
@@ -17,16 +17,22 @@
#include "BaseJsTest.h"
namespace
{
class JsEngineTest : public BaseJsTest
{
};
+
+ bool callbackCalled = false;
+ void Callback()
+ {
+ callbackCalled = true;
+ }
}
TEST_F(JsEngineTest, Evaluate)
{
jsEngine->Evaluate("function hello() { return 'Hello'; }");
AdblockPlus::JsValuePtr result = jsEngine->Evaluate("hello()");
ASSERT_TRUE(result->IsString());
ASSERT_EQ("Hello", result->AsString());
@@ -58,16 +64,41 @@ TEST_F(JsEngineTest, ValueCreation)
ASSERT_TRUE(value->IsBool());
ASSERT_TRUE(value->AsBool());
value = jsEngine->NewObject();
ASSERT_TRUE(value->IsObject());
ASSERT_EQ(0u, value->GetOwnPropertyNames().size());
}
+TEST_F(JsEngineTest, EventCallbacks)
+{
+ // Trigger event without a callback
+ callbackCalled = false;
+ jsEngine->Evaluate("_triggerEvent('foobar')");
+ ASSERT_FALSE(callbackCalled);
+
+ // Set callback
+ jsEngine->SetEventCallback("foobar", Callback);
+ callbackCalled = false;
+ jsEngine->Evaluate("_triggerEvent('foobar')");
+ ASSERT_TRUE(callbackCalled);
+
+ // Trigger a different event
+ callbackCalled = false;
+ jsEngine->Evaluate("_triggerEvent('barfoo')");
+ ASSERT_FALSE(callbackCalled);
+
+ // Remove callback
+ jsEngine->RemoveEventCallback("foobar");
+ callbackCalled = false;
+ jsEngine->Evaluate("_triggerEvent('foobar')");
+ ASSERT_FALSE(callbackCalled);
+}
+
TEST(NewJsEngineTest, CallbackGetSet)
{
AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
ASSERT_TRUE(jsEngine->GetLogSystem());
ASSERT_ANY_THROW(jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr()));
AdblockPlus::LogSystemPtr logSystem(new AdblockPlus::DefaultLogSystem());
jsEngine->SetLogSystem(logSystem);
« no previous file with comments | « test/FilterEngine.cpp ('k') | third_party/googletest.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld