Commit d71124c5 authored by Finnur Thorarinsson's avatar Finnur Thorarinsson Committed by Commit Bot

Windows Native Notifications: Add test coverage for HandleActivation.

Bug: 734095
Change-Id: I01e5d3c8bd133d8914fd64626494d12531dbcf37
Reviewed-on: https://chromium-review.googlesource.com/955596
Commit-Queue: Finnur Thorarinsson <finnur@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549863}
parent 35a52924
...@@ -33,6 +33,12 @@ namespace winxml = ABI::Windows::Data::Xml; ...@@ -33,6 +33,12 @@ namespace winxml = ABI::Windows::Data::Xml;
namespace { namespace {
const char kLaunchId[] = "0|0|Default|0|https://example.com/|notification_id";
const char kLaunchIdButtonClick[] =
"1|0|0|Default|0|https://example.com/|notification_id";
const char kLaunchIdSettings[] =
"2|0|Default|0|https://example.com/|notification_id";
Profile* CreateTestingProfile(const base::FilePath& path) { Profile* CreateTestingProfile(const base::FilePath& path) {
base::ScopedAllowBlockingForTesting allow_blocking; base::ScopedAllowBlockingForTesting allow_blocking;
ProfileManager* profile_manager = g_browser_process->profile_manager(); ProfileManager* profile_manager = g_browser_process->profile_manager();
...@@ -77,6 +83,11 @@ class NotificationPlatformBridgeWinUITest : public InProcessBrowserTest { ...@@ -77,6 +83,11 @@ class NotificationPlatformBridgeWinUITest : public InProcessBrowserTest {
browser()->profile()); browser()->profile());
} }
NotificationPlatformBridgeWin* GetBridge() {
return static_cast<NotificationPlatformBridgeWin*>(
g_browser_process->notification_platform_bridge());
}
void TearDownOnMainThread() override { display_service_tester_.reset(); } void TearDownOnMainThread() override { display_service_tester_.reset(); }
void HandleOperation(const base::RepeatingClosure& quit_task, void HandleOperation(const base::RepeatingClosure& quit_task,
...@@ -106,6 +117,24 @@ class NotificationPlatformBridgeWinUITest : public InProcessBrowserTest { ...@@ -106,6 +117,24 @@ class NotificationPlatformBridgeWinUITest : public InProcessBrowserTest {
} }
protected: protected:
void ProcessLaunchIdViaCmdLine(const std::string& launch_id) {
base::RunLoop run_loop;
display_service_tester_->SetProcessNotificationOperationDelegate(
base::BindRepeating(
&NotificationPlatformBridgeWinUITest::HandleOperation,
base::Unretained(this), run_loop.QuitClosure()));
// Simulate clicks on the toast.
NotificationPlatformBridgeWin* bridge = GetBridge();
ASSERT_TRUE(bridge);
base::CommandLine command_line = base::CommandLine::FromString(L"");
command_line.AppendSwitchASCII(switches::kNotificationLaunchId, launch_id);
ASSERT_TRUE(bridge->HandleActivation(command_line));
run_loop.Run();
}
bool ValidateNotificationValues(NotificationCommon::Operation operation, bool ValidateNotificationValues(NotificationCommon::Operation operation,
NotificationHandler::Type notification_type, NotificationHandler::Type notification_type,
const GURL& origin, const GURL& origin,
...@@ -202,9 +231,7 @@ IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, HandleEvent) { ...@@ -202,9 +231,7 @@ IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, HandleEvent) {
base::Unretained(this), run_loop.QuitClosure())); base::Unretained(this), run_loop.QuitClosure()));
// Simulate clicks on the toast. // Simulate clicks on the toast.
NotificationPlatformBridgeWin* bridge = NotificationPlatformBridgeWin* bridge = GetBridge();
static_cast<NotificationPlatformBridgeWin*>(
g_browser_process->notification_platform_bridge());
ASSERT_TRUE(bridge); ASSERT_TRUE(bridge);
bridge->ForwardHandleEventForTesting(NotificationCommon::CLICK, &toast, &args, bridge->ForwardHandleEventForTesting(NotificationCommon::CLICK, &toast, &args,
base::nullopt); base::nullopt);
...@@ -279,9 +306,7 @@ IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, HandleSettings) { ...@@ -279,9 +306,7 @@ IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, HandleSettings) {
base::Unretained(this), run_loop.QuitClosure())); base::Unretained(this), run_loop.QuitClosure()));
// Simulate clicks on the toast. // Simulate clicks on the toast.
NotificationPlatformBridgeWin* bridge = NotificationPlatformBridgeWin* bridge = GetBridge();
static_cast<NotificationPlatformBridgeWin*>(
g_browser_process->notification_platform_bridge());
ASSERT_TRUE(bridge); ASSERT_TRUE(bridge);
bridge->ForwardHandleEventForTesting(NotificationCommon::SETTINGS, &toast, bridge->ForwardHandleEventForTesting(NotificationCommon::SETTINGS, &toast,
&args, base::nullopt); &args, base::nullopt);
...@@ -303,9 +328,7 @@ IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, GetDisplayed) { ...@@ -303,9 +328,7 @@ IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, GetDisplayed) {
if (base::win::GetVersion() < base::win::VERSION_WIN8) if (base::win::GetVersion() < base::win::VERSION_WIN8)
return; return;
NotificationPlatformBridgeWin* bridge = NotificationPlatformBridgeWin* bridge = GetBridge();
static_cast<NotificationPlatformBridgeWin*>(
g_browser_process->notification_platform_bridge());
ASSERT_TRUE(bridge); ASSERT_TRUE(bridge);
std::vector<winui::Notifications::IToastNotification*> notifications; std::vector<winui::Notifications::IToastNotification*> notifications;
...@@ -397,3 +420,57 @@ IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, GetDisplayed) { ...@@ -397,3 +420,57 @@ IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, GetDisplayed) {
bridge->SetDisplayedNotificationsForTesting(nullptr); bridge->SetDisplayedNotificationsForTesting(nullptr);
} }
IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, CmdLineClick) {
// This test exercises a feature that is not enabled in older versions of
// Windows.
if (base::win::GetVersion() < base::win::VERSION_WIN8)
return;
ASSERT_NO_FATAL_FAILURE(ProcessLaunchIdViaCmdLine(kLaunchId));
// Validate the click values.
EXPECT_EQ(NotificationCommon::CLICK, last_operation_);
EXPECT_EQ(NotificationHandler::Type::WEB_PERSISTENT, last_notification_type_);
EXPECT_EQ(GURL("https://example.com/"), last_origin_);
EXPECT_EQ("notification_id", last_notification_id_);
EXPECT_EQ(-1, last_action_index_);
EXPECT_EQ(base::nullopt, last_reply_);
EXPECT_TRUE(last_by_user_);
}
IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, CmdLineButton) {
// This test exercises a feature that is not enabled in older versions of
// Windows.
if (base::win::GetVersion() < base::win::VERSION_WIN8)
return;
ASSERT_NO_FATAL_FAILURE(ProcessLaunchIdViaCmdLine(kLaunchIdButtonClick));
// Validate the click values.
EXPECT_EQ(NotificationCommon::CLICK, last_operation_);
EXPECT_EQ(NotificationHandler::Type::WEB_PERSISTENT, last_notification_type_);
EXPECT_EQ(GURL("https://example.com/"), last_origin_);
EXPECT_EQ("notification_id", last_notification_id_);
EXPECT_EQ(0, last_action_index_);
EXPECT_EQ(base::nullopt, last_reply_);
EXPECT_TRUE(last_by_user_);
}
IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, CmdLineSettings) {
// This test exercises a feature that is not enabled in older versions of
// Windows.
if (base::win::GetVersion() < base::win::VERSION_WIN8)
return;
ASSERT_NO_FATAL_FAILURE(ProcessLaunchIdViaCmdLine(kLaunchIdSettings));
// Validate the click values.
EXPECT_EQ(NotificationCommon::SETTINGS, last_operation_);
EXPECT_EQ(NotificationHandler::Type::WEB_PERSISTENT, last_notification_type_);
EXPECT_EQ(GURL("https://example.com/"), last_origin_);
EXPECT_EQ("notification_id", last_notification_id_);
EXPECT_EQ(-1, last_action_index_);
EXPECT_EQ(base::nullopt, last_reply_);
EXPECT_TRUE(last_by_user_);
}
...@@ -50,6 +50,7 @@ class NotificationPlatformBridgeWinTest : public testing::Test { ...@@ -50,6 +50,7 @@ class NotificationPlatformBridgeWinTest : public testing::Test {
~NotificationPlatformBridgeWinTest() override = default; ~NotificationPlatformBridgeWinTest() override = default;
HRESULT GetToast( HRESULT GetToast(
const NotificationLaunchId& launch_id,
bool renotify, bool renotify,
mswr::ComPtr<winui::Notifications::IToastNotification2>* toast2) { mswr::ComPtr<winui::Notifications::IToastNotification2>* toast2) {
GURL origin(kOrigin); GURL origin(kOrigin);
...@@ -60,8 +61,6 @@ class NotificationPlatformBridgeWinTest : public testing::Test { ...@@ -60,8 +61,6 @@ class NotificationPlatformBridgeWinTest : public testing::Test {
message_center::RichNotificationData(), nullptr /* delegate */); message_center::RichNotificationData(), nullptr /* delegate */);
notification->set_renotify(renotify); notification->set_renotify(renotify);
MockNotificationImageRetainer image_retainer; MockNotificationImageRetainer image_retainer;
NotificationLaunchId launch_id(kLaunchId);
DCHECK(launch_id.is_valid());
std::unique_ptr<NotificationTemplateBuilder> builder = std::unique_ptr<NotificationTemplateBuilder> builder =
NotificationTemplateBuilder::Build(&image_retainer, launch_id, NotificationTemplateBuilder::Build(&image_retainer, launch_id,
kProfileId, *notification); kProfileId, *notification);
...@@ -102,8 +101,11 @@ TEST_F(NotificationPlatformBridgeWinTest, GroupAndTag) { ...@@ -102,8 +101,11 @@ TEST_F(NotificationPlatformBridgeWinTest, GroupAndTag) {
base::win::ScopedCOMInitializer com_initializer; base::win::ScopedCOMInitializer com_initializer;
NotificationLaunchId launch_id(kLaunchId);
ASSERT_TRUE(launch_id.is_valid());
mswr::ComPtr<winui::Notifications::IToastNotification2> toast2; mswr::ComPtr<winui::Notifications::IToastNotification2> toast2;
ASSERT_HRESULT_SUCCEEDED(GetToast(false /* renotify */, &toast2)); ASSERT_HRESULT_SUCCEEDED(GetToast(launch_id, false /* renotify */, &toast2));
HSTRING hstring_group; HSTRING hstring_group;
ASSERT_HRESULT_SUCCEEDED(toast2->get_Group(&hstring_group)); ASSERT_HRESULT_SUCCEEDED(toast2->get_Group(&hstring_group));
...@@ -135,9 +137,12 @@ TEST_F(NotificationPlatformBridgeWinTest, Suppress) { ...@@ -135,9 +137,12 @@ TEST_F(NotificationPlatformBridgeWinTest, Suppress) {
mswr::ComPtr<winui::Notifications::IToastNotification2> toast2; mswr::ComPtr<winui::Notifications::IToastNotification2> toast2;
boolean suppress; boolean suppress;
NotificationLaunchId launch_id(kLaunchId);
ASSERT_TRUE(launch_id.is_valid());
// Make sure this works a toast is not suppressed when no notifications are // Make sure this works a toast is not suppressed when no notifications are
// registered. // registered.
ASSERT_HRESULT_SUCCEEDED(GetToast(false, &toast2)); ASSERT_HRESULT_SUCCEEDED(GetToast(launch_id, false, &toast2));
ASSERT_HRESULT_SUCCEEDED(toast2->get_SuppressPopup(&suppress)); ASSERT_HRESULT_SUCCEEDED(toast2->get_SuppressPopup(&suppress));
ASSERT_FALSE(suppress); ASSERT_FALSE(suppress);
...@@ -148,12 +153,12 @@ TEST_F(NotificationPlatformBridgeWinTest, Suppress) { ...@@ -148,12 +153,12 @@ TEST_F(NotificationPlatformBridgeWinTest, Suppress) {
notifications.push_back(&item1); notifications.push_back(&item1);
// Request this notification with renotify true (should not be suppressed). // Request this notification with renotify true (should not be suppressed).
ASSERT_HRESULT_SUCCEEDED(GetToast(true, &toast2)); ASSERT_HRESULT_SUCCEEDED(GetToast(launch_id, true, &toast2));
ASSERT_HRESULT_SUCCEEDED(toast2->get_SuppressPopup(&suppress)); ASSERT_HRESULT_SUCCEEDED(toast2->get_SuppressPopup(&suppress));
ASSERT_FALSE(suppress); ASSERT_FALSE(suppress);
// Request this notification with renotify false (should be suppressed). // Request this notification with renotify false (should be suppressed).
ASSERT_HRESULT_SUCCEEDED(GetToast(false, &toast2)); ASSERT_HRESULT_SUCCEEDED(GetToast(launch_id, false, &toast2));
ASSERT_HRESULT_SUCCEEDED(toast2->get_SuppressPopup(&suppress)); ASSERT_HRESULT_SUCCEEDED(toast2->get_SuppressPopup(&suppress));
ASSERT_TRUE(suppress); ASSERT_TRUE(suppress);
......
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