Bug 1184186 - Convert robocop testSharedPreferences to mochitest-chrome; r=nalexander
authorGeoff Brown <gbrown@mozilla.com>
Thu, 06 Aug 2015 07:27:48 -0600
changeset 288190 14abce1059c65f1f1cc6d4fd117342ebd5eb97f6
parent 288189 7822f3ad0aab51019eee1541d547ec39f08947f6
child 288191 75953f632ffca76e4e30ab336985170159e1704c
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1184186
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1184186 - Convert robocop testSharedPreferences to mochitest-chrome; r=nalexander
mobile/android/tests/browser/chrome/chrome.ini
mobile/android/tests/browser/chrome/test_shared_preferences.html
mobile/android/tests/browser/robocop/robocop.ini
mobile/android/tests/browser/robocop/testSharedPreferences.java
mobile/android/tests/browser/robocop/testSharedPreferences.js
--- a/mobile/android/tests/browser/chrome/chrome.ini
+++ b/mobile/android/tests/browser/chrome/chrome.ini
@@ -19,8 +19,9 @@ support-files =
 [test_jni.html]
 [test_migrate_ui.html]
 [test_network_manager.html]
 [test_offline_page.html]
 [test_reader_view.html]
 [test_resource_substitutions.html]
 [test_restricted_profiles.html]
 [test_session_form_data.html]
