Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Unified Diff: extensions/test/data/api_test/printer_provider/request_print/test.js

Issue 973993003: Instead of ArrayBuffer, pass blob with printerProvider.onPrintRequested (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase & add ext fun histogram Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();
});
« no previous file with comments | « extensions/renderer/resources/printer_provider_custom_bindings.js ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698