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

Delta Between Two Patch Sets: test/FileSystemJsObject.cpp

Issue 10198022: Pass application data into libadblockplus (Closed)
Left Patch Set: Created April 12, 2013, 1:23 p.m.
Right Patch Set: Merged upstream, addressed issues, renamed AppInfo fields Created April 17, 2013, 2:47 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
LEFTRIGHT
(no file at all)
1 #include <AdblockPlus.h> 1 #include <AdblockPlus.h>
2 #include <gtest/gtest.h> 2 #include <gtest/gtest.h>
3 3
4 #include "../src/Thread.h" 4 #include "../src/Thread.h"
5 #include "../src/Utils.h" 5 #include "../src/Utils.h"
6 6
7 namespace 7 namespace
8 { 8 {
9 class MockFileSystem : public AdblockPlus::FileSystem 9 class MockFileSystem : public AdblockPlus::FileSystem
10 { 10 {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 AdblockPlus::Sleep(10); 80 AdblockPlus::Sleep(10);
81 content = jsEngine.Evaluate("result.content")->AsString(); 81 content = jsEngine.Evaluate("result.content")->AsString();
82 error = jsEngine.Evaluate("result.error")->AsString(); 82 error = jsEngine.Evaluate("result.error")->AsString();
83 } 83 }
84 } 84 }
85 85
86 TEST(FileSystemJsObjectTest, Read) 86 TEST(FileSystemJsObjectTest, Read)
87 { 87 {
88 MockFileSystem fileSystem; 88 MockFileSystem fileSystem;
89 fileSystem.contentToRead = "foo"; 89 fileSystem.contentToRead = "foo";
90 AdblockPlus::JsEngine jsEngine(&fileSystem, 0, 0); 90 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0, 0);
91 std::string content; 91 std::string content;
92 std::string error; 92 std::string error;
93 ReadFile(jsEngine, content, error); 93 ReadFile(jsEngine, content, error);
94 ASSERT_EQ("foo", content); 94 ASSERT_EQ("foo", content);
95 ASSERT_EQ("", error); 95 ASSERT_EQ("", error);
96 } 96 }
97 97
98 TEST(FileSystemJsObjectTest, ReadIllegalArguments) 98 TEST(FileSystemJsObjectTest, ReadIllegalArguments)
99 { 99 {
100 AdblockPlus::JsEngine jsEngine(0, 0, 0); 100 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), 0, 0, 0);
101 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.read()")); 101 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.read()"));
102 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.read('', '')")); 102 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.read('', '')"));
103 } 103 }
104 104
105 TEST(FileSystemJsObjectTest, ReadError) 105 TEST(FileSystemJsObjectTest, ReadError)
106 { 106 {
107 MockFileSystem fileSystem; 107 MockFileSystem fileSystem;
108 fileSystem.success = false; 108 fileSystem.success = false;
109 AdblockPlus::JsEngine jsEngine(&fileSystem, 0, 0); 109 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0, 0);
110 std::string content; 110 std::string content;
111 std::string error; 111 std::string error;
112 ReadFile(jsEngine, content, error); 112 ReadFile(jsEngine, content, error);
113 ASSERT_NE("", error); 113 ASSERT_NE("", error);
114 ASSERT_EQ("", content); 114 ASSERT_EQ("", content);
115 } 115 }
116 116
117 TEST(FileSystemJsObjectTest, Write) 117 TEST(FileSystemJsObjectTest, Write)
118 { 118 {
119 MockFileSystem fileSystem; 119 MockFileSystem fileSystem;
120 AdblockPlus::JsEngine jsEngine(&fileSystem, 0, 0); 120 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0, 0);
121 jsEngine.Evaluate("_fileSystem.write('foo', 'bar', function(e) {error = e})"); 121 jsEngine.Evaluate("_fileSystem.write('foo', 'bar', function(e) {error = e})");
122 AdblockPlus::Sleep(10); 122 AdblockPlus::Sleep(10);
123 ASSERT_EQ("foo", fileSystem.lastWrittenPath); 123 ASSERT_EQ("foo", fileSystem.lastWrittenPath);
124 ASSERT_EQ("bar", fileSystem.lastWrittenContent); 124 ASSERT_EQ("bar", fileSystem.lastWrittenContent);
125 ASSERT_EQ("", jsEngine.Evaluate("error")->AsString()); 125 ASSERT_EQ("", jsEngine.Evaluate("error")->AsString());
126 } 126 }
127 127
128 TEST(FileSystemJsObjectTest, WriteIllegalArguments) 128 TEST(FileSystemJsObjectTest, WriteIllegalArguments)
129 { 129 {
130 AdblockPlus::JsEngine jsEngine(0, 0, 0); 130 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), 0, 0, 0);
131 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.write()")); 131 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.write()"));
132 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.write('', '', '')")); 132 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.write('', '', '')"));
133 } 133 }
134 134
135 TEST(FileSystemJsObjectTest, WriteError) 135 TEST(FileSystemJsObjectTest, WriteError)
136 { 136 {
137 MockFileSystem fileSystem; 137 MockFileSystem fileSystem;
138 fileSystem.success = false; 138 fileSystem.success = false;
139 AdblockPlus::JsEngine jsEngine(&fileSystem, 0, 0); 139 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0, 0);
140 jsEngine.Evaluate("_fileSystem.write('foo', 'bar', function(e) {error = e})"); 140 jsEngine.Evaluate("_fileSystem.write('foo', 'bar', function(e) {error = e})");
141 AdblockPlus::Sleep(10); 141 AdblockPlus::Sleep(10);
142 ASSERT_NE("", jsEngine.Evaluate("error")->AsString()); 142 ASSERT_NE("", jsEngine.Evaluate("error")->AsString());
143 } 143 }
144 144
145 TEST(FileSystemJsObjectTest, Move) 145 TEST(FileSystemJsObjectTest, Move)
146 { 146 {
147 MockFileSystem fileSystem; 147 MockFileSystem fileSystem;
148 AdblockPlus::JsEngine jsEngine(&fileSystem, 0, 0); 148 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0, 0);
149 jsEngine.Evaluate("_fileSystem.move('foo', 'bar', function(e) {error = e})"); 149 jsEngine.Evaluate("_fileSystem.move('foo', 'bar', function(e) {error = e})");
150 AdblockPlus::Sleep(10); 150 AdblockPlus::Sleep(10);
151 ASSERT_EQ("foo", fileSystem.movedFrom); 151 ASSERT_EQ("foo", fileSystem.movedFrom);
152 ASSERT_EQ("bar", fileSystem.movedTo); 152 ASSERT_EQ("bar", fileSystem.movedTo);
153 ASSERT_EQ("", jsEngine.Evaluate("error")->AsString()); 153 ASSERT_EQ("", jsEngine.Evaluate("error")->AsString());
154 } 154 }
155 155
156 TEST(FileSystemJsObjectTest, MoveIllegalArguments) 156 TEST(FileSystemJsObjectTest, MoveIllegalArguments)
157 { 157 {
158 AdblockPlus::JsEngine jsEngine(0, 0, 0); 158 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), 0, 0, 0);
159 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.move()")); 159 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.move()"));
160 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.move('', '', '')")); 160 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.move('', '', '')"));
161 } 161 }
162 162
163 TEST(FileSystemJsObjectTest, MoveError) 163 TEST(FileSystemJsObjectTest, MoveError)
164 { 164 {
165 MockFileSystem fileSystem; 165 MockFileSystem fileSystem;
166 fileSystem.success = false; 166 fileSystem.success = false;
167 AdblockPlus::JsEngine jsEngine(&fileSystem, 0, 0); 167 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0, 0);
168 jsEngine.Evaluate("_fileSystem.move('foo', 'bar', function(e) {error = e})"); 168 jsEngine.Evaluate("_fileSystem.move('foo', 'bar', function(e) {error = e})");
169 AdblockPlus::Sleep(10); 169 AdblockPlus::Sleep(10);
170 ASSERT_NE("", jsEngine.Evaluate("error")->AsString()); 170 ASSERT_NE("", jsEngine.Evaluate("error")->AsString());
171 } 171 }
172 172
173 TEST(FileSystemJsObjectTest, Remove) 173 TEST(FileSystemJsObjectTest, Remove)
174 { 174 {
175 MockFileSystem fileSystem; 175 MockFileSystem fileSystem;
176 AdblockPlus::JsEngine jsEngine(&fileSystem, 0, 0); 176 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0, 0);
177 jsEngine.Evaluate("_fileSystem.remove('foo', function(e) {error = e})"); 177 jsEngine.Evaluate("_fileSystem.remove('foo', function(e) {error = e})");
178 AdblockPlus::Sleep(10); 178 AdblockPlus::Sleep(10);
179 ASSERT_EQ("foo", fileSystem.removedPath); 179 ASSERT_EQ("foo", fileSystem.removedPath);
180 ASSERT_EQ("", jsEngine.Evaluate("error")->AsString()); 180 ASSERT_EQ("", jsEngine.Evaluate("error")->AsString());
181 } 181 }
182 182
183 TEST(FileSystemJsObjectTest, RemoveIllegalArguments) 183 TEST(FileSystemJsObjectTest, RemoveIllegalArguments)
184 { 184 {
185 AdblockPlus::JsEngine jsEngine(0, 0, 0); 185 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), 0, 0, 0);
186 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.remove()")); 186 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.remove()"));
187 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.remove('', '')")); 187 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.remove('', '')"));
188 } 188 }
189 189
190 TEST(FileSystemJsObjectTest, RemoveError) 190 TEST(FileSystemJsObjectTest, RemoveError)
191 { 191 {
192 MockFileSystem fileSystem; 192 MockFileSystem fileSystem;
193 fileSystem.success = false; 193 fileSystem.success = false;
194 AdblockPlus::JsEngine jsEngine(&fileSystem, 0, 0); 194 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0, 0);
195 jsEngine.Evaluate("_fileSystem.remove('foo', function(e) {error = e})"); 195 jsEngine.Evaluate("_fileSystem.remove('foo', function(e) {error = e})");
196 AdblockPlus::Sleep(10); 196 AdblockPlus::Sleep(10);
197 ASSERT_NE("", jsEngine.Evaluate("error")->AsString()); 197 ASSERT_NE("", jsEngine.Evaluate("error")->AsString());
198 } 198 }
199 199
200 TEST(FileSystemJsObjectTest, Stat) 200 TEST(FileSystemJsObjectTest, Stat)
201 { 201 {
202 MockFileSystem fileSystem; 202 MockFileSystem fileSystem;
203 fileSystem.statExists = true; 203 fileSystem.statExists = true;
204 fileSystem.statIsDirectory= false; 204 fileSystem.statIsDirectory= false;
205 fileSystem.statIsFile = true; 205 fileSystem.statIsFile = true;
206 fileSystem.statLastModified = 1337; 206 fileSystem.statLastModified = 1337;
207 AdblockPlus::JsEngine jsEngine(&fileSystem, 0, 0); 207 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0, 0);
208 jsEngine.Evaluate("_fileSystem.stat('foo', function(r) {result = r})"); 208 jsEngine.Evaluate("_fileSystem.stat('foo', function(r) {result = r})");
209 AdblockPlus::Sleep(10); 209 AdblockPlus::Sleep(10);
210 ASSERT_EQ("foo", fileSystem.statPath); 210 ASSERT_EQ("foo", fileSystem.statPath);
211 ASSERT_EQ("", jsEngine.Evaluate("result.error")->AsString()); 211 ASSERT_EQ("", jsEngine.Evaluate("result.error")->AsString());
212 ASSERT_TRUE(jsEngine.Evaluate("result.exists")->AsBool()); 212 ASSERT_TRUE(jsEngine.Evaluate("result.exists")->AsBool());
213 ASSERT_FALSE(jsEngine.Evaluate("result.isDirectory")->AsBool()); 213 ASSERT_FALSE(jsEngine.Evaluate("result.isDirectory")->AsBool());
214 ASSERT_TRUE(jsEngine.Evaluate("result.isFile")->AsBool()); 214 ASSERT_TRUE(jsEngine.Evaluate("result.isFile")->AsBool());
215 ASSERT_EQ(1337, jsEngine.Evaluate("result.lastModified")->AsInt()); 215 ASSERT_EQ(1337, jsEngine.Evaluate("result.lastModified")->AsInt());
216 } 216 }
217 217
218 TEST(FileSystemJsObjectTest, StatIllegalArguments) 218 TEST(FileSystemJsObjectTest, StatIllegalArguments)
219 { 219 {
220 AdblockPlus::JsEngine jsEngine(0, 0, 0); 220 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), 0, 0, 0);
221 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.stat()")); 221 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.stat()"));
222 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.stat('', '')")); 222 ASSERT_ANY_THROW(jsEngine.Evaluate("_fileSystem.stat('', '')"));
223 } 223 }
224 224
225 TEST(FileSystemJsObjectTest, StatError) 225 TEST(FileSystemJsObjectTest, StatError)
226 { 226 {
227 MockFileSystem fileSystem; 227 MockFileSystem fileSystem;
228 fileSystem.success = false; 228 fileSystem.success = false;
229 AdblockPlus::JsEngine jsEngine(&fileSystem, 0, 0); 229 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0, 0);
230 jsEngine.Evaluate("_fileSystem.stat('foo', function(r) {result = r})"); 230 jsEngine.Evaluate("_fileSystem.stat('foo', function(r) {result = r})");
231 AdblockPlus::Sleep(10); 231 AdblockPlus::Sleep(10);
232 ASSERT_NE("", jsEngine.Evaluate("result.error")->AsString()); 232 ASSERT_NE("", jsEngine.Evaluate("result.error")->AsString());
233 } 233 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld