Skip to content

Commit

Permalink
system-web-app: update link capture test expectations for LacrosOnly
Browse files Browse the repository at this point in the history
This CL updates SWA link capture test expectations to prepare for
WebAppsCrosapi flag removal.

Fixed: b/287167145
Change-Id: Ia3786ff2b7f50d0cbcef6e9d55df15b687f5c11a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4617697
Reviewed-by: Georg Neis <neis@chromium.org>
Commit-Queue: Jiewei Qian <qjw@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1159446}
  • Loading branch information
wacky6 authored and Chromium LUCI CQ committed Jun 19, 2023
1 parent 7efd74d commit 3575da7
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,13 @@ class SystemWebAppDelegate {
// If false, this app will be hidden from the Chrome OS search.
virtual bool ShouldShowInSearch() const;

// If true, navigations (e.g. Omnibox URL, anchor link) to this app
// will open in the app's window instead of the navigation's context (e.g.
// browser tab).
// If true, in Ash browser, navigations (e.g. Omnibox URL, anchor link) to
// this app will open in the app's window instead of the navigation's context
// (e.g. browser tab).
//
// This feature isn't applicable to Lacros browser. If you need navigations in
// Lacros to launch the app, use crosapi URL handler by adding the app's URL
// to `ChromeWebUIControllerFactory::GetListOfAcceptableURLs()`.
virtual bool ShouldCaptureNavigations() const;

// If false, the app will non-resizeable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ class SystemWebAppLinkCaptureBrowserTest
}
~SystemWebAppLinkCaptureBrowserTest() override = default;

bool IsLacrosOnly() {
return GetParam().crosapi_state == TestProfileParam::CrosapiParam::kEnabled;
}

content::WebContents* CreateInitiatingWebContents() {
if (IsLacrosOnly()) {
// Ash can only have app windows, launch the helper app.
return LaunchApp(kInitiatingAppType);
} else {
// Ash can have ordinary tabbed browser windows.
GURL kInitiatingChromeUrl = GURL(chrome::kChromeUIAboutURL);
NavigateToURLAndWait(browser(), kInitiatingChromeUrl);
EXPECT_EQ(kInitiatingChromeUrl, browser()
->tab_strip_model()
->GetActiveWebContents()
->GetLastCommittedURL());
return browser()->tab_strip_model()->GetActiveWebContents();
}
}

