forked from sanyaade-mobiledev/chromium.src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a browser test for functions in notification provider API
Add a basic browser test for functions in notification provider API. This is mainly to test the connection and provide a skeleton for future tests. The functions are not fully implemented yet, and more tests will be added as the functions are implemented. BUG= Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=287692 Review URL: https://codereview.chromium.org/416423006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287972 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
liyanhou@chromium.org
committed
Aug 7, 2014
1 parent
cf8c490
commit 6a72afc
Showing
3 changed files
with
170 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
chrome/test/data/extensions/api_test/notification_provider/basic_usage/background.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
const notificationProvider = chrome.notificationProvider; | ||
|
||
function notifyOnCleared(senderId, notificationId) { | ||
return new Promise(function (resolve, reject) { | ||
notificationProvider.notifyOnCleared(senderId, | ||
notificationId, | ||
function (wasCleared) { | ||
if (chrome.runtime.lastError || !wasCleared) { | ||
reject(new Error("Unable to send onClear message")); | ||
return; | ||
} | ||
resolve(wasCleared); | ||
return; | ||
}); | ||
}); | ||
}; | ||
|
||
function notifyOnClicked(senderId, notificationId) { | ||
return new Promise(function (resolve, reject) { | ||
notificationProvider.notifyOnClicked(senderId, | ||
notificationId, | ||
function (matchExists) { | ||
if (chrome.runtime.lastError || !matchExists) { | ||
reject(new Error("Unable to send onClick message")); | ||
return; | ||
} | ||
resolve(matchExists); | ||
return; | ||
}); | ||
}); | ||
}; | ||
|
||
function notifyOnButtonClicked(senderId, notificationId, buttonIndex) { | ||
return new Promise(function (resolve, reject) { | ||
notificationProvider.notifyOnButtonClicked(senderId, | ||
notificationId, | ||
buttonIndex, | ||
function (matchExists) { | ||
if (chrome.runtime.lastError || !matchExists) { | ||
reject(new Error("Unable to send onButtonClick message")); | ||
return; | ||
} | ||
resolve(matchExists); | ||
return; | ||
}); | ||
}); | ||
}; | ||
|
||
function notifyOnPermissionLevelChanged(senderId, permissionLevel) { | ||
return new Promise(function (resolve, reject) { | ||
notificationProvider.notifyOnPermissionLevelChanged( | ||
senderId, | ||
permissionLevel, | ||
function (notifierExists) { | ||
if (chrome.runtime.lastError || !notifierExists) { | ||
reject(new Error("Unable to send onPermissionLevelChanged message")); | ||
return; | ||
} | ||
resolve(notifierExists); | ||
return; | ||
}); | ||
}); | ||
}; | ||
|
||
function notifyOnShowSettings(senderId) { | ||
return new Promise(function (resolve, reject) { | ||
notificationProvider.notifyOnShowSettings(senderId, | ||
function (notifierExists) { | ||
if (chrome.runtime.lastError || !notifierExists) { | ||
reject(new Error("Unable to send onShowSettings message")); | ||
return; | ||
} | ||
resolve(notifierExists); | ||
return; | ||
}); | ||
}); | ||
}; | ||
|
||
function failTest(testName) { | ||
chrome.test.fail(testName); | ||
}; | ||
|
||
function testFunctions() { | ||
var testName = "testFunctions"; | ||
var notifierId; | ||
var notId; | ||
notificationProvider.onCreated.addListener(function(senderId, | ||
notificationId, | ||
content) { | ||
notifierId = senderId; | ||
notId = notificationId; | ||
|
||
notifyOnClicked(notifierId, notId) | ||
.catch(function() { failTest("NotifyOnClickedFailed"); }) | ||
.then(function() { return notifyOnButtonClicked(notifierId, notId, 0); }) | ||
.catch(function() { failTest("NotifyOnButtonClickedFailed"); }) | ||
.then(function () { return notifyOnCleared(notifierId, notId); }) | ||
.catch(function() { failTest("NotifyOnClearedFailed"); }) | ||
.then(function () { return notifyOnPermissionLevelChanged(notifierId, | ||
"granted"); }) | ||
.catch(function() { failTest("NotifyOnPermissionLevelChangedFailed"); }) | ||
.then(function () { return notifyOnShowSettings(notifierId); }) | ||
.catch(function() { failTest("NotifyOnShowSettingsFailed"); }) | ||
.then(function() { chrome.test.succeed(testName); }); | ||
}); | ||
}; | ||
|
||
chrome.test.runTests([ testFunctions ]); |
13 changes: 13 additions & 0 deletions
13
chrome/test/data/extensions/api_test/notification_provider/basic_usage/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "chrome.notificationProvider", | ||
"version": "0.1", | ||
"description": "Tests chrome.notificationProvider API functions", | ||
"app": { | ||
"background": { | ||
"scripts": ["background.js"] | ||
} | ||
}, | ||
"permissions": [ | ||
"notificationProvider" | ||
] | ||
} |