Bug 1288885: Split out the longest-running alarm tasks into separate units. r=aswan
authorKris Maglione <maglione.k@gmail.com>
Fri, 22 Jul 2016 19:29:58 -0700
changeset 347203 ef7029b01f880c3825cd59743ee02e0c233d6f7f
parent 347202 65c77163c69fb006738b598be090ac49c3ae5826
child 347204 ed4692732f03938009108bb32417ce189f5a3635
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1288885
milestone50.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 1288885: Split out the longest-running alarm tasks into separate units. r=aswan MozReview-Commit-ID: GwnRd6gncGI
toolkit/components/extensions/test/xpcshell/test_ext_alarms.js
toolkit/components/extensions/test/xpcshell/test_ext_alarms_does_not_fire.js
toolkit/components/extensions/test/xpcshell/test_ext_alarms_periodic.js
toolkit/components/extensions/test/xpcshell/test_ext_alarms_replaces.js
toolkit/components/extensions/test/xpcshell/xpcshell.ini
--- a/toolkit/components/extensions/test/xpcshell/test_ext_alarms.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_alarms.js
@@ -52,47 +52,16 @@ add_task(function* test_alarm_fires() {
   });
 
   yield extension.startup();
   yield extension.awaitFinish("alarm-fires");
   yield extension.unload();
 });
 
 
-add_task(function* test_cleared_alarm_does_not_fire() {
-  function backgroundScript() {
-    let ALARM_NAME = "test_ext_alarms";
-
-    browser.alarms.onAlarm.addListener(alarm => {
-      browser.test.fail("cleared alarm does not fire");
-      browser.test.notifyFail("alarm-cleared");
-    });
-    browser.alarms.create(ALARM_NAME, {when: Date.now() + 1000});
-
-    browser.alarms.clear(ALARM_NAME).then(wasCleared => {
-      browser.test.assertTrue(wasCleared, "alarm was cleared");
-      setTimeout(() => {
-        browser.test.notifyPass("alarm-cleared");
-      }, 2000);
-    });
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-cleared");
-  yield extension.unload();
-});
-
-
 add_task(function* test_alarm_fires_with_when() {
   function backgroundScript() {
     let ALARM_NAME = "test_ext_alarms";
     let timer;
 
     browser.alarms.onAlarm.addListener(alarm => {
       browser.test.assertEq(ALARM_NAME, alarm.name, "alarm has the expected name");
       clearTimeout(timer);
@@ -175,57 +144,16 @@ add_task(function* test_alarm_get_and_cl
   });
 
   yield extension.startup();
   yield extension.awaitFinish("alarm-single-arg");
   yield extension.unload();
 });
 
 
-add_task(function* test_periodic_alarm_fires() {
-  function backgroundScript() {
-    const ALARM_NAME = "test_ext_alarms";
-    let count = 0;
-    let timer;
-
-    browser.alarms.onAlarm.addListener(alarm => {
-      browser.test.assertEq(alarm.name, ALARM_NAME, "alarm has the expected name");
-      if (count++ === 3) {
-        clearTimeout(timer);
-        browser.alarms.clear(ALARM_NAME).then(wasCleared => {
-          browser.test.assertTrue(wasCleared, "alarm was cleared");
-          browser.test.notifyPass("alarm-periodic");
-        });
-      }
-    });
-
-    browser.alarms.create(ALARM_NAME, {periodInMinutes: 0.02});
-
-    timer = setTimeout(() => {
-      browser.test.fail("alarm fired expected number of times");
-      browser.alarms.clear(ALARM_NAME).then(wasCleared => {
-        browser.test.assertTrue(wasCleared, "alarm was cleared");
-      });
-      browser.test.notifyFail("alarm-periodic");
-    }, 30000);
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-periodic");
-  yield extension.unload();
-});
-
-
 add_task(function* test_get_get_all_clear_all_alarms() {
   function backgroundScript() {
     const ALARM_NAME = "test_alarm";
 
     let suffixes = [0, 1, 2];
 
     for (let suffix of suffixes) {
       browser.alarms.create(ALARM_NAME + suffix, {when: Date.now() + (suffix + 1) * 10000});
@@ -286,49 +214,8 @@ add_task(function* test_get_get_all_clea
     extension.awaitMessage("get-1"),
     extension.awaitMessage("get-2"),
     extension.awaitMessage("clear"),
     extension.awaitMessage("get-invalid"),
     extension.awaitMessage("clearAll"),
   ]);
   yield extension.unload();
 });
-
-add_task(function* test_duplicate_alarm_name_replaces_alarm() {
-  function backgroundScript() {
-    let count = 0;
-
-    browser.alarms.onAlarm.addListener(alarm => {
-      if (alarm.name === "master alarm") {
-        browser.alarms.create("child alarm", {delayInMinutes: 0.05});
-        browser.alarms.getAll().then(results => {
-          browser.test.assertEq(2, results.length, "exactly two alarms exist");
-          browser.test.assertEq("master alarm", results[0].name, "first alarm has the expected name");
-          browser.test.assertEq("child alarm", results[1].name, "second alarm has the expected name");
-        }).then(() => {
-          if (count++ === 3) {
-            browser.alarms.clear("master alarm").then(wasCleared => {
-              return browser.alarms.clear("child alarm");
-            }).then(wasCleared => {
-              browser.test.notifyPass("alarm-duplicate");
-            });
-          }
-        });
-      } else {
-        browser.test.fail("duplicate named alarm replaced existing alarm");
-        browser.test.notifyFail("alarm-duplicate");
-      }
-    });
-
-    browser.alarms.create("master alarm", {delayInMinutes: 0.025, periodInMinutes: 0.025});
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-duplicate");
-  yield extension.unload();
-});
copy from toolkit/components/extensions/test/xpcshell/test_ext_alarms.js
copy to toolkit/components/extensions/test/xpcshell/test_ext_alarms_does_not_fire.js
--- a/toolkit/components/extensions/test/xpcshell/test_ext_alarms.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_alarms_does_not_fire.js
@@ -1,67 +1,12 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-add_task(function* test_alarm_without_permissions() {
-  function backgroundScript() {
-    browser.test.assertTrue(!browser.alarms,
-                            "alarm API is not available when the alarm permission is not required");
-    browser.test.notifyPass("alarms_permission");
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: [],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarms_permission");
-  yield extension.unload();
-});
-
-
-add_task(function* test_alarm_fires() {
-  function backgroundScript() {
-    let ALARM_NAME = "test_ext_alarms";
-    let timer;
-
-    browser.alarms.onAlarm.addListener(alarm => {
-      browser.test.assertEq(ALARM_NAME, alarm.name, "alarm has the correct name");
-      clearTimeout(timer);
-      browser.test.notifyPass("alarm-fires");
-    });
-
-    browser.alarms.create(ALARM_NAME, {delayInMinutes: 0.02});
-
-    timer = setTimeout(() => {
-      browser.test.fail("alarm fired within expected time");
-      browser.alarms.clear(ALARM_NAME).then(wasCleared => {
-        browser.test.assertTrue(wasCleared, "alarm was cleared");
-      });
-      browser.test.notifyFail("alarm-fires");
-    }, 10000);
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-fires");
-  yield extension.unload();
-});
-
-
 add_task(function* test_cleared_alarm_does_not_fire() {
   function backgroundScript() {
     let ALARM_NAME = "test_ext_alarms";
 
     browser.alarms.onAlarm.addListener(alarm => {
       browser.test.fail("cleared alarm does not fire");
       browser.test.notifyFail("alarm-cleared");
     });
@@ -81,254 +26,8 @@ add_task(function* test_cleared_alarm_do
       permissions: ["alarms"],
     },
   });
 
   yield extension.startup();
   yield extension.awaitFinish("alarm-cleared");
   yield extension.unload();
 });
-
-
-add_task(function* test_alarm_fires_with_when() {
-  function backgroundScript() {
-    let ALARM_NAME = "test_ext_alarms";
-    let timer;
-
-    browser.alarms.onAlarm.addListener(alarm => {
-      browser.test.assertEq(ALARM_NAME, alarm.name, "alarm has the expected name");
-      clearTimeout(timer);
-      browser.test.notifyPass("alarm-when");
-    });
-
-    browser.alarms.create(ALARM_NAME, {when: Date.now() + 1000});
-
-    timer = setTimeout(() => {
-      browser.test.fail("alarm fired within expected time");
-      browser.alarms.clear(ALARM_NAME).then(wasCleared => {
-        browser.test.assertTrue(wasCleared, "alarm was cleared");
-      });
-      browser.test.notifyFail("alarm-when");
-    }, 10000);
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-when");
-  yield extension.unload();
-});
-
-
-add_task(function* test_alarm_clear_non_matching_name() {
-  function backgroundScript() {
-    let ALARM_NAME = "test_ext_alarms";
-
-    browser.alarms.create(ALARM_NAME, {when: Date.now() + 2000});
-
-    browser.alarms.clear(ALARM_NAME + "1").then(wasCleared => {
-      browser.test.assertFalse(wasCleared, "alarm was not cleared");
-      return browser.alarms.getAll();
-    }).then(alarms => {
-      browser.test.assertEq(1, alarms.length, "alarm was not removed");
-      browser.test.notifyPass("alarm-clear");
-    });
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-clear");
-  yield extension.unload();
-});
-
-
-add_task(function* test_alarm_get_and_clear_single_argument() {
-  function backgroundScript() {
-    browser.alarms.create({when: Date.now() + 2000});
-
-    browser.alarms.get().then(alarm => {
-      browser.test.assertEq("", alarm.name, "expected alarm returned");
-      return browser.alarms.clear();
-    }).then(wasCleared => {
-      browser.test.assertTrue(wasCleared, "alarm was cleared");
-      return browser.alarms.getAll();
-    }).then(alarms => {
-      browser.test.assertEq(0, alarms.length, "alarm was removed");
-      browser.test.notifyPass("alarm-single-arg");
-    });
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-single-arg");
-  yield extension.unload();
-});
-
-
-add_task(function* test_periodic_alarm_fires() {
-  function backgroundScript() {
-    const ALARM_NAME = "test_ext_alarms";
-    let count = 0;
-    let timer;
-
-    browser.alarms.onAlarm.addListener(alarm => {
-      browser.test.assertEq(alarm.name, ALARM_NAME, "alarm has the expected name");
-      if (count++ === 3) {
-        clearTimeout(timer);
-        browser.alarms.clear(ALARM_NAME).then(wasCleared => {
-          browser.test.assertTrue(wasCleared, "alarm was cleared");
-          browser.test.notifyPass("alarm-periodic");
-        });
-      }
-    });
-
-    browser.alarms.create(ALARM_NAME, {periodInMinutes: 0.02});
-
-    timer = setTimeout(() => {
-      browser.test.fail("alarm fired expected number of times");
-      browser.alarms.clear(ALARM_NAME).then(wasCleared => {
-        browser.test.assertTrue(wasCleared, "alarm was cleared");
-      });
-      browser.test.notifyFail("alarm-periodic");
-    }, 30000);
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-periodic");
-  yield extension.unload();
-});
-
-
-add_task(function* test_get_get_all_clear_all_alarms() {
-  function backgroundScript() {
-    const ALARM_NAME = "test_alarm";
-
-    let suffixes = [0, 1, 2];
-
-    for (let suffix of suffixes) {
-      browser.alarms.create(ALARM_NAME + suffix, {when: Date.now() + (suffix + 1) * 10000});
-    }
-
-    browser.alarms.getAll().then(alarms => {
-      browser.test.assertEq(suffixes.length, alarms.length, "expected number of alarms were found");
-      alarms.forEach((alarm, index) => {
-        browser.test.assertEq(ALARM_NAME + index, alarm.name, "alarm has the expected name");
-      });
-
-      return Promise.all(
-        suffixes.map(suffix => {
-          return browser.alarms.get(ALARM_NAME + suffix).then(alarm => {
-            browser.test.assertEq(ALARM_NAME + suffix, alarm.name, "alarm has the expected name");
-            browser.test.sendMessage(`get-${suffix}`);
-          });
-        })
-      );
-    }).then(() => {
-      return browser.alarms.clear(ALARM_NAME + suffixes[0]);
-    }).then(wasCleared => {
-      browser.test.assertTrue(wasCleared, "alarm was cleared");
-
-      return browser.alarms.getAll();
-    }).then(alarms => {
-      browser.test.assertEq(2, alarms.length, "alarm was removed");
-
-      return browser.alarms.get(ALARM_NAME + suffixes[0]);
-    }).then(alarm => {
-      browser.test.assertEq(undefined, alarm, "non-existent alarm is undefined");
-      browser.test.sendMessage(`get-invalid`);
-
-      return browser.alarms.clearAll();
-    }).then(wasCleared => {
-      browser.test.assertTrue(wasCleared, "alarms were cleared");
-
-      return browser.alarms.getAll();
-    }).then(alarms => {
-      browser.test.assertEq(0, alarms.length, "no alarms exist");
-      browser.test.sendMessage("clearAll");
-      browser.test.sendMessage("clear");
-      browser.test.sendMessage("getAll");
-    });
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield Promise.all([
-    extension.startup(),
-    extension.awaitMessage("getAll"),
-    extension.awaitMessage("get-0"),
-    extension.awaitMessage("get-1"),
-    extension.awaitMessage("get-2"),
-    extension.awaitMessage("clear"),
-    extension.awaitMessage("get-invalid"),
-    extension.awaitMessage("clearAll"),
-  ]);
-  yield extension.unload();
-});
-
-add_task(function* test_duplicate_alarm_name_replaces_alarm() {
-  function backgroundScript() {
-    let count = 0;
-
-    browser.alarms.onAlarm.addListener(alarm => {
-      if (alarm.name === "master alarm") {
-        browser.alarms.create("child alarm", {delayInMinutes: 0.05});
-        browser.alarms.getAll().then(results => {
-          browser.test.assertEq(2, results.length, "exactly two alarms exist");
-          browser.test.assertEq("master alarm", results[0].name, "first alarm has the expected name");
-          browser.test.assertEq("child alarm", results[1].name, "second alarm has the expected name");
-        }).then(() => {
-          if (count++ === 3) {
-            browser.alarms.clear("master alarm").then(wasCleared => {
-              return browser.alarms.clear("child alarm");
-            }).then(wasCleared => {
-              browser.test.notifyPass("alarm-duplicate");
-            });
-          }
-        });
-      } else {
-        browser.test.fail("duplicate named alarm replaced existing alarm");
-        browser.test.notifyFail("alarm-duplicate");
-      }
-    });
-
-    browser.alarms.create("master alarm", {delayInMinutes: 0.025, periodInMinutes: 0.025});
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-duplicate");
-  yield extension.unload();
-});
copy from toolkit/components/extensions/test/xpcshell/test_ext_alarms.js
copy to toolkit/components/extensions/test/xpcshell/test_ext_alarms_periodic.js
--- a/toolkit/components/extensions/test/xpcshell/test_ext_alarms.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_alarms_periodic.js
@@ -1,190 +1,12 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-add_task(function* test_alarm_without_permissions() {
-  function backgroundScript() {
-    browser.test.assertTrue(!browser.alarms,
-                            "alarm API is not available when the alarm permission is not required");
-    browser.test.notifyPass("alarms_permission");
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: [],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarms_permission");
-  yield extension.unload();
-});
-
-
-add_task(function* test_alarm_fires() {
-  function backgroundScript() {
-    let ALARM_NAME = "test_ext_alarms";
-    let timer;
-
-    browser.alarms.onAlarm.addListener(alarm => {
-      browser.test.assertEq(ALARM_NAME, alarm.name, "alarm has the correct name");
-      clearTimeout(timer);
-      browser.test.notifyPass("alarm-fires");
-    });
-
-    browser.alarms.create(ALARM_NAME, {delayInMinutes: 0.02});
-
-    timer = setTimeout(() => {
-      browser.test.fail("alarm fired within expected time");
-      browser.alarms.clear(ALARM_NAME).then(wasCleared => {
-        browser.test.assertTrue(wasCleared, "alarm was cleared");
-      });
-      browser.test.notifyFail("alarm-fires");
-    }, 10000);
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-fires");
-  yield extension.unload();
-});
-
-
-add_task(function* test_cleared_alarm_does_not_fire() {
-  function backgroundScript() {
-    let ALARM_NAME = "test_ext_alarms";
-
-    browser.alarms.onAlarm.addListener(alarm => {
-      browser.test.fail("cleared alarm does not fire");
-      browser.test.notifyFail("alarm-cleared");
-    });
-    browser.alarms.create(ALARM_NAME, {when: Date.now() + 1000});
-
-    browser.alarms.clear(ALARM_NAME).then(wasCleared => {
-      browser.test.assertTrue(wasCleared, "alarm was cleared");
-      setTimeout(() => {
-        browser.test.notifyPass("alarm-cleared");
-      }, 2000);
-    });
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-cleared");
-  yield extension.unload();
-});
-
-
-add_task(function* test_alarm_fires_with_when() {
-  function backgroundScript() {
-    let ALARM_NAME = "test_ext_alarms";
-    let timer;
-
-    browser.alarms.onAlarm.addListener(alarm => {
-      browser.test.assertEq(ALARM_NAME, alarm.name, "alarm has the expected name");
-      clearTimeout(timer);
-      browser.test.notifyPass("alarm-when");
-    });
-
-    browser.alarms.create(ALARM_NAME, {when: Date.now() + 1000});
-
-    timer = setTimeout(() => {
-      browser.test.fail("alarm fired within expected time");
-      browser.alarms.clear(ALARM_NAME).then(wasCleared => {
-        browser.test.assertTrue(wasCleared, "alarm was cleared");
-      });
-      browser.test.notifyFail("alarm-when");
-    }, 10000);
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-when");
-  yield extension.unload();
-});
-
-
-add_task(function* test_alarm_clear_non_matching_name() {
-  function backgroundScript() {
-    let ALARM_NAME = "test_ext_alarms";
-
-    browser.alarms.create(ALARM_NAME, {when: Date.now() + 2000});
-
-    browser.alarms.clear(ALARM_NAME + "1").then(wasCleared => {
-      browser.test.assertFalse(wasCleared, "alarm was not cleared");
-      return browser.alarms.getAll();
-    }).then(alarms => {
-      browser.test.assertEq(1, alarms.length, "alarm was not removed");
-      browser.test.notifyPass("alarm-clear");
-    });
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-clear");
-  yield extension.unload();
-});
-
-
-add_task(function* test_alarm_get_and_clear_single_argument() {
-  function backgroundScript() {
-    browser.alarms.create({when: Date.now() + 2000});
-
-    browser.alarms.get().then(alarm => {
-      browser.test.assertEq("", alarm.name, "expected alarm returned");
-      return browser.alarms.clear();
-    }).then(wasCleared => {
-      browser.test.assertTrue(wasCleared, "alarm was cleared");
-      return browser.alarms.getAll();
-    }).then(alarms => {
-      browser.test.assertEq(0, alarms.length, "alarm was removed");
-      browser.test.notifyPass("alarm-single-arg");
-    });
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-single-arg");
-  yield extension.unload();
-});
-
-
 add_task(function* test_periodic_alarm_fires() {
   function backgroundScript() {
     const ALARM_NAME = "test_ext_alarms";
     let count = 0;
     let timer;
 
     browser.alarms.onAlarm.addListener(alarm => {
       browser.test.assertEq(alarm.name, ALARM_NAME, "alarm has the expected name");
@@ -214,121 +36,8 @@ add_task(function* test_periodic_alarm_f
       permissions: ["alarms"],
     },
   });
 
   yield extension.startup();
   yield extension.awaitFinish("alarm-periodic");
   yield extension.unload();
 });
-
-
-add_task(function* test_get_get_all_clear_all_alarms() {
-  function backgroundScript() {
-    const ALARM_NAME = "test_alarm";
-
-    let suffixes = [0, 1, 2];
-
-    for (let suffix of suffixes) {
-      browser.alarms.create(ALARM_NAME + suffix, {when: Date.now() + (suffix + 1) * 10000});
-    }
-
-    browser.alarms.getAll().then(alarms => {
-      browser.test.assertEq(suffixes.length, alarms.length, "expected number of alarms were found");
-      alarms.forEach((alarm, index) => {
-        browser.test.assertEq(ALARM_NAME + index, alarm.name, "alarm has the expected name");
-      });
-
-      return Promise.all(
-        suffixes.map(suffix => {
-          return browser.alarms.get(ALARM_NAME + suffix).then(alarm => {
-            browser.test.assertEq(ALARM_NAME + suffix, alarm.name, "alarm has the expected name");
-            browser.test.sendMessage(`get-${suffix}`);
-          });
-        })
-      );
-    }).then(() => {
-      return browser.alarms.clear(ALARM_NAME + suffixes[0]);
-    }).then(wasCleared => {
-      browser.test.assertTrue(wasCleared, "alarm was cleared");
-
-      return browser.alarms.getAll();
-    }).then(alarms => {
-      browser.test.assertEq(2, alarms.length, "alarm was removed");
-
-      return browser.alarms.get(ALARM_NAME + suffixes[0]);
-    }).then(alarm => {
-      browser.test.assertEq(undefined, alarm, "non-existent alarm is undefined");
-      browser.test.sendMessage(`get-invalid`);
-
-      return browser.alarms.clearAll();
-    }).then(wasCleared => {
-      browser.test.assertTrue(wasCleared, "alarms were cleared");
-
-      return browser.alarms.getAll();
-    }).then(alarms => {
-      browser.test.assertEq(0, alarms.length, "no alarms exist");
-      browser.test.sendMessage("clearAll");
-      browser.test.sendMessage("clear");
-      browser.test.sendMessage("getAll");
-    });
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield Promise.all([
-    extension.startup(),
-    extension.awaitMessage("getAll"),
-    extension.awaitMessage("get-0"),
-    extension.awaitMessage("get-1"),
-    extension.awaitMessage("get-2"),
-    extension.awaitMessage("clear"),
-    extension.awaitMessage("get-invalid"),
-    extension.awaitMessage("clearAll"),
-  ]);
-  yield extension.unload();
-});
-
-add_task(function* test_duplicate_alarm_name_replaces_alarm() {
-  function backgroundScript() {
-    let count = 0;
-
-    browser.alarms.onAlarm.addListener(alarm => {
-      if (alarm.name === "master alarm") {
-        browser.alarms.create("child alarm", {delayInMinutes: 0.05});
-        browser.alarms.getAll().then(results => {
-          browser.test.assertEq(2, results.length, "exactly two alarms exist");
-          browser.test.assertEq("master alarm", results[0].name, "first alarm has the expected name");
-          browser.test.assertEq("child alarm", results[1].name, "second alarm has the expected name");
-        }).then(() => {
-          if (count++ === 3) {
-            browser.alarms.clear("master alarm").then(wasCleared => {
-              return browser.alarms.clear("child alarm");
-            }).then(wasCleared => {
-              browser.test.notifyPass("alarm-duplicate");
-            });
-          }
-        });
-      } else {
-        browser.test.fail("duplicate named alarm replaced existing alarm");
-        browser.test.notifyFail("alarm-duplicate");
-      }
-    });
-
-    browser.alarms.create("master alarm", {delayInMinutes: 0.025, periodInMinutes: 0.025});
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-duplicate");
-  yield extension.unload();
-});
copy from toolkit/components/extensions/test/xpcshell/test_ext_alarms.js
copy to toolkit/components/extensions/test/xpcshell/test_ext_alarms_replaces.js
--- a/toolkit/components/extensions/test/xpcshell/test_ext_alarms.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_alarms_replaces.js
@@ -1,301 +1,12 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-add_task(function* test_alarm_without_permissions() {
-  function backgroundScript() {
-    browser.test.assertTrue(!browser.alarms,
-                            "alarm API is not available when the alarm permission is not required");
-    browser.test.notifyPass("alarms_permission");
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: [],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarms_permission");
-  yield extension.unload();
-});
-
-
-add_task(function* test_alarm_fires() {
-  function backgroundScript() {
-    let ALARM_NAME = "test_ext_alarms";
-    let timer;
-
-    browser.alarms.onAlarm.addListener(alarm => {
-      browser.test.assertEq(ALARM_NAME, alarm.name, "alarm has the correct name");
-      clearTimeout(timer);
-      browser.test.notifyPass("alarm-fires");
-    });
-
-    browser.alarms.create(ALARM_NAME, {delayInMinutes: 0.02});
-
-    timer = setTimeout(() => {
-      browser.test.fail("alarm fired within expected time");
-      browser.alarms.clear(ALARM_NAME).then(wasCleared => {
-        browser.test.assertTrue(wasCleared, "alarm was cleared");
-      });
-      browser.test.notifyFail("alarm-fires");
-    }, 10000);
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-fires");
-  yield extension.unload();
-});
-
-
-add_task(function* test_cleared_alarm_does_not_fire() {
-  function backgroundScript() {
-    let ALARM_NAME = "test_ext_alarms";
-
-    browser.alarms.onAlarm.addListener(alarm => {
-      browser.test.fail("cleared alarm does not fire");
-      browser.test.notifyFail("alarm-cleared");
-    });
-    browser.alarms.create(ALARM_NAME, {when: Date.now() + 1000});
-
-    browser.alarms.clear(ALARM_NAME).then(wasCleared => {
-      browser.test.assertTrue(wasCleared, "alarm was cleared");
-      setTimeout(() => {
-        browser.test.notifyPass("alarm-cleared");
-      }, 2000);
-    });
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-cleared");
-  yield extension.unload();
-});
-
-
-add_task(function* test_alarm_fires_with_when() {
-  function backgroundScript() {
-    let ALARM_NAME = "test_ext_alarms";
-    let timer;
-
-    browser.alarms.onAlarm.addListener(alarm => {
-      browser.test.assertEq(ALARM_NAME, alarm.name, "alarm has the expected name");
-      clearTimeout(timer);
-      browser.test.notifyPass("alarm-when");
-    });
-
-    browser.alarms.create(ALARM_NAME, {when: Date.now() + 1000});
-
-    timer = setTimeout(() => {
-      browser.test.fail("alarm fired within expected time");
-      browser.alarms.clear(ALARM_NAME).then(wasCleared => {
-        browser.test.assertTrue(wasCleared, "alarm was cleared");
-      });
-      browser.test.notifyFail("alarm-when");
-    }, 10000);
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-when");
-  yield extension.unload();
-});
-
-
-add_task(function* test_alarm_clear_non_matching_name() {
-  function backgroundScript() {
-    let ALARM_NAME = "test_ext_alarms";
-
-    browser.alarms.create(ALARM_NAME, {when: Date.now() + 2000});
-
-    browser.alarms.clear(ALARM_NAME + "1").then(wasCleared => {
-      browser.test.assertFalse(wasCleared, "alarm was not cleared");
-      return browser.alarms.getAll();
-    }).then(alarms => {
-      browser.test.assertEq(1, alarms.length, "alarm was not removed");
-      browser.test.notifyPass("alarm-clear");
-    });
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-clear");
-  yield extension.unload();
-});
-
-
-add_task(function* test_alarm_get_and_clear_single_argument() {
-  function backgroundScript() {
-    browser.alarms.create({when: Date.now() + 2000});
-
-    browser.alarms.get().then(alarm => {
-      browser.test.assertEq("", alarm.name, "expected alarm returned");
-      return browser.alarms.clear();
-    }).then(wasCleared => {
-      browser.test.assertTrue(wasCleared, "alarm was cleared");
-      return browser.alarms.getAll();
-    }).then(alarms => {
-      browser.test.assertEq(0, alarms.length, "alarm was removed");
-      browser.test.notifyPass("alarm-single-arg");
-    });
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-single-arg");
-  yield extension.unload();
-});
-
-
-add_task(function* test_periodic_alarm_fires() {
-  function backgroundScript() {
-    const ALARM_NAME = "test_ext_alarms";
-    let count = 0;
-    let timer;
-
-    browser.alarms.onAlarm.addListener(alarm => {
-      browser.test.assertEq(alarm.name, ALARM_NAME, "alarm has the expected name");
-      if (count++ === 3) {
-        clearTimeout(timer);
-        browser.alarms.clear(ALARM_NAME).then(wasCleared => {
-          browser.test.assertTrue(wasCleared, "alarm was cleared");
-          browser.test.notifyPass("alarm-periodic");
-        });
-      }
-    });
-
-    browser.alarms.create(ALARM_NAME, {periodInMinutes: 0.02});
-
-    timer = setTimeout(() => {
-      browser.test.fail("alarm fired expected number of times");
-      browser.alarms.clear(ALARM_NAME).then(wasCleared => {
-        browser.test.assertTrue(wasCleared, "alarm was cleared");
-      });
-      browser.test.notifyFail("alarm-periodic");
-    }, 30000);
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield extension.startup();
-  yield extension.awaitFinish("alarm-periodic");
-  yield extension.unload();
-});
-
-
-add_task(function* test_get_get_all_clear_all_alarms() {
-  function backgroundScript() {
-    const ALARM_NAME = "test_alarm";
-
-    let suffixes = [0, 1, 2];
-
-    for (let suffix of suffixes) {
-      browser.alarms.create(ALARM_NAME + suffix, {when: Date.now() + (suffix + 1) * 10000});
-    }
-
-    browser.alarms.getAll().then(alarms => {
-      browser.test.assertEq(suffixes.length, alarms.length, "expected number of alarms were found");
-      alarms.forEach((alarm, index) => {
-        browser.test.assertEq(ALARM_NAME + index, alarm.name, "alarm has the expected name");
-      });
-
-      return Promise.all(
-        suffixes.map(suffix => {
-          return browser.alarms.get(ALARM_NAME + suffix).then(alarm => {
-            browser.test.assertEq(ALARM_NAME + suffix, alarm.name, "alarm has the expected name");
-            browser.test.sendMessage(`get-${suffix}`);
-          });
-        })
-      );
-    }).then(() => {
-      return browser.alarms.clear(ALARM_NAME + suffixes[0]);
-    }).then(wasCleared => {
-      browser.test.assertTrue(wasCleared, "alarm was cleared");
-
-      return browser.alarms.getAll();
-    }).then(alarms => {
-      browser.test.assertEq(2, alarms.length, "alarm was removed");
-
-      return browser.alarms.get(ALARM_NAME + suffixes[0]);
-    }).then(alarm => {
-      browser.test.assertEq(undefined, alarm, "non-existent alarm is undefined");
-      browser.test.sendMessage(`get-invalid`);
-
-      return browser.alarms.clearAll();
-    }).then(wasCleared => {
-      browser.test.assertTrue(wasCleared, "alarms were cleared");
-
-      return browser.alarms.getAll();
-    }).then(alarms => {
-      browser.test.assertEq(0, alarms.length, "no alarms exist");
-      browser.test.sendMessage("clearAll");
-      browser.test.sendMessage("clear");
-      browser.test.sendMessage("getAll");
-    });
-  }
-
-  let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
-    manifest: {
-      permissions: ["alarms"],
-    },
-  });
-
-  yield Promise.all([
-    extension.startup(),
-    extension.awaitMessage("getAll"),
-    extension.awaitMessage("get-0"),
-    extension.awaitMessage("get-1"),
-    extension.awaitMessage("get-2"),
-    extension.awaitMessage("clear"),
-    extension.awaitMessage("get-invalid"),
-    extension.awaitMessage("clearAll"),
-  ]);
-  yield extension.unload();
-});
 
 add_task(function* test_duplicate_alarm_name_replaces_alarm() {
   function backgroundScript() {
     let count = 0;
 
     browser.alarms.onAlarm.addListener(alarm => {
       if (alarm.name === "master alarm") {
         browser.alarms.create("child alarm", {delayInMinutes: 0.05});
--- a/toolkit/components/extensions/test/xpcshell/xpcshell.ini
+++ b/toolkit/components/extensions/test/xpcshell/xpcshell.ini
@@ -4,16 +4,19 @@ tail =
 firefox-appdir = browser
 skip-if = toolkit == 'gonk' || appname == "thunderbird"
 support-files =
   data/**
 
 [test_csp_custom_policies.js]
 [test_csp_validator.js]
 [test_ext_alarms.js]
+[test_ext_alarms_does_not_fire.js]
+[test_ext_alarms_periodic.js]
+[test_ext_alarms_replaces.js]
 [test_ext_background_generated_load_events.js]
 [test_ext_background_generated_reload.js]
 [test_ext_background_runtime_connect_params.js]
 [test_ext_background_sub_windows.js]
 [test_ext_background_window_properties.js]
 skip-if = os == "android"
 [test_ext_contexts.js]
 [test_ext_downloads.js]