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

Side by Side 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, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
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);
14 }
15 reader.readAsText(blob)
16 }
17
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(
23 callback,
24 ['OK'],
25 'Event callback must not be called more than once.');
26 }
27
5 chrome.test.sendMessage('loaded', function(test) { 28 chrome.test.sendMessage('loaded', function(test) {
6 chrome.test.runTests([function printTest() { 29 chrome.test.runTests([function printTest() {
7 if (test == 'NO_LISTENER') { 30 if (test == 'NO_LISTENER') {
8 chrome.test.sendMessage('ready'); 31 chrome.test.sendMessage('ready');
9 chrome.test.succeed(); 32 chrome.test.succeed();
10 return; 33 return;
11 } 34 }
12 35
13 chrome.printerProvider.onPrintRequested.addListener(function(job, 36 chrome.printerProvider.onPrintRequested.addListener(function(job,
14 callback) { 37 callback) {
15 chrome.test.assertFalse(!!chrome.printerProviderInternal); 38 chrome.test.assertFalse(!!chrome.printerProviderInternal);
16 chrome.test.assertTrue(!!job); 39 chrome.test.assertTrue(!!job);
17 40
18 if (test == 'IGNORE_CALLBACK') { 41 switch (test) {
19 chrome.test.succeed(); 42 case 'IGNORE_CALLBACK':
20 return; 43 break;
44 case 'ASYNC_RESPONSE':
45 setTimeout(callback.bind(null, 'OK'), 0);
46 break;
47 case 'INVALID_VALUE':
48 chrome.test.assertThrows(
49 callback,
50 ['XXX'],
51 'Invalid value for argument 1. ' +
52 'Value must be one of: ' +
53 '[OK, FAILED, INVALID_TICKET, INVALID_DATA].');
54 break;
55 case 'FAILED':
56 case 'INVALID_TICKET':
57 case 'INVALID_DATA':
58 wrapPrintCallback(callback, test);
59 break;
60 case 'OK':
61 readBlob(job.document, function(content) {
62 wrapPrintCallback(callback, !!content ? 'OK' : 'INVALID_DATA');
63
64 if (content)
65 chrome.test.assertEq('bytes', content);
66
67 chrome.test.succeed();
68 });
69
70 // Test will end asynchronously.
71 return;
72 default:
73 callback('FAILED');
74 chrome.test.fail('Invalid input');
75 return;
21 } 76 }
22 77
23 if (test == 'ASYNC_RESPONSE') {
24 setTimeout(callback.bind(null, 'OK'), 0);
25 chrome.test.succeed();
26 return;
27 }
28
29 if (test == 'INVALID_VALUE') {
30 chrome.test.assertThrows(
31 callback,
32 ['XXX'],
33 'Invalid value for argument 1. ' +
34 'Value must be one of: ' +
35 '[OK, FAILED, INVALID_TICKET, INVALID_DATA].');
36 } else {
37 chrome.test.assertTrue(test == 'OK' || test == 'FAILED' ||
38 test == 'INVALID_TICKET' || test == 'INVALID_DATA');
39 callback(test);
40 }
41
42 chrome.test.assertThrows(
43 callback,
44 [test],
45 'Event callback must not be called more than once.');
46
47 chrome.test.succeed(); 78 chrome.test.succeed();
48 }); 79 });
49 80
50 chrome.test.sendMessage('ready'); 81 chrome.test.sendMessage('ready');
51 }]); 82 }]);
52 }); 83 });
OLDNEW
« 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