OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2012 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 import os |
| 5 import sys |
| 6 |
| 7 import telemetry |
| 8 from telemetry import tab_crash_exception |
| 9 from telemetry import util |
| 10 from telemetry_auto.webui_page import WebUIPage |
| 11 |
| 12 class OobePage(WebUIPage): |
| 13 def __init__(self, browser): |
| 14 self.current_screen = None |
| 15 self.page_urls = ["chrome://oobe/", "chrome://oobe/login"] |
| 16 super(OobePage, self).__init__(browser) |
| 17 |
| 18 def GetCurrentScreenId(self): |
| 19 try: |
| 20 self.current_screen = self.page.runtime.Evaluate( |
| 21 'cr.ui.Oobe.getInstance().currentScreen.id') |
| 22 except: |
| 23 return None |
| 24 return self.current_screen |
| 25 |
| 26 def WaitForStartupScreen(self): |
| 27 # Wait for any OOBE screen to show up . |
| 28 util.WaitFor(lambda: |
| 29 not self.GetCurrentScreenId() is None, |
| 30 timeout = 30) |
| 31 return self.current_screen |
| 32 |
| 33 def WaitUntilScreenChanges(self, last_screen): |
| 34 # Wait for any OOBE screen to show up . |
| 35 util.WaitFor(lambda: |
| 36 self.GetCurrentScreenId() != last_screen, |
| 37 timeout = 30) |
| 38 return self.current_screen |
| 39 |
| 40 def AttachTestHooks(self): |
| 41 # Wait for any OOBE screen to show up. |
| 42 screen_id = self.WaitForStartupScreen() |
| 43 self.AddTestHelperMethods() |
| 44 return screen_id |
| 45 |
| 46 def _WaitForScreen(self, screen_id): |
| 47 util.WaitFor( |
| 48 lambda: self.page.runtime.Evaluate( |
| 49 'cr.ui.Oobe.getInstance().currentScreen.id') == screen_id, |
| 50 timeout = 30) |
| 51 |
| 52 def LoginUser(self, email, password): |
| 53 self.WaitForPageToLoad(self.page_urls) |
| 54 # Get the initial screen id and set up helper functions. |
| 55 screen_id = self.AttachTestHooks() |
| 56 print 'Starting at screen %s' % screen_id |
| 57 if screen_id == 'account-picker': |
| 58 # We want to add a new user here. |
| 59 self.ClickOnButton('add-user-button') |
| 60 elif screen_id == 'connect': |
| 61 # Pass user network selection screen. |
| 62 self.ClickOnButton('continue-button') |
| 63 |
| 64 screen_id = self.WaitUntilScreenChanges(screen_id); |
| 65 print 'At screen %s' % screen_id |
| 66 |
| 67 if screen_id == 'eula': |
| 68 self.ClickOnButton('accept-button') |
| 69 screen_id = self.WaitUntilScreenChanges(screen_id); |
| 70 print 'At screen %s' % screen_id |
| 71 |
| 72 # Trigger GAIA login event. |
| 73 self._WaitForScreen('gaia-signin') |
| 74 self._LoginAs(email, password) |
| 75 try: |
| 76 # Pass user avatar image selection. |
| 77 self._WaitForScreen('user-image') |
| 78 self.ClickOnButton('ok-button') |
| 79 except(tab_crash_exception.TabCrashException): |
| 80 # Since OOBE is going away here, there is a chance that its debugger |
| 81 # handler might disappear while we are still waiting for its response. |
| 82 pass |
| 83 |
| 84 def _LoginAs(self, email, password): |
| 85 login_command = """ |
| 86 $('gaia-signin').onMessage_( |
| 87 { origin: |
| 88 'chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik/main.html', |
| 89 source: $('signin-frame').contentWindow, |
| 90 data: { |
| 91 method: 'completeLogin', |
| 92 email: '%s', |
| 93 password: '%s' |
| 94 } |
| 95 }); |
| 96 """ % (email, password) |
| 97 self.page.runtime.Execute(login_command) |
OLD | NEW |