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