def test_lock_screen_open_sms_notification(self):
        lock_screen = LockScreen(self.marionette)

        # Check if the screen is turned off
        #self.assertFalse(self.device.is_screen_enabled)

        _text_message_content = "Automated Test %s" % str(time.time())

        system = System(self.marionette)

        # Send a SMS to the device
        self.data_layer.send_sms(self.testvars['carrier']['phone_number'], _text_message_content)
        
        self.device.lock()
        self.device.turn_screen_off()
        
        lock_screen.wait_for_notification()
        
        #Click notification
        notifications = self.marionette.find_elements(By.CSS_SELECTOR, '#notifications-lockscreen-container div[class="notification"]')

        for no in notifications:
            if "Automated Test" in no.text:
                no.tap()
                open = self.marionette.find_element(By.CSS_SELECTOR, '#notifications-lockscreen-container span[class="button-actionable"]')
                open.tap()
                break;
        
        self.wait_for_condition(lambda m: self.apps.displayed_app.name == 'Messages')
        self.assertEqual(self.apps.displayed_app.name, 'Messages')
class TestLockScreenNotification(GaiaTestCase):

    _notification_title = "TestNotificationBar_TITLE"
    _notification_body = "TestNotificationBar_BODY"

    def test_lock_screen_wake_with_notification(self):

        self.lockscreen.lock()
        self.lock_screen = LockScreen(self.marionette)
        self.device.turn_screen_off()

        # Check if the screen is turned off
        self.assertFalse(self.device.is_screen_enabled)

        self.marionette.execute_script(
            'navigator.mozNotification.createNotification("%s", "%s").show();'
            % (self._notification_title, self._notification_body)
        )
        self.lock_screen.wait_for_notification()

        # Check if the screen is turned on
        self.assertTrue(self.device.is_screen_enabled)

        # Check if the notification is displayed on the screen
        self.assertTrue(self.lock_screen.notifications[0].is_visible)
        self.assertEqual(self.lock_screen.notifications[0].content, self._notification_body)
    def test_dialer_miss_call_from_known_contact_notification(self):
        """
        https://moztrap.mozilla.org/manage/case/9294/
        """
        PLIVO_TIMEOUT = 30

        self.device.lock()

        from gaiatest.utils.plivo.plivo_util import PlivoUtil
        self.plivo = PlivoUtil(
            self.testvars['plivo']['auth_id'],
            self.testvars['plivo']['auth_token'],
            self.testvars['plivo']['phone_number']
        )
        self.call_uuid = self.plivo.make_call(
            to_number=self.testvars['local_phone_numbers'][0].replace('+', ''),
            timeout=PLIVO_TIMEOUT)

        call_screen = CallScreen(self.marionette)
        call_screen.wait_for_incoming_call_with_locked_screen()
        self.plivo.hangup_call(self.call_uuid)

        Wait(self.plivo, timeout=PLIVO_TIMEOUT).until(
            lambda p: p.is_call_completed(self.call_uuid),
            message="Plivo didn't report the call as completed")
        self.call_uuid = None

        lock_screen = LockScreen(self.marionette)
        lock_screen.switch_to_frame()
        lock_screen.wait_for_notification()

        # Check if the screen is turned on
        self.assertTrue(self.device.is_screen_enabled)

        # Verify the user sees a missed call notification message
        # and the known contacts info is shown.
        self.assertTrue(lock_screen.notifications[0].is_visible)
        self.assertEqual(lock_screen.notifications[0].title, 'Missed call')
        self.assertTrue(self.contact.givenName in lock_screen.notifications[0].content)

        self.device.unlock()

        system = System(self.marionette)
        system.wait_for_notification_toaster_not_displayed()

        # Expand the notification bar
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        # Verify the user sees the missed call event in the notification center
        # and the known contacts info is shown.
        notifications = utility_tray.notifications
        self.assertEqual(notifications[0].title, 'Missed call')
        self.assertTrue(self.contact.givenName in notifications[0].content)
    def test_dialer_miss_call_from_known_contact_notification(self):
        """
        https://moztrap.mozilla.org/manage/case/9294/
        """
        PLIVO_TIMEOUT = 30

        self.device.lock()

        from gaiatest.utils.plivo.plivo_util import PlivoUtil
        self.plivo = PlivoUtil(self.testvars['plivo']['auth_id'],
                               self.testvars['plivo']['auth_token'],
                               self.testvars['plivo']['phone_number'])
        self.call_uuid = self.plivo.make_call(
            to_number=self.testvars['local_phone_numbers'][0].replace('+', ''),
            timeout=PLIVO_TIMEOUT)

        call_screen = CallScreen(self.marionette)
        call_screen.wait_for_incoming_call_with_locked_screen()
        self.plivo.hangup_call(self.call_uuid)

        Wait(self.plivo, timeout=PLIVO_TIMEOUT).until(
            lambda p: p.is_call_completed(self.call_uuid),
            message="Plivo didn't report the call as completed")
        self.call_uuid = None

        lock_screen = LockScreen(self.marionette)
        lock_screen.switch_to_frame()
        lock_screen.wait_for_notification()

        # Check if the screen is turned on
        self.assertTrue(self.device.is_screen_enabled)

        # Verify the user sees a missed call notification message
        # and the known contacts info is shown.
        self.assertTrue(lock_screen.notifications[0].is_visible)
        self.assertEqual(lock_screen.notifications[0].title, 'Missed call')
        self.assertTrue(
            self.contact.givenName in lock_screen.notifications[0].content)

        self.device.unlock()

        system = System(self.marionette)
        system.wait_for_notification_toaster_not_displayed()

        # Expand the notification bar
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        # Verify the user sees the missed call event in the notification center
        # and the known contacts info is shown.
        notifications = utility_tray.notifications
        self.assertEqual(notifications[0].title, 'Missed call')
        self.assertTrue(self.contact.givenName in notifications[0].content)
    def test_dialer_miss_call_from_known_contact_notification(self):
        """
        https://moztrap.mozilla.org/manage/case/9294/
        """
        self.device.lock()

        from gaiatest.utils.plivo.plivo_util import PlivoUtil

        self.plivo = PlivoUtil(
            self.testvars["plivo"]["auth_id"],
            self.testvars["plivo"]["auth_token"],
            self.testvars["plivo"]["phone_number"],
        )
        self.call_uuid = self.plivo.make_call(to_number=self.environment.phone_numbers[0].replace("+", ""))

        call_screen = CallScreen(self.marionette)
        call_screen.wait_for_incoming_call()

        self.plivo.hangup_call(self.call_uuid)
        self.plivo.wait_for_call_completed(self.call_uuid)
        self.call_uuid = None

        lock_screen = LockScreen(self.marionette)
        lock_screen.switch_to_frame()
        lock_screen.wait_for_notification()

        # Check if the screen is turned on
        self.assertTrue(self.device.is_screen_enabled)

        # Verify the user sees a missed call notification message
        # and the known contacts info is shown.
        self.assertTrue(lock_screen.notifications[0].is_visible)
        self.assertEqual(lock_screen.notifications[0].title, "Missed call")
        self.assertTrue(self.contact.givenName in lock_screen.notifications[0].content)

        self.device.unlock()

        system = System(self.marionette)
        system.wait_for_notification_toaster_not_displayed()

        # Expand the notification bar
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        # Verify the user sees the missed call event in the notification center
        # and the known contacts info is shown.
        notifications = utility_tray.notifications
        self.assertEqual(notifications[0].title, "Missed call")
        self.assertTrue(self.contact.givenName in notifications[0].content)
    def test_lock_screen_wake_with_notification(self):
        lock_screen = LockScreen(self.marionette)

        # Check if the screen is turned off
        self.assertFalse(self.device.is_screen_enabled)

        self.marionette.execute_script('new Notification("%s", {body: "%s"});'
                                       % (self._notification_title, self._notification_body))
        lock_screen.wait_for_notification()

        # Check if the screen is turned on
        self.assertTrue(self.device.is_screen_enabled)

        # Check if the notification is displayed on the screen
        self.assertTrue(lock_screen.notifications[0].is_visible)
        self.assertEqual(lock_screen.notifications[0].content, self._notification_body)
    def test_lock_screen_open_notification(self):
        lock_screen = LockScreen(self.marionette)

        # Check if the screen is turned off
        self.assertFalse(self.device.is_screen_enabled)

        self.marionette.execute_script('new Notification("%s", {body: "%s"});'
                                       % (self._notification_title, self._notification_body))
        lock_screen.wait_for_notification()
        
        #Click notification
        notifications = self.marionette.find_elements(By.CSS_SELECTOR, '#notifications-lockscreen-container div[class="notification"]')

        for no in notifications:
            if self._notification_title in no.text:
                no.tap()
                open = self.marionette.find_element(By.CSS_SELECTOR, '#notifications-lockscreen-container span[class="button-actionable"]')
                open.tap()
                break;
        
        self.wait_for_condition(lambda m: self.apps.displayed_app.name == 'Homescreen')
        self.assertEqual(self.apps.displayed_app.name, 'Homescreen')