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

Side by Side Diff: test/GlobalJsObject.cpp

Issue 29523555: Issue 5552 - use strict mode for all JS in libadblocklus (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created Aug. 22, 2017, 7:29 a.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 16 matching lines...) Expand all
27 { 27 {
28 ThrowingPlatformCreationParameters params; 28 ThrowingPlatformCreationParameters params;
29 params.timer = AdblockPlus::CreateDefaultTimer(); 29 params.timer = AdblockPlus::CreateDefaultTimer();
30 platform.reset(new AdblockPlus::Platform(std::move(params))); 30 platform.reset(new AdblockPlus::Platform(std::move(params)));
31 } 31 }
32 }; 32 };
33 } 33 }
34 34
35 TEST_F(GlobalJsObjectTest, SetTimeout) 35 TEST_F(GlobalJsObjectTest, SetTimeout)
36 { 36 {
37 GetJsEngine().Evaluate("setTimeout(function() {foo = 'bar';}, 100)"); 37 GetJsEngine().Evaluate("let foo; setTimeout(function() {foo = 'bar';}, 100)");
38 ASSERT_TRUE(GetJsEngine().Evaluate("this.foo").IsUndefined()); 38 ASSERT_TRUE(GetJsEngine().Evaluate("foo").IsUndefined());
39 AdblockPlus::Sleep(200); 39 AdblockPlus::Sleep(200);
40 ASSERT_EQ("bar", GetJsEngine().Evaluate("this.foo").AsString()); 40 ASSERT_EQ("bar", GetJsEngine().Evaluate("foo").AsString());
41 } 41 }
42 42
43 TEST_F(GlobalJsObjectTest, SetTimeoutWithArgs) 43 TEST_F(GlobalJsObjectTest, SetTimeoutWithArgs)
44 { 44 {
45 GetJsEngine().Evaluate("setTimeout(function(s) {foo = s;}, 100, 'foobar')"); 45 GetJsEngine().Evaluate("let foo; setTimeout(function(s) {foo = s;}, 100, 'foob ar')");
46 ASSERT_TRUE(GetJsEngine().Evaluate("this.foo").IsUndefined()); 46 ASSERT_TRUE(GetJsEngine().Evaluate("foo").IsUndefined());
47 AdblockPlus::Sleep(200); 47 AdblockPlus::Sleep(200);
48 ASSERT_EQ("foobar", GetJsEngine().Evaluate("this.foo").AsString()); 48 ASSERT_EQ("foobar", GetJsEngine().Evaluate("foo").AsString());
49 } 49 }
50 50
51 TEST_F(GlobalJsObjectTest, SetTimeoutWithInvalidArgs) 51 TEST_F(GlobalJsObjectTest, SetTimeoutWithInvalidArgs)
52 { 52 {
53 ASSERT_ANY_THROW(GetJsEngine().Evaluate("setTimeout()")); 53 ASSERT_ANY_THROW(GetJsEngine().Evaluate("setTimeout()"));
54 ASSERT_ANY_THROW(GetJsEngine().Evaluate("setTimeout('', 1)")); 54 ASSERT_ANY_THROW(GetJsEngine().Evaluate("setTimeout('', 1)"));
55 } 55 }
56 56
57 TEST_F(GlobalJsObjectTest, SetMultipleTimeouts) 57 TEST_F(GlobalJsObjectTest, SetMultipleTimeouts)
58 { 58 {
59 GetJsEngine().Evaluate("foo = []"); 59 GetJsEngine().Evaluate("let foo = []");
60 GetJsEngine().Evaluate("setTimeout(function(s) {foo.push('1');}, 100)"); 60 GetJsEngine().Evaluate("setTimeout(function(s) {foo.push('1');}, 100)");
61 GetJsEngine().Evaluate("setTimeout(function(s) {foo.push('2');}, 150)"); 61 GetJsEngine().Evaluate("setTimeout(function(s) {foo.push('2');}, 150)");
62 AdblockPlus::Sleep(200); 62 AdblockPlus::Sleep(200);
63 ASSERT_EQ("1,2", GetJsEngine().Evaluate("this.foo").AsString()); 63 ASSERT_EQ("1,2", GetJsEngine().Evaluate("foo").AsString());
64 } 64 }
OLDNEW
« src/JsEngine.cpp ('K') | « test/FileSystemJsObject.cpp ('k') | test/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld