diff options
author | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-29 01:07:06 +0000 |
---|---|---|
committer | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-29 01:07:06 +0000 |
commit | 932fd710af1cff10f012626c0bfca92402917d0e (patch) | |
tree | 11042759483127aa29f556a3c439caa310c4ca86 | |
parent | 5998e87615bedd38f7d01a13189f15c89961b46e (diff) | |
download | chromium_src-932fd710af1cff10f012626c0bfca92402917d0e.zip chromium_src-932fd710af1cff10f012626c0bfca92402917d0e.tar.gz chromium_src-932fd710af1cff10f012626c0bfca92402917d0e.tar.bz2 |
Enable some pyauto notification tests. Wait for the notifications ondisplay
callback to be invoked before proceeding with the test.
BUG=66072, 80510
TEST=none
Review URL: http://codereview.chromium.org/6880223
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83462 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/test/data/notifications/notification_tester.html | 30 | ||||
-rw-r--r-- | chrome/test/functional/PYAUTO_TESTS | 7 | ||||
-rw-r--r-- | chrome/test/functional/notifications.py | 67 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 13 |
4 files changed, 61 insertions, 56 deletions
diff --git a/chrome/test/data/notifications/notification_tester.html b/chrome/test/data/notifications/notification_tester.html index 46d65b1..5bbe0f7 100644 --- a/chrome/test/data/notifications/notification_tester.html +++ b/chrome/test/data/notifications/notification_tester.html @@ -23,7 +23,7 @@ function createNotification(iconUrl, title, text, replaceId) { sendResultToTest(-1); return; } - sendResultToTest(createNotificationHelper(note, replaceId)); + createNotificationHelper(note, replaceId, true); } // Creates an HTML notification with a given content url. @@ -31,14 +31,16 @@ function createNotification(iconUrl, title, text, replaceId) { // |cancelNotification|. If two notifications are created with the same // replaceId, the second one should replace the first. If the notification // cannot be created, this returns -1. -function createHTMLNotification(contentUrl, replaceId) { +// If |waitForDisplay| is true, a response will not be sent until the +// notification is actually displayed. +function createHTMLNotification(contentUrl, replaceId, waitForDisplay) { try { var note = webkitNotifications.createHTMLNotification(contentUrl); } catch (exception) { sendResultToTest(-1); return; } - sendResultToTest(createNotificationHelper(note, replaceId)); + createNotificationHelper(note, replaceId, waitForDisplay); } // Cancels a notification with the given id. The notification must be showing, @@ -76,13 +78,25 @@ function onPermissionGranted() { g_permissionGranted = true; } -// Helper function that shows the notification and adds it to -// |g_notifications|. -function createNotificationHelper(note, replaceId) { +// Helper function that adds a notification to |g_notifications| and shows +// it. The index of the notification is sent back to the test, or -1 is sent +// back on error. If |waitForDisplay| is true, the response will not be sent +// until the notification is actually displayed. +function createNotificationHelper(note, replaceId, waitForDisplay) { + function sendNotificationIdToTest() { + sendResultToTest(g_notifications.length - 1); + } + g_notifications.push(note); note.replaceId = replaceId; + if (waitForDisplay) + note.ondisplay = sendNotificationIdToTest; + note.onerror = function() { + sendResultToTest(-1); + } + note.show(); - // |push| returns the length of the array after the add. - return g_notifications.push(note) - 1; + if (!waitForDisplay) + sendNotificationIdToTest(); } // Sends a result back to the main test logic. diff --git a/chrome/test/functional/PYAUTO_TESTS b/chrome/test/functional/PYAUTO_TESTS index 3d71a2f..3ad771b 100644 --- a/chrome/test/functional/PYAUTO_TESTS +++ b/chrome/test/functional/PYAUTO_TESTS @@ -63,10 +63,9 @@ '-instant.InstantTest.testInstantLoadsFor100CharsLongQuery', 'navigation', 'notifications', - # crbug.com/66072 - '-notifications.NotificationsTest.testNotificationOrderAfterClosingOne', - # crbug.com/79826 + # crbug.com/80063, simple notifications do not show '-notifications.NotificationsTest.testCreateSimpleNotification', + '-notifications.NotificationsTest.testNotificationOrderAfterClosingOne', '-notifications.NotificationsTest.testNotificationReplacement', '-notifications.NotificationsTest.testNotificationWithPropertyMissing', 'ntp', @@ -121,8 +120,6 @@ '-downloads.DownloadsTest.testOpenWhenDone', '-downloads.DownloadsTest.testAlwaysOpenFileType', '-instant.InstantTest.testInstantNavigation', # crbug.com/69090 - # crbug.com/80510 - '-notifications.NotificationsTest.testKillNotificationProcess', '-ntp.NTPTest.testLaunchAppNewWindow', # crbug.com/79812 # crbug.com/70437 '-omnibox.OmniboxTest.testHistoryResult', diff --git a/chrome/test/functional/notifications.py b/chrome/test/functional/notifications.py index 5229374..1d2cd45 100644 --- a/chrome/test/functional/notifications.py +++ b/chrome/test/functional/notifications.py @@ -14,7 +14,7 @@ class NotificationsTest(pyauto.PyUITest): """Test of HTML5 desktop notifications.""" def __init__(self, methodName='runTest'): super(NotificationsTest, self).__init__(methodName) - self.NO_SUCH_URL = 'http://no_such_url_exists/' + self.EMPTY_PAGE_URL = self.GetHttpURLForDataPath('empty.html') # Content settings for default notification permission. self.ALLOW_ALL_SETTING = 1 self.DENY_ALL_SETTING = 2 @@ -161,8 +161,8 @@ class NotificationsTest(pyauto.PyUITest): tab_index, windex); - def _CreateHTMLNotification(self, content_url, replace_id='', tab_index=0, - windex=0): + def _CreateHTMLNotification(self, content_url, replace_id='', + wait_for_display=True, tab_index=0, windex=0): """Creates an HTML notification. Returns the id of the notification, which can be used to cancel it later. @@ -176,11 +176,12 @@ class NotificationsTest(pyauto.PyUITest): replace_id: id string to be used for this notification. If another notification is shown with the same replace_id, the former will be replaced. + wait_for_display: whether we should wait for the notification to display tab_index: index of the tab within the given window windex: index of the window """ return self.CallJavascriptFunc('createHTMLNotification', - [content_url, replace_id], + [content_url, replace_id, wait_for_display], tab_index, windex) @@ -234,10 +235,10 @@ class NotificationsTest(pyauto.PyUITest): """Creates an HTML notification using a fake url.""" self._AllowAllOrigins() self.NavigateToURL(self.TEST_PAGE_URL) - self._CreateHTMLNotification(self.NO_SUCH_URL) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL) self.assertEquals(1, len(self.GetActiveNotifications())) notification = self.GetActiveNotifications()[0] - self.assertEquals(self.NO_SUCH_URL, notification['content_url']) + self.assertEquals(self.EMPTY_PAGE_URL, notification['content_url']) self.assertEquals('', notification['display_source']) self.assertEquals('file:///', notification['origin_url']) @@ -245,7 +246,7 @@ class NotificationsTest(pyauto.PyUITest): """Creates a notification and closes it.""" self._AllowAllOrigins() self.NavigateToURL(self.TEST_PAGE_URL) - self._CreateHTMLNotification(self.NO_SUCH_URL) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL) self.CloseNotification(0) self.assertFalse(self.GetActiveNotifications()) @@ -253,7 +254,7 @@ class NotificationsTest(pyauto.PyUITest): """Creates a notification and cancels it in the origin page.""" self._AllowAllOrigins() self.NavigateToURL(self.TEST_PAGE_URL) - note_id = self._CreateHTMLNotification(self.NO_SUCH_URL) + note_id = self._CreateHTMLNotification(self.EMPTY_PAGE_URL) self.assertNotEquals(-1, note_id) self.WaitForNotificationCount(1) self._CancelNotification(note_id) @@ -271,13 +272,13 @@ class NotificationsTest(pyauto.PyUITest): """Tries to create a notification and clicks allow on the infobar.""" self.NavigateToURL(self.TEST_PAGE_URL) # This notification should not be shown because we do not have permission. - self._CreateHTMLNotification(self.NO_SUCH_URL) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL) self.assertFalse(self.GetActiveNotifications()) self._RequestPermission() self.assertTrue(self.WaitForInfobarCount(1)) self.PerformActionOnInfobar('accept', 0) - self._CreateHTMLNotification(self.NO_SUCH_URL) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL) self.WaitForNotificationCount(1) def testOriginPreferencesBasic(self): @@ -323,7 +324,7 @@ class NotificationsTest(pyauto.PyUITest): self._RequestPermission() self.assertTrue(self.WaitForInfobarCount(1)) self.PerformActionOnInfobar('cancel', 0) - self._CreateHTMLNotification(self.NO_SUCH_URL) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL) self.assertFalse(self.GetActiveNotifications()) self.assertEquals(['file:///'], self._GetDeniedOrigins()) @@ -334,7 +335,7 @@ class NotificationsTest(pyauto.PyUITest): self._RequestPermission() self.assertTrue(self.WaitForInfobarCount(1)) self.PerformActionOnInfobar('dismiss', 0) - self._CreateHTMLNotification(self.NO_SUCH_URL) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL) self.assertFalse(self.GetActiveNotifications()) self.assertFalse(self._GetDeniedOrigins()) @@ -352,7 +353,7 @@ class NotificationsTest(pyauto.PyUITest): """Verify that all domains can be allowed to show notifications.""" self._SetDefaultPermissionSetting(self.ALLOW_ALL_SETTING) self.NavigateToURL(self.TEST_PAGE_URL) - self._CreateHTMLNotification(self.NO_SUCH_URL) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL) self.assertEquals(1, len(self.GetActiveNotifications())) self.assertFalse(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) @@ -360,7 +361,7 @@ class NotificationsTest(pyauto.PyUITest): """Verify that no domain can show notifications.""" self._SetDefaultPermissionSetting(self.DENY_ALL_SETTING) self.NavigateToURL(self.TEST_PAGE_URL) - self._CreateHTMLNotification(self.NO_SUCH_URL) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL) self.assertFalse(self.GetActiveNotifications()) def testDenyDomainAndAllowAll(self): @@ -369,7 +370,7 @@ class NotificationsTest(pyauto.PyUITest): self._DenyOrigin('file:///') self._SetDefaultPermissionSetting(self.ALLOW_ALL_SETTING) self.NavigateToURL(self.TEST_PAGE_URL) - self._CreateHTMLNotification(self.NO_SUCH_URL) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL) self.assertFalse(self.GetActiveNotifications()) def testAllowDomainAndDenyAll(self): @@ -378,7 +379,7 @@ class NotificationsTest(pyauto.PyUITest): self._AllowOrigin('file:///') self._SetDefaultPermissionSetting(self.DENY_ALL_SETTING) self.NavigateToURL(self.TEST_PAGE_URL) - self._CreateHTMLNotification(self.NO_SUCH_URL) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL) self.assertEquals(1, len(self.GetActiveNotifications())) self.assertFalse(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) @@ -386,10 +387,10 @@ class NotificationsTest(pyauto.PyUITest): """Verify that denying and again allowing should show notifications.""" self._DenyOrigin('file:///') self.NavigateToURL(self.TEST_PAGE_URL) - self._CreateHTMLNotification(self.NO_SUCH_URL) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL) self.assertEquals(len(self.GetActiveNotifications()), 0) self._AllowOrigin('file:///') - self._CreateHTMLNotification(self.NO_SUCH_URL) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL) self.assertEquals(1, len(self.GetActiveNotifications())) self.assertFalse(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) @@ -397,7 +398,7 @@ class NotificationsTest(pyauto.PyUITest): """Verify able to create, deny, and close the notification.""" self._AllowAllOrigins() self.NavigateToURL(self.TEST_PAGE_URL) - self._CreateHTMLNotification(self.NO_SUCH_URL) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL) self.assertEquals(1, len(self.GetActiveNotifications())) origin = 'file:///' self._DenyOrigin(origin) @@ -417,7 +418,7 @@ class NotificationsTest(pyauto.PyUITest): self._RequestPermission(windex=1) self.assertTrue(self.WaitForInfobarCount(1, windex=1)) self.PerformActionOnInfobar('accept', 0, windex=1) - self._CreateHTMLNotification(self.NO_SUCH_URL, windex=1) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL, windex=1) self.assertEquals(1, len(self.GetActiveNotifications())) self.NavigateToURL(self.TEST_PAGE_URL, 1, 0) @@ -435,20 +436,22 @@ class NotificationsTest(pyauto.PyUITest): def testCrashTabWithPermissionInfobar(self): """Test crashing the tab with permission infobar doesn't crash Chrome.""" - self.AppendTab(pyauto.GURL(self.NO_SUCH_URL)) + self.AppendTab(pyauto.GURL(self.EMPTY_PAGE_URL)) self.assertTrue(self.ActivateTab(0)) self.NavigateToURL(self.TEST_PAGE_URL) self._RequestPermission() self.assertTrue(self.WaitForInfobarCount(1)) - self.Kill(self.GetBrowserInfo()['windows'][0]['tabs'][0]['renderer_pid']) + self.KillRendererProcess( + self.GetBrowserInfo()['windows'][0]['tabs'][0]['renderer_pid']) self.assertTrue(self.IsBrowserRunning()) def testKillNotificationProcess(self): """Test killing a notification doesn't crash Chrome.""" self._AllowAllOrigins() self.NavigateToURL(self.TEST_PAGE_URL) - self._CreateHTMLNotification(self.NO_SUCH_URL) - self.Kill(self.GetActiveNotifications()[0]['pid']) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL) + self.KillRendererProcess( + self.GetActiveNotifications()[0]['pid']) self.assertTrue(self.IsBrowserRunning()) self.WaitForNotificationCount(0) @@ -460,14 +463,15 @@ class NotificationsTest(pyauto.PyUITest): self._RequestPermission(windex=1) self.assertTrue(self.WaitForInfobarCount(1, windex=1)) self.PerformActionOnInfobar('accept', infobar_index=0, windex=1) - self._CreateHTMLNotification(self.NO_SUCH_URL, windex=1) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL, windex=1) self.assertEquals(1, len(self.GetActiveNotifications())) def testSpecialURLNotification(self): """Test a page cannot create a notification to a chrome: url.""" self._AllowAllOrigins() self.NavigateToURL(self.TEST_PAGE_URL) - self._CreateHTMLNotification('chrome://extensions/') + self._CreateHTMLNotification('chrome://extensions/', + wait_for_display=False); self.assertFalse(self.GetActiveNotifications()) def testCloseTabWithPermissionInfobar(self): @@ -492,7 +496,7 @@ class NotificationsTest(pyauto.PyUITest): self._RequestPermission() self.assertTrue(self.WaitForInfobarCount(1)) self.PerformActionOnInfobar('accept', 0) - self._CreateHTMLNotification(self.NO_SUCH_URL) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL) self.assertEquals(1, len(self.GetActiveNotifications())) def testCrashRendererNotificationRemain(self): @@ -501,9 +505,10 @@ class NotificationsTest(pyauto.PyUITest): self.AppendTab(pyauto.GURL('about:blank')) self.ActivateTab(0) self.NavigateToURL(self.TEST_PAGE_URL) - self._CreateHTMLNotification(self.NO_SUCH_URL) + self._CreateHTMLNotification(self.EMPTY_PAGE_URL) self.assertEquals(1, len(self.GetActiveNotifications())) - self.Kill(self.GetBrowserInfo()['windows'][0]['tabs'][0]['renderer_pid']) + self.KillRendererProcess( + self.GetBrowserInfo()['windows'][0]['tabs'][0]['renderer_pid']) self.assertTrue(self.IsBrowserRunning()) self.assertEquals(1, len(self.GetActiveNotifications())) @@ -532,10 +537,10 @@ class NotificationsTest(pyauto.PyUITest): self.WaitForNotificationCount(1) # Since this notification has the same replaceId, 'chat', it should replace # the first notification. - self._CreateHTMLNotification(self.NO_SUCH_URL, 'chat') + self._CreateHTMLNotification(self.EMPTY_PAGE_URL, 'chat') notifications = self.GetActiveNotifications() self.assertEquals(1, len(notifications)) - self.assertEquals(self.NO_SUCH_URL, notifications[0]['content_url']) + self.assertEquals(self.EMPTY_PAGE_URL, notifications[0]['content_url']) if __name__ == '__main__': diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index 9ca3504..8685826 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -1921,18 +1921,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): Returns: a string that was sent back via the domAutomationController.send method """ - # Convert the given arguments for evaluation in a javascript statement. - converted_args = [] - for arg in args: - # If it is a string argument, we need to quote and escape it properly. - if type(arg) == type('string') or type(arg) == type(u'unicode'): - # We must convert all " in the string to \", so that we don't try - # to evaluate invalid javascript like ""arg"". - converted_arg = '"' + arg.replace('"', '\\"') + '"' - else: - # Convert it to a string so that we can use |join| later. - converted_arg = str(arg) - converted_args += [converted_arg] + converted_args = map(lambda arg: json.dumps(arg), args) js = '%s(%s)' % (function, ', '.join(converted_args)) logging.debug('Executing javascript: %s', js) return self.ExecuteJavascript(js, windex, tab_index) |