Commit 82aa15ff authored by David Bertoni's avatar David Bertoni Committed by Commit Bot

[Extensions] Add more Alarms API test coverage.

Bug: 1093066
Change-Id: I8298635bd7f1717c29f020a6901a362f72c7d9e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2404943
Commit-Queue: David Bertoni <dbertoni@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808124}
parent af8d9846
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
let inIncognito = chrome.extension.inIncognitoContext; let inIncognito = chrome.extension.inIncognitoContext;
let alarmName = inIncognito ? 'incognito' : 'normal';
chrome.alarms.onAlarm.addListener(function(alarm) { chrome.alarms.onAlarm.addListener(function(alarm) {
chrome.test.assertEq(inIncognito ? 'incognito' : 'normal', alarm.name); chrome.test.assertEq(inIncognito ? 'incognito' : 'normal', alarm.name);
...@@ -11,8 +12,27 @@ chrome.alarms.onAlarm.addListener(function(alarm) { ...@@ -11,8 +12,27 @@ chrome.alarms.onAlarm.addListener(function(alarm) {
chrome.test.runTests([ chrome.test.runTests([
// Creates an alarm with the name of the context it was created in. // Creates an alarm with the name of the context it was created in.
function createAlarms() { function createAlarm() {
const alarmName = inIncognito ? 'incognito' : 'normal'; chrome.alarms.create(alarmName, {delayInMinutes: 0.001,
chrome.alarms.create(alarmName, {delayInMinutes: 0.001}); periodInMinutes: 60});
},
function getAlarm() {
chrome.alarms.get(alarmName, function(alarm) {
chrome.test.assertEq(alarmName, alarm.name);
chrome.test.succeed();
});
},
function getAllAlarms() {
chrome.alarms.getAll(function(alarms) {
chrome.test.assertEq(1, alarms.length);
chrome.test.assertEq(alarmName, alarms[0].name);
chrome.test.succeed();
});
},
function clearAlarm() {
chrome.alarms.clear(alarmName, function(wasCleared) {
chrome.test.assertTrue(wasCleared);
chrome.test.succeed();
});
} }
]); ]);
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
let inIncognito = chrome.extension.inIncognitoContext; let inIncognito = chrome.extension.inIncognitoContext;
let alarmName = inIncognito ? 'incognito' : 'normal';
let alarmTriggered = false; let alarmTriggered = false;
let testEventFired = false; let testEventFired = false;
...@@ -24,9 +25,30 @@ chrome.test.onMessage.addListener(function() { ...@@ -24,9 +25,30 @@ chrome.test.onMessage.addListener(function() {
chrome.test.runTests([ chrome.test.runTests([
// Creates an alarm with the name of the context it was created in. // Creates an alarm with the name of the context it was created in.
function createAlarms() { function createAlarm() {
const alarmName = inIncognito ? 'incognito' : 'normal'; // This test will pass when checkAndComplete() is called
chrome.alarms.create(alarmName, {delayInMinutes: 0.001}); // after the C++ code sends the expected message.
chrome.alarms.create(alarmName, {delayInMinutes: 0.001,
periodInMinutes: 60});
},
function getAlarm() {
chrome.alarms.get(alarmName, function(alarm) {
chrome.test.assertEq(alarmName, alarm.name);
chrome.test.succeed();
});
},
function getAllAlarms() {
chrome.alarms.getAll(function(alarms) {
chrome.test.assertEq(1, alarms.length);
chrome.test.assertEq(alarmName, alarms[0].name);
chrome.test.succeed();
});
},
function clearAlarm() {
chrome.alarms.clear(alarmName, function(wasCleared) {
chrome.test.assertTrue(wasCleared);
chrome.test.succeed();
});
} }
]); ]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment