Skip to content

Commit

Permalink
[dpwa] Uses BrowserAddedWaiter to find the app_browser instead of usi…
Browse files Browse the repository at this point in the history
…ng last active one.

There is a flakiness issue when last active browser is used.
The last active browser may not guarantee that's the app browser.
Using the browser returned from BrowserAddedWaiter should solve this issue.

Bug: 1296825, 1297742
Change-Id: Ibfa6c807326e52028ed8ccd10c08a2c33c12e456
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3469822
Commit-Queue: Clifford Cheng <[email protected]>
Reviewed-by: Daniel Murphy <[email protected]>
Commit-Queue: Daniel Murphy <[email protected]>
Cr-Commit-Position: refs/heads/main@{#972604}
  • Loading branch information
Clifford Cheng authored and Chromium LUCI CQ committed Feb 17, 2022
1 parent 38b99bc commit d0430d4
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -761,16 +761,19 @@ void WebAppIntegrationTestDriver::LaunchFromMenuOption(
NavigateBrowser(site_mode);
absl::optional<AppState> app_state = GetAppBySiteMode(
before_state_change_action_state_.get(), profile(), site_mode);
ASSERT_TRUE(app_state);
auto app_id = app_state->id;

content::WindowedNotificationObserver app_loaded_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
BrowserAddedWaiter browser_added_waiter;
CHECK(chrome::ExecuteCommand(browser(), IDC_OPEN_IN_PWA_WINDOW));
browser_added_waiter.Wait();
app_loaded_observer.Wait();

app_browser_ = BrowserList::GetInstance()->GetLastActive();
app_browser_ = browser_added_waiter.browser_added();
active_app_id_ = app_id;

ASSERT_TRUE(AppBrowserController::IsForWebApp(app_browser(), active_app_id_));
ASSERT_EQ(GetBrowserWindowTitle(app_browser()), app_state->name);
AfterStateChangeAction();
Expand All @@ -781,11 +784,12 @@ void WebAppIntegrationTestDriver::LaunchFromShortcut(
BeforeStateChangeAction();
absl::optional<AppState> app_state = GetAppBySiteMode(
before_state_change_action_state_.get(), profile(), site_mode);
ASSERT_TRUE(app_state);
auto app_id = app_state->id;
content::WindowedNotificationObserver app_loaded_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
std::vector<Browser*> app_browsers;
BrowserAddedWaiter browser_added_waiter;

#if BUILDFLAG(IS_MAC)
auto* provider = GetProviderForProfile(profile());
Expand All @@ -804,13 +808,14 @@ void WebAppIntegrationTestDriver::LaunchFromShortcut(
command_line, base::FilePath(), chrome::startup::IsProcessStartup::kNo,
{profile(), StartupProfileMode::kBrowserWindow}, {}));
#endif
browser_added_waiter.Wait();
app_browser_ = browser_added_waiter.browser_added();
app_loaded_observer.Wait();
content::RunAllTasksUntilIdle();
app_browsers.push_back(BrowserList::GetInstance()->GetLastActive());

for (auto* app_browser : app_browsers) {
ASSERT_EQ(GetBrowserWindowTitle(app_browser), app_state->name);
}
ASSERT_EQ(app_browser()->app_controller()->app_id(), app_state->id);
ASSERT_EQ(GetBrowserWindowTitle(app_browser()), app_state->name);
active_app_id_ = app_id;
AfterStateChangeAction();
}

Expand Down

0 comments on commit d0430d4

Please sign in to comment.