OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 import os |
| 6 import sys |
| 7 |
| 8 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
| 9 sys.path.append(os.path.join(os.path.dirname(__file__), |
| 10 '..', '..', 'telemetry')) |
| 11 import telemetry |
| 12 import telemetry_auto |
| 13 |
| 14 from telemetry import extension_page |
| 15 |
| 16 def RunOOBE(browser): |
| 17 p = telemetry_auto.OobePage(browser) |
| 18 p.LoginUser('test@test.test', 'test') |
| 19 # Wait until OOBE page goes away, we are logged in aftet that |
| 20 p.WaitUnitGone() |
| 21 print "OOBE completed!" |
| 22 |
| 23 def LoadTab(ext, url): |
| 24 create_properties = { 'url': url } |
| 25 # Then open a new tab and wait until the new tab loads. |
| 26 (call_results, event_args) = ext.RunMethodWithEvents( |
| 27 [extension_page.ExtensionEvent('chrome.tabs.onUpdated', |
| 28 """arguments.length >= 2 && arguments[1] && |
| 29 arguments[1].status == 'complete';""")], |
| 30 'chrome.tabs.create', |
| 31 create_properties) |
| 32 # Return back Tab object properties. |
| 33 return call_results["0"] |
| 34 |
| 35 def RemoveTab(ext, tab_id): |
| 36 remove_properties = [ tab_id ] |
| 37 # Then open a new tab and wait until the new tab loads. |
| 38 (call_results, event_args) = ext.RunMethodWithEvents( |
| 39 [extension_page.ExtensionEvent('chrome.tabs.onRemoved', |
| 40 """arguments.length >= 1 && arguments[0] && |
| 41 arguments[0] == %s;""" % tab_id)], |
| 42 'chrome.tabs.remove', |
| 43 remove_properties) |
| 44 |
| 45 def FindAutomationExtension(browser): |
| 46 # Attach to automation extension. |
| 47 extensions = browser.extensions.GetAllForUrl( |
| 48 'chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/' + |
| 49 '_generated_background_page.html') |
| 50 # Get the last loaded extension |
| 51 return extensions[len(extensions) - 1] |
| 52 |
| 53 def TestIntegration(args): |
| 54 options = telemetry.BrowserOptions() |
| 55 parser = options.CreateParser('telemetry_extension_test.py') |
| 56 options, args = parser.parse_args(args) |
| 57 browser_to_create = telemetry.FindBrowser(options) |
| 58 assert browser_to_create |
| 59 with browser_to_create.Create() as browser: |
| 60 # Get us through OOBE first. |
| 61 RunOOBE(browser) |
| 62 auto = FindAutomationExtension(browser) |
| 63 # Load somethin' in a tab once we are in session. |
| 64 t1 = LoadTab(auto, 'chrome://settings') |
| 65 t2 = LoadTab(auto, 'http://www.google.com/') |
| 66 RemoveTab(auto, t1["id"]) |
| 67 RemoveTab(auto, t2["id"]) |
| 68 |
| 69 def Main(args): |
| 70 for i in range(1, 10000): |
| 71 print "Test pass %d" % i |
| 72 TestIntegration(args) |
| 73 return 0 |
| 74 |
| 75 if __name__ == '__main__': |
| 76 sys.exit(Main(sys.argv[1:])) |
OLD | NEW |