| 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/message_center_display_service.h" |
| 16 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" |
| 17 #include "chrome/browser/notifications/notification_test_util.h" | 17 #include "chrome/browser/notifications/notification_test_util.h" |
| 18 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 18 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 19 #include "chrome/browser/permissions/permission_manager.h" | 19 #include "chrome/browser/permissions/permission_manager.h" |
| 20 #include "chrome/browser/permissions/permission_request_manager.h" |
| 20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 22 #include "chrome/browser/ui/website_settings/permission_bubble_manager.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/browser/permission_type.h" | 26 #include "content/public/browser/permission_type.h" |
| 27 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
| 28 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
| 29 #include "net/base/filename_util.h" | 29 #include "net/base/filename_util.h" |
| 30 #include "net/test/embedded_test_server/embedded_test_server.h" | 30 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 31 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
| 32 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" | 32 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 // Executes |script| and stores the result as a string in |result|. A boolean | 81 // Executes |script| and stores the result as a string in |result|. A boolean |
| 82 // will be returned, indicating whether the script was executed successfully. | 82 // will be returned, indicating whether the script was executed successfully. |
| 83 bool RunScript(const std::string& script, std::string* result) const; | 83 bool RunScript(const std::string& script, std::string* result) const; |
| 84 | 84 |
| 85 net::HostPortPair ServerHostPort() const; | 85 net::HostPortPair ServerHostPort() const; |
| 86 GURL TestPageUrl() const; | 86 GURL TestPageUrl() const; |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 std::string RequestAndRespondToPermission( | 89 std::string RequestAndRespondToPermission( |
| 90 PermissionBubbleManager::AutoResponseType bubble_response); | 90 PermissionRequestManager::AutoResponseType bubble_response); |
| 91 | 91 |
| 92 content::WebContents* GetActiveWebContents(Browser* browser) { | 92 content::WebContents* GetActiveWebContents(Browser* browser) { |
| 93 return browser->tab_strip_model()->GetActiveWebContents(); | 93 return browser->tab_strip_model()->GetActiveWebContents(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 const base::FilePath server_root_; | 96 const base::FilePath server_root_; |
| 97 const std::string test_page_url_; | 97 const std::string test_page_url_; |
| 98 std::unique_ptr<StubNotificationUIManager> ui_manager_; | 98 std::unique_ptr<StubNotificationUIManager> ui_manager_; |
| 99 std::unique_ptr<MessageCenterDisplayService> display_service_; | 99 std::unique_ptr<MessageCenterDisplayService> display_service_; |
| 100 std::unique_ptr<net::EmbeddedTestServer> https_server_; | 100 std::unique_ptr<net::EmbeddedTestServer> https_server_; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 const { | 168 const { |
| 169 return https_server_->host_port_pair(); | 169 return https_server_->host_port_pair(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 GURL PlatformNotificationServiceBrowserTest::TestPageUrl() const { | 172 GURL PlatformNotificationServiceBrowserTest::TestPageUrl() const { |
| 173 return https_server_->GetURL(test_page_url_); | 173 return https_server_->GetURL(test_page_url_); |
| 174 } | 174 } |
| 175 | 175 |
| 176 std::string | 176 std::string |
| 177 PlatformNotificationServiceBrowserTest::RequestAndRespondToPermission( | 177 PlatformNotificationServiceBrowserTest::RequestAndRespondToPermission( |
| 178 PermissionBubbleManager::AutoResponseType bubble_response) { | 178 PermissionRequestManager::AutoResponseType bubble_response) { |
| 179 std::string result; | 179 std::string result; |
| 180 content::WebContents* web_contents = GetActiveWebContents(browser()); | 180 content::WebContents* web_contents = GetActiveWebContents(browser()); |
| 181 PermissionBubbleManager::FromWebContents(web_contents) | 181 PermissionRequestManager::FromWebContents(web_contents) |
| 182 ->set_auto_response_for_test(bubble_response); | 182 ->set_auto_response_for_test(bubble_response); |
| 183 EXPECT_TRUE(RunScript("RequestPermission();", &result)); | 183 EXPECT_TRUE(RunScript("RequestPermission();", &result)); |
| 184 return result; | 184 return result; |
| 185 } | 185 } |
| 186 | 186 |
| 187 bool PlatformNotificationServiceBrowserTest::RequestAndAcceptPermission() { | 187 bool PlatformNotificationServiceBrowserTest::RequestAndAcceptPermission() { |
| 188 std::string result = | 188 std::string result = |
| 189 RequestAndRespondToPermission(PermissionBubbleManager::ACCEPT_ALL); | 189 RequestAndRespondToPermission(PermissionRequestManager::ACCEPT_ALL); |
| 190 return "granted" == result; | 190 return "granted" == result; |
| 191 } | 191 } |
| 192 | 192 |
| 193 bool PlatformNotificationServiceBrowserTest::RequestAndDenyPermission() { | 193 bool PlatformNotificationServiceBrowserTest::RequestAndDenyPermission() { |
| 194 std::string result = | 194 std::string result = |
| 195 RequestAndRespondToPermission(PermissionBubbleManager::DENY_ALL); | 195 RequestAndRespondToPermission(PermissionRequestManager::DENY_ALL); |
| 196 return "denied" == result; | 196 return "denied" == result; |
| 197 } | 197 } |
| 198 | 198 |
| 199 // ----------------------------------------------------------------------------- | 199 // ----------------------------------------------------------------------------- |
| 200 | 200 |
| 201 // TODO(peter): Move PlatformNotificationService-related tests over from | 201 // TODO(peter): Move PlatformNotificationService-related tests over from |
| 202 // notification_browsertest.cc to this file. | 202 // notification_browsertest.cc to this file. |
| 203 | 203 |
| 204 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 204 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 205 DisplayPersistentNotificationWithoutPermission) { | 205 DisplayPersistentNotificationWithoutPermission) { |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); | 506 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); |
| 507 | 507 |
| 508 notification.delegate()->ButtonClick(0); | 508 notification.delegate()->ButtonClick(0); |
| 509 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 509 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
| 510 EXPECT_EQ("action_button_click actionId1", script_result); | 510 EXPECT_EQ("action_button_click actionId1", script_result); |
| 511 | 511 |
| 512 notification.delegate()->ButtonClick(1); | 512 notification.delegate()->ButtonClick(1); |
| 513 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 513 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
| 514 EXPECT_EQ("action_button_click actionId2", script_result); | 514 EXPECT_EQ("action_button_click actionId2", script_result); |
| 515 } | 515 } |
| OLD | NEW |