Bug 1184186 - Convert robocop testHomeProvider to mochitest-chrome; r=margaret
authorGeoff Brown <gbrown@mozilla.com>
Thu, 06 Aug 2015 07:27:47 -0600
changeset 288181 1264230fac8c88838d125327ca510711acb4148d
parent 288180 3f2f8b2f8ef49ac7a464034b736092b9df5e515d
child 288182 f4fc37fa5a2cbe2e6bfbe23424fe1b9ebd48eff8
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)
reviewersmargaret
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 testHomeProvider to mochitest-chrome; r=margaret
mobile/android/tests/browser/chrome/chrome.ini
mobile/android/tests/browser/chrome/test_home_provider.html
mobile/android/tests/browser/robocop/robocop.ini
mobile/android/tests/browser/robocop/testHomeProvider.java
mobile/android/tests/browser/robocop/testHomeProvider.js
--- a/mobile/android/tests/browser/chrome/chrome.ini
+++ b/mobile/android/tests/browser/chrome/chrome.ini
@@ -6,9 +6,10 @@ support-files =
 
 [test_about_logins.html]
 [test_accounts.html]
 [test_android_log.html]
 [test_app_constants.html]
 [test_debugger_server.html]
 [test_desktop_useragent.html]
 [test_device_search_engine.html]
+[test_home_provider.html]
 [test_resource_substitutions.html]
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/chrome/test_home_provider.html
@@ -0,0 +1,165 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=942288
+Migrated from Robocop: https://bugzilla.mozilla.org/show_bug.cgi?id=1184186
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 942288</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">
+
+  const { utils: Cu } = Components;
+
+  Cu.import("resource://gre/modules/HomeProvider.jsm");
+  Cu.import("resource://gre/modules/osfile.jsm");
+  Cu.import("resource://gre/modules/Services.jsm");
+  Cu.import("resource://gre/modules/Sqlite.jsm");
+  Cu.import("resource://gre/modules/Task.jsm");
+
+  const TEST_DATASET_ID = "test-dataset-id";
+  const TEST_URL = "http://test.com";
+  const TEST_TITLE = "Test";
+  const TEST_BACKGROUND_URL = "http://example.com/background";
+  const TEST_BACKGROUND_COLOR = "#FF9500";
+
+  const PREF_SYNC_CHECK_INTERVAL_SECS = "home.sync.checkIntervalSecs";
+  const TEST_INTERVAL_SECS = 1;
+
+  const DB_PATH = OS.Path.join(OS.Constants.Path.profileDir, "home.sqlite");
+
+  test_request_sync();
+  test_periodic_sync();
+
+  function test_request_sync() {
+    // The current implementation of requestSync is synchronous.
+    let success = HomeProvider.requestSync(TEST_DATASET_ID, function callback(datasetId) {
+      is(datasetId, TEST_DATASET_ID, "expected dataset ID");
+    });
+
+    ok(success, "requestSync success");
+  }
+
+  function test_periodic_sync() {
+    SimpleTest.registerCleanupFunction(function() {
+      Services.prefs.clearUserPref(PREF_SYNC_CHECK_INTERVAL_SECS);
+      HomeProvider.removePeriodicSync(TEST_DATASET_ID);
+    });
+
+    // Lower the check interval for testing purposes.
+    Services.prefs.setIntPref(PREF_SYNC_CHECK_INTERVAL_SECS, TEST_INTERVAL_SECS);
+
+    HomeProvider.addPeriodicSync(TEST_DATASET_ID, TEST_INTERVAL_SECS, function callback(datasetId) {
+      is(datasetId, TEST_DATASET_ID, "expected dataset ID");
+    });
+  }
+
+  add_task(function* test_save_and_delete() {
+    // Use the HomeProvider API to save some data.
+    let storage = HomeProvider.getStorage(TEST_DATASET_ID);
+    yield storage.save([{
+      title: TEST_TITLE,
+      url: TEST_URL,
+      background_url: TEST_BACKGROUND_URL,
+      background_color: TEST_BACKGROUND_COLOR
+    }]);
+
+    // Peek in the DB to make sure we have the right data.
+    let db = yield Sqlite.openConnection({ path: DB_PATH });
+
+    // Make sure the items table was created.
+    ok((yield db.tableExists("items")), "items table exists");
+
+    // Make sure the correct values for the item ended up in there.
+    let result = yield db.execute("SELECT * FROM items", null, function onRow(row){
+      is(row.getResultByName("dataset_id"), TEST_DATASET_ID, "expected dataset ID");
+      is(row.getResultByName("url"), TEST_URL, "expected test url");
+      is(row.getResultByName("background_url"), TEST_BACKGROUND_URL, "expected background url");
+      is(row.getResultByName("background_color"), TEST_BACKGROUND_COLOR, "expected background color");
+    });
+
+    // Use the HomeProvider API to delete the data.
+    yield storage.deleteAll();
+
+    // Make sure the data was deleted.
+    result = yield db.execute("SELECT * FROM items");
+    is(result.length, 0, "length is 0");
+
+    db.close();
+  });
+
+  add_task(function* test_row_validation() {
+    // Use the HomeProvider API to save some data.
+    let storage = HomeProvider.getStorage(TEST_DATASET_ID);
+
+    let invalidRows = [
+      { url: "url" },
+      { title: "title" },
+      { description: "description" },
+      { image_url: "image_url" }
+    ];
+
+    // None of these save calls should save anything
+    for (let row of invalidRows) {
+      try {
+        yield storage.save([row]);
+      } catch (e if e instanceof HomeProvider.ValidationError) {
+        // Just catch and ignore validation errors
+      }
+    }
+
+    // Peek in the DB to make sure we have the right data.
+    let db = yield Sqlite.openConnection({ path: DB_PATH });
+
+    // Make sure no data has been saved.
+    let result = yield db.execute("SELECT * FROM items");
+    is(result.length, 0, "length is 0");
+
+    db.close();
+  });
+
+  add_task(function* test_save_transaction() {
+    // Use the HomeProvider API to save some data.
+    let storage = HomeProvider.getStorage(TEST_DATASET_ID);
+
+    // One valid, one invalid
+    let rows = [
+      { title: TEST_TITLE, url: TEST_URL },
+      { image_url: "image_url" }
+    ];
+
+    // Try to save all the rows at once
+    try {
+      yield storage.save(rows);
+    } catch (e if e instanceof HomeProvider.ValidationError) {
+      // Just catch and ignore validation errors
+    }
+
+    // Peek in the DB to make sure we have the right data.
+    let db = yield Sqlite.openConnection({ path: DB_PATH });
+
+    // Make sure no data has been saved.
+    let result = yield db.execute("SELECT * FROM items");
+    is(result.length, 0, "length is 0");
+
+    db.close();
+  });
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=942288">Mozilla Bug 942288</a>
+<br>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1184186">Migrated from Robocop testHomeProvider</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
@@ -56,17 +56,16 @@ skip-if = android_version == "10" || and
 [testInputUrlBar.java]
 # disabled on 2.3 bug 1165511
 skip-if = android_version == "10"
 [testJarReader.java]
 [testLinkContextMenu.java]
 # disabled on 4.3, bug 1083666
 skip-if = android_version == "18"
 # [testHomeListsProvider.java] # see bug 952310
