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 <memory> | 5 #include <memory> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.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/message_center_display_service.h" |
15 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.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/permissions/permission_manager.h" | 19 #include "chrome/browser/permissions/permission_manager.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/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" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 std::string RequestAndRespondToPermission( | 88 std::string RequestAndRespondToPermission( |
88 PermissionBubbleManager::AutoResponseType bubble_response); | 89 PermissionBubbleManager::AutoResponseType bubble_response); |
89 | 90 |
90 content::WebContents* GetActiveWebContents(Browser* browser) { | 91 content::WebContents* GetActiveWebContents(Browser* browser) { |
91 return browser->tab_strip_model()->GetActiveWebContents(); | 92 return browser->tab_strip_model()->GetActiveWebContents(); |
92 } | 93 } |
93 | 94 |
94 const base::FilePath server_root_; | 95 const base::FilePath server_root_; |
95 const std::string test_page_url_; | 96 const std::string test_page_url_; |
96 std::unique_ptr<StubNotificationUIManager> ui_manager_; | 97 std::unique_ptr<StubNotificationUIManager> ui_manager_; |
| 98 std::unique_ptr<MessageCenterDisplayService> display_service_; |
97 std::unique_ptr<net::EmbeddedTestServer> https_server_; | 99 std::unique_ptr<net::EmbeddedTestServer> https_server_; |
98 }; | 100 }; |
99 | 101 |
100 // ----------------------------------------------------------------------------- | 102 // ----------------------------------------------------------------------------- |
101 | 103 |
102 namespace { | 104 namespace { |
103 const char kTestFileName[] = "notifications/platform_notification_service.html"; | 105 const char kTestFileName[] = "notifications/platform_notification_service.html"; |
104 } | 106 } |
105 | 107 |
106 PlatformNotificationServiceBrowserTest::PlatformNotificationServiceBrowserTest() | 108 PlatformNotificationServiceBrowserTest::PlatformNotificationServiceBrowserTest() |
107 : server_root_(FILE_PATH_LITERAL("chrome/test/data")), | 109 : server_root_(FILE_PATH_LITERAL("chrome/test/data")), |
108 // The test server has a base directory that doesn't exist in the | 110 // The test server has a base directory that doesn't exist in the |
109 // filesystem. | 111 // filesystem. |
110 test_page_url_(std::string("/") + kTestFileName) {} | 112 test_page_url_(std::string("/") + kTestFileName) {} |
111 | 113 |
112 void PlatformNotificationServiceBrowserTest::SetUpCommandLine( | 114 void PlatformNotificationServiceBrowserTest::SetUpCommandLine( |
113 base::CommandLine* command_line) { | 115 base::CommandLine* command_line) { |
114 command_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); | 116 command_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); |
115 command_line->AppendSwitch(switches::kEnableNotificationActionIcons); | 117 command_line->AppendSwitch(switches::kEnableNotificationActionIcons); |
116 | 118 |
117 InProcessBrowserTest::SetUpCommandLine(command_line); | 119 InProcessBrowserTest::SetUpCommandLine(command_line); |
118 } | 120 } |
119 | 121 |
120 void PlatformNotificationServiceBrowserTest::SetUp() { | 122 void PlatformNotificationServiceBrowserTest::SetUp() { |
121 ui_manager_.reset(new StubNotificationUIManager); | 123 ui_manager_.reset(new StubNotificationUIManager); |
122 https_server_.reset( | 124 https_server_.reset( |
123 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); | 125 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
124 https_server_->ServeFilesFromSourceDirectory(server_root_); | 126 https_server_->ServeFilesFromSourceDirectory(server_root_); |
125 ASSERT_TRUE(https_server_->Start()); | 127 ASSERT_TRUE(https_server_->Start()); |
126 | |
127 service()->SetNotificationUIManagerForTesting(ui_manager_.get()); | |
128 | |
129 InProcessBrowserTest::SetUp(); | 128 InProcessBrowserTest::SetUp(); |
130 } | 129 } |
131 | 130 |
132 void PlatformNotificationServiceBrowserTest::SetUpOnMainThread() { | 131 void PlatformNotificationServiceBrowserTest::SetUpOnMainThread() { |
133 NavigateToTestPage(test_page_url_); | 132 NavigateToTestPage(test_page_url_); |
134 | 133 display_service_.reset( |
| 134 new MessageCenterDisplayService(browser()->profile(), ui_manager_.get())); |
| 135 service()->SetNotificationDisplayServiceForTesting(display_service_.get()); |
135 InProcessBrowserTest::SetUpOnMainThread(); | 136 InProcessBrowserTest::SetUpOnMainThread(); |
136 } | 137 } |
137 | 138 |
138 void PlatformNotificationServiceBrowserTest::TearDown() { | 139 void PlatformNotificationServiceBrowserTest::TearDown() { |
139 service()->SetNotificationUIManagerForTesting(nullptr); | 140 service()->SetNotificationDisplayServiceForTesting(nullptr); |
140 } | 141 } |
141 | 142 |
142 void PlatformNotificationServiceBrowserTest:: | 143 void PlatformNotificationServiceBrowserTest:: |
143 GrantNotificationPermissionForTest() const { | 144 GrantNotificationPermissionForTest() const { |
144 GURL origin = TestPageUrl().GetOrigin(); | 145 GURL origin = TestPageUrl().GetOrigin(); |
145 | 146 |
146 DesktopNotificationProfileUtil::GrantPermission(browser()->profile(), origin); | 147 DesktopNotificationProfileUtil::GrantPermission(browser()->profile(), origin); |
147 ASSERT_EQ(CONTENT_SETTING_ALLOW, | 148 ASSERT_EQ(CONTENT_SETTING_ALLOW, |
148 DesktopNotificationProfileUtil::GetContentSetting( | 149 DesktopNotificationProfileUtil::GetContentSetting( |
149 browser()->profile(), origin)); | 150 browser()->profile(), origin)); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); | 492 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); |
492 | 493 |
493 notification.delegate()->ButtonClick(0); | 494 notification.delegate()->ButtonClick(0); |
494 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 495 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
495 EXPECT_EQ("action_button_click actionId1", script_result); | 496 EXPECT_EQ("action_button_click actionId1", script_result); |
496 | 497 |
497 notification.delegate()->ButtonClick(1); | 498 notification.delegate()->ButtonClick(1); |
498 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 499 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
499 EXPECT_EQ("action_button_click actionId2", script_result); | 500 EXPECT_EQ("action_button_click actionId2", script_result); |
500 } | 501 } |
OLD | NEW |