[ntp modules] Add hide and restore behavior to Microsoft Auth module.
1. Sets up handler + mojo for the Microsoft Auth module.
2. Adds ability to hide module via its header and restore it via
a toast that appears in the bottom left corner of the NTP.
Logic to resurface the module after 12 hours will be addressed in
a follow up CL.
Change-Id: I38125a3ac6b729a3711c899589c5da372c6843f0
Bug: 377378212
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6055265
Code-Coverage: [email protected] <[email protected]>
Reviewed-by: Dominic Battré <[email protected]>
Reviewed-by: Joe Mason <[email protected]>
Commit-Queue: Paul Adedeji <[email protected]>
Reviewed-by: Riley Tatum <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1394450}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 509c398..360ded3 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -3814,6 +3814,8 @@
"new_tab_page/modules/safe_browsing/safe_browsing_handler.h",
"new_tab_page/modules/safe_browsing/safe_browsing_prefs.cc",
"new_tab_page/modules/safe_browsing/safe_browsing_prefs.h",
+ "new_tab_page/modules/v2/authentication/microsoft_auth_page_handler.cc",
+ "new_tab_page/modules/v2/authentication/microsoft_auth_page_handler.h",
"new_tab_page/modules/v2/calendar/calendar_fake_data_helper.cc",
"new_tab_page/modules/v2/calendar/calendar_fake_data_helper.h",
"new_tab_page/modules/v2/calendar/google_calendar_page_handler.cc",
@@ -8680,6 +8682,7 @@
"//chrome/browser/new_tab_page/chrome_colors:generate_colors_info",
"//chrome/browser/new_tab_page/modules/file_suggestion:mojo_bindings",
"//chrome/browser/new_tab_page/modules/safe_browsing:mojo_bindings",
+ "//chrome/browser/new_tab_page/modules/v2/authentication:mojo_bindings",
"//chrome/browser/new_tab_page/modules/v2/calendar:mojo_bindings",
"//chrome/browser/new_tab_page/modules/v2/most_relevant_tab_resumption:mojo_bindings",
"//chrome/browser/profile_resetter:profile_reset_report_proto",
diff --git a/chrome/browser/chrome_browser_interface_binders.cc b/chrome/browser/chrome_browser_interface_binders.cc
index 9569917..ace43cd 100644
--- a/chrome/browser/chrome_browser_interface_binders.cc
+++ b/chrome/browser/chrome_browser_interface_binders.cc
@@ -151,6 +151,7 @@
#else
#include "chrome/browser/badging/badge_manager.h"
#include "chrome/browser/new_tab_page/modules/file_suggestion/drive_suggestion.mojom.h"
+#include "chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth.mojom.h"
#include "chrome/browser/new_tab_page/modules/v2/calendar/google_calendar.mojom.h"
#include "chrome/browser/new_tab_page/modules/v2/calendar/outlook_calendar.mojom.h"
#include "chrome/browser/new_tab_page/modules/v2/most_relevant_tab_resumption/most_relevant_tab_resumption.mojom.h"
@@ -1147,6 +1148,13 @@
ntp::calendar::mojom::OutlookCalendarPageHandler, NewTabPageUI>(map);
}
+ if (base::FeatureList::IsEnabled(
+ ntp_features::kNtpMicrosoftAuthenticationModule)) {
+ RegisterWebUIControllerInterfaceBinder<
+ ntp::authentication::mojom::MicrosoftAuthPageHandler, NewTabPageUI>(
+ map);
+ }
+
#if BUILDFLAG(IS_CHROMEOS_ASH)
RegisterWebUIControllerInterfaceBinder<
ash::mojom::HidPreservingBluetoothStateController,
diff --git a/chrome/browser/new_tab_page/modules/v2/authentication/BUILD.gn b/chrome/browser/new_tab_page/modules/v2/authentication/BUILD.gn
new file mode 100644
index 0000000..32a371e
--- /dev/null
+++ b/chrome/browser/new_tab_page/modules/v2/authentication/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2024 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//mojo/public/tools/bindings/mojom.gni")
+
+mojom("mojo_bindings") {
+ sources = [ "microsoft_auth.mojom" ]
+ webui_module_path = "/"
+ public_deps = [ "//mojo/public/mojom/base" ]
+}
diff --git a/chrome/browser/new_tab_page/modules/v2/authentication/OWNERS b/chrome/browser/new_tab_page/modules/v2/authentication/OWNERS
new file mode 100644
index 0000000..08850f4
--- /dev/null
+++ b/chrome/browser/new_tab_page/modules/v2/authentication/OWNERS
@@ -0,0 +1,2 @@
+per-file *.mojom=set noparent
+per-file *.mojom=file://ipc/SECURITY_OWNERS
diff --git a/chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth.mojom b/chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth.mojom
new file mode 100644
index 0000000..a5403a1
--- /dev/null
+++ b/chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth.mojom
@@ -0,0 +1,14 @@
+// Copyright 2024 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+module ntp.authentication.mojom;
+
+// Browser-side handler for requests from
+// NTP Microsoft Authentication Module UI.
+interface MicrosoftAuthPageHandler {
+ // Dismisses module for fixed amount of time.
+ DismissModule();
+ // Restores the module immediately.
+ RestoreModule();
+};
diff --git a/chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth_page_handler.cc b/chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth_page_handler.cc
new file mode 100644
index 0000000..ed63d37
--- /dev/null
+++ b/chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth_page_handler.cc
@@ -0,0 +1,44 @@
+// Copyright 2024 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth_page_handler.h"
+
+#include "chrome/browser/profiles/profile.h"
+#include "components/prefs/pref_registry_simple.h"
+#include "components/prefs/pref_service.h"
+#include "components/search/ntp_features.h"
+
+namespace {
+
+const char kMicrosoftAuthLastDismissedTimePrefName[] =
+ "NewTabPage.MicrosoftAuthentication.LastDimissedTime";
+
+} // namespace
+
+// static
+void MicrosoftAuthPageHandler::RegisterProfilePrefs(
+ PrefRegistrySimple* registry) {
+ registry->RegisterTimePref(kMicrosoftAuthLastDismissedTimePrefName,
+ base::Time());
+}
+
+MicrosoftAuthPageHandler::MicrosoftAuthPageHandler(
+ mojo::PendingReceiver<ntp::authentication::mojom::MicrosoftAuthPageHandler>
+ handler,
+ Profile* profile)
+ : handler_(this, std::move(handler)),
+ profile_(profile),
+ pref_service_(profile_->GetPrefs()) {}
+
+MicrosoftAuthPageHandler::~MicrosoftAuthPageHandler() = default;
+
+void MicrosoftAuthPageHandler::DismissModule() {
+ // TODO(b:377378212): Resurface module after 12 hours.
+ pref_service_->SetTime(kMicrosoftAuthLastDismissedTimePrefName,
+ base::Time::Now());
+}
+
+void MicrosoftAuthPageHandler::RestoreModule() {
+ pref_service_->SetTime(kMicrosoftAuthLastDismissedTimePrefName, base::Time());
+}
diff --git a/chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth_page_handler.h b/chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth_page_handler.h
new file mode 100644
index 0000000..813691d3
--- /dev/null
+++ b/chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth_page_handler.h
@@ -0,0 +1,38 @@
+// Copyright 2024 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_NEW_TAB_PAGE_MODULES_V2_AUTHENTICATION_MICROSOFT_AUTH_PAGE_HANDLER_H_
+#define CHROME_BROWSER_NEW_TAB_PAGE_MODULES_V2_AUTHENTICATION_MICROSOFT_AUTH_PAGE_HANDLER_H_
+
+#include "base/memory/raw_ptr.h"
+#include "chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth.mojom.h"
+#include "mojo/public/cpp/bindings/pending_receiver.h"
+#include "mojo/public/cpp/bindings/receiver.h"
+
+class PrefRegistrySimple;
+class PrefService;
+class Profile;
+
+class MicrosoftAuthPageHandler
+ : public ntp::authentication::mojom::MicrosoftAuthPageHandler {
+ public:
+ explicit MicrosoftAuthPageHandler(
+ mojo::PendingReceiver<
+ ntp::authentication::mojom::MicrosoftAuthPageHandler> handler,
+ Profile* profile);
+ ~MicrosoftAuthPageHandler() override;
+
+ static void RegisterProfilePrefs(PrefRegistrySimple* registry);
+
+ // ntp::authentication::mojom::MicrosoftAuthPageHandler:
+ void DismissModule() override;
+ void RestoreModule() override;
+
+ private:
+ mojo::Receiver<ntp::authentication::mojom::MicrosoftAuthPageHandler> handler_;
+ raw_ptr<Profile> profile_;
+ raw_ptr<PrefService> pref_service_;
+};
+
+#endif // CHROME_BROWSER_NEW_TAB_PAGE_MODULES_V2_AUTHENTICATION_MICROSOFT_AUTH_PAGE_HANDLER_H_
diff --git a/chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth_page_handler_unittest.cc b/chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth_page_handler_unittest.cc
new file mode 100644
index 0000000..3c22d62
--- /dev/null
+++ b/chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth_page_handler_unittest.cc
@@ -0,0 +1,65 @@
+// Copyright 2024 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth_page_handler.h"
+
+#include "chrome/test/base/testing_profile.h"
+#include "components/prefs/pref_service.h"
+#include "components/search/ntp_features.h"
+#include "content/public/test/browser_task_environment.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class MicrosoftAuthPageHandlerTest : public testing::Test {
+ public:
+ MicrosoftAuthPageHandlerTest() {
+ feature_list_.InitWithFeatures(
+ /*enabled_features=*/{ntp_features::kNtpMicrosoftAuthenticationModule},
+ /*disabled_features=*/{});
+ profile_ = std::make_unique<TestingProfile>();
+ pref_service_ = profile_->GetPrefs();
+ }
+
+ void SetUp() override {
+ handler_ = std::make_unique<MicrosoftAuthPageHandler>(
+ mojo::PendingReceiver<
+ ntp::authentication::mojom::MicrosoftAuthPageHandler>(),
+ profile_.get());
+ }
+
+ void TearDown() override { handler_.reset(); }
+
+ MicrosoftAuthPageHandler& handler() { return *handler_; }
+ PrefService& pref_service() { return *pref_service_; }
+ TestingProfile& profile() { return *profile_; }
+ content::BrowserTaskEnvironment& task_environment() {
+ return task_environment_;
+ }
+
+ private:
+ // NOTE: The initialization order of these members matters.
+ content::BrowserTaskEnvironment task_environment_{
+ base::test::TaskEnvironment::TimeSource::MOCK_TIME};
+ base::test::ScopedFeatureList feature_list_;
+ std::unique_ptr<TestingProfile> profile_;
+ std::unique_ptr<MicrosoftAuthPageHandler> handler_;
+ raw_ptr<PrefService> pref_service_;
+};
+
+TEST_F(MicrosoftAuthPageHandlerTest, DismissAndRestoreModule) {
+ const char kMicrosoftAuthLastDismissedTimePrefName[] =
+ "NewTabPage.MicrosoftAuthentication.LastDimissedTime";
+
+ EXPECT_EQ(pref_service().GetTime(kMicrosoftAuthLastDismissedTimePrefName),
+ base::Time());
+
+ handler().DismissModule();
+
+ EXPECT_EQ(pref_service().GetTime(kMicrosoftAuthLastDismissedTimePrefName),
+ base::Time::Now());
+
+ handler().RestoreModule();
+
+ EXPECT_EQ(pref_service().GetTime(kMicrosoftAuthLastDismissedTimePrefName),
+ base::Time());
+}
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 39ec9e1..f2669c3 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -277,6 +277,7 @@
#include "chrome/browser/nearby_sharing/common/nearby_share_prefs.h"
#include "chrome/browser/new_tab_page/modules/file_suggestion/drive_service.h"
#include "chrome/browser/new_tab_page/modules/safe_browsing/safe_browsing_handler.h"
+#include "chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth_page_handler.h"
#include "chrome/browser/new_tab_page/modules/v2/calendar/google_calendar_page_handler.h"
#include "chrome/browser/new_tab_page/modules/v2/most_relevant_tab_resumption/most_relevant_tab_resumption_page_handler.h"
#include "chrome/browser/new_tab_page/promos/promo_service.h"
@@ -2172,6 +2173,7 @@
NtpCustomBackgroundService::RegisterProfilePrefs(registry);
media_router::RegisterAccessCodeProfilePrefs(registry);
media_router::RegisterProfilePrefs(registry);
+ MicrosoftAuthPageHandler::RegisterProfilePrefs(registry);
NewTabPageHandler::RegisterProfilePrefs(registry);
NewTabPageUI::RegisterProfilePrefs(registry);
ntp::SafeBrowsingHandler::RegisterProfilePrefs(registry);
diff --git a/chrome/browser/resources/new_tab_page/BUILD.gn b/chrome/browser/resources/new_tab_page/BUILD.gn
index 5a63caa..daa37f81 100644
--- a/chrome/browser/resources/new_tab_page/BUILD.gn
+++ b/chrome/browser/resources/new_tab_page/BUILD.gn
@@ -47,6 +47,7 @@
mojo_files_deps = [
"//chrome/browser/new_tab_page/modules/file_suggestion:mojo_bindings_ts__generator",
+ "//chrome/browser/new_tab_page/modules/v2/authentication:mojo_bindings_ts__generator",
"//chrome/browser/new_tab_page/modules/v2/calendar:mojo_bindings_ts__generator",
"//chrome/browser/new_tab_page/modules/v2/most_relevant_tab_resumption:mojo_bindings_ts__generator",
"//chrome/browser/ui/webui/new_tab_page:mojo_bindings_ts__generator",
@@ -57,6 +58,7 @@
"$root_gen_dir/chrome/browser/new_tab_page/modules/v2/calendar/calendar_data.mojom-webui.ts",
"$root_gen_dir/chrome/browser/new_tab_page/modules/v2/calendar/outlook_calendar.mojom-webui.ts",
"$root_gen_dir/chrome/browser/new_tab_page/modules/v2/calendar/google_calendar.mojom-webui.ts",
+ "$root_gen_dir/chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth.mojom-webui.ts",
"$root_gen_dir/chrome/browser/new_tab_page/modules/v2/most_relevant_tab_resumption/url_visit_types.mojom-webui.ts",
"$root_gen_dir/chrome/browser/new_tab_page/modules/v2/most_relevant_tab_resumption/most_relevant_tab_resumption.mojom-webui.ts",
"$root_gen_dir/chrome/browser/ui/webui/new_tab_page/new_tab_page.mojom-webui.ts",
diff --git a/chrome/browser/resources/new_tab_page/lazy_load.ts b/chrome/browser/resources/new_tab_page/lazy_load.ts
index a7c5dfe..e81f92d 100644
--- a/chrome/browser/resources/new_tab_page/lazy_load.ts
+++ b/chrome/browser/resources/new_tab_page/lazy_load.ts
@@ -27,6 +27,7 @@
export {ModuleRegistry} from './modules/module_registry.js';
export {ModuleWrapperElement} from './modules/module_wrapper.js';
export {microsoftAuthModuleDescriptor, MicrosoftAuthModuleElement} from './modules/v2/authentication/microsoft_auth_module.js';
+export {MicrosoftAuthProxyImpl} from './modules/v2/authentication/microsoft_auth_module_proxy.js';
export {CalendarElement} from './modules/v2/calendar/calendar.js';
export {CalendarEventElement} from './modules/v2/calendar/calendar_event.js';
export {CalendarAction} from './modules/v2/calendar/common.js';
diff --git a/chrome/browser/resources/new_tab_page/modules/modules.gni b/chrome/browser/resources/new_tab_page/modules/modules.gni
index 0a84760..047f49f 100644
--- a/chrome/browser/resources/new_tab_page/modules/modules.gni
+++ b/chrome/browser/resources/new_tab_page/modules/modules.gni
@@ -17,7 +17,8 @@
"modules/module_descriptor.ts",
"modules/module_descriptors.ts",
"modules/module_registry.ts",
- ] + calendar_v2_non_web_component_files +
+ ] + authentication_non_web_component_files +
+ calendar_v2_non_web_component_files +
file_suggestion_non_web_component_files +
most_relevant_tab_resumption_v2_non_web_component_files
diff --git a/chrome/browser/resources/new_tab_page/modules/v2/authentication/authentication.gni b/chrome/browser/resources/new_tab_page/modules/v2/authentication/authentication.gni
index 2dd569b..d8f3cc4 100644
--- a/chrome/browser/resources/new_tab_page/modules/v2/authentication/authentication.gni
+++ b/chrome/browser/resources/new_tab_page/modules/v2/authentication/authentication.gni
@@ -6,5 +6,9 @@
authentication_web_component_files =
[ "modules/v2/authentication/microsoft_auth_module.ts" ]
+# List of files that don't need to be passed to html_to_wrapper().
+authentication_non_web_component_files =
+ [ "modules/v2/authentication/microsoft_auth_module_proxy.ts" ]
+
authentication_css_files =
[ "modules/v2/authentication/microsoft_auth_module.css" ]
diff --git a/chrome/browser/resources/new_tab_page/modules/v2/authentication/microsoft_auth_module.ts b/chrome/browser/resources/new_tab_page/modules/v2/authentication/microsoft_auth_module.ts
index f59dbb9..5d169512 100644
--- a/chrome/browser/resources/new_tab_page/modules/v2/authentication/microsoft_auth_module.ts
+++ b/chrome/browser/resources/new_tab_page/modules/v2/authentication/microsoft_auth_module.ts
@@ -7,11 +7,14 @@
import {CrLitElement} from 'chrome://resources/lit/v3_0/lit.rollup.js';
import {I18nMixinLit, loadTimeData} from '../../../i18n_setup.js';
+import type {MicrosoftAuthPageHandlerRemote} from '../../../microsoft_auth.mojom-webui.js';
import {ModuleDescriptor} from '../../module_descriptor.js';
import type {MenuItem, ModuleHeaderElement} from '../module_header.js';
import {getCss} from './microsoft_auth_module.css.js';
import {getHtml} from './microsoft_auth_module.html.js';
+import {MicrosoftAuthProxyImpl} from './microsoft_auth_module_proxy.js';
+
export interface MicrosoftAuthModuleElement {
$: {
@@ -39,6 +42,13 @@
return getHtml.bind(this)();
}
+ private handler_: MicrosoftAuthPageHandlerRemote;
+
+ constructor() {
+ super();
+ this.handler_ = MicrosoftAuthProxyImpl.getInstance().handler;
+ }
+
protected getMenuItemGroups_(): MenuItem[][] {
return [
[
@@ -76,7 +86,17 @@
}
protected onDismissButtonClick_() {
- // TODO(crbug.com/377378212): Handle button click.
+ this.handler_.dismissModule();
+ this.dispatchEvent(new CustomEvent('dismiss-module-instance', {
+ bubbles: true,
+ composed: true,
+ detail: {
+ message: loadTimeData.getStringF(
+ 'dismissModuleToastMessage',
+ loadTimeData.getString('modulesMicrosoftAuthName')),
+ restoreCallback: () => this.handler_.restoreModule(),
+ },
+ }));
}
protected onSignInClick_() {
diff --git a/chrome/browser/resources/new_tab_page/modules/v2/authentication/microsoft_auth_module_proxy.ts b/chrome/browser/resources/new_tab_page/modules/v2/authentication/microsoft_auth_module_proxy.ts
new file mode 100644
index 0000000..6dc1715
--- /dev/null
+++ b/chrome/browser/resources/new_tab_page/modules/v2/authentication/microsoft_auth_module_proxy.ts
@@ -0,0 +1,39 @@
+// Copyright 2024 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import type {MicrosoftAuthPageHandlerRemote} from '../../../microsoft_auth.mojom-webui.js';
+import {MicrosoftAuthPageHandler} from '../../../microsoft_auth.mojom-webui.js';
+
+/**
+ * @fileoverview This file provides a singleton class that exposes the Mojo
+ * handler interface used for bidirectional communication between the page and
+ * the browser.
+ */
+
+export interface MicrosoftAuthProxy {
+ handler: MicrosoftAuthPageHandlerRemote;
+}
+
+export class MicrosoftAuthProxyImpl implements MicrosoftAuthProxy {
+ handler: MicrosoftAuthPageHandlerRemote;
+
+ constructor(handler: MicrosoftAuthPageHandlerRemote) {
+ this.handler = handler;
+ }
+
+ static getInstance(): MicrosoftAuthProxy {
+ if (instance) {
+ return instance;
+ }
+
+ const handler = MicrosoftAuthPageHandler.getRemote();
+ return instance = new MicrosoftAuthProxyImpl(handler);
+ }
+
+ static setInstance(obj: MicrosoftAuthProxy) {
+ instance = obj;
+ }
+}
+
+let instance: MicrosoftAuthProxy|null = null;
diff --git a/chrome/browser/resources/new_tab_page/new_tab_page.gni b/chrome/browser/resources/new_tab_page/new_tab_page.gni
index c94d5eaa..d276d8ec 100644
--- a/chrome/browser/resources/new_tab_page/new_tab_page.gni
+++ b/chrome/browser/resources/new_tab_page/new_tab_page.gni
@@ -52,9 +52,10 @@
"drive_suggestion.mojom-webui.js",
"file_suggestion.mojom-webui.js",
"google_calendar.mojom-webui.js",
- "outlook_calendar.mojom-webui.js",
- "new_tab_page.mojom-webui.js",
+ "microsoft_auth.mojom-webui.js",
"most_relevant_tab_resumption.mojom-webui.js",
+ "new_tab_page.mojom-webui.js",
+ "outlook_calendar.mojom-webui.js",
"url_visit_types.mojom-webui.js",
]
diff --git a/chrome/browser/ui/webui/new_tab_page/new_tab_page_ui.cc b/chrome/browser/ui/webui/new_tab_page/new_tab_page_ui.cc
index 9b73e5e..c3e0ea7 100644
--- a/chrome/browser/ui/webui/new_tab_page/new_tab_page_ui.cc
+++ b/chrome/browser/ui/webui/new_tab_page/new_tab_page_ui.cc
@@ -22,6 +22,7 @@
#include "chrome/browser/buildflags.h"
#include "chrome/browser/new_tab_page/feature_promo_helper/new_tab_page_feature_promo_helper.h"
#include "chrome/browser/new_tab_page/modules/file_suggestion/drive_suggestion_handler.h"
+#include "chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth_page_handler.h"
#include "chrome/browser/new_tab_page/modules/v2/calendar/google_calendar_page_handler.h"
#include "chrome/browser/new_tab_page/modules/v2/calendar/outlook_calendar_page_handler.h"
#include "chrome/browser/new_tab_page/modules/v2/most_relevant_tab_resumption/most_relevant_tab_resumption_page_handler.h"
@@ -704,6 +705,13 @@
}
void NewTabPageUI::BindInterface(
+ mojo::PendingReceiver<ntp::authentication::mojom::MicrosoftAuthPageHandler>
+ pending_page_handler) {
+ microsoft_auth_handler_ = std::make_unique<MicrosoftAuthPageHandler>(
+ std::move(pending_page_handler), profile_);
+}
+
+void NewTabPageUI::BindInterface(
mojo::PendingReceiver<page_image_service::mojom::PageImageServiceHandler>
pending_page_handler) {
base::WeakPtr<page_image_service::ImageService> image_service_weak;
diff --git a/chrome/browser/ui/webui/new_tab_page/new_tab_page_ui.h b/chrome/browser/ui/webui/new_tab_page/new_tab_page_ui.h
index 04ee3ef..176c3704 100644
--- a/chrome/browser/ui/webui/new_tab_page/new_tab_page_ui.h
+++ b/chrome/browser/ui/webui/new_tab_page/new_tab_page_ui.h
@@ -13,6 +13,7 @@
#include "base/time/time.h"
#include "chrome/browser/new_tab_page/modules/file_suggestion/drive_suggestion.mojom.h"
#include "chrome/browser/new_tab_page/modules/new_tab_page_modules.h"
+#include "chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth.mojom.h"
#include "chrome/browser/new_tab_page/modules/v2/calendar/google_calendar.mojom.h"
#include "chrome/browser/new_tab_page/modules/v2/calendar/outlook_calendar.mojom.h"
#include "chrome/browser/new_tab_page/modules/v2/most_relevant_tab_resumption/most_relevant_tab_resumption.mojom.h"
@@ -73,6 +74,7 @@
class GoogleCalendarPageHandler;
class OutlookCalendarPageHandler;
class GURL;
+class MicrosoftAuthPageHandler;
class MostRelevantTabResumptionPageHandler;
class MostVisitedHandler;
class NewTabPageHandler;
@@ -176,6 +178,13 @@
mojo::PendingReceiver<ntp::calendar::mojom::OutlookCalendarPageHandler>
pending_receiver);
+ // Instantiates the implementor of
+ // npt::authentication::mojom::MicrosoftAuthPageHandler mojo
+ // interface passing the pending receiver that will be internally bound.
+ void BindInterface(mojo::PendingReceiver<
+ ntp::authentication::mojom::MicrosoftAuthPageHandler>
+ pending_receiver);
+
#if !defined(OFFICIAL_BUILD)
// Instantiates the implementor of the foo::mojom::FooHandler mojo interface
// passing the pending receiver that will be internally bound.
@@ -280,8 +289,9 @@
const std::vector<ntp::ModuleIdDetail> module_id_details_;
// Mojo implementations for modules:
- std::unique_ptr<GoogleCalendarPageHandler> google_calendar_handler_;
std::unique_ptr<DriveSuggestionHandler> drive_handler_;
+ std::unique_ptr<GoogleCalendarPageHandler> google_calendar_handler_;
+ std::unique_ptr<MicrosoftAuthPageHandler> microsoft_auth_handler_;
std::unique_ptr<OutlookCalendarPageHandler> outlook_calendar_handler_;
PrefChangeRegistrar pref_change_registrar_;
diff --git a/chrome/test/BUILD.gn b/chrome/test/BUILD.gn
index aa2beb2c..6d55b3a 100644
--- a/chrome/test/BUILD.gn
+++ b/chrome/test/BUILD.gn
@@ -7841,6 +7841,7 @@
"../browser/new_tab_page/modules/safe_browsing/safe_browsing_handler_unittest.cc",
"../browser/new_tab_page/modules/test_support.cc",
"../browser/new_tab_page/modules/test_support.h",
+ "../browser/new_tab_page/modules/v2/authentication/microsoft_auth_page_handler_unittest.cc",
"../browser/new_tab_page/modules/v2/calendar/google_calendar_page_handler_unittest.cc",
"../browser/new_tab_page/modules/v2/calendar/outlook_calendar_page_handler_unittest.cc",
"../browser/new_tab_page/modules/v2/most_relevant_tab_resumption/most_relevant_tab_resumption_page_handler_unittest.cc",
@@ -7896,6 +7897,7 @@
"//chrome/browser/media/webrtc:test_support",
"//chrome/browser/metrics/desktop_session_duration",
"//chrome/browser/new_tab_page/chrome_colors",
+ "//chrome/browser/new_tab_page/modules/v2/authentication:mojo_bindings",
"//chrome/browser/new_tab_page/modules/v2/calendar:mojo_bindings",
"//chrome/browser/new_tab_page/modules/v2/most_relevant_tab_resumption:mojo_bindings",
"//chrome/browser/profile_resetter:fake_profile_resetter",
diff --git a/chrome/test/data/webui/new_tab_page/modules/v2/authentication/microsoft_auth_module_test.ts b/chrome/test/data/webui/new_tab_page/modules/v2/authentication/microsoft_auth_module_test.ts
index 4f202dfd..9a02dce 100644
--- a/chrome/test/data/webui/new_tab_page/modules/v2/authentication/microsoft_auth_module_test.ts
+++ b/chrome/test/data/webui/new_tab_page/modules/v2/authentication/microsoft_auth_module_test.ts
@@ -2,27 +2,37 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import type {DisableModuleEvent, MicrosoftAuthModuleElement} from 'chrome://new-tab-page/lazy_load.js';
-import {microsoftAuthModuleDescriptor} from 'chrome://new-tab-page/lazy_load.js';
+import type {DisableModuleEvent, DismissModuleInstanceEvent, MicrosoftAuthModuleElement} from 'chrome://new-tab-page/lazy_load.js';
+import {microsoftAuthModuleDescriptor, MicrosoftAuthProxyImpl} from 'chrome://new-tab-page/lazy_load.js';
+import {MicrosoftAuthPageHandlerRemote} from 'chrome://new-tab-page/microsoft_auth.mojom-webui.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.js';
import {assertEquals, assertTrue} from 'chrome://webui-test/chai_assert.js';
+import type {TestMock} from 'chrome://webui-test/test_mock.js';
import {eventToPromise, microtasksFinished} from 'chrome://webui-test/test_util.js';
+import {installMock} from '../../../test_support.js';
+
suite('MicrosoftAuthModule', () => {
+ let handler: TestMock<MicrosoftAuthPageHandlerRemote>;
+ let microsoftAuthModule: MicrosoftAuthModuleElement;
+ const modulesMicrosoftAuthName = 'Microsoft Authentication';
+
setup(async () => {
document.body.innerHTML = window.trustedTypes!.emptyHTML;
+ loadTimeData.overrideValues(
+ {modulesMicrosoftAuthName: modulesMicrosoftAuthName});
+ handler = installMock(
+ MicrosoftAuthPageHandlerRemote,
+ mock => MicrosoftAuthProxyImpl.setInstance(
+ new MicrosoftAuthProxyImpl(mock)));
+ microsoftAuthModule = await microsoftAuthModuleDescriptor.initialize(0) as
+ MicrosoftAuthModuleElement;
+ assertTrue(!!microsoftAuthModule);
+ document.body.append(microsoftAuthModule);
+ await microtasksFinished();
});
test('clicking the disable button fires a disable module event', async () => {
- // Arrange.
- const modulesMicrosoftAuthName = 'Microsoft Authentication';
- loadTimeData.overrideValues(
- {modulesMicrosoftAuthName: modulesMicrosoftAuthName});
- const microsoftAuthModule = await microsoftAuthModuleDescriptor.initialize(
- 0) as MicrosoftAuthModuleElement;
- document.body.append(microsoftAuthModule);
- await microtasksFinished();
-
// Act.
const whenFired = eventToPromise('disable-module', microsoftAuthModule);
const disableButton =
@@ -37,4 +47,24 @@
('You won\'t see ' + modulesMicrosoftAuthName + ' on this page again'),
event.detail.message);
});
+
+ test('dismisses and restores module', async () => {
+ // Act.
+ const whenFired =
+ eventToPromise('dismiss-module-instance', microsoftAuthModule);
+ microsoftAuthModule.$.moduleHeaderElementV2.dispatchEvent(
+ new Event('dismiss-button-click'));
+
+ // Assert.
+ const event: DismissModuleInstanceEvent = await whenFired;
+ assertEquals((modulesMicrosoftAuthName + ' hidden'), event.detail.message);
+ assertTrue(!!event.detail.restoreCallback);
+ assertEquals(1, handler.getCallCount('dismissModule'));
+
+ // Act.
+ event.detail.restoreCallback!();
+
+ // Assert.
+ assertEquals(1, handler.getCallCount('restoreModule'));
+ });
});