Loading packages/PrintSpooler/tests/outofprocess/src/com/android/printspooler/outofprocess/tests/BasePrintTest.java +21 −11 Original line number Diff line number Diff line Loading @@ -16,6 +16,14 @@ package com.android.printspooler.outofprocess.tests; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import android.annotation.NonNull; import android.app.Instrumentation; import android.content.Context; Loading @@ -26,16 +34,19 @@ import android.print.PrintAttributes; import android.print.PrintDocumentAdapter; import android.print.PrintManager; import android.print.PrinterId; import com.android.printspooler.outofprocess.tests.mockservice.PrintServiceCallbacks; import com.android.printspooler.outofprocess.tests.mockservice.PrinterDiscoverySessionCallbacks; import com.android.printspooler.outofprocess.tests.mockservice.StubbablePrinterDiscoverySession; import android.printservice.CustomPrinterIconCallback; import android.printservice.PrintJob; import android.printservice.PrintService; import android.support.test.InstrumentationRegistry; import android.support.test.rule.ActivityTestRule; import android.support.test.uiautomator.UiDevice; import com.android.printspooler.outofprocess.tests.mockservice.PrintServiceCallbacks; import com.android.printspooler.outofprocess.tests.mockservice.PrinterDiscoverySessionCallbacks; import com.android.printspooler.outofprocess.tests.mockservice.StubbablePrinterDiscoverySession; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; import org.mockito.stubbing.Answer; Loading @@ -44,14 +55,6 @@ import java.io.FileInputStream; import java.io.IOException; import java.util.List; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; /** * This is the base class for print tests. */ Loading Loading @@ -99,6 +102,13 @@ abstract class BasePrintTest { .getTargetContext().getCacheDir().getPath()); } @Before public void unlockScreen() throws Exception { // Unlock screen. runShellCommand(getInstrumentation(), "input keyevent KEYCODE_WAKEUP"); runShellCommand(getInstrumentation(), "wm dismiss-keyguard"); } @After public void exitActivities() throws Exception { // Exit print spooler Loading packages/PrintSpooler/tests/outofprocess/src/com/android/printspooler/outofprocess/tests/WorkflowTest.java +8 −77 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.printspooler.outofprocess.tests; import static org.junit.Assert.assertNotNull; import android.graphics.pdf.PdfDocument; import android.os.Bundle; import android.os.CancellationSignal; Loading @@ -27,10 +29,6 @@ import android.print.PrintDocumentInfo; import android.print.PrinterCapabilitiesInfo; import android.print.PrinterId; import android.print.PrinterInfo; import com.android.printspooler.outofprocess.tests.mockservice.AddPrintersActivity; import com.android.printspooler.outofprocess.tests.mockservice.MockPrintService; import com.android.printspooler.outofprocess.tests.mockservice.PrinterDiscoverySessionCallbacks; import com.android.printspooler.outofprocess.tests.mockservice.StubbablePrinterDiscoverySession; import android.print.pdf.PrintedPdfDocument; import android.support.test.filters.LargeTest; import android.support.test.uiautomator.By; Loading @@ -39,13 +37,16 @@ import android.support.test.uiautomator.UiObjectNotFoundException; import android.support.test.uiautomator.UiSelector; import android.support.test.uiautomator.Until; import android.util.Log; import org.junit.AfterClass; import org.junit.BeforeClass; import com.android.printspooler.outofprocess.tests.mockservice.AddPrintersActivity; import com.android.printspooler.outofprocess.tests.mockservice.MockPrintService; import com.android.printspooler.outofprocess.tests.mockservice.PrinterDiscoverySessionCallbacks; import com.android.printspooler.outofprocess.tests.mockservice.StubbablePrinterDiscoverySession; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; Loading @@ -54,8 +55,6 @@ import java.util.List; import java.util.concurrent.TimeoutException; import java.util.function.Supplier; import static org.junit.Assert.assertNotNull; /** * Tests for the basic printing workflows */ Loading Loading @@ -101,74 +100,6 @@ public class WorkflowTest extends BasePrintTest { } } /** * Executes a shell command using shell user identity, and return the standard output in * string. * * @param cmd the command to run * * @return the standard output of the command */ private static String runShellCommand(String cmd) throws IOException { try (FileInputStream is = new ParcelFileDescriptor.AutoCloseInputStream( getInstrumentation().getUiAutomation().executeShellCommand(cmd))) { byte[] buf = new byte[64]; int bytesRead; StringBuilder stdout = new StringBuilder(); while ((bytesRead = is.read(buf)) != -1) { stdout.append(new String(buf, 0, bytesRead)); } return stdout.toString(); } } @BeforeClass public static void disableAnimations() throws Exception { try { sWindowAnimationScaleBefore = Float.parseFloat(runShellCommand( "settings get global window_animation_scale")); runShellCommand("settings put global window_animation_scale 0"); } catch (NumberFormatException e) { sWindowAnimationScaleBefore = Float.NaN; } try { sTransitionAnimationScaleBefore = Float.parseFloat(runShellCommand( "settings get global transition_animation_scale")); runShellCommand("settings put global transition_animation_scale 0"); } catch (NumberFormatException e) { sTransitionAnimationScaleBefore = Float.NaN; } try { sAnimatiorDurationScaleBefore = Float.parseFloat(runShellCommand( "settings get global animator_duration_scale")); runShellCommand("settings put global animator_duration_scale 0"); } catch (NumberFormatException e) { sAnimatiorDurationScaleBefore = Float.NaN; } } @AfterClass public static void enableAnimations() throws Exception { if (sWindowAnimationScaleBefore != Float.NaN) { runShellCommand( "settings put global window_animation_scale " + sWindowAnimationScaleBefore); } if (sTransitionAnimationScaleBefore != Float.NaN) { runShellCommand( "settings put global transition_animation_scale " + sTransitionAnimationScaleBefore); } if (sAnimatiorDurationScaleBefore != Float.NaN) { runShellCommand( "settings put global animator_duration_scale " + sAnimatiorDurationScaleBefore); } } /** Add a printer with a given name and supported mediasize to a session */ private void addPrinter(StubbablePrinterDiscoverySession session, String name, PrintAttributes.MediaSize mediaSize) { Loading Loading
packages/PrintSpooler/tests/outofprocess/src/com/android/printspooler/outofprocess/tests/BasePrintTest.java +21 −11 Original line number Diff line number Diff line Loading @@ -16,6 +16,14 @@ package com.android.printspooler.outofprocess.tests; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import android.annotation.NonNull; import android.app.Instrumentation; import android.content.Context; Loading @@ -26,16 +34,19 @@ import android.print.PrintAttributes; import android.print.PrintDocumentAdapter; import android.print.PrintManager; import android.print.PrinterId; import com.android.printspooler.outofprocess.tests.mockservice.PrintServiceCallbacks; import com.android.printspooler.outofprocess.tests.mockservice.PrinterDiscoverySessionCallbacks; import com.android.printspooler.outofprocess.tests.mockservice.StubbablePrinterDiscoverySession; import android.printservice.CustomPrinterIconCallback; import android.printservice.PrintJob; import android.printservice.PrintService; import android.support.test.InstrumentationRegistry; import android.support.test.rule.ActivityTestRule; import android.support.test.uiautomator.UiDevice; import com.android.printspooler.outofprocess.tests.mockservice.PrintServiceCallbacks; import com.android.printspooler.outofprocess.tests.mockservice.PrinterDiscoverySessionCallbacks; import com.android.printspooler.outofprocess.tests.mockservice.StubbablePrinterDiscoverySession; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; import org.mockito.stubbing.Answer; Loading @@ -44,14 +55,6 @@ import java.io.FileInputStream; import java.io.IOException; import java.util.List; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; /** * This is the base class for print tests. */ Loading Loading @@ -99,6 +102,13 @@ abstract class BasePrintTest { .getTargetContext().getCacheDir().getPath()); } @Before public void unlockScreen() throws Exception { // Unlock screen. runShellCommand(getInstrumentation(), "input keyevent KEYCODE_WAKEUP"); runShellCommand(getInstrumentation(), "wm dismiss-keyguard"); } @After public void exitActivities() throws Exception { // Exit print spooler Loading
packages/PrintSpooler/tests/outofprocess/src/com/android/printspooler/outofprocess/tests/WorkflowTest.java +8 −77 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.printspooler.outofprocess.tests; import static org.junit.Assert.assertNotNull; import android.graphics.pdf.PdfDocument; import android.os.Bundle; import android.os.CancellationSignal; Loading @@ -27,10 +29,6 @@ import android.print.PrintDocumentInfo; import android.print.PrinterCapabilitiesInfo; import android.print.PrinterId; import android.print.PrinterInfo; import com.android.printspooler.outofprocess.tests.mockservice.AddPrintersActivity; import com.android.printspooler.outofprocess.tests.mockservice.MockPrintService; import com.android.printspooler.outofprocess.tests.mockservice.PrinterDiscoverySessionCallbacks; import com.android.printspooler.outofprocess.tests.mockservice.StubbablePrinterDiscoverySession; import android.print.pdf.PrintedPdfDocument; import android.support.test.filters.LargeTest; import android.support.test.uiautomator.By; Loading @@ -39,13 +37,16 @@ import android.support.test.uiautomator.UiObjectNotFoundException; import android.support.test.uiautomator.UiSelector; import android.support.test.uiautomator.Until; import android.util.Log; import org.junit.AfterClass; import org.junit.BeforeClass; import com.android.printspooler.outofprocess.tests.mockservice.AddPrintersActivity; import com.android.printspooler.outofprocess.tests.mockservice.MockPrintService; import com.android.printspooler.outofprocess.tests.mockservice.PrinterDiscoverySessionCallbacks; import com.android.printspooler.outofprocess.tests.mockservice.StubbablePrinterDiscoverySession; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; Loading @@ -54,8 +55,6 @@ import java.util.List; import java.util.concurrent.TimeoutException; import java.util.function.Supplier; import static org.junit.Assert.assertNotNull; /** * Tests for the basic printing workflows */ Loading Loading @@ -101,74 +100,6 @@ public class WorkflowTest extends BasePrintTest { } } /** * Executes a shell command using shell user identity, and return the standard output in * string. * * @param cmd the command to run * * @return the standard output of the command */ private static String runShellCommand(String cmd) throws IOException { try (FileInputStream is = new ParcelFileDescriptor.AutoCloseInputStream( getInstrumentation().getUiAutomation().executeShellCommand(cmd))) { byte[] buf = new byte[64]; int bytesRead; StringBuilder stdout = new StringBuilder(); while ((bytesRead = is.read(buf)) != -1) { stdout.append(new String(buf, 0, bytesRead)); } return stdout.toString(); } } @BeforeClass public static void disableAnimations() throws Exception { try { sWindowAnimationScaleBefore = Float.parseFloat(runShellCommand( "settings get global window_animation_scale")); runShellCommand("settings put global window_animation_scale 0"); } catch (NumberFormatException e) { sWindowAnimationScaleBefore = Float.NaN; } try { sTransitionAnimationScaleBefore = Float.parseFloat(runShellCommand( "settings get global transition_animation_scale")); runShellCommand("settings put global transition_animation_scale 0"); } catch (NumberFormatException e) { sTransitionAnimationScaleBefore = Float.NaN; } try { sAnimatiorDurationScaleBefore = Float.parseFloat(runShellCommand( "settings get global animator_duration_scale")); runShellCommand("settings put global animator_duration_scale 0"); } catch (NumberFormatException e) { sAnimatiorDurationScaleBefore = Float.NaN; } } @AfterClass public static void enableAnimations() throws Exception { if (sWindowAnimationScaleBefore != Float.NaN) { runShellCommand( "settings put global window_animation_scale " + sWindowAnimationScaleBefore); } if (sTransitionAnimationScaleBefore != Float.NaN) { runShellCommand( "settings put global transition_animation_scale " + sTransitionAnimationScaleBefore); } if (sAnimatiorDurationScaleBefore != Float.NaN) { runShellCommand( "settings put global animator_duration_scale " + sAnimatiorDurationScaleBefore); } } /** Add a printer with a given name and supported mediasize to a session */ private void addPrinter(StubbablePrinterDiscoverySession session, String name, PrintAttributes.MediaSize mediaSize) { Loading