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

Side by Side Diff: test/GlobalJsObject.cpp

Issue 10260028: Refactor tests, use fixtures and avoid duplication (Closed)
Patch Set: Created April 19, 2013, 4:11 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') | test/JsEngine.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 #include <AdblockPlus.h> 1 #include "BaseJsTest.h"
2 #include <gtest/gtest.h>
3
4 #include "../src/Thread.h" 2 #include "../src/Thread.h"
5 3
6 TEST(GlobalJsObjectTest, SetTimeout) 4 namespace
7 { 5 {
8 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); 6 class GlobalJsObjectTest : public BaseJsTest
7 {
8 };
9 }
10
11 TEST_F(GlobalJsObjectTest, SetTimeout)
12 {
9 jsEngine->Evaluate("setTimeout(function() {foo = 'bar';}, 100)"); 13 jsEngine->Evaluate("setTimeout(function() {foo = 'bar';}, 100)");
10 ASSERT_TRUE(jsEngine->Evaluate("this.foo")->IsUndefined()); 14 ASSERT_TRUE(jsEngine->Evaluate("this.foo")->IsUndefined());
11 AdblockPlus::Sleep(200); 15 AdblockPlus::Sleep(200);
12 ASSERT_EQ("bar", jsEngine->Evaluate("this.foo")->AsString()); 16 ASSERT_EQ("bar", jsEngine->Evaluate("this.foo")->AsString());
13 } 17 }
14 18
15 TEST(GlobalJsObjectTest, SetTimeoutWithArgs) 19 TEST_F(GlobalJsObjectTest, SetTimeoutWithArgs)
16 { 20 {
17 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
18 jsEngine->Evaluate("setTimeout(function(s) {foo = s;}, 100, 'foobar')"); 21 jsEngine->Evaluate("setTimeout(function(s) {foo = s;}, 100, 'foobar')");
19 ASSERT_TRUE(jsEngine->Evaluate("this.foo")->IsUndefined()); 22 ASSERT_TRUE(jsEngine->Evaluate("this.foo")->IsUndefined());
20 AdblockPlus::Sleep(200); 23 AdblockPlus::Sleep(200);
21 ASSERT_EQ("foobar", jsEngine->Evaluate("this.foo")->AsString()); 24 ASSERT_EQ("foobar", jsEngine->Evaluate("this.foo")->AsString());
22 } 25 }
23 26
24 TEST(GlobalJsObjectTest, SetTimeoutWithInvalidArgs) 27 TEST_F(GlobalJsObjectTest, SetTimeoutWithInvalidArgs)
25 { 28 {
26 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
27 ASSERT_ANY_THROW(jsEngine->Evaluate("setTimeout()")); 29 ASSERT_ANY_THROW(jsEngine->Evaluate("setTimeout()"));
28 ASSERT_ANY_THROW(jsEngine->Evaluate("setTimeout('', 1)")); 30 ASSERT_ANY_THROW(jsEngine->Evaluate("setTimeout('', 1)"));
29 } 31 }
30 32
31 TEST(GlobalJsObjectTest, SetMultipleTimeouts) 33 TEST_F(GlobalJsObjectTest, SetMultipleTimeouts)
32 { 34 {
33 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
34 jsEngine->Evaluate("foo = []"); 35 jsEngine->Evaluate("foo = []");
35 jsEngine->Evaluate("setTimeout(function(s) {foo.push('1');}, 100)"); 36 jsEngine->Evaluate("setTimeout(function(s) {foo.push('1');}, 100)");
36 jsEngine->Evaluate("setTimeout(function(s) {foo.push('2');}, 150)"); 37 jsEngine->Evaluate("setTimeout(function(s) {foo.push('2');}, 150)");
37 AdblockPlus::Sleep(200); 38 AdblockPlus::Sleep(200);
38 ASSERT_EQ("1,2", jsEngine->Evaluate("this.foo")->AsString()); 39 ASSERT_EQ("1,2", jsEngine->Evaluate("this.foo")->AsString());
39 } 40 }
OLDNEW
« no previous file with comments | « test/FilterEngine.cpp ('k') | test/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld