Bug 830430 - automation.py should read profile data from a file, r=jhammel
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Tue, 07 May 2013 11:19:46 -0400
changeset 137897 9e5ad7ec4b6ec9a6d473b1527d69b3c091dc4f18
parent 137896 86cdfca59c81867641f90739127f9dfd2bf1b37d
child 137898 87a68fd848003634c41e9c568e3126b7b0ac7148
push idunknown
push userunknown
push dateunknown
reviewersjhammel
bugs830430
milestone23.0a1
Bug 830430 - automation.py should read profile data from a file, r=jhammel * * * Copy prefs general
build/Makefile.in
build/automation.py.in
build/mobile/b2gautomation.py
build/pgo/Makefile.in
testing/mochitest/runtests.py
testing/profiles/prefs_general.js
--- a/build/Makefile.in
+++ b/build/Makefile.in
@@ -88,16 +88,17 @@ include $(topsrcdir)/config/rules.mk
 TARGET_DEPTH = ..
 include $(srcdir)/automation-build.mk
 
 _LEAKTEST_DIR = $(DEPTH)/_leaktest
 
 _LEAKTEST_FILES =    \
 		automation.py \
 		automationutils.py \
+		$(topsrcdir)/testing/profiles/prefs_general.js \
 		leaktest.py \
 		bloatcycle.html \
 		$(topsrcdir)/build/pgo/server-locations.txt \
 		$(topsrcdir)/build/pgo/favicon.ico \
 		$(topsrcdir)/build/pgo/blueprint/sample.html \
 		$(topsrcdir)/build/pgo/blueprint/elements.html \
 		$(topsrcdir)/build/pgo/blueprint/forms.html \
 		$(topsrcdir)/build/pgo/blueprint/grid.html \
--- a/build/automation.py.in
+++ b/build/automation.py.in
@@ -38,16 +38,18 @@ except:
             'mozlog']
     for dep in deps:
         module = os.path.join(mozbase, dep)
         if module not in sys.path:
             sys.path.append(module)
     import mozcrash
 # ---------------------------------------------------------------
 
+_DEFAULT_PREFERENCE_FILE = os.path.join(SCRIPT_DIR, 'prefs_general.js')
+
 _DEFAULT_WEB_SERVER = "127.0.0.1"
 _DEFAULT_HTTP_PORT = 8888
 _DEFAULT_SSL_PORT = 4443
 _DEFAULT_WEBSOCKET_PORT = 9988
 
 # from nsIPrincipal.idl
 _APP_STATUS_NOT_INSTALLED = 0
 _APP_STATUS_INSTALLED     = 1
@@ -428,154 +430,41 @@ class Automation(object):
 
       manifestDir = os.path.join(webappsDir, app['name'])
       os.mkdir(manifestDir)
 
       manifestFile = open(os.path.join(manifestDir, "manifest.webapp"), "a")
       manifestFile.write(manifest)
       manifestFile.close()
 
-  def initializeProfile(self, profileDir, extraPrefs=[],
-                        useServerLocations=False,
-                        initialProfile=None):
+  def initializeProfile(self, profileDir,
+                              extraPrefs=None,
+                              useServerLocations=False,
+                              initialProfile=None,
+                              prefsPath=_DEFAULT_PREFERENCE_FILE):
     " Sets up the standard testing profile."
 
+    extraPrefs = extraPrefs or []
     prefs = []
     # Start with a clean slate.
     shutil.rmtree(profileDir, True)
 
     if initialProfile:
       shutil.copytree(initialProfile, profileDir)
     else:
       os.mkdir(profileDir)
 
     # Set up permissions database
     locations = self.readLocations()
     self.setupPermissionsDatabase(profileDir,
       {'allowXULXBL':[(l.host, 'noxul' not in l.options) for l in locations]});
 
