Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: chrome/browser/notifications/platform_notification_service_browsertest.cc

Issue 1388483002: Implement the Notification `timestamp` property (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h"
13 #include "chrome/browser/notifications/desktop_notification_profile_util.h" 14 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
14 #include "chrome/browser/notifications/notification_permission_context.h" 15 #include "chrome/browser/notifications/notification_permission_context.h"
15 #include "chrome/browser/notifications/notification_permission_context_factory.h " 16 #include "chrome/browser/notifications/notification_permission_context_factory.h "
16 #include "chrome/browser/notifications/notification_test_util.h" 17 #include "chrome/browser/notifications/notification_test_util.h"
17 #include "chrome/browser/notifications/platform_notification_service_impl.h" 18 #include "chrome/browser/notifications/platform_notification_service_impl.h"
18 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" 20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 21 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
21 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
22 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
23 #include "chrome/test/base/in_process_browser_test.h" 24 #include "chrome/test/base/in_process_browser_test.h"
24 #include "chrome/test/base/ui_test_utils.h" 25 #include "chrome/test/base/ui_test_utils.h"
25 #include "content/public/test/browser_test_utils.h" 26 #include "content/public/test/browser_test_utils.h"
26 #include "net/base/filename_util.h" 27 #include "net/base/filename_util.h"
27 #include "net/test/spawned_test_server/spawned_test_server.h" 28 #include "net/test/spawned_test_server/spawned_test_server.h"
28 #include "testing/gmock/include/gmock/gmock.h" 29 #include "testing/gmock/include/gmock/gmock.h"
29 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
30 31
31 // ----------------------------------------------------------------------------- 32 // -----------------------------------------------------------------------------
32 33
33 // Dimensions of the icon.png resource in the notification test data directory. 34 // Dimensions of the icon.png resource in the notification test data directory.
34 const int kIconWidth = 100; 35 const int kIconWidth = 100;
35 const int kIconHeight = 100; 36 const int kIconHeight = 100;
36 37
37 const int kNotificationVibrationPattern[] = { 100, 200, 300 }; 38 const int kNotificationVibrationPattern[] = { 100, 200, 300 };
38 39
40 const double kNotificationTimestamp = 621046800000.;
41
39 class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest { 42 class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest {
40 public: 43 public:
41 PlatformNotificationServiceBrowserTest(); 44 PlatformNotificationServiceBrowserTest();
42 ~PlatformNotificationServiceBrowserTest() override {} 45 ~PlatformNotificationServiceBrowserTest() override {}
43 46
44 // InProcessBrowserTest overrides. 47 // InProcessBrowserTest overrides.
45 void SetUp() override; 48 void SetUp() override;
46 void SetUpCommandLine(base::CommandLine* command_line) override; 49 void SetUpCommandLine(base::CommandLine* command_line) override;
47 void SetUpOnMainThread() override; 50 void SetUpOnMainThread() override;
48 void TearDown() override; 51 void TearDown() override;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 EXPECT_EQ("ok", script_result); 241 EXPECT_EQ("ok", script_result);
239 242
240 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 243 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
241 244
242 // We don't use or check the notification's direction and language. 245 // We don't use or check the notification's direction and language.
243 const Notification& default_notification = ui_manager()->GetNotificationAt(0); 246 const Notification& default_notification = ui_manager()->GetNotificationAt(0);
244 EXPECT_EQ("Some title", base::UTF16ToUTF8(default_notification.title())); 247 EXPECT_EQ("Some title", base::UTF16ToUTF8(default_notification.title()));
245 EXPECT_EQ("", base::UTF16ToUTF8(default_notification.message())); 248 EXPECT_EQ("", base::UTF16ToUTF8(default_notification.message()));
246 EXPECT_EQ("", default_notification.tag()); 249 EXPECT_EQ("", default_notification.tag());
247 EXPECT_TRUE(default_notification.icon().IsEmpty()); 250 EXPECT_TRUE(default_notification.icon().IsEmpty());
251
252 // Verifies that the notification's default timestamp is set in the last 30
253 // seconds. This number has no significance, but it needs to be significantly
254 // high to avoid flakiness in the test.
255 EXPECT_NEAR(default_notification.timestamp().ToJsTime(),
256 base::Time::Now().ToJsTime(), 30 * 1000);
257
248 EXPECT_FALSE(default_notification.silent()); 258 EXPECT_FALSE(default_notification.silent());
249 EXPECT_FALSE(default_notification.never_timeout()); 259 EXPECT_FALSE(default_notification.never_timeout());
250 260
251 // Now, test the non-default values. 261 // Now, test the non-default values.
252 262
253 ASSERT_TRUE(RunScript("DisplayPersistentAllOptionsNotification()", 263 ASSERT_TRUE(RunScript("DisplayPersistentAllOptionsNotification()",
254 &script_result)); 264 &script_result));
255 EXPECT_EQ("ok", script_result); 265 EXPECT_EQ("ok", script_result);
256 266
257 ASSERT_EQ(2u, ui_manager()->GetNotificationCount()); 267 ASSERT_EQ(2u, ui_manager()->GetNotificationCount());
258 268
259 // We don't use or check the notification's direction and language. 269 // We don't use or check the notification's direction and language.
260 const Notification& all_options_notification = 270 const Notification& all_options_notification =
261 ui_manager()->GetNotificationAt(1); 271 ui_manager()->GetNotificationAt(1);
262 EXPECT_EQ("Title", base::UTF16ToUTF8(all_options_notification.title())); 272 EXPECT_EQ("Title", base::UTF16ToUTF8(all_options_notification.title()));
263 EXPECT_EQ("Contents", base::UTF16ToUTF8(all_options_notification.message())); 273 EXPECT_EQ("Contents", base::UTF16ToUTF8(all_options_notification.message()));
264 EXPECT_EQ("replace-id", all_options_notification.tag()); 274 EXPECT_EQ("replace-id", all_options_notification.tag());
265 EXPECT_FALSE(all_options_notification.icon().IsEmpty()); 275 EXPECT_FALSE(all_options_notification.icon().IsEmpty());
276 EXPECT_DOUBLE_EQ(kNotificationTimestamp,
277 all_options_notification.timestamp().ToJsTime());
266 EXPECT_TRUE(all_options_notification.silent()); 278 EXPECT_TRUE(all_options_notification.silent());
267 EXPECT_TRUE(all_options_notification.never_timeout()); 279 EXPECT_TRUE(all_options_notification.never_timeout());
268 280
269 EXPECT_EQ(kIconWidth, all_options_notification.icon().Width()); 281 EXPECT_EQ(kIconWidth, all_options_notification.icon().Width());
270 EXPECT_EQ(kIconHeight, all_options_notification.icon().Height()); 282 EXPECT_EQ(kIconHeight, all_options_notification.icon().Height());
271 } 283 }
272 284
273 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 285 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
274 WebNotificationSiteSettingsButton) { 286 WebNotificationSiteSettingsButton) {
275 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); 287 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest());
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 430
419 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 431 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
420 432
421 const Notification& notification = ui_manager()->GetNotificationAt(0); 433 const Notification& notification = ui_manager()->GetNotificationAt(0);
422 EXPECT_FALSE(notification.icon().IsEmpty()); 434 EXPECT_FALSE(notification.icon().IsEmpty());
423 435
424 EXPECT_EQ("Blob Title", base::UTF16ToUTF8(notification.title())); 436 EXPECT_EQ("Blob Title", base::UTF16ToUTF8(notification.title()));
425 EXPECT_EQ(kIconWidth, notification.icon().Width()); 437 EXPECT_EQ(kIconWidth, notification.icon().Width());
426 EXPECT_EQ(kIconHeight, notification.icon().Height()); 438 EXPECT_EQ(kIconHeight, notification.icon().Height());
427 } 439 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698