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-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 package org.adblockplus.libadblockplus.tests; | 18 package org.adblockplus.libadblockplus.tests; |
19 | 19 |
| 20 import org.adblockplus.libadblockplus.FileSystem; |
20 import org.adblockplus.libadblockplus.FilterEngine; | 21 import org.adblockplus.libadblockplus.FilterEngine; |
21 import org.adblockplus.libadblockplus.LazyWebRequest; | 22 import org.adblockplus.libadblockplus.LazyWebRequest; |
22 | 23 |
23 public abstract class FilterEngineGenericTest extends BaseJsTest | 24 public abstract class FilterEngineGenericTest extends BaseJsTest |
24 { | 25 { |
25 protected FilterEngine filterEngine; | 26 protected FilterEngine filterEngine; |
26 | 27 |
| 28 private static final class PatternsIniStubFileSystem extends FileSystem |
| 29 { |
| 30 private static final String PATTERNS_INI = "patterns.ini"; |
| 31 |
| 32 private boolean patternsIniExists = true; |
| 33 |
| 34 public boolean isPatternsIniExists() |
| 35 { |
| 36 return patternsIniExists; |
| 37 } |
| 38 |
| 39 public void setPatternsIniExists(boolean patternsIniExists) |
| 40 { |
| 41 this.patternsIniExists = patternsIniExists; |
| 42 } |
| 43 |
| 44 @Override |
| 45 public byte[] read(String path) |
| 46 { |
| 47 String result; |
| 48 if (path.equals(PATTERNS_INI)) |
| 49 { |
| 50 result = "# Adblock Plus preferences\n[Subscription]\nurl=~fl~"; |
| 51 } |
| 52 else if (path.equals("prefs.json")) |
| 53 { |
| 54 result = "{}"; |
| 55 } |
| 56 else |
| 57 { |
| 58 result = ""; |
| 59 } |
| 60 return result.getBytes(); |
| 61 } |
| 62 |
| 63 @Override |
| 64 public void write(String path, byte[] data) |
| 65 { |
| 66 |
| 67 } |
| 68 |
| 69 @Override |
| 70 public void move(String fromPath, String toPath) |
| 71 { |
| 72 |
| 73 } |
| 74 |
| 75 @Override |
| 76 public void remove(String path) |
| 77 { |
| 78 |
| 79 } |
| 80 |
| 81 @Override |
| 82 public FileSystem.StatResult stat(String path) |
| 83 { |
| 84 return path.equals(PATTERNS_INI) |
| 85 ? new FileSystem.StatResult(patternsIniExists, false, true, 0) |
| 86 : new FileSystem.StatResult(false, false, false, 0); |
| 87 } |
| 88 |
| 89 @Override |
| 90 public String resolve(String path) |
| 91 { |
| 92 return path; |
| 93 } |
| 94 } |
| 95 |
27 @Override | 96 @Override |
28 protected void setUp() throws Exception | 97 protected void setUp() throws Exception |
29 { | 98 { |
30 super.setUp(); | 99 super.setUp(); |
31 | 100 |
32 jsEngine.setWebRequest(new LazyWebRequest()); | 101 jsEngine.setWebRequest(new LazyWebRequest()); |
33 jsEngine.setDefaultLogSystem(); | 102 jsEngine.setDefaultLogSystem(); |
| 103 jsEngine.setFileSystem(new PatternsIniStubFileSystem()); |
34 | 104 |
35 filterEngine = new FilterEngine(jsEngine); | 105 filterEngine = new FilterEngine(jsEngine); |
36 } | 106 } |
37 } | 107 } |
OLD | NEW |