PageRenderTime 60ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/windmill/browser/__init__.py

https://github.com/ijs/windmill
Python | 148 lines | 116 code | 10 blank | 22 comment | 5 complexity | 117b561a44ff5f5989f27d95aee5ceb9 MD5 | raw file
  1. # Copyright (c) 2006-2007 Open Source Applications Foundation
  2. # Copyright (c) 2008-2009 Mikeal Rogers <mikeal.rogers@gmail.com>
  3. # Copyright (c) 2009 Domen Kozar <domen@dev.si>
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. import windmill
  17. import sys
  18. import copy
  19. from pkg_resources import resource_string
  20. import os
  21. if not sys.version.startswith('2.4'):
  22. from urlparse import urlparse
  23. else:
  24. # python 2.4
  25. from windmill.tools.urlparse_25 import urlparse
  26. windmill.browser_registry = {}
  27. def get_firefox_controller():
  28. """Get the firefox browser object"""
  29. from windmill.dep import mozrunner
  30. global_settings = mozrunner.global_settings
  31. from windmill.dep import simplesettings
  32. mozrunner_settings = simplesettings.initialize_settings(global_settings, mozrunner,
  33. local_env_variable=mozrunner.settings_env)
  34. for key, value in mozrunner.settings.items():
  35. if not windmill.settings.has_key(key):
  36. windmill.settings[key] = value
  37. test_url = windmill.get_test_url(windmill.settings['TEST_URL'])
  38. if windmill.settings['INSTALL_FIREBUG']:
  39. windmill.settings['MOZILLA_PLUGINS'] = [os.path.join(os.path.dirname(__file__), os.path.pardir, 'xpi', 'firebug-1.5.0.xpi.xpi')]
  40. prop_hash = {
  41. 'extensions.chromebug.openalways' : True,
  42. 'extensions.chromebug.showIntroduction' : False,
  43. 'general.warnOnAboutConfig' : False,
  44. 'extensions.venkman.enableChromeFilter' : False,
  45. # Get rid of default browser check
  46. "browser.shell.checkDefaultBrowser": False,
  47. # Suppress authentication confirmations
  48. "network.http.phishy-userpass-length": 255,
  49. # Disable pop-up blocking
  50. "browser.allowpopups": True,
  51. "dom.disable_open_during_load": False,
  52. # Open links in new windows (Firefox 2.0)
  53. "browser.link.open_external": 2,
  54. "browser.link.open_newwindow": 2,
  55. # Configure local proxy
  56. "network.proxy.http": '127.0.0.1',
  57. "network.proxy.http_port": windmill.settings['SERVER_HTTP_PORT'],
  58. "network.proxy.no_proxies_on": "",
  59. "network.proxy.type": 1,
  60. #"network.http.proxy.pipelining" : True,
  61. "network.http.max-connections": 10,
  62. "network.http.max-connections-per-server": 8,
  63. # "network.http.max-persistent-connections-per-proxy": 2,
  64. # "network.http.max-persistent-connections-per-server": 2,
  65. "network.http.pipelining.maxrequests": 10,
  66. # Turn off favicon requests, no need for even more requests
  67. "browser.chrome.favicons": False,
  68. "startup.homepage_override_url": test_url,
  69. "browser.startup.homepage": test_url,
  70. "startup.homepage_welcome_url": "",
  71. # Disable security warnings
  72. "security.warn_submit_insecure": False,
  73. "security.warn_submit_insecure.show_once": False,
  74. "security.warn_entering_secure": False,
  75. "security.warn_entering_secure.show_once": False,
  76. "security.warn_entering_weak": False,
  77. "security.warn_entering_weak.show_once": False,
  78. "security.warn_leaving_secure": False,
  79. "security.warn_leaving_secure.show_once": False,
  80. "security.warn_viewing_mixed": False,
  81. "security.warn_viewing_mixed.show_once": False,
  82. # Disable cache
  83. "browser.cache.disk.enable": False,
  84. "browser.sessionstore.resume_from_crash": False,
  85. # self.user_pref('"browser.cache.memory.enable", false')
  86. # Disable "do you want to remember this password?"
  87. "signon.rememberSignons": False,
  88. "dom.max_script_run_time": 100,
  89. # Disable OSCP validation, breaks through proxy.
  90. "security.OCSP.enabled":0,
  91. #Make the firefox IDE stop showing the location bar
  92. "dom.disable_window_open_feature.location":False,
  93. "browser.rights.3.shown": True,
  94. }
  95. if windmill.has_ssl:
  96. prop_hash["network.proxy.ssl"] = '127.0.0.1'
  97. prop_hash["network.proxy.ssl_port"] = windmill.settings['SERVER_HTTP_PORT']
  98. windmill.settings['MOZILLA_PREFERENCES'].update(prop_hash)
  99. windmill.settings['MOZILLA_CMD_ARGS'] = [test_url]
  100. controller = mozrunner.get_moz_from_settings(copy.copy(windmill.settings))
  101. # Override cert8.db with one from windmill which has windmill certificate
  102. # in it, that way self-signed certificate warning is suppressed.
  103. cert8 = resource_string(__name__, 'cert8.db')
  104. if sys.platform not in ('win32', 'cygwin',):
  105. f = open(os.path.join(controller.profile, 'cert8.db'), 'w')
  106. else:
  107. f = open(os.path.join(controller.profile, 'cert8.db'), 'wb')
  108. f.write(cert8)
  109. f.close()
  110. windmill.settings['MOZILLA_PROFILE'] = mozrunner.settings['MOZILLA_PROFILE']
  111. return controller
  112. def get_ie_controller():
  113. """Get the IE browser object"""
  114. import ie
  115. browser = ie.InternetExplorer()
  116. return browser
  117. def get_safari_controller():
  118. """Get the Safari browser object"""
  119. import safari
  120. browser = safari.Safari()
  121. return browser
  122. def get_chrome_controller():
  123. """Get the Safari browser object"""
  124. import chrome
  125. browser = chrome.Chrome()
  126. return browser