Left: | ||
Right: |
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 String read(String path) | |
46 { | |
47 if (path.equals(PATTERNS_INI)) | |
48 { | |
49 return "# Adblock Plus preferences\n[Subscription]\nurl=~fl~"; | |
50 } | |
51 else if (path.equals("prefs.json")) | |
52 { | |
53 return "{}"; | |
54 } | |
55 else | |
56 { | |
57 return ""; | |
58 } | |
59 } | |
60 | |
61 @Override | |
62 public void write(String path, String data) | |
63 { | |
64 | |
65 } | |
66 | |
67 @Override | |
68 public void move(String fromPath, String toPath) | |
69 { | |
70 | |
71 } | |
72 | |
73 @Override | |
74 public void remove(String path) | |
75 { | |
76 | |
77 } | |
78 | |
79 @Override | |
80 public FileSystem.StatResult stat(String path) | |
81 { | |
82 return path.equals(PATTERNS_INI) | |
83 ? new FileSystem.StatResult(patternsIniExists, false, true, 0) | |
84 : new FileSystem.StatResult(false, false, false, 0); | |
85 } | |
86 | |
87 @Override | |
88 public String resolve(String path) | |
89 { | |
90 return path; | |
91 } | |
92 } | |
93 | |
27 @Override | 94 @Override |
28 protected void setUp() throws Exception | 95 protected void setUp() throws Exception |
29 { | 96 { |
30 super.setUp(); | 97 super.setUp(); |
31 | 98 |
32 jsEngine.setWebRequest(new LazyWebRequest()); | 99 jsEngine.setWebRequest(new LazyWebRequest()); |
33 jsEngine.setDefaultLogSystem(); | 100 jsEngine.setDefaultLogSystem(); |
101 jsEngine.setFileSystem(new PatternsIniStubFileSystem()); | |
sergei
2017/05/22 12:09:06
Just for reference, I would expect that the propos
anton
2017/05/22 13:04:37
Acknowledged.
| |
34 | 102 |
35 filterEngine = new FilterEngine(jsEngine); | 103 filterEngine = new FilterEngine(jsEngine); |
36 } | 104 } |
37 } | 105 } |
OLD | NEW |