Index: chrome/test/data/extensions/api_test/copresence/test_copresence_api.js |
diff --git a/chrome/test/data/extensions/api_test/copresence/test_copresence_api.js b/chrome/test/data/extensions/api_test/copresence/test_copresence_api.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..694503509e9e99955b72a243fce6d99c673f69b7 |
--- /dev/null |
+++ b/chrome/test/data/extensions/api_test/copresence/test_copresence_api.js |
@@ -0,0 +1,95 @@ |
+// Copyright 2013 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. |
+ |
+function stringToArrayBuffer(str) { |
+ var utf8_string = unescape(encodeURIComponent(str)); |
+ var buffer = new ArrayBuffer(utf8_string.length); |
+ var view = new Uint8Array(buffer); |
+ for (var i = 0; i < utf8_string.length; ++i) { |
+ view[i] = utf8_string.charCodeAt(i); |
+ } |
+ return buffer; |
+} |
+ |
+function arrayBufferToString(buffer) { |
+ var utf8_string = String.fromCharCode.apply(null, new Uint8Array(buffer)); |
+ return decodeURIComponent(escape(utf8_string)); |
+} |
+ |
+function assertSuccess(status) { |
+ chrome.test.assertEq('success', status); |
+ chrome.test.assertNoLastError(); |
+} |
+ |
+chrome.copresence.onMessagesReceived.addListener( |
+ function(subscriptionId, messages) { |
+ chrome.test.assertEq('response', subscriptionId); |
+ chrome.test.assertEq(2, messages.length); |
+ chrome.test.assertEq('joke', messages[0].type); |
+ chrome.test.assertEq('Who\'s there?', |
+ arrayBufferToString(messages[0].payload)); |
+ chrome.test.succeed(); |
+ }); |
+ |
+var PUBLISH_OPERATION = { |
+ id: 'call', |
+ message: { |
+ type: 'joke', |
+ payload: stringToArrayBuffer('Knock Knock!') |
+ }, |
+ timeToLiveMillis: 1000, |
+ policy: {}, |
+ strategies: { |
+ onlyBroadcast: true |
+ } |
+}; |
+ |
+var SUBSCRIBE_OPERATION = { |
+ id: 'response', |
+ filter: { |
+ type: 'joke' |
+ }, |
+ timeToLiveMillis: 1000, |
+ strategies: { |
+ onlyScan: true |
+ } |
+}; |
+ |
+chrome.test.runTests([ |
+ function testPubSub() { |
+ chrome.copresence.execute( |
+ [{ publish: PUBLISH_OPERATION }], |
+ assertSuccess); |
rkc
2014/08/07 08:56:57
kalman@ already mentioned that you need callbackPa
Charlie
2014/08/07 22:24:15
Yeah I didn't understand the conventions for wrapp
|
+ |
+ chrome.copresence.execute( |
+ [{ subscribe: SUBSCRIBE_OPERATION }], |
+ assertSuccess); |
not at google - send to devlin
2014/08/06 21:45:27
2 general comments:
- it'd be good to enforce som
Charlie
2014/08/07 22:24:15
Done. I think.
|
+ }, |
+ |
+ function testUnPubSub() { |
+ chrome.copresence.execute( |
+ [{ |
+ unpublish: { unpublishId: 'call' } |
+ }, |
+ { |
+ unsubscribe: { unsubscribeId: 'response' } |
+ }], |
+ chrome.test.callbackPass(assertSuccess)); |
+ }, |
+ |
+ function testBadId() { |
+ chrome.copresence.execute( |
+ [{ unsubscribe: { unsubscribeId: 'invalid' } }], |
+ chrome.test.callbackFail("Invalid operation in operations array.")); |
+ }, |
+ |
+ function testMultipleOperations() { |
+ chrome.copresence.execute( |
+ [{ |
+ publish: PUBLISH_OPERATION, |
+ subscribe: SUBSCRIBE_OPERATION |
+ }], |
+ chrome.test.callbackFail("Invalid operation in operations array.")); |
+ } |
+]); |