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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/printing/PrintingControllerTest.java

Issue 618553002: [Android] Move printing test to the correct package. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 package org.chromium.printing; 5 package org.chromium.chrome.browser.printing;
6 6
7 import android.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.os.Build; 8 import android.os.Build;
9 import android.os.CancellationSignal; 9 import android.os.CancellationSignal;
10 import android.os.ParcelFileDescriptor; 10 import android.os.ParcelFileDescriptor;
11 import android.print.PageRange; 11 import android.print.PageRange;
12 import android.print.PrintAttributes; 12 import android.print.PrintAttributes;
13 import android.print.PrintDocumentAdapter; 13 import android.print.PrintDocumentAdapter;
14 import android.print.PrintDocumentInfo; 14 import android.print.PrintDocumentInfo;
15 import android.test.suitebuilder.annotation.LargeTest; 15 import android.test.suitebuilder.annotation.LargeTest;
16 16
17 import org.chromium.base.ApiCompatibilityUtils; 17 import org.chromium.base.ApiCompatibilityUtils;
18 import org.chromium.base.test.util.Feature; 18 import org.chromium.base.test.util.Feature;
19 import org.chromium.base.test.util.TestFileUtil; 19 import org.chromium.base.test.util.TestFileUtil;
20 import org.chromium.base.test.util.UrlUtils; 20 import org.chromium.base.test.util.UrlUtils;
21 import org.chromium.chrome.browser.printing.TabPrinter;
22 import org.chromium.chrome.shell.ChromeShellTab; 21 import org.chromium.chrome.shell.ChromeShellTab;
23 import org.chromium.chrome.shell.ChromeShellTestBase; 22 import org.chromium.chrome.shell.ChromeShellTestBase;
23 import org.chromium.printing.PrintDocumentAdapterWrapper;
24 import org.chromium.printing.PrintManagerDelegate;
25 import org.chromium.printing.PrintingControllerImpl;
24 26
25 import java.io.File; 27 import java.io.File;
26 import java.io.FileInputStream; 28 import java.io.FileInputStream;
27 import java.io.IOException; 29 import java.io.IOException;
28 import java.util.concurrent.Callable; 30 import java.util.concurrent.Callable;
29 import java.util.concurrent.FutureTask; 31 import java.util.concurrent.FutureTask;
30 import java.util.concurrent.TimeUnit; 32 import java.util.concurrent.TimeUnit;
31 33
32 /** 34 /**
33 * Tests Android printing. 35 * Tests Android printing.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 87
86 final PrintingControllerImpl printingController = createControllerOnUiTh read(); 88 final PrintingControllerImpl printingController = createControllerOnUiTh read();
87 89
88 startControllerOnUiThread(printingController, currentTab); 90 startControllerOnUiThread(printingController, currentTab);
89 // {@link PrintDocumentAdapter#onStart} is always called first. 91 // {@link PrintDocumentAdapter#onStart} is always called first.
90 callStartOnUiThread(printingController); 92 callStartOnUiThread(printingController);
91 93
92 // Create a temporary file to save the PDF. 94 // Create a temporary file to save the PDF.
93 final File cacheDir = getInstrumentation().getTargetContext().getCacheDi r(); 95 final File cacheDir = getInstrumentation().getTargetContext().getCacheDi r();
94 final File tempFile = File.createTempFile(TEMP_FILE_NAME, TEMP_FILE_EXTE NSION, cacheDir); 96 final File tempFile = File.createTempFile(TEMP_FILE_NAME, TEMP_FILE_EXTE NSION, cacheDir);
95 final ParcelFileDescriptor fileDescriptor = 97 final ParcelFileDescriptor fileDescriptor = ParcelFileDescriptor.open(te mpFile,
96 ParcelFileDescriptor.open(tempFile, (ParcelFileDescriptor.MODE_C REATE | 98 (ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_RE AD_WRITE));
97 ParcelFileDescriptor.MODE_R EAD_WRITE));
98 99
99 PrintAttributes attributes = new PrintAttributes.Builder() 100 PrintAttributes attributes = new PrintAttributes.Builder()
100 .setMediaSize(PrintAttributes.MediaSize.ISO_A4) 101 .setMediaSize(PrintAttributes.MediaSize.ISO_A4)
101 .setResolution(new PrintAttributes.Resolution("foo", "bar", 300, 300)) 102 .setResolution(new PrintAttributes.Resolution("foo", "bar", 300, 300))
102 .setMinMargins(PrintAttributes.Margins.NO_MARGINS) 103 .setMinMargins(PrintAttributes.Margins.NO_MARGINS)
103 .build(); 104 .build();
104 105
105 // Use this to wait for PDF generation to complete, as it will happen as ynchronously. 106 // Use this to wait for PDF generation to complete, as it will happen as ynchronously.
106 final FutureTask<Boolean> result = 107 final FutureTask<Boolean> result = new FutureTask<Boolean>(new Callable< Boolean>() {
107 new FutureTask<Boolean>(new Callable<Boolean>() {
108 @Override
109 public Boolean call() {
110 return true;
111 }
112 });
113
114 callLayoutOnUiThread(
115 printingController,
116 null,
117 attributes,
118 new LayoutResultCallbackWrapperMock() {
119 // Called on UI thread
120 @Override 108 @Override
121 public void onLayoutFinished(PrintDocumentInfo info, boolean changed ) { 109 public Boolean call() {
122 callWriteOnUiThread(printingController, fileDescriptor, result); 110 return true;
123 } 111 }
124 }); 112 });
125 113
114 callLayoutOnUiThread(printingController, null, attributes,
115 new LayoutResultCallbackWrapperMock() {
116 // Called on UI thread
117 @Override
118 public void onLayoutFinished(PrintDocumentInfo info, boolean changed) {
119 callWriteOnUiThread(printingController, fileDescriptor, result);
120 }
121 });
122
126 FileInputStream in = null; 123 FileInputStream in = null;
127 try { 124 try {
128 // This blocks until the PDF is generated. 125 // This blocks until the PDF is generated.
129 result.get(TEST_TIMEOUT, TimeUnit.MILLISECONDS); 126 result.get(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
130 assertTrue(tempFile.length() > 0); 127 assertTrue(tempFile.length() > 0);
131 in = new FileInputStream(tempFile); 128 in = new FileInputStream(tempFile);
132 byte[] b = new byte[PDF_PREAMBLE.length()]; 129 byte[] b = new byte[PDF_PREAMBLE.length()];
133 in.read(b); 130 in.read(b);
134 String preamble = new String(b); 131 String preamble = new String(b);
135 assertEquals(PDF_PREAMBLE, preamble); 132 assertEquals(PDF_PREAMBLE, preamble);
(...skipping 26 matching lines...) Expand all
162 fail("Error on creating PrintingControllerImpl on the UI thread: " + e); 159 fail("Error on creating PrintingControllerImpl on the UI thread: " + e);
163 } 160 }
164 return null; 161 return null;
165 } 162 }
166 163
167 private void startControllerOnUiThread(final PrintingControllerImpl controll er, 164 private void startControllerOnUiThread(final PrintingControllerImpl controll er,
168 final ChromeShellTab tab) { 165 final ChromeShellTab tab) {
169 try { 166 try {
170 final PrintManagerDelegate mockPrintManagerDelegate = new PrintManag erDelegate() { 167 final PrintManagerDelegate mockPrintManagerDelegate = new PrintManag erDelegate() {
171 @Override 168 @Override
172 public void print(String printJobName, 169 public void print(String printJobName, PrintDocumentAdapter docu mentAdapter,
173 PrintDocumentAdapter documentAdapter,
174 PrintAttributes attributes) { 170 PrintAttributes attributes) {
175 // Do nothing, as we will emulate the framework call sequenc e within the test. 171 // Do nothing, as we will emulate the framework call sequenc e within the test.
176 } 172 }
177 }; 173 };
178 174
179 runTestOnUiThread(new Runnable() { 175 runTestOnUiThread(new Runnable() {
180 @Override 176 @Override
181 public void run() { 177 public void run() {
182 controller.startPrint(new TabPrinter(tab), mockPrintManagerD elegate); 178 controller.startPrint(new TabPrinter(tab), mockPrintManagerD elegate);
183 } 179 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 @Override 253 @Override
258 public void run() { 254 public void run() {
259 controller.onFinish(); 255 controller.onFinish();
260 } 256 }
261 }); 257 });
262 } catch (Throwable e) { 258 } catch (Throwable e) {
263 fail("Error on calling onFinish of PrintingControllerImpl " + e); 259 fail("Error on calling onFinish of PrintingControllerImpl " + e);
264 } 260 }
265 } 261 }
266 } 262 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698