Exemplo n.º 1
0
 def testGetFileContents(self):  # pylint: disable=R0201
     remote = options_for_unittests.Get().cros_remote
     cri = cros_interface.CrOSInterface(
         remote,
         options_for_unittests.Get().cros_ssh_identity)
     hosts = cri.GetFileContents('/etc/hosts')
     assert hosts.startswith('# /etc/hosts')
Exemplo n.º 2
0
 def testGetFileContentsForSomethingThatDoesntExist(self):
     remote = options_for_unittests.Get().cros_remote
     cri = cros_interface.CrOSInterface(
         remote,
         options_for_unittests.Get().cros_ssh_identity)
     self.assertRaises(
         OSError, lambda: cri.GetFileContents('/tmp/209fuslfskjf/dfsfsf'))
Exemplo n.º 3
0
    def testIsServiceRunning(self):
        remote = options_for_unittests.Get().cros_remote
        cri = cros_interface.CrOSInterface(
            remote,
            options_for_unittests.Get().cros_ssh_identity)

        self.assertTrue(cri.IsServiceRunning('openssh-server'))
Exemplo n.º 4
0
 def testExists(self):
     remote = options_for_unittests.Get().cros_remote
     cri = cros_interface.CrOSInterface(
         remote,
         options_for_unittests.Get().cros_ssh_identity)
     self.assertTrue(cri.FileExistsOnDevice('/proc/cpuinfo'))
     self.assertTrue(cri.FileExistsOnDevice('/etc/passwd'))
     self.assertFalse(cri.FileExistsOnDevice('/etc/sdlfsdjflskfjsflj'))
Exemplo n.º 5
0
 def testPushContents(self):
     remote = options_for_unittests.Get().cros_remote
     cri = cros_interface.CrOSInterface(
         remote,
         options_for_unittests.Get().cros_ssh_identity)
     cri.GetCmdOutput(['rm', '-rf', '/tmp/testPushContents'])
     cri.PushContents('hello world', '/tmp/testPushContents')
     contents = cri.GetFileContents('/tmp/testPushContents')
     self.assertEquals(contents, 'hello world')
Exemplo n.º 6
0
    def testListProcesses(self):  # pylint: disable=R0201
        remote = options_for_unittests.Get().cros_remote
        cri = cros_interface.CrOSInterface(
            remote,
            options_for_unittests.Get().cros_ssh_identity)
        with cros_interface.DeviceSideProcess(cri, ['sleep', '11']):
            procs = cri.ListProcesses()
            sleeps = [x for x in procs if x[1] == 'sleep 11']

            assert len(sleeps) == 1
Exemplo n.º 7
0
    def testDeviceSideProcessFailureToLaunch(self):
        remote = options_for_unittests.Get().cros_remote
        cri = cros_interface.CrOSInterface(
            remote,
            options_for_unittests.Get().cros_ssh_identity)

        def WillFail():
            dsp = cros_interface.DeviceSideProcess(cri,
                                                   ['sfsdfskjflwejfweoij'])
            dsp.Close()

        self.assertRaises(OSError, WillFail)
Exemplo n.º 8
0
    def testDeviceSideProcessCloseDoesClose(self):
        remote = options_for_unittests.Get().cros_remote
        cri = cros_interface.CrOSInterface(
            remote,
            options_for_unittests.Get().cros_ssh_identity)

        with cros_interface.DeviceSideProcess(cri, ['sleep', '111']) as dsp:
            procs = cri.ListProcesses()
            sleeps = [x for x in procs if x[1] == 'sleep 111']
            assert dsp.IsAlive()
        procs = cri.ListProcesses()
        sleeps = [x for x in procs if x[1] == 'sleep 111']
        self.assertEquals(len(sleeps), 0)
Exemplo n.º 9
0
    def _RebuildCredentials(self):
        credentials = {}
        if self._credentials_path == None:
            pass
        elif os.path.exists(self._credentials_path):
            with open(self._credentials_path, 'r') as f:
                credentials = json.loads(f.read())

        # TODO(nduca): use system keychain, if possible.
        homedir_credentials_path = os.path.expanduser('~/.crc-credentials')
        homedir_credentials = {}

        if (not options_for_unittests.Get()
                and os.path.exists(homedir_credentials_path)):
            logging.info(
                "Found ~/.crc-credentials. Its contents will be used when "
                "no other credentials can be found.")
            with open(homedir_credentials_path, 'r') as f:
                homedir_credentials = json.loads(f.read())

        self._credentials = {}
        all_keys = set(credentials.keys()).union(
            homedir_credentials.keys()).union(self._extra_credentials.keys())

        for k in all_keys:
            if k in credentials:
                self._credentials[k] = credentials[k]
            if k in homedir_credentials:
                logging.info("Will use ~/.crc-credentials for %s logins." % k)
                self._credentials[k] = homedir_credentials[k]
            if k in self._extra_credentials:
                self._credentials[k] = self._extra_credentials[k]
