diff options
author | tbarzic <tbarzic@chromium.org> | 2015-01-21 16:43:33 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-22 00:44:34 +0000 |
commit | 44f4c2fef4f1c0e86977a161459f4b067abf6af6 (patch) | |
tree | eb26f562347eb59fe6fa988bec61c3b0ce5028cb /extensions/test/data | |
parent | e53409112ade857d53896ee0891d25a0f692ae3c (diff) | |
download | chromium_src-44f4c2fef4f1c0e86977a161459f4b067abf6af6.zip chromium_src-44f4c2fef4f1c0e86977a161459f4b067abf6af6.tar.gz chromium_src-44f4c2fef4f1c0e86977a161459f4b067abf6af6.tar.bz2 |
Hook up chrome.printerProvider.onPrintRequested
This adds PrinterProviderAPI service which implements logic for dispatching
onPrintRequested event, and keeps track of pending event callbacks.
Adds PrinterProviderInternalAPI service and
PrinterProviderInternalAPIObserver. The internal API service keeps observer list,
which gets notified when printerProviderInternal API functions get called.
PrinterProviderAPI observes PrinterProviderInternalAPI service for when
print request result is reported, and runs the appropriate callback.
The callback is identified by the request_id param passed to the
internal API function (whose value is the one passed to chrome.printerProvider
event when it's dispatched).
BUG=408772
Review URL: https://codereview.chromium.org/853263002
Cr-Commit-Position: refs/heads/master@{#312506}
Diffstat (limited to 'extensions/test/data')
-rw-r--r-- | extensions/test/data/api_test/printer_provider/request_print/manifest.json | 14 | ||||
-rw-r--r-- | extensions/test/data/api_test/printer_provider/request_print/test.js | 47 |
2 files changed, 61 insertions, 0 deletions
diff --git a/extensions/test/data/api_test/printer_provider/request_print/manifest.json b/extensions/test/data/api_test/printer_provider/request_print/manifest.json new file mode 100644 index 0000000..5d1fc90 --- /dev/null +++ b/extensions/test/data/api_test/printer_provider/request_print/manifest.json @@ -0,0 +1,14 @@ +{ + "name": "Test printer provider", + "description": "Test extension for chrome.printerProvider.onPrintRequested event", + "manifest_version": 2, + "version": "0.1", + "app": { + "background": { + "scripts": ["test.js"] + } + }, + "permissions": [ + "printerProvider" + ] +} 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 new file mode 100644 index 0000000..c0d0a4f --- /dev/null +++ b/extensions/test/data/api_test/printer_provider/request_print/test.js @@ -0,0 +1,47 @@ +// Copyright 2015 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. + +chrome.test.sendMessage('loaded', function(test) { + chrome.test.runTests([function printTest() { + if (test == 'NO_LISTENER') { + chrome.test.sendMessage('ready'); + chrome.test.succeed(); + return; + } + + chrome.printerProvider.onPrintRequested.addListener(function(job, + callback) { + chrome.test.assertFalse(!!chrome.printerProviderInternal); + chrome.test.assertTrue(!!job); + + if (test == 'ASYNC_RESPONSE') { + setTimeout(callback.bind(null, 'OK'), 0); + chrome.test.succeed(); + return; + } + + 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.assertThrows( + callback, + [test], + 'Event callback must not be called more than once.'); + + chrome.test.succeed(); + }); + + chrome.test.sendMessage('ready'); + }]); +}); |