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

Side by Side Diff: test/GlobalJsObject.cpp

Issue 29417624: Issue 5034 - Part 4: JsEngine::Evaluate() return a JsValue (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created April 19, 2017, 6:18 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
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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
(...skipping 10 matching lines...) Expand all
21 namespace 21 namespace
22 { 22 {
23 class GlobalJsObjectTest : public BaseJsTest 23 class GlobalJsObjectTest : public BaseJsTest
24 { 24 {
25 }; 25 };
26 } 26 }
27 27
28 TEST_F(GlobalJsObjectTest, SetTimeout) 28 TEST_F(GlobalJsObjectTest, SetTimeout)
29 { 29 {
30 jsEngine->Evaluate("setTimeout(function() {foo = 'bar';}, 100)"); 30 jsEngine->Evaluate("setTimeout(function() {foo = 'bar';}, 100)");
31 ASSERT_TRUE(jsEngine->Evaluate("this.foo")->IsUndefined()); 31 ASSERT_TRUE(jsEngine->Evaluate("this.foo").IsUndefined());
32 AdblockPlus::Sleep(200); 32 AdblockPlus::Sleep(200);
33 ASSERT_EQ("bar", jsEngine->Evaluate("this.foo")->AsString()); 33 ASSERT_EQ("bar", jsEngine->Evaluate("this.foo").AsString());
34 } 34 }
35 35
36 TEST_F(GlobalJsObjectTest, SetTimeoutWithArgs) 36 TEST_F(GlobalJsObjectTest, SetTimeoutWithArgs)
37 { 37 {
38 jsEngine->Evaluate("setTimeout(function(s) {foo = s;}, 100, 'foobar')"); 38 jsEngine->Evaluate("setTimeout(function(s) {foo = s;}, 100, 'foobar')");
39 ASSERT_TRUE(jsEngine->Evaluate("this.foo")->IsUndefined()); 39 ASSERT_TRUE(jsEngine->Evaluate("this.foo").IsUndefined());
40 AdblockPlus::Sleep(200); 40 AdblockPlus::Sleep(200);
41 ASSERT_EQ("foobar", jsEngine->Evaluate("this.foo")->AsString()); 41 ASSERT_EQ("foobar", jsEngine->Evaluate("this.foo").AsString());
42 } 42 }
43 43
44 TEST_F(GlobalJsObjectTest, SetTimeoutWithInvalidArgs) 44 TEST_F(GlobalJsObjectTest, SetTimeoutWithInvalidArgs)
45 { 45 {
46 ASSERT_ANY_THROW(jsEngine->Evaluate("setTimeout()")); 46 ASSERT_ANY_THROW(jsEngine->Evaluate("setTimeout()"));
47 ASSERT_ANY_THROW(jsEngine->Evaluate("setTimeout('', 1)")); 47 ASSERT_ANY_THROW(jsEngine->Evaluate("setTimeout('', 1)"));
48 } 48 }
49 49
50 TEST_F(GlobalJsObjectTest, SetMultipleTimeouts) 50 TEST_F(GlobalJsObjectTest, SetMultipleTimeouts)
51 { 51 {
52 jsEngine->Evaluate("foo = []"); 52 jsEngine->Evaluate("foo = []");
53 jsEngine->Evaluate("setTimeout(function(s) {foo.push('1');}, 100)"); 53 jsEngine->Evaluate("setTimeout(function(s) {foo.push('1');}, 100)");
54 jsEngine->Evaluate("setTimeout(function(s) {foo.push('2');}, 150)"); 54 jsEngine->Evaluate("setTimeout(function(s) {foo.push('2');}, 150)");
55 AdblockPlus::Sleep(200); 55 AdblockPlus::Sleep(200);
56 ASSERT_EQ("1,2", jsEngine->Evaluate("this.foo")->AsString()); 56 ASSERT_EQ("1,2", jsEngine->Evaluate("this.foo").AsString());
57 } 57 }
58 58
59 TEST_F(GlobalJsObjectTest, TimeoutDoesNotKeepJsEngine) 59 TEST_F(GlobalJsObjectTest, TimeoutDoesNotKeepJsEngine)
60 { 60 {
61 jsEngine->Evaluate("setTimeout(function() {}, 50000)"); 61 jsEngine->Evaluate("setTimeout(function() {}, 50000)");
62 EXPECT_EQ(1u, jsEngine.use_count()); // check that counter is still 1 62 EXPECT_EQ(1u, jsEngine.use_count()); // check that counter is still 1
63 AdblockPlus::Sleep(200); 63 AdblockPlus::Sleep(200);
64 std::weak_ptr<AdblockPlus::JsEngine> weakJsEngine = jsEngine; 64 std::weak_ptr<AdblockPlus::JsEngine> weakJsEngine = jsEngine;
65 jsEngine.reset(); 65 jsEngine.reset();
66 EXPECT_FALSE(weakJsEngine.lock()); 66 EXPECT_FALSE(weakJsEngine.lock());
67 } 67 }
OLDNEW

Powered by Google App Engine
This is Rietveld