Exemplo n.º 10
0
  def runCredentialsTest(self, # pylint: disable=R0201
                         credentials_backend,
                         results):
    page = page_module.Page('http://www.google.com')
    page.credentials = "test"
    ps = page_set.PageSet()
    ps.pages.append(page)

    did_run = [False]

    with tempfile.NamedTemporaryFile() as f:
      f.write(SIMPLE_CREDENTIALS_STRING)
      f.flush()
      ps.credentials_path = f.name

      class TestThatInstallsCredentialsBackend(page_test.PageTest):
        def __init__(self, credentials_backend):
          super(TestThatInstallsCredentialsBackend, self).__init__('RunTest')
          self._credentials_backend = credentials_backend

        def SetUpBrowser(self, browser):
          browser.credentials.AddBackend(self._credentials_backend)

        def RunTest(self, page, tab, results): # pylint: disable=W0613,R0201
          did_run[0] = True

      test = TestThatInstallsCredentialsBackend(credentials_backend)
      with page_runner.PageRunner(ps) as runner:
        options = options_for_unittests.Get()
        possible_browser = browser_finder.FindBrowser(options)
        runner.Run(options, possible_browser, test, results)

    return did_run[0]
Exemplo n.º 11
0
    def testBrowserCreation(self):
        options = options_for_unittests.Get()
        browser_to_create = browser_finder.FindBrowser(options)
        if not browser_to_create:
            raise Exception('No browser found, cannot continue test.')
        with browser_to_create.Create() as b:
            self.assertEquals(1, b.num_tabs)

            # Different browsers boot up to different things
            assert b.GetNthTabUrl(0)
Exemplo n.º 12
0
 def setUp(self):
   self._browser = None
   self._tab = None
   options = options_for_unittests.Get()
   browser_to_create = browser_finder.FindBrowser(options)
   if not browser_to_create:
     raise Exception('No browser found, cannot continue test.')
   try:
     self._browser = browser_to_create.Create()
     self._tab = self._browser.ConnectToNthTab(0)
   except:
     self.tearDown()
     raise
Exemplo n.º 13
0
 def testNewCloseTab(self):
     options = options_for_unittests.Get()
     browser_to_create = browser_finder.FindBrowser(options)
     with browser_to_create.Create() as b:
         self.assertEquals(1, b.num_tabs)
         existing_tab_url = b.GetNthTabUrl(0)
         b.NewTab()
         self.assertEquals(2, b.num_tabs)
         self.assertEquals(b.GetNthTabUrl(0), existing_tab_url)
         self.assertEquals(b.GetNthTabUrl(1), 'about:blank')
         b.CloseTab(1)
         self.assertEquals(1, b.num_tabs)
         self.assertEquals(b.GetNthTabUrl(0), existing_tab_url)
         self.assertRaises(AssertionError, b.CloseTab, 0)
    def testBasicHosting(self):
        unittest_data_dir = os.path.join(os.path.dirname(__file__), '..',
                                         'unittest_data')
        options = options_for_unittests.Get()
        browser_to_create = browser_finder.FindBrowser(options)
        with browser_to_create.Create() as b:
            b.SetHTTPServerDirectory(unittest_data_dir)
            with b.ConnectToNthTab(0) as t:
                t.page.Navigate(b.http_server.UrlOf('/blank.html'))
                t.WaitForDocumentReadyStateToBeComplete()
                x = t.runtime.Evaluate('document.body.innerHTML')
                x = x.strip()

                self.assertEquals(x, 'Hello world')
Exemplo n.º 15
0
    def testRealLoginIfPossible(self):
        credentials_path = os.path.join(os.path.dirname(__file__), '..', '..',
                                        'perf', 'data', 'credentials.json')
        if not os.path.exists(credentials_path):
            return

        options = options_for_unittests.Get()
        with browser_finder.FindBrowser(options).Create() as b:
            b.credentials.credentials_path = credentials_path
            if not b.credentials.CanLogin('google'):
                return
            with b.ConnectToNthTab(0) as tab:
                ret = b.credentials.LoginNeeded(tab, 'google')
                self.assertTrue(ret)
Exemplo n.º 16
0
    def testCommandLineOverriding(self):
        # This test starts the browser with --enable-benchmarking, which should
        # create a chrome.Interval namespace. This tests whether the command line is
        # being set.
        options = options_for_unittests.Get()

        flag1 = '--user-agent=chrome_remote_control'
        options.extra_browser_args.append(flag1)

        browser_to_create = browser_finder.FindBrowser(options)
        with browser_to_create.Create() as b:
            with b.ConnectToNthTab(0) as t:
                t.page.Navigate('http://www.google.com/')
                t.WaitForDocumentReadyStateToBeInteractiveOrBetter()
                self.assertEquals(t.runtime.Evaluate('navigator.userAgent'),
                                  'chrome_remote_control')
  def RunBenchmark(self, benchmark, ps):
    """Runs a benchmark against a pageset, returning the rows its outputs."""
    options = options_for_unittests.Get()
    assert options
    temp_parser = options.CreateParser()
    benchmark.AddOptions(temp_parser)
    defaults = temp_parser.get_default_values()
    for k, v in defaults.__dict__.items():
      if hasattr(options, k):
        continue
      setattr(options, k, v)

    benchmark.CustomizeBrowserOptions(options)
    self.CustomizeOptionsForTest(options)
    possible_browser = browser_finder.FindBrowser(options)

    results = multi_page_benchmark.BenchmarkResults()
    with page_runner.PageRunner(ps) as runner:
      runner.Run(options, possible_browser, benchmark, results)
    return results