OSDN Git Service

Merge "Change suggestion window text color based on user feedback." into nyc-dev
[android-x86/frameworks-base.git] / core / tests / coretests / src / android / print / IPrintManagerParametersTest.java
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package android.print;
18
19 import android.annotation.NonNull;
20 import android.content.ComponentName;
21 import android.content.Context;
22 import android.os.Bundle;
23 import android.os.CancellationSignal;
24 import android.os.Handler;
25 import android.os.Looper;
26 import android.os.ParcelFileDescriptor;
27 import android.os.Process;
28 import android.os.ServiceManager;
29 import android.os.UserHandle;
30 import android.print.PrintAttributes.Margins;
31 import android.print.PrintAttributes.MediaSize;
32 import android.print.PrintAttributes.Resolution;
33 import android.printservice.PrintServiceInfo;
34
35 import android.print.mockservice.MockPrintService;
36 import android.print.mockservice.PrintServiceCallbacks;
37 import android.print.mockservice.PrinterDiscoverySessionCallbacks;
38 import android.print.mockservice.StubbablePrinterDiscoverySession;
39
40 import org.mockito.invocation.InvocationOnMock;
41 import org.mockito.stubbing.Answer;
42
43 import java.util.ArrayList;
44 import java.util.List;
45
46 /**
47  * tests feeding all possible parameters to the IPrintManager Binder.
48  */
49 public class IPrintManagerParametersTest extends BasePrintTest {
50
51     private final int BAD_APP_ID = 0xffffffff;
52
53     private final int mAppId;
54     private final int mUserId;
55     private final PrintJobId mBadPrintJobId;
56
57     private PrintJob mGoodPrintJob;
58     private PrinterId mBadPrinterId;
59     private PrinterId mGoodPrinterId;
60     private ComponentName mGoodComponentName;
61     private ComponentName mBadComponentName;
62
63     private IPrintManager mIPrintManager;
64
65     /**
66      * Create a new IPrintManagerParametersTest and setup basic fields.
67      */
68     public IPrintManagerParametersTest() {
69         super();
70
71         mAppId = UserHandle.getAppId(Process.myUid());
72         mUserId = UserHandle.myUserId();
73         mBadPrintJobId = new PrintJobId();
74         mBadComponentName = new ComponentName("bad", "bad");
75     }
76
77     /**
78      * Create a mock PrintDocumentAdapter.
79      *
80      * @return The adapter
81      */
82     private @NonNull PrintDocumentAdapter createMockAdapter() {
83         return new PrintDocumentAdapter() {
84             @Override
85             public void onStart() {
86                 onStartCalled();
87             }
88
89             @Override
90             public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
91                     CancellationSignal cancellationSignal, LayoutResultCallback callback,
92                     Bundle extras) {
93             }
94
95             @Override
96             public void onWrite(PageRange[] pages, ParcelFileDescriptor destination,
97                     CancellationSignal cancellationSignal, WriteResultCallback callback) {
98             }
99         };
100     }
101
102     /**
103      * Create mock print service callbacks.
104      *
105      * @return the callbacks
106      */
107     private PrintServiceCallbacks createMockCallbacks() {
108         return createMockPrintServiceCallbacks(
109                 new Answer<PrinterDiscoverySessionCallbacks>() {
110                     @Override
111                     public PrinterDiscoverySessionCallbacks answer(InvocationOnMock invocation) {
112                         return createMockPrinterDiscoverySessionCallbacks(new Answer<Void>() {
113                             @Override
114                             public Void answer(InvocationOnMock invocation) {
115                                 // Get the session.
116                                 StubbablePrinterDiscoverySession session =
117                                         ((PrinterDiscoverySessionCallbacks) invocation
118                                         .getMock()).getSession();
119
120                                 if (session.getPrinters().isEmpty()) {
121                                     final String PRINTER_NAME = "good printer";
122                                     List<PrinterInfo> printers = new ArrayList<>();
123
124                                     // Add the printer.
125                                     mGoodPrinterId = session.getService()
126                                             .generatePrinterId(PRINTER_NAME);
127
128                                     PrinterCapabilitiesInfo capabilities =
129                                             new PrinterCapabilitiesInfo.Builder(mGoodPrinterId)
130                                                     .setMinMargins(
131                                                             new Margins(200, 200, 200, 200))
132                                                     .addMediaSize(MediaSize.ISO_A4, true)
133                                                     .addResolution(new Resolution("300x300",
134                                                             "300x300", 300, 300),
135                                                             true)
136                                                     .setColorModes(
137                                                             PrintAttributes.COLOR_MODE_COLOR,
138                                                             PrintAttributes.COLOR_MODE_COLOR)
139                                                     .build();
140
141                                     PrinterInfo printer = new PrinterInfo.Builder(
142                                             mGoodPrinterId,
143                                             PRINTER_NAME,
144                                             PrinterInfo.STATUS_IDLE)
145                                                     .setCapabilities(capabilities)
146                                                     .build();
147                                     printers.add(printer);
148
149                                     session.addPrinters(printers);
150                                 }
151                                 onPrinterDiscoverySessionStartCalled();
152                                 return null;
153                             }
154                         }, null, null, null, null, null, null);
155                     }
156                 },
157                 null, null);
158     }
159
160     /**
161      * Create a IPrintJobStateChangeListener object.
162      *
163      * @return the object
164      * @throws Exception if the object could not be created.
165      */
166     private IPrintJobStateChangeListener createMockIPrintJobStateChangeListener() throws Exception {
167         return new PrintManager.PrintJobStateChangeListenerWrapper(null,
168                 new Handler(Looper.getMainLooper()));
169     }
170
171     /**
172      * Create a IPrintServicesChangeListener object.
173      *
174      * @return the object
175      * @throws Exception if the object could not be created.
176      */
177     private IPrintServicesChangeListener createMockIPrintServicesChangeListener() throws Exception {
178         return new PrintManager.PrintServicesChangeListenerWrapper(null,
179                 new Handler(Looper.getMainLooper()));
180     }
181
182
183     /**
184      * Create a IPrinterDiscoveryObserver object.
185      *
186      * @return the object
187      * @throws Exception if the object could not be created.
188      */
189     private IPrinterDiscoveryObserver createMockIPrinterDiscoveryObserver() throws Exception {
190         return new PrinterDiscoverySession.PrinterDiscoveryObserver(null);
191     }
192
193     private void startPrinting() {
194         mGoodPrintJob = print(createMockAdapter(), null);
195
196         // Wait for PrintActivity to be ready
197         waitForStartAdapterCallbackCalled();
198
199         // Wait for printer discovery session to be ready
200         waitForPrinterDiscoverySessionStartCallbackCalled();
201     }
202
203     @Override
204     public void setUp() throws Exception {
205         super.setUp();
206
207         MockPrintService.setCallbacks(createMockCallbacks());
208
209         mGoodComponentName = getActivity().getComponentName();
210
211         mIPrintManager = IPrintManager.Stub
212                 .asInterface(ServiceManager.getService(Context.PRINT_SERVICE));
213
214         // Generate dummy printerId which is a valid PrinterId object, but does not correspond to a
215         // printer
216         mBadPrinterId = new PrinterId(mGoodComponentName, "dummy printer");
217     }
218
219     /**
220      * {@link Runnable} that can throw and {@link Exception}
221      */
222     private interface Invokable {
223         /**
224          * Execute the invokable
225          *
226          * @throws Exception
227          */
228         void run() throws Exception;
229     }
230
231     /**
232      * Assert that the invokable throws an expectedException
233      *
234      * @param invokable The {@link Invokable} to run
235      * @param expectedClass The {@link Exception} that is supposed to be thrown
236      */
237     public void assertException(Invokable invokable, Class<? extends Exception> expectedClass)
238             throws Exception {
239         try {
240             invokable.run();
241         } catch (Exception e) {
242             if (e.getClass().isAssignableFrom(expectedClass)) {
243                 return;
244             } else {
245                 throw new AssertionError("Expected: " + expectedClass.getName() + ", got: "
246                                 + e.getClass().getName());
247             }
248         }
249
250         throw new AssertionError("No exception thrown");
251     }
252
253     /**
254      * test IPrintManager.getPrintJobInfo
255      */
256     public void testGetPrintJobInfo() throws Exception {
257         startPrinting();
258
259         assertEquals(mGoodPrintJob.getId(), mIPrintManager.getPrintJobInfo(mGoodPrintJob.getId(),
260                         mAppId, mUserId).getId());
261         assertEquals(null, mIPrintManager.getPrintJobInfo(mBadPrintJobId, mAppId, mUserId));
262         assertEquals(null, mIPrintManager.getPrintJobInfo(null, mAppId, mUserId));
263
264         assertException(new Invokable() {
265             @Override
266             public void run() throws Exception {
267                 mIPrintManager.getPrintJobInfo(mGoodPrintJob.getId(), BAD_APP_ID, mUserId);
268             }
269         }, SecurityException.class);
270
271         // Cannot test bad user Id as these tests are allowed to call across users
272     }
273
274     /**
275      * test IPrintManager.getPrintJobInfos
276      */
277     public void testGetPrintJobInfos() throws Exception {
278         startPrinting();
279
280         List<PrintJobInfo> infos = mIPrintManager.getPrintJobInfos(mAppId, mUserId);
281
282         boolean foundPrintJob = false;
283         for (PrintJobInfo info : infos) {
284             if (info.getId().equals(mGoodPrintJob.getId())) {
285                 assertEquals(PrintJobInfo.STATE_CREATED, info.getState());
286                 foundPrintJob = true;
287             }
288         }
289         assertTrue(foundPrintJob);
290
291         assertException(new Invokable() {
292             @Override
293             public void run() throws Exception {
294                 mIPrintManager.getPrintJobInfos(BAD_APP_ID, mUserId);
295             }
296         }, SecurityException.class);
297
298         // Cannot test bad user Id as these tests are allowed to call across users
299     }
300
301     /**
302      * test IPrintManager.print
303      */
304     public void testPrint() throws Exception {
305         final String name = "dummy print job";
306
307         final IPrintDocumentAdapter adapter = new PrintManager
308                 .PrintDocumentAdapterDelegate(getActivity(), createMockAdapter());
309
310         startPrinting();
311
312         assertException(new Invokable() {
313             @Override
314             public void run() throws Exception {
315                 mIPrintManager.print(null, adapter, null, mGoodComponentName.getPackageName(),
316                         mAppId, mUserId);
317             }
318         }, IllegalArgumentException.class);
319
320         assertException(new Invokable() {
321             @Override
322             public void run() throws Exception {
323                 mIPrintManager.print(name, null, null, mGoodComponentName.getPackageName(),
324                         mAppId, mUserId);
325             }
326         }, NullPointerException.class);
327
328         assertException(new Invokable() {
329             @Override
330             public void run() throws Exception {
331                 mIPrintManager.print(name, adapter, null, null, mAppId, mUserId);
332             }
333         }, IllegalArgumentException.class);
334
335         assertException(new Invokable() {
336             @Override
337             public void run() throws Exception {
338                 mIPrintManager.print(name, adapter, null, mBadComponentName.getPackageName(),
339                         mAppId, mUserId);
340             }
341         }, IllegalArgumentException.class);
342
343         assertException(new Invokable() {
344             @Override
345             public void run() throws Exception {
346                 mIPrintManager.print(name, adapter, null, mGoodComponentName.getPackageName(),
347                         BAD_APP_ID, mUserId);
348             }
349         }, SecurityException.class);
350
351         // Cannot test bad user Id as these tests are allowed to call across users
352     }
353
354     /**
355      * test IPrintManager.cancelPrintJob
356      */
357     public void testCancelPrintJob() throws Exception {
358         startPrinting();
359
360         // Invalid print jobs IDs do not produce an exception
361         mIPrintManager.cancelPrintJob(mBadPrintJobId, mAppId, mUserId);
362         mIPrintManager.cancelPrintJob(null, mAppId, mUserId);
363
364         assertException(new Invokable() {
365             @Override
366             public void run() throws Exception {
367                 mIPrintManager.cancelPrintJob(mGoodPrintJob.getId(), BAD_APP_ID, mUserId);
368             }
369         }, SecurityException.class);
370
371         // Cannot test bad user Id as these tests are allowed to call across users
372
373         // Must be last as otherwise mGoodPrintJob will not be good anymore
374         mIPrintManager.cancelPrintJob(mGoodPrintJob.getId(), mAppId, mUserId);
375     }
376
377     /**
378      * test IPrintManager.restartPrintJob
379      */
380     public void testRestartPrintJob() throws Exception {
381         startPrinting();
382
383         mIPrintManager.restartPrintJob(mGoodPrintJob.getId(), mAppId, mUserId);
384
385         // Invalid print jobs IDs do not produce an exception
386         mIPrintManager.restartPrintJob(mBadPrintJobId, mAppId, mUserId);
387         mIPrintManager.restartPrintJob(null, mAppId, mUserId);
388
389         assertException(new Invokable() {
390             @Override
391             public void run() throws Exception {
392                 mIPrintManager.restartPrintJob(mGoodPrintJob.getId(), BAD_APP_ID, mUserId);
393             }
394         }, SecurityException.class);
395
396         // Cannot test bad user Id as these tests are allowed to call across users
397     }
398
399     /**
400      * test IPrintManager.addPrintJobStateChangeListener
401      */
402     public void testAddPrintJobStateChangeListener() throws Exception {
403         final IPrintJobStateChangeListener listener = createMockIPrintJobStateChangeListener();
404
405         mIPrintManager.addPrintJobStateChangeListener(listener, mAppId, mUserId);
406
407         assertException(new Invokable() {
408             @Override
409             public void run() throws Exception {
410                 mIPrintManager.addPrintJobStateChangeListener(null, mAppId, mUserId);
411             }
412         }, NullPointerException.class);
413
414         assertException(new Invokable() {
415             @Override
416             public void run() throws Exception {
417                 mIPrintManager.addPrintJobStateChangeListener(listener, BAD_APP_ID, mUserId);
418             }
419         }, SecurityException.class);
420
421         // Cannot test bad user Id as these tests are allowed to call across users
422     }
423
424     /**
425      * test IPrintManager.removePrintJobStateChangeListener
426      */
427     public void testRemovePrintJobStateChangeListener() throws Exception {
428         final IPrintJobStateChangeListener listener = createMockIPrintJobStateChangeListener();
429
430         mIPrintManager.addPrintJobStateChangeListener(listener, mAppId, mUserId);
431         mIPrintManager.removePrintJobStateChangeListener(listener, mUserId);
432
433         // Removing unknown listeners is a no-op
434         mIPrintManager.removePrintJobStateChangeListener(listener, mUserId);
435
436         mIPrintManager.addPrintJobStateChangeListener(listener, mAppId, mUserId);
437         assertException(new Invokable() {
438             @Override
439             public void run() throws Exception {
440                 mIPrintManager.removePrintJobStateChangeListener(null, mUserId);
441             }
442         }, NullPointerException.class);
443
444         // Cannot test bad user Id as these tests are allowed to call across users
445     }
446
447     /**
448      * test IPrintManager.addPrintServicesChangeListener
449      */
450     public void testAddPrintServicesChangeListener() throws Exception {
451         final IPrintServicesChangeListener listener = createMockIPrintServicesChangeListener();
452
453         mIPrintManager.addPrintServicesChangeListener(listener, mUserId);
454
455         assertException(new Invokable() {
456             @Override
457             public void run() throws Exception {
458                 mIPrintManager.addPrintServicesChangeListener(null, mUserId);
459             }
460         }, NullPointerException.class);
461
462         // Cannot test bad user Id as these tests are allowed to call across users
463     }
464
465     /**
466      * test IPrintManager.removePrintServicesChangeListener
467      */
468     public void testRemovePrintServicesChangeListener() throws Exception {
469         final IPrintServicesChangeListener listener = createMockIPrintServicesChangeListener();
470
471         mIPrintManager.addPrintServicesChangeListener(listener, mUserId);
472         mIPrintManager.removePrintServicesChangeListener(listener, mUserId);
473
474         // Removing unknown listeners is a no-op
475         mIPrintManager.removePrintServicesChangeListener(listener, mUserId);
476
477         mIPrintManager.addPrintServicesChangeListener(listener, mUserId);
478         assertException(new Invokable() {
479             @Override
480             public void run() throws Exception {
481                 mIPrintManager.removePrintServicesChangeListener(null, mUserId);
482             }
483         }, NullPointerException.class);
484
485         // Cannot test bad user Id as these tests are allowed to call across users
486     }
487
488     /**
489      * test IPrintManager.getPrintServices
490      */
491     public void testGetPrintServices() throws Exception {
492         List<PrintServiceInfo> printServices = mIPrintManager.getPrintServices(
493                 PrintManager.ALL_SERVICES, mUserId);
494         assertTrue(printServices.size() >= 2);
495
496         printServices = mIPrintManager.getPrintServices(0, mUserId);
497         assertEquals(printServices, null);
498
499         assertException(new Invokable() {
500             @Override
501             public void run() throws Exception {
502                 mIPrintManager.getPrintServices(~PrintManager.ALL_SERVICES, mUserId);
503             }
504         }, IllegalArgumentException.class);
505
506         // Cannot test bad user Id as these tests are allowed to call across users
507     }
508
509     /**
510      * test IPrintManager.setPrintServiceEnabled
511      */
512     public void testSetPrintServiceEnabled() throws Exception {
513         final ComponentName printService = mIPrintManager.getPrintServices(
514                 PrintManager.ALL_SERVICES, mUserId).get(0).getComponentName();
515
516         assertException(new Invokable() {
517             @Override
518             public void run() throws Exception {
519                 mIPrintManager.setPrintServiceEnabled(printService, false, mUserId);
520             }
521         }, SecurityException.class);
522
523         assertException(new Invokable() {
524             @Override
525             public void run() throws Exception {
526                 mIPrintManager.setPrintServiceEnabled(printService, true, mUserId);
527             }
528         }, SecurityException.class);
529
530         assertException(new Invokable() {
531             @Override
532             public void run() throws Exception {
533                 mIPrintManager.setPrintServiceEnabled(new ComponentName("bad", "name"), true,
534                                 mUserId);
535             }
536         }, SecurityException.class);
537
538         assertException(new Invokable() {
539             @Override
540             public void run() throws Exception {
541                 mIPrintManager.setPrintServiceEnabled(null, true, mUserId);
542             }
543         }, SecurityException.class);
544
545         // Cannot test bad user Id as these tests are allowed to call across users
546     }
547
548     /**
549      * test IPrintManager.createPrinterDiscoverySession
550      */
551     public void testCreatePrinterDiscoverySession() throws Exception {
552         final IPrinterDiscoveryObserver listener = createMockIPrinterDiscoveryObserver();
553
554         mIPrintManager.createPrinterDiscoverySession(listener, mUserId);
555
556         try {
557             assertException(new Invokable() {
558                 @Override
559                 public void run() throws Exception {
560                     mIPrintManager.createPrinterDiscoverySession(null, mUserId);
561                 }
562             }, NullPointerException.class);
563
564             // Cannot test bad user Id as these tests are allowed to call across users
565         } finally {
566             // Remove discovery session so that the next test create a new one. Usually a leaked
567             // session is removed on the next call from the print service. But in this case we want
568             // to force a new call to onPrinterDiscoverySessionStart in the next test.
569             mIPrintManager.destroyPrinterDiscoverySession(listener, mUserId);
570         }
571     }
572
573     /**
574      * test IPrintManager.startPrinterDiscovery
575      */
576     public void testStartPrinterDiscovery() throws Exception {
577         startPrinting();
578
579         final IPrinterDiscoveryObserver listener = createMockIPrinterDiscoveryObserver();
580         final List<PrinterId> goodPrinters = new ArrayList<>();
581         goodPrinters.add(mGoodPrinterId);
582
583         final List<PrinterId> badPrinters = new ArrayList<>();
584         badPrinters.add(mBadPrinterId);
585
586         final List<PrinterId> emptyPrinters = new ArrayList<>();
587
588         final List<PrinterId> nullPrinters = new ArrayList<>();
589         nullPrinters.add(null);
590
591         mIPrintManager.startPrinterDiscovery(listener, goodPrinters, mUserId);
592
593         // Bad or no printers do no cause exceptions
594         mIPrintManager.startPrinterDiscovery(listener, badPrinters, mUserId);
595         mIPrintManager.startPrinterDiscovery(listener, emptyPrinters, mUserId);
596         mIPrintManager.startPrinterDiscovery(listener, null, mUserId);
597
598         assertException(new Invokable() {
599             @Override
600             public void run() throws Exception {
601                 mIPrintManager.startPrinterDiscovery(listener, nullPrinters, mUserId);
602             }
603         }, NullPointerException.class);
604
605         assertException(new Invokable() {
606             @Override
607             public void run() throws Exception {
608                 mIPrintManager.startPrinterDiscovery(null, goodPrinters, mUserId);
609             }
610         }, NullPointerException.class);
611
612         // Cannot test bad user Id as these tests are allowed to call across users
613     }
614
615     /**
616      * test IPrintManager.stopPrinterDiscovery
617      */
618     public void testStopPrinterDiscovery() throws Exception {
619         final IPrinterDiscoveryObserver listener = createMockIPrinterDiscoveryObserver();
620
621         mIPrintManager.startPrinterDiscovery(listener, null, mUserId);
622         mIPrintManager.stopPrinterDiscovery(listener, mUserId);
623
624         // Stopping an already stopped session is a no-op
625         mIPrintManager.stopPrinterDiscovery(listener, mUserId);
626
627         mIPrintManager.startPrinterDiscovery(listener, null, mUserId);
628         assertException(new Invokable() {
629             @Override
630             public void run() throws Exception {
631                 mIPrintManager.stopPrinterDiscovery(null, mUserId);
632             }
633         }, NullPointerException.class);
634
635         // Cannot test bad user Id as these tests are allowed to call across users
636     }
637
638     /**
639      * test IPrintManager.validatePrinters
640      */
641     public void testValidatePrinters() throws Exception {
642         startPrinting();
643
644         final List<PrinterId> goodPrinters = new ArrayList<>();
645         goodPrinters.add(mGoodPrinterId);
646
647         final List<PrinterId> badPrinters = new ArrayList<>();
648         badPrinters.add(mBadPrinterId);
649
650         final List<PrinterId> emptyPrinters = new ArrayList<>();
651
652         final List<PrinterId> nullPrinters = new ArrayList<>();
653         nullPrinters.add(null);
654
655         mIPrintManager.validatePrinters(goodPrinters, mUserId);
656
657         // Bad or empty list of printers do no cause exceptions
658         mIPrintManager.validatePrinters(badPrinters, mUserId);
659         mIPrintManager.validatePrinters(emptyPrinters, mUserId);
660
661         assertException(new Invokable() {
662             @Override
663             public void run() throws Exception {
664                 mIPrintManager.validatePrinters(null, mUserId);
665             }
666         }, NullPointerException.class);
667
668         assertException(new Invokable() {
669             @Override
670             public void run() throws Exception {
671                 mIPrintManager.validatePrinters(nullPrinters, mUserId);
672             }
673         }, NullPointerException.class);
674
675         // Cannot test bad user Id as these tests are allowed to call across users
676     }
677
678     /**
679      * test IPrintManager.startPrinterStateTracking
680      */
681     public void testStartPrinterStateTracking() throws Exception {
682         startPrinting();
683
684         mIPrintManager.startPrinterStateTracking(mGoodPrinterId, mUserId);
685
686         // Bad printers do no cause exceptions
687         mIPrintManager.startPrinterStateTracking(mBadPrinterId, mUserId);
688
689         assertException(new Invokable() {
690             @Override
691             public void run() throws Exception {
692                 mIPrintManager.startPrinterStateTracking(null, mUserId);
693             }
694         }, NullPointerException.class);
695
696         // Cannot test bad user Id as these tests are allowed to call across users
697     }
698
699     /**
700      * test IPrintManager.getCustomPrinterIcon
701      */
702     public void testGetCustomPrinterIcon() throws Exception {
703         startPrinting();
704
705         mIPrintManager.getCustomPrinterIcon(mGoodPrinterId, mUserId);
706
707         // Bad printers do no cause exceptions
708         mIPrintManager.getCustomPrinterIcon(mBadPrinterId, mUserId);
709
710         assertException(new Invokable() {
711             @Override
712             public void run() throws Exception {
713                 mIPrintManager.getCustomPrinterIcon(null, mUserId);
714             }
715         }, NullPointerException.class);
716
717         // Cannot test bad user Id as these tests are allowed to call across users
718     }
719
720     /**
721      * test IPrintManager.stopPrinterStateTracking
722      */
723     public void testStopPrinterStateTracking() throws Exception {
724         startPrinting();
725
726         mIPrintManager.startPrinterStateTracking(mGoodPrinterId, mUserId);
727         mIPrintManager.stopPrinterStateTracking(mGoodPrinterId, mUserId);
728
729         // Stop to track a non-tracked printer is a no-op
730         mIPrintManager.stopPrinterStateTracking(mGoodPrinterId, mUserId);
731
732         // Bad printers do no cause exceptions
733         mIPrintManager.startPrinterStateTracking(mBadPrinterId, mUserId);
734         mIPrintManager.stopPrinterStateTracking(mBadPrinterId, mUserId);
735
736         assertException(new Invokable() {
737             @Override
738             public void run() throws Exception {
739                 mIPrintManager.stopPrinterStateTracking(null, mUserId);
740             }
741         }, NullPointerException.class);
742
743         // Cannot test bad user Id as these tests are allowed to call across users
744     }
745
746     /**
747      * test IPrintManager.destroyPrinterDiscoverySession
748      */
749     public void testDestroyPrinterDiscoverySession() throws Exception {
750         final IPrinterDiscoveryObserver listener = createMockIPrinterDiscoveryObserver();
751
752         mIPrintManager.createPrinterDiscoverySession(listener, mUserId);
753         mIPrintManager.destroyPrinterDiscoverySession(listener, mUserId);
754
755         // Destroying already destroyed session is a no-op
756         mIPrintManager.destroyPrinterDiscoverySession(listener, mUserId);
757
758         assertException(new Invokable() {
759             @Override
760             public void run() throws Exception {
761                 mIPrintManager.destroyPrinterDiscoverySession(null, mUserId);
762             }
763         }, NullPointerException.class);
764
765         // Cannot test bad user Id as these tests are allowed to call across users
766     }
767 }