Commit 58a46950 authored by Glen Robertson's avatar Glen Robertson Committed by Commit Bot

desktop-pwas: Remove fake_app_banner_manager and use test_ABM instead.

Just moved all the methods across for now to ensure tests were not
affected by this cleanup change. Some duplication (now within TABM)
could be cleaned up in future.

In prep for making an ABM factory as suggested by bsep@ in
crrev.com/c/2075001

Change-Id: Idcaad639bcc270a7ed3cc1f77f88b0fd5f2366a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2082220
Commit-Queue: Glen Robertson <glenrob@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746196}
parent 683bcaa6
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/banners/app_banner_manager_browsertest_base.h" #include "chrome/browser/banners/app_banner_manager_browsertest_base.h"
#include "chrome/browser/banners/app_banner_manager_desktop.h" #include "chrome/browser/banners/app_banner_manager_desktop.h"
#include "chrome/browser/banners/app_banner_metrics.h" #include "chrome/browser/banners/app_banner_metrics.h"
#include "chrome/browser/banners/app_banner_settings_helper.h" #include "chrome/browser/banners/app_banner_settings_helper.h"
#include "chrome/browser/banners/test_app_banner_manager_desktop.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_command_controller.h" #include "chrome/browser/ui/browser_command_controller.h"
...@@ -35,78 +35,9 @@ ...@@ -35,78 +35,9 @@
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
namespace { namespace banners {
class FakeAppBannerManagerDesktop : public banners::AppBannerManagerDesktop { using State = AppBannerManager::State;
public:
explicit FakeAppBannerManagerDesktop(content::WebContents* web_contents)
: AppBannerManagerDesktop(web_contents) {
MigrateObserverListForTesting(web_contents);
}
static FakeAppBannerManagerDesktop* CreateForWebContents(
content::WebContents* web_contents) {
auto banner_manager =
std::make_unique<FakeAppBannerManagerDesktop>(web_contents);
banner_manager->MigrateObserverListForTesting(web_contents);
FakeAppBannerManagerDesktop* result = banner_manager.get();
web_contents->SetUserData(FakeAppBannerManagerDesktop::UserDataKey(),
std::move(banner_manager));
return result;
}
// Configures a callback to be invoked when the app banner flow finishes.
void PrepareDone(base::OnceClosure on_done) { on_done_ = std::move(on_done); }
State state() { return AppBannerManager::state(); }
void AwaitAppInstall() {
base::RunLoop loop;
on_install_ = loop.QuitClosure();
loop.Run();
}
protected:
void OnInstall(blink::mojom::DisplayMode display) override {
AppBannerManager::OnInstall(display);
if (on_install_)
std::move(on_install_).Run();
}
void OnFinished() {
if (on_done_) {
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
std::move(on_done_));
}
}
void DidFinishCreatingWebApp(const web_app::AppId& app_id,
web_app::InstallResultCode code) override {
AppBannerManagerDesktop::DidFinishCreatingWebApp(app_id, code);
OnFinished();
}
void UpdateState(AppBannerManager::State state) override {
AppBannerManager::UpdateState(state);
if (state == AppBannerManager::State::PENDING_ENGAGEMENT ||
state == AppBannerManager::State::PENDING_PROMPT ||
state == AppBannerManager::State::COMPLETE) {
OnFinished();
}
}
private:
base::OnceClosure on_done_;
base::OnceClosure on_install_;
DISALLOW_COPY_AND_ASSIGN(FakeAppBannerManagerDesktop);
};
} // anonymous namespace
using State = banners::AppBannerManager::State;
class AppBannerManagerDesktopBrowserTest class AppBannerManagerDesktopBrowserTest
: public AppBannerManagerBrowserTestBase { : public AppBannerManagerBrowserTestBase {
...@@ -135,7 +66,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest, ...@@ -135,7 +66,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest,
content::WebContents* web_contents = content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
auto* manager = auto* manager =
FakeAppBannerManagerDesktop::CreateForWebContents(web_contents); TestAppBannerManagerDesktop::CreateForWebContents(web_contents);
{ {
base::RunLoop run_loop; base::RunLoop run_loop;
...@@ -161,7 +92,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest, ...@@ -161,7 +92,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest,
content::TitleWatcher watcher(web_contents, title); content::TitleWatcher watcher(web_contents, title);
EXPECT_EQ(title, watcher.WaitAndGetTitle()); EXPECT_EQ(title, watcher.WaitAndGetTitle());
tester.ExpectUniqueSample(banners::kInstallDisplayModeHistogram, tester.ExpectUniqueSample(kInstallDisplayModeHistogram,
blink::mojom::DisplayMode::kStandalone, 1); blink::mojom::DisplayMode::kStandalone, 1);
} }
...@@ -171,7 +102,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest, ...@@ -171,7 +102,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest,
content::WebContents* web_contents = content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
auto* manager = auto* manager =
FakeAppBannerManagerDesktop::CreateForWebContents(web_contents); TestAppBannerManagerDesktop::CreateForWebContents(web_contents);
{ {
base::RunLoop run_loop; base::RunLoop run_loop;
...@@ -218,7 +149,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest, DestroyWebContents) { ...@@ -218,7 +149,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest, DestroyWebContents) {
content::WebContents* web_contents = content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
auto* manager = auto* manager =
FakeAppBannerManagerDesktop::CreateForWebContents(web_contents); TestAppBannerManagerDesktop::CreateForWebContents(web_contents);
{ {
base::RunLoop run_loop; base::RunLoop run_loop;
...@@ -260,8 +191,8 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest, ...@@ -260,8 +191,8 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest,
InstallPromptAfterUserMenuInstall) { InstallPromptAfterUserMenuInstall) {
base::HistogramTester tester; base::HistogramTester tester;
FakeAppBannerManagerDesktop* manager = TestAppBannerManagerDesktop* manager =
FakeAppBannerManagerDesktop::CreateForWebContents( TestAppBannerManagerDesktop::CreateForWebContents(
browser()->tab_strip_model()->GetActiveWebContents()); browser()->tab_strip_model()->GetActiveWebContents());
{ {
...@@ -283,7 +214,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest, ...@@ -283,7 +214,7 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest,
EXPECT_FALSE(manager->IsPromptAvailableForTesting()); EXPECT_FALSE(manager->IsPromptAvailableForTesting());
tester.ExpectUniqueSample(banners::kInstallDisplayModeHistogram, tester.ExpectUniqueSample(kInstallDisplayModeHistogram,
blink::mojom::DisplayMode::kMinimalUi, 1); blink::mojom::DisplayMode::kMinimalUi, 1);
} }
...@@ -291,8 +222,8 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest, ...@@ -291,8 +222,8 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest,
InstallPromptAfterUserOmniboxInstall) { InstallPromptAfterUserOmniboxInstall) {
base::HistogramTester tester; base::HistogramTester tester;
FakeAppBannerManagerDesktop* manager = TestAppBannerManagerDesktop* manager =
FakeAppBannerManagerDesktop::CreateForWebContents( TestAppBannerManagerDesktop::CreateForWebContents(
browser()->tab_strip_model()->GetActiveWebContents()); browser()->tab_strip_model()->GetActiveWebContents());
{ {
...@@ -316,14 +247,14 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest, ...@@ -316,14 +247,14 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest,
EXPECT_FALSE(manager->IsPromptAvailableForTesting()); EXPECT_FALSE(manager->IsPromptAvailableForTesting());
tester.ExpectUniqueSample(banners::kInstallDisplayModeHistogram, tester.ExpectUniqueSample(kInstallDisplayModeHistogram,
blink::mojom::DisplayMode::kFullscreen, 1); blink::mojom::DisplayMode::kFullscreen, 1);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest, IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest,
PolicyAppInstalled_NoPrompt) { PolicyAppInstalled_NoPrompt) {
FakeAppBannerManagerDesktop* manager = TestAppBannerManagerDesktop* manager =
FakeAppBannerManagerDesktop::CreateForWebContents( TestAppBannerManagerDesktop::CreateForWebContents(
browser()->tab_strip_model()->GetActiveWebContents()); browser()->tab_strip_model()->GetActiveWebContents());
web_app::ExternalInstallOptions options = web_app::ExternalInstallOptions options =
...@@ -341,7 +272,9 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest, ...@@ -341,7 +272,9 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest,
EXPECT_EQ(State::COMPLETE, manager->state()); EXPECT_EQ(State::COMPLETE, manager->state());
} }
EXPECT_EQ(banners::AppBannerManager::InstallableWebAppCheckResult::kNo, EXPECT_EQ(AppBannerManager::InstallableWebAppCheckResult::kNo,
manager->GetInstallableWebAppCheckResultForTesting()); manager->GetInstallableWebAppCheckResultForTesting());
EXPECT_FALSE(manager->IsPromptAvailableForTesting()); EXPECT_FALSE(manager->IsPromptAvailableForTesting());
} }
} // namespace banners
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <utility> #include <utility>
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/installable/installable_logging.h" #include "chrome/browser/installable/installable_logging.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -45,6 +46,20 @@ bool TestAppBannerManagerDesktop::WaitForInstallableCheck() { ...@@ -45,6 +46,20 @@ bool TestAppBannerManagerDesktop::WaitForInstallableCheck() {
return *installable_; return *installable_;
} }
void TestAppBannerManagerDesktop::PrepareDone(base::OnceClosure on_done) {
on_done_ = std::move(on_done);
}
AppBannerManager::State TestAppBannerManagerDesktop::state() {
return AppBannerManager::state();
}
void TestAppBannerManagerDesktop::AwaitAppInstall() {
base::RunLoop loop;
on_install_ = loop.QuitClosure();
loop.Run();
}
void TestAppBannerManagerDesktop::OnDidGetManifest( void TestAppBannerManagerDesktop::OnDidGetManifest(
const InstallableData& result) { const InstallableData& result) {
AppBannerManagerDesktop::OnDidGetManifest(result); AppBannerManagerDesktop::OnDidGetManifest(result);
...@@ -68,6 +83,29 @@ void TestAppBannerManagerDesktop::ResetCurrentPageData() { ...@@ -68,6 +83,29 @@ void TestAppBannerManagerDesktop::ResetCurrentPageData() {
std::move(tear_down_quit_closure_).Run(); std::move(tear_down_quit_closure_).Run();
} }
void TestAppBannerManagerDesktop::OnInstall(blink::mojom::DisplayMode display) {
AppBannerManager::OnInstall(display);
if (on_install_)
std::move(on_install_).Run();
}
void TestAppBannerManagerDesktop::DidFinishCreatingWebApp(
const web_app::AppId& app_id,
web_app::InstallResultCode code) {
AppBannerManagerDesktop::DidFinishCreatingWebApp(app_id, code);
OnFinished();
}
void TestAppBannerManagerDesktop::UpdateState(AppBannerManager::State state) {
AppBannerManager::UpdateState(state);
if (state == AppBannerManager::State::PENDING_ENGAGEMENT ||
state == AppBannerManager::State::PENDING_PROMPT ||
state == AppBannerManager::State::COMPLETE) {
OnFinished();
}
}
void TestAppBannerManagerDesktop::SetInstallable(bool installable) { void TestAppBannerManagerDesktop::SetInstallable(bool installable) {
DCHECK(!installable_.has_value()); DCHECK(!installable_.has_value());
installable_ = installable; installable_ = installable;
...@@ -75,4 +113,11 @@ void TestAppBannerManagerDesktop::SetInstallable(bool installable) { ...@@ -75,4 +113,11 @@ void TestAppBannerManagerDesktop::SetInstallable(bool installable) {
std::move(installable_quit_closure_).Run(); std::move(installable_quit_closure_).Run();
} }
void TestAppBannerManagerDesktop::OnFinished() {
if (on_done_) {
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
std::move(on_done_));
}
}
} // namespace banners } // namespace banners
...@@ -32,18 +32,37 @@ class TestAppBannerManagerDesktop : public AppBannerManagerDesktop { ...@@ -32,18 +32,37 @@ class TestAppBannerManagerDesktop : public AppBannerManagerDesktop {
// Returns whether the installable check passed. // Returns whether the installable check passed.
bool WaitForInstallableCheck(); bool WaitForInstallableCheck();
// Configures a callback to be invoked when the app banner flow finishes.
void PrepareDone(base::OnceClosure on_done);
// Returns the internal state of the AppBannerManager.
AppBannerManager::State state();
// Block until the current app has been installed.
void AwaitAppInstall();
// AppBannerManager: // AppBannerManager:
void OnDidGetManifest(const InstallableData& result) override; void OnDidGetManifest(const InstallableData& result) override;
void OnDidPerformInstallableWebAppCheck( void OnDidPerformInstallableWebAppCheck(
const InstallableData& result) override; const InstallableData& result) override;
void ResetCurrentPageData() override; void ResetCurrentPageData() override;
protected:
// AppBannerManager:
void OnInstall(blink::mojom::DisplayMode display) override;
void DidFinishCreatingWebApp(const web_app::AppId& app_id,
web_app::InstallResultCode code) override;
void UpdateState(AppBannerManager::State state) override;
private: private:
void SetInstallable(bool installable); void SetInstallable(bool installable);
void OnFinished();
base::Optional<bool> installable_; base::Optional<bool> installable_;
base::OnceClosure tear_down_quit_closure_; base::OnceClosure tear_down_quit_closure_;
base::OnceClosure installable_quit_closure_; base::OnceClosure installable_quit_closure_;
base::OnceClosure on_done_;
base::OnceClosure on_install_;
DISALLOW_COPY_AND_ASSIGN(TestAppBannerManagerDesktop); DISALLOW_COPY_AND_ASSIGN(TestAppBannerManagerDesktop);
}; };
......
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