protected:
Browser* CreateIncognitoBrowser() {
Browser* incognito = Browser::Create(Browser::CreateParams(
Expand All @@ -106,6 +126,12 @@ class SystemWebAppLinkCaptureBrowserTest

IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest,
OmniboxTypeURLAndNavigate) {
if (IsLacrosOnly()) {
GTEST_SKIP() << "In LacrosOnly mode, Ash can't create browser windows with "
"Omnibox. Because users can't interact with Omnibox, "
"there's no need to test this.";
}

WaitForTestSystemAppInstall();

content::TestNavigationObserver observer(GetStartUrl());
Expand All @@ -123,6 +149,12 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest,
}

IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest, OmniboxPasteAndGo) {
if (IsLacrosOnly()) {
GTEST_SKIP() << "In LacrosOnly mode, Ash can't create browser windows "
"with Omnibox. Because users can't interact with "
"Omnibox, there's no need to test this.";
}

WaitForTestSystemAppInstall();
OmniboxEditModel* model =
browser()->window()->GetLocationBar()->GetOmniboxView()->model();
Expand All @@ -142,20 +174,11 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest, OmniboxPasteAndGo) {
}

IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest, AnchorLinkClick) {
// TODO(b/287167145): Fix the test and remove this.
if (GetParam().crosapi_state == TestProfileParam::CrosapiParam::kEnabled) {
GTEST_SKIP()
<< "Skipping test body for CrosapiParam::kEnabled, see b/287167145.";
}

WaitForTestSystemAppInstall();

GURL kInitiatingChromeUrl = GURL(chrome::kChromeUIAboutURL);
NavigateToURLAndWait(browser(), kInitiatingChromeUrl);
EXPECT_EQ(kInitiatingChromeUrl, browser()
->tab_strip_model()
->GetActiveWebContents()
->GetLastCommittedURL());
content::WebContents* initiating_web_contents = CreateInitiatingWebContents();
const GURL& initiating_url = initiating_web_contents->GetLastCommittedURL();
size_t starting_browser_count = chrome::GetTotalBrowserCount();

const std::string kAnchorTargets[] = {"", "_blank", "_self"};
const std::string kAnchorRelValues[] = {"", "noreferrer", "noopener",
Expand All @@ -168,7 +191,7 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest, AnchorLinkClick) {
content::TestNavigationObserver observer(GetStartUrl());
observer.StartWatchingNewWebContents();
EXPECT_TRUE(content::ExecJs(
browser()->tab_strip_model()->GetActiveWebContents(),
initiating_web_contents,
content::JsReplace("{"
" let el = document.createElement('a');"
" el.href = $1;"
Expand All @@ -185,27 +208,25 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest, AnchorLinkClick) {
FindSystemWebAppBrowser(browser()->profile(), GetAppType());
EXPECT_TRUE(app_browser);
ui_test_utils::BrowserActivationWaiter(app_browser).WaitForActivation();
EXPECT_EQ(2U, chrome::GetTotalBrowserCount());
EXPECT_EQ(1 + starting_browser_count, chrome::GetTotalBrowserCount());
EXPECT_EQ(Browser::TYPE_APP, app_browser->type());
EXPECT_FALSE(app_browser->app_controller()->ShouldShowCustomTabBar());
app_browser->window()->Close();
ui_test_utils::WaitForBrowserToClose(app_browser);

// Check the initiating browser window is intact.
EXPECT_EQ(kInitiatingChromeUrl, browser()
->tab_strip_model()
->GetActiveWebContents()
->GetLastCommittedURL());
// Check the initiating page is intact.
EXPECT_EQ(initiating_url, initiating_web_contents->GetLastCommittedURL());
}
}
}

IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest,
AnchorLinkContextMenuNewTab) {
// TODO(b/287167145): Fix the test and remove this.
if (GetParam().crosapi_state == TestProfileParam::CrosapiParam::kEnabled) {
GTEST_SKIP()
<< "Skipping test body for CrosapiParam::kEnabled, see b/287167145.";
if (IsLacrosOnly()) {
GTEST_SKIP() << "In LacrosOnly mode, Ash can't create browser windows "
"with Omnibox, and we don't show new tab option for links "
"to a different SWA in SWA browser windows. So it makes no "
"sense to test this.";
}

WaitForTestSystemAppInstall();
Expand Down Expand Up @@ -253,10 +274,11 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest,

IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest,
AnchorLinkContextMenuNewWindow) {
// TODO(b/287167145): Fix the test and remove this.
if (GetParam().crosapi_state == TestProfileParam::CrosapiParam::kEnabled) {
GTEST_SKIP()
<< "Skipping test body for CrosapiParam::kEnabled, see b/287167145.";
if (IsLacrosOnly()) {
GTEST_SKIP() << "In LacrosOnly mode, Ash can't create browser windows "
"with Omnibox, and we don't show new window option for "
"links to SWA in SWA browser windows. So it makes no sense "
"to test this.";
}

WaitForTestSystemAppInstall();
Expand Down Expand Up @@ -303,58 +325,37 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest,
}

IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest, ChangeLocationHref) {
// TODO(b/287167145): Fix the test and remove this.
if (GetParam().crosapi_state == TestProfileParam::CrosapiParam::kEnabled) {
GTEST_SKIP()
<< "Skipping test body for CrosapiParam::kEnabled, see b/287167145.";
}

WaitForTestSystemAppInstall();

GURL kInitiatingChromeUrl = GURL(chrome::kChromeUIAboutURL);
NavigateToURLAndWait(browser(), kInitiatingChromeUrl);
EXPECT_EQ(kInitiatingChromeUrl, browser()
->tab_strip_model()
->GetActiveWebContents()
->GetLastCommittedURL());
content::WebContents* initiating_web_contents = CreateInitiatingWebContents();
const GURL& initiating_url = initiating_web_contents->GetLastCommittedURL();
size_t starting_browser_count = chrome::GetTotalBrowserCount();

content::TestNavigationObserver observer(GetStartUrl());
observer.StartWatchingNewWebContents();
EXPECT_TRUE(
content::ExecJs(browser()->tab_strip_model()->GetActiveWebContents(),
content::ExecJs(initiating_web_contents,
content::JsReplace("location.href=$1;", GetStartUrl())));
observer.Wait();

Browser* app_browser =
FindSystemWebAppBrowser(browser()->profile(), GetAppType());
EXPECT_TRUE(app_browser);
ui_test_utils::BrowserActivationWaiter(app_browser).WaitForActivation();
EXPECT_EQ(2U, chrome::GetTotalBrowserCount());
EXPECT_EQ(1 + starting_browser_count, chrome::GetTotalBrowserCount());
EXPECT_EQ(Browser::TYPE_APP, app_browser->type());
EXPECT_FALSE(app_browser->app_controller()->ShouldShowCustomTabBar());

// Check the initiating browser window is intact.
EXPECT_EQ(kInitiatingChromeUrl, browser()
->tab_strip_model()
->GetActiveWebContents()
->GetLastCommittedURL());
EXPECT_EQ(initiating_url, initiating_web_contents->GetLastCommittedURL());
}

IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest, WindowOpen) {
// TODO(b/287167145): Fix the test and remove this.
if (GetParam().crosapi_state == TestProfileParam::CrosapiParam::kEnabled) {
GTEST_SKIP()
<< "Skipping test body for CrosapiParam::kEnabled, see b/287167145.";
}

WaitForTestSystemAppInstall();

GURL kInitiatingChromeUrl = GURL(chrome::kChromeUIAboutURL);
NavigateToURLAndWait(browser(), kInitiatingChromeUrl);
EXPECT_EQ(kInitiatingChromeUrl, browser()
->tab_strip_model()
->GetActiveWebContents()
->GetLastCommittedURL());
content::WebContents* initiating_web_contents = CreateInitiatingWebContents();
const GURL& initiating_url = initiating_web_contents->GetLastCommittedURL();
size_t starting_browser_count = chrome::GetTotalBrowserCount();

const std::string kWindowOpenTargets[] = {"", "_blank"};
const std::string kWindowOpenFeatures[] = {"", "noreferrer", "noopener",
Expand All @@ -367,7 +368,7 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest, WindowOpen) {
content::TestNavigationObserver observer(GetStartUrl());
observer.StartWatchingNewWebContents();
EXPECT_TRUE(
content::ExecJs(browser()->tab_strip_model()->GetActiveWebContents(),
content::ExecJs(initiating_web_contents,
content::JsReplace("window.open($1, $2, $3);",
GetStartUrl(), target, features)));
observer.Wait();
Expand All @@ -376,17 +377,14 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest, WindowOpen) {
FindSystemWebAppBrowser(browser()->profile(), GetAppType());
EXPECT_TRUE(app_browser);
ui_test_utils::BrowserActivationWaiter(app_browser).WaitForActivation();
EXPECT_EQ(2U, chrome::GetTotalBrowserCount());
EXPECT_EQ(1 + starting_browser_count, chrome::GetTotalBrowserCount());
EXPECT_EQ(Browser::TYPE_APP, app_browser->type());
EXPECT_FALSE(app_browser->app_controller()->ShouldShowCustomTabBar());
app_browser->window()->Close();
ui_test_utils::WaitForBrowserToClose(app_browser);

// Check the initiating browser window is intact.
EXPECT_EQ(kInitiatingChromeUrl, browser()
->tab_strip_model()
->GetActiveWebContents()
->GetLastCommittedURL());
EXPECT_EQ(initiating_url, initiating_web_contents->GetLastCommittedURL());
}
}
}
Expand Down Expand Up @@ -466,6 +464,12 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest,

IN_PROC_BROWSER_TEST_P(SystemWebAppLinkCaptureBrowserTest,
IncognitoBrowserOmniboxLinkCapture) {
if (IsLacrosOnly()) {
GTEST_SKIP() << "In LacrosOnly mode, Ash can't create browser windows with "
"Omnibox. Because users can't interact with Omnibox, "
"there's no need to test this.";
}

WaitForTestSystemAppInstall();
GURL start_url = GetStartUrl();

Expand Down

0 comments on commit 3575da7

Please sign in to comment.