+[test_shared_preferences.html]
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/chrome/test_shared_preferences.html
@@ -0,0 +1,255 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=866271
+Migrated from Robocop: https://bugzilla.mozilla.org/show_bug.cgi?id=1184186
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 866271</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+  <script type="application/javascript;version=1.7">
+
+  Components.utils.import("resource://gre/modules/SharedPreferences.jsm");
+  Components.utils.import("resource://gre/modules/Promise.jsm");
+  Components.utils.import("resource://gre/modules/Task.jsm");
+
+  let _observerId = 0;
+
+  function makeObserver() {
+    let deferred = Promise.defer();
+
+    let ret = {
+      id: _observerId++,
+      count: 0,
+      promise: deferred.promise,
+      observe: function (subject, topic, data) {
+        ret.count += 1;
+        let msg = { subject: subject,
+                    topic: topic,
+                    data: data };
+        deferred.resolve(msg);
+      },
+    };
+
+    return ret;
+  };
+
+  add_task(function* test_get_set() {
+    let branch = SharedPreferences.forAndroid("test");
+
+    branch.setBoolPref("boolKey", true);
+    branch.setCharPref("charKey", "string value");
+    branch.setIntPref("intKey", 1000);
+
+    is(branch.getBoolPref("boolKey"), true);
+    is(branch.getCharPref("charKey"), "string value");
+    is(branch.getIntPref("intKey"), 1000);
+
+    branch.setBoolPref("boolKey", false);
+    branch.setCharPref("charKey", "different string value");
+    branch.setIntPref("intKey", -2000);
+
+    is(branch.getBoolPref("boolKey"), false);
+    is(branch.getCharPref("charKey"), "different string value");
+    is(branch.getIntPref("intKey"), -2000);
+
+    is(typeof(branch.getBoolPref("boolKey")), "boolean");
+    is(typeof(branch.getCharPref("charKey")), "string");
+    is(typeof(branch.getIntPref("intKey")), "number");
+  });
+
+  add_task(function* test_default() {
+    let branch = SharedPreferences.forAndroid();
+
+    branch.setBoolPref("boolKey", true);
+    branch.setCharPref("charKey", "string value");
+    branch.setIntPref("intKey", 1000);
+
+    is(branch.getBoolPref("boolKey"), true);
+    is(branch.getCharPref("charKey"), "string value");
+    is(branch.getIntPref("intKey"), 1000);
+
+    branch.setBoolPref("boolKey", false);
+    branch.setCharPref("charKey", "different string value");
+    branch.setIntPref("intKey", -2000);
+
+    is(branch.getBoolPref("boolKey"), false);
+    is(branch.getCharPref("charKey"), "different string value");
+    is(branch.getIntPref("intKey"), -2000);
+
+    is(typeof(branch.getBoolPref("boolKey")), "boolean");
+    is(typeof(branch.getCharPref("charKey")), "string");
+    is(typeof(branch.getIntPref("intKey")), "number");
+  });
+
+  add_task(function* test_multiple_branches() {
+    let branch1 = SharedPreferences.forAndroid("test1");
+    let branch2 = SharedPreferences.forAndroid("test2");
+
+    branch1.setBoolPref("boolKey", true);
+    branch2.setBoolPref("boolKey", false);
+
+    is(branch1.getBoolPref("boolKey"), true);
+    is(branch2.getBoolPref("boolKey"), false);
+
+    branch1.setCharPref("charKey", "a value");
+    branch2.setCharPref("charKey", "a different value");
+
+    is(branch1.getCharPref("charKey"), "a value");
+    is(branch2.getCharPref("charKey"), "a different value");
+  });
+
+  add_task(function* test_add_remove_observer() {
+    let branch = SharedPreferences.forAndroid("test");
+
+    branch.setBoolPref("boolKey", false);
+    is(branch.getBoolPref("boolKey"), false);
+
+    let obs1 = makeObserver();
+    branch.addObserver("boolKey", obs1);
+
+    try {
+      branch.setBoolPref("boolKey", true);
+      is(branch.getBoolPref("boolKey"), true);
+
+      let value1 = yield obs1.promise;
+      is(obs1.count, 1);
+
+      is(value1.subject, obs1);
+      is(value1.topic, "boolKey");
+      is(typeof(value1.data), "boolean");
+      is(value1.data, true);
+    } finally {
+      branch.removeObserver("boolKey", obs1);
+    }
+
+    // Make sure the original observer is really gone, or as close as
+    // we: install a second observer, wait for it to be notified, and
+    // then verify the original observer was *not* notified.  This
+    // depends, of course, on the order that observers are notified, but
+    // is better than nothing.
+
+    let obs2 = makeObserver();
+    branch.addObserver("boolKey", obs2);
+
+    try {
+      branch.setBoolPref("boolKey", false);
+      is(branch.getBoolPref("boolKey"), false);
+
+      let value2 = yield obs2.promise;
+      is(obs2.count, 1);
+
+      is(value2.subject, obs2);
+      is(value2.topic, "boolKey");
+      is(typeof(value2.data), "boolean");
+      is(value2.data, false);
+
+      // Original observer count is preserved.
+      is(obs1.count, 1);
+    } finally {
+      branch.removeObserver("boolKey", obs2);
+    }
+  });
+
+  add_task(function* test_observer_ignores() {
+    let branch = SharedPreferences.forAndroid("test");
+
+    branch.setCharPref("charKey", "first value");
+    is(branch.getCharPref("charKey"), "first value");
+
+    let obs = makeObserver();
+    branch.addObserver("charKey", obs);
+
+    try {
+      // These should all be ignored.
+      branch.setBoolPref("boolKey", true);
+      branch.setBoolPref("boolKey", false);
+      branch.setIntPref("intKey", -3000);
+      branch.setIntPref("intKey", 4000);
+
+      branch.setCharPref("charKey", "a value");
+      let value = yield obs.promise;
+
+      // Observer should have been notified exactly once.
+      is(obs.count, 1);
+
+      is(value.subject, obs);
+      is(value.topic, "charKey");
+      is(typeof(value.data), "string");
+      is(value.data, "a value");
+    } finally {
+      branch.removeObserver("charKey", obs);
+    }
+  });
+
+  add_task(function* test_observer_ignores_branches() {
+    let branch = SharedPreferences.forAndroid("test");
+
+    branch.setCharPref("charKey", "first value");
+    is(branch.getCharPref("charKey"), "first value");
+
+    let obs = makeObserver();
+    branch.addObserver("charKey", obs);
+
+    try {
+      // These should all be ignored.
+      let branch2 = SharedPreferences.forAndroid("test2");
+      branch2.setCharPref("charKey", "a wrong value");
+      let branch3 = SharedPreferences.forAndroid("test.2");
+      branch3.setCharPref("charKey", "a different wrong value");
+
+      // This should not be ignored.
+      branch.setCharPref("charKey", "a value");
+
+      let value = yield obs.promise;
+
+      // Observer should have been notified exactly once.
+      is(obs.count, 1);
+
+      is(value.subject, obs);
+      is(value.topic, "charKey");
+      is(typeof(value.data), "string");
+      is(value.data, "a value");
+    } finally {
+      branch.removeObserver("charKey", obs);
+    }
+  });
+
+  add_task(function* test_scopes() {
+    let forApp = SharedPreferences.forApp();
+    let forProfile = SharedPreferences.forProfile();
+    let forProfileName = SharedPreferences.forProfileName("testProfile");
+    let forAndroidDefault = SharedPreferences.forAndroid();
+    let forAndroidBranch = SharedPreferences.forAndroid("testBranch");
+
+    forApp.setCharPref("charKey", "forApp");
+    forProfile.setCharPref("charKey", "forProfile");
+    forProfileName.setCharPref("charKey", "forProfileName");
+    forAndroidDefault.setCharPref("charKey", "forAndroidDefault");
+    forAndroidBranch.setCharPref("charKey", "forAndroidBranch");
+
+    is(forApp.getCharPref("charKey"), "forApp");
+    is(forProfile.getCharPref("charKey"), "forProfile");
+    is(forProfileName.getCharPref("charKey"), "forProfileName");
+    is(forAndroidDefault.getCharPref("charKey"), "forAndroidDefault");
+    is(forAndroidBranch.getCharPref("charKey"), "forAndroidBranch");
+  });
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=866271">Mozilla Bug 866271</a>
+<br>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1184186">Migrated from Robocop testSharedPreferences</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>
--- a/mobile/android/tests/browser/robocop/robocop.ini
+++ b/mobile/android/tests/browser/robocop/robocop.ini
@@ -118,17 +118,16 @@ skip-if = android_version == "18"
 skip-if = android_version == "18"
 # [testMozPay.java] # see bug 945675
 [testOrderedBroadcast.java]
 [testOSLocale.java]
 # disabled on 2.3 and 4.3: Bug 1124494
 skip-if = android_version == "10" || android_version == "18"
 [testReadingListCache.java]
 [testRestrictions.java]
