Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: chrome/browser/notifications/platform_notification_service_browsertest.cc

Issue 661643002: Adds a context message of the security origin for web notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/strings/utf_string_conversions.h"
10 #include "chrome/browser/infobars/infobar_service.h" 11 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/notifications/notification_test_util.h" 12 #include "chrome/browser/notifications/notification_test_util.h"
12 #include "chrome/browser/notifications/platform_notification_service_impl.h" 13 #include "chrome/browser/notifications/platform_notification_service_impl.h"
13 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/test/base/in_process_browser_test.h" 16 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
17 #include "components/infobars/core/confirm_infobar_delegate.h" 18 #include "components/infobars/core/confirm_infobar_delegate.h"
18 #include "components/infobars/core/infobar.h" 19 #include "components/infobars/core/infobar.h"
19 #include "components/infobars/core/infobar_manager.h" 20 #include "components/infobars/core/infobar_manager.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // Returns the UI Manager on which notifications will be displayed. 99 // Returns the UI Manager on which notifications will be displayed.
99 StubNotificationUIManager* ui_manager() const { return ui_manager_.get(); } 100 StubNotificationUIManager* ui_manager() const { return ui_manager_.get(); }
100 101
101 // Navigates the browser to the test page indicated by |path|. 102 // Navigates the browser to the test page indicated by |path|.
102 void NavigateToTestPage(const std::string& path) const; 103 void NavigateToTestPage(const std::string& path) const;
103 104
104 // Executes |script| and stores the result as a string in |result|. A boolean 105 // Executes |script| and stores the result as a string in |result|. A boolean
105 // will be returned, indicating whether the script was executed successfully. 106 // will be returned, indicating whether the script was executed successfully.
106 bool RunScript(const std::string& script, std::string* result) const; 107 bool RunScript(const std::string& script, std::string* result) const;
107 108
109 net::HostPortPair ServerHostPort() const;
110
108 private: 111 private:
109 scoped_ptr<StubNotificationUIManager> ui_manager_; 112 scoped_ptr<StubNotificationUIManager> ui_manager_;
110 scoped_ptr<net::SpawnedTestServer> https_server_; 113 scoped_ptr<net::SpawnedTestServer> https_server_;
111 }; 114 };
112 115
113 // ----------------------------------------------------------------------------- 116 // -----------------------------------------------------------------------------
114 117
115 namespace { 118 namespace {
116 119
117 const char kTestPageUrl[] = 120 const char kTestPageUrl[] =
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 160 }
158 161
159 bool PlatformNotificationServiceBrowserTest::RunScript( 162 bool PlatformNotificationServiceBrowserTest::RunScript(
160 const std::string& script, std::string* result) const { 163 const std::string& script, std::string* result) const {
161 return content::ExecuteScriptAndExtractString( 164 return content::ExecuteScriptAndExtractString(
162 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), 165 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(),
163 script, 166 script,
164 result); 167 result);
165 } 168 }
166 169
170 net::HostPortPair PlatformNotificationServiceBrowserTest::ServerHostPort()
171 const {
172 return https_server_->host_port_pair();
173 }
174
167 // ----------------------------------------------------------------------------- 175 // -----------------------------------------------------------------------------
168 176
169 // TODO(peter): Move PlatformNotificationService-related tests over from 177 // TODO(peter): Move PlatformNotificationService-related tests over from
170 // notification_browsertest.cc to this file. 178 // notification_browsertest.cc to this file.
171 179
172 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 180 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
173 DisplayPersistentNotificationWithoutPermission) { 181 DisplayPersistentNotificationWithoutPermission) {
174 std::string script_result; 182 std::string script_result;
175 183
176 InfoBarResponder accepting_responder(browser(), false); 184 InfoBarResponder accepting_responder(browser(), false);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 231 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
224 232
225 const Notification& notification = ui_manager()->GetNotificationAt(0); 233 const Notification& notification = ui_manager()->GetNotificationAt(0);
226 notification.delegate()->Click(); 234 notification.delegate()->Click();
227 235
228 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); 236 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result));
229 EXPECT_EQ("action_close", script_result); 237 EXPECT_EQ("action_close", script_result);
230 238
231 ASSERT_EQ(0u, ui_manager()->GetNotificationCount()); 239 ASSERT_EQ(0u, ui_manager()->GetNotificationCount());
232 } 240 }
241
242 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
243 TestDisplayOriginContextMessage) {
244 std::string script_result;
245
246 // Creates a simple notification.
247 InfoBarResponder accepting_responder(browser(), true);
248 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
249 ASSERT_EQ("granted", script_result);
250 ASSERT_TRUE(RunScript("DisplayPersistentNotification()", &script_result));
251
252 net::HostPortPair host_port = ServerHostPort();
253
254 const Notification& notification = ui_manager()->GetNotificationAt(0);
255
256 EXPECT_EQ(base::UTF8ToUTF16(host_port.ToString()),
257 notification.context_message());
258 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698