Commit 793e69bd authored by Ehsan Karamad's avatar Ehsan Karamad Committed by Commit Bot

[ MimeHandlerView ] Make PDF*LinkClickTest* pass

The tests use the old input targeting approach of sending events to the
embedder which does not work correctly when MHV is frame-based. This CL
makes sure that with frame-based MHV the input goes to the guest
directly.

Bug: 961786
Change-Id: I2b3b78a3db7dd5be3f5435c6babf3b647fa79839
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1611776Reviewed-by: default avatarJames MacLean <wjmaclean@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Ehsan Karamad <ekaramad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659687}
parent 1ba57576
......@@ -1239,6 +1239,12 @@ class PDFExtensionLinkClickTest : public PDFExtensionTest {
guest_contents_ = guest_contents;
}
content::WebContents* GetWebContentsForInputRouting() {
return content::MimeHandlerViewMode::UsesCrossProcessFrame()
? guest_contents_
: GetActiveWebContents();
}
private:
WebContents* guest_contents_;
};
......@@ -1251,9 +1257,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, CtrlLeft) {
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_TAB_ADDED,
content::NotificationService::AllSources());
content::SimulateMouseClickAt(web_contents, kDefaultKeyModifier,
blink::WebMouseEvent::Button::kLeft,
GetLinkPosition());
content::SimulateMouseClickAt(
GetWebContentsForInputRouting(), kDefaultKeyModifier,
blink::WebMouseEvent::Button::kLeft, GetLinkPosition());
observer.Wait();
int tab_count = browser()->tab_strip_model()->count();
......@@ -1279,7 +1285,7 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, Middle) {
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_TAB_ADDED,
content::NotificationService::AllSources());
content::SimulateMouseClickAt(web_contents, 0,
content::SimulateMouseClickAt(GetWebContentsForInputRouting(), 0,
blink::WebMouseEvent::Button::kMiddle,
GetLinkPosition());
observer.Wait();
......@@ -1309,7 +1315,7 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, CtrlShiftLeft) {
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_TAB_ADDED,
content::NotificationService::AllSources());
content::SimulateMouseClickAt(web_contents, modifiers,
content::SimulateMouseClickAt(GetWebContentsForInputRouting(), modifiers,
blink::WebMouseEvent::Button::kLeft,
GetLinkPosition());
observer.Wait();
......@@ -1332,9 +1338,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, ShiftMiddle) {
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_TAB_ADDED,
content::NotificationService::AllSources());
content::SimulateMouseClickAt(web_contents, blink::WebInputEvent::kShiftKey,
blink::WebMouseEvent::Button::kMiddle,
GetLinkPosition());
content::SimulateMouseClickAt(
GetWebContentsForInputRouting(), blink::WebInputEvent::kShiftKey,
blink::WebMouseEvent::Button::kMiddle, GetLinkPosition());
observer.Wait();
int tab_count = browser()->tab_strip_model()->count();
......@@ -1357,9 +1363,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, ShiftLeft) {
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_BROWSER_OPENED,
content::NotificationService::AllSources());
content::SimulateMouseClickAt(web_contents, blink::WebInputEvent::kShiftKey,
blink::WebMouseEvent::Button::kLeft,
GetLinkPosition());
content::SimulateMouseClickAt(
GetWebContentsForInputRouting(), blink::WebInputEvent::kShiftKey,
blink::WebMouseEvent::Button::kLeft, GetLinkPosition());
observer.Wait();
ASSERT_EQ(2U, chrome::GetTotalBrowserCount());
......@@ -1403,9 +1409,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, OpenPDFWithReplaceState) {
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_TAB_ADDED,
content::NotificationService::AllSources());
content::SimulateMouseClickAt(web_contents, kDefaultKeyModifier,
blink::WebMouseEvent::Button::kLeft,
GetLinkPosition());
content::SimulateMouseClickAt(
GetWebContentsForInputRouting(), kDefaultKeyModifier,
blink::WebMouseEvent::Button::kLeft, GetLinkPosition());
observer.Wait();
// We should have two tabs now. One with the PDF and the second for
......
......@@ -66,9 +66,14 @@ void MimeHandlerViewEmbedder::DidStartNavigation(
content::NavigationHandle* handle) {
// This observer is created after the observed |frame_tree_node_id_| started
// its navigation to the |resource_url|. If any new navigations start then
// we should stop now and do not create a MHVG.
if (handle->GetFrameTreeNodeId() == frame_tree_node_id_)
// we should stop now and do not create a MHVG. Same document navigations
// could occur for {replace,push}State among other reasons and should not
// lead to deleting the MVHE (e.g., the test
// PDFExtensionLinkClickTest.OpenPDFWithReplaceState reaches here).
if (handle->GetFrameTreeNodeId() == frame_tree_node_id_ &&
!handle->IsSameDocument()) {
GetMimeHandlerViewEmbeddersMap()->erase(frame_tree_node_id_);
}
}
void MimeHandlerViewEmbedder::ReadyToCommitNavigation(
......
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