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 "base/threading/platform_thread.h" | 6 #include "base/threading/platform_thread.h" |
7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
8 #include "chrome/browser/notifications/notification_test_util.h" | 8 #include "chrome/browser/notifications/notification_test_util.h" |
9 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 9 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 service()->DisplayNameForOriginInProcessId(profile(), | 183 service()->DisplayNameForOriginInProcessId(profile(), |
184 GURL("https://chrome.com/"), | 184 GURL("https://chrome.com/"), |
185 0 /* render_process_id */); | 185 0 /* render_process_id */); |
186 | 186 |
187 EXPECT_EQ(base::ASCIIToUTF16("chrome.com"), display_name); | 187 EXPECT_EQ(base::ASCIIToUTF16("chrome.com"), display_name); |
188 | 188 |
189 // TODO(peter): Include unit tests for the extension-name translation | 189 // TODO(peter): Include unit tests for the extension-name translation |
190 // functionality of DisplayNameForOriginInProcessId. | 190 // functionality of DisplayNameForOriginInProcessId. |
191 } | 191 } |
192 | 192 |
| 193 TEST_F(PlatformNotificationServiceTest, TestOriginDisplayName) { |
| 194 std::string language("en-us"); |
| 195 |
| 196 GURL https_origin("https://mail.google.com/"); |
| 197 base::string16 expected_display_name = base::ASCIIToUTF16("mail.google.com"); |
| 198 EXPECT_EQ(expected_display_name, |
| 199 PlatformNotificationServiceImpl::OriginDisplayName(https_origin, |
| 200 language)); |
| 201 |
| 202 GURL https_origin_standard_port("https://mail.google.com:443/"); |
| 203 expected_display_name = base::ASCIIToUTF16("mail.google.com"); |
| 204 EXPECT_EQ(expected_display_name, |
| 205 PlatformNotificationServiceImpl::OriginDisplayName( |
| 206 https_origin_standard_port, language)); |
| 207 |
| 208 GURL https_origin_nonstandard_port("https://mail.google.com:444/"); |
| 209 expected_display_name = base::ASCIIToUTF16("mail.google.com:444"); |
| 210 EXPECT_EQ(expected_display_name, |
| 211 PlatformNotificationServiceImpl::OriginDisplayName( |
| 212 https_origin_nonstandard_port, language)); |
| 213 |
| 214 GURL http_origin("http://mail.google.com/"); |
| 215 expected_display_name = base::ASCIIToUTF16("mail.google.com"); |
| 216 EXPECT_EQ(expected_display_name, |
| 217 PlatformNotificationServiceImpl::OriginDisplayName(http_origin, |
| 218 language)); |
| 219 |
| 220 GURL http_origin_standard_port("http://mail.google.com:80/"); |
| 221 expected_display_name = base::ASCIIToUTF16("mail.google.com"); |
| 222 EXPECT_EQ(expected_display_name, |
| 223 PlatformNotificationServiceImpl::OriginDisplayName( |
| 224 http_origin_standard_port, language)); |
| 225 |
| 226 GURL http_origin_nonstandard_port("http://mail.google.com:81/"); |
| 227 expected_display_name = base::ASCIIToUTF16("mail.google.com:81"); |
| 228 EXPECT_EQ(expected_display_name, |
| 229 PlatformNotificationServiceImpl::OriginDisplayName( |
| 230 http_origin_nonstandard_port, language)); |
| 231 // TODO(dewittj): Add file origin once it's supported. |
| 232 } |
| 233 |
193 TEST_F(PlatformNotificationServiceTest, NotificationPermissionLastUsage) { | 234 TEST_F(PlatformNotificationServiceTest, NotificationPermissionLastUsage) { |
194 // Both page and persistent notifications should update the last usage | 235 // Both page and persistent notifications should update the last usage |
195 // time of the notification permission for the origin. | 236 // time of the notification permission for the origin. |
196 GURL origin("https://chrome.com/"); | 237 GURL origin("https://chrome.com/"); |
197 base::Time begin_time; | 238 base::Time begin_time; |
198 | 239 |
199 CreateSimplePageNotification(); | 240 CreateSimplePageNotification(); |
200 | 241 |
201 base::Time after_page_notification = | 242 base::Time after_page_notification = |
202 profile()->GetHostContentSettingsMap()->GetLastUsage( | 243 profile()->GetHostContentSettingsMap()->GetLastUsage( |
203 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 244 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
204 EXPECT_GT(after_page_notification, begin_time); | 245 EXPECT_GT(after_page_notification, begin_time); |
205 | 246 |
206 // Ensure that there is at least some time between the two calls. | 247 // Ensure that there is at least some time between the two calls. |
207 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); | 248 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); |
208 | 249 |
209 service()->DisplayPersistentNotification(profile(), | 250 service()->DisplayPersistentNotification(profile(), |
210 42 /* sw_registration_id */, | 251 42 /* sw_registration_id */, |
211 origin, | 252 origin, |
212 SkBitmap(), | 253 SkBitmap(), |
213 content::PlatformNotificationData(), | 254 content::PlatformNotificationData(), |
214 0 /* render_process_id */); | 255 0 /* render_process_id */); |
215 | 256 |
216 base::Time after_persistent_notification = | 257 base::Time after_persistent_notification = |
217 profile()->GetHostContentSettingsMap()->GetLastUsage( | 258 profile()->GetHostContentSettingsMap()->GetLastUsage( |
218 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 259 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
219 EXPECT_GT(after_persistent_notification, after_page_notification); | 260 EXPECT_GT(after_persistent_notification, after_page_notification); |
220 } | 261 } |
OLD | NEW |