-    # NOTE: For refactoring purposes we are temporarily storing these prefs
-    #       in two locations. If you update a pref below, please also update
-    #       it in source/testing/profiles/prefs_general.js.
-    #       See bug 830430 for more details.
-    part = """\
-user_pref("browser.console.showInPanel", true);
-user_pref("browser.dom.window.dump.enabled", true);
-user_pref("browser.firstrun.show.localepicker", false);
-user_pref("browser.firstrun.show.uidiscovery", false);
-user_pref("browser.startup.page", 0); // use about:blank, not browser.startup.homepage
-user_pref("browser.ui.layout.tablet", 0); // force tablet UI off
-user_pref("dom.allow_scripts_to_close_windows", true);
-user_pref("dom.disable_open_during_load", false);
-user_pref("dom.experimental_forms", true); // on for testing
-user_pref("dom.experimental_forms_range", true); // on for testing
-user_pref("dom.max_script_run_time", 0); // no slow script dialogs
-user_pref("hangmonitor.timeout", 0); // no hang monitor
-user_pref("dom.max_chrome_script_run_time", 0);
-user_pref("dom.popup_maximum", -1);
-user_pref("dom.send_after_paint_to_content", true);
-user_pref("dom.successive_dialog_time_limit", 0);
-user_pref("signed.applets.codebase_principal_support", true);
-user_pref("browser.shell.checkDefaultBrowser", false);
-user_pref("shell.checkDefaultClient", false);
-user_pref("browser.warnOnQuit", false);
-user_pref("accessibility.typeaheadfind.autostart", false);
-user_pref("javascript.options.showInConsole", true);
-user_pref("devtools.errorconsole.enabled", true);
-user_pref("devtools.debugger.remote-port", 6023);
-user_pref("layout.debug.enable_data_xbl", true);
-user_pref("browser.EULA.override", true);
-user_pref("javascript.options.jit_hardening", true);
-user_pref("gfx.color_management.force_srgb", true);
-user_pref("network.manage-offline-status", false);
-user_pref("dom.min_background_timeout_value", 1000);
-user_pref("test.mousescroll", true);
-user_pref("security.default_personal_cert", "Select Automatically"); // Need to client auth test be w/o any dialogs
-user_pref("network.http.prompt-temp-redirect", false);
-user_pref("media.cache_size", 100);
-user_pref("media.volume_scale", "0.01");
-user_pref("security.warn_viewing_mixed", false);
-user_pref("app.update.enabled", false);
-user_pref("app.update.staging.enabled", false);
-user_pref("browser.panorama.experienced_first_run", true); // Assume experienced
-user_pref("dom.w3c_touch_events.enabled", 1);
-user_pref("dom.undo_manager.enabled", true);
-user_pref("dom.webcomponents.enabled", true);
-// Set a future policy version to avoid the telemetry prompt.
-user_pref("toolkit.telemetry.prompted", 999);
-user_pref("toolkit.telemetry.notifiedOptOut", 999);
-// Existing tests assume there is no font size inflation.
-user_pref("font.size.inflation.emPerLine", 0);
-user_pref("font.size.inflation.minTwips", 0);
-
-// Only load extensions from the application and user profile
-// AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_APPLICATION
-user_pref("extensions.enabledScopes", 5);
-// Disable metadata caching for installed add-ons by default
-user_pref("extensions.getAddons.cache.enabled", false);
-// Disable intalling any distribution add-ons
-user_pref("extensions.installDistroAddons", false);
-
-user_pref("geo.wifi.uri", "http://%(server)s/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs");
-user_pref("geo.wifi.testing", true);
-user_pref("geo.ignore.location_filter", true);
-
-user_pref("camino.warn_when_closing", false); // Camino-only, harmless to others
-
-// Make url-classifier updates so rare that they won't affect tests
-user_pref("urlclassifier.updateinterval", 172800);
-// Point the url-classifier to the local testing server for fast failures
-user_pref("browser.safebrowsing.gethashURL", "http://%(server)s/safebrowsing-dummy/gethash");
-user_pref("browser.safebrowsing.keyURL", "http://%(server)s/safebrowsing-dummy/newkey");
-user_pref("browser.safebrowsing.updateURL", "http://%(server)s/safebrowsing-dummy/update");
-// Point update checks to the local testing server for fast failures
-user_pref("extensions.update.url", "http://%(server)s/extensions-dummy/updateURL");
-user_pref("extensions.update.background.url", "http://%(server)s/extensions-dummy/updateBackgroundURL");
-user_pref("extensions.blocklist.url", "http://%(server)s/extensions-dummy/blocklistURL");
-user_pref("extensions.hotfix.url", "http://%(server)s/extensions-dummy/hotfixURL");
-// Turn off extension updates so they don't bother tests
-user_pref("extensions.update.enabled", false);
-// Make sure opening about:addons won't hit the network
-user_pref("extensions.webservice.discoverURL", "http://%(server)s/extensions-dummy/discoveryURL");
-// Make sure AddonRepository won't hit the network
-user_pref("extensions.getAddons.maxResults", 0);
-user_pref("extensions.getAddons.get.url", "http://%(server)s/extensions-dummy/repositoryGetURL");
-user_pref("extensions.getAddons.getWithPerformance.url", "http://%(server)s/extensions-dummy/repositoryGetWithPerformanceURL");
-user_pref("extensions.getAddons.search.browseURL", "http://%(server)s/extensions-dummy/repositoryBrowseURL");
-user_pref("extensions.getAddons.search.url", "http://%(server)s/extensions-dummy/repositorySearchURL");
-// Make sure that opening the plugins check page won't hit the network
-user_pref("plugins.update.url", "http://%(server)s/plugins-dummy/updateCheckURL");
-
-// Existing tests don't wait for the notification button security delay
-user_pref("security.notification_enable_delay", 0);
-
-// Make enablePrivilege continue to work for test code. :-(
-user_pref("security.turn_off_all_security_so_that_viruses_can_take_over_this_computer", true);
-
-// In the default configuration, we bypass XBL scopes (a security feature) for
-// domains whitelisted for remote XUL, so that intranet apps and such continue
-// to work without major rewrites. However, we also use the whitelist mechanism
-// to run our XBL tests in automation, in which case we really want to be testing
-// the configuration that we ship to users without special whitelisting. So we
-// use an additional pref here to allow automation to use the "normal" behavior.
-user_pref("dom.use_xbl_scopes_for_remote_xul", true);
-
-// Get network events.
-user_pref("network.activity.blipIntervalMilliseconds", 250);
-
-// Don't allow the Data Reporting service to prompt for policy acceptance.
-user_pref("datareporting.policy.dataSubmissionPolicyBypassAcceptance", true);
-
-// Point Firefox Health Report at a local server. We don't care if it actually
-// works. It just can't hit the default production endpoint.
-user_pref("datareporting.healthreport.documentServerURI", "http://%(server)s/healthreport/");
-
-// Make sure CSS error reporting is enabled for tests
-user_pref("layout.css.report_errors", true);
-""" % { "server" : self.webServer + ":" + str(self.httpPort) }
+    f = open(prefsPath, 'r')
+    part = f.read() % {"server" : "%s:%s" % (self.webServer, self.httpPort)}
+    f.close()
     prefs.append(part)
 
     if useServerLocations:
       # We need to proxy every server but the primary one.
       origins = ["'%s://%s:%s'" % (l.scheme, l.host, l.port)
                 for l in filter(lambda l: "primary" not in l.options, locations)]
       origins = ", ".join(origins)
 
@@ -614,26 +503,25 @@ function FindProxyForURL(url, host)
     return 'PROXY %(remote)s:%(sslport)s';
   return 'DIRECT';
 }""" % { "origins": origins,
          "remote":  self.webServer,
          "httpport":self.httpPort,
          "sslport": self.sslPort }
       pacURL = "".join(pacURL.splitlines())
 
-      part += """
+      part = """
 user_pref("network.proxy.type", 2);
 user_pref("network.proxy.autoconfig_url", "%(pacURL)s");
 
 user_pref("camino.use_system_proxy_settings", false); // Camino-only, harmless to others
 """ % {"pacURL": pacURL}
-      prefs.append(part)
     else:
       part = 'user_pref("network.proxy.type", 0);\n'
-      prefs.append(part)
+    prefs.append(part)
 
     for v in extraPrefs:
       thispref = v.split("=", 1)
       if len(thispref) < 2:
         print "Error: syntax error in --setpref=" + v
         sys.exit(1)
       part = 'user_pref("%s", %s);\n' % (thispref[0], thispref[1])
       prefs.append(part)
--- a/build/mobile/b2gautomation.py
+++ b/build/mobile/b2gautomation.py
@@ -115,26 +115,16 @@ class B2GRemoteAutomation(Automation):
                 crashed = mozcrash.check_for_crashes(local_dump_dir, symbolsPath, test_name=self.lastTestSeen)
             except:
                 traceback.print_exc()
             finally:
                 shutil.rmtree(local_dump_dir)
                 self._devicemanager.removeDir(remote_dump_dir)
         return crashed
 
