コード例 #1
0
  def __init__(self, backend, platform_backend, credentials_path):
    super(Browser, self).__init__(app_backend=backend,
                                  platform_backend=platform_backend)
    self._browser_backend = backend
    self._platform_backend = platform_backend
    self._local_server_controller = local_server.LocalServerController(
        platform_backend)
    self._tabs = tab_list.TabList(backend.tab_list_backend)
    self.credentials = browser_credentials.BrowserCredentials()
    self.credentials.credentials_path = credentials_path
    self._platform_backend.DidCreateBrowser(self, self._browser_backend)

    browser_options = self._browser_backend.browser_options
    self.platform.FlushDnsCache()
    if browser_options.clear_sytem_cache_for_browser_and_profile_on_start:
      if self.platform.CanFlushIndividualFilesFromSystemCache():
        self.platform.FlushSystemCacheForDirectory(
            self._browser_backend.profile_directory)
        self.platform.FlushSystemCacheForDirectory(
            self._browser_backend.browser_directory)
      else:
        self.platform.FlushEntireSystemCache()

    self._browser_backend.SetBrowser(self)
    self._browser_backend.Start()
    self._platform_backend.DidStartBrowser(self, self._browser_backend)
    self._profiling_controller = profiling_controller.ProfilingController(
        self._browser_backend.profiling_controller_backend)
コード例 #2
0
 def CheckCredentials(self, story_set):
   """Verify that all pages in story_set use proper credentials"""
   for story in story_set.stories:
     if not isinstance(story, page.Page):
       continue
     credentials = browser_credentials.BrowserCredentials()
     if story.credentials_path:
       credentials.credentials_path = (
           os.path.join(story.base_dir, story.credentials_path))
     fail_message = ('page %s of %s has invalid credentials %s' %
                     (story.url, story_set.file_path, story.credentials))
     if story.credentials:
       try:
         self.assertTrue(credentials.CanLogin(story.credentials), fail_message)
       except browser_credentials.CredentialsError:
         self.fail(fail_message)
コード例 #3
0
ファイル: browser.py プロジェクト: wanghui0720/catapult
    def __init__(self, backend, platform_backend, credentials_path):
        super(Browser, self).__init__(app_backend=backend,
                                      platform_backend=platform_backend)
        try:
            self._browser_backend = backend
            self._platform_backend = platform_backend
            self._tabs = tab_list.TabList(backend.tab_list_backend)
            self.credentials = browser_credentials.BrowserCredentials()
            self.credentials.credentials_path = credentials_path
            self._platform_backend.DidCreateBrowser(self,
                                                    self._browser_backend)
            browser_options = self._browser_backend.browser_options
            self.platform.FlushDnsCache()
            if browser_options.clear_sytem_cache_for_browser_and_profile_on_start:
                if self.platform.CanFlushIndividualFilesFromSystemCache():
                    self.platform.FlushSystemCacheForDirectory(
                        self._browser_backend.profile_directory)
                    self.platform.FlushSystemCacheForDirectory(
                        self._browser_backend.browser_directory)
                elif self.platform.SupportFlushEntireSystemCache():
                    self.platform.FlushEntireSystemCache()
                else:
                    logging.warning('Flush system cache is not supported. ' +
                                    'Did not flush system cache.')

            self._browser_backend.SetBrowser(self)
            self._browser_backend.Start()
            self._LogBrowserInfo()
            self._platform_backend.DidStartBrowser(self, self._browser_backend)
            self._profiling_controller = profiling_controller.ProfilingController(
                self._browser_backend.profiling_controller_backend)
        except Exception:
            exc_info = sys.exc_info()
            logging.error(
                'Failed with %s while starting the browser backend.',
                exc_info[0].__name__)  # Show the exception name only.
            try:
                self._platform_backend.WillCloseBrowser(
                    self, self._browser_backend)
            except Exception:
                exception_formatter.PrintFormattedException(
                    msg='Exception raised while closing platform backend')
            raise exc_info[0], exc_info[1], exc_info[2]
コード例 #4
0
    def testCredentialsInfrastructure(self):
        google_backend = BackendStub("google")
        othersite_backend = BackendStub("othersite")
        browser_cred = browser_credentials.BrowserCredentials(
            [google_backend, othersite_backend])
        try:
            with tempfile.NamedTemporaryFile(delete=False) as f:
                f.write(SIMPLE_CREDENTIALS_STRING)

            browser_cred.credentials_path = f.name

            # Should true because it has a password and a backend.
            self.assertTrue(browser_cred.CanLogin('google'))

            # Should be false succeed because it has no password.
            self.assertFalse(browser_cred.CanLogin('othersite'))

            # Should fail because it has no backend.
            self.assertRaises(Exception,
                              lambda: browser_cred.CanLogin('foobar'))

            class FakeTab(object):
                def __init__(self):
                    self.action_runner = None

            tab = FakeTab()
            ret = browser_cred.LoginNeeded(tab, 'google')
            self.assertTrue(ret)
            self.assertTrue(google_backend.login_needed_called is not None)
            self.assertEqual(tab, google_backend.login_needed_called[0])
            self.assertEqual("example",
                             google_backend.login_needed_called[1]["username"])
            self.assertEqual("asdf",
                             google_backend.login_needed_called[1]["password"])

            browser_cred.LoginNoLongerNeeded(tab, 'google')
            self.assertTrue(
                google_backend.login_no_longer_needed_called is not None)
            self.assertEqual(tab,
                             google_backend.login_no_longer_needed_called[0])
        finally:
            os.remove(f.name)