Fix PrintingControllerTest#testNormalPrintingFlow and reenable the test

Moves the creation of PrintingControllerImpl into the UI thread.
Before, it wasn't being created in the UI thread, and for some reason
PrintingControllerImpl#create wasn't failing its UI thread assertion.
It did start to fail for N4 with KitKat, so this fixes the issue and
re-enables the test.

BUG=330291

Review URL: https://codereview.chromium.org/123883002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243850 0039d316-1c4b-4281-b951-d872f2087c98
parent bf5c7d37
...@@ -13,16 +13,12 @@ import android.print.PrintDocumentInfo; ...@@ -13,16 +13,12 @@ import android.print.PrintDocumentInfo;
import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.LargeTest;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.TestFileUtil; import org.chromium.base.test.util.TestFileUtil;
import org.chromium.base.test.util.UrlUtils; import org.chromium.base.test.util.UrlUtils;
import org.chromium.chrome.browser.printing.TabPrinter; import org.chromium.chrome.browser.printing.TabPrinter;
import org.chromium.chrome.testshell.ChromiumTestShellTestBase; import org.chromium.chrome.testshell.ChromiumTestShellTestBase;
import org.chromium.chrome.testshell.TestShellTab; import org.chromium.chrome.testshell.TestShellTab;
import org.chromium.printing.PrintDocumentAdapterWrapper;
import org.chromium.printing.PrintManagerDelegate;
import org.chromium.printing.PrintingControllerImpl;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -75,30 +71,18 @@ public class PrintingControllerTest extends ChromiumTestShellTestBase { ...@@ -75,30 +71,18 @@ public class PrintingControllerTest extends ChromiumTestShellTestBase {
* Test a basic printing flow by emulating the corresponding system calls to the printing * Test a basic printing flow by emulating the corresponding system calls to the printing
* controller: onStart, onLayout, onWrite, onFinish. Each one is called once, and in this * controller: onStart, onLayout, onWrite, onFinish. Each one is called once, and in this
* order, in the UI thread. * order, in the UI thread.
@LargeTest
@Feature({"Printing"})
crbug.com/330291
*/ */
@DisabledTest @LargeTest
@Feature({"Printing"})
public void testNormalPrintingFlow() throws Throwable { public void testNormalPrintingFlow() throws Throwable {
if (!ApiCompatibilityUtils.isPrintingSupported()) return; if (!ApiCompatibilityUtils.isPrintingSupported()) return;
final TestShellTab currentTab = launchChromiumTestShellWithUrl(URL).getActiveTab(); final TestShellTab currentTab = launchChromiumTestShellWithUrl(URL).getActiveTab();
assertTrue(waitForActiveShellToBeDoneLoading()); assertTrue(waitForActiveShellToBeDoneLoading());
final PrintManagerDelegate mockPrintManagerDelegate = new PrintManagerDelegate() { final PrintingControllerImpl printingController = createControllerOnUiThread();
@Override
public void print(String printJobName,
PrintDocumentAdapter documentAdapter,
PrintAttributes attributes) {
// Do nothing, as we will emulate the framework call sequence within the test.
}
};
final PrintingControllerImpl printingController =
(PrintingControllerImpl) PrintingControllerImpl.create(mockPrintManagerDelegate,
new PrintDocumentAdapterWrapper(), PRINT_JOB_NAME);
startController(printingController, currentTab); startControllerOnUiThread(printingController, currentTab);
// {@link PrintDocumentAdapter#onStart} is always called first. // {@link PrintDocumentAdapter#onStart} is always called first.
callStartOnUiThread(printingController); callStartOnUiThread(printingController);
...@@ -156,7 +140,39 @@ public class PrintingControllerTest extends ChromiumTestShellTestBase { ...@@ -156,7 +140,39 @@ public class PrintingControllerTest extends ChromiumTestShellTestBase {
} }
private void startController(final PrintingControllerImpl controller, final TestShellTab tab) { private PrintingControllerImpl createControllerOnUiThread() {
try {
final PrintManagerDelegate mockPrintManagerDelegate = new PrintManagerDelegate() {
@Override
public void print(String printJobName,
PrintDocumentAdapter documentAdapter,
PrintAttributes attributes) {
// Do nothing, as we will emulate the framework call sequence within the test.
}
};
final FutureTask<PrintingControllerImpl> task =
new FutureTask<PrintingControllerImpl>(new Callable<PrintingControllerImpl>() {
@Override
public PrintingControllerImpl call() throws Exception {
return (PrintingControllerImpl) PrintingControllerImpl.create(
mockPrintManagerDelegate,
new PrintDocumentAdapterWrapper(),
PRINT_JOB_NAME);
}
});
runTestOnUiThread(task);
PrintingControllerImpl result = task.get(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
return result;
} catch (Throwable e) {
fail("Error on creating PrintingControllerImpl on the UI thread: " + e);
}
return null;
}
private void startControllerOnUiThread(final PrintingControllerImpl controller,
final TestShellTab tab) {
try { try {
runTestOnUiThread(new Runnable() { runTestOnUiThread(new Runnable() {
@Override @Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment