1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/tests/background/junit3/src/healthreport/TestEnvironmentBuilder.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +package org.mozilla.gecko.background.healthreport; 1.8 + 1.9 +import java.io.File; 1.10 +import java.io.IOException; 1.11 + 1.12 +import org.json.JSONException; 1.13 +import org.json.JSONObject; 1.14 +import org.mozilla.gecko.AppConstants; 1.15 +import org.mozilla.gecko.background.common.GlobalConstants; 1.16 +import org.mozilla.gecko.background.helpers.FakeProfileTestCase; 1.17 + 1.18 +public class TestEnvironmentBuilder extends FakeProfileTestCase { 1.19 + public static void testIgnoringAddons() throws JSONException { 1.20 + Environment env = new Environment() { 1.21 + @Override 1.22 + public int register() { 1.23 + return 0; 1.24 + } 1.25 + }; 1.26 + 1.27 + JSONObject addons = new JSONObject(); 1.28 + JSONObject foo = new JSONObject(); 1.29 + foo.put("a", 1); 1.30 + foo.put("b", "c"); 1.31 + addons.put("foo", foo); 1.32 + JSONObject ignore = new JSONObject(); 1.33 + ignore.put("ignore", true); 1.34 + addons.put("ig", ignore); 1.35 + 1.36 + env.setJSONForAddons(addons); 1.37 + 1.38 + JSONObject kept = env.getNonIgnoredAddons(); 1.39 + assertTrue(kept.has("foo")); 1.40 + assertFalse(kept.has("ig")); 1.41 + JSONObject fooCopy = kept.getJSONObject("foo"); 1.42 + assertSame(foo, fooCopy); 1.43 + } 1.44 + 1.45 + public void testSanity() throws IOException { 1.46 + File subdir = new File(this.fakeProfileDirectory.getAbsolutePath() + 1.47 + File.separator + "testPersisting"); 1.48 + subdir.mkdir(); 1.49 + long now = System.currentTimeMillis(); 1.50 + int expectedDays = (int) (now / GlobalConstants.MILLISECONDS_PER_DAY); 1.51 + 1.52 + MockProfileInformationCache cache = new MockProfileInformationCache(subdir.getAbsolutePath()); 1.53 + assertFalse(cache.getFile().exists()); 1.54 + cache.beginInitialization(); 1.55 + cache.setBlocklistEnabled(true); 1.56 + cache.setTelemetryEnabled(false); 1.57 + cache.setProfileCreationTime(now); 1.58 + cache.completeInitialization(); 1.59 + assertTrue(cache.getFile().exists()); 1.60 + 1.61 + Environment environment = EnvironmentBuilder.getCurrentEnvironment(cache); 1.62 + assertEquals(AppConstants.MOZ_APP_BUILDID, environment.appBuildID); 1.63 + assertEquals("Android", environment.os); 1.64 + assertTrue(100 < environment.memoryMB); // Seems like a sane lower bound... 1.65 + assertTrue(environment.cpuCount >= 1); 1.66 + assertEquals(1, environment.isBlocklistEnabled); 1.67 + assertEquals(0, environment.isTelemetryEnabled); 1.68 + assertEquals(expectedDays, environment.profileCreation); 1.69 + assertEquals(EnvironmentBuilder.getCurrentEnvironment(cache).getHash(), 1.70 + environment.getHash()); 1.71 + 1.72 + cache.beginInitialization(); 1.73 + cache.setBlocklistEnabled(false); 1.74 + cache.completeInitialization(); 1.75 + 1.76 + assertFalse(EnvironmentBuilder.getCurrentEnvironment(cache).getHash() 1.77 + .equals(environment.getHash())); 1.78 + } 1.79 +}