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

Side by Side Diff: test/JsEngine.cpp

Issue 29500602: Issue 5450 - introduce the Platform class (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created July 28, 2017, 12:40 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <stdexcept> 18 #include <stdexcept>
19 #include "BaseJsTest.h" 19 #include "BaseJsTest.h"
20 20
21 using namespace AdblockPlus; 21 using namespace AdblockPlus;
22 22
23 namespace 23 namespace
24 { 24 {
25 class JsEngineTest : public BaseJsTest 25 class JsEngineTest : public BaseJsTest
26 { 26 {
27 protected:
28 JsEnginePtr jsEngine;
29 void SetUp() override
30 {
31 BaseJsTest::SetUp();
32 jsEngine = platform->GetJsEngine();
33 }
27 }; 34 };
28 } 35 }
29 36
30 TEST_F(JsEngineTest, Evaluate) 37 TEST_F(JsEngineTest, Evaluate)
31 { 38 {
32 jsEngine->Evaluate("function hello() { return 'Hello'; }"); 39 jsEngine->Evaluate("function hello() { return 'Hello'; }");
33 auto result = jsEngine->Evaluate("hello()"); 40 auto result = jsEngine->Evaluate("hello()");
34 ASSERT_TRUE(result.IsString()); 41 ASSERT_TRUE(result.IsString());
35 ASSERT_EQ("Hello", result.AsString()); 42 ASSERT_EQ("Hello", result.AsString());
36 } 43 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 164
158 // Remove callback 165 // Remove callback
159 jsEngine->RemoveEventCallback("foobar"); 166 jsEngine->RemoveEventCallback("foobar");
160 callbackCalled = false; 167 callbackCalled = false;
161 jsEngine->Evaluate("_triggerEvent('foobar')"); 168 jsEngine->Evaluate("_triggerEvent('foobar')");
162 ASSERT_FALSE(callbackCalled); 169 ASSERT_FALSE(callbackCalled);
163 } 170 }
164 171
165 TEST(NewJsEngineTest, GlobalPropertyTest) 172 TEST(NewJsEngineTest, GlobalPropertyTest)
166 { 173 {
167 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); 174 Platform platform{ThrowingPlatformCreationParameters()};
175 auto jsEngine = platform.GetJsEngine();
168 jsEngine->SetGlobalProperty("foo", jsEngine->NewValue("bar")); 176 jsEngine->SetGlobalProperty("foo", jsEngine->NewValue("bar"));
169 auto foo = jsEngine->Evaluate("foo"); 177 auto foo = jsEngine->Evaluate("foo");
170 ASSERT_TRUE(foo.IsString()); 178 ASSERT_TRUE(foo.IsString());
171 ASSERT_EQ(foo.AsString(), "bar"); 179 ASSERT_EQ(foo.AsString(), "bar");
172 } 180 }
173 181
174 TEST(NewJsEngineTest, MemoryLeak_NoCircularReferences) 182 TEST(NewJsEngineTest, MemoryLeak_NoCircularReferences)
175 { 183 {
176 std::weak_ptr<AdblockPlus::JsEngine> weakJsEngine; 184 std::weak_ptr<AdblockPlus::JsEngine> weakJsEngine;
177 { 185 {
178 weakJsEngine = AdblockPlus::JsEngine::New(); 186 weakJsEngine = Platform{ThrowingPlatformCreationParameters()}.GetJsEngine();
179 } 187 }
180 EXPECT_FALSE(weakJsEngine.lock()); 188 EXPECT_FALSE(weakJsEngine.lock());
181 } 189 }
182 190
183 #if UINTPTR_MAX == UINT32_MAX // detection of 32-bit platform 191 #if UINTPTR_MAX == UINT32_MAX // detection of 32-bit platform
184 static_assert(sizeof(intptr_t) == 4, "It should be 32bit platform"); 192 static_assert(sizeof(intptr_t) == 4, "It should be 32bit platform");
185 TEST(NewJsEngineTest, 32bitsOnly_MemoryLeak_NoLeak) 193 TEST(NewJsEngineTest, 32bitsOnly_MemoryLeak_NoLeak)
186 #else 194 #else
187 TEST(NewJsEngineTest, DISABLED_32bitsOnly_MemoryLeak_NoLeak) 195 TEST(NewJsEngineTest, DISABLED_32bitsOnly_MemoryLeak_NoLeak)
188 #endif 196 #endif
189 { 197 {
190 // v8::Isolate by default requires 32MB (depends on platform), so if there is 198 // v8::Isolate by default requires 32MB (depends on platform), so if there is
191 // a memory leak than we will run out of memory on 32 bit platform because it 199 // a memory leak than we will run out of memory on 32 bit platform because it
192 // will allocate 32000 MB which is less than 2GB where it reaches out of 200 // will allocate 32000 MB which is less than 2GB where it reaches out of
193 // memory. Even on android where it allocates initially 16MB, the test still 201 // memory. Even on android where it allocates initially 16MB, the test still
194 // makes sense. 202 // makes sense.
195 for (int i = 0; i < 1000; ++i) 203 for (int i = 0; i < 1000; ++i)
196 { 204 {
197 AdblockPlus::JsEngine::New(); 205 Platform{ThrowingPlatformCreationParameters()}.GetJsEngine();
198 } 206 }
199 } 207 }
OLDNEW
« include/AdblockPlus/JsEngine.h ('K') | « test/GlobalJsObject.cpp ('k') | test/JsValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld