OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import os |
| 7 import urllib |
| 8 |
| 9 import pyauto_functional |
| 10 import pyauto |
| 11 |
| 12 |
| 13 class NotificationsTest(pyauto.PyUITest): |
| 14 """Test of HTML5 desktop notifications.""" |
| 15 def __init__(self, methodName='runTest'): |
| 16 super(NotificationsTest, self).__init__(methodName) |
| 17 self.EMPTY_PAGE_URL = self.GetHttpURLForDataPath('empty.html') |
| 18 # Content settings for default notification permission. |
| 19 self.ALLOW_ALL_SETTING = 1 |
| 20 self.DENY_ALL_SETTING = 2 |
| 21 self.ASK_SETTING = 3 |
| 22 |
| 23 # HTML page used for notification testing. |
| 24 self.TEST_PAGE_URL = self.GetFileURLForDataPath( |
| 25 os.path.join('notifications', 'notification_tester.html')) |
| 26 |
| 27 def Debug(self): |
| 28 """Test method for experimentation. |
| 29 |
| 30 This method will not run automatically. |
| 31 """ |
| 32 while True: |
| 33 raw_input('Interact with the browser and hit <enter> to dump notification' |
| 34 'state...') |
| 35 print '*' * 20 |
| 36 self.pprint(self.GetActiveNotifications()) |
| 37 self.pprint(self._GetDefaultPermissionSetting()) |
| 38 |
| 39 def _SetDefaultPermissionSetting(self, setting): |
| 40 """Sets the default setting for whether sites are allowed to create |
| 41 notifications. |
| 42 """ |
| 43 self.SetPrefs(pyauto.kDefaultContentSettings, {u'notifications': setting}) |
| 44 |
| 45 def _GetDefaultPermissionSetting(self): |
| 46 """Gets the default setting for whether sites are allowed to create |
| 47 notifications. |
| 48 """ |
| 49 return self.GetPrefsInfo().Prefs( |
| 50 pyauto.kDefaultContentSettings)[u'notifications'] |
| 51 |
| 52 def _GetDeniedOrigins(self): |
| 53 """Gets the list of origins that are explicitly denied to create |
| 54 notifications. |
| 55 """ |
| 56 return (self.GetPrefsInfo().Prefs(pyauto.kDesktopNotificationDeniedOrigins) |
| 57 or []) |
| 58 |
| 59 def _GetAllowedOrigins(self): |
| 60 """Gets the list of origins that are explicitly allowed to create |
| 61 notifications. |
| 62 """ |
| 63 return (self.GetPrefsInfo().Prefs(pyauto.kDesktopNotificationAllowedOrigins) |
| 64 or []) |
| 65 |
| 66 def _SetAllowedOrigins(self, origins): |
| 67 """Sets the list of allowed origins to the given list. |
| 68 |
| 69 None of the items in the list should be explicitly denied. |
| 70 """ |
| 71 return self.SetPrefs(pyauto.kDesktopNotificationAllowedOrigins, origins) |
| 72 |
| 73 def _SetDeniedOrigins(self, origins): |
| 74 """Sets the list of denied origins to the given list. |
| 75 |
| 76 None of the items in the list should be explicitly allowed. |
| 77 """ |
| 78 return self.SetPrefs(pyauto.kDesktopNotificationDeniedOrigins, origins) |
| 79 |
| 80 def _DenyOrigin(self, new_origin): |
| 81 """Denies the given origin to create notifications. |
| 82 |
| 83 If it was explicitly allowed, that preference is dropped. |
| 84 """ |
| 85 self._DropOriginPreference(new_origin) |
| 86 denied = self._GetDeniedOrigins() |
| 87 if new_origin not in denied: |
| 88 self._SetDeniedOrigins(denied + [new_origin]) |
| 89 |
| 90 def _AllowOrigin(self, new_origin): |
| 91 """Allows the given origin to create notifications. If it was explicitly |
| 92 denied, that preference is dropped. |
| 93 """ |
| 94 self._DropOriginPreference(new_origin) |
| 95 allowed = self._GetAllowedOrigins() |
| 96 if new_origin not in allowed: |
| 97 self._SetAllowedOrigins(allowed + [new_origin]) |
| 98 |
| 99 def _DropOriginPreference(self, new_origin): |
| 100 """Drops the preference as to whether this origin should be allowed to |
| 101 create notifications. If it was explicitly allowed or explicitly denied, |
| 102 that preference is removed. |
| 103 """ |
| 104 allowed = self._GetAllowedOrigins() |
| 105 if allowed and new_origin in allowed: |
| 106 allowed.remove(new_origin) |
| 107 self._SetAllowedOrigins(allowed) |
| 108 denied = self._GetDeniedOrigins() |
| 109 if denied and new_origin in denied: |
| 110 denied.remove(new_origin) |
| 111 self._SetDeniedOrigins(denied) |
| 112 |
| 113 def _AllowAllOrigins(self): |
| 114 """Allows any origin to create notifications.""" |
| 115 self._SetDefaultPermissionSetting(self.ALLOW_ALL_SETTING) |
| 116 self._SetDeniedOrigins([]) |
| 117 |
| 118 def _VerifyInfobar(self, origin, tab_index=0, windex=0): |
| 119 """Helper to verify the notification infobar contents are correct. |
| 120 |
| 121 Defaults to first tab in first window. |
| 122 |
| 123 Args: |
| 124 origin: origin of the notification, e.g., www.gmail.com |
| 125 tab_index: index of the tab within the given window |
| 126 windex: index of the window |
| 127 """ |
| 128 tab_info = self.GetBrowserInfo()['windows'][windex]['tabs'][tab_index] |
| 129 self.assertEquals(1, len(tab_info['infobars'])) |
| 130 infobar = tab_info['infobars'][0] |
| 131 text = 'Allow %s to show desktop notifications?' % origin |
| 132 self.assertEqual(text, infobar['text']) |
| 133 self.assertEqual(2, len(infobar['buttons'])) |
| 134 self.assertEqual('Allow', infobar['buttons'][0]) |
| 135 self.assertEqual('Deny', infobar['buttons'][1]) |
| 136 |
| 137 def _CreateSimpleNotification(self, img_url, title, text, |
| 138 replace_id='', tab_index=0, windex=0): |
| 139 """Creates a simple notification. |
| 140 |
| 141 Returns the id of the notification, which can be used to cancel it later. |
| 142 |
| 143 This executes a script in the page which shows a notification. |
| 144 This will only work if the page is navigated to |TEST_PAGE_URL|. |
| 145 The page must also have permission to show notifications. |
| 146 |
| 147 Args: |
| 148 img_url: url of a image to use; can be a data url |
| 149 title: title of the notification |
| 150 text: text in the notification |
| 151 replace_id: id string to be used for this notification. If another |
| 152 notification is shown with the same replace_id, the former |
| 153 will be replaced. |
| 154 tab_index: index of the tab within the given window |
| 155 windex: index of the window |
| 156 """ |
| 157 return self.CallJavascriptFunc('createNotification', |
| 158 [img_url, title, text, replace_id], |
| 159 tab_index, |
| 160 windex); |
| 161 |
| 162 def _CreateHTMLNotification(self, content_url, replace_id='', |
| 163 wait_for_display=True, tab_index=0, windex=0): |
| 164 """Creates an HTML notification. |
| 165 |
| 166 Returns the id of the notification, which can be used to cancel it later. |
| 167 |
| 168 This executes a script in the page which shows a notification. |
| 169 This will only work if the page is navigated to |TEST_PAGE_URL|. |
| 170 The page must also have permission to show notifications. |
| 171 |
| 172 Args: |
| 173 content_url: url of the page to show in the notification |
| 174 replace_id: id string to be used for this notification. If another |
| 175 notification is shown with the same replace_id, the former |
| 176 will be replaced. |
| 177 wait_for_display: whether we should wait for the notification to display |
| 178 tab_index: index of the tab within the given window |
| 179 windex: index of the window |
| 180 """ |
| 181 return self.CallJavascriptFunc('createHTMLNotification', |
| 182 [content_url, replace_id, wait_for_display], |
| 183 tab_index, |
| 184 windex) |
| 185 |
| 186 def _RequestPermission(self, tab_index=0, windex=0): |
| 187 """Requests permission to create notifications. |
| 188 |
| 189 This will only work if the current page is navigated to |TEST_PAGE_URL|. |
| 190 |
| 191 Args: |
| 192 tab_index: index of the tab within the given window |
| 193 windex: index of the window |
| 194 """ |
| 195 self.CallJavascriptFunc('requestPermission', [], tab_index, windex) |
| 196 |
| 197 def _CancelNotification(self, notification_id, tab_index=0, windex=0): |
| 198 """Cancels a notification with the given id. |
| 199 |
| 200 This canceling is done in the page that showed that notification and so |
| 201 follows a different path than closing a notification via the UI. |
| 202 |
| 203 This function should NOT be called until |WaitForNotificationCount| has been |
| 204 used to verify the notification is showing. This function cannot be used to |
| 205 cancel a notification that is in the display queue. |
| 206 |
| 207 This will only work if the page is navigated to |TEST_PAGE_URL|. |
| 208 |
| 209 Args: |
| 210 notification_id: id of the notification to cancel |
| 211 tab_index: index of the tab within the given window that created the |
| 212 notification |
| 213 windex: index of the window |
| 214 """ |
| 215 msg = self.CallJavascriptFunc( |
| 216 'cancelNotification', [notification_id], tab_index, windex) |
| 217 # '1' signifies success. |
| 218 self.assertEquals('1', msg) |
| 219 |
| 220 def testCreateSimpleNotification(self): |
| 221 """Creates a simple notification.""" |
| 222 self._AllowAllOrigins() |
| 223 self.NavigateToURL(self.TEST_PAGE_URL) |
| 224 self._CreateSimpleNotification('no_such_file.png', 'My Title', 'My Body') |
| 225 self.assertEquals(1, len(self.GetActiveNotifications())) |
| 226 notification = self.GetActiveNotifications()[0] |
| 227 html_data = urllib.unquote(notification['content_url']) |
| 228 self.assertTrue('no_such_file.png' in html_data) |
| 229 self.assertTrue('My Title' in html_data) |
| 230 self.assertTrue('My Body' in html_data) |
| 231 |
| 232 def testCreateHTMLNotification(self): |
| 233 """Creates an HTML notification using a fake url.""" |
| 234 self._AllowAllOrigins() |
| 235 self.NavigateToURL(self.TEST_PAGE_URL) |
| 236 self._CreateHTMLNotification(self.EMPTY_PAGE_URL) |
| 237 self.assertEquals(1, len(self.GetActiveNotifications())) |
| 238 notification = self.GetActiveNotifications()[0] |
| 239 self.assertEquals(self.EMPTY_PAGE_URL, notification['content_url']) |
| 240 self.assertEquals('', notification['display_source']) |
| 241 self.assertEquals('file:///', notification['origin_url']) |
| 242 |
| 243 def testCloseNotification(self): |
| 244 """Creates a notification and closes it.""" |
| 245 self._AllowAllOrigins() |
| 246 self.NavigateToURL(self.TEST_PAGE_URL) |
| 247 self._CreateHTMLNotification(self.EMPTY_PAGE_URL) |
| 248 self.CloseNotification(0) |
| 249 self.assertFalse(self.GetActiveNotifications()) |
| 250 |
| 251 def testCancelNotification(self): |
| 252 """Creates a notification and cancels it in the origin page.""" |
| 253 self._AllowAllOrigins() |
| 254 self.NavigateToURL(self.TEST_PAGE_URL) |
| 255 note_id = self._CreateHTMLNotification(self.EMPTY_PAGE_URL) |
| 256 self.assertNotEquals(-1, note_id) |
| 257 self.WaitForNotificationCount(1) |
| 258 self._CancelNotification(note_id) |
| 259 self.assertFalse(self.GetActiveNotifications()) |
| 260 |
| 261 def testPermissionInfobarAppears(self): |
| 262 """Requests notification privileges and verifies the infobar appears.""" |
| 263 self.NavigateToURL(self.TEST_PAGE_URL) |
| 264 self._RequestPermission() |
| 265 self.assertTrue(self.WaitForInfobarCount(1)) |
| 266 self.assertFalse(self.GetActiveNotifications()) |
| 267 self._VerifyInfobar('') # file:/// origins are blank |
| 268 |
| 269 def testAllowOnPermissionInfobar(self): |
| 270 """Tries to create a notification and clicks allow on the infobar.""" |
| 271 self.NavigateToURL(self.TEST_PAGE_URL) |
| 272 # This notification should not be shown because we do not have permission. |
| 273 self._CreateHTMLNotification(self.EMPTY_PAGE_URL) |
| 274 self.assertFalse(self.GetActiveNotifications()) |
| 275 |
| 276 self._RequestPermission() |
| 277 self.assertTrue(self.WaitForInfobarCount(1)) |
| 278 self.PerformActionOnInfobar('accept', 0) |
| 279 self._CreateHTMLNotification(self.EMPTY_PAGE_URL) |
| 280 self.WaitForNotificationCount(1) |
| 281 |
| 282 def testOriginPreferencesBasic(self): |
| 283 """Tests that we can allow and deny origins.""" |
| 284 altavista = 'http://www.altavista.com' |
| 285 gmail = 'http://www.gmail.com' |
| 286 yahoo = 'http://www.yahoo.com' |
| 287 self._SetDeniedOrigins([altavista, gmail]) |
| 288 self.assertEquals(altavista, self._GetDeniedOrigins()[0]) |
| 289 self.assertEquals(gmail, self._GetDeniedOrigins()[1]) |
| 290 self._DenyOrigin(yahoo) |
| 291 self.assertEquals(yahoo, self._GetDeniedOrigins()[2]) |
| 292 self.assertEquals(3, len(self._GetDeniedOrigins())) |
| 293 self._DropOriginPreference(gmail) |
| 294 self.assertEquals(2, len(self._GetDeniedOrigins())) |
| 295 self.assertFalse(gmail in self._GetDeniedOrigins()) |
| 296 |
| 297 self._AllowOrigin(yahoo) |
| 298 self.assertEquals(1, len(self._GetDeniedOrigins())) |
| 299 self.assertFalse(yahoo in self._GetDeniedOrigins()) |
| 300 self.assertTrue(yahoo in self._GetAllowedOrigins()) |
| 301 |
| 302 self._SetAllowedOrigins([altavista, gmail]) |
| 303 self._SetDeniedOrigins([]) |
| 304 self.assertEquals(altavista, self._GetAllowedOrigins()[0]) |
| 305 self.assertEquals(gmail, self._GetAllowedOrigins()[1]) |
| 306 self._AllowOrigin(yahoo) |
| 307 self.assertEquals(yahoo, self._GetAllowedOrigins()[2]) |
| 308 self.assertEquals(3, len(self._GetAllowedOrigins())) |
| 309 self._DropOriginPreference(gmail) |
| 310 self.assertEquals(2, len(self._GetAllowedOrigins())) |
| 311 self.assertFalse(gmail in self._GetAllowedOrigins()) |
| 312 |
| 313 self._DenyOrigin(yahoo) |
| 314 self.assertEquals(1, len(self._GetAllowedOrigins())) |
| 315 self.assertTrue(yahoo in self._GetDeniedOrigins()) |
| 316 self.assertFalse(yahoo in self._GetAllowedOrigins()) |
| 317 |
| 318 def testDenyOnPermissionInfobar (self): |
| 319 """Test that no notification is created when Deny is chosen |
| 320 from permission infobar.""" |
| 321 self.NavigateToURL(self.TEST_PAGE_URL) |
| 322 self._RequestPermission() |
| 323 self.assertTrue(self.WaitForInfobarCount(1)) |
| 324 self.PerformActionOnInfobar('cancel', 0) |
| 325 self._CreateHTMLNotification(self.EMPTY_PAGE_URL) |
| 326 self.assertFalse(self.GetActiveNotifications()) |
| 327 self.assertEquals(['file:///'], self._GetDeniedOrigins()) |
| 328 |
| 329 def testClosePermissionInfobar(self): |
| 330 """Test that no notification is created when permission |
| 331 infobar is dismissed.""" |
| 332 self.NavigateToURL(self.TEST_PAGE_URL) |
| 333 self._RequestPermission() |
| 334 self.assertTrue(self.WaitForInfobarCount(1)) |
| 335 self.PerformActionOnInfobar('dismiss', 0) |
| 336 self._CreateHTMLNotification(self.EMPTY_PAGE_URL) |
| 337 self.assertFalse(self.GetActiveNotifications()) |
| 338 self.assertFalse(self._GetDeniedOrigins()) |
| 339 |
| 340 def testNotificationWithPropertyMissing(self): |
| 341 """Test that a notification can be created if one property is missing.""" |
| 342 self._AllowAllOrigins() |
| 343 self.NavigateToURL(self.TEST_PAGE_URL) |
| 344 self._CreateSimpleNotification('no_such_file.png', 'My Title', '') |
| 345 self.assertEquals(1, len(self.GetActiveNotifications())) |
| 346 html_data = urllib.unquote(self.GetActiveNotifications()[0]['content_url']) |
| 347 self.assertTrue('no_such_file.png' in html_data) |
| 348 self.assertTrue('My Title' in html_data) |
| 349 |
| 350 def testAllowNotificationsFromAllSites(self): |
| 351 """Verify that all domains can be allowed to show notifications.""" |
| 352 self._SetDefaultPermissionSetting(self.ALLOW_ALL_SETTING) |
| 353 self.NavigateToURL(self.TEST_PAGE_URL) |
| 354 self._CreateHTMLNotification(self.EMPTY_PAGE_URL) |
| 355 self.assertEquals(1, len(self.GetActiveNotifications())) |
| 356 self.assertFalse(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) |
| 357 |
| 358 def testDenyNotificationsFromAllSites(self): |
| 359 """Verify that no domain can show notifications.""" |
| 360 self._SetDefaultPermissionSetting(self.DENY_ALL_SETTING) |
| 361 self.NavigateToURL(self.TEST_PAGE_URL) |
| 362 self._CreateHTMLNotification(self.EMPTY_PAGE_URL) |
| 363 self.assertFalse(self.GetActiveNotifications()) |
| 364 |
| 365 def testDenyDomainAndAllowAll(self): |
| 366 """Verify that denying a domain and allowing all shouldn't show |
| 367 notifications from the denied domain.""" |
| 368 self._DenyOrigin('file:///') |
| 369 self._SetDefaultPermissionSetting(self.ALLOW_ALL_SETTING) |
| 370 self.NavigateToURL(self.TEST_PAGE_URL) |
| 371 self._CreateHTMLNotification(self.EMPTY_PAGE_URL) |
| 372 self.assertFalse(self.GetActiveNotifications()) |
| 373 |
| 374 def testAllowDomainAndDenyAll(self): |
| 375 """Verify that allowing a domain and denying all others should show |
| 376 notifications from the allowed domain.""" |
| 377 self._AllowOrigin('file:///') |
| 378 self._SetDefaultPermissionSetting(self.DENY_ALL_SETTING) |
| 379 self.NavigateToURL(self.TEST_PAGE_URL) |
| 380 self._CreateHTMLNotification(self.EMPTY_PAGE_URL) |
| 381 self.assertEquals(1, len(self.GetActiveNotifications())) |
| 382 self.assertFalse(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) |
| 383 |
| 384 def testDenyAndThenAllowDomain(self): |
| 385 """Verify that denying and again allowing should show notifications.""" |
| 386 self._DenyOrigin('file:///') |
| 387 self.NavigateToURL(self.TEST_PAGE_URL) |
| 388 self._CreateHTMLNotification(self.EMPTY_PAGE_URL) |
| 389 self.assertEquals(len(self.GetActiveNotifications()), 0) |
| 390 self._AllowOrigin('file:///') |
| 391 self._CreateHTMLNotification(self.EMPTY_PAGE_URL) |
| 392 self.assertEquals(1, len(self.GetActiveNotifications())) |
| 393 self.assertFalse(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) |
| 394 |
| 395 def testCreateDenyCloseNotifications(self): |
| 396 """Verify able to create, deny, and close the notification.""" |
| 397 self._AllowAllOrigins() |
| 398 self.NavigateToURL(self.TEST_PAGE_URL) |
| 399 self._CreateHTMLNotification(self.EMPTY_PAGE_URL) |
| 400 self.assertEquals(1, len(self.GetActiveNotifications())) |
| 401 origin = 'file:///' |
| 402 self._DenyOrigin(origin) |
| 403 self.assertTrue(origin in self._GetDeniedOrigins()) |
| 404 self.CloseNotification(0) |
| 405 self.assertEquals(0, len(self.GetActiveNotifications())) |
| 406 |
| 407 def testOriginPrefsNotSavedInIncognito(self): |
| 408 """Verify that allow/deny origin preferences are not saved in incognito.""" |
| 409 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
| 410 self.NavigateToURL(self.TEST_PAGE_URL, 1, 0) |
| 411 self._RequestPermission(windex=1) |
| 412 self.assertTrue(self.WaitForInfobarCount(1, windex=1)) |
| 413 self.PerformActionOnInfobar('cancel', 0, windex=1) |
| 414 |
| 415 self.CloseBrowserWindow(1) |
| 416 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
| 417 self.NavigateToURL(self.TEST_PAGE_URL, 1, 0) |
| 418 self._RequestPermission(windex=1) |
| 419 self.assertTrue(self.WaitForInfobarCount(1, windex=1)) |
| 420 self.PerformActionOnInfobar('accept', 0, windex=1) |
| 421 self._CreateHTMLNotification(self.EMPTY_PAGE_URL, windex=1) |
| 422 self.assertEquals(1, len(self.GetActiveNotifications())) |
| 423 |
| 424 self.CloseBrowserWindow(1) |
| 425 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
| 426 self.NavigateToURL(self.TEST_PAGE_URL, 1, 0) |
| 427 self._RequestPermission(windex=1) |
| 428 self.assertTrue(self.WaitForInfobarCount(1, windex=1)) |
| 429 |
| 430 self.assertFalse(self._GetDeniedOrigins()) |
| 431 self.assertFalse(self._GetAllowedOrigins()) |
| 432 |
| 433 def testExitBrowserWithInfobar(self): |
| 434 """Exit the browser window, when the infobar appears.""" |
| 435 self.NavigateToURL(self.TEST_PAGE_URL) |
| 436 self._RequestPermission() |
| 437 self.assertTrue(self.WaitForInfobarCount(1)) |
| 438 |
| 439 def testCrashTabWithPermissionInfobar(self): |
| 440 """Test crashing the tab with permission infobar doesn't crash Chrome.""" |
| 441 self.AppendTab(pyauto.GURL(self.EMPTY_PAGE_URL)) |
| 442 self.assertTrue(self.ActivateTab(0)) |
| 443 self.NavigateToURL(self.TEST_PAGE_URL) |
| 444 self._RequestPermission() |
| 445 self.assertTrue(self.WaitForInfobarCount(1)) |
| 446 self.KillRendererProcess( |
| 447 self.GetBrowserInfo()['windows'][0]['tabs'][0]['renderer_pid']) |
| 448 |
| 449 def testKillNotificationProcess(self): |
| 450 """Test killing a notification doesn't crash Chrome.""" |
| 451 self._AllowAllOrigins() |
| 452 self.NavigateToURL(self.TEST_PAGE_URL) |
| 453 self._CreateHTMLNotification(self.EMPTY_PAGE_URL) |
| 454 self.KillRendererProcess(self.GetActiveNotifications()[0]['pid']) |
| 455 self.WaitForNotificationCount(0) |
| 456 |
| 457 def testIncognitoNotification(self): |
| 458 """Test notifications in incognito window.""" |
| 459 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
| 460 self.NavigateToURL(self.TEST_PAGE_URL, 1, 0) |
| 461 self.assertTrue(self.ActivateTab(0, 1)) |
| 462 self._RequestPermission(windex=1) |
| 463 self.assertTrue(self.WaitForInfobarCount(1, windex=1)) |
| 464 self.PerformActionOnInfobar('accept', infobar_index=0, windex=1) |
| 465 self._CreateHTMLNotification(self.EMPTY_PAGE_URL, windex=1) |
| 466 self.assertEquals(1, len(self.GetActiveNotifications())) |
| 467 |
| 468 def testSpecialURLNotification(self): |
| 469 """Test a page cannot create a notification to a chrome: url.""" |
| 470 self._AllowAllOrigins() |
| 471 self.NavigateToURL(self.TEST_PAGE_URL) |
| 472 self._CreateHTMLNotification('chrome://settings', |
| 473 wait_for_display=False); |
| 474 self.assertFalse(self.GetActiveNotifications()) |
| 475 |
| 476 def testCloseTabWithPermissionInfobar(self): |
| 477 """Test that user can close tab when infobar present.""" |
| 478 self.AppendTab(pyauto.GURL('about:blank')) |
| 479 self.ActivateTab(0) |
| 480 self.NavigateToURL(self.TEST_PAGE_URL) |
| 481 self._RequestPermission() |
| 482 self.assertTrue(self.WaitForInfobarCount(1)) |
| 483 self.CloseTab() |
| 484 |
| 485 def testNavigateAwayWithPermissionInfobar(self): |
| 486 """Test navigating away when an infobar is present, then trying to create a |
| 487 notification from the same page.""" |
| 488 self.AppendTab(pyauto.GURL('about:blank')) |
| 489 self.assertTrue(self.ActivateTab(0)) |
| 490 self.NavigateToURL(self.TEST_PAGE_URL) |
| 491 self._RequestPermission() |
| 492 self.assertTrue(self.WaitForInfobarCount(1)) |
| 493 self.NavigateToURL(self.TEST_PAGE_URL) |
| 494 self._RequestPermission() |
| 495 self.assertTrue(self.WaitForInfobarCount(1)) |
| 496 self.PerformActionOnInfobar('accept', 0) |
| 497 self._CreateHTMLNotification(self.EMPTY_PAGE_URL) |
| 498 self.assertEquals(1, len(self.GetActiveNotifications())) |
| 499 |
| 500 def testCrashRendererNotificationRemain(self): |
| 501 """Test crashing renderer does not close or crash notification.""" |
| 502 self._AllowAllOrigins() |
| 503 self.AppendTab(pyauto.GURL('about:blank')) |
| 504 self.ActivateTab(0) |
| 505 self.NavigateToURL(self.TEST_PAGE_URL) |
| 506 self._CreateHTMLNotification(self.EMPTY_PAGE_URL) |
| 507 self.assertEquals(1, len(self.GetActiveNotifications())) |
| 508 self.KillRendererProcess( |
| 509 self.GetBrowserInfo()['windows'][0]['tabs'][0]['renderer_pid']) |
| 510 self.assertEquals(1, len(self.GetActiveNotifications())) |
| 511 |
| 512 def testNotificationOrderAfterClosingOne(self): |
| 513 """Tests that closing a notification leaves the rest |
| 514 of the notifications in the correct order. |
| 515 """ |
| 516 if self.IsWin7(): |
| 517 return # crbug.com/66072 |
| 518 self._AllowAllOrigins() |
| 519 self.NavigateToURL(self.TEST_PAGE_URL) |
| 520 self._CreateSimpleNotification('', 'Title1', '') |
| 521 self._CreateSimpleNotification('', 'Title2', '') |
| 522 self._CreateSimpleNotification('', 'Title3', '') |
| 523 old_notifications = self.GetAllNotifications() |
| 524 self.assertEquals(3, len(old_notifications)) |
| 525 self.CloseNotification(1) |
| 526 new_notifications = self.GetAllNotifications() |
| 527 self.assertEquals(2, len(new_notifications)) |
| 528 self.assertEquals(old_notifications[0]['id'], new_notifications[0]['id']) |
| 529 self.assertEquals(old_notifications[2]['id'], new_notifications[1]['id']) |
| 530 |
| 531 def testNotificationReplacement(self): |
| 532 """Test that we can replace a notification using the replaceId.""" |
| 533 self._AllowAllOrigins() |
| 534 self.NavigateToURL(self.TEST_PAGE_URL) |
| 535 self._CreateSimpleNotification('', 'Title2', '', 'chat') |
| 536 self.WaitForNotificationCount(1) |
| 537 # Since this notification has the same replaceId, 'chat', it should replace |
| 538 # the first notification. |
| 539 self._CreateHTMLNotification(self.EMPTY_PAGE_URL, 'chat') |
| 540 notifications = self.GetActiveNotifications() |
| 541 self.assertEquals(1, len(notifications)) |
| 542 self.assertEquals(self.EMPTY_PAGE_URL, notifications[0]['content_url']) |
| 543 |
| 544 |
| 545 if __name__ == '__main__': |
| 546 pyauto_functional.Main() |
OLD | NEW |