15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#!/usr/bin/env python
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Copyright (c) 2011 The Chromium Authors. All rights reserved.
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Use of this source code is governed by a BSD-style license that can be
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# found in the LICENSE file.
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import re
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import pyauto_functional
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import chromeos_network  # pyauto_functional must come before chromeos_network
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WifiNotification(chromeos_network.PyNetworkUITest):
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  """Test for ChromeOS wifi Network Disconnected Notification.
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  These tests will be testing Network Disconnected Notification on
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  various network encryptions (WEP,RSN, WPA) and various password lengths.
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  """
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  password1 = 'wrongpasswor'
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  password5 = 'tente'
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  password10 = 'tententent'
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  password13 = 'thirteenthirt'
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  password26 = 'twentysixtwentysixtwentysi'
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  password64 = \
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl'
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def _WifiNotification(self, router_name, password):
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    """Basic test for wifi notification.
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Args:
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      router_name: The name of the router.
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      password: invalid password.
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    """
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self.InitWifiPowerStrip()
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    router_config = self.GetRouterConfig(router_name)
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self.RouterPower(router_name, True)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self.assertTrue(self.WaitUntilWifiNetworkAvailable(router_config['ssid']),
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    'Wifi network %s never showed up.' % router_config['ssid'])
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    service_path = self.GetServicePath(router_config['ssid'])
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self.ConnectToWifiNetwork(service_path, password=password)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self.WaitForNotificationCount(1)
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    notification_result = self.GetActiveNotifications()[0]['content_url']
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    result_error = re.search('Error|Failed', notification_result)
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self.assertTrue(result_error, 'Expected to find Error/Failed in '
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  'notification, not found as expected.')
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    result_ssid = re.search(router_config['ssid'], notification_result)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self.assertTrue(result_ssid,
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    'SSID is not found. Notification text is: "%s"'
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    % notification_result)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def testWifiNotificationWEP_Linksys_WRT54G2_wrongpassword(self):
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    """wifi disconnect notification-Linksys_WRT54G2.(WEP)-invalid password"""
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self._WifiNotification('Linksys_WRT54G2', WifiNotification.password1)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def testWifiNotificationWEP_Linksys_WRT54G2_five_char(self):
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    """wifi disconnect notification for Linksys_WRT54G2.(WEP)-5 password """
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self._WifiNotification('Linksys_WRT54G2', WifiNotification.password5)
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def testWifiNotificationWEP_Linksys_WRT54G2_ten_char(self):
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    """wifi disconnect notification for Linksys_WRT54G2.(WEP)-10 password"""
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self._WifiNotification('Linksys_WRT54G2', WifiNotification.password10)
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def testWifiNotificationWEP_Linksys_WRT54G2_thirteen_char(self):
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    """wifi disconnect notification for Linksys_WRT54G2.(WEP)-13 password"""
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self._WifiNotification('Linksys_WRT54G2', WifiNotification.password13)
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def testWifiNotificationWEP_Linksys_WRT54G2_twentysix_char(self):
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    """wifi disconnect notification for Linksys_WRT54G2.(WEP)-26 password"""
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self._WifiNotification('Linksys_WRT54G2', WifiNotification.password26)
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def testWifiNotificationRSN_Belkin_G_wrongpassword(self):
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    """wifi disconnect notification for Belkin_G (rsn)-wrong password"""
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self._WifiNotification('Belkin_G', WifiNotification.password1)
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def testWifiNotificationWPA_Trendnet_639gr_wrongpassword(self):
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    """wifi disconnect notification for Trendnet_639gr (WPA)-wrong password"""
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self._WifiNotification('Trendnet_639gr', WifiNotification.password1)
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def testWifiNotificationWPA_Trendnet_639gr_five_char(self):
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    """wifi disconnect notification for Trendnet_639gr (WPA)-5 password"""
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self._WifiNotification('Trendnet_639gr', WifiNotification.password5)
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  def testWifiNotificationWPA_Trendnet_639gr_sixtyfour_char(self):
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    """wifi disconnect notification for Trendnet_639gr (WPA)-64 password"""
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    self._WifiNotification('Trendnet_639gr', WifiNotification.password64)
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)if __name__ == '__main__':
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  pyauto_functional.Main()
93