michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: package org.mozilla.gecko.background.healthreport; michael@0: michael@0: import java.io.File; michael@0: import java.io.IOException; michael@0: michael@0: import org.json.JSONException; michael@0: import org.json.JSONObject; michael@0: import org.mozilla.gecko.AppConstants; michael@0: import org.mozilla.gecko.background.common.GlobalConstants; michael@0: import org.mozilla.gecko.background.helpers.FakeProfileTestCase; michael@0: michael@0: public class TestEnvironmentBuilder extends FakeProfileTestCase { michael@0: public static void testIgnoringAddons() throws JSONException { michael@0: Environment env = new Environment() { michael@0: @Override michael@0: public int register() { michael@0: return 0; michael@0: } michael@0: }; michael@0: michael@0: JSONObject addons = new JSONObject(); michael@0: JSONObject foo = new JSONObject(); michael@0: foo.put("a", 1); michael@0: foo.put("b", "c"); michael@0: addons.put("foo", foo); michael@0: JSONObject ignore = new JSONObject(); michael@0: ignore.put("ignore", true); michael@0: addons.put("ig", ignore); michael@0: michael@0: env.setJSONForAddons(addons); michael@0: michael@0: JSONObject kept = env.getNonIgnoredAddons(); michael@0: assertTrue(kept.has("foo")); michael@0: assertFalse(kept.has("ig")); michael@0: JSONObject fooCopy = kept.getJSONObject("foo"); michael@0: assertSame(foo, fooCopy); michael@0: } michael@0: michael@0: public void testSanity() throws IOException { michael@0: File subdir = new File(this.fakeProfileDirectory.getAbsolutePath() + michael@0: File.separator + "testPersisting"); michael@0: subdir.mkdir(); michael@0: long now = System.currentTimeMillis(); michael@0: int expectedDays = (int) (now / GlobalConstants.MILLISECONDS_PER_DAY); michael@0: michael@0: MockProfileInformationCache cache = new MockProfileInformationCache(subdir.getAbsolutePath()); michael@0: assertFalse(cache.getFile().exists()); michael@0: cache.beginInitialization(); michael@0: cache.setBlocklistEnabled(true); michael@0: cache.setTelemetryEnabled(false); michael@0: cache.setProfileCreationTime(now); michael@0: cache.completeInitialization(); michael@0: assertTrue(cache.getFile().exists()); michael@0: michael@0: Environment environment = EnvironmentBuilder.getCurrentEnvironment(cache); michael@0: assertEquals(AppConstants.MOZ_APP_BUILDID, environment.appBuildID); michael@0: assertEquals("Android", environment.os); michael@0: assertTrue(100 < environment.memoryMB); // Seems like a sane lower bound... michael@0: assertTrue(environment.cpuCount >= 1); michael@0: assertEquals(1, environment.isBlocklistEnabled); michael@0: assertEquals(0, environment.isTelemetryEnabled); michael@0: assertEquals(expectedDays, environment.profileCreation); michael@0: assertEquals(EnvironmentBuilder.getCurrentEnvironment(cache).getHash(), michael@0: environment.getHash()); michael@0: michael@0: cache.beginInitialization(); michael@0: cache.setBlocklistEnabled(false); michael@0: cache.completeInitialization(); michael@0: michael@0: assertFalse(EnvironmentBuilder.getCurrentEnvironment(cache).getHash() michael@0: .equals(environment.getHash())); michael@0: } michael@0: }