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 <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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "net/test/embedded_test_server/embedded_test_server.h" | 29 #include "net/test/embedded_test_server/embedded_test_server.h" |
30 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
31 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
32 | 32 |
33 // ----------------------------------------------------------------------------- | 33 // ----------------------------------------------------------------------------- |
34 | 34 |
35 // Dimensions of the icon.png resource in the notification test data directory. | 35 // Dimensions of the icon.png resource in the notification test data directory. |
36 const int kIconWidth = 100; | 36 const int kIconWidth = 100; |
37 const int kIconHeight = 100; | 37 const int kIconHeight = 100; |
38 | 38 |
| 39 // The maximum width and height of badges. Oversized images are scaled down to |
| 40 // these values. |
| 41 const int kMaxBadgeSize = 96; |
| 42 |
39 const int kNotificationVibrationPattern[] = { 100, 200, 300 }; | 43 const int kNotificationVibrationPattern[] = { 100, 200, 300 }; |
40 const double kNotificationTimestamp = 621046800000.; | 44 const double kNotificationTimestamp = 621046800000.; |
41 | 45 |
42 class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest { | 46 class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest { |
43 public: | 47 public: |
44 PlatformNotificationServiceBrowserTest(); | 48 PlatformNotificationServiceBrowserTest(); |
45 ~PlatformNotificationServiceBrowserTest() override {} | 49 ~PlatformNotificationServiceBrowserTest() override {} |
46 | 50 |
47 // InProcessBrowserTest overrides. | 51 // InProcessBrowserTest overrides. |
48 void SetUpCommandLine(base::CommandLine* command_line) override; | 52 void SetUpCommandLine(base::CommandLine* command_line) override; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 103 } |
100 | 104 |
101 PlatformNotificationServiceBrowserTest::PlatformNotificationServiceBrowserTest() | 105 PlatformNotificationServiceBrowserTest::PlatformNotificationServiceBrowserTest() |
102 : server_root_(FILE_PATH_LITERAL("chrome/test/data")), | 106 : server_root_(FILE_PATH_LITERAL("chrome/test/data")), |
103 // The test server has a base directory that doesn't exist in the | 107 // The test server has a base directory that doesn't exist in the |
104 // filesystem. | 108 // filesystem. |
105 test_page_url_(std::string("/") + kTestFileName) {} | 109 test_page_url_(std::string("/") + kTestFileName) {} |
106 | 110 |
107 void PlatformNotificationServiceBrowserTest::SetUpCommandLine( | 111 void PlatformNotificationServiceBrowserTest::SetUpCommandLine( |
108 base::CommandLine* command_line) { | 112 base::CommandLine* command_line) { |
| 113 command_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); |
109 command_line->AppendSwitch(switches::kEnableNotificationActionIcons); | 114 command_line->AppendSwitch(switches::kEnableNotificationActionIcons); |
110 | 115 |
111 InProcessBrowserTest::SetUpCommandLine(command_line); | 116 InProcessBrowserTest::SetUpCommandLine(command_line); |
112 } | 117 } |
113 | 118 |
114 void PlatformNotificationServiceBrowserTest::SetUp() { | 119 void PlatformNotificationServiceBrowserTest::SetUp() { |
115 ui_manager_.reset(new StubNotificationUIManager); | 120 ui_manager_.reset(new StubNotificationUIManager); |
116 https_server_.reset( | 121 https_server_.reset( |
117 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); | 122 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
118 https_server_->ServeFilesFromSourceDirectory(server_root_); | 123 https_server_->ServeFilesFromSourceDirectory(server_root_); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 EXPECT_EQ("ok", script_result); | 243 EXPECT_EQ("ok", script_result); |
239 | 244 |
240 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 245 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
241 | 246 |
242 // We don't use or check the notification's direction and language. | 247 // We don't use or check the notification's direction and language. |
243 const Notification& default_notification = ui_manager()->GetNotificationAt(0); | 248 const Notification& default_notification = ui_manager()->GetNotificationAt(0); |
244 EXPECT_EQ("Some title", base::UTF16ToUTF8(default_notification.title())); | 249 EXPECT_EQ("Some title", base::UTF16ToUTF8(default_notification.title())); |
245 EXPECT_EQ("", base::UTF16ToUTF8(default_notification.message())); | 250 EXPECT_EQ("", base::UTF16ToUTF8(default_notification.message())); |
246 EXPECT_EQ("", default_notification.tag()); | 251 EXPECT_EQ("", default_notification.tag()); |
247 EXPECT_TRUE(default_notification.icon().IsEmpty()); | 252 EXPECT_TRUE(default_notification.icon().IsEmpty()); |
| 253 EXPECT_TRUE(default_notification.small_image().IsEmpty()); |
248 EXPECT_FALSE(default_notification.renotify()); | 254 EXPECT_FALSE(default_notification.renotify()); |
249 EXPECT_FALSE(default_notification.silent()); | 255 EXPECT_FALSE(default_notification.silent()); |
250 EXPECT_FALSE(default_notification.never_timeout()); | 256 EXPECT_FALSE(default_notification.never_timeout()); |
251 EXPECT_EQ(0u, default_notification.buttons().size()); | 257 EXPECT_EQ(0u, default_notification.buttons().size()); |
252 | 258 |
253 // Verifies that the notification's default timestamp is set in the last 30 | 259 // Verifies that the notification's default timestamp is set in the last 30 |
254 // seconds. This number has no significance, but it needs to be significantly | 260 // seconds. This number has no significance, but it needs to be significantly |
255 // high to avoid flakiness in the test. | 261 // high to avoid flakiness in the test. |
256 EXPECT_NEAR(default_notification.timestamp().ToJsTime(), | 262 EXPECT_NEAR(default_notification.timestamp().ToJsTime(), |
257 base::Time::Now().ToJsTime(), 30 * 1000); | 263 base::Time::Now().ToJsTime(), 30 * 1000); |
258 | 264 |
259 // Now, test the non-default values. | 265 // Now, test the non-default values. |
260 | 266 |
261 ASSERT_TRUE(RunScript("DisplayPersistentAllOptionsNotification()", | 267 ASSERT_TRUE(RunScript("DisplayPersistentAllOptionsNotification()", |
262 &script_result)); | 268 &script_result)); |
263 EXPECT_EQ("ok", script_result); | 269 EXPECT_EQ("ok", script_result); |
264 | 270 |
265 ASSERT_EQ(2u, ui_manager()->GetNotificationCount()); | 271 ASSERT_EQ(2u, ui_manager()->GetNotificationCount()); |
266 | 272 |
267 // We don't use or check the notification's direction and language. | 273 // We don't use or check the notification's direction and language. |
268 const Notification& all_options_notification = | 274 const Notification& all_options_notification = |
269 ui_manager()->GetNotificationAt(1); | 275 ui_manager()->GetNotificationAt(1); |
270 EXPECT_EQ("Title", base::UTF16ToUTF8(all_options_notification.title())); | 276 EXPECT_EQ("Title", base::UTF16ToUTF8(all_options_notification.title())); |
271 EXPECT_EQ("Contents", base::UTF16ToUTF8(all_options_notification.message())); | 277 EXPECT_EQ("Contents", base::UTF16ToUTF8(all_options_notification.message())); |
272 EXPECT_EQ("replace-id", all_options_notification.tag()); | 278 EXPECT_EQ("replace-id", all_options_notification.tag()); |
273 EXPECT_FALSE(all_options_notification.icon().IsEmpty()); | 279 EXPECT_FALSE(all_options_notification.icon().IsEmpty()); |
274 EXPECT_EQ(kIconWidth, all_options_notification.icon().Width()); | 280 EXPECT_EQ(kIconWidth, all_options_notification.icon().Width()); |
275 EXPECT_EQ(kIconHeight, all_options_notification.icon().Height()); | 281 EXPECT_EQ(kIconHeight, all_options_notification.icon().Height()); |
| 282 EXPECT_FALSE(all_options_notification.small_image().IsEmpty()); |
| 283 EXPECT_EQ(kMaxBadgeSize, all_options_notification.small_image().Width()); |
| 284 EXPECT_EQ(kMaxBadgeSize, all_options_notification.small_image().Height()); |
276 EXPECT_TRUE(all_options_notification.renotify()); | 285 EXPECT_TRUE(all_options_notification.renotify()); |
277 EXPECT_TRUE(all_options_notification.silent()); | 286 EXPECT_TRUE(all_options_notification.silent()); |
278 EXPECT_TRUE(all_options_notification.never_timeout()); | 287 EXPECT_TRUE(all_options_notification.never_timeout()); |
279 EXPECT_DOUBLE_EQ(kNotificationTimestamp, | 288 EXPECT_DOUBLE_EQ(kNotificationTimestamp, |
280 all_options_notification.timestamp().ToJsTime()); | 289 all_options_notification.timestamp().ToJsTime()); |
281 EXPECT_EQ(1u, all_options_notification.buttons().size()); | 290 EXPECT_EQ(1u, all_options_notification.buttons().size()); |
282 EXPECT_EQ("actionTitle", | 291 EXPECT_EQ("actionTitle", |
283 base::UTF16ToUTF8(all_options_notification.buttons()[0].title)); | 292 base::UTF16ToUTF8(all_options_notification.buttons()[0].title)); |
284 EXPECT_FALSE(all_options_notification.buttons()[0].icon.IsEmpty()); | 293 EXPECT_FALSE(all_options_notification.buttons()[0].icon.IsEmpty()); |
285 EXPECT_EQ(kIconWidth, all_options_notification.buttons()[0].icon.Width()); | 294 EXPECT_EQ(kIconWidth, all_options_notification.buttons()[0].icon.Width()); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); | 487 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); |
479 | 488 |
480 notification.delegate()->ButtonClick(0); | 489 notification.delegate()->ButtonClick(0); |
481 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 490 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
482 EXPECT_EQ("action_button_click actionId1", script_result); | 491 EXPECT_EQ("action_button_click actionId1", script_result); |
483 | 492 |
484 notification.delegate()->ButtonClick(1); | 493 notification.delegate()->ButtonClick(1); |
485 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 494 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
486 EXPECT_EQ("action_button_click actionId2", script_result); | 495 EXPECT_EQ("action_button_click actionId2", script_result); |
487 } | 496 } |
OLD | NEW |