OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "chrome/browser/notifications/notification_test_util.h" | 6 #include "chrome/browser/notifications/notification_test_util.h" |
7 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 7 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
8 #include "chrome/test/base/testing_profile.h" | 8 #include "chrome/test/base/testing_profile.h" |
9 #include "content/public/browser/desktop_notification_delegate.h" | 9 #include "content/public/browser/desktop_notification_delegate.h" |
| 10 #include "content/public/common/platform_notification_data.h" |
10 #include "content/public/test/test_browser_thread_bundle.h" | 11 #include "content/public/test/test_browser_thread_bundle.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/skia/include/core/SkBitmap.h" |
12 | 14 |
13 namespace { | 15 namespace { |
14 | 16 |
15 class MockDesktopNotificationDelegate | 17 class MockDesktopNotificationDelegate |
16 : public content::DesktopNotificationDelegate { | 18 : public content::DesktopNotificationDelegate { |
17 public: | 19 public: |
18 MockDesktopNotificationDelegate() | 20 MockDesktopNotificationDelegate() |
19 : displayed_(false), | 21 : displayed_(false), |
20 clicked_(false) {} | 22 clicked_(false) {} |
21 | 23 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // delegate receiving events for it (ownership is transferred to the service). | 59 // delegate receiving events for it (ownership is transferred to the service). |
58 MockDesktopNotificationDelegate* CreateSimplePageNotification() const { | 60 MockDesktopNotificationDelegate* CreateSimplePageNotification() const { |
59 return CreateSimplePageNotificationWithCloseClosure(nullptr); | 61 return CreateSimplePageNotificationWithCloseClosure(nullptr); |
60 } | 62 } |
61 | 63 |
62 // Displays a simple, fake notification and returns a weak pointer to the | 64 // Displays a simple, fake notification and returns a weak pointer to the |
63 // delegate receiving events for it (ownership is transferred to the service). | 65 // delegate receiving events for it (ownership is transferred to the service). |
64 // The close closure may be specified if so desired. | 66 // The close closure may be specified if so desired. |
65 MockDesktopNotificationDelegate* CreateSimplePageNotificationWithCloseClosure( | 67 MockDesktopNotificationDelegate* CreateSimplePageNotificationWithCloseClosure( |
66 base::Closure* close_closure) const { | 68 base::Closure* close_closure) const { |
67 content::ShowDesktopNotificationHostMsgParams params; | 69 content::PlatformNotificationData notification_data; |
68 params.origin = GURL("https://example.com/"); | 70 notification_data.title = base::ASCIIToUTF16("My Notification"); |
69 params.title = base::ASCIIToUTF16("My Notification"); | 71 notification_data.body = base::ASCIIToUTF16("Hello, world!"); |
70 params.body = base::ASCIIToUTF16("Hello, world!"); | |
71 | 72 |
72 MockDesktopNotificationDelegate* delegate = | 73 MockDesktopNotificationDelegate* delegate = |
73 new MockDesktopNotificationDelegate(); | 74 new MockDesktopNotificationDelegate(); |
74 | 75 |
75 service()->DisplayNotification(profile(), | 76 service()->DisplayNotification(profile(), |
76 params, | 77 GURL("https://example.com/"), |
| 78 SkBitmap(), |
| 79 notification_data, |
77 make_scoped_ptr(delegate), | 80 make_scoped_ptr(delegate), |
78 0 /* render_process_id */, | 81 0 /* render_process_id */, |
79 close_closure); | 82 close_closure); |
80 | 83 |
81 return delegate; | 84 return delegate; |
82 } | 85 } |
83 | 86 |
84 // Returns the Platform Notification Service these unit tests are for. | 87 // Returns the Platform Notification Service these unit tests are for. |
85 PlatformNotificationServiceImpl* service() const { | 88 PlatformNotificationServiceImpl* service() const { |
86 return PlatformNotificationServiceImpl::GetInstance(); | 89 return PlatformNotificationServiceImpl::GetInstance(); |
(...skipping 28 matching lines...) Expand all Loading... |
115 ASSERT_FALSE(close_closure.is_null()); | 118 ASSERT_FALSE(close_closure.is_null()); |
116 close_closure.Run(); | 119 close_closure.Run(); |
117 | 120 |
118 EXPECT_EQ(0u, ui_manager()->GetNotificationCount()); | 121 EXPECT_EQ(0u, ui_manager()->GetNotificationCount()); |
119 | 122 |
120 // Note that we cannot verify whether the closed event was called on the | 123 // Note that we cannot verify whether the closed event was called on the |
121 // delegate given that it'd result in a use-after-free. | 124 // delegate given that it'd result in a use-after-free. |
122 } | 125 } |
123 | 126 |
124 TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) { | 127 TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) { |
125 content::ShowDesktopNotificationHostMsgParams params; | 128 content::PlatformNotificationData notification_data; |
126 params.origin = GURL("https://chrome.com/"); | 129 notification_data.title = base::ASCIIToUTF16("My notification's title"); |
127 params.title = base::ASCIIToUTF16("My notification's title"); | 130 notification_data.body = base::ASCIIToUTF16("Hello, world!"); |
128 params.body = base::ASCIIToUTF16("Hello, world!"); | |
129 | 131 |
130 MockDesktopNotificationDelegate* delegate | 132 MockDesktopNotificationDelegate* delegate |
131 = new MockDesktopNotificationDelegate(); | 133 = new MockDesktopNotificationDelegate(); |
132 service()->DisplayNotification(profile(), | 134 service()->DisplayNotification(profile(), |
133 params, | 135 GURL("https://chrome.com/"), |
| 136 SkBitmap(), |
| 137 notification_data, |
134 make_scoped_ptr(delegate), | 138 make_scoped_ptr(delegate), |
135 0 /* render_process_id */, | 139 0 /* render_process_id */, |
136 nullptr); | 140 nullptr); |
137 | 141 |
138 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 142 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
139 | 143 |
140 const Notification& notification = ui_manager()->GetNotificationAt(0); | 144 const Notification& notification = ui_manager()->GetNotificationAt(0); |
141 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec()); | 145 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec()); |
142 EXPECT_EQ("My notification's title", | 146 EXPECT_EQ("My notification's title", |
143 base::UTF16ToUTF8(notification.title())); | 147 base::UTF16ToUTF8(notification.title())); |
144 EXPECT_EQ("Hello, world!", | 148 EXPECT_EQ("Hello, world!", |
145 base::UTF16ToUTF8(notification.message())); | 149 base::UTF16ToUTF8(notification.message())); |
146 } | 150 } |
147 | 151 |
148 TEST_F(PlatformNotificationServiceTest, DisplayNameForOrigin) { | 152 TEST_F(PlatformNotificationServiceTest, DisplayNameForOrigin) { |
149 base::string16 display_name = | 153 base::string16 display_name = |
150 service()->DisplayNameForOriginInProcessId(profile(), | 154 service()->DisplayNameForOriginInProcessId(profile(), |
151 GURL("https://chrome.com/"), | 155 GURL("https://chrome.com/"), |
152 0 /* render_process_id */); | 156 0 /* render_process_id */); |
153 | 157 |
154 EXPECT_EQ(base::ASCIIToUTF16("chrome.com"), display_name); | 158 EXPECT_EQ(base::ASCIIToUTF16("chrome.com"), display_name); |
155 | 159 |
156 // TODO(peter): Include unit tests for the extension-name translation | 160 // TODO(peter): Include unit tests for the extension-name translation |
157 // functionality of DisplayNameForOriginInProcessId. | 161 // functionality of DisplayNameForOriginInProcessId. |
158 } | 162 } |
OLD | NEW |