| 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 | 117 |
| 116 InProcessBrowserTest::SetUpCommandLine(command_line); | 118 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 117 } | 119 } |
| 118 | 120 |
| 119 void PlatformNotificationServiceBrowserTest::SetUp() { | 121 void PlatformNotificationServiceBrowserTest::SetUp() { |
| 120 ui_manager_.reset(new StubNotificationUIManager); | 122 ui_manager_.reset(new StubNotificationUIManager); |
| 121 https_server_.reset( | 123 https_server_.reset( |
| 122 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); | 124 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
| 123 https_server_->ServeFilesFromSourceDirectory(server_root_); | 125 https_server_->ServeFilesFromSourceDirectory(server_root_); |
| 124 ASSERT_TRUE(https_server_->Start()); | 126 ASSERT_TRUE(https_server_->Start()); |
| 125 | |
| 126 service()->SetNotificationUIManagerForTesting(ui_manager_.get()); | |
| 127 | |
| 128 InProcessBrowserTest::SetUp(); | 127 InProcessBrowserTest::SetUp(); |
| 129 } | 128 } |
| 130 | 129 |
| 131 void PlatformNotificationServiceBrowserTest::SetUpOnMainThread() { | 130 void PlatformNotificationServiceBrowserTest::SetUpOnMainThread() { |
| 132 NavigateToTestPage(test_page_url_); | 131 NavigateToTestPage(test_page_url_); |
| 133 | 132 display_service_.reset( |
| 133 new MessageCenterDisplayService(browser()->profile(), ui_manager_.get())); |
| 134 service()->SetNotificationDisplayServiceForTesting(display_service_.get()); |
| 134 InProcessBrowserTest::SetUpOnMainThread(); | 135 InProcessBrowserTest::SetUpOnMainThread(); |
| 135 } | 136 } |
| 136 | 137 |
| 137 void PlatformNotificationServiceBrowserTest::TearDown() { | 138 void PlatformNotificationServiceBrowserTest::TearDown() { |
| 138 service()->SetNotificationUIManagerForTesting(nullptr); | 139 service()->SetNotificationDisplayServiceForTesting(nullptr); |
| 139 } | 140 } |
| 140 | 141 |
| 141 void PlatformNotificationServiceBrowserTest:: | 142 void PlatformNotificationServiceBrowserTest:: |
| 142 GrantNotificationPermissionForTest() const { | 143 GrantNotificationPermissionForTest() const { |
| 143 GURL origin = TestPageUrl().GetOrigin(); | 144 GURL origin = TestPageUrl().GetOrigin(); |
| 144 | 145 |
| 145 DesktopNotificationProfileUtil::GrantPermission(browser()->profile(), origin); | 146 DesktopNotificationProfileUtil::GrantPermission(browser()->profile(), origin); |
| 146 ASSERT_EQ(CONTENT_SETTING_ALLOW, | 147 ASSERT_EQ(CONTENT_SETTING_ALLOW, |
| 147 DesktopNotificationProfileUtil::GetContentSetting( | 148 DesktopNotificationProfileUtil::GetContentSetting( |
| 148 browser()->profile(), origin)); | 149 browser()->profile(), origin)); |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); | 491 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); |
| 491 | 492 |
| 492 notification.delegate()->ButtonClick(0); | 493 notification.delegate()->ButtonClick(0); |
| 493 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 494 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
| 494 EXPECT_EQ("action_button_click actionId1", script_result); | 495 EXPECT_EQ("action_button_click actionId1", script_result); |
| 495 | 496 |
| 496 notification.delegate()->ButtonClick(1); | 497 notification.delegate()->ButtonClick(1); |
| 497 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 498 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
| 498 EXPECT_EQ("action_button_click actionId2", script_result); | 499 EXPECT_EQ("action_button_click actionId2", script_result); |
| 499 } | 500 } |
| OLD | NEW |