| 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 unittest | |
| 5 | |
| 6 from telemetry.core import browser_finder | |
| 7 from telemetry.test import options_for_unittests | |
| 8 | |
| 9 class BrowserTest(unittest.TestCase): | |
| 10 def testBrowserCreation(self): | |
| 11 options = options_for_unittests.GetCopy() | |
| 12 browser_to_create = browser_finder.FindBrowser(options) | |
| 13 if not browser_to_create: | |
| 14 raise Exception('No browser found, cannot continue test.') | |
| 15 with browser_to_create.Create() as b: | |
| 16 self.assertEquals(1, len(b.tabs)) | |
| 17 | |
| 18 # Different browsers boot up to different things | |
| 19 assert b.tabs[0].url | |
| 20 | |
| 21 def testCommandLineOverriding(self): | |
| 22 # This test starts the browser with --enable-benchmarking, which should | |
| 23 # create a chrome.Interval namespace. This tests whether the command line is | |
| 24 # being set. | |
| 25 options = options_for_unittests.GetCopy() | |
| 26 | |
| 27 flag1 = '--user-agent=telemetry' | |
| 28 options.extra_browser_args.append(flag1) | |
| 29 | |
| 30 browser_to_create = browser_finder.FindBrowser(options) | |
| 31 with browser_to_create.Create() as b: | |
| 32 t = b.tabs[0] | |
| 33 t.Navigate('http://www.google.com/') | |
| 34 t.WaitForDocumentReadyStateToBeInteractiveOrBetter() | |
| 35 self.assertEquals(t.EvaluateJavaScript('navigator.userAgent'), | |
| 36 'telemetry') | |
| 37 | |
| 38 def testVersionDetection(self): | |
| 39 options = options_for_unittests.GetCopy() | |
| 40 browser_to_create = browser_finder.FindBrowser(options) | |
| 41 with browser_to_create.Create() as b: | |
| 42 # pylint: disable=W0212 | |
| 43 self.assertTrue(b._browser_backend._inspector_protocol_version > 0) | |
| 44 self.assertTrue(b._browser_backend._chrome_branch_number > 0) | |
| 45 self.assertTrue(b._browser_backend._webkit_base_revision > 0) | |
| 46 | |
| 47 def testNewCloseTab(self): | |
| 48 options = options_for_unittests.GetCopy() | |
| 49 browser_to_create = browser_finder.FindBrowser(options) | |
| 50 with browser_to_create.Create() as b: | |
| 51 existing_tab = b.tabs[0] | |
| 52 self.assertEquals(1, len(b.tabs)) | |
| 53 existing_tab_url = existing_tab.url | |
| 54 | |
| 55 new_tab = b.tabs.New() | |
| 56 self.assertEquals(2, len(b.tabs)) | |
| 57 self.assertEquals(existing_tab.url, existing_tab_url) | |
| 58 self.assertEquals(new_tab.url, 'about:blank') | |
| 59 | |
| 60 new_tab.Close() | |
| 61 self.assertEquals(1, len(b.tabs)) | |
| 62 self.assertEquals(existing_tab.url, existing_tab_url) | |
| 63 | |
| 64 def testMultipleTabCalls(self): | |
| 65 options = options_for_unittests.GetCopy() | |
| 66 browser_to_create = browser_finder.FindBrowser(options) | |
| 67 with browser_to_create.Create() as b: | |
| 68 b.tabs[0].Navigate('http://www.google.com/') | |
| 69 b.tabs[0].WaitForDocumentReadyStateToBeInteractiveOrBetter() | |
| 70 | |
| 71 def testTabCallByReference(self): | |
| 72 options = options_for_unittests.GetCopy() | |
| 73 browser_to_create = browser_finder.FindBrowser(options) | |
| 74 with browser_to_create.Create() as b: | |
| 75 tab = b.tabs[0] | |
| 76 tab.Navigate('http://www.google.com/') | |
| 77 b.tabs[0].WaitForDocumentReadyStateToBeInteractiveOrBetter() | |
| 78 | |
| 79 def testCloseReferencedTab(self): | |
| 80 options = options_for_unittests.GetCopy() | |
| 81 browser_to_create = browser_finder.FindBrowser(options) | |
| 82 with browser_to_create.Create() as b: | |
| 83 b.tabs.New() | |
| 84 tab = b.tabs[0] | |
| 85 tab.Navigate('http://www.google.com/') | |
| 86 tab.Close() | |
| 87 self.assertEquals(1, len(b.tabs)) | |
| OLD | NEW |