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

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

Issue 1693583002: Add browser test for notification action icons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ActionIconToJava
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 "base/time/time.h"
14 #include "chrome/browser/notifications/desktop_notification_profile_util.h" 14 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
15 #include "chrome/browser/notifications/notification.h"
15 #include "chrome/browser/notifications/notification_permission_context.h" 16 #include "chrome/browser/notifications/notification_permission_context.h"
16 #include "chrome/browser/notifications/notification_permission_context_factory.h " 17 #include "chrome/browser/notifications/notification_permission_context_factory.h "
17 #include "chrome/browser/notifications/notification_test_util.h" 18 #include "chrome/browser/notifications/notification_test_util.h"
18 #include "chrome/browser/notifications/platform_notification_service_impl.h" 19 #include "chrome/browser/notifications/platform_notification_service_impl.h"
19 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
21 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 22 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
22 #include "chrome/common/chrome_switches.h"
23 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
24 #include "chrome/test/base/in_process_browser_test.h" 24 #include "chrome/test/base/in_process_browser_test.h"
25 #include "chrome/test/base/ui_test_utils.h" 25 #include "chrome/test/base/ui_test_utils.h"
26 #include "content/public/common/content_switches.h"
26 #include "content/public/test/browser_test_utils.h" 27 #include "content/public/test/browser_test_utils.h"
27 #include "net/base/filename_util.h" 28 #include "net/base/filename_util.h"
28 #include "net/test/embedded_test_server/embedded_test_server.h" 29 #include "net/test/embedded_test_server/embedded_test_server.h"
29 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
30 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
31 32
32 // ----------------------------------------------------------------------------- 33 // -----------------------------------------------------------------------------
33 34
34 // 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.
35 const int kIconWidth = 100; 36 const int kIconWidth = 100;
36 const int kIconHeight = 100; 37 const int kIconHeight = 100;
37 38
38 const int kNotificationVibrationPattern[] = { 100, 200, 300 }; 39 const int kNotificationVibrationPattern[] = { 100, 200, 300 };
39 const double kNotificationTimestamp = 621046800000.; 40 const double kNotificationTimestamp = 621046800000.;
40 41
41 class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest { 42 class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest {
42 public: 43 public:
43 PlatformNotificationServiceBrowserTest(); 44 PlatformNotificationServiceBrowserTest();
44 ~PlatformNotificationServiceBrowserTest() override {} 45 ~PlatformNotificationServiceBrowserTest() override {}
45 46
46 // InProcessBrowserTest overrides. 47 // InProcessBrowserTest overrides.
48 void SetUpCommandLine(base::CommandLine* command_line) override;
47 void SetUp() override; 49 void SetUp() override;
48 void SetUpOnMainThread() override; 50 void SetUpOnMainThread() override;
49 void TearDown() override; 51 void TearDown() override;
50 52
51 protected: 53 protected:
52 // Returns the Platform Notification Service these unit tests are for. 54 // Returns the Platform Notification Service these unit tests are for.
53 PlatformNotificationServiceImpl* service() const { 55 PlatformNotificationServiceImpl* service() const {
54 return PlatformNotificationServiceImpl::GetInstance(); 56 return PlatformNotificationServiceImpl::GetInstance();
55 } 57 }
56 58
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 namespace { 97 namespace {
96 const char kTestFileName[] = "notifications/platform_notification_service.html"; 98 const char kTestFileName[] = "notifications/platform_notification_service.html";
97 } 99 }
98 100
99 PlatformNotificationServiceBrowserTest::PlatformNotificationServiceBrowserTest() 101 PlatformNotificationServiceBrowserTest::PlatformNotificationServiceBrowserTest()
100 : server_root_(FILE_PATH_LITERAL("chrome/test/data")), 102 : server_root_(FILE_PATH_LITERAL("chrome/test/data")),
101 // The test server has a base directory that doesn't exist in the 103 // The test server has a base directory that doesn't exist in the
102 // filesystem. 104 // filesystem.
103 test_page_url_(std::string("/") + kTestFileName) {} 105 test_page_url_(std::string("/") + kTestFileName) {}
104 106
107 void PlatformNotificationServiceBrowserTest::SetUpCommandLine(
108 base::CommandLine* command_line) {
109 command_line->AppendSwitch(switches::kEnableNotificationActionIcons);
110
111 InProcessBrowserTest::SetUpCommandLine(command_line);
112 }
113
105 void PlatformNotificationServiceBrowserTest::SetUp() { 114 void PlatformNotificationServiceBrowserTest::SetUp() {
106 ui_manager_.reset(new StubNotificationUIManager); 115 ui_manager_.reset(new StubNotificationUIManager);
107 https_server_.reset( 116 https_server_.reset(
108 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); 117 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS));
109 https_server_->ServeFilesFromSourceDirectory(server_root_); 118 https_server_->ServeFilesFromSourceDirectory(server_root_);
110 ASSERT_TRUE(https_server_->Start()); 119 ASSERT_TRUE(https_server_->Start());
111 120
112 service()->SetNotificationUIManagerForTesting(ui_manager_.get()); 121 service()->SetNotificationUIManagerForTesting(ui_manager_.get());
113 122
114 InProcessBrowserTest::SetUp(); 123 InProcessBrowserTest::SetUp();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 241
233 // We don't use or check the notification's direction and language. 242 // We don't use or check the notification's direction and language.
234 const Notification& default_notification = ui_manager()->GetNotificationAt(0); 243 const Notification& default_notification = ui_manager()->GetNotificationAt(0);
235 EXPECT_EQ("Some title", base::UTF16ToUTF8(default_notification.title())); 244 EXPECT_EQ("Some title", base::UTF16ToUTF8(default_notification.title()));
236 EXPECT_EQ("", base::UTF16ToUTF8(default_notification.message())); 245 EXPECT_EQ("", base::UTF16ToUTF8(default_notification.message()));
237 EXPECT_EQ("", default_notification.tag()); 246 EXPECT_EQ("", default_notification.tag());
238 EXPECT_TRUE(default_notification.icon().IsEmpty()); 247 EXPECT_TRUE(default_notification.icon().IsEmpty());
239 EXPECT_FALSE(default_notification.renotify()); 248 EXPECT_FALSE(default_notification.renotify());
240 EXPECT_FALSE(default_notification.silent()); 249 EXPECT_FALSE(default_notification.silent());
241 EXPECT_FALSE(default_notification.never_timeout()); 250 EXPECT_FALSE(default_notification.never_timeout());
251 EXPECT_EQ(0u, default_notification.buttons().size());
242 252
243 // Verifies that the notification's default timestamp is set in the last 30 253 // Verifies that the notification's default timestamp is set in the last 30
244 // seconds. This number has no significance, but it needs to be significantly 254 // seconds. This number has no significance, but it needs to be significantly
245 // high to avoid flakiness in the test. 255 // high to avoid flakiness in the test.
246 EXPECT_NEAR(default_notification.timestamp().ToJsTime(), 256 EXPECT_NEAR(default_notification.timestamp().ToJsTime(),
247 base::Time::Now().ToJsTime(), 30 * 1000); 257 base::Time::Now().ToJsTime(), 30 * 1000);
248 258
249 // Now, test the non-default values. 259 // Now, test the non-default values.
250 260
251 ASSERT_TRUE(RunScript("DisplayPersistentAllOptionsNotification()", 261 ASSERT_TRUE(RunScript("DisplayPersistentAllOptionsNotification()",
252 &script_result)); 262 &script_result));
253 EXPECT_EQ("ok", script_result); 263 EXPECT_EQ("ok", script_result);
254 264
255 ASSERT_EQ(2u, ui_manager()->GetNotificationCount()); 265 ASSERT_EQ(2u, ui_manager()->GetNotificationCount());
256 266
257 // We don't use or check the notification's direction and language. 267 // We don't use or check the notification's direction and language.
258 const Notification& all_options_notification = 268 const Notification& all_options_notification =
259 ui_manager()->GetNotificationAt(1); 269 ui_manager()->GetNotificationAt(1);
260 EXPECT_EQ("Title", base::UTF16ToUTF8(all_options_notification.title())); 270 EXPECT_EQ("Title", base::UTF16ToUTF8(all_options_notification.title()));
261 EXPECT_EQ("Contents", base::UTF16ToUTF8(all_options_notification.message())); 271 EXPECT_EQ("Contents", base::UTF16ToUTF8(all_options_notification.message()));
262 EXPECT_EQ("replace-id", all_options_notification.tag()); 272 EXPECT_EQ("replace-id", all_options_notification.tag());
263 EXPECT_FALSE(all_options_notification.icon().IsEmpty()); 273 EXPECT_FALSE(all_options_notification.icon().IsEmpty());
274 EXPECT_EQ(kIconWidth, all_options_notification.icon().Width());
275 EXPECT_EQ(kIconHeight, all_options_notification.icon().Height());
264 EXPECT_TRUE(all_options_notification.renotify()); 276 EXPECT_TRUE(all_options_notification.renotify());
265 EXPECT_TRUE(all_options_notification.silent()); 277 EXPECT_TRUE(all_options_notification.silent());
266 EXPECT_TRUE(all_options_notification.never_timeout()); 278 EXPECT_TRUE(all_options_notification.never_timeout());
267 EXPECT_DOUBLE_EQ(kNotificationTimestamp, 279 EXPECT_DOUBLE_EQ(kNotificationTimestamp,
268 all_options_notification.timestamp().ToJsTime()); 280 all_options_notification.timestamp().ToJsTime());
269 281 EXPECT_EQ(1u, all_options_notification.buttons().size());
270 EXPECT_EQ(kIconWidth, all_options_notification.icon().Width()); 282 EXPECT_EQ("actionTitle",
271 EXPECT_EQ(kIconHeight, all_options_notification.icon().Height()); 283 base::UTF16ToUTF8(all_options_notification.buttons()[0].title));
284 EXPECT_FALSE(all_options_notification.buttons()[0].icon.IsEmpty());
285 EXPECT_EQ(kIconWidth, all_options_notification.buttons()[0].icon.Width());
286 EXPECT_EQ(kIconHeight, all_options_notification.buttons()[0].icon.Height());
272 } 287 }
273 288
274 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 289 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
275 WebNotificationSiteSettingsButton) { 290 WebNotificationSiteSettingsButton) {
276 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); 291 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest());
277 292
278 std::string script_result; 293 std::string script_result;
279 ASSERT_TRUE( 294 ASSERT_TRUE(
280 RunScript("DisplayPersistentAllOptionsNotification()", &script_result)); 295 RunScript("DisplayPersistentAllOptionsNotification()", &script_result));
281 EXPECT_EQ("ok", script_result); 296 EXPECT_EQ("ok", script_result);
282 297
283 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 298 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
284 299
285 const Notification& notification = ui_manager()->GetNotificationAt(0); 300 const Notification& notification = ui_manager()->GetNotificationAt(0);
286 const std::vector<message_center::ButtonInfo>& buttons = 301 const std::vector<message_center::ButtonInfo>& buttons =
287 notification.buttons(); 302 notification.buttons();
288 EXPECT_EQ(0u, buttons.size()); 303 EXPECT_EQ(1u, buttons.size());
johnme 2016/02/11 18:13:33 Nit: Instead of changing this line, change the Run
Michael van Ouwerkerk 2016/02/12 11:04:43 Done.
289 304
290 notification.delegate()->SettingsClick(); 305 notification.delegate()->SettingsClick();
291 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 306 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
292 content::WebContents* web_contents = 307 content::WebContents* web_contents =
293 browser()->tab_strip_model()->GetActiveWebContents(); 308 browser()->tab_strip_model()->GetActiveWebContents();
294 ASSERT_TRUE(content::WaitForLoadStop(web_contents)); 309 ASSERT_TRUE(content::WaitForLoadStop(web_contents));
295 ASSERT_EQ("chrome://settings/contentExceptions#notifications", 310 ASSERT_EQ("chrome://settings/contentExceptions#notifications",
296 web_contents->GetLastCommittedURL().spec()); 311 web_contents->GetLastCommittedURL().spec());
297 } 312 }
298 313
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 454
440 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 455 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
441 456
442 const Notification& notification = ui_manager()->GetNotificationAt(0); 457 const Notification& notification = ui_manager()->GetNotificationAt(0);
443 EXPECT_FALSE(notification.icon().IsEmpty()); 458 EXPECT_FALSE(notification.icon().IsEmpty());
444 459
445 EXPECT_EQ("Blob Title", base::UTF16ToUTF8(notification.title())); 460 EXPECT_EQ("Blob Title", base::UTF16ToUTF8(notification.title()));
446 EXPECT_EQ(kIconWidth, notification.icon().Width()); 461 EXPECT_EQ(kIconWidth, notification.icon().Width());
447 EXPECT_EQ(kIconHeight, notification.icon().Height()); 462 EXPECT_EQ(kIconHeight, notification.icon().Height());
448 } 463 }
464
465 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
466 DisplayPersistentNotificationWithActionButtons) {
467 RequestAndAcceptPermission();
468
469 std::string script_result;
470 ASSERT_TRUE(RunScript("DisplayPersistentNotificationWithActionButtons()",
471 &script_result));
472 EXPECT_EQ("ok", script_result);
473 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
474
475 const Notification& notification = ui_manager()->GetNotificationAt(0);
476 ASSERT_EQ(2u, notification.buttons().size());
johnme 2016/02/11 18:13:33 Nit: this still doesn't check that the order of ti
Michael van Ouwerkerk 2016/02/12 11:04:43 Done.
477
478 notification.delegate()->ButtonClick(0);
479 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result));
480 EXPECT_EQ("action_button_click actionId1", script_result);
481
482 notification.delegate()->ButtonClick(1);
483 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result));
484 EXPECT_EQ("action_button_click actionId2", script_result);
485 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698