Add tests for notifications and set the BaseNotification as the default in wait_for_notification r?sydpolk, maja_zf draft
authorDave Hunt <dhunt@mozilla.com>
Thu, 14 Apr 2016 09:00:30 +0100
changeset 350791 613bddd86a5a532c47098472cedb82e0d758d54a
parent 348946 c99067d0dc986b1b1b06dcc1c942910a525b1e1c
child 518405 30edfc99ce4cbc54ec34c5c6b73006816c30dff3
push id15417
push userdhunt@mozilla.com
push dateThu, 14 Apr 2016 08:52:08 +0000
reviewerssydpolk, maja_zf
milestone48.0a1
Add tests for notifications and set the BaseNotification as the default in wait_for_notification r?sydpolk, maja_zf MozReview-Commit-ID: 7XnM6bjOYbk
testing/firefox-ui/tests/puppeteer/manifest.ini
testing/firefox-ui/tests/puppeteer/mn-restartless-unsigned.xpi
testing/firefox-ui/tests/puppeteer/test_notifications.py
testing/puppeteer/firefox/firefox_puppeteer/ui/browser/window.py
--- a/testing/firefox-ui/tests/puppeteer/manifest.ini
+++ b/testing/firefox-ui/tests/puppeteer/manifest.ini
@@ -8,13 +8,14 @@ tags = local
 [test_security.py]
 tags = remote
 [test_software_update.py]
 [test_utils.py]
 
 # UI tests
 [test_about_window.py]
 [test_menubar.py]
+[test_notifications.py]
 [test_page_info_window.py]
 [test_tabbar.py]
 [test_toolbars.py]
 tags = remote
 [test_windows.py]
new file mode 100644
index 0000000000000000000000000000000000000000..c8877b55dec371fa6417fc626ef1a6f3113cc2bc
GIT binary patch
literal 1552
zc$^FHW@Zs#U|`^2xLcX!&XKXBU5t@|;S&(^Fvu_@<>!|amlP!y=w%g$hHx@4I|ev~
zfpBRBHv=Qf3uXoeFtN7(bk<=50oU*Uy1c{uJeFQcbqa5EQfzhD{W56U@r_Mu3@@!v
z<o)^ml;)SM@4Q}|n_Dcg_kj0%p?Q|>-Zu)oD;`)ZNYONB-^7&Y;V;nT%v65;yzqYO
z_q=60Kb{MVNO-N&>f*ge^UliX*5iC^(~e)helD+ju_uR4M(m^)vvjUJda*>mHR;Wq
z<xg3vpYmig?GSu?N|?j#LU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~*V}J(3GZ`x+YhX1DR~AEd-du!XNEr^Fskm|nvZ)qK448R^6_Qu*I2AK1ARD>>
cXedg?V1;B13<Fu&K$=*Aa5hk9JPU{i03S06YXATM
new file mode 100644
--- /dev/null
+++ b/testing/firefox-ui/tests/puppeteer/test_notifications.py
@@ -0,0 +1,50 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+
+from firefox_ui_harness.testcases import FirefoxTestCase
+from firefox_puppeteer.ui.browser.notifications import (
+    AddOnInstallFailedNotification)
+
+here = os.path.abspath(os.path.dirname(__file__))
+
+
+class TestNotifications(FirefoxTestCase):
+
+    def tearDown(self):
+        try:
+            if self.browser.notification is not None:
+                self.browser.notification.close()
+        finally:
+            FirefoxTestCase.tearDown(self)
+
+    def test_no_notification(self):
+        """No initial notifications are shown"""
+        assert self.browser.notification is None
+
+    def test_notification_without_origin(self):
+        """Origin is not shown for local add-ons"""
+        self.trigger_add_on_notification('mn-restartless-unsigned.xpi')
+        self.assertIsNotNone(self.browser.notification.label)
+        self.assertIsNone(self.browser.notification.origin)
+
+    def test_close_notification(self):
+        """Trigger and dismiss a notification"""
+        self.trigger_add_on_notification('mn-restartless-unsigned.xpi')
+        self.browser.notification.close()
+        self.assertIsNone(self.browser.notification)
+
+    def test_add_on_failed_notification(self):
+        """Trigger add-on failed notification using an unsigned add-on"""
+        self.trigger_add_on_notification('mn-restartless-unsigned.xpi')
+        self.assertIsInstance(self.browser.notification,
+                              AddOnInstallFailedNotification)
+
+    def trigger_add_on_notification(self, add_on):
+        path = os.path.join(here, add_on)
+        with self.marionette.using_context('content'):
+            self.marionette.execute_script(
+                'document.location = "file://{0}";'.format(path))
+        self.browser.wait_for_notification()
--- a/testing/puppeteer/firefox/firefox_puppeteer/ui/browser/window.py
+++ b/testing/puppeteer/firefox/firefox_puppeteer/ui/browser/window.py
@@ -14,17 +14,18 @@ from firefox_puppeteer.api.l10n import L
 from firefox_puppeteer.api.prefs import Preferences
 from firefox_puppeteer.decorators import use_class_as_property
 from firefox_puppeteer.ui.about_window.window import AboutWindow
 from firefox_puppeteer.ui.browser.notifications import (
     AddOnInstallBlockedNotification,
     AddOnInstallConfirmationNotification,
     AddOnInstallCompleteNotification,
     AddOnInstallFailedNotification,
-    AddOnProgressNotification)
+    AddOnProgressNotification,
+    BaseNotification)
 from firefox_puppeteer.ui.browser.tabbar import TabBar
 from firefox_puppeteer.ui.browser.toolbars import NavBar
 from firefox_puppeteer.ui.pageinfo.window import PageInfoWindow
 from firefox_puppeteer.ui.windows import BaseWindow, Windows
 import firefox_puppeteer.errors as errors
 
 
 class BrowserWindow(BaseWindow):
@@ -108,17 +109,17 @@ class BrowserWindow(BaseWindow):
             notification = self.window_element.find_element(
                 By.CSS_SELECTOR, '#notification-popup popupnotification')
         except NoSuchElementException:
             return None  # no notification is displayed
         notification_id = notification.get_attribute('id')
         return notifications_map[notification_id](
             lambda: self.marionette, self, notification)
 
-    def wait_for_notification(self, notification_class):
+    def wait_for_notification(self, notification_class=BaseNotification):
         """Waits for the specified notification to be displayed."""
         Wait(self.marionette).until(
             lambda _: isinstance(self.notification, notification_class),
             message='{0} not present.'.format(notification_class.__name__))
 
     @property
     def tabbar(self):
         """Provides access to the tab bar.