[context menu] add print page test for empty space CM
chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java \ --gtest_filter=ContextMenuTest.testPrintPage Bug: 391719844 Test: tools/autotest.py -C out/android_x64/ \ Change-Id: If88bd2f4278be0b6117a373c6a431724686e0ca2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6482169 Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Sinan Sahin <sinansahin@google.com> Commit-Queue: Lei Zhang <thestig@chromium.org> Auto-Submit: Grace Cham <hscham@chromium.org> Reviewed-by: Benjamin Gordon <bmgordon@chromium.org> Cr-Commit-Position: refs/heads/main@{#1454276}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
67876c8a87
commit
0f5dbc42e6
chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu
printing/android/java/src/org/chromium/printing
@ -95,6 +95,9 @@ import org.chromium.content_public.browser.test.util.DOMUtils;
|
|||||||
import org.chromium.content_public.browser.test.util.TestTouchUtils;
|
import org.chromium.content_public.browser.test.util.TestTouchUtils;
|
||||||
import org.chromium.content_public.common.ContentFeatures;
|
import org.chromium.content_public.common.ContentFeatures;
|
||||||
import org.chromium.net.test.EmbeddedTestServer;
|
import org.chromium.net.test.EmbeddedTestServer;
|
||||||
|
import org.chromium.printing.Printable;
|
||||||
|
import org.chromium.printing.PrintingController;
|
||||||
|
import org.chromium.printing.PrintingControllerImpl;
|
||||||
import org.chromium.ui.base.Clipboard;
|
import org.chromium.ui.base.Clipboard;
|
||||||
import org.chromium.ui.base.DeviceFormFactor;
|
import org.chromium.ui.base.DeviceFormFactor;
|
||||||
import org.chromium.ui.mojom.MenuSourceType;
|
import org.chromium.ui.mojom.MenuSourceType;
|
||||||
@ -118,6 +121,7 @@ public class ContextMenuTest {
|
|||||||
|
|
||||||
@Mock private TabContextMenuItemDelegate mItemDelegate;
|
@Mock private TabContextMenuItemDelegate mItemDelegate;
|
||||||
@Mock private ShareDelegate mShareDelegate;
|
@Mock private ShareDelegate mShareDelegate;
|
||||||
|
@Mock private PrintingController mPrintingController;
|
||||||
@Mock private DataProtectionBridge.Natives mDataProtectionBridgeMock;
|
@Mock private DataProtectionBridge.Natives mDataProtectionBridgeMock;
|
||||||
|
|
||||||
@ClassRule
|
@ClassRule
|
||||||
@ -1192,6 +1196,31 @@ public class ContextMenuTest {
|
|||||||
chromeExtrasCaptor.getValue().saveLastUsed());
|
chromeExtrasCaptor.getValue().saveLastUsed());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@MediumTest
|
||||||
|
@Restriction(DeviceFormFactor.DESKTOP)
|
||||||
|
@EnableFeatures({ChromeFeatureList.CONTEXT_MENU_EMPTY_SPACE})
|
||||||
|
public void testPrintPage() throws Exception {
|
||||||
|
Tab tab = sDownloadTestRule.getActivity().getActivityTab();
|
||||||
|
ThreadUtils.runOnUiThreadBlocking(
|
||||||
|
// Set printing controller to use the mock instance.
|
||||||
|
() -> {
|
||||||
|
PrintingControllerImpl.setInstanceForTesting(mPrintingController);
|
||||||
|
});
|
||||||
|
|
||||||
|
ContextMenuUtils.selectContextMenuItemFromRightClick(
|
||||||
|
InstrumentationRegistry.getInstrumentation(),
|
||||||
|
sDownloadTestRule.getActivity(),
|
||||||
|
tab,
|
||||||
|
"testEmptySpace",
|
||||||
|
R.id.contextmenu_print_page);
|
||||||
|
|
||||||
|
// Check that the started print job has the same title as the current tab.
|
||||||
|
ArgumentCaptor<Printable> printableCaptor = ArgumentCaptor.forClass(Printable.class);
|
||||||
|
verify(mPrintingController).startPrint(printableCaptor.capture(), any());
|
||||||
|
Assert.assertEquals(tab.getTitle(), printableCaptor.getValue().getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(benwgold): Add more test coverage for histogram recording of other context menu types.
|
// TODO(benwgold): Add more test coverage for histogram recording of other context menu types.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,6 +16,7 @@ import android.print.PrintDocumentInfo;
|
|||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import org.chromium.base.Log;
|
import org.chromium.base.Log;
|
||||||
|
import org.chromium.base.ResettersForTesting;
|
||||||
import org.chromium.base.ThreadUtils;
|
import org.chromium.base.ThreadUtils;
|
||||||
import org.chromium.build.annotations.NullMarked;
|
import org.chromium.build.annotations.NullMarked;
|
||||||
import org.chromium.build.annotations.Nullable;
|
import org.chromium.build.annotations.Nullable;
|
||||||
@ -58,6 +59,8 @@ public class PrintingControllerImpl implements PrintingController, PdfGenerator
|
|||||||
/** The singleton instance for this class. */
|
/** The singleton instance for this class. */
|
||||||
@VisibleForTesting protected static @Nullable PrintingController sInstance;
|
@VisibleForTesting protected static @Nullable PrintingController sInstance;
|
||||||
|
|
||||||
|
private static @Nullable PrintingController sInstanceForTesting;
|
||||||
|
|
||||||
private @Nullable String mErrorMessage;
|
private @Nullable String mErrorMessage;
|
||||||
|
|
||||||
private int mRenderProcessId;
|
private int mRenderProcessId;
|
||||||
@ -103,6 +106,11 @@ public class PrintingControllerImpl implements PrintingController, PdfGenerator
|
|||||||
mPrintDocumentAdapterWrapper = new PrintDocumentAdapterWrapper(this);
|
mPrintDocumentAdapterWrapper = new PrintDocumentAdapterWrapper(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setInstanceForTesting(PrintingController instanceForTesting) {
|
||||||
|
sInstanceForTesting = instanceForTesting;
|
||||||
|
ResettersForTesting.register(() -> sInstanceForTesting = null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the singleton instance, lazily creating one if needed.
|
* Returns the singleton instance, lazily creating one if needed.
|
||||||
*
|
*
|
||||||
@ -111,6 +119,8 @@ public class PrintingControllerImpl implements PrintingController, PdfGenerator
|
|||||||
public static PrintingController getInstance() {
|
public static PrintingController getInstance() {
|
||||||
ThreadUtils.assertOnUiThread();
|
ThreadUtils.assertOnUiThread();
|
||||||
|
|
||||||
|
if (sInstanceForTesting != null) return sInstanceForTesting;
|
||||||
|
|
||||||
if (sInstance == null) {
|
if (sInstance == null) {
|
||||||
sInstance = new PrintingControllerImpl();
|
sInstance = new PrintingControllerImpl();
|
||||||
}
|
}
|
||||||
@ -152,6 +162,11 @@ public class PrintingControllerImpl implements PrintingController, PdfGenerator
|
|||||||
return mIsBusy;
|
return mIsBusy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
public @Nullable Printable getPrintable() {
|
||||||
|
return mPrintable;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPendingPrint(
|
public void setPendingPrint(
|
||||||
final Printable printable,
|
final Printable printable,
|
||||||
|
Reference in New Issue
Block a user