Chromium Code Reviews| Index: chrome/browser/notifications/platform_notification_service_browsertest.cc |
| diff --git a/chrome/browser/notifications/platform_notification_service_browsertest.cc b/chrome/browser/notifications/platform_notification_service_browsertest.cc |
| index 3ea3b1cb5863958d558c0afa1e33310ca4ebf38e..d79ea5b0fa2f3a9dd60bf1e25546fc3478a63824 100644 |
| --- a/chrome/browser/notifications/platform_notification_service_browsertest.cc |
| +++ b/chrome/browser/notifications/platform_notification_service_browsertest.cc |
| @@ -7,6 +7,7 @@ |
| #include "base/command_line.h" |
| #include "base/files/file_path.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "chrome/browser/infobars/infobar_service.h" |
| #include "chrome/browser/notifications/notification_test_util.h" |
| #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| @@ -19,6 +20,7 @@ |
| #include "components/infobars/core/infobar_manager.h" |
| #include "content/public/common/content_switches.h" |
| #include "content/public/test/browser_test_utils.h" |
| +#include "net/base/filename_util.h" |
| #include "net/test/spawned_test_server/spawned_test_server.h" |
| // ----------------------------------------------------------------------------- |
| @@ -81,6 +83,7 @@ void InfoBarResponder::Respond(ConfirmInfoBarDelegate* delegate) { |
| class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest { |
| public: |
| + PlatformNotificationServiceBrowserTest(); |
| ~PlatformNotificationServiceBrowserTest() override {} |
| // InProcessBrowserTest overrides. |
| @@ -98,6 +101,8 @@ class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest { |
| // Returns the UI Manager on which notifications will be displayed. |
| StubNotificationUIManager* ui_manager() const { return ui_manager_.get(); } |
| + const base::FilePath& server_root() const { return server_root_; } |
| + |
| // Navigates the browser to the test page indicated by |path|. |
| void NavigateToTestPage(const std::string& path) const; |
| @@ -105,7 +110,10 @@ class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest { |
| // will be returned, indicating whether the script was executed successfully. |
| bool RunScript(const std::string& script, std::string* result) const; |
| + net::HostPortPair ServerHostPort() const; |
| + |
| private: |
| + const base::FilePath server_root_; |
| scoped_ptr<StubNotificationUIManager> ui_manager_; |
| scoped_ptr<net::SpawnedTestServer> https_server_; |
| }; |
| @@ -114,11 +122,13 @@ class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest { |
| namespace { |
| -const char kTestPageUrl[] = |
| - "files/notifications/platform_notification_service.html"; |
| - |
| +const char kTestFileName[] = "notifications/platform_notification_service.html"; |
| } // namespace |
|
Peter Beverloo
2015/01/27 13:37:04
micro nit:
namespace {
const char kTestFileName[]
dewittj
2015/01/27 23:10:12
Done.
|
| +PlatformNotificationServiceBrowserTest::PlatformNotificationServiceBrowserTest() |
| + : server_root_(FILE_PATH_LITERAL("chrome/test/data")) { |
| +} |
| + |
| void PlatformNotificationServiceBrowserTest::SetUpCommandLine( |
| base::CommandLine* command_line) { |
| command_line->AppendSwitch( |
| @@ -131,9 +141,8 @@ void PlatformNotificationServiceBrowserTest::SetUp() { |
| ui_manager_.reset(new StubNotificationUIManager); |
| https_server_.reset(new net::SpawnedTestServer( |
| net::SpawnedTestServer::TYPE_HTTPS, |
| - net::BaseTestServer::SSLOptions( |
| - net::BaseTestServer::SSLOptions::CERT_OK), |
| - base::FilePath(FILE_PATH_LITERAL("chrome/test/data/")))); |
| + net::BaseTestServer::SSLOptions(net::BaseTestServer::SSLOptions::CERT_OK), |
| + server_root_)); |
| ASSERT_TRUE(https_server_->Start()); |
| service()->SetNotificationUIManagerForTesting(ui_manager_.get()); |
| @@ -142,7 +151,11 @@ void PlatformNotificationServiceBrowserTest::SetUp() { |
| } |
| void PlatformNotificationServiceBrowserTest::SetUpOnMainThread() { |
| - NavigateToTestPage(kTestPageUrl); |
| + // The test server has a base directory that doesn't exist in the |
| + // filesystem. |
| + std::string test_page_url = std::string("files/") + kTestFileName; |
| + |
| + NavigateToTestPage(test_page_url); |
| InProcessBrowserTest::SetUpOnMainThread(); |
| } |
| @@ -164,6 +177,11 @@ bool PlatformNotificationServiceBrowserTest::RunScript( |
| result); |
| } |
| +net::HostPortPair PlatformNotificationServiceBrowserTest::ServerHostPort() |
| + const { |
| + return https_server_->host_port_pair(); |
| +} |
| + |
| // ----------------------------------------------------------------------------- |
| // TODO(peter): Move PlatformNotificationService-related tests over from |
| @@ -230,3 +248,42 @@ IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| ASSERT_EQ(0u, ui_manager()->GetNotificationCount()); |
| } |
| + |
| +IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| + TestDisplayOriginContextMessage) { |
| + std::string script_result; |
| + |
| + // Creates a simple notification. |
| + InfoBarResponder accepting_responder(browser(), true); |
| + ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); |
| + ASSERT_EQ("granted", script_result); |
| + ASSERT_TRUE(RunScript("DisplayPersistentNotification()", &script_result)); |
| + |
| + net::HostPortPair host_port = ServerHostPort(); |
| + |
| + const Notification& notification = ui_manager()->GetNotificationAt(0); |
| + |
| + EXPECT_EQ(base::UTF8ToUTF16(host_port.ToString()), |
| + notification.context_message()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| + CheckFilePermissionNotGranted) { |
| + base::FilePath full_file_path = |
| + server_root().Append(base::FilePath::FromUTF8Unsafe(kTestFileName)); |
| + GURL file_url(net::FilePathToFileURL(full_file_path)); |
|
Peter Beverloo
2015/01/27 13:37:04
QQ: If server_root_ is "chrome/test/data" (which i
dewittj
2015/01/27 23:10:12
Right, looks like the try bots failed on that. It
|
| + ui_test_utils::NavigateToURL(browser(), file_url); |
| + |
| + std::string script_result; |
| + |
| + InfoBarResponder accepting_responder(browser(), true); |
| + |
| + // TODO(dewittj): Update the |
| + // |PlatformNotificationServiceImpl::WebOriginDisplayName| function to |
| + // properly display file:// URL origins. See crbug.com/402191. |
| + ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); |
| + EXPECT_EQ("default", script_result) |
| + << "If this test fails, you may have fixed a bug preventing file origins " |
| + << "from sending their origin from Blink; if so you need to update the " |
| + << "display function for notification origins to show the file path."; |
| +} |