Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | package org.mozilla.gecko.background.healthreport; |
michael@0 | 5 | |
michael@0 | 6 | import java.io.File; |
michael@0 | 7 | import java.io.IOException; |
michael@0 | 8 | |
michael@0 | 9 | import org.json.JSONException; |
michael@0 | 10 | import org.json.JSONObject; |
michael@0 | 11 | import org.mozilla.gecko.AppConstants; |
michael@0 | 12 | import org.mozilla.gecko.background.common.GlobalConstants; |
michael@0 | 13 | import org.mozilla.gecko.background.helpers.FakeProfileTestCase; |
michael@0 | 14 | |
michael@0 | 15 | public class TestEnvironmentBuilder extends FakeProfileTestCase { |
michael@0 | 16 | public static void testIgnoringAddons() throws JSONException { |
michael@0 | 17 | Environment env = new Environment() { |
michael@0 | 18 | @Override |
michael@0 | 19 | public int register() { |
michael@0 | 20 | return 0; |
michael@0 | 21 | } |
michael@0 | 22 | }; |
michael@0 | 23 | |
michael@0 | 24 | JSONObject addons = new JSONObject(); |
michael@0 | 25 | JSONObject foo = new JSONObject(); |
michael@0 | 26 | foo.put("a", 1); |
michael@0 | 27 | foo.put("b", "c"); |
michael@0 | 28 | addons.put("foo", foo); |
michael@0 | 29 | JSONObject ignore = new JSONObject(); |
michael@0 | 30 | ignore.put("ignore", true); |
michael@0 | 31 | addons.put("ig", ignore); |
michael@0 | 32 | |
michael@0 | 33 | env.setJSONForAddons(addons); |
michael@0 | 34 | |
michael@0 | 35 | JSONObject kept = env.getNonIgnoredAddons(); |
michael@0 | 36 | assertTrue(kept.has("foo")); |
michael@0 | 37 | assertFalse(kept.has("ig")); |
michael@0 | 38 | JSONObject fooCopy = kept.getJSONObject("foo"); |
michael@0 | 39 | assertSame(foo, fooCopy); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | public void testSanity() throws IOException { |
michael@0 | 43 | File subdir = new File(this.fakeProfileDirectory.getAbsolutePath() + |
michael@0 | 44 | File.separator + "testPersisting"); |
michael@0 | 45 | subdir.mkdir(); |
michael@0 | 46 | long now = System.currentTimeMillis(); |
michael@0 | 47 | int expectedDays = (int) (now / GlobalConstants.MILLISECONDS_PER_DAY); |
michael@0 | 48 | |
michael@0 | 49 | MockProfileInformationCache cache = new MockProfileInformationCache(subdir.getAbsolutePath()); |
michael@0 | 50 | assertFalse(cache.getFile().exists()); |
michael@0 | 51 | cache.beginInitialization(); |
michael@0 | 52 | cache.setBlocklistEnabled(true); |
michael@0 | 53 | cache.setTelemetryEnabled(false); |
michael@0 | 54 | cache.setProfileCreationTime(now); |
michael@0 | 55 | cache.completeInitialization(); |
michael@0 | 56 | assertTrue(cache.getFile().exists()); |
michael@0 | 57 | |
michael@0 | 58 | Environment environment = EnvironmentBuilder.getCurrentEnvironment(cache); |
michael@0 | 59 | assertEquals(AppConstants.MOZ_APP_BUILDID, environment.appBuildID); |
michael@0 | 60 | assertEquals("Android", environment.os); |
michael@0 | 61 | assertTrue(100 < environment.memoryMB); // Seems like a sane lower bound... |
michael@0 | 62 | assertTrue(environment.cpuCount >= 1); |
michael@0 | 63 | assertEquals(1, environment.isBlocklistEnabled); |
michael@0 | 64 | assertEquals(0, environment.isTelemetryEnabled); |
michael@0 | 65 | assertEquals(expectedDays, environment.profileCreation); |
michael@0 | 66 | assertEquals(EnvironmentBuilder.getCurrentEnvironment(cache).getHash(), |
michael@0 | 67 | environment.getHash()); |
michael@0 | 68 | |
michael@0 | 69 | cache.beginInitialization(); |
michael@0 | 70 | cache.setBlocklistEnabled(false); |
michael@0 | 71 | cache.completeInitialization(); |
michael@0 | 72 | |
michael@0 | 73 | assertFalse(EnvironmentBuilder.getCurrentEnvironment(cache).getHash() |
michael@0 | 74 | .equals(environment.getHash())); |
michael@0 | 75 | } |
michael@0 | 76 | } |