Chromium Code Reviews| 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..96cbc36a48e3cde3f59a2b62fb6ff74e960995e2 |
| --- /dev/null |
| +++ b/components/test/data/password_manager/website.py |
| @@ -0,0 +1,182 @@ |
| +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" |
|
vabr (Chromium)
2014/05/08 13:53:45
Please add a TODO for removing this as soon as the
rchtara
2014/05/14 11:58:04
Done.
|
| + "/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: |
|
vabr (Chromium)
2014/05/08 13:53:45
You use the
x in y or y in x
pattern quite often f
rchtara
2014/05/14 11:58:04
Done.
|
| + self.driver.execute_script( |
| + "document.querySelectorAll('#saved-passwords-list " |
| + ".row-delete-button')[%d].click()" % i) |
| + time.sleep(1) # wait until command is executed |
|
vabr (Chromium)
2014/05/08 13:53:45
nit: please start the comment with a capital lette
rchtara
2014/05/14 11:58:04
Done.
|
| + 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): |
| + name = self.name |
| + print "\nWrong Login Test for %s \n" % name |
| + p = self.password |
|
vabr (Chromium)
2014/05/08 13:53:45
Please use more descriptive variable names.
Here,
rchtara
2014/05/14 11:58:04
Done.
|
| + self.password = self.password + "1" |
| + self.LoginWhenNotAutofilled() |
| + self.password = p |
| + self.internals_file = "wrongpass.html" |
| + self.SwitchToInternals() |
| + self.UrlExists("unsuccessfullogins", ("Error: password manager " |
| + "thinks that a login with wrong " |
| + "password was successful for the " |
| + "following website : %s \n" % name)) |
| + self.UrlNotExists( |
| + "showedprompts", |
| + "Error: prompt is shown for a " |
| + "wrong password for the following website : %s \n" % name) |
| + self.SwitchFromInternals() |
| + |
| + def SuccessfulLoginTest(self): |
| + name = self.name |
| + print "\nSuccessful Login Test for %s \n" % name |
| + self.LoginWhenNotAutofilled() |
| + time.sleep(2) |
| + self.internals_file = "rightpass.html" |
| + self.SwitchToInternals() |
| + self.UrlExists( |
| + "successfullogins", |
| + "Error: password manager " |
| + "hasn't detected a successful login for the following website : %s" |
| + " \n" |
| + % name) |
| + self.UrlExists( |
| + "showedprompts", |
| + "Error: prompt is not shown for a " |
| + "right password for the following website : %s \n" % name) |
| + self.SwitchFromInternals() |
| + self.Logout() |
| + |
| + def SuccessfulLoginWithAutofilledPasswordTest(self): |
| + name = self.name |
| + print "\nSuccessful Login With Autofilled Password Test %s \n" % name |
| + self.LoginWhenAutofilled() |
| + time.sleep(2) |
| + self.internals_file = "rightpass.html" |
| + self.SwitchToInternals() |
| + self.UrlExists( |
| + "successfullogins", |
| + "Error: password manager " |
| + "hasn't detected a successful login for the following website : %s" |
| + " \n" |
| + % name) |
| + self.UrlExists( |
| + "showedprompts", |
| + "Error: prompt is not shown for a " |
| + "right password for the following website : %s \n" % name) |
| + self.SwitchFromInternals() |
| + self.Logout() |
| + |
| + def SuccessfulLoginAfterDeletionTest(self): |
| + name = self.name |
| + print "\nSuccessful Login After Deletion Test for %s \n" % name |
| + self.LoginWhenNotAutofilled() |
| + self.internals_file = "rightpass.html" |
| + self.SwitchToInternals() |
| + self.UrlExists( |
| + "successfullogins", |
| + "Error: password manager " |
| + "hasn't detected a successful login for the following website : %s" |
| + " \n" |
| + % name) |
| + self.UrlExists( |
| + "showedprompts", |
| + "Error: prompt is not shown for a " |
| + "right password for the following website : %s \n" % name) |
| + self.SwitchFromInternals() |
| + self.Logout() |