1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Reads a blob content.
6 // @param {!Blob} blob The blob to read.
7 // @param {function(?string)} callback Called with the read blob content.
8 // the content will be null on error.
9 function readBlob(blob, callback) {
10 var reader = new FileReader();
11 reader.onerror = function() { callback(null); };
12 reader.onloadend = function() {
13 callback(reader.result);
15 reader.readAsText(blob)
18 // Invokes |callback| with |returnValue| and verified a subsequent callback
19 // invocation throws an exception.
20 function wrapPrintCallback(callback, returnValue) {
21 callback(returnValue);
22 chrome.test.assertThrows(
25 'Event callback must not be called more than once.');
28 chrome.test.sendMessage('loaded', function(test) {
29 chrome.test.runTests([function printTest() {
30 if (test == 'NO_LISTENER') {
31 chrome.test.sendMessage('ready');
32 chrome.test.succeed();
36 chrome.printerProvider.onPrintRequested.addListener(function(job,
38 chrome.test.assertFalse(!!chrome.printerProviderInternal);
39 chrome.test.assertTrue(!!job);
42 case 'IGNORE_CALLBACK':
44 case 'ASYNC_RESPONSE':
45 setTimeout(callback.bind(null, 'OK'), 0);
48 chrome.test.assertThrows(
51 'Invalid value for argument 1. ' +
52 'Value must be one of: ' +
53 '[OK, FAILED, INVALID_TICKET, INVALID_DATA].');
56 case 'INVALID_TICKET':
58 wrapPrintCallback(callback, test);
61 readBlob(job.document, function(content) {
62 wrapPrintCallback(callback, !!content ? 'OK' : 'INVALID_DATA');
65 chrome.test.assertEq('bytes', content);
67 chrome.test.assertEq('Print job', job.title);
69 chrome.test.succeed();
72 // Test will end asynchronously.
76 chrome.test.fail('Invalid input');
80 chrome.test.succeed();
83 chrome.test.sendMessage('ready');