Commit 5620e165 authored by Maggie Cai's avatar Maggie Cai Committed by Commit Bot

[IntentHandling] Add browser tests to test pushstate and reload.

This CL adds 3 browser tests for intent picker:
1. If the website call pushstate on page loaded, with same URL, the
intent picker should work as normal.
2. If call pushstate to a different URL, the intent picker should check
with the new URL and update the visibility status accordingly.
3. If we reload a page after install an app that can be handle by that
page, we should be able to see intent picker icon after reload.

BUG=853604

Change-Id: I8fe9f13b6d21e691f382fedcd4170729bc35c0c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2546679Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Maggie Cai <mxcai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828983}
parent 20d9ad23
...@@ -128,6 +128,12 @@ class IntentPickerBubbleView : public LocationBarBubbleDelegateView { ...@@ -128,6 +128,12 @@ class IntentPickerBubbleView : public LocationBarBubbleDelegateView {
DismissBubble); DismissBubble);
FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewBrowserTestChromeOS, FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewBrowserTestChromeOS,
ShowBubbleTwice); ShowBubbleTwice);
FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewBrowserTestChromeOS,
PushStateLoadingTest);
FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewBrowserTestChromeOS,
PushStateURLChangeTest);
FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewBrowserTestChromeOS,
ReloadAfterInstall);
static std::unique_ptr<IntentPickerBubbleView> CreateBubbleViewForTesting( static std::unique_ptr<IntentPickerBubbleView> CreateBubbleViewForTesting(
views::View* anchor_view, views::View* anchor_view,
......
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
#include "components/services/app_service/public/cpp/intent_util.h" #include "components/services/app_service/public/cpp/intent_util.h"
#include "components/services/app_service/public/mojom/types.mojom.h" #include "components/services/app_service/public/mojom/types.mojom.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "content/public/test/test_navigation_observer.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/widget/any_widget_observer.h" #include "ui/views/widget/any_widget_observer.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -453,3 +455,134 @@ IN_PROC_BROWSER_TEST_F(IntentPickerBubbleViewBrowserTestChromeOS, ...@@ -453,3 +455,134 @@ IN_PROC_BROWSER_TEST_F(IntentPickerBubbleViewBrowserTestChromeOS,
EXPECT_TRUE(intent_picker_bubble()->GetVisible()); EXPECT_TRUE(intent_picker_bubble()->GetVisible());
EXPECT_EQ(2U, intent_picker_bubble()->GetScrollViewSize()); EXPECT_EQ(2U, intent_picker_bubble()->GetScrollViewSize());
} }
// Test that loading a page with pushState() call that doesn't change URL work
// as normal.
IN_PROC_BROWSER_TEST_F(IntentPickerBubbleViewBrowserTestChromeOS,
PushStateLoadingTest) {
ASSERT_TRUE(embedded_test_server()->Start());
const GURL test_url =
embedded_test_server()->GetURL("/intent_picker/push_state_test.html");
std::string app_name = "test_name";
auto app_id = AddArcAppWithIntentFilter(app_name, test_url);
PageActionIconView* intent_picker_view = GetIntentPickerIcon();
chrome::NewTab(browser());
ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
// Navigate from a link.
NavigateParams params(browser(), test_url,
ui::PageTransition::PAGE_TRANSITION_LINK);
views::NamedWidgetShownWaiter waiter(views::test::AnyWidgetTestPasskey{},
"IntentPickerBubbleView");
// Navigates and waits for loading to finish.
ui_test_utils::NavigateToURL(&params);
waiter.WaitIfNeededAndGet();
EXPECT_TRUE(intent_picker_view->GetVisible());
ASSERT_TRUE(intent_picker_bubble());
EXPECT_TRUE(intent_picker_bubble()->GetVisible());
EXPECT_EQ(1U, intent_picker_bubble()->GetScrollViewSize());
auto& app_info = intent_picker_bubble()->app_info_for_testing();
ASSERT_EQ(1U, app_info.size());
EXPECT_EQ(app_id, app_info[0].launch_name);
EXPECT_EQ(app_name, app_info[0].display_name);
// Launch the default selected app.
EXPECT_EQ(0U, launched_arc_apps().size());
intent_picker_bubble()->AcceptDialog();
WaitForAppService();
ASSERT_EQ(1U, launched_arc_apps().size());
EXPECT_EQ(app_name, launched_arc_apps()[0].activity->package_name);
EXPECT_EQ(test_url.spec(), launched_arc_apps()[0].intent->data);
}
// Test that loading a page with pushState() call that changes URL
// updates the intent picker view.
IN_PROC_BROWSER_TEST_F(IntentPickerBubbleViewBrowserTestChromeOS,
PushStateURLChangeTest) {
ASSERT_TRUE(embedded_test_server()->Start());
const GURL test_url =
embedded_test_server()->GetURL("/intent_picker/push_state_test.html");
std::string app_name = "test_name";
auto app_id = AddArcAppWithIntentFilter(app_name, test_url);
PageActionIconView* intent_picker_view = GetIntentPickerIcon();
chrome::NewTab(browser());
ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
// Navigate from a link.
NavigateParams params(browser(), test_url,
ui::PageTransition::PAGE_TRANSITION_LINK);
views::NamedWidgetShownWaiter waiter(views::test::AnyWidgetTestPasskey{},
"IntentPickerBubbleView");
// Navigates and waits for loading to finish.
ui_test_utils::NavigateToURL(&params);
waiter.WaitIfNeededAndGet();
EXPECT_TRUE(intent_picker_view->GetVisible());
ASSERT_TRUE(intent_picker_bubble());
EXPECT_TRUE(intent_picker_bubble()->GetVisible());
EXPECT_EQ(1U, intent_picker_bubble()->GetScrollViewSize());
auto& app_info = intent_picker_bubble()->app_info_for_testing();
ASSERT_EQ(1U, app_info.size());
EXPECT_EQ(app_id, app_info[0].launch_name);
EXPECT_EQ(app_name, app_info[0].display_name);
EXPECT_TRUE(intent_picker_bubble()->Close());
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
content::TestNavigationObserver observer(web_contents);
SimulateMouseClickOrTapElementWithId(web_contents, "push_to_new_url_button");
observer.WaitForNavigationFinished();
EXPECT_FALSE(intent_picker_view->GetVisible());
}
// Test that reload a page after app installation will show intent picker.
IN_PROC_BROWSER_TEST_F(IntentPickerBubbleViewBrowserTestChromeOS,
ReloadAfterInstall) {
GURL test_url("https://www.google.com/");
PageActionIconView* intent_picker_view = GetIntentPickerIcon();
chrome::NewTab(browser());
ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
// Navigate from a link.
NavigateParams params(browser(), test_url,
ui::PageTransition::PAGE_TRANSITION_LINK);
// Navigates and waits for loading to finish.
ui_test_utils::NavigateToURL(&params);
WaitForAppService();
EXPECT_FALSE(intent_picker_view->GetVisible());
std::string app_name = "test_name";
auto app_id = AddArcAppWithIntentFilter(app_name, test_url);
// Reload the page and the intent picker should show up.
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
content::TestNavigationObserver observer(web_contents);
chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB);
observer.WaitForNavigationFinished();
EXPECT_TRUE(intent_picker_view->GetVisible());
ClickIconToShowBubble();
EXPECT_EQ(1U, intent_picker_bubble()->GetScrollViewSize());
auto& app_info = intent_picker_bubble()->app_info_for_testing();
ASSERT_EQ(1U, app_info.size());
EXPECT_EQ(app_id, app_info[0].launch_name);
EXPECT_EQ(app_name, app_info[0].display_name);
// Launch the default selected app.
EXPECT_EQ(0U, launched_arc_apps().size());
intent_picker_bubble()->AcceptDialog();
WaitForAppService();
ASSERT_EQ(1U, launched_arc_apps().size());
EXPECT_EQ(app_name, launched_arc_apps()[0].activity->package_name);
EXPECT_EQ(test_url.spec(), launched_arc_apps()[0].intent->data);
}
<html>
<head>
<script>
window.onload = function() {
history.pushState("", "");
}
function pushToNewUrl() {
history.pushState("", "", "/newurl.html");
}
</script>
</head>
<body>
<button id="push_to_new_url_button" onclick="pushToNewUrl()">push to new url</button>
</body>
</html>
\ No newline at end of file
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