-[testHomeProvider.java]
 [testLoad.java]
 [testMailToContextMenu.java]
 # [testMasterPassword.java] disabled for being finicky, see bug 1033013
 # disabled on 2.3; bug 979603
 # disabled on 4.0; bug 1006242
 # skip-if = android_version == "10" || android_version == "15"
 [testNewTab.java]
 # disabled on 4.3, bug 1145851
deleted file mode 100644
--- a/mobile/android/tests/browser/robocop/testHomeProvider.java
+++ /dev/null
@@ -1,12 +0,0 @@
-/* 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/. */
-
-package org.mozilla.gecko.tests;
-
-
-public class testHomeProvider extends JavascriptTest {
-    public testHomeProvider() {
-        super("testHomeProvider.js");
-    }
-}
deleted file mode 100644
--- a/mobile/android/tests/browser/robocop/testHomeProvider.js
+++ /dev/null
@@ -1,141 +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/. */
-
-const { utils: Cu } = Components;
-
-Cu.import("resource://gre/modules/HomeProvider.jsm");
-Cu.import("resource://gre/modules/osfile.jsm");
-Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/Sqlite.jsm");
-Cu.import("resource://gre/modules/Task.jsm");
-
-const TEST_DATASET_ID = "test-dataset-id";
-const TEST_URL = "http://test.com";
-const TEST_TITLE = "Test";
-const TEST_BACKGROUND_URL = "http://example.com/background";
-const TEST_BACKGROUND_COLOR = "#FF9500";
-
-const PREF_SYNC_CHECK_INTERVAL_SECS = "home.sync.checkIntervalSecs";
-const TEST_INTERVAL_SECS = 1;
-
-const DB_PATH = OS.Path.join(OS.Constants.Path.profileDir, "home.sqlite");
-
-add_test(function test_request_sync() {
-  // The current implementation of requestSync is synchronous.
-  let success = HomeProvider.requestSync(TEST_DATASET_ID, function callback(datasetId) {
-    do_check_eq(datasetId, TEST_DATASET_ID);
-  });
-
-  do_check_true(success);
-  run_next_test();
-});
-
-add_test(function test_periodic_sync() {
-  do_register_cleanup(function cleanup() {
-    Services.prefs.clearUserPref(PREF_SYNC_CHECK_INTERVAL_SECS);
-    HomeProvider.removePeriodicSync(TEST_DATASET_ID);
-  });
-
-  // Lower the check interval for testing purposes.
-  Services.prefs.setIntPref(PREF_SYNC_CHECK_INTERVAL_SECS, TEST_INTERVAL_SECS);
-
-  HomeProvider.addPeriodicSync(TEST_DATASET_ID, TEST_INTERVAL_SECS, function callback(datasetId) {
-    do_check_eq(datasetId, TEST_DATASET_ID);
-    run_next_test();
-  });
-});
-
-add_task(function test_save_and_delete() {
-  // Use the HomeProvider API to save some data.
-  let storage = HomeProvider.getStorage(TEST_DATASET_ID);
-  yield storage.save([{
-    title: TEST_TITLE,
-    url: TEST_URL,
-    background_url: TEST_BACKGROUND_URL,
-    background_color: TEST_BACKGROUND_COLOR
-  }]);
-
-  // Peek in the DB to make sure we have the right data.
-  let db = yield Sqlite.openConnection({ path: DB_PATH });
-
-  // Make sure the items table was created.
-  do_check_true(yield db.tableExists("items"));
-
-  // Make sure the correct values for the item ended up in there.
-  let result = yield db.execute("SELECT * FROM items", null, function onRow(row){
-    do_check_eq(row.getResultByName("dataset_id"), TEST_DATASET_ID);
-    do_check_eq(row.getResultByName("url"), TEST_URL);
-    do_check_eq(row.getResultByName("background_url"), TEST_BACKGROUND_URL);
-    do_check_eq(row.getResultByName("background_color"), TEST_BACKGROUND_COLOR);
-  });
-
-  // Use the HomeProvider API to delete the data.
-  yield storage.deleteAll();
-
-  // Make sure the data was deleted.
-  result = yield db.execute("SELECT * FROM items");
-  do_check_eq(result.length, 0);
-
-  db.close();
-});
-
-add_task(function test_row_validation() {
-  // Use the HomeProvider API to save some data.
-  let storage = HomeProvider.getStorage(TEST_DATASET_ID);
-
-  let invalidRows = [
-    { url: "url" },
-    { title: "title" },
-    { description: "description" },
-    { image_url: "image_url" }
-  ];
-
-  // None of these save calls should save anything
-  for (let row of invalidRows) {
-    try {
-      yield storage.save([row]);
-    } catch (e if e instanceof HomeProvider.ValidationError) {
-      // Just catch and ignore validation errors
-    }
-  }
-
-  // Peek in the DB to make sure we have the right data.
-  let db = yield Sqlite.openConnection({ path: DB_PATH });
-
-  // Make sure no data has been saved.
-  let result = yield db.execute("SELECT * FROM items");
-  do_check_eq(result.length, 0);
-
-  db.close();
-});
-
-add_task(function test_save_transaction() {
-  // Use the HomeProvider API to save some data.
-  let storage = HomeProvider.getStorage(TEST_DATASET_ID);
-
-  // One valid, one invalid
-  let rows = [
-    { title: TEST_TITLE, url: TEST_URL },
-    { image_url: "image_url" }
-  ];
-
-  // Try to save all the rows at once
-  try {
-    yield storage.save(rows);
-  } catch (e if e instanceof HomeProvider.ValidationError) {
-    // Just catch and ignore validation errors
-  }
-
-  // Peek in the DB to make sure we have the right data.
-  let db = yield Sqlite.openConnection({ path: DB_PATH });
-
-  // Make sure no data has been saved.
-  let result = yield db.execute("SELECT * FROM items");
-  do_check_eq(result.length, 0);
-
-  db.close();
-});
-
-run_next_test();