Index: extensions/test/data/api_test/printer_provider/request_print/test.js |
diff --git a/extensions/test/data/api_test/printer_provider/request_print/test.js b/extensions/test/data/api_test/printer_provider/request_print/test.js |
index 868898dd1fdcf8251d7578cd7b398daca0ccd937..c0942eafd329f8f9de5e4ac477c342d9a03c6277 100644 |
--- a/extensions/test/data/api_test/printer_provider/request_print/test.js |
+++ b/extensions/test/data/api_test/printer_provider/request_print/test.js |
@@ -2,6 +2,29 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+// Reads a blob content. |
+// @param {!Blob} blob The blob to read. |
+// @param {function(?string)} callback Called with the read blob content. |
+// the content will be null on error. |
+function readBlob(blob, callback) { |
+ var reader = new FileReader(); |
+ reader.onerror = function() { callback(null); }; |
+ reader.onloadend = function() { |
+ callback(reader.result); |
+ } |
+ reader.readAsText(blob) |
+} |
+ |
+// Invokes |callback| with |returnValue| and verified a subsequent callback |
+// invocation throws an exception. |
+function wrapPrintCallback(callback, returnValue) { |
+ callback(returnValue); |
+ chrome.test.assertThrows( |
+ callback, |
+ ['OK'], |
+ 'Event callback must not be called more than once.'); |
+} |
+ |
chrome.test.sendMessage('loaded', function(test) { |
chrome.test.runTests([function printTest() { |
if (test == 'NO_LISTENER') { |
@@ -15,34 +38,42 @@ chrome.test.sendMessage('loaded', function(test) { |
chrome.test.assertFalse(!!chrome.printerProviderInternal); |
chrome.test.assertTrue(!!job); |
- if (test == 'IGNORE_CALLBACK') { |
- chrome.test.succeed(); |
- return; |
- } |
+ switch (test) { |
+ case 'IGNORE_CALLBACK': |
+ break; |
+ case 'ASYNC_RESPONSE': |
+ setTimeout(callback.bind(null, 'OK'), 0); |
+ break; |
+ case 'INVALID_VALUE': |
+ chrome.test.assertThrows( |
+ callback, |
+ ['XXX'], |
+ 'Invalid value for argument 1. ' + |
+ 'Value must be one of: ' + |
+ '[OK, FAILED, INVALID_TICKET, INVALID_DATA].'); |
+ break; |
+ case 'FAILED': |
+ case 'INVALID_TICKET': |
+ case 'INVALID_DATA': |
+ wrapPrintCallback(callback, test); |
+ break; |
+ case 'OK': |
+ readBlob(job.document, function(content) { |
+ wrapPrintCallback(callback, !!content ? 'OK' : 'INVALID_DATA'); |
- if (test == 'ASYNC_RESPONSE') { |
- setTimeout(callback.bind(null, 'OK'), 0); |
- chrome.test.succeed(); |
- return; |
- } |
+ if (content) |
+ chrome.test.assertEq('bytes', content); |
- if (test == 'INVALID_VALUE') { |
- chrome.test.assertThrows( |
- callback, |
- ['XXX'], |
- 'Invalid value for argument 1. ' + |
- 'Value must be one of: ' + |
- '[OK, FAILED, INVALID_TICKET, INVALID_DATA].'); |
- } else { |
- chrome.test.assertTrue(test == 'OK' || test == 'FAILED' || |
- test == 'INVALID_TICKET' || test == 'INVALID_DATA'); |
- callback(test); |
- } |
+ chrome.test.succeed(); |
+ }); |
- chrome.test.assertThrows( |
- callback, |
- [test], |
- 'Event callback must not be called more than once.'); |
+ // Test will end asynchronously. |
+ return; |
+ default: |
+ callback('FAILED'); |
+ chrome.test.fail('Invalid input'); |
+ return; |
+ } |
chrome.test.succeed(); |
}); |