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

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 4 years, 10 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/embedded_test_server/embedded_test_server.h" 28 #include "net/test/embedded_test_server/embedded_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 };
39 const double kNotificationTimestamp = 621046800000.;
38 40
39 class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest { 41 class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest {
40 public: 42 public:
41 PlatformNotificationServiceBrowserTest(); 43 PlatformNotificationServiceBrowserTest();
42 ~PlatformNotificationServiceBrowserTest() override {} 44 ~PlatformNotificationServiceBrowserTest() override {}
43 45
44 // InProcessBrowserTest overrides. 46 // InProcessBrowserTest overrides.
45 void SetUp() override; 47 void SetUp() override;
46 void SetUpOnMainThread() override; 48 void SetUpOnMainThread() override;
47 void TearDown() override; 49 void TearDown() override;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 232
231 // We don't use or check the notification's direction and language. 233 // We don't use or check the notification's direction and language.
232 const Notification& default_notification = ui_manager()->GetNotificationAt(0); 234 const Notification& default_notification = ui_manager()->GetNotificationAt(0);
233 EXPECT_EQ("Some title", base::UTF16ToUTF8(default_notification.title())); 235 EXPECT_EQ("Some title", base::UTF16ToUTF8(default_notification.title()));
234 EXPECT_EQ("", base::UTF16ToUTF8(default_notification.message())); 236 EXPECT_EQ("", base::UTF16ToUTF8(default_notification.message()));
235 EXPECT_EQ("", default_notification.tag()); 237 EXPECT_EQ("", default_notification.tag());
236 EXPECT_TRUE(default_notification.icon().IsEmpty()); 238 EXPECT_TRUE(default_notification.icon().IsEmpty());
237 EXPECT_FALSE(default_notification.silent()); 239 EXPECT_FALSE(default_notification.silent());
238 EXPECT_FALSE(default_notification.never_timeout()); 240 EXPECT_FALSE(default_notification.never_timeout());
239 241
242 // Verifies that the notification's default timestamp is set in the last 30
243 // seconds. This number has no significance, but it needs to be significantly
244 // high to avoid flakiness in the test.
245 EXPECT_NEAR(default_notification.timestamp().ToJsTime(),
246 base::Time::Now().ToJsTime(), 30 * 1000);
247
240 // Now, test the non-default values. 248 // Now, test the non-default values.
241 249
242 ASSERT_TRUE(RunScript("DisplayPersistentAllOptionsNotification()", 250 ASSERT_TRUE(RunScript("DisplayPersistentAllOptionsNotification()",
243 &script_result)); 251 &script_result));
244 EXPECT_EQ("ok", script_result); 252 EXPECT_EQ("ok", script_result);
245 253
246 ASSERT_EQ(2u, ui_manager()->GetNotificationCount()); 254 ASSERT_EQ(2u, ui_manager()->GetNotificationCount());
247 255
248 // We don't use or check the notification's direction and language. 256 // We don't use or check the notification's direction and language.
249 const Notification& all_options_notification = 257 const Notification& all_options_notification =
250 ui_manager()->GetNotificationAt(1); 258 ui_manager()->GetNotificationAt(1);
251 EXPECT_EQ("Title", base::UTF16ToUTF8(all_options_notification.title())); 259 EXPECT_EQ("Title", base::UTF16ToUTF8(all_options_notification.title()));
252 EXPECT_EQ("Contents", base::UTF16ToUTF8(all_options_notification.message())); 260 EXPECT_EQ("Contents", base::UTF16ToUTF8(all_options_notification.message()));
253 EXPECT_EQ("replace-id", all_options_notification.tag()); 261 EXPECT_EQ("replace-id", all_options_notification.tag());
254 EXPECT_FALSE(all_options_notification.icon().IsEmpty()); 262 EXPECT_FALSE(all_options_notification.icon().IsEmpty());
255 EXPECT_TRUE(all_options_notification.silent()); 263 EXPECT_TRUE(all_options_notification.silent());
256 EXPECT_TRUE(all_options_notification.never_timeout()); 264 EXPECT_TRUE(all_options_notification.never_timeout());
265 EXPECT_DOUBLE_EQ(kNotificationTimestamp,
266 all_options_notification.timestamp().ToJsTime());
257 267
258 EXPECT_EQ(kIconWidth, all_options_notification.icon().Width()); 268 EXPECT_EQ(kIconWidth, all_options_notification.icon().Width());
259 EXPECT_EQ(kIconHeight, all_options_notification.icon().Height()); 269 EXPECT_EQ(kIconHeight, all_options_notification.icon().Height());
260 } 270 }
261 271
262 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 272 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
263 WebNotificationSiteSettingsButton) { 273 WebNotificationSiteSettingsButton) {
264 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); 274 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest());
265 275
266 std::string script_result; 276 std::string script_result;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 420
411 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 421 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
412 422
413 const Notification& notification = ui_manager()->GetNotificationAt(0); 423 const Notification& notification = ui_manager()->GetNotificationAt(0);
414 EXPECT_FALSE(notification.icon().IsEmpty()); 424 EXPECT_FALSE(notification.icon().IsEmpty());
415 425
416 EXPECT_EQ("Blob Title", base::UTF16ToUTF8(notification.title())); 426 EXPECT_EQ("Blob Title", base::UTF16ToUTF8(notification.title()));
417 EXPECT_EQ(kIconWidth, notification.icon().Width()); 427 EXPECT_EQ(kIconWidth, notification.icon().Width());
418 EXPECT_EQ(kIconHeight, notification.icon().Height()); 428 EXPECT_EQ(kIconHeight, notification.icon().Height());
419 } 429 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698