-    def initializeProfile(self,  profileDir, extraPrefs=[],
-                          useServerLocations=False,
-                          initialProfile=None):
-        # add b2g specific prefs
-        extraPrefs.extend(["browser.manifestURL='dummy (bug 772307)'"])
-        return Automation.initializeProfile(self, profileDir,
-                                            extraPrefs,
-                                            useServerLocations,
-                                            initialProfile)
-
     def buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs):
         # if remote profile is specified, use that instead
         if (self._remoteProfile):
             profileDir = self._remoteProfile
 
         cmd, args = Automation.buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs)
 
         return app, args
--- a/build/pgo/Makefile.in
+++ b/build/pgo/Makefile.in
@@ -25,16 +25,17 @@ else
 browser_path = \"$(TARGET_DIST)/$(MOZ_APP_NAME)/$(PROGRAM)\"
 endif
    
 # Stuff to make a build with a profile
 
 _PGO_FILES = 	\
   automation.py \
   $(topsrcdir)/build/automationutils.py \
+  $(topsrcdir)/testing/profiles/prefs_general.js \
   profileserver.py \
   genpgocert.py \
   index.html \
   server-locations.txt \
   favicon.ico \
   $(NULL)
 
 genpgocert.py: genpgocert.py.in
--- a/testing/mochitest/runtests.py
+++ b/testing/mochitest/runtests.py
@@ -583,17 +583,19 @@ class Mochitest(object):
     return self.getFullPath(logFile)
 
   def buildProfile(self, options):
     """ create the profile and add optional chrome bits and files if requested """
     if options.browserChrome and options.timeout:
       options.extraPrefs.append("testing.browserTestHarness.timeout=%d" % options.timeout)
     self.automation.initializeProfile(options.profilePath,
                                       options.extraPrefs,
-                                      useServerLocations=True)
+                                      useServerLocations=True,
+                                      prefsPath=os.path.join(self.SCRIPT_DIRECTORY,
+                                                        'profile_data', 'prefs_general.js'))
     manifest = self.addChromeToProfile(options)
     self.copyExtraFilesToProfile(options)
     self.installExtensionsToProfile(options)
     return manifest
 
   def buildBrowserEnv(self, options):
     """ build the environment variables for the specific test and operating system """
     browserEnv = self.automation.environment(xrePath = options.xrePath)
--- a/testing/profiles/prefs_general.js
+++ b/testing/profiles/prefs_general.js
@@ -88,16 +88,24 @@ user_pref("extensions.getAddons.search.u
 user_pref("plugins.update.url", "http://%(server)s/plugins-dummy/updateCheckURL");
 
 // Existing tests don't wait for the notification button security delay
 user_pref("security.notification_enable_delay", 0);
 
 // Make enablePrivilege continue to work for test code. :-(
 user_pref("security.turn_off_all_security_so_that_viruses_can_take_over_this_computer", true);
 
+// In the default configuration, we bypass XBL scopes (a security feature) for
+// domains whitelisted for remote XUL, so that intranet apps and such continue
+// to work without major rewrites. However, we also use the whitelist mechanism
+// to run our XBL tests in automation, in which case we really want to be testing
+// the configuration that we ship to users without special whitelisting. So we
+// use an additional pref here to allow automation to use the "normal" behavior.
+user_pref("dom.use_xbl_scopes_for_remote_xul", true);
+
 // Get network events.
 user_pref("network.activity.blipIntervalMilliseconds", 250);
 
 // Don't allow the Data Reporting service to prompt for policy acceptance.
 user_pref("datareporting.policy.dataSubmissionPolicyBypassAcceptance", true);
 
 // Point Firefox Health Report at a local server. We don't care if it actually
 // works. It just can't hit the default production endpoint.