| Index: components/test/data/password_manager/website.py
|
| diff --git a/components/test/data/password_manager/website.py b/components/test/data/password_manager/website.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d48807f270986820ce236a95179b02b829e21f9d
|
| --- /dev/null
|
| +++ b/components/test/data/password_manager/website.py
|
| @@ -0,0 +1,178 @@
|
| +import time
|
| +
|
| +
|
| +from action import Action
|
| +
|
| +
|
| +class Website:
|
| +
|
| + def __init__(
|
| + self, name, username, password, driver, test_environment,
|
| + username_not_auto=False):
|
| + self.name = name
|
| + self.driver = driver
|
| + self.username = username
|
| + self.password = password
|
| + if test_environment.passwords_tree != None:
|
| + if username == None:
|
| + username_tag = (test_environment.
|
| + passwords_tree.find(".//*[@name='%s']/username" % name))
|
| + if (username_tag != None):
|
| + self.username = username_tag.text
|
| + if password == None:
|
| + password_tag = (test_environment.
|
| + passwords_tree.find(".//*[@name='%s']/password" % name))
|
| + if (password_tag != None):
|
| + self.password = password_tag.text
|
| + self.login_actions = []
|
| + self.logout_actions = []
|
| + self.internals_folder = ("file:///usr/local/google/home/rchtara/chrome"
|
| + "/python/passwordinternals/internalmock/")
|
| + self.internals_file = ""
|
| + self.username_not_auto = username_not_auto
|
| + self.test_environment = test_environment
|
| +
|
| + def AddLoginAction(self, action_type, param):
|
| + self.login_actions.append(Action(action_type, param, self))
|
| +
|
| + def AddLogoutAction(self, action_type, param):
|
| + self.logout_actions.append(Action(action_type, param, self))
|
| +
|
| + def Url(self):
|
| + for action in self.login_actions:
|
| + if (action.action_type == "goto"):
|
| + return action.param
|
| + return ""
|
| +
|
| + def LoginWhenAutofilled(self):
|
| + for action in self.login_actions:
|
| + action.DoAutofilled(self.driver)
|
| +
|
| + def LoginWhenNotAutofilled(self):
|
| + for action in self.login_actions:
|
| + action.DoNotAutofilled(self.driver)
|
| +
|
| + def Logout(self):
|
| + for action in self.logout_actions:
|
| + action.Do(self.driver)
|
| +
|
| + def RemoveAllPasswords(self, urls):
|
| + url_to_remove = self.Url()
|
| + if (url_to_remove != ""):
|
| + i = 0
|
| + for current_url in urls:
|
| + if current_url in url_to_remove or url_to_remove in current_url:
|
| + self.driver.execute_script(
|
| + "document.querySelectorAll('#saved-passwords-list "
|
| + ".row-delete-button')[%d].click()" % i)
|
| + time.sleep(1) # wait until command is executed
|
| + else:
|
| + i = i + 1
|
| +
|
| + def SwitchToInternals(self):
|
| + self.driver.switch_to_window(self.test_environment.internals_window)
|
| + self.driver.get(self.internals_folder + self.internals_file)
|
| +
|
| + def SwitchFromInternals(self):
|
| + self.driver.switch_to_window(self.test_environment.websitewindow)
|
| +
|
| + """ TestsTools """
|
| +
|
| + def UrlExists(self, id, msg):
|
| + url = self.Url()
|
| + elments = self.driver.find_element_by_id(id)
|
| + urls = elments.find_elements_by_class_name("url")
|
| + match = False
|
| + for u in urls:
|
| + if (u.text in url or url in u.text or
|
| + u.text in self.name or self.name in u.text):
|
| + match = True
|
| + break
|
| + assert match, msg
|
| +
|
| + def UrlNotExists(self, id, msg):
|
| + url = self.Url()
|
| + elments = self.driver.find_element_by_id(id)
|
| + urls = elments.find_elements_by_class_name("url")
|
| + match = False
|
| + for u in urls:
|
| + if u.text in url or url in u.text:
|
| + match = True
|
| + break
|
| + assert match == False, msg
|
| +
|
| + """ Tests """
|
| +
|
| + def WrongLoginTest(self):
|
| + p = self.password
|
| + self.password = self.password + "1"
|
| + self.LoginWhenNotAutofilled()
|
| + self.password = p
|
| + self.internals_file = "wrongpass.html"
|
| + self.SwitchToInternals()
|
| + url = self.Url()
|
| + self.UrlExists("unsuccessfullogins", ("Error: password manager "
|
| + "thinks that a login with wrong "
|
| + "password was successful for the "
|
| + "following website : %s \n" % url))
|
| + self.UrlNotExists(
|
| + "showedprompts",
|
| + "Error: prompt is shown for a "
|
| + "wrong password for the following website : %s \n" % url)
|
| + self.SwitchFromInternals()
|
| +
|
| + def SucessfulLoginTest(self):
|
| + self.LoginWhenNotAutofilled()
|
| + time.sleep(2)
|
| + self.internals_file = "rightpass.html"
|
| + self.SwitchToInternals()
|
| + url = self.Url()
|
| + self.UrlExists(
|
| + "successfullogins",
|
| + "Error: password manager "
|
| + "hasn't detected a successful login for the following website : %s"
|
| + " \n"
|
| + % url)
|
| + self.UrlExists(
|
| + "showedprompts",
|
| + "Error: prompt is not shown for a "
|
| + "right password for the following website : %s \n" % url)
|
| + self.SwitchFromInternals()
|
| + self.Logout()
|
| +
|
| + def SucessfulLoginWithAutofilledPasswordTest(self):
|
| + self.LoginWhenAutofilled()
|
| + time.sleep(2)
|
| + self.internals_file = "rightpass.html"
|
| + self.SwitchToInternals()
|
| + url = self.Url()
|
| + self.UrlExists(
|
| + "successfullogins",
|
| + "Error: password manager "
|
| + "hasn't detected a successful login for the following website : %s"
|
| + " \n"
|
| + % url)
|
| + self.UrlExists(
|
| + "showedprompts",
|
| + "Error: prompt is not shown for a "
|
| + "right password for the following website : %s \n" % url)
|
| + self.SwitchFromInternals()
|
| + self.Logout()
|
| +
|
| + def SucessfulLoginAfterDeletionTest(self):
|
| + self.LoginWhenNotAutofilled()
|
| + self.internals_file = "rightpass.html"
|
| + self.SwitchToInternals()
|
| + url = self.Url()
|
| + self.UrlExists(
|
| + "successfullogins",
|
| + "Error: password manager "
|
| + "hasn't detected a successful login for the following website : %s"
|
| + " \n"
|
| + % url)
|
| + self.UrlExists(
|
| + "showedprompts",
|
| + "Error: prompt is not shown for a "
|
| + "right password for the following website : %s \n" % url)
|
| + self.SwitchFromInternals()
|
| + self.Logout()
|
|
|