1# Copyright 2013 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import unittest 6 7from telemetry.testing import simple_mock 8 9_ = simple_mock.DONT_CARE 10 11 12class FormBasedCredentialsBackendUnitTestBase(unittest.TestCase): 13 def setUp(self): 14 self._credentials_type = None 15 16 def testLoginUsingMock(self): 17 raise NotImplementedError() 18 19 def _LoginUsingMock(self, backend, login_page_url, email_element_id, 20 password_element_id, form_element_id, 21 already_logged_in_js): # pylint: disable=no-self-use 22 del form_element_id # Unused. 23 del email_element_id # Unused. 24 del password_element_id # Unused. 25 tab = simple_mock.MockObject() 26 ar = simple_mock.MockObject() 27 28 config = {'username': 'blah', 29 'password': 'blargh'} 30 31 tab.ExpectCall('Navigate', login_page_url) 32 tab.ExpectCall( 33 'EvaluateJavaScript', already_logged_in_js).WillReturn(False) 34 tab.ExpectCall('WaitForDocumentReadyStateToBeInteractiveOrBetter') 35 36 ar.ExpectCall( 37 'WaitForJavaScriptCondition', 38 '(document.querySelector({{ form_id }}) !== null) || ({{ @code }})') 39 ar.ExpectCall('WaitForNavigate') 40 41 def VerifyEmail(js): 42 assert '{{ selector }}' in js 43 assert '{{ username }}' in js 44 tab.ExpectCall('ExecuteJavaScript', _).WhenCalled(VerifyEmail) 45 46 def VerifyPw(js): 47 assert '{{ selector }}' in js 48 assert '{{ password }}' in js 49 tab.ExpectCall('ExecuteJavaScript', _).WhenCalled(VerifyPw) 50 51 def VerifySubmit(js): 52 assert '.submit' in js or '.click' in js 53 tab.ExpectCall('ExecuteJavaScript', _).WhenCalled(VerifySubmit) 54 55 # Checking for form still up. 56 tab.ExpectCall('EvaluateJavaScript', _).WillReturn(False) 57 58 backend.LoginNeeded(tab, ar, config) 59