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 { ...@@ -1239,6 +1239,12 @@ class PDFExtensionLinkClickTest : public PDFExtensionTest {
guest_contents_ = guest_contents; guest_contents_ = guest_contents;
} }
content::WebContents* GetWebContentsForInputRouting() {
return content::MimeHandlerViewMode::UsesCrossProcessFrame()
? guest_contents_
: GetActiveWebContents();
}
private: private:
WebContents* guest_contents_; WebContents* guest_contents_;
}; };
...@@ -1251,9 +1257,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, CtrlLeft) { ...@@ -1251,9 +1257,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, CtrlLeft) {
content::WindowedNotificationObserver observer( content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_TAB_ADDED, chrome::NOTIFICATION_TAB_ADDED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
content::SimulateMouseClickAt(web_contents, kDefaultKeyModifier, content::SimulateMouseClickAt(
blink::WebMouseEvent::Button::kLeft, GetWebContentsForInputRouting(), kDefaultKeyModifier,
GetLinkPosition()); blink::WebMouseEvent::Button::kLeft, GetLinkPosition());
observer.Wait(); observer.Wait();
int tab_count = browser()->tab_strip_model()->count(); int tab_count = browser()->tab_strip_model()->count();
...@@ -1279,7 +1285,7 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, Middle) { ...@@ -1279,7 +1285,7 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, Middle) {
content::WindowedNotificationObserver observer( content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_TAB_ADDED, chrome::NOTIFICATION_TAB_ADDED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
content::SimulateMouseClickAt(web_contents, 0, content::SimulateMouseClickAt(GetWebContentsForInputRouting(), 0,
blink::WebMouseEvent::Button::kMiddle, blink::WebMouseEvent::Button::kMiddle,
GetLinkPosition()); GetLinkPosition());
observer.Wait(); observer.Wait();
...@@ -1309,7 +1315,7 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, CtrlShiftLeft) { ...@@ -1309,7 +1315,7 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, CtrlShiftLeft) {
content::WindowedNotificationObserver observer( content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_TAB_ADDED, chrome::NOTIFICATION_TAB_ADDED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
content::SimulateMouseClickAt(web_contents, modifiers, content::SimulateMouseClickAt(GetWebContentsForInputRouting(), modifiers,
blink::WebMouseEvent::Button::kLeft, blink::WebMouseEvent::Button::kLeft,
GetLinkPosition()); GetLinkPosition());
observer.Wait(); observer.Wait();
...@@ -1332,9 +1338,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, ShiftMiddle) { ...@@ -1332,9 +1338,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, ShiftMiddle) {
content::WindowedNotificationObserver observer( content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_TAB_ADDED, chrome::NOTIFICATION_TAB_ADDED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
content::SimulateMouseClickAt(web_contents, blink::WebInputEvent::kShiftKey, content::SimulateMouseClickAt(
blink::WebMouseEvent::Button::kMiddle, GetWebContentsForInputRouting(), blink::WebInputEvent::kShiftKey,
GetLinkPosition()); blink::WebMouseEvent::Button::kMiddle, GetLinkPosition());
observer.Wait(); observer.Wait();
int tab_count = browser()->tab_strip_model()->count(); int tab_count = browser()->tab_strip_model()->count();
...@@ -1357,9 +1363,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, ShiftLeft) { ...@@ -1357,9 +1363,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, ShiftLeft) {
content::WindowedNotificationObserver observer( content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_BROWSER_OPENED, chrome::NOTIFICATION_BROWSER_OPENED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
content::SimulateMouseClickAt(web_contents, blink::WebInputEvent::kShiftKey, content::SimulateMouseClickAt(
blink::WebMouseEvent::Button::kLeft, GetWebContentsForInputRouting(), blink::WebInputEvent::kShiftKey,
GetLinkPosition()); blink::WebMouseEvent::Button::kLeft, GetLinkPosition());
observer.Wait(); observer.Wait();
ASSERT_EQ(2U, chrome::GetTotalBrowserCount()); ASSERT_EQ(2U, chrome::GetTotalBrowserCount());
...@@ -1403,9 +1409,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, OpenPDFWithReplaceState) { ...@@ -1403,9 +1409,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionLinkClickTest, OpenPDFWithReplaceState) {
content::WindowedNotificationObserver observer( content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_TAB_ADDED, chrome::NOTIFICATION_TAB_ADDED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
content::SimulateMouseClickAt(web_contents, kDefaultKeyModifier, content::SimulateMouseClickAt(
blink::WebMouseEvent::Button::kLeft, GetWebContentsForInputRouting(), kDefaultKeyModifier,
GetLinkPosition()); blink::WebMouseEvent::Button::kLeft, GetLinkPosition());
observer.Wait(); observer.Wait();
// We should have two tabs now. One with the PDF and the second for // We should have two tabs now. One with the PDF and the second for
......
...@@ -66,9 +66,14 @@ void MimeHandlerViewEmbedder::DidStartNavigation( ...@@ -66,9 +66,14 @@ void MimeHandlerViewEmbedder::DidStartNavigation(
content::NavigationHandle* handle) { content::NavigationHandle* handle) {
// This observer is created after the observed |frame_tree_node_id_| started // This observer is created after the observed |frame_tree_node_id_| started
// its navigation to the |resource_url|. If any new navigations start then // its navigation to the |resource_url|. If any new navigations start then
// we should stop now and do not create a MHVG. // we should stop now and do not create a MHVG. Same document navigations
if (handle->GetFrameTreeNodeId() == frame_tree_node_id_) // 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_); GetMimeHandlerViewEmbeddersMap()->erase(frame_tree_node_id_);
}
} }
void MimeHandlerViewEmbedder::ReadyToCommitNavigation( 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