-[testSharedPreferences.java]
 [testSimpleDiscovery.java]
 [testTrackingProtection.java]
 # disabled on 4.3, bug 1158363
 skip-if = android_version == "18"
 [testUITelemetry.java]
 [testVideoControls.java]
 # disabled on Android 2.3 due to video playback issues, bug 1088038; on 4.3, bug 1098532
 skip-if = android_version == "10" || android_version == "18"
deleted file mode 100644
--- a/mobile/android/tests/browser/robocop/testSharedPreferences.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.mozilla.gecko.tests;
-
-
-
-public class testSharedPreferences extends JavascriptTest {
-    public testSharedPreferences() {
-        super("testSharedPreferences.js");
-    }
-}
deleted file mode 100644
--- a/mobile/android/tests/browser/robocop/testSharedPreferences.js
+++ /dev/null
@@ -1,231 +0,0 @@
-// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-Components.utils.import("resource://gre/modules/SharedPreferences.jsm");
-Components.utils.import("resource://gre/modules/Promise.jsm");
-
-let _observerId = 0;
-
-function makeObserver() {
-  let deferred = Promise.defer();
-
-  let ret = {
-    id: _observerId++,
-    count: 0,
-    promise: deferred.promise,
-    observe: function (subject, topic, data) {
-      ret.count += 1;
-      let msg = { subject: subject,
-                  topic: topic,
-                  data: data };
-      deferred.resolve(msg);
-    },
-  };
-
-  return ret;
-};
-
-add_task(function test_get_set() {
-  let branch = SharedPreferences.forAndroid("test");
-
-  branch.setBoolPref("boolKey", true);
-  branch.setCharPref("charKey", "string value");
-  branch.setIntPref("intKey", 1000);
-
-  do_check_eq(branch.getBoolPref("boolKey"), true);
-  do_check_eq(branch.getCharPref("charKey"), "string value");
-  do_check_eq(branch.getIntPref("intKey"), 1000);
-
-  branch.setBoolPref("boolKey", false);
-  branch.setCharPref("charKey", "different string value");
-  branch.setIntPref("intKey", -2000);
-
-  do_check_eq(branch.getBoolPref("boolKey"), false);
-  do_check_eq(branch.getCharPref("charKey"), "different string value");
-  do_check_eq(branch.getIntPref("intKey"), -2000);
-
-  do_check_eq(typeof(branch.getBoolPref("boolKey")), "boolean");
-  do_check_eq(typeof(branch.getCharPref("charKey")), "string");
-  do_check_eq(typeof(branch.getIntPref("intKey")), "number");
-});
-
-add_task(function test_default() {
-  let branch = SharedPreferences.forAndroid();
-
-  branch.setBoolPref("boolKey", true);
-  branch.setCharPref("charKey", "string value");
-  branch.setIntPref("intKey", 1000);
-
-  do_check_eq(branch.getBoolPref("boolKey"), true);
-  do_check_eq(branch.getCharPref("charKey"), "string value");
-  do_check_eq(branch.getIntPref("intKey"), 1000);
-
-  branch.setBoolPref("boolKey", false);
-  branch.setCharPref("charKey", "different string value");
-  branch.setIntPref("intKey", -2000);
-
-  do_check_eq(branch.getBoolPref("boolKey"), false);
-  do_check_eq(branch.getCharPref("charKey"), "different string value");
-  do_check_eq(branch.getIntPref("intKey"), -2000);
-
-  do_check_eq(typeof(branch.getBoolPref("boolKey")), "boolean");
-  do_check_eq(typeof(branch.getCharPref("charKey")), "string");
-  do_check_eq(typeof(branch.getIntPref("intKey")), "number");
-});
-
-add_task(function test_multiple_branches() {
-  let branch1 = SharedPreferences.forAndroid("test1");
-  let branch2 = SharedPreferences.forAndroid("test2");
-
-  branch1.setBoolPref("boolKey", true);
-  branch2.setBoolPref("boolKey", false);
-
-  do_check_eq(branch1.getBoolPref("boolKey"), true);
-  do_check_eq(branch2.getBoolPref("boolKey"), false);
-
-  branch1.setCharPref("charKey", "a value");
-  branch2.setCharPref("charKey", "a different value");
-
-  do_check_eq(branch1.getCharPref("charKey"), "a value");
-  do_check_eq(branch2.getCharPref("charKey"), "a different value");
-});
-
-add_task(function test_add_remove_observer() {
-  let branch = SharedPreferences.forAndroid("test");
-
-  branch.setBoolPref("boolKey", false);
-  do_check_eq(branch.getBoolPref("boolKey"), false);
-
-  let obs1 = makeObserver();
-  branch.addObserver("boolKey", obs1);
-
-  try {
-    branch.setBoolPref("boolKey", true);
-    do_check_eq(branch.getBoolPref("boolKey"), true);
-
-    let value1 = yield obs1.promise;
-    do_check_eq(obs1.count, 1);
-
-    do_check_eq(value1.subject, obs1);
-    do_check_eq(value1.topic, "boolKey");
-    do_check_eq(typeof(value1.data), "boolean");
-    do_check_eq(value1.data, true);
-  } finally {
-    branch.removeObserver("boolKey", obs1);
-  }
-
-  // Make sure the original observer is really gone, or as close as
-  // we: install a second observer, wait for it to be notified, and
-  // then verify the original observer was *not* notified.  This
-  // depends, of course, on the order that observers are notified, but
-  // is better than nothing.
-
-  let obs2 = makeObserver();
-  branch.addObserver("boolKey", obs2);
-
-  try {
-    branch.setBoolPref("boolKey", false);
-    do_check_eq(branch.getBoolPref("boolKey"), false);
-
-    let value2 = yield obs2.promise;
-    do_check_eq(obs2.count, 1);
-
-    do_check_eq(value2.subject, obs2);
-    do_check_eq(value2.topic, "boolKey");
-    do_check_eq(typeof(value2.data), "boolean");
-    do_check_eq(value2.data, false);
-
-    // Original observer count is preserved.
-    do_check_eq(obs1.count, 1);
-  } finally {
-    branch.removeObserver("boolKey", obs2);
-  }
-});
-
-add_task(function test_observer_ignores() {
-  let branch = SharedPreferences.forAndroid("test");
-
-  branch.setCharPref("charKey", "first value");
-  do_check_eq(branch.getCharPref("charKey"), "first value");
-
-  let obs = makeObserver();
-  branch.addObserver("charKey", obs);
-
-  try {
-    // These should all be ignored.
-    branch.setBoolPref("boolKey", true);
-    branch.setBoolPref("boolKey", false);
-    branch.setIntPref("intKey", -3000);
-    branch.setIntPref("intKey", 4000);
-
-    branch.setCharPref("charKey", "a value");
-    let value = yield obs.promise;
-
-    // Observer should have been notified exactly once.
-    do_check_eq(obs.count, 1);
-
-    do_check_eq(value.subject, obs);
-    do_check_eq(value.topic, "charKey");
-    do_check_eq(typeof(value.data), "string");
-    do_check_eq(value.data, "a value");
-  } finally {
-    branch.removeObserver("charKey", obs);
-  }
-});
-
-add_task(function test_observer_ignores_branches() {
-  let branch = SharedPreferences.forAndroid("test");
-
-  branch.setCharPref("charKey", "first value");
-  do_check_eq(branch.getCharPref("charKey"), "first value");
-
-  let obs = makeObserver();
-  branch.addObserver("charKey", obs);
-
-  try {
-    // These should all be ignored.
-    let branch2 = SharedPreferences.forAndroid("test2");
-    branch2.setCharPref("charKey", "a wrong value");
-    let branch3 = SharedPreferences.forAndroid("test.2");
-    branch3.setCharPref("charKey", "a different wrong value");
-
-    // This should not be ignored.
-    branch.setCharPref("charKey", "a value");
-
-    let value = yield obs.promise;
-
-    // Observer should have been notified exactly once.
-    do_check_eq(obs.count, 1);
-
-    do_check_eq(value.subject, obs);
-    do_check_eq(value.topic, "charKey");
-    do_check_eq(typeof(value.data), "string");
-    do_check_eq(value.data, "a value");
-  } finally {
-    branch.removeObserver("charKey", obs);
-  }
-});
-
-add_task(function test_scopes() {
-  let forApp = SharedPreferences.forApp();
-  let forProfile = SharedPreferences.forProfile();
-  let forProfileName = SharedPreferences.forProfileName("testProfile");
-  let forAndroidDefault = SharedPreferences.forAndroid();
-  let forAndroidBranch = SharedPreferences.forAndroid("testBranch");
-
-  forApp.setCharPref("charKey", "forApp");
-  forProfile.setCharPref("charKey", "forProfile");
-  forProfileName.setCharPref("charKey", "forProfileName");
-  forAndroidDefault.setCharPref("charKey", "forAndroidDefault");
-  forAndroidBranch.setCharPref("charKey", "forAndroidBranch");
-
-  do_check_eq(forApp.getCharPref("charKey"), "forApp");
-  do_check_eq(forProfile.getCharPref("charKey"), "forProfile");
-  do_check_eq(forProfileName.getCharPref("charKey"), "forProfileName");
-  do_check_eq(forAndroidDefault.getCharPref("charKey"), "forAndroidDefault");
-  do_check_eq(forAndroidBranch.getCharPref("charKey"), "forAndroidBranch");
-});
-
-run_next_test();