OLD | NEW |
---|---|
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.printing; |
6 | 6 |
7 import android.annotation.TargetApi; | |
8 import android.os.Build; | |
7 import android.os.CancellationSignal; | 9 import android.os.CancellationSignal; |
8 import android.os.ParcelFileDescriptor; | 10 import android.os.ParcelFileDescriptor; |
9 import android.print.PageRange; | 11 import android.print.PageRange; |
10 import android.print.PrintAttributes; | 12 import android.print.PrintAttributes; |
11 import android.print.PrintDocumentAdapter; | 13 import android.print.PrintDocumentAdapter; |
12 import android.print.PrintDocumentInfo; | 14 import android.print.PrintDocumentInfo; |
13 import android.test.suitebuilder.annotation.LargeTest; | 15 import android.test.suitebuilder.annotation.LargeTest; |
14 | 16 |
15 import org.chromium.base.ApiCompatibilityUtils; | 17 import org.chromium.base.ApiCompatibilityUtils; |
16 import org.chromium.base.test.util.Feature; | 18 import org.chromium.base.test.util.Feature; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 | 67 |
66 @Override | 68 @Override |
67 public void onWriteCancelled() {} | 69 public void onWriteCancelled() {} |
68 } | 70 } |
69 | 71 |
70 /** | 72 /** |
71 * Test a basic printing flow by emulating the corresponding system calls to the printing | 73 * Test a basic printing flow by emulating the corresponding system calls to the printing |
72 * controller: onStart, onLayout, onWrite, onFinish. Each one is called onc e, and in this | 74 * controller: onStart, onLayout, onWrite, onFinish. Each one is called onc e, and in this |
73 * order, in the UI thread. | 75 * order, in the UI thread. |
74 */ | 76 */ |
77 @TargetApi(Build.VERSION_CODES.KITKAT) | |
75 @LargeTest | 78 @LargeTest |
76 @Feature({"Printing"}) | 79 @Feature({"Printing"}) |
77 public void testNormalPrintingFlow() throws Throwable { | 80 public void testNormalPrintingFlow() throws Throwable { |
78 if (!ApiCompatibilityUtils.isPrintingSupported()) return; | 81 if (!ApiCompatibilityUtils.isPrintingSupported()) return; |
79 | 82 |
80 final ChromeShellTab currentTab = launchChromeShellWithUrl(URL).getActiv eTab(); | 83 final ChromeShellTab currentTab = launchChromeShellWithUrl(URL).getActiv eTab(); |
81 assertTrue(waitForActiveShellToBeDoneLoading()); | 84 assertTrue(waitForActiveShellToBeDoneLoading()); |
82 | 85 |
83 final PrintingControllerImpl printingController = createControllerOnUiTh read(); | 86 final PrintingControllerImpl printingController = createControllerOnUiTh read(); |
84 | 87 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 @Override | 193 @Override |
191 public void run() { | 194 public void run() { |
192 controller.onStart(); | 195 controller.onStart(); |
193 } | 196 } |
194 }); | 197 }); |
195 } catch (Throwable e) { | 198 } catch (Throwable e) { |
196 fail("Error on calling onStart of PrintingControllerImpl " + e); | 199 fail("Error on calling onStart of PrintingControllerImpl " + e); |
197 } | 200 } |
198 } | 201 } |
199 | 202 |
203 @TargetApi(Build.VERSION_CODES.JELLY_BEAN) | |
aurimas (slooooooooow)
2014/08/12 02:47:55
What makes this Jelly Bean only method?
AKVT
2014/08/12 03:13:39
CancellationSignal is only available with JELLY_BE
| |
200 private void callLayoutOnUiThread( | 204 private void callLayoutOnUiThread( |
201 final PrintingControllerImpl controller, | 205 final PrintingControllerImpl controller, |
202 final PrintAttributes oldAttributes, | 206 final PrintAttributes oldAttributes, |
203 final PrintAttributes newAttributes, | 207 final PrintAttributes newAttributes, |
204 final PrintDocumentAdapterWrapper.LayoutResultCallbackWrapper layout ResultCallback) { | 208 final PrintDocumentAdapterWrapper.LayoutResultCallbackWrapper layout ResultCallback) { |
205 try { | 209 try { |
206 runTestOnUiThread(new Runnable() { | 210 runTestOnUiThread(new Runnable() { |
207 @Override | 211 @Override |
208 public void run() { | 212 public void run() { |
209 controller.onLayout( | 213 controller.onLayout( |
210 oldAttributes, | 214 oldAttributes, |
211 newAttributes, | 215 newAttributes, |
212 new CancellationSignal(), | 216 new CancellationSignal(), |
213 layoutResultCallback, | 217 layoutResultCallback, |
214 null); | 218 null); |
215 } | 219 } |
216 }); | 220 }); |
217 } catch (Throwable e) { | 221 } catch (Throwable e) { |
218 fail("Error on calling onLayout of PrintingControllerImpl " + e); | 222 fail("Error on calling onLayout of PrintingControllerImpl " + e); |
219 } | 223 } |
220 } | 224 } |
221 | 225 |
226 @TargetApi(Build.VERSION_CODES.KITKAT) | |
222 private void callWriteOnUiThread( | 227 private void callWriteOnUiThread( |
223 final PrintingControllerImpl controller, | 228 final PrintingControllerImpl controller, |
224 final ParcelFileDescriptor descriptor, | 229 final ParcelFileDescriptor descriptor, |
225 final FutureTask<Boolean> result) { | 230 final FutureTask<Boolean> result) { |
226 try { | 231 try { |
227 controller.onWrite( | 232 controller.onWrite( |
228 new PageRange[] {PageRange.ALL_PAGES}, | 233 new PageRange[] {PageRange.ALL_PAGES}, |
229 descriptor, | 234 descriptor, |
230 new CancellationSignal(), | 235 new CancellationSignal(), |
231 new WriteResultCallbackWrapperMock() { | 236 new WriteResultCallbackWrapperMock() { |
(...skipping 20 matching lines...) Expand all Loading... | |
252 @Override | 257 @Override |
253 public void run() { | 258 public void run() { |
254 controller.onFinish(); | 259 controller.onFinish(); |
255 } | 260 } |
256 }); | 261 }); |
257 } catch (Throwable e) { | 262 } catch (Throwable e) { |
258 fail("Error on calling onFinish of PrintingControllerImpl " + e); | 263 fail("Error on calling onFinish of PrintingControllerImpl " + e); |
259 } | 264 } |
260 } | 265 } |
261 } | 266 } |
OLD | NEW |