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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
13 #include "chrome/browser/notifications/desktop_notification_service.h" | 13 #include "chrome/browser/notifications/desktop_notification_service.h" |
14 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 14 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
15 #include "chrome/browser/notifications/notification_test_util.h" | 15 #include "chrome/browser/notifications/notification_test_util.h" |
16 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 16 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
19 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
20 #include "chrome/test/base/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
21 #include "components/infobars/core/confirm_infobar_delegate.h" | 21 #include "components/infobars/core/confirm_infobar_delegate.h" |
22 #include "components/infobars/core/infobar.h" | 22 #include "components/infobars/core/infobar.h" |
23 #include "components/infobars/core/infobar_manager.h" | 23 #include "components/infobars/core/infobar_manager.h" |
24 #include "content/public/common/content_switches.h" | |
25 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
26 #include "net/base/filename_util.h" | 25 #include "net/base/filename_util.h" |
27 #include "net/test/spawned_test_server/spawned_test_server.h" | 26 #include "net/test/spawned_test_server/spawned_test_server.h" |
28 | 27 |
29 // ----------------------------------------------------------------------------- | 28 // ----------------------------------------------------------------------------- |
30 | 29 |
31 // Accept or rejects the first shown confirm infobar. The infobar will be | 30 // Accept or rejects the first shown confirm infobar. The infobar will be |
32 // responsed to asynchronously, to imitate the behavior of a user. | 31 // responsed to asynchronously, to imitate the behavior of a user. |
33 // TODO(peter): Generalize this class, as it's commonly useful. | 32 // TODO(peter): Generalize this class, as it's commonly useful. |
34 class InfoBarResponder : public infobars::InfoBarManager::Observer { | 33 class InfoBarResponder : public infobars::InfoBarManager::Observer { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 82 } |
84 | 83 |
85 // ----------------------------------------------------------------------------- | 84 // ----------------------------------------------------------------------------- |
86 | 85 |
87 class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest { | 86 class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest { |
88 public: | 87 public: |
89 PlatformNotificationServiceBrowserTest(); | 88 PlatformNotificationServiceBrowserTest(); |
90 ~PlatformNotificationServiceBrowserTest() override {} | 89 ~PlatformNotificationServiceBrowserTest() override {} |
91 | 90 |
92 // InProcessBrowserTest overrides. | 91 // InProcessBrowserTest overrides. |
93 void SetUpCommandLine(base::CommandLine* command_line) override; | |
94 void SetUp() override; | 92 void SetUp() override; |
95 void SetUpOnMainThread() override; | 93 void SetUpOnMainThread() override; |
96 void TearDown() override; | 94 void TearDown() override; |
97 | 95 |
98 protected: | 96 protected: |
99 // Returns the Platform Notification Service these unit tests are for. | 97 // Returns the Platform Notification Service these unit tests are for. |
100 PlatformNotificationServiceImpl* service() const { | 98 PlatformNotificationServiceImpl* service() const { |
101 return PlatformNotificationServiceImpl::GetInstance(); | 99 return PlatformNotificationServiceImpl::GetInstance(); |
102 } | 100 } |
103 | 101 |
(...skipping 25 matching lines...) Expand all Loading... |
129 const char kTestFileName[] = "notifications/platform_notification_service.html"; | 127 const char kTestFileName[] = "notifications/platform_notification_service.html"; |
130 } | 128 } |
131 | 129 |
132 PlatformNotificationServiceBrowserTest::PlatformNotificationServiceBrowserTest() | 130 PlatformNotificationServiceBrowserTest::PlatformNotificationServiceBrowserTest() |
133 : server_root_(FILE_PATH_LITERAL("chrome/test/data")), | 131 : server_root_(FILE_PATH_LITERAL("chrome/test/data")), |
134 // The test server has a base directory that doesn't exist in the | 132 // The test server has a base directory that doesn't exist in the |
135 // filesystem. | 133 // filesystem. |
136 test_page_url_(std::string("files/") + kTestFileName) { | 134 test_page_url_(std::string("files/") + kTestFileName) { |
137 } | 135 } |
138 | 136 |
139 void PlatformNotificationServiceBrowserTest::SetUpCommandLine( | |
140 base::CommandLine* command_line) { | |
141 command_line->AppendSwitch( | |
142 switches::kEnableExperimentalWebPlatformFeatures); | |
143 | |
144 InProcessBrowserTest::SetUpCommandLine(command_line); | |
145 } | |
146 | |
147 void PlatformNotificationServiceBrowserTest::SetUp() { | 137 void PlatformNotificationServiceBrowserTest::SetUp() { |
148 ui_manager_.reset(new StubNotificationUIManager); | 138 ui_manager_.reset(new StubNotificationUIManager); |
149 https_server_.reset(new net::SpawnedTestServer( | 139 https_server_.reset(new net::SpawnedTestServer( |
150 net::SpawnedTestServer::TYPE_HTTPS, | 140 net::SpawnedTestServer::TYPE_HTTPS, |
151 net::BaseTestServer::SSLOptions(net::BaseTestServer::SSLOptions::CERT_OK), | 141 net::BaseTestServer::SSLOptions(net::BaseTestServer::SSLOptions::CERT_OK), |
152 server_root_)); | 142 server_root_)); |
153 ASSERT_TRUE(https_server_->Start()); | 143 ASSERT_TRUE(https_server_->Start()); |
154 | 144 |
155 service()->SetNotificationUIManagerForTesting(ui_manager_.get()); | 145 service()->SetNotificationUIManagerForTesting(ui_manager_.get()); |
156 | 146 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 | 297 |
308 InfoBarResponder accepting_responder_file(browser(), true); | 298 InfoBarResponder accepting_responder_file(browser(), true); |
309 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); | 299 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); |
310 EXPECT_EQ("granted", script_result); | 300 EXPECT_EQ("granted", script_result); |
311 | 301 |
312 EXPECT_FALSE(notification_service->IsNotifierEnabled(file_notifier)) | 302 EXPECT_FALSE(notification_service->IsNotifierEnabled(file_notifier)) |
313 << "If this test fails, you may have fixed a bug preventing file origins " | 303 << "If this test fails, you may have fixed a bug preventing file origins " |
314 << "from sending their origin from Blink; if so you need to update the " | 304 << "from sending their origin from Blink; if so you need to update the " |
315 << "display function for notification origins to show the file path."; | 305 << "display function for notification origins to show the file path."; |
316 } | 306 } |
OLD | NEW |