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

Unified Diff: test/GlobalJsObject.cpp

Issue 10085006: Implement setTimeout (Closed)
Patch Set: Created April 8, 2013, 1:07 p.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
« src/GlobalJsObject.cpp ('K') | « src/JsEngine.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/GlobalJsObject.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/GlobalJsObject.cpp
@@ -0,0 +1,40 @@
+#include <AdblockPlus.h>
+#include <gtest/gtest.h>
+
+#include "../src/Thread.h"
+
+TEST(GlobalJsObjectTest, SetTimeout)
+{
+ AdblockPlus::JsEngine jsEngine(0, 0);
+ jsEngine.Evaluate("setTimeout(function() {foo = 'bar';}, 100)");
+ ASSERT_EQ("", jsEngine.GetVariable("foo"));
+ AdblockPlus::Sleep(200);
+ ASSERT_EQ("bar", jsEngine.GetVariable("foo"));
+}
+
+TEST(GlobalJsObjectTest, SetTimeoutWithArgs)
+{
+ AdblockPlus::JsEngine jsEngine(0, 0);
+ jsEngine.Evaluate("setTimeout(function(s) {foo = s;}, 100, 'foobar')");
+ ASSERT_EQ("", jsEngine.GetVariable("foo"));
+ AdblockPlus::Sleep(200);
+ ASSERT_EQ("foobar", jsEngine.GetVariable("foo"));
+}
+
+TEST(GlobalJsObjectTest, SetTimeoutWithInvalidArgs)
+{
+ AdblockPlus::JsEngine jsEngine(0, 0);
+ ASSERT_ANY_THROW(jsEngine.Evaluate("setTimeout()"));
+ ASSERT_ANY_THROW(jsEngine.Evaluate("setTimeout('', 1)"));
+ ASSERT_ANY_THROW(jsEngine.Evaluate("setTimeout(function(){}, '')"));
+}
+
+TEST(GlobalJsObjectTest, SetMultipleTimeouts)
+{
+ AdblockPlus::JsEngine jsEngine(0, 0);
+ jsEngine.Evaluate("foo = []");
+ jsEngine.Evaluate("setTimeout(function(s) {foo.push('1');}, 100)");
+ jsEngine.Evaluate("setTimeout(function(s) {foo.push('2');}, 150)");
+ AdblockPlus::Sleep(200);
+ ASSERT_EQ("1,2", jsEngine.GetVariable("foo"));
+}
« src/GlobalJsObject.cpp ('K') | « src/JsEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld