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

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

Issue 1175443002: Revert of Convert the WebRtcTestBase to use infobar and bubble autoresponders (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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/path_service.h" 10 #include "base/path_service.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 151
152 // ----------------------------------------------------------------------------- 152 // -----------------------------------------------------------------------------
153 153
154 // TODO(peter): Move PlatformNotificationService-related tests over from 154 // TODO(peter): Move PlatformNotificationService-related tests over from
155 // notification_browsertest.cc to this file. 155 // notification_browsertest.cc to this file.
156 156
157 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 157 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
158 DisplayPersistentNotificationWithoutPermission) { 158 DisplayPersistentNotificationWithoutPermission) {
159 std::string script_result; 159 std::string script_result;
160 160
161 InfoBarResponder cancelling_responder(GetInfoBarService(), 161 InfoBarResponder cancelling_responder(GetInfoBarService(), false);
162 InfoBarResponder::DENY);
163 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 162 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
164 EXPECT_EQ("denied", script_result); 163 EXPECT_EQ("denied", script_result);
165 164
166 ASSERT_TRUE(RunScript("DisplayPersistentNotification()", &script_result)); 165 ASSERT_TRUE(RunScript("DisplayPersistentNotification()", &script_result));
167 EXPECT_EQ( 166 EXPECT_EQ(
168 "TypeError: No notification permission has been granted for this origin.", 167 "TypeError: No notification permission has been granted for this origin.",
169 script_result); 168 script_result);
170 169
171 ASSERT_EQ(0u, ui_manager()->GetNotificationCount()); 170 ASSERT_EQ(0u, ui_manager()->GetNotificationCount());
172 } 171 }
173 172
174 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 173 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
175 DisplayPersistentNotificationWithPermission) { 174 DisplayPersistentNotificationWithPermission) {
176 std::string script_result; 175 std::string script_result;
177 176
178 InfoBarResponder accepting_responder(GetInfoBarService(), 177 InfoBarResponder accepting_responder(GetInfoBarService(), true);
179 InfoBarResponder::ACCEPT);
180 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 178 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
181 EXPECT_EQ("granted", script_result); 179 EXPECT_EQ("granted", script_result);
182 180
183 ASSERT_TRUE(RunScript("DisplayPersistentNotification('action_none')", 181 ASSERT_TRUE(RunScript("DisplayPersistentNotification('action_none')",
184 &script_result)); 182 &script_result));
185 EXPECT_EQ("ok", script_result); 183 EXPECT_EQ("ok", script_result);
186 184
187 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 185 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
188 186
189 const Notification& notification = ui_manager()->GetNotificationAt(0); 187 const Notification& notification = ui_manager()->GetNotificationAt(0);
190 notification.delegate()->Click(); 188 notification.delegate()->Click();
191 189
192 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); 190 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result));
193 EXPECT_EQ("action_none", script_result); 191 EXPECT_EQ("action_none", script_result);
194 192
195 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 193 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
196 } 194 }
197 195
198 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 196 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
199 WebNotificationOptionsReflection) { 197 WebNotificationOptionsReflection) {
200 std::string script_result; 198 std::string script_result;
201 199
202 // TODO(peter): It doesn't add much value if we use the InfoBarResponder for 200 // TODO(peter): It doesn't add much value if we use the InfoBarResponder for
203 // each test. Rather, we should just toggle the content setting. 201 // each test. Rather, we should just toggle the content setting.
204 InfoBarResponder accepting_responder(GetInfoBarService(), 202 InfoBarResponder accepting_responder(GetInfoBarService(), true);
205 InfoBarResponder::ACCEPT);
206 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 203 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
207 EXPECT_EQ("granted", script_result); 204 EXPECT_EQ("granted", script_result);
208 205
209 ASSERT_TRUE(RunScript("DisplayPersistentAllOptionsNotification()", 206 ASSERT_TRUE(RunScript("DisplayPersistentAllOptionsNotification()",
210 &script_result)); 207 &script_result));
211 EXPECT_EQ("ok", script_result); 208 EXPECT_EQ("ok", script_result);
212 209
213 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 210 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
214 211
215 // We don't use or check the notification's direction and language. 212 // We don't use or check the notification's direction and language.
216 const Notification& notification = ui_manager()->GetNotificationAt(0); 213 const Notification& notification = ui_manager()->GetNotificationAt(0);
217 EXPECT_EQ("Title", base::UTF16ToUTF8(notification.title())); 214 EXPECT_EQ("Title", base::UTF16ToUTF8(notification.title()));
218 EXPECT_EQ("Contents", base::UTF16ToUTF8(notification.message())); 215 EXPECT_EQ("Contents", base::UTF16ToUTF8(notification.message()));
219 EXPECT_EQ("replace-id", notification.tag()); 216 EXPECT_EQ("replace-id", notification.tag());
220 EXPECT_FALSE(notification.icon().IsEmpty()); 217 EXPECT_FALSE(notification.icon().IsEmpty());
221 EXPECT_TRUE(notification.silent()); 218 EXPECT_TRUE(notification.silent());
222 219
223 EXPECT_EQ(kIconWidth, notification.icon().Width()); 220 EXPECT_EQ(kIconWidth, notification.icon().Width());
224 EXPECT_EQ(kIconHeight, notification.icon().Height()); 221 EXPECT_EQ(kIconHeight, notification.icon().Height());
225 } 222 }
226 223
227 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 224 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
228 WebNotificationOptionsVibrationPattern) { 225 WebNotificationOptionsVibrationPattern) {
229 std::string script_result; 226 std::string script_result;
230 227
231 InfoBarResponder accepting_responder(GetInfoBarService(), 228 InfoBarResponder accepting_responder(GetInfoBarService(), true);
232 InfoBarResponder::ACCEPT);
233 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 229 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
234 EXPECT_EQ("granted", script_result); 230 EXPECT_EQ("granted", script_result);
235 231
236 ASSERT_TRUE(RunScript("DisplayPersistentNotificationVibrate()", 232 ASSERT_TRUE(RunScript("DisplayPersistentNotificationVibrate()",
237 &script_result)); 233 &script_result));
238 EXPECT_EQ("ok", script_result); 234 EXPECT_EQ("ok", script_result);
239 235
240 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 236 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
241 237
242 const Notification& notification = ui_manager()->GetNotificationAt(0); 238 const Notification& notification = ui_manager()->GetNotificationAt(0);
243 EXPECT_EQ("Title", base::UTF16ToUTF8(notification.title())); 239 EXPECT_EQ("Title", base::UTF16ToUTF8(notification.title()));
244 EXPECT_EQ("Contents", base::UTF16ToUTF8(notification.message())); 240 EXPECT_EQ("Contents", base::UTF16ToUTF8(notification.message()));
245 241
246 EXPECT_THAT(notification.vibration_pattern(), 242 EXPECT_THAT(notification.vibration_pattern(),
247 testing::ElementsAreArray(kNotificationVibrationPattern)); 243 testing::ElementsAreArray(kNotificationVibrationPattern));
248 } 244 }
249 245
250 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 246 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
251 CloseDisplayedPersistentNotification) { 247 CloseDisplayedPersistentNotification) {
252 std::string script_result; 248 std::string script_result;
253 249
254 InfoBarResponder accepting_responder(GetInfoBarService(), 250 InfoBarResponder accepting_responder(GetInfoBarService(), true);
255 InfoBarResponder::ACCEPT);
256 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 251 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
257 EXPECT_EQ("granted", script_result); 252 EXPECT_EQ("granted", script_result);
258 253
259 ASSERT_TRUE(RunScript("DisplayPersistentNotification('action_close')", 254 ASSERT_TRUE(RunScript("DisplayPersistentNotification('action_close')",
260 &script_result)); 255 &script_result));
261 EXPECT_EQ("ok", script_result); 256 EXPECT_EQ("ok", script_result);
262 257
263 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 258 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
264 259
265 const Notification& notification = ui_manager()->GetNotificationAt(0); 260 const Notification& notification = ui_manager()->GetNotificationAt(0);
266 notification.delegate()->Click(); 261 notification.delegate()->Click();
267 262
268 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); 263 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result));
269 EXPECT_EQ("action_close", script_result); 264 EXPECT_EQ("action_close", script_result);
270 265
271 ASSERT_EQ(0u, ui_manager()->GetNotificationCount()); 266 ASSERT_EQ(0u, ui_manager()->GetNotificationCount());
272 } 267 }
273 268
274 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 269 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
275 TestDisplayOriginContextMessage) { 270 TestDisplayOriginContextMessage) {
276 std::string script_result; 271 std::string script_result;
277 272
278 // Creates a simple notification. 273 // Creates a simple notification.
279 InfoBarResponder accepting_responder(GetInfoBarService(), 274 InfoBarResponder accepting_responder(GetInfoBarService(), true);
280 InfoBarResponder::ACCEPT);
281 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 275 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
282 ASSERT_EQ("granted", script_result); 276 ASSERT_EQ("granted", script_result);
283 ASSERT_TRUE(RunScript("DisplayPersistentNotification()", &script_result)); 277 ASSERT_TRUE(RunScript("DisplayPersistentNotification()", &script_result));
284 278
285 net::HostPortPair host_port = ServerHostPort(); 279 net::HostPortPair host_port = ServerHostPort();
286 280
287 const Notification& notification = ui_manager()->GetNotificationAt(0); 281 const Notification& notification = ui_manager()->GetNotificationAt(0);
288 282
289 EXPECT_EQ(base::UTF8ToUTF16(host_port.ToString()), 283 EXPECT_EQ(base::UTF8ToUTF16(host_port.ToString()),
290 notification.context_message()); 284 notification.context_message());
291 } 285 }
292 286
293 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 287 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
294 CheckFilePermissionNotGranted) { 288 CheckFilePermissionNotGranted) {
295 // TODO(dewittj): This test verifies that a bug exists in Chrome; the test 289 // TODO(dewittj): This test verifies that a bug exists in Chrome; the test
296 // will fail if the bug is fixed. The 290 // will fail if the bug is fixed. The
297 // |PlatformNotificationServiceImpl::WebOriginDisplayName| function needs 291 // |PlatformNotificationServiceImpl::WebOriginDisplayName| function needs
298 // to be updated to properly display file:// URL origins. 292 // to be updated to properly display file:// URL origins.
299 // See crbug.com/402191. 293 // See crbug.com/402191.
300 std::string script_result; 294 std::string script_result;
301 295
302 InfoBarResponder accepting_responder_web(GetInfoBarService(), 296 InfoBarResponder accepting_responder_web(GetInfoBarService(), true);
303 InfoBarResponder::ACCEPT);
304 297
305 DesktopNotificationService* notification_service = 298 DesktopNotificationService* notification_service =
306 DesktopNotificationServiceFactory::GetForProfile(browser()->profile()); 299 DesktopNotificationServiceFactory::GetForProfile(browser()->profile());
307 ASSERT_TRUE(notification_service); 300 ASSERT_TRUE(notification_service);
308 message_center::NotifierId web_notifier(TestPageUrl()); 301 message_center::NotifierId web_notifier(TestPageUrl());
309 EXPECT_FALSE(notification_service->IsNotifierEnabled(web_notifier)); 302 EXPECT_FALSE(notification_service->IsNotifierEnabled(web_notifier));
310 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 303 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
311 EXPECT_EQ("granted", script_result); 304 EXPECT_EQ("granted", script_result);
312 305
313 EXPECT_TRUE(notification_service->IsNotifierEnabled(web_notifier)); 306 EXPECT_TRUE(notification_service->IsNotifierEnabled(web_notifier));
314 307
315 base::FilePath dir_source_root; 308 base::FilePath dir_source_root;
316 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &dir_source_root)); 309 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &dir_source_root));
317 base::FilePath full_file_path = 310 base::FilePath full_file_path =
318 dir_source_root.Append(server_root()).AppendASCII(kTestFileName); 311 dir_source_root.Append(server_root()).AppendASCII(kTestFileName);
319 GURL file_url(net::FilePathToFileURL(full_file_path)); 312 GURL file_url(net::FilePathToFileURL(full_file_path));
320 ui_test_utils::NavigateToURL(browser(), file_url); 313 ui_test_utils::NavigateToURL(browser(), file_url);
321 314
322 message_center::NotifierId file_notifier(file_url); 315 message_center::NotifierId file_notifier(file_url);
323 EXPECT_FALSE(notification_service->IsNotifierEnabled(file_notifier)); 316 EXPECT_FALSE(notification_service->IsNotifierEnabled(file_notifier));
324 317
325 InfoBarResponder accepting_responder_file(GetInfoBarService(), 318 InfoBarResponder accepting_responder_file(GetInfoBarService(), true);
326 InfoBarResponder::ACCEPT);
327 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 319 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
328 EXPECT_EQ("granted", script_result); 320 EXPECT_EQ("granted", script_result);
329 321
330 EXPECT_FALSE(notification_service->IsNotifierEnabled(file_notifier)) 322 EXPECT_FALSE(notification_service->IsNotifierEnabled(file_notifier))
331 << "If this test fails, you may have fixed a bug preventing file origins " 323 << "If this test fails, you may have fixed a bug preventing file origins "
332 << "from sending their origin from Blink; if so you need to update the " 324 << "from sending their origin from Blink; if so you need to update the "
333 << "display function for notification origins to show the file path."; 325 << "display function for notification origins to show the file path.";
334 } 326 }
335 327
336 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 328 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
(...skipping 26 matching lines...) Expand all
363 355
364 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 356 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
365 357
366 const Notification& notification = ui_manager()->GetNotificationAt(0); 358 const Notification& notification = ui_manager()->GetNotificationAt(0);
367 EXPECT_FALSE(notification.icon().IsEmpty()); 359 EXPECT_FALSE(notification.icon().IsEmpty());
368 360
369 EXPECT_EQ("Blob Title", base::UTF16ToUTF8(notification.title())); 361 EXPECT_EQ("Blob Title", base::UTF16ToUTF8(notification.title()));
370 EXPECT_EQ(kIconWidth, notification.icon().Width()); 362 EXPECT_EQ(kIconWidth, notification.icon().Width());
371 EXPECT_EQ(kIconHeight, notification.icon().Height()); 363 EXPECT_EQ(kIconHeight, notification.icon().Height());
372 } 364 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc_browsertest_base.cc ('k') | chrome/browser/push_messaging/push_messaging_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698