OLD | NEW |
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 97 |
98 // Remove callback | 98 // Remove callback |
99 jsEngine->RemoveEventCallback("foobar"); | 99 jsEngine->RemoveEventCallback("foobar"); |
100 callbackCalled = false; | 100 callbackCalled = false; |
101 jsEngine->Evaluate("_triggerEvent('foobar')"); | 101 jsEngine->Evaluate("_triggerEvent('foobar')"); |
102 ASSERT_FALSE(callbackCalled); | 102 ASSERT_FALSE(callbackCalled); |
103 } | 103 } |
104 | 104 |
105 TEST(NewJsEngineTest, CallbackGetSet) | 105 TEST(NewJsEngineTest, CallbackGetSet) |
106 { | 106 { |
107 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); | 107 auto jsEngine = AdblockPlus::JsEngine::New(); |
108 | 108 |
109 ASSERT_TRUE(jsEngine->GetLogSystem()); | 109 ASSERT_TRUE(jsEngine->GetLogSystem()); |
110 ASSERT_ANY_THROW(jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr())); | 110 ASSERT_ANY_THROW(jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr())); |
111 AdblockPlus::LogSystemPtr logSystem(new AdblockPlus::DefaultLogSystem()); | 111 auto logSystem(std::make_shared<AdblockPlus::DefaultLogSystem>()); |
112 jsEngine->SetLogSystem(logSystem); | 112 jsEngine->SetLogSystem(logSystem); |
113 ASSERT_EQ(logSystem, jsEngine->GetLogSystem()); | 113 ASSERT_EQ(logSystem, jsEngine->GetLogSystem()); |
114 | 114 |
115 ASSERT_TRUE(jsEngine->GetFileSystem()); | 115 ASSERT_TRUE(jsEngine->GetFileSystem()); |
116 ASSERT_ANY_THROW(jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr())); | 116 ASSERT_ANY_THROW(jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr())); |
117 AdblockPlus::FileSystemPtr fileSystem(new AdblockPlus::DefaultFileSystem()); | 117 auto fileSystem(std::make_shared<AdblockPlus::DefaultFileSystem>()); |
118 jsEngine->SetFileSystem(fileSystem); | 118 jsEngine->SetFileSystem(fileSystem); |
119 ASSERT_EQ(fileSystem, jsEngine->GetFileSystem()); | 119 ASSERT_EQ(fileSystem, jsEngine->GetFileSystem()); |
120 | 120 |
121 ASSERT_TRUE(jsEngine->GetWebRequest()); | 121 ASSERT_TRUE(jsEngine->GetWebRequest()); |
122 ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr())); | 122 ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr())); |
123 AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest()); | 123 auto webRequest(std::make_shared<AdblockPlus::DefaultWebRequest>()); |
124 jsEngine->SetWebRequest(webRequest); | 124 jsEngine->SetWebRequest(webRequest); |
125 ASSERT_EQ(webRequest, jsEngine->GetWebRequest()); | 125 ASSERT_EQ(webRequest, jsEngine->GetWebRequest()); |
| 126 |
| 127 ASSERT_EQ(1, jsEngine.use_count()); |
| 128 jsEngine.reset(); |
126 } | 129 } |
127 | 130 |
128 TEST(NewJsEngineTest, GlobalPropertyTest) | 131 TEST(NewJsEngineTest, GlobalPropertyTest) |
129 { | 132 { |
130 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); | 133 auto jsEngine = AdblockPlus::JsEngine::New(); |
131 jsEngine->SetGlobalProperty("foo", jsEngine->NewValue("bar")); | 134 jsEngine->SetGlobalProperty("foo", jsEngine->NewValue("bar")); |
132 AdblockPlus::JsValuePtr foo = jsEngine->Evaluate("foo"); | 135 /* |
133 ASSERT_TRUE(foo->IsString()); | 136 * Use a separate scope for JsValue variable to ensure its destruction |
134 ASSERT_EQ(foo->AsString(), "bar"); | 137 * before we check the use count of the engine. |
| 138 */ |
| 139 { |
| 140 auto foo = jsEngine->Evaluate("foo"); |
| 141 ASSERT_TRUE(foo->IsString()); |
| 142 ASSERT_EQ(foo->AsString(), "bar"); |
| 143 } |
| 144 ASSERT_EQ(1, jsEngine.use_count()); |
| 145 jsEngine.reset(); |
135 } | 146 } |
136 | 147 |
OLD | NEW |