Merge mozilla-central into services-central
authorGregory Szorc <gps@mozilla.com>
Tue, 10 Jul 2012 10:22:21 -0700
changeset 102007 5124e5684be353762035b3fa0c214fdfd9ecadb5
parent 102006 f6a5b82eb76bd7c0d4f01cf3bf87cd4f533c2134 (current diff)
parent 101469 5b77d71ed9275a71ab9e3223e488eb6effd31cdf (diff)
child 102008 f010345cf137f3b9b8188e976e9824edcc2513e5
push idunknown
push userunknown
push dateunknown
milestone16.0a1
Merge mozilla-central into services-central
--- a/Makefile.in
+++ b/Makefile.in
@@ -216,8 +216,10 @@ libs:: .gdbinit
 .PHONY: maybe_clobber_profiledbuild
 
 # Look for R_386_PC32 relocations in shared libs, these
 # break x86_64 builds and SELinux users.
 ifeq ($(OS_TARGET)_$(TARGET_XPCOM_ABI),Linux_x86-gcc3)
 scheck::
 	@relcount=`find $(DIST)/bin -name "*.so" | xargs objdump -R | grep R_386_PC32 | wc -l` && if test $$relcount -gt 0; then echo "FAILED: R_386_PC32 relocations detected in a shared library.  Did you use a system header without adding it to config/system-headers?"; exit 1; else echo "PASSED"; fi
 endif
+
+js/src/Makefile: subsrcdir := js/src
--- a/accessible/tests/mochitest/Makefile.in
+++ b/accessible/tests/mochitest/Makefile.in
@@ -31,19 +31,18 @@ DIRS	= \
   textcaret \
   textselection \
   tree \
   treeupdate \
   value \
   $(null)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_A11Y_FILES =\
 		formimage.png \
 		letters.gif \
 		moz.png \
 		$(topsrcdir)/content/media/test/bug461281.ogg \
 		longdesc_src.html \
 		actions.js \
 		attributes.js \
 		autocomplete.js \
@@ -69,10 +68,9 @@ include $(topsrcdir)/config/rules.mk
 		test_textboxes.html \
 		test_textboxes.xul \
 		testTextboxes.js \
 		text.js \
 		treeview.css \
 		treeview.js \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/actions/Makefile.in
+++ b/accessible/tests/mochitest/actions/Makefile.in
@@ -5,27 +5,25 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/actions
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_A11Y_FILES =\
 		test_anchors.html \
 		test_aria.html \
 		test_general.html \
 		test_general.xul \
 		test_controls.html \
 		test_keys_menu.xul \
 		test_keys.html \
 		test_link.html \
 		test_media.html \
 		test_select.html \
 		test_tree.xul \
 		test_treegrid.xul \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/attributes/Makefile.in
+++ b/accessible/tests/mochitest/attributes/Makefile.in
@@ -5,24 +5,22 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/attributes
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_A11Y_FILES =\
 		test_obj.html \
 		test_obj_css.html \
 		test_obj_css.xul \
 		test_obj_group.html \
 		test_obj_group.xul \
 		test_obj_group_tree.xul \
 		test_tag.html \
 		test_text.html \
 		test_xml-roles.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/bounds/Makefile.in
+++ b/accessible/tests/mochitest/bounds/Makefile.in
@@ -5,18 +5,16 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/bounds
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_A11Y_FILES =\
 		test_list.html \
 		test_select.html \
 		test_zoom.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/editabletext/Makefile.in
+++ b/accessible/tests/mochitest/editabletext/Makefile.in
@@ -5,18 +5,16 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/editabletext
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_A11Y_FILES =\
 		editabletext.js \
 		test_1.html \
 		test_2.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/elm/Makefile.in
+++ b/accessible/tests/mochitest/elm/Makefile.in
@@ -5,19 +5,17 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/elm
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_A11Y_FILES =\
 		test_figure.html \
 		test_listbox.xul \
 		test_nsApplicationAcc.html \
 		test_plugin.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/events/Makefile.in
+++ b/accessible/tests/mochitest/events/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/events
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_A11Y_FILES =\
 		docload_wnd.html \
 		focus.html \
 		scroll.html \
 		test_aria_alert.html \
 		test_aria_menu.html \
 		test_aria_objattr.html \
 		test_aria_statechange.html \
 		test_attrs.html \
@@ -57,10 +56,9 @@ include $(topsrcdir)/config/rules.mk
 		test_statechange.html \
 		test_text_alg.html \
 		test_text.html \
 		test_textattrchange.html \
 		test_tree.xul \
 		test_valuechange.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/focus/Makefile.in
+++ b/accessible/tests/mochitest/focus/Makefile.in
@@ -5,18 +5,16 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/focus
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_A11Y_FILES =\
 		test_focusedChild.html \
 		test_takeFocus.html \
 		test_takeFocus.xul \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/hittest/Makefile.in
+++ b/accessible/tests/mochitest/hittest/Makefile.in
@@ -5,20 +5,18 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/hittest
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_A11Y_FILES = \
 		test_browser.html \
 		test_general.html \
 		test_zoom_tree.xul \
 		test_zoom.html \
 		zoom_tree.xul \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/hyperlink/Makefile.in
+++ b/accessible/tests/mochitest/hyperlink/Makefile.in
@@ -5,18 +5,16 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/hyperlink
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_A11Y_FILES =\
 		hyperlink.js \
 		test_general.html \
 		test_general.xul \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/hypertext/Makefile.in
+++ b/accessible/tests/mochitest/hypertext/Makefile.in
@@ -5,17 +5,15 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/hypertext
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_A11Y_FILES = \
 		test_general.html \
 		test_update.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/name/Makefile.in
+++ b/accessible/tests/mochitest/name/Makefile.in
@@ -5,27 +5,25 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/name
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_A11Y_FILES =\
 		general.css \
 		general.xbl \
 		markup.js \
 		test_button.html \
 		test_general.html \
 		test_general.xul \
 		test_link.html \
 		test_list.html \
 		test_markup.html \
 		test_browserui.xul \
 		test_tree.xul \
 		markuprules.xml \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/pivot/Makefile.in
+++ b/accessible/tests/mochitest/pivot/Makefile.in
@@ -5,17 +5,15 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/pivot
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_A11Y_FILES = \
 		doc_virtualcursor.html \
 		test_virtualcursor.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/relations/Makefile.in
+++ b/accessible/tests/mochitest/relations/Makefile.in
@@ -5,23 +5,21 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/relations
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_A11Y_FILES =\
 		test_bindings.xhtml \
 		test_embeds.xul \
 		test_general.html \
 		test_general.xul \
 		test_tabbrowser.xul \
 		test_tree.xul \
 		test_ui_modalprompt.html \
 		test_update.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/role/Makefile.in
+++ b/accessible/tests/mochitest/role/Makefile.in
@@ -4,18 +4,16 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/role
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_A11Y_FILES =\
 		test_aria.html \
 		test_aria.xul \
 		test_general.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/selectable/Makefile.in
+++ b/accessible/tests/mochitest/selectable/Makefile.in
@@ -5,21 +5,19 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/selectable
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_A11Y_FILES =\
 		test_aria.html \
 		test_listbox.xul \
 		test_menu.xul \
 		test_menulist.xul \
 		test_select.html \
 		test_tree.xul \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/states/Makefile.in
+++ b/accessible/tests/mochitest/states/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/states
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_A11Y_FILES =\
 		test_aria.html \
 		test_aria_imgmap.html \
 		test_aria_widgetitems.html \
 		test_buttons.html \
 		test_controls.html \
 		test_controls.xul \
 		test_doc.html \
 		test_docarticle.html \
@@ -34,10 +33,9 @@ include $(topsrcdir)/config/rules.mk
 		test_visibility.html \
 		z_frames.html \
 		z_frames_article.html \
 		z_frames_checkbox.html \
 		z_frames_textbox.html \
 		z_frames_update.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/table/Makefile.in
+++ b/accessible/tests/mochitest/table/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/table
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_A11Y_FILES = \
 		test_headers_ariagrid.html \
 		test_headers_listbox.xul \
 		test_headers_table.html \
 		test_headers_tree.xul \
 		test_indexes_ariagrid.html \
 		test_indexes_listbox.xul \
 		test_indexes_table.html \
 		test_indexes_tree.xul \
@@ -30,10 +29,9 @@ include $(topsrcdir)/config/rules.mk
 		test_struct_ariatreegrid.html \
 		test_struct_listbox.xul \
 		test_struct_table.html \
 		test_struct_tree.xul \
 		test_table_1.html \
 		test_table_2.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/text/Makefile.in
+++ b/accessible/tests/mochitest/text/Makefile.in
@@ -5,23 +5,21 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/text
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_A11Y_FILES = \
 		doc.html \
 		test_doc.html \
 		test_hypertext.html \
 		test_passwords.html \
 		test_selection.html \
 		test_singleline.html \
 		test_whitespaces.html \
 		test_words.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/textcaret/Makefile.in
+++ b/accessible/tests/mochitest/textcaret/Makefile.in
@@ -5,17 +5,15 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/textcaret
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_A11Y_FILES = \
 		test_browserui.xul \
 		test_general.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/textselection/Makefile.in
+++ b/accessible/tests/mochitest/textselection/Makefile.in
@@ -5,16 +5,14 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/textselection
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_A11Y_FILES = \
 		test_general.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/tree/Makefile.in
+++ b/accessible/tests/mochitest/tree/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/tree
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_A11Y_FILES =\
 		dockids.html \
 	$(warning test_applicationacc.xul temporarily disabled, see bug 561508) \
 		test_aria_globals.html \
 		test_aria_imgmap.html \
 		test_aria_presentation.html \
 		test_button.xul \
 		test_canvas.html \
 		test_combobox.xul \
@@ -41,10 +40,9 @@ include $(topsrcdir)/config/rules.mk
 		test_table.html \
 		test_tree.xul \
 		test_txtcntr.html \
 		test_txtctrl.html \
 		test_txtctrl.xul \
 		wnd.xul \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/treeupdate/Makefile.in
+++ b/accessible/tests/mochitest/treeupdate/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/treeupdate
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_A11Y_FILES =\
 		test_ariadialog.html \
 		test_canvas.html \
 		test_colorpicker.xul \
 		test_cssoverflow.html \
 		test_contextmenu.xul \
 		test_doc.html \
 		test_gencontent.html \
 		test_hidden.html \
@@ -29,10 +28,9 @@ include $(topsrcdir)/config/rules.mk
 		test_menubutton.xul \
 		test_recreation.html \
 		test_select.html \
 		test_textleaf.html \
 		test_visibility.html \
 		test_whitespace.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/accessible/tests/mochitest/value/Makefile.in
+++ b/accessible/tests/mochitest/value/Makefile.in
@@ -5,18 +5,16 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible/value
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_A11Y_FILES =\
 		test_general.html \
 		test_progress.html \
 		test_progress.xul \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/app/Makefile.in
+++ b/browser/app/Makefile.in
@@ -26,16 +26,18 @@ DEFINES += \
   -DDOCUMENT_ICO=\"$(DIST)/branding/document.ico\" \
   -DNEWWINDOW_ICO=\"$(DIST)/branding/newwindow.ico\" \
   -DNEWTAB_ICO=\"$(DIST)/branding/newtab.ico\" \
   -DPBMODE_ICO=\"$(DIST)/branding/pbmode.ico\" \
 
   $(NULL)
 
 ifdef LIBXUL_SDK #{
+PREF_JS_EXPORTS += $(srcdir)/profile/channel-prefs.js
+
 include $(topsrcdir)/config/rules.mk
 else
 # Build a binary bootstrapping with XRE_main
 
 PROGRAM = $(MOZ_APP_NAME)$(BIN_SUFFIX)
 
 CPPSRCS = nsBrowserApp.cpp
 
@@ -137,18 +139,16 @@ endif
 libs:: $(srcdir)/profile/prefs.js
 	$(INSTALL) $(IFLAGS1) $^ $(DIST)/bin/defaults/profile
 
 ifndef LIBXUL_SDK
 # channel-prefs.js is handled separate from other prefs due to bug 756325
 libs:: $(srcdir)/profile/channel-prefs.js
 	$(NSINSTALL) -D $(DIST)/bin/defaults/pref
 	$(PYTHON) $(topsrcdir)/config/Preprocessor.py $(PREF_PPFLAGS) $(ACDEFINES) $^ > $(DIST)/bin/defaults/pref/channel-prefs.js
-else
-PREF_JS_EXPORTS += $(srcdir)/profile/channel-prefs.js
 endif
 
 libs:: $(srcdir)/blocklist.xml
 	$(INSTALL) $(IFLAGS1) $^ $(DIST)/bin
 
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 
 MAC_APP_NAME = $(MOZ_APP_DISPLAYNAME)
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1472,17 +1472,19 @@ var gBrowserInit = {
     // Enable Style Editor?
     let styleEditorEnabled = gPrefService.getBoolPref(StyleEditor.prefEnabledName);
     if (styleEditorEnabled) {
       document.getElementById("menu_styleeditor").hidden = false;
       document.getElementById("Tools:StyleEditor").removeAttribute("disabled");
 #ifdef MENUBAR_CAN_AUTOHIDE
       document.getElementById("appmenu_styleeditor").hidden = false;
 #endif
-      document.getElementById("developer-toolbar-styleeditor").hidden = false;
+      // We don't show the Style Editor button in the developer toolbar for now.
+      // See bug 771203
+      // document.getElementById("developer-toolbar-styleeditor").hidden = false;
     }
 
 #ifdef MENUBAR_CAN_AUTOHIDE
     // If the user (or the locale) hasn't enabled the top-level "Character
     // Encoding" menu via the "browser.menu.showCharacterEncoding" preference,
     // hide it.
     if ("true" != gPrefService.getComplexValue("browser.menu.showCharacterEncoding",
                                                Ci.nsIPrefLocalizedString).data)
--- a/browser/base/content/newtab/cells.js
+++ b/browser/base/content/newtab/cells.js
@@ -93,21 +93,21 @@ Cell.prototype = {
   isEmpty: function Cell_isEmpty() {
     return !this.site;
   },
 
   /**
    * Handles all cell events.
    */
   handleEvent: function Cell_handleEvent(aEvent) {
-    // We're not responding to external drag/drop events 
+    // We're not responding to external drag/drop events
     // when our parent window is in private browsing mode.
-    if (inPrivateBrowsingMode && !gDrag.draggedSite)
+    if (inPrivateBrowsingMode() && !gDrag.draggedSite)
       return;
-    
+
     if (aEvent.type != "dragexit" && !gDrag.isValid(aEvent))
       return;
 
     switch (aEvent.type) {
       case "dragenter":
         aEvent.preventDefault();
         gDrop.enter(this, aEvent);
         break;
--- a/browser/base/content/newtab/newTab.js
+++ b/browser/base/content/newtab/newTab.js
@@ -17,36 +17,38 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 
 let {
   links: gLinks,
   allPages: gAllPages,
   pinnedLinks: gPinnedLinks,
   blockedLinks: gBlockedLinks
 } = NewTabUtils;
 
-let chromeWin = window.QueryInterface(Ci.nsIInterfaceRequestor)
-                      .getInterface(Ci.nsIWebNavigation)
-                      .QueryInterface(Ci.nsIDocShellTreeItem)
-                      .rootTreeItem
-                      .QueryInterface(Ci.nsIInterfaceRequestor)
-                      .getInterface(Ci.nsIDOMWindow)
-                      .wrappedJSObject;
-
-let inPrivateBrowsingMode = false;
-
-if ("gPrivateBrowsingUI" in chromeWin)
-  inPrivateBrowsingMode = chromeWin.gPrivateBrowsingUI.privateWindow;
-
 XPCOMUtils.defineLazyGetter(this, "gStringBundle", function() {
   return Services.strings.
     createBundle("chrome://browser/locale/newTab.properties");
 });
 
 function newTabString(name) gStringBundle.GetStringFromName('newtab.' + name);
 
+function inPrivateBrowsingMode() {
+  let chromeWin = window.QueryInterface(Ci.nsIInterfaceRequestor)
+                        .getInterface(Ci.nsIWebNavigation)
+                        .QueryInterface(Ci.nsIDocShellTreeItem)
+                        .rootTreeItem
+                        .QueryInterface(Ci.nsIInterfaceRequestor)
+                        .getInterface(Ci.nsIDOMWindow)
+                        .wrappedJSObject;
+
+  if ("gPrivateBrowsingUI" in chromeWin)
+    return chromeWin.gPrivateBrowsingUI.privateWindow;
+
+  return false;
+}
+
 const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
 
 #include batch.js
 #include transformations.js
 #include page.js
 #include grid.js
 #include cells.js
 #include sites.js
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -8,19 +8,18 @@ srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = browser/base/content/test
 
 DIRS += \
 		newtab \
 		$(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
 		test_feed_discovery.html \
 		feed_discovery.html \
 		test_bug395533.html \
 		bug395533-data.txt \
 		ctxmenu-image.png \
 		video.ogg \
 		test_offlineNotification.html \
 		offlineChild.html \
@@ -39,17 +38,17 @@ include $(topsrcdir)/config/rules.mk
 		gZipOfflineChild.html \
 		gZipOfflineChild.html^headers^ \
 		gZipOfflineChild.cacheManifest \
 		gZipOfflineChild.cacheManifest^headers^ \
 		$(NULL)
 
 # test_contextmenu.html is disabled on Linux due to bug 513558
 ifneq (gtk2,$(MOZ_WIDGET_TOOLKIT))
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		audio.ogg \
 		test_contextmenu.html \
 		subtst_contextmenu.html \
 		$(NULL)
 endif
 
 # The following tests are disabled because they are unreliable:
 #   browser_bug423833.js is bug 428712
@@ -266,13 +265,12 @@ else
 		browser_bug565667.js \
 		$(NULL)
 
 # TODO: Activate after carbon test plugin lands, bug 628651
 # 		browser_maconly_carbon_mismatch_plugin.js \
 
 endif
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
 
 libs::	$(_BROWSER_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
--- a/browser/components/downloads/test/browser/Makefile.in
+++ b/browser/components/downloads/test/browser/Makefile.in
@@ -4,17 +4,15 @@
 DEPTH     = ../../../../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
 
 relativesrcdir = browser/components/downloads/test/browser
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_BROWSER_FILES = \
+MOCHITEST_BROWSER_FILES = \
   browser_basic_functionality.js \
   head.js \
   $(NULL)
 
-libs:: $(_BROWSER_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/components/feeds/test/Makefile.in
+++ b/browser/components/feeds/test/Makefile.in
@@ -12,23 +12,20 @@ include $(DEPTH)/config/autoconf.mk
 
 MODULE		= test_browser_feeds
 XPCSHELL_TESTS	= unit
 
 DIRS = \
 	chrome \
 	$(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES =	bug408328-data.xml \
+MOCHITEST_FILES =	bug408328-data.xml \
 		bug368464-data.xml \
 		test_bug494328.html \
 		bug494328-data.xml \
 		test_bug589543.html \
 		bug589543-data.xml \
 		test_registerHandler.html \
 		valid-feed.xml \
 		valid-unsniffable-feed.xml \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/components/feeds/test/chrome/Makefile.in
+++ b/browser/components/feeds/test/chrome/Makefile.in
@@ -5,28 +5,23 @@
 
 DEPTH		= ../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = browser/components/feeds/test/chrome
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
 # sample_feed.atom was copied from toolkit/components/places/tests/chrome
-_HTTP_FILES	= \
+MOCHITEST_FILES	= \
 		sample_feed.atom \
 		$(NULL)
 
-_CHROME_FILES	= \
+MOCHITEST_CHROME_FILES	= \
 		test_423060.xul \
 		test_bug368464.html \
 		test_bug408328.html \
 		test_maxSniffing.html \
 		$(NULL)
 
-libs:: $(_HTTP_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
 
-libs:: $(_CHROME_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
-
--- a/browser/components/places/tests/browser/Makefile.in
+++ b/browser/components/places/tests/browser/Makefile.in
@@ -4,19 +4,18 @@
 
 DEPTH			= ../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH			= @srcdir@
 relativesrcdir  = browser/components/places/tests/browser
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_FILES = \
 	head.js \
 	browser_0_library_left_pane_migration.js \
 	browser_library_left_pane_fixnames.js \
 	browser_425884.js \
 	browser_475045.js \
 	browser_423515.js \
 	browser_410196_paste_into_tags.js \
 	browser_sort_in_library.js \
@@ -40,10 +39,9 @@ include $(topsrcdir)/config/rules.mk
 	frameRight.html \
 	browser_toolbar_migration.js \
 	browser_library_batch_delete.js \
 	browser_555547.js \
 	browser_416459_cut.js \
 	browser_library_downloads.js \
 	$(NULL)
 
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/components/places/tests/chrome/Makefile.in
+++ b/browser/components/places/tests/chrome/Makefile.in
@@ -4,24 +4,22 @@
 
 DEPTH          = ../../../../..
 topsrcdir      = @top_srcdir@
 srcdir         = @srcdir@
 VPATH          = @srcdir@
 relativesrcdir = browser/components/places/tests/chrome
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_CHROME_TEST_FILES = \
+MOCHITEST_CHROME_FILES = \
 	test_treeview_date.xul \
 	test_bug485100-change-case-loses-tag.xul \
 	test_bug427633_no_newfolder_if_noip.xul \
 	test_0_multiple_left_pane.xul \
 	test_0_bug510634.xul \
 	test_bug549192.xul \
 	test_bug549491.xul \
 	test_editBookmarkOverlay_tags_liveUpdate.xul \
 	test_bug631374_tags_selector_scroll.xul \
 	$(NULL)
 
-libs:: $(_CHROME_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/components/privatebrowsing/test/browser/Makefile.in
+++ b/browser/components/privatebrowsing/test/browser/Makefile.in
@@ -4,19 +4,18 @@
 
 DEPTH		= ../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = browser/components/privatebrowsing/test/browser
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_BROWSER_TEST_FILES =  \
+MOCHITEST_BROWSER_FILES =  \
 		head.js \
 		browser_console_clear.js \
 		browser_privatebrowsing_certexceptionsui.js \
 		browser_privatebrowsing_commandline_toggle.js \
 		browser_privatebrowsing_concurrent.js \
 		browser_privatebrowsing_concurrent_page.html \
 		browser_privatebrowsing_crh.js \
 		browser_privatebrowsing_fastswitch.js \
@@ -62,16 +61,15 @@ include $(topsrcdir)/config/rules.mk
 		title.sjs \
 		$(NULL)
 
 # Disabled until bug 564934 is fixed:
 #		browser_privatebrowsing_downloadmonitor.js \
 
 # Turn off private browsing tests that perma-timeout on Linux.
 ifneq (Linux,$(OS_ARCH))
-_BROWSER_TEST_FILES += \
+MOCHITEST_BROWSER_FILES += \
 		browser_privatebrowsing_beforeunload.js \
 		browser_privatebrowsing_cookieacceptdialog.js \
 		$(NULL)
 endif
 
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/components/search/test/Makefile.in
+++ b/browser/components/search/test/Makefile.in
@@ -4,26 +4,24 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  =  browser/components/search/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_BROWSER_TEST_FILES = 	  browser_405664.js \
+MOCHITEST_BROWSER_FILES = 	  browser_405664.js \
 	                  browser_addEngine.js \
 	                  browser_contextmenu.js \
 	                  testEngine.xml \
 	                  testEngine_mozsearch.xml \
 	                  testEngine.src \
 	                  browser_426329.js \
 	                  426329.xml \
 	                  browser_483086.js \
 	                  483086-1.xml \
 	                  483086-2.xml \
 	                  test.html \
 	                  $(NULL)
 
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/components/sessionstore/test/Makefile.in
+++ b/browser/components/sessionstore/test/Makefile.in
@@ -4,24 +4,23 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = browser/components/sessionstore/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
 # browser_506482.js is disabled because of frequent failures (bug 538672)
 # browser_526613.js is disabled because of frequent failures (bug 534489)
 # browser_589246.js is disabled for leaking browser windows (bug 752467)
 # browser_580512.js is disabled for leaking browser windows (bug 752467)
 
-_BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_FILES = \
 	head.js \
 	browser_form_restore_events.js \
 	browser_form_restore_events_sample.html \
 	browser_formdata_format.js \
 	browser_formdata_format_sample.html \
 	browser_248970_a.js \
 	browser_248970_b.js \
 	browser_248970_b_sample.html \
@@ -133,16 +132,15 @@ include $(topsrcdir)/config/rules.mk
 	browser_705597.js \
 	browser_707862.js \
 	browser_739531.js \
 	browser_739531_sample.html \
 	browser_739805.js \
 	$(NULL)
 
 ifneq ($(OS_ARCH),Darwin)
-_BROWSER_TEST_FILES += \
+MOCHITEST_BROWSER_FILES += \
 	browser_597071.js \
 	browser_625016.js \
 	$(NULL)
 endif
 
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/components/shell/test/Makefile.in
+++ b/browser/components/shell/test/Makefile.in
@@ -8,16 +8,14 @@ srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = browser/components/shell/test
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE		= test_browser_shell
 XPCSHELL_TESTS	= unit
 
-include $(topsrcdir)/config/rules.mk
 
-_BROWSER_TEST_FILES = browser_420786.js \
+MOCHITEST_BROWSER_FILES = browser_420786.js \
     browser_633221.js \
 	$(NULL)
 
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/components/test/Makefile.in
+++ b/browser/components/test/Makefile.in
@@ -4,16 +4,14 @@
 
 DEPTH     = ../../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
 relativesrcdir  = browser/components/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_FILES = \
   browser_bug538331.js \
   $(NULL)
 
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/devtools/commandline/test/Makefile.in
+++ b/browser/devtools/commandline/test/Makefile.in
@@ -5,36 +5,31 @@
 
 DEPTH     = ../../../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
 relativesrcdir  = browser/devtools/commandline/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_FILES = \
   browser_gcli_break.js \
   browser_gcli_commands.js \
   browser_gcli_edit.js \
   browser_gcli_inspect.js \
   browser_gcli_integrate.js \
   browser_gcli_pref.js \
   browser_gcli_settings.js \
   browser_gcli_web.js \
   head.js \
   $(NULL)
 
-_BROWSER_TEST_PAGES = \
+MOCHITEST_BROWSER_FILES += \
   browser_gcli_break.html \
   browser_gcli_inspect.html \
   resources_inpage.js \
   resources_inpage1.css \
   resources_inpage2.css \
   resources.html \
   $(NULL)
 
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
-
-libs:: $(_BROWSER_TEST_PAGES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/devtools/debugger/test/Makefile.in
+++ b/browser/devtools/debugger/test/Makefile.in
@@ -4,19 +4,18 @@
 
 DEPTH           = ../../../..
 topsrcdir       = @top_srcdir@
 srcdir          = @srcdir@
 VPATH           = @srcdir@
 relativesrcdir  = browser/devtools/debugger/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_TESTS = \
 	browser_dbg_createRemote.js \
 	browser_dbg_createChrome.js \
 	browser_dbg_debugger-tab-switch.js \
 	browser_dbg_debugger-tab-switch-window.js \
 	browser_dbg_debuggerstatement.js \
 	browser_dbg_listtabs.js \
 	browser_dbg_tabactor-01.js \
 	browser_dbg_tabactor-02.js \
@@ -56,30 +55,28 @@ include $(topsrcdir)/config/rules.mk
 	browser_dbg_displayName.js \
 	browser_dbg_iframes.js \
 	browser_dbg_pause-exceptions.js \
 	browser_dbg_multiple-windows.js \
 	browser_dbg_menustatus.js \
 	head.js \
 	$(NULL)
 
-_BROWSER_TEST_PAGES = \
+MOCHITEST_BROWSER_PAGES = \
 	browser_dbg_tab1.html \
 	browser_dbg_tab2.html \
 	browser_dbg_debuggerstatement.html \
 	browser_dbg_stack.html \
 	browser_dbg_script-switching.html \
 	test-script-switching-01.js \
 	test-script-switching-02.js \
 	browser_dbg_frame-parameters.html \
 	browser_dbg_update-editor-mode.html \
 	test-editor-mode \
 	browser_dbg_displayName.html \
 	browser_dbg_iframes.html \
 	browser_dbg_with-frame.html \
 	browser_dbg_pause-exceptions.html \
 	$(NULL)
 
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+MOCHITEST_BROWSER_FILES_PARTS = MOCHITEST_BROWSER_TESTS MOCHITEST_BROWSER_PAGES
 
-libs:: $(_BROWSER_TEST_PAGES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/devtools/highlighter/InsideOutBox.jsm
+++ b/browser/devtools/highlighter/InsideOutBox.jsm
@@ -209,22 +209,23 @@ InsideOutBox.prototype =
   {
     let objectBox = this.createObjectBox(aObject);
     if (!objectBox) {
       return null;
     }
     this.selectObjectBox(objectBox, forceOpen);
     if (makeBoxVisible) {
       this.openObjectBox(objectBox);
-      if (scrollIntoView) {
-        // We want to center the label of the element, not the whole tag
-        // (which includes all of its children, and is vertically huge).
-        LayoutHelpers.scrollIntoViewIfNeeded(objectBox.firstElementChild);
-      }
     }
+    if (scrollIntoView) {
+      // We want to center the label of the element, not the whole tag
+      // (which includes all of its children, and is vertically huge).
+      LayoutHelpers.scrollIntoViewIfNeeded(objectBox.firstElementChild);
+    }
+
     return objectBox;
   },
 
   /**
    * Expands/contracts the given object, depending on its state.
    * @param aObject
    *        The tree node to expand/contract.
    */
@@ -336,16 +337,151 @@ InsideOutBox.prototype =
 
       // Force it open the first time it is selected
       if (forceOpen)
         this.expandObjectBox(aObjectBox, true);
     }
   },
 
   /**
+   * Returns the next object box in the tree for navigation purposes.
+   */
+  nextObjectBox: function IOBox_nextObjectBox(aBoxObject)
+  {
+    let candidate;
+    let boxObject = aBoxObject || this.selectedObjectBox;
+    if (!boxObject)
+      return this.rootObjectBox;
+
+    // If expanded, return the first child.
+    let isOpen = this.view.hasClass(boxObject, "open");
+    let childObjectBox = this.getChildObjectBox(boxObject);
+    if (isOpen && childObjectBox && childObjectBox.firstChild) {
+      candidate = childObjectBox.firstChild;
+    } else {
+      // Otherwise we get the next available sibling.
+      while (boxObject) {
+        if (boxObject.nextSibling) {
+          boxObject = boxObject.nextSibling;
+          break;
+        }
+        boxObject = this.getParentObjectBox(boxObject);
+      }
+      candidate = boxObject;
+    }
+
+    // If the node is not an element (comments or text nodes), we
+    // jump to the next line.
+    if (candidate &&
+        candidate.repObject.nodeType != candidate.repObject.ELEMENT_NODE) {
+      return this.nextObjectBox(candidate);
+    }
+
+    return candidate;
+  },
+
+  /**
+   * Returns the next object in the tree for navigation purposes.
+   */
+  nextObject: function IOBox_nextObject()
+  {
+    let next = this.nextObjectBox();
+    return next ? next.repObject : null;
+  },
+
+  /**
+   * Returns the object that is below the selection.
+   *
+   * @param aDistance Number of lines to jump.
+   */
+   farNextObject: function IOBox_farPreviousProject(aDistance)
+   {
+     let boxObject = this.selectedObjectBox;
+     while (aDistance-- > 0) {
+       let newBoxObject = this.nextObjectBox(boxObject);
+       if (!newBoxObject) {
+         break;
+       }
+       boxObject = newBoxObject;
+     }
+     return boxObject ? boxObject.repObject : null;
+   },
+
+  /**
+   * Returns the last visible child box of an object box.
+   */
+  lastVisible: function IOBox_lastVisibleChild(aNode)
+  {
+    if (!this.view.hasClass(aNode, "open"))
+      return aNode;
+
+    let childBox = this.getChildObjectBox(aNode);
+    if (!childBox || !childBox.lastChild)
+      return aNode;
+
+    return this.lastVisible(childBox.lastChild);
+  },
+
+  /**
+   * Returns the previous object box in the tree for navigation purposes.
+   */
+  previousObjectBox: function IOBox_previousObjectBox(aBoxObject)
+  {
+    let boxObject = aBoxObject || this.selectedObjectBox;
+    if (!boxObject)
+        return this.rootObjectBox;
+
+    let candidate;
+    let sibling = boxObject.previousSibling;
+    if (sibling) {
+      candidate = this.lastVisible(sibling);
+    } else {
+      candidate = this.getParentObjectBox(boxObject);
+    }
+
+    // If the node is not an element (comments or text nodes), we
+    // jump to the previous line.
+    if (candidate &&
+        candidate.repObject.nodeType != candidate.repObject.ELEMENT_NODE) {
+      return this.previousObjectBox(candidate);
+    }
+
+    return candidate;
+  },
+
+  /**
+   * Returns the previous object in the tree for navigation purposes.
+   */
+  previousObject: function IOBox_previousObject()
+  {
+    let boxObject = this.previousObjectBox();
+    return boxObject ? boxObject.repObject : null;
+  },
+
+  /**
+   * Returns the object that is above the selection.
+   *
+   * @param aDistance Number of lines to jump.
+   */
+   farPreviousObject: function IOBox_farPreviousProject(aDistance)
+   {
+     let boxObject = this.selectedObjectBox;
+     while (aDistance-- > 0) {
+       let newBoxObject = this.previousObjectBox(boxObject);
+       if (!newBoxObject) {
+         break;
+       }
+       boxObject = newBoxObject;
+       if (boxObject === this.rootObjectBox)
+         break;
+     }
+     return boxObject ? boxObject.repObject : null;
+   },
+
+  /**
    * Open the ancestors of the given object box.
    * @param aObjectBox
    *        The object box to open.
    */
   openObjectBox: function IOBox_openObjectBox(aObjectBox)
   {
     if (!aObjectBox)
       return;
--- a/browser/devtools/highlighter/TreePanel.jsm
+++ b/browser/devtools/highlighter/TreePanel.jsm
@@ -1,20 +1,22 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const Cu = Components.utils;
+const Ci = Components.interfaces;
 
 Cu.import("resource:///modules/domplate.jsm");
 Cu.import("resource:///modules/InsideOutBox.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource:///modules/inspector.jsm");
+Cu.import("resource:///modules/devtools/LayoutHelpers.jsm");
 
 var EXPORTED_SYMBOLS = ["TreePanel", "DOMHelpers"];
 
 const INSPECTOR_URI = "chrome://browser/content/inspector.html";
 
 /**
  * TreePanel
  * A container for the Inspector's HTML Tree Panel widget constructor function.
@@ -75,16 +77,18 @@ TreePanel.prototype = {
     }
     this.treeBrowserDocument = this.treeIFrame.contentDocument;
     this.treePanelDiv = this.treeBrowserDocument.createElement("div");
     this.treeBrowserDocument.body.appendChild(this.treePanelDiv);
     this.treePanelDiv.ownerPanel = this;
     this.ioBox = new InsideOutBox(this, this.treePanelDiv);
     this.ioBox.createObjectBox(this.IUI.win.document.documentElement);
     this.treeLoaded = true;
+    this._boundTreeKeyPress = this.onTreeKeyPress.bind(this);
+    this.treeIFrame.addEventListener("keypress", this._boundTreeKeyPress.bind(this), true);
     this.treeIFrame.addEventListener("click", this.onTreeClick.bind(this), false);
     this.treeIFrame.addEventListener("dblclick", this.onTreeDblClick.bind(this), false);
     this.treeIFrame.focus();
     delete this.initializingTreePanel;
     Services.obs.notifyObservers(null,
       this.IUI.INSPECTOR_NOTIFICATIONS.TREEPANELREADY, null);
     if (this.pendingSelection) {
       this.select(this.pendingSelection.node, this.pendingSelection.scroll);
@@ -177,16 +181,17 @@ TreePanel.prototype = {
     let treeBoxParent = treeBox.parentNode;
     treeBoxParent.removeChild(this.splitter);
     treeBoxParent.removeChild(treeBox);
 
     if (this.treePanelDiv) {
       this.treePanelDiv.ownerPanel = null;
       let parent = this.treePanelDiv.parentNode;
       parent.removeChild(this.treePanelDiv);
+      this.treeIFrame.removeEventListener("keypress", this._boundTreeKeyPress, true);
       delete this.treePanelDiv;
       delete this.treeBrowserDocument;
     }
 
     if (this.ioBox) {
       this.ioBox.destroy();
       delete this.ioBox;
     }
@@ -267,18 +272,17 @@ TreePanel.prototype = {
 
     if (node) {
       if (hitTwisty) {
         this.ioBox.toggleObject(node);
       } else {
         if (this.IUI.inspecting) {
           this.IUI.stopInspecting(true);
         } else {
-          this.IUI.select(node, true, false);
-          this.IUI.highlighter.highlight(node);
+          this.navigate(node);
         }
       }
     }
   },
 
   /**
    * Handle double-click events in the html tree panel.
    * Double-clicking an attribute name or value allows it to be edited.
@@ -311,16 +315,62 @@ TreePanel.prototype = {
       let attrName = target.innerHTML;
       let attrValNode = target.nextSibling.nextSibling; // skip 2 (=)
 
       if (attrValNode)
         this.editAttribute(target, repObj, attrName, attrValNode.innerHTML);
     }
   },
 
+  navigate: function TP_navigate(node)
+  {
+    if (!node)
+      return;
+    this.ioBox.select(node, false, false, true);
+
+    if (this.IUI.highlighter.isNodeHighlightable(node)) {
+      this.IUI.select(node, true, false, "treepanel");
+      this.IUI.highlighter.highlight(node);
+    }
+  },
+
+  onTreeKeyPress: function TP_onTreeKeyPress(aEvent)
+  {
+    let handled = true;
+    switch(aEvent.keyCode) {
+      case Ci.nsIDOMKeyEvent.DOM_VK_LEFT:
+        this.ioBox.contractObjectBox(this.ioBox.selectedObjectBox);
+        break;
+      case Ci.nsIDOMKeyEvent.DOM_VK_RIGHT:
+        this.ioBox.expandObjectBox(this.ioBox.selectedObjectBox);
+        break;
+      case Ci.nsIDOMKeyEvent.DOM_VK_UP:
+        this.navigate(this.ioBox.previousObject());
+        break;
+      case Ci.nsIDOMKeyEvent.DOM_VK_DOWN:
+        this.navigate(this.ioBox.nextObject());
+        break;
+      case Ci.nsIDOMKeyEvent.DOM_VK_PAGE_UP:
+        this.navigate(this.ioBox.farPreviousObject(10));
+        break;
+      case Ci.nsIDOMKeyEvent.DOM_VK_PAGE_DOWN:
+        this.navigate(this.ioBox.farNextObject(10));
+        break;
+      case Ci.nsIDOMKeyEvent.DOM_VK_HOME:
+        this.navigate(this.ioBox.rootObject);
+        break;
+      default:
+        handled = false;
+    }
+    if (handled) {
+      aEvent.stopPropagation();
+      aEvent.preventDefault();
+    }
+  },
+
   /**
    * Starts the editor for an attribute name or value.
    * @param aAttrObj
    *        The DOM object representing the attribute name or value in the HTML
    *        Tree.
    * @param aRepObj
    *        The original DOM (target) object being inspected/edited
    * @param aAttrName
@@ -537,20 +587,20 @@ TreePanel.prototype = {
     this.closeEditor();
   },
 
   /**
    * Simple tree select method.
    * @param aNode the DOM node in the content document to select.
    * @param aScroll boolean scroll to the visible node?
    */
-  select: function TP_select(aNode, aScroll)
+  select: function TP_select(aNode, aScroll, aFrom)
   {
     if (this.ioBox) {
-      this.ioBox.select(aNode, true, true, aScroll);
+      this.ioBox.select(aNode, true, aFrom != "treepanel", aScroll);
     } else {
       this.pendingSelection = { node: aNode, scroll: aScroll };
     }
   },
 
   ///////////////////////////////////////////////////////////////////////////
   //// Utility functions
 
--- a/browser/devtools/highlighter/inspector.jsm
+++ b/browser/devtools/highlighter/inspector.jsm
@@ -435,17 +435,17 @@ InspectorUI.prototype = {
     } else {
       this.sidebar.hide();
     }
   },
 
   /**
    * Toggle the TreePanel.
    */
-  toggleHTMLPanel: function TP_toggleHTMLPanel()
+  toggleHTMLPanel: function IUI_toggleHTMLPanel()
   {
     if (this.treePanel.isOpen()) {
       this.treePanel.close();
       Services.prefs.setBoolPref("devtools.inspector.htmlPanelOpen", false);
       this.currentInspector._htmlPanelOpen = false;
     } else {
       this.treePanel.open();
       Services.prefs.setBoolPref("devtools.inspector.htmlPanelOpen", true);
@@ -648,36 +648,28 @@ InspectorUI.prototype = {
 
   /**
    * Browse nodes according to the breadcrumbs layout, only for some specific
    * elements of the UI.
    */
    setupNavigationKeys: function IUI_setupNavigationKeys()
    {
      // UI elements that are arrow keys sensitive:
-     // - highlighter veil;
-     // - content window (when the highlighter `veil is pointer-events:none`;
      // - the Inspector toolbar.
 
      this.onKeypress = this.onKeypress.bind(this);
 
-     this.highlighter.highlighterContainer.addEventListener("keypress",
-       this.onKeypress, true);
-     this.win.addEventListener("keypress", this.onKeypress, true);
      this.toolbar.addEventListener("keypress", this.onKeypress, true);
    },
 
   /**
    * Remove the event listeners for the arrowkeys.
    */
    removeNavigationKeys: function IUI_removeNavigationKeys()
    {
-      this.highlighter.highlighterContainer.removeEventListener("keypress",
-        this.onKeypress, true);
-      this.win.removeEventListener("keypress", this.onKeypress, true);
       this.toolbar.removeEventListener("keypress", this.onKeypress, true);
    },
 
   /**
    * Close inspector UI and associated panels. Unhighlight and stop inspecting.
    * Remove event listeners for document scrolling, resize,
    * tabContainer.TabSelect and others.
    *
@@ -852,17 +844,17 @@ InspectorUI.prototype = {
       this.selection = aNode;
       if (!this.inspecting) {
         this.highlighter.highlight(this.selection);
       }
     }
 
     this.breadcrumbs.update();
     this.chromeWin.Tilt.update(aNode);
-    this.treePanel.select(aNode, aScroll);
+    this.treePanel.select(aNode, aScroll, aFrom);
 
     this._notifySelected(aFrom);
   },
 
   /**
    * Toggle the pseudo-class lock on the currently inspected element. If the
    * pseudo-class is :hover or :active, that pseudo-class will also be toggled
    * on every ancestor of the element, mirroring real :hover and :active
@@ -1919,17 +1911,17 @@ HTMLBreadcrumbs.prototype = {
     let tagLabel = this.IUI.chromeDoc.createElement("label");
     tagLabel.className = "inspector-breadcrumbs-tag plain";
 
     let idLabel = this.IUI.chromeDoc.createElement("label");
     idLabel.className = "inspector-breadcrumbs-id plain";
 
     let classesLabel = this.IUI.chromeDoc.createElement("label");
     classesLabel.className = "inspector-breadcrumbs-classes plain";
-    
+
     let pseudosLabel = this.IUI.chromeDoc.createElement("label");
     pseudosLabel.className = "inspector-breadcrumbs-pseudo-classes plain";
 
     tagLabel.textContent = aNode.tagName.toLowerCase();
     idLabel.textContent = aNode.id ? ("#" + aNode.id) : "";
 
     let classesText = "";
     for (let i = 0; i < aNode.classList.length; i++) {
@@ -2148,16 +2140,17 @@ HTMLBreadcrumbs.prototype = {
     }
 
     button.onBreadcrumbsClick = function onBreadcrumbsClick() {
       inspector.stopInspecting();
       inspector.select(aNode, true, true, "breadcrumbs");
     };
 
     button.onclick = (function _onBreadcrumbsRightClick(aEvent) {
+      button.focus();
       if (aEvent.button == 2) {
         this.openSiblingMenu(button, aNode);
       }
     }).bind(this);
 
     button.onBreadcrumbsHold = (function _onBreadcrumbsHold() {
       this.openSiblingMenu(button, aNode);
     }).bind(this);
--- a/browser/devtools/highlighter/test/Makefile.in
+++ b/browser/devtools/highlighter/test/Makefile.in
@@ -37,16 +37,18 @@ include $(topsrcdir)/config/rules.mk
 		browser_inspector_ruleviewstore.js \
 		browser_inspector_invalidate.js \
 		browser_inspector_sidebarstate.js \
 		browser_inspector_treePanel_menu.js \
 		browser_inspector_pseudoclass_lock.js \
 		browser_inspector_pseudoClass_menu.js \
 		browser_inspector_destroyselection.html \
 		browser_inspector_destroyselection.js \
+		browser_inspector_treePanel_navigation.html \
+		browser_inspector_treePanel_navigation.js \
 		head.js \
 		$(NULL)
 
 # Disabled due to constant failures
 # 		browser_inspector_treePanel_click.js \
 
 libs::	$(_BROWSER_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
--- a/browser/devtools/highlighter/test/browser_inspector_bug_672902_keyboard_shortcuts.js
+++ b/browser/devtools/highlighter/test/browser_inspector_bug_672902_keyboard_shortcuts.js
@@ -37,16 +37,18 @@ function test()
     Services.obs.removeObserver(findAndHighlightNode,
                                 InspectorUI.INSPECTOR_NOTIFICATIONS.OPENED);
 
     executeSoon(function() {
       InspectorUI.highlighter.addListener("nodeselected", highlightBodyNode);
       // Test that navigating around without a selected node gets us to the
       // body element.
       node = doc.querySelector("body");
+      let bc = InspectorUI.breadcrumbs;
+      bc.nodeHierarchy[bc.currentIndex].button.focus();
       EventUtils.synthesizeKey("VK_RIGHT", { });
     });
   }
 
   function highlightBodyNode()
   {
     InspectorUI.highlighter.removeListener("nodeselected", highlightBodyNode);
     is(InspectorUI.selection, node, "selected body element");
new file mode 100644
--- /dev/null
+++ b/browser/devtools/highlighter/test/browser_inspector_treePanel_navigation.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+
+<html class="html">
+  <meta charset=utf-8 />
+
+  <body class="body">
+    <div class="node0">
+      <p class="node1">line1</p>
+      <p class="node2">line2</p>
+      <p class="node3">line3</p>
+      <!-- A comment -->
+      <p class="node4">line4
+      <span class="node5">line5</span>
+      <span class="node6">line6</span>
+      <!-- A comment -->
+      <a class="node7">line7<span class="node8">line8</span></a>
+      <span class="node9">line9</span>
+      <span class="node10">line10</span>
+      <span class="node11">line11</span>
+      <a class="node12">line12<span class="node13">line13</span></a>
+      </p>
+      <p class="node14">line14</p>
+      <p class="node15">line15</p>
+    </div>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/browser/devtools/highlighter/test/browser_inspector_treePanel_navigation.js
@@ -0,0 +1,103 @@
+/* Any copyright is dedicated to the Public Domain.
+http://creativecommons.org/publicdomain/zero/1.0/ */
+
+
+function test() {
+
+  waitForExplicitFinish();
+
+  let doc;
+
+  let keySequence = "right down right ";
+  keySequence += "down down down down right ";
+  keySequence += "down down down right ";
+  keySequence += "down down down down down right ";
+  keySequence += "down down down down down ";
+  keySequence += "up up up left down home ";
+  keySequence += "pagedown left down down pageup pageup left down";
+
+  keySequence = keySequence.split(" ");
+
+  let keySequenceRes = "body node0 node0 ";
+  keySequenceRes += "node1 node2 node3 node4 node4 ";
+  keySequenceRes += "node5 node6 node7 node7 ";
+  keySequenceRes += "node8 node9 node10 node11 node12 node12 ";
+  keySequenceRes += "node13 node14 node15 node15 node15 ";
+  keySequenceRes += "node14 node13 node12 node12 node14 html ";
+  keySequenceRes += "node7 node7 node9 node10 body html html html";
+
+  keySequenceRes = keySequenceRes.split(" ");
+
+
+  gBrowser.selectedTab = gBrowser.addTab();
+  gBrowser.selectedBrowser.addEventListener("load", function onload() {
+    gBrowser.selectedBrowser.removeEventListener("load", onload, true);
+    doc = content.document;
+    waitForFocus(setupTest, content);
+  }, true);
+
+  content.location = "http://mochi.test:8888/browser/browser/devtools/highlighter/test/browser_inspector_treePanel_navigation.html";
+
+  function setupTest() {
+    Services.obs.addObserver(runTests, InspectorUI.INSPECTOR_NOTIFICATIONS.OPENED, false);
+    InspectorUI.toggleInspectorUI();
+  }
+
+  function runTests() {
+    Services.obs.removeObserver(runTests, InspectorUI.INSPECTOR_NOTIFICATIONS.OPENED);
+    Services.obs.addObserver(startNavigation, InspectorUI.INSPECTOR_NOTIFICATIONS.TREEPANELREADY, false);
+    InspectorUI.select(doc.body, true, true, true);
+    InspectorUI.toggleHTMLPanel();
+  }
+
+  function startNavigation() {
+    Services.obs.removeObserver(startNavigation, InspectorUI.INSPECTOR_NOTIFICATIONS.TREEPANELREADY);
+    nextStep(0);
+  }
+
+  function nextStep(cursor) {
+    let key = keySequence[cursor];
+    let className = keySequenceRes[cursor];
+    switch(key) {
+      case "right":
+        EventUtils.synthesizeKey("VK_RIGHT", {});
+        break;
+      case "down":
+        EventUtils.synthesizeKey("VK_DOWN", {});
+        break;
+      case "left":
+        EventUtils.synthesizeKey("VK_LEFT", {});
+        break;
+      case "up":
+        EventUtils.synthesizeKey("VK_UP", {});
+        break;
+      case "pageup":
+        EventUtils.synthesizeKey("VK_PAGE_UP", {});
+        break;
+      case "pagedown":
+        EventUtils.synthesizeKey("VK_PAGE_DOWN", {});
+        break;
+      case "home":
+        EventUtils.synthesizeKey("VK_HOME", {});
+        break;
+    }
+
+    executeSoon(function() {
+      if (cursor >= keySequence.length) {
+        Services.obs.addObserver(finishUp, InspectorUI.INSPECTOR_NOTIFICATIONS.CLOSED, false);
+        InspectorUI.closeInspectorUI();
+      } else {
+        let node = InspectorUI.treePanel.ioBox.selectedObjectBox.repObject;
+        is(node.className, className, "[" + cursor + "] right node selected: " + className);
+        nextStep(cursor + 1);
+      }
+    });
+  }
+
+  function finishUp() {
+    Services.obs.removeObserver(finishUp, InspectorUI.INSPECTOR_NOTIFICATIONS.CLOSED);
+    doc = null;
+    gBrowser.removeCurrentTab();
+    finish();
+  }
+}
--- a/browser/devtools/responsivedesign/responsivedesign.jsm
+++ b/browser/devtools/responsivedesign/responsivedesign.jsm
@@ -107,21 +107,23 @@ function ResponsiveUI(aWindow, aTab)
   this.bound_startResizing = this.startResizing.bind(this);
   this.bound_stopResizing = this.stopResizing.bind(this);
   this.bound_onDrag = this.onDrag.bind(this);
   this.bound_onKeypress = this.onKeypress.bind(this);
 
   // Events
   this.tab.addEventListener("TabClose", this);
   this.tabContainer.addEventListener("TabSelect", this);
-  this.mainWindow.addEventListener("keypress", this.bound_onKeypress, true);
+  this.mainWindow.document.addEventListener("keypress", this.bound_onKeypress, false);
 
   this.buildUI();
   this.checkMenus();
 
+  this.inspectorWasOpen = this.mainWindow.InspectorUI.isInspectorOpen;
+
   try {
     if (Services.prefs.getBoolPref("devtools.responsiveUI.rotate")) {
       this.rotate();
     }
   } catch(e) {}
 }
 
 ResponsiveUI.prototype = {
@@ -135,31 +137,35 @@ ResponsiveUI.prototype = {
       this.stack.setAttribute("notransition", "true");
     }
   },
 
   /**
    * Destroy the nodes. Remove listeners. Reset the style.
    */
   close: function RUI_unload() {
+    if (this.closing)
+      return;
+    this.closing = true;
+
     this.unCheckMenus();
     // Reset style of the stack.
     let style = "max-width: none;" +
                 "min-width: 0;" +
                 "max-height: none;" +
                 "min-height: 0;";
     this.stack.setAttribute("style", style);
 
     if (this.isResizing)
       this.stopResizing();
 
     this.saveCurrentPreset();
 
     // Remove listeners.
-    this.mainWindow.removeEventListener("keypress", this.bound_onKeypress, true);
+    this.mainWindow.document.removeEventListener("keypress", this.bound_onKeypress, false);
     this.menulist.removeEventListener("select", this.bound_presetSelected, true);
     this.tab.removeEventListener("TabClose", this);
     this.tabContainer.removeEventListener("TabSelect", this);
     this.rotatebutton.removeEventListener("command", this.bound_rotate, true);
 
     // Removed elements.
     this.container.removeChild(this.toolbar);
     this.stack.removeChild(this.resizer);
@@ -190,19 +196,27 @@ ResponsiveUI.prototype = {
   /**
    * Handle keypressed.
    *
    * @param aEvent
    */
   onKeypress: function RUI_onKeypress(aEvent) {
     if (aEvent.keyCode == this.mainWindow.KeyEvent.DOM_VK_ESCAPE &&
         this.mainWindow.gBrowser.selectedBrowser == this.browser) {
-      aEvent.preventDefault();
-      aEvent.stopPropagation();
-      this.close();
+
+      // If the inspector wasn't open at first but is open now,
+      // we don't want to close the Responsive Mode on Escape.
+      // We let the inspector close first.
+
+      let isInspectorOpen = this.mainWindow.InspectorUI.isInspectorOpen;
+      if (this.inspectorWasOpen || !isInspectorOpen) {
+        aEvent.preventDefault();
+        aEvent.stopPropagation();
+        this.close();
+      }
     }
   },
 
   /**
    * Handle events
    */
   handleEvent: function (aEvent) {
     switch (aEvent.type) {
--- a/browser/devtools/scratchpad/test/Makefile.in
+++ b/browser/devtools/scratchpad/test/Makefile.in
@@ -4,19 +4,18 @@
 
 DEPTH			= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH			= @srcdir@
 relativesrcdir  = browser/devtools/scratchpad/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_FILES = \
 		browser_scratchpad_initialization.js \
 		browser_scratchpad_contexts.js \
 		browser_scratchpad_tab_switch.js \
 		browser_scratchpad_execute_print.js \
 		browser_scratchpad_inspect.js \
 		browser_scratchpad_files.js \
 		browser_scratchpad_ui.js \
 		browser_scratchpad_bug_646070_chrome_context_pref.js \
@@ -30,10 +29,9 @@ include $(topsrcdir)/config/rules.mk
 		browser_scratchpad_bug684546_reset_undo.js \
 		browser_scratchpad_bug690552_display_outputs_errors.js \
 		browser_scratchpad_bug650345_find_ui.js \
 		browser_scratchpad_bug714942_goto_line_ui.js \
 		browser_scratchpad_bug_650760_help_key.js \
 		browser_scratchpad_bug_651942_recent_files.js \
 		head.js \
 
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/devtools/shared/test/Makefile.in
+++ b/browser/devtools/shared/test/Makefile.in
@@ -5,35 +5,30 @@
 
 DEPTH     = ../../../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
 relativesrcdir  = browser/devtools/shared/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_FILES = \
   browser_browser_basic.js \
   browser_promise_basic.js \
   browser_require_basic.js \
   browser_templater_basic.js \
   browser_toolbar_basic.js \
   browser_toolbar_tooltip.js \
   browser_toolbar_webconsole_errors_count.js \
   browser_layoutHelpers.js \
   head.js \
   $(NULL)
 
-_BROWSER_TEST_PAGES = \
+MOCHITEST_BROWSER_FILES += \
   browser_templater_basic.html \
   browser_toolbar_basic.html \
   browser_toolbar_webconsole_errors_count.html \
   browser_layoutHelpers.html \
   browser_layoutHelpers_iframe.html \
   $(NULL)
 
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
-
-libs:: $(_BROWSER_TEST_PAGES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/devtools/sourceeditor/test/Makefile.in
+++ b/browser/devtools/sourceeditor/test/Makefile.in
@@ -4,19 +4,18 @@
 
 DEPTH     = ../../../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
 relativesrcdir = browser/devtools/sourceeditor/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_FILES = \
 		browser_sourceeditor_initialization.js \
 		browser_bug684862_paste_html.js \
 		browser_bug687573_vscroll.js \
 		browser_bug687568_pagescroll.js \
 		browser_bug687580_drag_and_drop.js \
 		browser_bug684546_reset_undo.js \
 		browser_bug695035_middle_click_paste.js \
 		browser_bug687160_line_api.js \
@@ -28,10 +27,9 @@ include $(topsrcdir)/config/rules.mk
 		browser_bug725618_moveLines_shortcut.js \
 		browser_bug700893_dirty_state.js \
 		browser_bug729480_line_vertical_align.js \
 		browser_bug725430_comment_uncomment.js \
 		browser_bug731721_debugger_stepping.js \
 		browser_bug729960_block_bracket_jump.js \
 		head.js \
 
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/devtools/styleinspector/test/Makefile.in
+++ b/browser/devtools/styleinspector/test/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH     = ../../../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
 relativesrcdir  = browser/devtools/styleinspector/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_FILES = \
   browser_styleinspector.js \
   browser_bug683672.js \
   browser_styleinspector_bug_672746_default_styles.js \
   browser_styleinspector_bug_672744_search_filter.js \
   browser_bug589375_keybindings.js \
   browser_styleinspector_bug_689759_no_results_placeholder.js \
   browser_bug_692400_element_style.js \
   browser_csslogic_inherited.js \
@@ -35,25 +34,21 @@ include $(topsrcdir)/config/rules.mk
   browser_bug_592743_specificity.js \
   browser_ruleview_bug_703643_context_menu_copy.js \
   browser_computedview_bug_703643_context_menu_copy.js \
   browser_ruleview_734259_style_editor_link.js \
   browser_computedview_734259_style_editor_link.js \
   head.js \
   $(NULL)
 
-_BROWSER_TEST_PAGES = \
+MOCHITEST_BROWSER_FILES += \
   browser_bug683672.html \
   browser_bug705707_is_content_stylesheet.html \
   browser_bug705707_is_content_stylesheet_imported.css \
   browser_bug705707_is_content_stylesheet_imported2.css \
   browser_bug705707_is_content_stylesheet_linked.css \
   browser_bug705707_is_content_stylesheet_script.css \
   browser_bug705707_is_content_stylesheet.xul \
   browser_bug705707_is_content_stylesheet_xul.css \
   browser_bug722196_identify_media_queries.html \
   $(NULL)
 
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
-
-libs:: $(_BROWSER_TEST_PAGES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/devtools/tilt/test/Makefile.in
+++ b/browser/devtools/tilt/test/Makefile.in
@@ -4,23 +4,22 @@
 
 DEPTH			= ../../../..
 topsrcdir		= @top_srcdir@
 srcdir			= @srcdir@
 VPATH			= @srcdir@
 relativesrcdir 	= browser/devtools/tilt/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_BROWSER_TEST_FILES = head.js
+MOCHITEST_BROWSER_FILES = head.js
 
 # browser_tilt* disabled on Linux due to bug 759157
 ifneq (gtk2,$(MOZ_WIDGET_TOOLKIT))
-_BROWSER_TEST_FILES += \
+MOCHITEST_BROWSER_FILES += \
 	browser_tilt_01_lazy_getter.js \
 	browser_tilt_02_notifications-seq.js \
 	browser_tilt_02_notifications.js \
 	browser_tilt_03_tab_switch.js \
 	browser_tilt_04_initialization-key.js \
 	browser_tilt_04_initialization.js \
 	browser_tilt_05_destruction-esc.js \
 	browser_tilt_05_destruction-url.js \
@@ -57,10 +56,9 @@ ifneq (gtk2,$(MOZ_WIDGET_TOOLKIT))
 	browser_tilt_utils04.js \
 	browser_tilt_utils05.js \
 	browser_tilt_utils06.js \
 	browser_tilt_visualizer.js \
 	browser_tilt_zoom.js \
 	$(NULL)
 endif
 
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/devtools/webconsole/test/Makefile.in
+++ b/browser/devtools/webconsole/test/Makefile.in
@@ -4,19 +4,18 @@
 
 DEPTH			= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH			= @srcdir@
 relativesrcdir  = browser/devtools/webconsole/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_FILES = \
 	browser_webconsole_notifications.js \
 	browser_webconsole_message_node_id.js \
 	browser_webconsole_bug_580030_errors_after_page_reload.js \
 	browser_webconsole_basic_net_logging.js \
 	browser_webconsole_bug_579412_input_focus.js \
 	browser_webconsole_bug_580001_closing_after_completion.js \
 	browser_webconsole_bug_580400_groups.js \
 	browser_webconsole_bug_588730_text_node_insertion.js \
@@ -108,17 +107,17 @@ include $(topsrcdir)/config/rules.mk
 	browser_webconsole_bug_622303_persistent_filters.js \
 	browser_webconsole_window_zombie.js \
 	browser_cached_messages.js \
 	browser_bug664688_sandbox_update_after_navigation.js \
 	browser_webconsole_menustatus.js \
 	head.js \
 	$(NULL)
 
-_BROWSER_TEST_PAGES = \
+MOCHITEST_BROWSER_FILES += \
 	test-console.html \
 	test-network.html \
 	test-network-request.html \
 	test-mutation.html \
 	testscript.js \
 	test-filter.html \
 	test-observe-http-ajax.html \
 	test-data.json \
@@ -179,13 +178,9 @@ include $(topsrcdir)/config/rules.mk
 	test-bug-632275-getters.html \
 	test-bug-646025-console-file-location.html \
 	test-file-location.js \
 	test-bug-658368-time-methods.html \
 	test-webconsole-error-observer.html \
 	test-for-of.html \
 	$(NULL)
 
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
-
-libs:: $(_BROWSER_TEST_PAGES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/browser/extensions/pdfjs/test/Makefile.in
+++ b/browser/extensions/pdfjs/test/Makefile.in
@@ -4,18 +4,16 @@
 
 DEPTH     = ../../../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
 relativesrcdir  = browser/extensions/pdfjs/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_FILES = \
   browser_pdfjs_main.js \
   browser_pdfjs_savedialog.js \
   file_pdfjs_test.pdf \
   $(NULL)
 
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir) 
+include $(topsrcdir)/config/rules.mk
--- a/browser/themes/gnomestripe/devtools/debugger.css
+++ b/browser/themes/gnomestripe/devtools/debugger.css
@@ -269,20 +269,16 @@
 #step-in {
   list-style-image: url("chrome://browser/skin/devtools/debugger-step-in.png");
 }
 
 #step-out {
   list-style-image: url("chrome://browser/skin/devtools/debugger-step-out.png");
 }
 
-#step-over {
-  list-style-image: url("chrome://browser/skin/devtools/debugger-step-over.png");
-}
-
 #debugger-controls > toolbarbutton {
   border-width: 0;
   -moz-border-end-width: 1px;
   border-radius: 0;
   box-shadow: none;
   margin: 0;
   outline-offset: -3px;
 }
--- a/browser/themes/pinstripe/devtools/debugger.css
+++ b/browser/themes/pinstripe/devtools/debugger.css
@@ -269,20 +269,16 @@
 #step-in {
   list-style-image: url("chrome://browser/skin/devtools/debugger-step-in.png");
 }
 
 #step-out {
   list-style-image: url("chrome://browser/skin/devtools/debugger-step-out.png");
 }
 
-#step-over {
-  list-style-image: url("chrome://browser/skin/devtools/debugger-step-over.png");
-}
-
 #debugger-controls > toolbarbutton {
   border-width: 0;
   -moz-border-end-width: 1px;
   border-radius: 0;
   box-shadow: none;
   margin: 0;
   outline-offset: -3px;
 }
--- a/browser/themes/winstripe/devtools/debugger.css
+++ b/browser/themes/winstripe/devtools/debugger.css
@@ -272,20 +272,16 @@
 #step-in {
   list-style-image: url("chrome://browser/skin/devtools/debugger-step-in.png");
 }
 
 #step-out {
   list-style-image: url("chrome://browser/skin/devtools/debugger-step-out.png");
 }
 
-#step-over {
-  list-style-image: url("chrome://browser/skin/devtools/debugger-step-over.png");
-}
-
 #debugger-controls > toolbarbutton {
   border-width: 0;
   -moz-border-end-width: 1px;
   border-radius: 0;
   box-shadow: none;
   margin: 0;
   outline-offset: -3px;
 }
--- a/build/unix/elfhack/elfhack.cpp
+++ b/build/unix/elfhack/elfhack.cpp
@@ -437,29 +437,30 @@ int do_relocation_section(Elf *elf, unsi
         }
     }
     if (relhack_entry.r_offset)
         relhack->push_back(relhack_entry);
     // Last entry must be NULL
     relhack_entry.r_offset = relhack_entry.r_info = 0;
     relhack->push_back(relhack_entry);
 
-    relhackcode->insertAfter(section);
+    unsigned int old_end = section->getOffset() + section->getSize();
+
+    relhackcode->insertBefore(section);
     relhack->insertAfter(relhackcode);
 
-    unsigned int old_end = section->getOffset() + section->getSize();
     section->rels.assign(new_rels.begin(), new_rels.end());
     section->shrink(new_rels.size() * section->getEntSize());
     ElfLocation *init = new ElfLocation(relhackcode, relhackcode->getEntryPoint());
     dyn->setValueForType(DT_INIT, init);
     // TODO: adjust the value according to the remaining number of relative relocations
     if (dyn->getValueForType(Rel_Type::d_tag_count))
         dyn->setValueForType(Rel_Type::d_tag_count, new ElfPlainValue(0));
 
-    if (relhack->getOffset() + relhack->getSize() >= old_end) {
+    if (section->getOffset() + section->getSize() >= old_end) {
         fprintf(stderr, "No gain. Skipping\n");
         return -1;
     }
     return 0;
 }
 
 static inline int backup_file(const char *name)
 {
--- a/build/unix/elfhack/elfxx.h
+++ b/build/unix/elfhack/elfxx.h
@@ -355,16 +355,33 @@ public:
         } else
             next = NULL;
         if (next != NULL)
             next->previous = this;
         if (dirty)
             markDirty();
     }
 
+    void insertBefore(ElfSection *section, bool dirty = true) {
+        if (previous != NULL)
+            previous->next = next;
+        if (next != NULL)
+            next->previous = previous;
+        next = section;
+        if (section != NULL) {
+            previous = section->previous;
+            section->previous = this;
+        } else
+            previous = NULL;
+        if (previous != NULL)
+            previous->next = this;
+        if (dirty)
+            markDirty();
+    }
+
     void markDirty() {
         if (link != NULL)
             shdr.sh_link = -1;
         if (info.index)
             shdr.sh_info = -1;
         shdr.sh_offset = -1;
         if (isRelocatable())
             shdr.sh_addr = -1;
--- a/caps/tests/mochitest/Makefile.in
+++ b/caps/tests/mochitest/Makefile.in
@@ -5,25 +5,23 @@
 
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = caps/tests/mochitest
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = 	test_bug423375.html \
+MOCHITEST_FILES = 	test_bug423375.html \
                 test_bug246699.html \
                 test_bug292789.html \
                 test_bug470804.html \
                 test_disallowInheritPrincipal.html \
                 $(NULL)
 
 test_bug292789.html : % : %.in
 	$(PYTHON) $(topsrcdir)/config/Preprocessor.py \
 	     $(AUTOMATION_PPARGS) $(DEFINES) $(ACDEFINES) $< > $@
 
 GARBAGE += test_bug292789.html
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -662,9 +662,11 @@ JS_SHARED_LIBRARY = @JS_SHARED_LIBRARY@
 MOZ_INSTRUMENT_EVENT_LOOP = @MOZ_INSTRUMENT_EVENT_LOOP@
 
 MOZ_SYSTEM_PLY = @MOZ_SYSTEM_PLY@
 
 MOZ_PACKAGE_JSSHELL = @MOZ_PACKAGE_JSSHELL@
 
 MOZ_LINKER_EXTRACT = @MOZ_LINKER_EXTRACT@
 
+MOZ_PER_WINDOW_PRIVATE_BROWSING = @MOZ_PER_WINDOW_PRIVATE_BROWSING@
+
 include $(topsrcdir)/config/baseconfig.mk
new file mode 100644
--- /dev/null
+++ b/config/makefiles/mochitest.mk
@@ -0,0 +1,60 @@
+# -*- makefile -*-
+# vim:set ts=8 sw=8 sts=8 noet:
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+ifndef INCLUDED_TESTS_MOCHITEST_MK #{
+
+ifdef relativesrcdir
+  mochitestdir = $(DEPTH)/_tests/testing/mochitest/$1/$(relativesrcdir)
+else
+  mochitestdir = $(DEPTH)/_tests/testing/mochitest/$1/$(subst $(topsrcdir),,$(srcdir))
+endif
+
+define mochitest-libs-rule-template
+libs:: $$($(1))
+	$$(INSTALL) $$(foreach f,$$^,"$$(f)") $$(call mochitestdir,$(2))
+endef
+
+# Provide support for modules with such a large number of tests that
+# installing them with a single $(INSTALL) invocation would overflow
+# command-line length limits on some operating systems.
+ifdef MOCHITEST_FILES_PARTS
+ifdef MOCHITEST_FILES
+$(error You must define only one of MOCHITEST_FILES_PARTS or MOCHITEST_FILES)
+endif
+$(foreach part,$(MOCHITEST_FILES_PARTS),$(eval $(call mochitest-libs-rule-template,$(part),tests)))
+endif
+
+ifdef MOCHITEST_FILES
+$(eval $(call mochitest-libs-rule-template,MOCHITEST_FILES,tests))
+endif
+
+ifdef MOCHITEST_CHROME_FILES
+$(eval $(call mochitest-libs-rule-template,MOCHITEST_CHROME_FILES,chrome))
+endif
+
+ifdef MOCHITEST_BROWSER_FILES_PARTS
+ifdef MOCHITEST_BROWSER_FILES
+$(error You must define only one of MOCHITEST_BROWSER_FILES_PARTS or MOCHITEST_BROWSER_FILES)
+endif
+$(foreach part,$(MOCHITEST_BROWSER_FILES_PARTS),$(eval $(call mochitest-libs-rule-template,$(part),browser)))
+endif
+
+ifdef MOCHITEST_BROWSER_FILES
+$(eval $(call mochitest-libs-rule-template,MOCHITEST_BROWSER_FILES,browser))
+endif
+
+ifdef MOCHITEST_A11Y_FILES
+$(eval $(call mochitest-libs-rule-template,MOCHITEST_A11Y_FILES,a11y))
+endif
+
+ifdef MOCHITEST_WEBAPPRT_CHROME_FILES
+$(eval $(call mochitest-libs-rule-template,MOCHITEST_WEBAPPRT_CHROME_FILES,webapprtChrome))
+endif
+
+INCLUDED_TESTS_MOCHITEST_MK := 1
+
+endif #} INCLUDED_TESTS_MOCHITEST_MK
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -84,16 +84,20 @@ ifdef ENABLE_TESTS
 # that changes to tests may not be updated and code could assume to pass
 # locally against non-current test code.
 DIRS += $(TEST_DIRS)
 
 ifndef INCLUDED_TESTS_XPCSHELL_MK #{
   include $(topsrcdir)/config/makefiles/xpcshell.mk
 endif #}
 
+ifndef INCLUDED_TESTS_MOCHITEST_MK #{
+  include $(topsrcdir)/config/makefiles/mochitest.mk
+endif #}
+
 ifdef CPP_UNIT_TESTS
 
 # Compile the tests to $(DIST)/bin.  Make lots of niceties available by default
 # through TestHarness.h, by modifying the list of includes and the libs against
 # which stuff links.
 CPPSRCS += $(CPP_UNIT_TESTS)
 SIMPLE_PROGRAMS += $(CPP_UNIT_TESTS:.cpp=$(BIN_SUFFIX))
 INCLUDES += -I$(DIST)/include/testing
@@ -1156,17 +1160,17 @@ ifndef NO_MAKEFILE_RULE
 Makefile: Makefile.in
 	@$(PERL) $(AUTOCONF_TOOLS)/make-makefile -t $(topsrcdir) -d $(DEPTH)
 endif
 
 ifndef NO_SUBMAKEFILES_RULE
 ifdef SUBMAKEFILES
 # VPATH does not work on some machines in this case, so add $(srcdir)
 $(SUBMAKEFILES): % : $(srcdir)/%.in
-	$(PERL) $(AUTOCONF_TOOLS)/make-makefile -t $(topsrcdir) -d $(DEPTH) $@
+	$(if $(subsrcdir),cd $(subsrcdir) && )$(PERL) $(AUTOCONF_TOOLS)/make-makefile -t $(topsrcdir)$(addprefix /,$(subsrcdir)) -d $(DEPTH) $(@:$(subsrcdir)/%=%)
 endif
 endif
 
 ifdef AUTOUPDATE_CONFIGURE
 $(topsrcdir)/configure: $(topsrcdir)/configure.in
 	(cd $(topsrcdir) && $(AUTOCONF)) && (cd $(DEPTH) && ./config.status --recheck)
 endif
 
--- a/configure.in
+++ b/configure.in
@@ -4292,18 +4292,18 @@ case "${target}" in
         fi
 
         NSS_DISABLE_DBM=1
         NECKO_WIFI=
         MOZ_THEME_FASTSTRIPE=1
         MOZ_TREE_FREETYPE=1
         MOZ_MEMORY=1
         MOZ_RAW=1
-        MOZ_WEBRTC=
         ;;
+
 esac
 
 MOZ_ARG_ENABLE_STRING(application,
 [  --enable-application=APP
                           Options include:
                             browser (Firefox)
                             xulrunner
                             tools/update-packaging (AUS-related packaging tools)],
@@ -5243,16 +5243,35 @@ MOZ_ARG_DISABLE_BOOL(printing,
     NS_PRINTING=,
     NS_PRINTING=1)
 
 if test "$NS_PRINTING"; then
     AC_DEFINE(NS_PRINTING)
     AC_DEFINE(NS_PRINT_PREVIEW)
 fi
 
+dnl Turn off webrtc for OS's we don't handle yet, but allow 
+dnl --enable-webrtc to override.  Can disable for everything in
+dnl the master list above.
+if test -n "$MOZ_WEBRTC"; then
+    case "$target" in
+    *-android*|*-linuxandroid*)
+        dnl Make sure doesn't get matched by *-linux*
+        MOZ_WEBRTC=
+        ;;
+    *-linux*|*-mingw*|*-darwin*)
+        dnl Leave enabled
+        ;;
+    *)
+        dnl default to disabled for all others
+        MOZ_WEBRTC=
+        ;;
+    esac
+fi
+
 dnl ========================================================
 dnl = Disable WebRTC code
 dnl ========================================================
 MOZ_ARG_DISABLE_BOOL(webrtc,
 [  --disable-webrtc        Disable support for WebRTC],
     MOZ_WEBRTC=,
     MOZ_WEBRTC=1)
 
@@ -8370,16 +8389,17 @@ AC_SUBST(XPCOM_STANDALONE_STATICRUNTIME_
 AC_SUBST(USE_DEPENDENT_LIBS)
 
 AC_SUBST(MOZ_BUILD_ROOT)
 AC_SUBST(MOZ_OS2_TOOLS)
 
 AC_SUBST(MOZ_POST_DSO_LIB_COMMAND)
 AC_SUBST(MOZ_POST_PROGRAM_COMMAND)
 AC_SUBST(MOZ_LINKER_EXTRACT)
+AC_SUBST(MOZ_PER_WINDOW_PRIVATE_BROWSING)
 
 dnl ========================================================
 dnl = Mac bundle name prefix
 dnl ========================================================
 MOZ_ARG_WITH_STRING(macbundlename-prefix,
 [  --with-macbundlename-prefix=prefix
                           Prefix for MOZ_MACBUNDLE_NAME],
 [ MOZ_MACBUNDLE_NAME_PREFIX="$withval"])
new file mode 100644
--- /dev/null
+++ b/content/base/crashtests/771639.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<script>
+var root = document.documentElement;
+while(root.firstChild) { root.removeChild(root.firstChild); }
+var div = document.createElement("div");
+root.appendChild(div);
+
+document.addEventListener("DOMNodeRemoved", function() {
+  root.appendChild(document.createTextNode("some mutation"));
+}, false);
+
+var range = document.createRange();
+range.setStart(root, 0);
+range.setEnd(root, root.childNodes.length);
+range.deleteContents();
+</script>
--- a/content/base/crashtests/crashtests.list
+++ b/content/base/crashtests/crashtests.list
@@ -104,11 +104,12 @@ load 700090-2.html
 load 700512.html
 load xhr_html_nullresponse.html
 load 709384.html
 load 713417.html
 load 713417-2.html
 load 715056.html
 load 741163-1.html
 load 766426.html
+load 771639.html
 asserts(0-1) load 752226-1.html
 asserts(0-1) load 752226-2.html
 HTTP(..) load xhr_abortinprogress.html
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -6092,17 +6092,17 @@ nsDocument::AdoptNode(nsIDOMNode *aAdopt
     default:
     {
       NS_WARNING("Don't know how to adopt this nodetype for adoptNode.");
 
       return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
     }
   }
 
-  nsIDocument *oldDocument = adoptedNode->OwnerDoc();
+  nsCOMPtr<nsIDocument> oldDocument = adoptedNode->OwnerDoc();
   bool sameDocument = oldDocument == this;
 
   JSContext *cx = nsnull;
   JSObject *newScope = nsnull;
   if (!sameDocument) {
     rv = GetContextAndScope(oldDocument, this, &cx, &newScope);
     NS_ENSURE_SUCCESS(rv, rv);
   }
--- a/content/base/src/nsFrameLoader.cpp
+++ b/content/base/src/nsFrameLoader.cpp
@@ -291,16 +291,17 @@ nsFrameLoader::nsFrameLoader(Element* aO
   , mInShow(false)
   , mHideCalled(false)
   , mNetworkCreated(aNetworkCreated)
   , mDelayRemoteDialogs(false)
   , mRemoteBrowserShown(false)
   , mRemoteFrame(false)
   , mClipSubdocument(true)
   , mClampScrollPosition(true)
+  , mRemoteBrowserInitialized(false)
   , mCurrentRemoteFrame(nsnull)
   , mRemoteBrowser(nsnull)
   , mRenderMode(RENDER_MODE_DEFAULT)
   , mEventMode(EVENT_MODE_NORMAL_DISPATCH)
 {
 }
 
 nsFrameLoader*
@@ -908,19 +909,20 @@ nsFrameLoader::ShowRemoteFrame(const nsI
     }
 
     mRemoteBrowser->Show(size);
     mRemoteBrowserShown = true;
 
     EnsureMessageManager();
 
     nsCOMPtr<nsIObserverService> os = services::GetObserverService();
-    if (OwnerIsBrowserFrame() && os) {
+    if (OwnerIsBrowserFrame() && os && !mRemoteBrowserInitialized) {
       os->NotifyObservers(NS_ISUPPORTS_CAST(nsIFrameLoader*, this),
                           "remote-browser-frame-shown", NULL);
+      mRemoteBrowserInitialized = true;
     }
   } else {
     nsRect dimensions;
     NS_ENSURE_SUCCESS(GetWindowDimensions(dimensions), false);
     mRemoteBrowser->UpdateDimensions(dimensions, size);
   }
 
   return true;
@@ -2236,9 +2238,17 @@ nsFrameLoader::GetOwnerElement(nsIDOMEle
 }
 
 void
 nsFrameLoader::SetRemoteBrowser(nsITabParent* aTabParent)
 {
   MOZ_ASSERT(!mRemoteBrowser);
   MOZ_ASSERT(!mCurrentRemoteFrame);
   mRemoteBrowser = static_cast<TabParent*>(aTabParent);
+
+  EnsureMessageManager();
+  nsCOMPtr<nsIObserverService> os = services::GetObserverService();
+  if (OwnerIsBrowserFrame() && os) {
+    mRemoteBrowserInitialized = true;
+    os->NotifyObservers(NS_ISUPPORTS_CAST(nsIFrameLoader*, this),
+                        "remote-browser-frame-shown", NULL);
+  }
 }
--- a/content/base/src/nsFrameLoader.h
+++ b/content/base/src/nsFrameLoader.h
@@ -325,16 +325,17 @@ private:
   // it may lose the flag.
   bool mNetworkCreated : 1;
 
   bool mDelayRemoteDialogs : 1;
   bool mRemoteBrowserShown : 1;
   bool mRemoteFrame : 1;
   bool mClipSubdocument : 1;
   bool mClampScrollPosition : 1;
+  bool mRemoteBrowserInitialized : 1;
 
   // XXX leaking
   nsCOMPtr<nsIObserver> mChildHost;
   RenderFrameParent* mCurrentRemoteFrame;
   TabParent* mRemoteBrowser;
 
   // See nsIFrameLoader.idl.  Short story, if !(mRenderMode &
   // RENDER_MODE_ASYNC_SCROLL), all the fields below are ignored in
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -3560,17 +3560,17 @@ nsGenericElement::AddScriptEventListener
 
 const nsAttrName*
 nsGenericElement::InternalGetExistingAttrNameFromQName(const nsAString& aStr) const
 {
   return mAttrsAndChildren.GetExistingAttrNameFromQName(aStr);
 }
 
 nsresult
-nsGenericElement::CopyInnerTo(nsGenericElement* aDst) const
+nsGenericElement::CopyInnerTo(nsGenericElement* aDst)
 {
   PRUint32 i, count = mAttrsAndChildren.AttrCount();
   for (i = 0; i < count; ++i) {
     const nsAttrName* name = mAttrsAndChildren.AttrNameAt(i);
     const nsAttrValue* value = mAttrsAndChildren.AttrAt(i);
     nsAutoString valStr;
     value->ToString(valStr);
     nsresult rv = aDst->SetAttr(name->NamespaceID(), name->LocalName(),
--- a/content/base/src/nsGenericElement.h
+++ b/content/base/src/nsGenericElement.h
@@ -769,17 +769,17 @@ protected:
    */
   virtual nsEventListenerManager*
     GetEventListenerManagerForAttr(nsIAtom* aAttrName, bool* aDefer);
 
   /**
    * Copy attributes and state to another element
    * @param aDest the object to copy to
    */
-  nsresult CopyInnerTo(nsGenericElement* aDest) const;
+  nsresult CopyInnerTo(nsGenericElement* aDest);
 
   /**
    * Internal hook for converting an attribute name-string to an atomized name
    */
   virtual const nsAttrName* InternalGetExistingAttrNameFromQName(const nsAString& aStr) const;
 
   /**
    * Retrieve the rectangle for the offsetX properties, which
@@ -995,17 +995,17 @@ nsresult                                
   *aResult = nsnull;                                                        \
   nsCOMPtr<nsINodeInfo> ni = aNodeInfo;                                     \
   _elementName *it = new _elementName(ni.forget());                         \
   if (!it) {                                                                \
     return NS_ERROR_OUT_OF_MEMORY;                                          \
   }                                                                         \
                                                                             \
   nsCOMPtr<nsINode> kungFuDeathGrip = it;                                   \
-  nsresult rv = CopyInnerTo(it);                                            \
+  nsresult rv = const_cast<_elementName*>(this)->CopyInnerTo(it);           \
   if (NS_SUCCEEDED(rv)) {                                                   \
     kungFuDeathGrip.swap(*aResult);                                         \
   }                                                                         \
                                                                             \
   return rv;                                                                \
 }
 
 #define NS_IMPL_ELEMENT_CLONE_WITH_INIT(_elementName)                       \
@@ -1016,17 +1016,17 @@ nsresult                                
   nsCOMPtr<nsINodeInfo> ni = aNodeInfo;                                     \
   _elementName *it = new _elementName(ni.forget());                         \
   if (!it) {                                                                \
     return NS_ERROR_OUT_OF_MEMORY;                                          \
   }                                                                         \
                                                                             \
   nsCOMPtr<nsINode> kungFuDeathGrip = it;                                   \
   nsresult rv = it->Init();                                                 \
-  rv |= CopyInnerTo(it);                                                    \
+  rv |= const_cast<_elementName*>(this)->CopyInnerTo(it);                   \
   if (NS_SUCCEEDED(rv)) {                                                   \
     kungFuDeathGrip.swap(*aResult);                                         \
   }                                                                         \
                                                                             \
   return rv;                                                                \
 }
 
 #define DOMCI_NODE_DATA(_interface, _class)                             \
--- a/content/base/src/nsRange.cpp
+++ b/content/base/src/nsRange.cpp
@@ -1448,16 +1448,21 @@ PrependChild(nsIDOMNode* aParent, nsIDOM
 
 // Helper function for CutContents, making sure that the current node wasn't
 // removed by mutation events (bug 766426)
 static bool
 ValidateCurrentNode(nsRange* aRange, RangeSubtreeIterator& aIter)
 {
   bool before, after;
   nsCOMPtr<nsIDOMNode> domNode = aIter.GetCurrentNode();
+  if (!domNode) {
+    // We don't have to worry that the node was removed if it doesn't exist,
+    // e.g., the iterator is done.
+    return true;
+  }
   nsCOMPtr<nsINode> node = do_QueryInterface(domNode);
   MOZ_ASSERT(node);
 
   nsresult res = nsRange::CompareNodeToRange(node, aRange, &before, &after);
 
   return NS_SUCCEEDED(res) && !before && !after;
 }
 
--- a/content/base/test/Makefile.in
+++ b/content/base/test/Makefile.in
@@ -28,21 +28,20 @@ CPP_UNIT_TESTS = \
 XPCSHELL_TESTS = \
                unit \
                $(NULL)
 # FIXME/bug 575918: out-of-process xpcshell is broken on OS X
 ifneq ($(OS_ARCH),Darwin)
 XPCSHELL_TESTS += unit_ipc
 endif
 
-include $(topsrcdir)/config/rules.mk
 
 # Split files arbitrarily in two groups to not run into too-long command lines
 # which break on Windows (see bug 563151)
-_TEST_FILES1 = \
+MOCHITEST_FILES_A = \
 		responseIdentical.sjs \
 		test_bug5141.html \
 		test_bug51034.html \
 		test_bug166235.html \
 		test_bug199959.html \
 		test_bug218236.html \
 		file_bug218236_multipart.txt \
 		file_bug218236_multipart.txt^headers^ \
@@ -253,17 +252,17 @@ include $(topsrcdir)/config/rules.mk
 		file_XHRDocURI.text \
 		file_XHRDocURI.text^headers^ \
 		test_DOMException.html \
 		test_mutationobservers.html \
 		mutationobserver_dialog.html \
 		test_bug744830.html \
 		$(NULL)
 
-_TEST_FILES2 = \
+MOCHITEST_FILES_B = \
 		test_bug459424.html \
 		bug461735-redirect1.sjs \
 		bug461735-redirect2.sjs \
 		bug461735-post-redirect.js \
 		test_bug513194.html \
 		test_bug461735.html \
 		test_bug380418.html \
 		test_bug469304.html \
@@ -552,42 +551,35 @@ include $(topsrcdir)/config/rules.mk
 		test_bug761120.html \
 		test_XHR_onuploadprogress.html \
 		test_XHR_anon.html \
 		file_XHR_anon.sjs \
 		test_XHR_system.html \
 		test_XHR_parameters.html \
 		$(NULL)
 
-_CHROME_FILES =	\
+MOCHITEST_CHROME_FILES =	\
 		test_bug357450.js \
 		$(NULL)
 
+MOCHITEST_FILES_PARTS = $(foreach s,A B,MOCHITEST_FILES_$(s))
+
 # This test fails on the Mac for some reason
 ifneq (,$(filter gtk2 windows,$(MOZ_WIDGET_TOOLKIT)))
-_TEST_FILES2 += 	test_copyimage.html \
+MOCHITEST_FILES_C = 	test_copyimage.html \
 		$(NULL)
+MOCHITEST_FILES_PARTS += MOCHITEST_FILES_C
 endif
 
 # Disabled for now. Mochitest isn't reliable enough for these.
 # test_bug444546.html \
 # bug444546.sjs \
 
 # Disabled due to making the harness time out
 #		test_bug503473.html \
 #		file_bug503473-frame.sjs \
 
-_BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_FILES = \
 		browser_bug593387.js \
 		$(NULL)
 
-libs:: $(_TEST_FILES1)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs:: $(_TEST_FILES2)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
 
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
-
-libs:: $(_CHROME_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
-
--- a/content/base/test/chrome/Makefile.in
+++ b/content/base/test/chrome/Makefile.in
@@ -4,23 +4,22 @@
 
 DEPTH     = ../../../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
 relativesrcdir  = content/base/test/chrome
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
     bug421622-referer.sjs \
     $(NULL)
 
-_CHROME_FILES = \
+MOCHITEST_CHROME_FILES = \
     test_bug206691.xul \
     test_bug391728.html \
     file_bug391728.html \
     file_bug391728_2.html \
     test_bug421622.xul \
     test_bug429785.xul \
     test_bug430050.xul \
     test_bug467123.xul \
@@ -41,13 +40,9 @@ include $(topsrcdir)/config/rules.mk
     test_bug599295.html \
     test_bug650776.html \
     test_bug650784.html \
     test_bug752226-3.xul \
     test_bug752226-4.xul \
     test_bug682305.html \
     $(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs:: $(_CHROME_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/content/base/test/websocket_hybi/Makefile.in
+++ b/content/base/test/websocket_hybi/Makefile.in
@@ -5,25 +5,21 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = content/base/test/websocket_hybi
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
 #### MODULE = content
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
     test_send-arraybuffer.html \
     test_send-blob.html \
     file_check-binary-messages_wsh.py \
     test_receive-arraybuffer.html \
     test_receive-blob.html \
     file_binary-frames_wsh.py \
     $(NULL)
 
-
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
+include $(topsrcdir)/config/rules.mk
--- a/content/canvas/test/Makefile.in
+++ b/content/canvas/test/Makefile.in
@@ -6,18 +6,17 @@
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = content/canvas/test
 DIRS		+= webgl crossorigin
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
-_TEST_FILES_0 = \
+MOCHITEST_FILES = \
 	test_canvas.html \
 	image_transparent50.png \
 	image_redtransparent.png \
 	image_yellow.png \
 	image_anim-poster-gr.png \
 	image_green-16x16.png \
 	image_red-16x16.png \
 	image_green-1x1.png \
@@ -56,17 +55,17 @@ include $(topsrcdir)/config/rules.mk
 	test_canvas_strokeStyle_getter.html \
 	test_bug613794.html \
 	test_bug753758.html \
 	test_drawImage_edge_cases.html \
 	$(NULL)
 
 ifneq (1_Linux,$(MOZ_SUITE)_$(OS_ARCH))
 # This test fails in Suite on Linux for some reason, disable it there
-_TEST_FILES_0 += test_2d.composite.uncovered.image.destination-atop.html
+MOCHITEST_FILES += test_2d.composite.uncovered.image.destination-atop.html
 endif
 
 # xor and lighter aren't well handled by cairo; they mostly work, but we don't want
 # to test that
 #	test_2d.composite.solid.xor.html \
 #	test_2d.composite.solid.lighter.html \
 #	test_2d.composite.transparent.xor.html \
 #	test_2d.composite.transparent.lighter.html \
@@ -76,63 +75,63 @@ endif
 #	test_2d.composite.canvas.lighter.html \
 #	test_2d.composite.clip.xor.html \
 #	test_2d.composite.clip.lighter.html \
 #
 
 # Tests that fail on Mac (possibly because spec is underdefined?).  Bug 407105
 ifneq ($(MOZ_WIDGET_TOOLKIT),cocoa)
 # XXX vlad don't test these anywhere, cairo behaviour changed
-_TEST_FILES_0 += \
+MOCHITEST_FILES += \
 	test_2d.line.join.parallel.html \
 	$(NULL)
 
 # This is an issue with Quartz's handling of radial gradients and some numeric
 # imprecision that results in errors here.
-_TEST_FILES_0 += \
+MOCHITEST_FILES += \
 	test_2d.gradient.radial.inside2.html \
 	test_2d.gradient.radial.inside3.html \
 	test_2d.gradient.radial.outside1.html \
 	test_2d.gradient.radial.cone.front.html \
 	test_2d.gradient.radial.cone.top.html \
 	$(NULL)
 
 # This is another Quartz bug -- closed paths that don't lie fully within the
 # destination bounds seem to have problems with the BEVEL/SQUARE join/cap combo.
 # The joins are rendered as if with MITER; the correct behaviour is also seen
 # if BUTT is used instead of SQUARE.
-_TEST_FILES_0 += test_2d.line.cap.closed.html
+MOCHITEST_FILES += test_2d.line.cap.closed.html
 
 endif
 
 # Tests that fail on non-Mac (bug 407107)
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
 
 # still need bug numbers
-_TEST_FILES_0 += \
+MOCHITEST_FILES += \
 	test_2d.composite.uncovered.fill.source-in.html \
 	test_2d.composite.uncovered.fill.destination-in.html \
 	test_2d.composite.uncovered.fill.source-out.html \
 	test_2d.composite.uncovered.fill.destination-atop.html \
 	test_2d.composite.uncovered.pattern.source-in.html \
 	test_2d.composite.uncovered.pattern.destination-in.html \
 	test_2d.composite.uncovered.pattern.source-out.html \
 	test_2d.composite.uncovered.pattern.destination-atop.html \
 	$(NULL)
 
 # still need bug numbers
-_TEST_FILES_0 += \
+MOCHITEST_FILES += \
 	test_2d.gradient.radial.outside2.html \
 	test_2d.gradient.radial.outside3.html \
 	$(NULL)
 
 # still need bug numbers
-_TEST_FILES_0 += test_2d.path.arc.shape.3.html
+MOCHITEST_FILES += test_2d.path.arc.shape.3.html
 
-_TEST_FILES_0 += test_2d.path.rect.selfintersect.html
+MOCHITEST_FILES += test_2d.path.rect.selfintersect.html
 endif
 
 # These tests only pass on Mac OS X >= 10.5; see bug 450114
 # test_2d.gradient.radial.touch1.html \
 # test_2d.gradient.radial.touch2.html \
 # test_2d.gradient.radial.touch3.html \
 # test_2d.gradient.radial.equal.html \
 
@@ -142,10 +141,9 @@ endif
 #	test_2d.gradient.radial.cone.shape2.html \
 #	test_2d.gradient.radial.cone.behind.html \
 #	test_2d.gradient.radial.cone.beside.html \
 
 # This test is bogus according to the spec; see bug 407107
 # test_2d.path.rect.zero.6.html
 
 # split up into groups to work around command-line length limits
-libs:: $(_TEST_FILES_0)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/content/canvas/test/crossorigin/Makefile.in
+++ b/content/canvas/test/crossorigin/Makefile.in
@@ -5,23 +5,21 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = content/canvas/test/crossorigin
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
-_TEST_FILES = \
+MOCHITEST_FILES = \
 	image-allow-credentials.png \
 	image-allow-credentials.png^headers^ \
 	image-allow-star.png \
 	image-allow-star.png^headers^ \
 	image.png \
 	test_canvas2d_crossorigin.html \
 	test_webgl_crossorigin_textures.html \
 	video.sjs \
 	test_video_crossorigin.html \
 	$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/content/canvas/test/webgl/Makefile.in
+++ b/content/canvas/test/webgl/Makefile.in
@@ -5,24 +5,24 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = content/canvas/test/webgl
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
-_TEST_FILES = \
+MOCHITEST_FILES = \
   test_webgl_conformance_test_suite.html \
   00_test_list.txt \
   failing_tests_linux.txt \
   failing_tests_windows.txt \
   failing_tests_mac.txt \
   failing_tests_android.txt \
   $(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
+
+libs::
 	$(TAR) -cf - -C $(srcdir) \
 	  resources \
 	  conformance \
 	  | $(TAR) -xf - -C $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
--- a/content/events/src/nsEventListenerManager.cpp
+++ b/content/events/src/nsEventListenerManager.cpp
@@ -277,17 +277,19 @@ nsEventListenerManager::AddEventListener
              (aTypeAtom == nsGkAtoms::ontouchstart ||
               aTypeAtom == nsGkAtoms::ontouchend ||
               aTypeAtom == nsGkAtoms::ontouchmove ||
               aTypeAtom == nsGkAtoms::ontouchenter ||
               aTypeAtom == nsGkAtoms::ontouchleave ||
               aTypeAtom == nsGkAtoms::ontouchcancel)) {
     mMayHaveTouchEventListener = true;
     nsPIDOMWindow* window = GetInnerWindowForTarget();
-    if (window)
+    // we don't want touchevent listeners added by scrollbars to flip this flag
+    // so we ignore listeners created with system event flag
+    if (window && !(aFlags & NS_EVENT_FLAG_SYSTEM_EVENT))
       window->SetHasTouchEventListeners();
   } else if (aTypeAtom == nsGkAtoms::onmouseenter ||
              aTypeAtom == nsGkAtoms::onmouseleave) {
     mMayHaveMouseEnterLeaveEventListener = true;
     nsPIDOMWindow* window = GetInnerWindowForTarget();
     if (window) {
 #ifdef DEBUG
       nsCOMPtr<nsIDocument> d = do_QueryInterface(window->GetExtantDocument());
--- a/content/events/test/Makefile.in
+++ b/content/events/test/Makefile.in
@@ -5,21 +5,20 @@
 
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = content/events/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
 # Disabled due to timeouts.
 # 		test_bug563329.html
-_TEST_FILES = \
+MOCHITEST_FILES = \
 		test_bug226361.xhtml \
 		     bug226361_iframe.xhtml \
 		test_bug238987.html \
 		test_bug288392.html \
 		test_bug299673-1.html \
 		test_bug299673-2.html \
 		     bug299673.js \
 		test_bug322588.html \
@@ -85,35 +84,35 @@ include $(topsrcdir)/config/rules.mk
 		test_bug741666.html \
 		test_dom_keyboard_event.html \
 		test_dom_mouse_event.html \
 		test_bug742376.html \
 		$(NULL)
 
 #bug 585630
 ifneq (mobile,$(MOZ_BUILD_APP))
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_dragstart.html \
 		$(NULL)
 endif
 
 # bug 565245
 ifneq (Linux,$(OS_ARCH))
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_bug493251.html \
 		$(NULL)
 endif
 
 ifeq (android,$(MOZ_WIDGET_TOOLKIT))
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_bug603008.html \
 		$(NULL)
 endif
 
-_CHROME_FILES = \
+MOCHITEST_CHROME_FILES = \
 		test_bug336682_2.xul \
 		test_bug336682.js \
 		test_bug350471.xul \
 		test_bug586961.xul \
 		test_bug415498.xul \
 		bug415498-doc1.html \
 		bug415498-doc2.html \
 		test_bug591249.xul \
@@ -122,13 +121,9 @@ endif
 		test_bug602962.xul \
 		test_bug617528.xul \
 		window_bug617528.xul \
 		test_bug679494.xul \
 		file_bug679494.html \
 		test_eventctors.xul \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs:: $(_CHROME_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/content/html/content/public/nsHTMLCanvasElement.h
+++ b/content/html/content/public/nsHTMLCanvasElement.h
@@ -119,17 +119,17 @@ public:
                    const nsAString& aValue, bool aNotify)
   {
     return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
   }
   virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
                            nsIAtom* aPrefix, const nsAString& aValue,
                            bool aNotify);
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
-  nsresult CopyInnerTo(nsGenericElement* aDest) const;
+  nsresult CopyInnerTo(nsGenericElement* aDest);
 
   /*
    * Helpers called by various users of Canvas
    */
 
   already_AddRefed<CanvasLayer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
                                                CanvasLayer *aOldLayer,
                                                LayerManager *aManager);
--- a/content/html/content/public/nsHTMLMediaElement.h
+++ b/content/html/content/public/nsHTMLMediaElement.h
@@ -340,17 +340,17 @@ public:
   already_AddRefed<nsILoadGroup> GetDocumentLoadGroup();
 
   /**
    * Returns true if the media has played or completed a seek.
    * Used by video frame to determine whether to paint the poster.
    */
   bool GetPlayedOrSeeked() const { return mHasPlayedOrSeeked; }
 
-  nsresult CopyInnerTo(nsGenericElement* aDest) const;
+  nsresult CopyInnerTo(nsGenericElement* aDest);
 
   /**
    * Sets the Accept header on the HTTP channel to the required
    * video or audio MIME types.
    */
   virtual nsresult SetAcceptHeader(nsIHttpChannel* aChannel) = 0;
 
   /**
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -270,17 +270,17 @@ nsGenericHTMLElement::DOMQueryInterface(
   NS_INTERFACE_TABLE_TO_MAP_SEGUE
   NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMElementCSSInlineStyle,
                                  new nsGenericHTMLElementTearoff(this))
   NS_INTERFACE_MAP_END
 
 // No closing bracket, because NS_INTERFACE_MAP_END does that for us.
 
 nsresult
-nsGenericHTMLElement::CopyInnerTo(nsGenericElement* aDst) const
+nsGenericHTMLElement::CopyInnerTo(nsGenericElement* aDst)
 {
   nsresult rv;
   PRInt32 i, count = GetAttrCount();
   for (i = 0; i < count; ++i) {
     const nsAttrName *name = mAttrsAndChildren.AttrNameAt(i);
     const nsAttrValue *value = mAttrsAndChildren.AttrAt(i);
 
     nsAutoString valStr;
--- a/content/html/content/src/nsGenericHTMLElement.h
+++ b/content/html/content/src/nsGenericHTMLElement.h
@@ -66,17 +66,17 @@ public:
    * @param aIID the IID to QI to
    * @param aInstancePtr the QI'd method [OUT]
    * @see nsGenericHTMLElementTearoff
    */
   nsresult DOMQueryInterface(nsIDOMHTMLElement *aElement, REFNSIID aIID,
                              void **aInstancePtr);
 
   // From nsGenericElement
-  nsresult CopyInnerTo(nsGenericElement* aDest) const;
+  nsresult CopyInnerTo(nsGenericElement* aDest);
 
   // Implementation for nsIDOMElement
   NS_METHOD SetAttribute(const nsAString& aName,
                          const nsAString& aValue);
 
   // nsIDOMHTMLElement methods. Note that these are non-virtual
   // methods, implementations are expected to forward calls to these
   // methods.
--- a/content/html/content/src/nsGenericHTMLFrameElement.cpp
+++ b/content/html/content/src/nsGenericHTMLFrameElement.cpp
@@ -223,17 +223,17 @@ nsGenericHTMLFrameElement::DestroyConten
     mFrameLoader->Destroy();
     mFrameLoader = nsnull;
   }
 
   nsGenericHTMLElement::DestroyContent();
 }
 
 nsresult
-nsGenericHTMLFrameElement::CopyInnerTo(nsGenericElement* aDest) const
+nsGenericHTMLFrameElement::CopyInnerTo(nsGenericElement* aDest)
 {
   nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsIDocument* doc = aDest->OwnerDoc();
   if (doc->IsStaticDocument() && mFrameLoader) {
     nsGenericHTMLFrameElement* dest =
       static_cast<nsGenericHTMLFrameElement*>(aDest);
--- a/content/html/content/src/nsGenericHTMLFrameElement.h
+++ b/content/html/content/src/nsGenericHTMLFrameElement.h
@@ -48,17 +48,17 @@ public:
   {
     return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
   }
   virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
                            nsIAtom* aPrefix, const nsAString& aValue,
                            bool aNotify);
   virtual void DestroyContent();
 
-  nsresult CopyInnerTo(nsGenericElement* aDest) const;
+  nsresult CopyInnerTo(nsGenericElement* aDest);
 
   // nsIDOMHTMLElement
   NS_IMETHOD GetTabIndex(PRInt32 *aTabIndex);
   NS_IMETHOD SetTabIndex(PRInt32 aTabIndex);
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsGenericHTMLFrameElement,
                                                      nsGenericHTMLElement)
 
--- a/content/html/content/src/nsHTMLCanvasElement.cpp
+++ b/content/html/content/src/nsHTMLCanvasElement.cpp
@@ -119,17 +119,17 @@ nsHTMLCanvasElement::SetAttr(PRInt32 aNa
     rv = UpdateContext();
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return rv;
 }
 
 nsresult
-nsHTMLCanvasElement::CopyInnerTo(nsGenericElement* aDest) const
+nsHTMLCanvasElement::CopyInnerTo(nsGenericElement* aDest)
 {
   nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest);
   NS_ENSURE_SUCCESS(rv, rv);
   if (aDest->OwnerDoc()->IsStaticDocument()) {
     nsHTMLCanvasElement* dest = static_cast<nsHTMLCanvasElement*>(aDest);
     nsCOMPtr<nsISupports> cxt;
     dest->GetContext(NS_LITERAL_STRING("2d"), JSVAL_VOID, getter_AddRefs(cxt));
     nsCOMPtr<nsIDOMCanvasRenderingContext2D> context2d = do_QueryInterface(cxt);
--- a/content/html/content/src/nsHTMLImageElement.cpp
+++ b/content/html/content/src/nsHTMLImageElement.cpp
@@ -518,17 +518,17 @@ nsHTMLImageElement::GetNaturalWidth(PRUi
   PRInt32 width;
   if (NS_SUCCEEDED(image->GetWidth(&width))) {
     *aNaturalWidth = width;
   }
   return NS_OK;
 }
 
 nsresult
-nsHTMLImageElement::CopyInnerTo(nsGenericElement* aDest) const
+nsHTMLImageElement::CopyInnerTo(nsGenericElement* aDest)
 {
   if (aDest->OwnerDoc()->IsStaticDocument()) {
     CreateStaticImageClone(static_cast<nsHTMLImageElement*>(aDest));
   }
   return nsGenericHTMLElement::CopyInnerTo(aDest);
 }
 
 CORSMode
--- a/content/html/content/src/nsHTMLImageElement.h
+++ b/content/html/content/src/nsHTMLImageElement.h
@@ -90,17 +90,17 @@ public:
 
   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
                               nsIContent* aBindingParent,
                               bool aCompileEventHandlers);
 
   virtual nsEventStates IntrinsicState() const;
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
-  nsresult CopyInnerTo(nsGenericElement* aDest) const;
+  nsresult CopyInnerTo(nsGenericElement* aDest);
 
   void MaybeLoadImage();
   virtual nsXPCClassInfo* GetClassInfo();
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
   nsIntPoint GetXY();
   virtual void GetItemValueText(nsAString& text);
   virtual void SetItemValueText(const nsAString& text);
--- a/content/html/content/src/nsHTMLInputElement.cpp
+++ b/content/html/content/src/nsHTMLInputElement.cpp
@@ -639,17 +639,17 @@ nsresult
 nsHTMLInputElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
 {
   *aResult = nsnull;
 
   nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
   nsRefPtr<nsHTMLInputElement> it =
     new nsHTMLInputElement(ni.forget(), NOT_FROM_PARSER);
 
-  nsresult rv = CopyInnerTo(it);
+  nsresult rv = const_cast<nsHTMLInputElement*>(this)->CopyInnerTo(it);
   NS_ENSURE_SUCCESS(rv, rv);
 
   switch (mType) {
     case NS_FORM_INPUT_EMAIL:
     case NS_FORM_INPUT_SEARCH:
     case NS_FORM_INPUT_TEXT:
     case NS_FORM_INPUT_PASSWORD:
     case NS_FORM_INPUT_TEL:
--- a/content/html/content/src/nsHTMLMediaElement.cpp
+++ b/content/html/content/src/nsHTMLMediaElement.cpp
@@ -3316,17 +3316,17 @@ already_AddRefed<nsILoadGroup> nsHTMLMed
 {
   if (!OwnerDoc()->IsActive()) {
     NS_WARNING("Load group requested for media element in inactive document.");
   }
   return OwnerDoc()->GetDocumentLoadGroup();
 }
 
 nsresult
-nsHTMLMediaElement::CopyInnerTo(nsGenericElement* aDest) const
+nsHTMLMediaElement::CopyInnerTo(nsGenericElement* aDest)
 {
   nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest);
   NS_ENSURE_SUCCESS(rv, rv);
   if (aDest->OwnerDoc()->IsStaticDocument()) {
     nsHTMLMediaElement* dest = static_cast<nsHTMLMediaElement*>(aDest);
     if (mPrintSurface) {
       dest->mPrintSurface = mPrintSurface;
       dest->mMediaSize = mMediaSize;
--- a/content/html/content/src/nsHTMLMenuItemElement.cpp
+++ b/content/html/content/src/nsHTMLMenuItemElement.cpp
@@ -185,17 +185,17 @@ NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLA
 //NS_IMPL_ELEMENT_CLONE(nsHTMLMenuItemElement)
 nsresult
 nsHTMLMenuItemElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
 {
   *aResult = nsnull;
   nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
   nsRefPtr<nsHTMLMenuItemElement> it =
     new nsHTMLMenuItemElement(ni.forget(), NOT_FROM_PARSER);
-  nsresult rv = CopyInnerTo(it);
+  nsresult rv = const_cast<nsHTMLMenuItemElement*>(this)->CopyInnerTo(it);
   if (NS_SUCCEEDED(rv)) {
     switch (mType) {
       case CMD_TYPE_CHECKBOX:
       case CMD_TYPE_RADIO:
         if (mCheckedDirty) {
           // We no longer have our original checked state.  Set our
           // checked state on the clone.
           it->mCheckedDirty = true;
--- a/content/html/content/src/nsHTMLObjectElement.cpp
+++ b/content/html/content/src/nsHTMLObjectElement.cpp
@@ -110,17 +110,17 @@ public:
   virtual nsEventStates IntrinsicState() const;
   virtual void DestroyContent();
 
   // nsObjectLoadingContent
   virtual PRUint32 GetCapabilities() const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
-  nsresult CopyInnerTo(nsGenericElement* aDest) const;
+  nsresult CopyInnerTo(nsGenericElement* aDest);
 
   void StartObjectLoad() { StartObjectLoad(true); }
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLObjectElement,
                                                      nsGenericHTMLFormElement)
 
   virtual nsXPCClassInfo* GetClassInfo();
 
@@ -545,17 +545,17 @@ nsHTMLObjectElement::GetCapabilities() c
 void
 nsHTMLObjectElement::DestroyContent()
 {
   RemovedFromDocument();
   nsGenericHTMLFormElement::DestroyContent();
 }
 
 nsresult
-nsHTMLObjectElement::CopyInnerTo(nsGenericElement* aDest) const
+nsHTMLObjectElement::CopyInnerTo(nsGenericElement* aDest)
 {
   nsresult rv = nsGenericHTMLFormElement::CopyInnerTo(aDest);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (aDest->OwnerDoc()->IsStaticDocument()) {
     CreateStaticClone(static_cast<nsHTMLObjectElement*>(aDest));
   }
 
--- a/content/html/content/src/nsHTMLOptionElement.cpp
+++ b/content/html/content/src/nsHTMLOptionElement.cpp
@@ -429,17 +429,17 @@ nsHTMLOptionElement::Initialize(nsISuppo
       }
     }
   }
 
   return result;
 }
 
 nsresult
-nsHTMLOptionElement::CopyInnerTo(nsGenericElement* aDest) const
+nsHTMLOptionElement::CopyInnerTo(nsGenericElement* aDest)
 {
   nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (aDest->OwnerDoc()->IsStaticDocument()) {
     static_cast<nsHTMLOptionElement*>(aDest)->SetSelected(Selected());
   }
   return NS_OK;
--- a/content/html/content/src/nsHTMLOptionElement.h
+++ b/content/html/content/src/nsHTMLOptionElement.h
@@ -68,17 +68,17 @@ public:
   virtual void UnbindFromTree(bool aDeep = true,
                               bool aNullParent = true);
 
   // nsIContent
   virtual nsEventStates IntrinsicState() const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
-  nsresult CopyInnerTo(nsGenericElement* aDest) const;
+  nsresult CopyInnerTo(nsGenericElement* aDest);
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 
   virtual bool IsDisabled() const {
     return HasAttr(kNameSpaceID_None, nsGkAtoms::disabled);
   }
--- a/content/html/content/src/nsHTMLScriptElement.cpp
+++ b/content/html/content/src/nsHTMLScriptElement.cpp
@@ -174,17 +174,17 @@ nsHTMLScriptElement::Clone(nsINodeInfo *
 {
   *aResult = nsnull;
 
   nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
   nsHTMLScriptElement* it =
     new nsHTMLScriptElement(ni.forget(), NOT_FROM_PARSER);
 
   nsCOMPtr<nsINode> kungFuDeathGrip = it;
-  nsresult rv = CopyInnerTo(it);
+  nsresult rv = const_cast<nsHTMLScriptElement*>(this)->CopyInnerTo(it);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // The clone should be marked evaluated if we are.
   it->mAlreadyStarted = mAlreadyStarted;
   it->mLineNumber = mLineNumber;
   it->mMalformed = mMalformed;
 
   kungFuDeathGrip.swap(*aResult);
--- a/content/html/content/src/nsHTMLSharedObjectElement.cpp
+++ b/content/html/content/src/nsHTMLSharedObjectElement.cpp
@@ -102,17 +102,17 @@ public:
   virtual nsEventStates IntrinsicState() const;
   virtual void DestroyContent();
 
   // nsObjectLoadingContent
   virtual PRUint32 GetCapabilities() const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
-  nsresult CopyInnerTo(nsGenericElement* aDest) const;
+  nsresult CopyInnerTo(nsGenericElement* aDest);
 
   void StartObjectLoad() { StartObjectLoad(true); }
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLSharedObjectElement,
                                                      nsGenericHTMLElement)
 
   virtual nsXPCClassInfo* GetClassInfo()
   {
@@ -504,17 +504,17 @@ nsHTMLSharedObjectElement::GetCapabiliti
 void
 nsHTMLSharedObjectElement::DestroyContent()
 {
   RemovedFromDocument();
   nsGenericHTMLElement::DestroyContent();
 }
 
 nsresult
-nsHTMLSharedObjectElement::CopyInnerTo(nsGenericElement* aDest) const
+nsHTMLSharedObjectElement::CopyInnerTo(nsGenericElement* aDest)
 {
   nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (aDest->OwnerDoc()->IsStaticDocument()) {
     CreateStaticClone(static_cast<nsHTMLSharedObjectElement*>(aDest));
   }
 
--- a/content/html/content/src/nsHTMLTextAreaElement.cpp
+++ b/content/html/content/src/nsHTMLTextAreaElement.cpp
@@ -163,17 +163,17 @@ public:
 
   virtual bool IsHTMLFocusable(bool aWithMouse, bool *aIsFocusable, PRInt32 *aTabIndex);
 
   virtual void DoneAddingChildren(bool aHaveNotified);
   virtual bool IsDoneAddingChildren();
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
-  nsresult CopyInnerTo(nsGenericElement* aDest) const;
+  nsresult CopyInnerTo(nsGenericElement* aDest);
 
   /**
    * Called when an attribute is about to be changed
    */
   virtual nsresult BeforeSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
                                  const nsAttrValueOrString* aValue,
                                  bool aNotify);
 
@@ -1268,17 +1268,17 @@ nsHTMLTextAreaElement::AfterSetAttr(PRIn
     UpdateState(aNotify);
   }
 
   return nsGenericHTMLFormElement::AfterSetAttr(aNameSpaceID, aName, aValue,
                                                 aNotify);
 }
 
 nsresult
-nsHTMLTextAreaElement::CopyInnerTo(nsGenericElement* aDest) const
+nsHTMLTextAreaElement::CopyInnerTo(nsGenericElement* aDest)
 {
   nsresult rv = nsGenericHTMLFormElement::CopyInnerTo(aDest);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (aDest->OwnerDoc()->IsStaticDocument()) {
     nsAutoString value;
     GetValueInternal(value, true);
     static_cast<nsHTMLTextAreaElement*>(aDest)->SetValue(value);
--- a/content/html/content/test/Makefile.in
+++ b/content/html/content/test/Makefile.in
@@ -17,19 +17,18 @@ include $(DEPTH)/config/autoconf.mk
 # it exists in that case, which we use to detect failure.
 # We can't have index.html in this directory because it would prevent
 # running the tests here.
 TEST_DIRS += bug649134
 
 # For form-related test suite.
 TEST_DIRS += forms
 
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
 		test_hidden.html \
 		test_bug589.html \
 		test_bug691.html \
 		nnc_lockup.gif \
 		test_bug694.html \
 		test_bug696.html \
 		test_bug1297.html \
 		test_bug1366.html \
@@ -263,19 +262,15 @@ include $(topsrcdir)/config/rules.mk
 		test_object_plugin_nav.html \
 		test_bug742030.html \
 		test_bug742549.html \
 		test_bug745685.html \
 		test_input_file_picker.html \
 		test_bug763626.html \
 		$(NULL)
 
-_BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_FILES = \
 		browser_bug649778.js \
 		file_bug649778.html \
 		file_bug649778.html^headers^ \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/content/html/content/test/bug649134/Makefile.in
+++ b/content/html/content/test/bug649134/Makefile.in
@@ -5,14 +5,12 @@
 
 DEPTH          = ../../../../..
 topsrcdir      = @top_srcdir@
 srcdir         = @srcdir@
 VPATH          = @srcdir@
 relativesrcdir = content/html/content/test/bug649134
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = file_bug649134-1.sjs file_bug649134-2.sjs index.html
+MOCHITEST_FILES = file_bug649134-1.sjs file_bug649134-2.sjs index.html
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/content/html/content/test/forms/Makefile.in
+++ b/content/html/content/test/forms/Makefile.in
@@ -4,19 +4,18 @@
 
 DEPTH          = ../../../../..
 topsrcdir      = @top_srcdir@
 srcdir         = @srcdir@
 VPATH          = @srcdir@
 relativesrcdir = content/html/content/test/forms
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
 		save_restore_radio_groups.sjs \
 		test_save_restore_radio_groups.html \
 		test_change_event.html \
 		test_mozistextfield.html \
 		test_input_attributes_reflection.html \
 		test_input_list_attribute.html \
 		test_input_email.html \
 		test_input_url.html \
@@ -46,11 +45,10 @@ include $(topsrcdir)/config/rules.mk
 		test_min_attribute.html \
 		test_step_attribute.html \
 		test_stepup_stepdown.html \
 		test_valueasnumber_attribute.html \
 		test_experimental_forms_pref.html \
 		test_input_number_value.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
 
--- a/content/html/document/test/Makefile.in
+++ b/content/html/document/test/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = content/html/document/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = 	test_bug1682.html \
+MOCHITEST_FILES = 	test_bug1682.html \
 		test_bug1823.html \
 		test_bug57600.html \
 		test_bug196523.html \
 		bug196523-subframe.html \
 		test_bug199692.html \
 		bug199692-nested.html \
 		bug199692-nested-d2.html \
 		bug199692-popup.html \
@@ -71,21 +70,15 @@ include $(topsrcdir)/config/rules.mk
 		test_bug512367.html \
 		test_bug571981.html \
 		test_bug677495.html \
 		test_bug677495-1.html \
 		test_bug741266.html \
 		$(NULL)
 
 ifneq (mobile,$(MOZ_BUILD_APP))
-_BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_FILES = \
 		browser_bug592641.js \
 		bug592641_img.jpg \
 		$(NULL)
 endif
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-ifneq (mobile,$(MOZ_BUILD_APP))
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
-endif
+include $(topsrcdir)/config/rules.mk
--- a/content/media/test/Makefile.in
+++ b/content/media/test/Makefile.in
@@ -4,17 +4,16 @@
 
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= content/media/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
 # Media tests should be backend independent, i.e., not conditioned on
 # MOZ_OGG, MOZ_WAVE etc. (The only exception is the can_play_type tests,
 # which necessarily depend on the backend(s) configured.) As far as possible,
 # each test should work with any resource type. This makes it
 # easy to add new backends and reduces the amount of test duplication.
 
 # For each supported backend, resources that can be played by that backend
@@ -29,17 +28,17 @@ include $(topsrcdir)/config/rules.mk
 # add it to gPlayTests in manifest.js. To test whether an invalid
 # resource correctly throws an error (and does not cause a crash or hang),
 # just add it to gErrorTests in manifest.js.
 
 # To test for a specific bug in handling a specific resource type,
 # make the test first check canPlayType for the type, and if it's not
 # supported, just do ok(true, "Type not supported") and stop the test.
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
 		allowed.sjs \
 		can_play_type_ogg.js \
 		can_play_type_wave.js \
 		can_play_type_webm.js \
 		cancellable_request.sjs \
 		dynamic_redirect.sjs \
 		dynamic_resource.sjs \
 		file_access_controls.html \
@@ -120,30 +119,30 @@ include $(topsrcdir)/config/rules.mk
 		test_video_to_canvas.html \
 		use_large_cache.js \
 		test_audiowrite.html \
 		test_mozHasAudio.html \
 		test_source_media.html \
 		$(NULL)
 
 # Bug 759221
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_autoplay_contentEditable.html \
 		test_buffered.html \
 		test_bug448534.html \
 		test_bug463162.xhtml \
 		test_decoder_disable.html \
 		test_media_selection.html \
 		test_playback.html \
 		test_seekLies.html \
 		$(NULL)
 
 # Don't run in suite
 ifndef MOZ_SUITE
-_TEST_FILES += test_play_twice.html
+MOCHITEST_FILES += test_play_twice.html
 else
 $(warning test_play_twice.html is disabled pending investigation. Bug 598252)
 endif
 
 # These tests are disabled until we figure out random failures.
 # When these tests are fixed, we should also make them backend-independent.
 #		test_resume.html \
 # Bug 492821:
@@ -151,17 +150,17 @@ endif
 # Bug 493692:
 #   test_preload_suspend.html
 # Bug 567954 and Bug 574586:
 #   test_mixed_principals.html
 # Disabled since we don't play Wave files standalone, for now
 #		test_audioDocumentTitle.html
 
 # sample files
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		320x240.ogv \
 		448636.ogv \
 		audio-overhang.ogg \
 		audio-gaps.ogg \
 		beta-phrasebook.ogg \
 		bogus.ogv \
 		bug495129.ogv \
 		bug495794.ogg \
@@ -205,51 +204,51 @@ endif
 		sound.ogg \
 		spacestorm-1000Hz-100ms.ogg \
 		video-overhang.ogg \
 		file_a4_tone.ogg \
 		detodos.opus \
 		$(NULL)
 
 # Wave sample files
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		big.wav \
 		bogus.wav \
 		r11025_msadpcm_c1.wav \
 		r11025_s16_c1.wav \
 		r11025_s16_c1_trailing.wav \
 		r11025_u8_c1.wav \
 		r11025_u8_c1_trunc.wav \
 		r16000_u8_c1_list.wav \
 		wavedata_u8.wav \
 		wavedata_s16.wav \
 		audio.wav \
 		$(NULL)
 
 # Other files
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		bogus.duh \
 		$(NULL)
 
 # These tests contain backend-specific tests. Try to write backend
 # independent tests rather than adding to this list.
 ifdef MOZ_OGG
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_can_play_type_ogg.html \
 		noContentLength.sjs \
 		test_seekable3.html \
 		test_a4_tone.html \
 		file_audio_event_adopt_iframe.html \
 		test_audio_event_adopt.html \
 		test_referer.html \
 		test_bug726904.html \
 		$(NULL)
 
 # Bug 759221
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_bug686137.html \
 		test_contentDuration1.html \
 		test_contentDuration2.html \
 		test_contentDuration3.html \
 		test_contentDuration4.html \
 		test_contentDuration5.html \
 		test_contentDuration6.html \
 		test_contentDuration7.html \
@@ -259,44 +258,43 @@ ifdef MOZ_OGG
 		contentDuration4.sjs \
 		contentDuration5.sjs \
 		contentDuration6.sjs \
 		contentDuration7.sjs \
 		test_framebuffer.html \
 		test_seekable2.html \
 		$(NULL)
 else
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_can_play_type_no_ogg.html \
 		$(NULL)
 endif
 
 ifdef MOZ_WEBM
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_can_play_type_webm.html \
 		$(NULL)
 else
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_can_play_type_no_webm.html \
 		$(NULL)
 endif
 
 ifdef MOZ_WAVE
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_can_play_type_wave.html \
 		$(NULL)
 
 
 # Bug 759221
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_fragment_play.html \
 		test_fragment_noplay.html \
 		test_wave_data_u8.html \
 		test_wave_data_s16.html \
 		$(NULL)
 else
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_can_play_type_no_wave.html \
 		$(NULL)
 endif
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/content/smil/test/Makefile.in
+++ b/content/smil/test/Makefile.in
@@ -3,19 +3,18 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = content/smil/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
 	  db_smilAnimateMotion.js \
 	  db_smilCSSFromBy.js \
 	  db_smilCSSFromTo.js \
 	  db_smilCSSPaced.js \
 	  db_smilCSSPropertyList.js \
 	  db_smilMappedAttrList.js \
 	  smilAnimateMotionValueLists.js \
 	  smilTestUtils.js \
@@ -60,10 +59,9 @@ include $(topsrcdir)/config/rules.mk
 	  test_smilUpdatedInterval.xhtml \
 	  test_smilValues.xhtml \
 	  test_smilXHR.xhtml \
 	  $(NULL)
 
 # Tests disabled due to intermittent orange
 # test_smilCSSInherit.xhtml disabled until bug 501183 is fixed
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/content/svg/content/src/nsSVGElement.h
+++ b/content/svg/content/src/nsSVGElement.h
@@ -149,16 +149,17 @@ public:
    */
   virtual gfxMatrix PrependLocalTransformsTo(const gfxMatrix &aMatrix,
                       TransformTypes aWhich = eAllTransforms) const;
 
   // Setter for to set the current <animateMotion> transformation
   // Only visible for nsSVGGraphicElement, so it's a no-op here, and that
   // subclass has the useful implementation.
   virtual void SetAnimateMotionTransform(const gfxMatrix* aMatrix) {/*no-op*/}
+  virtual const gfxMatrix* GetAnimateMotionTransform() const { return nsnull; }
 
   bool IsStringAnimatable(PRUint8 aAttrEnum) {
     return GetStringInfo().mStringInfo[aAttrEnum].mIsAnimatable;
   }
   bool NumberAttrAllowsPercentage(PRUint8 aAttrEnum) {
     return GetNumberInfo().mNumberInfo[aAttrEnum].mPercentagesAllowed;
   }
   virtual bool HasValidDimensions() const {
--- a/content/svg/content/src/nsSVGGraphicElement.cpp
+++ b/content/svg/content/src/nsSVGGraphicElement.cpp
@@ -147,17 +147,18 @@ nsSVGGraphicElement::IsAttributeMapped(c
 }
 
 nsChangeHint
 nsSVGGraphicElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
                                             PRInt32 aModType) const
 {
   nsChangeHint retval =
     nsSVGGraphicElementBase::GetAttributeChangeHint(aAttribute, aModType);
-  if (aAttribute == nsGkAtoms::transform) {
+  if (aAttribute == nsGkAtoms::transform ||
+      aAttribute == nsGkAtoms::mozAnimateMotionDummyAttr) {
     // We add nsChangeHint_UpdateOverflow so that nsFrame::UpdateOverflow()
     // will be called on us and our ancestors.
     nsIFrame* frame =
       const_cast<nsSVGGraphicElement*>(this)->GetPrimaryFrame();
     if (frame && frame->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD) {
       // No need to do anything.
     } else if (aModType == nsIDOMMutationEvent::ADDITION ||
                aModType == nsIDOMMutationEvent::REMOVAL) {
@@ -221,16 +222,22 @@ nsSVGGraphicElement::PrependLocalTransfo
 
   if (mTransforms) {
     result.PreMultiply(mTransforms->GetAnimValue().GetConsolidationMatrix());
   }
 
   return result;
 }
 
+const gfxMatrix*
+nsSVGGraphicElement::GetAnimateMotionTransform() const
+{
+  return mAnimateMotionTransform.get();
+}
+
 void
 nsSVGGraphicElement::SetAnimateMotionTransform(const gfxMatrix* aMatrix)
 {
   if ((!aMatrix && !mAnimateMotionTransform) ||
       aMatrix && mAnimateMotionTransform && *aMatrix == *mAnimateMotionTransform) {
     return;
   }
   mAnimateMotionTransform = aMatrix ? new gfxMatrix(*aMatrix) : nsnull;
--- a/content/svg/content/src/nsSVGGraphicElement.h
+++ b/content/svg/content/src/nsSVGGraphicElement.h
@@ -29,16 +29,17 @@ public:
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
                                       PRInt32 aModType) const;
 
   virtual gfxMatrix PrependLocalTransformsTo(const gfxMatrix &aMatrix,
                       TransformTypes aWhich = eAllTransforms) const;
+  virtual const gfxMatrix* GetAnimateMotionTransform() const;
   virtual void SetAnimateMotionTransform(const gfxMatrix* aMatrix);
 
   virtual mozilla::SVGAnimatedTransformList* GetAnimatedTransformList();
   virtual nsIAtom* GetTransformListAttrName() const {
     return nsGkAtoms::transform;
   }
 
 protected:
--- a/content/svg/content/src/nsSVGImageElement.cpp
+++ b/content/svg/content/src/nsSVGImageElement.cpp
@@ -259,15 +259,15 @@ nsSVGImageElement::GetPreserveAspectRati
 nsSVGElement::StringAttributesInfo
 nsSVGImageElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
                               ArrayLength(sStringInfo));
 }
 
 nsresult
-nsSVGImageElement::CopyInnerTo(nsGenericElement* aDest) const
+nsSVGImageElement::CopyInnerTo(nsGenericElement* aDest)
 {
   if (aDest->OwnerDoc()->IsStaticDocument()) {
     CreateStaticImageClone(static_cast<nsSVGImageElement*>(aDest));
   }
   return nsSVGImageElementBase::CopyInnerTo(aDest);
 }
--- a/content/svg/content/src/nsSVGImageElement.h
+++ b/content/svg/content/src/nsSVGImageElement.h
@@ -57,17 +57,17 @@ public:
   // nsSVGPathGeometryElement methods:
   virtual void ConstructPath(gfxContext *aCtx);
 
   // nsSVGSVGElement methods:
   virtual bool HasValidDimensions() const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
-  nsresult CopyInnerTo(nsGenericElement* aDest) const;
+  nsresult CopyInnerTo(nsGenericElement* aDest);
 
   void MaybeLoadSVGImage();
 
   bool IsImageSrcSetDisabled() const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
--- a/content/svg/content/src/nsSVGSVGElement.cpp
+++ b/content/svg/content/src/nsSVGSVGElement.cpp
@@ -183,17 +183,17 @@ nsresult
 nsSVGSVGElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
 {
   *aResult = nsnull;
   nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
   nsSVGSVGElement *it = new nsSVGSVGElement(ni.forget(), NOT_FROM_PARSER);
 
   nsCOMPtr<nsINode> kungFuDeathGrip = it;
   nsresult rv = it->Init();
-  rv |= CopyInnerTo(it);
+  rv |= const_cast<nsSVGSVGElement*>(this)->CopyInnerTo(it);
   if (NS_SUCCEEDED(rv)) {
     kungFuDeathGrip.swap(*aResult);
   }
 
   return rv;
 }
 
 
--- a/content/svg/content/src/nsSVGScriptElement.cpp
+++ b/content/svg/content/src/nsSVGScriptElement.cpp
@@ -124,17 +124,17 @@ nsSVGScriptElement::Clone(nsINodeInfo *a
 {
   *aResult = nsnull;
 
   nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
   nsSVGScriptElement* it = new nsSVGScriptElement(ni.forget(), NOT_FROM_PARSER);
 
   nsCOMPtr<nsINode> kungFuDeathGrip = it;
   nsresult rv = it->Init();
-  rv |= CopyInnerTo(it);
+  rv |= const_cast<nsSVGScriptElement*>(this)->CopyInnerTo(it);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // The clone should be marked evaluated if we are.
   it->mAlreadyStarted = mAlreadyStarted;
   it->mLineNumber = mLineNumber;
   it->mMalformed = mMalformed;
 
   kungFuDeathGrip.swap(*aResult);
--- a/content/svg/content/src/nsSVGUseElement.cpp
+++ b/content/svg/content/src/nsSVGUseElement.cpp
@@ -103,17 +103,17 @@ nsSVGUseElement::Clone(nsINodeInfo *aNod
   nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
   nsSVGUseElement *it = new nsSVGUseElement(ni.forget());
   if (!it) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   nsCOMPtr<nsINode> kungFuDeathGrip(it);
   nsresult rv = it->Init();
-  rv |= CopyInnerTo(it);
+  rv |= const_cast<nsSVGUseElement*>(this)->CopyInnerTo(it);
 
   // nsSVGUseElement specific portion - record who we cloned from
   it->mOriginal = const_cast<nsSVGUseElement*>(this);
 
   if (NS_SUCCEEDED(rv)) {
     kungFuDeathGrip.swap(*aResult);
   }
 
--- a/content/svg/content/test/Makefile.in
+++ b/content/svg/content/test/Makefile.in
@@ -5,23 +5,22 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = content/svg/content/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
 # Disabled:
 #		bbox-helper.svg \
 #		test_length.xhtml \
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
 		matrixUtils.js \
 		MutationEventChecker.js \
 		test_a_href_01.xhtml \
 		test_a_href_02.xhtml \
 		a_href_destination.svg \
 		a_href_helper_01.svg \
 		a_href_helper_02_03.svg \
 		a_href_helper_04.svg \
@@ -79,10 +78,9 @@ include $(topsrcdir)/config/rules.mk
 		test_valueAsString.xhtml \
 		test_valueLeaks.xhtml \
 		viewport-helper.svg \
 		test_viewport.html \
 		zoom-helper.svg \
 		test_zoom.xhtml \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/content/xbl/test/Makefile.in
+++ b/content/xbl/test/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = content/xbl/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =	\
+MOCHITEST_FILES =	\
 		test_bug310107.html \
 		bug310107-resource.xhtml \
 		test_bug366770.html \
 		test_bug371724.xhtml \
 		test_bug372769.xhtml \
 		test_bug378866.xhtml \
 		test_bug397934.xhtml \
 		test_bug389322.xhtml \
@@ -35,23 +34,19 @@ include $(topsrcdir)/config/rules.mk
 		test_bug526178.xhtml \
 		test_bug542406.xhtml \
 		test_bug591198.html \
 		file_bug591198_xbl.xml \
 		file_bug591198_inner.html \
 		test_bug639338.xhtml \
 		$(NULL)
 
-_CHROME_FILES = \
+MOCHITEST_CHROME_FILES = \
 		test_bug296375.xul \
 		test_bug378518.xul \
 		test_bug398135.xul \
 		test_bug398492.xul \
 		test_bug721452.xul \
 		test_bug723676.xul \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
 
-libs:: $(_CHROME_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
-
--- a/content/xml/document/test/Makefile.in
+++ b/content/xml/document/test/Makefile.in
@@ -5,25 +5,23 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = content/xml/document/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = 	test_bug232004.xhtml \
+MOCHITEST_FILES = 	test_bug232004.xhtml \
 		test_bug343870.xhtml \
 		test_bug355213.xhtml \
 		test_bug392338.html \
 		test_bug399502.xhtml \
 		test_bug445330.html \
 		test_viewport.xhtml \
 		test_bug293347.html \
 		file_bug293347.xml \
 		file_bug293347xslt.xml \
 		test_bug691215.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/content/xslt/tests/mochitest/Makefile.in
+++ b/content/xslt/tests/mochitest/Makefile.in
@@ -5,28 +5,26 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = content/xslt/tests/mochitest
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = 	test_bug319374.xhtml \
+MOCHITEST_FILES = 	test_bug319374.xhtml \
 		test_bug440974.html \
 		test_bug427060.html \
 		test_bug468208.html \
 		test_bug453441.html \
 		test_bug511487.html \
 		test_bug551412.html \
 		test_bug551654.html \
 		test_bug566629.html \
 		test_bug566629.xhtml \
 		test_bug603159.html \
 		test_bug616774.html \
 		test_bug667315.html \
 		test_exslt_regex.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/content/xtf/src/nsXTFElementWrapper.cpp
+++ b/content/xtf/src/nsXTFElementWrapper.cpp
@@ -560,17 +560,17 @@ nsXTFElementWrapper::Clone(nsINodeInfo *
   nsCOMPtr<nsIContent> it;
   nsContentUtils::GetXTFService()->CreateElement(getter_AddRefs(it),
                                                  aNodeInfo);
   if (!it)
     return NS_ERROR_OUT_OF_MEMORY;
 
   nsXTFElementWrapper* wrapper =
     static_cast<nsXTFElementWrapper*>(it.get());
-  nsresult rv = CopyInnerTo(wrapper);
+  nsresult rv = const_cast<nsXTFElementWrapper*>(this)->CopyInnerTo(wrapper);
 
   if (NS_SUCCEEDED(rv)) {
     if (mAttributeHandler) {
       PRUint32 innerCount = 0;
       mAttributeHandler->GetAttributeCount(&innerCount);
       for (PRUint32 i = 0; i < innerCount; ++i) {
         nsCOMPtr<nsIAtom> attrName;
         mAttributeHandler->GetAttributeNameAt(i, getter_AddRefs(attrName));
--- a/content/xul/content/src/nsXULElement.cpp
+++ b/content/xul/content/src/nsXULElement.cpp
@@ -383,17 +383,17 @@ nsXULElement::Clone(nsINodeInfo *aNodeIn
 
     // XXX TODO: set up RDF generic builder n' stuff if there is a
     // 'datasources' attribute? This is really kind of tricky,
     // because then we'd need to -selectively- copy children that
     // -weren't- generated from RDF. Ugh. Forget it.
 
     // Note that we're _not_ copying mControllers.
 
-    nsresult rv = CopyInnerTo(element);
+    nsresult rv = const_cast<nsXULElement*>(this)->CopyInnerTo(element);
     if (NS_SUCCEEDED(rv)) {
         NS_ADDREF(*aResult = element);
     }
 
     return rv;
 }
 
 //----------------------------------------------------------------------
--- a/content/xul/content/test/Makefile.in
+++ b/content/xul/content/test/Makefile.in
@@ -5,26 +5,21 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = content/xul/content/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = 	\
+MOCHITEST_FILES = 	\
 		test_bug486990.xul \
 		test_bug749367.xul \
 		$(NULL)
 
-_CHROME_FILES = \
+MOCHITEST_CHROME_FILES = \
 		test_bug233643.xul \
- 		test_bug398289.html \
- 		398289-resource.xul \
- 		$(NULL)
+		test_bug398289.html \
+		398289-resource.xul \
+		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs:: $(_CHROME_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/content/xul/document/test/Makefile.in
+++ b/content/xul/document/test/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = content/xul/document/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_CHROME_FILES	= \
+MOCHITEST_CHROME_FILES	= \
 		test_bug311681.xul \
 		test_bug199692.xul \
 		test_bug391002.xul \
 		test_bug403868.xul \
 		test_bug414907.xul \
 		test_bug418216.xul \
 		test_bug445177.xul \
 		test_bug449457.xul \
@@ -28,10 +27,9 @@ include $(topsrcdir)/config/rules.mk
 		bug497875-iframe.xul \
 		test_bug335375.xul \
 		overlay1_bug335375.xul \
 		overlay2_bug335375.xul \
 		test_bug757137.xul \
 		window_bug757137.xul \
 		$(NULL)
 
-libs:: $(_CHROME_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/content/xul/templates/tests/chrome/Makefile.in
+++ b/content/xul/templates/tests/chrome/Makefile.in
@@ -5,22 +5,21 @@
 
 DEPTH		= ../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= content/xul/templates/tests/chrome
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
 # NOTE: it is important that the first test of the test_tmpl_* tests here use
 #       datasources="rdf:null" to ensure that the real animals.rdf datasource
 #       can be synchronously loaded before the tests run.
-_TEST_FILES = \
+MOCHITEST_CHROME_FILES = \
 		test_bug476634.xul \
 		templates_shared.js \
 		animals.rdf \
 		animals.xml \
 		animals.sqlite \
 		test_tmpl_bindingsextendedsyntax.xul \
 		test_tmpl_bindingsmultiple.xul \
 		test_tmpl_bindingsquerysyntax.xul \
@@ -228,10 +227,9 @@ include $(topsrcdir)/config/rules.mk
 		test_tmpl_errors.xul \
 		test_tmpl_regenerate.xul \
 		test_bug441785.xul \
 		bug441785-1.rdf \
 		bug441785-2.rdf \
 		test_sortservice.xul \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/docshell/test/Makefile.in
+++ b/docshell/test/Makefile.in
@@ -22,19 +22,17 @@ XPCSHELL_TESTS = unit
 ifneq ($(OS_ARCH),Darwin)
 XPCSHELL_TESTS += unit_ipc
 endif
 
 ifneq (mobile,$(MOZ_BUILD_APP))
 	DIRS += browser
 endif
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES = \
+MOCHITEST_FILES = \
 		test_bug94514.html \
 		bug94514-postpage.html \
 		test_bug123696.html \
 		bug123696-subframe.html \
 		test_bug344861.html \
 		test_bug369814.html \
 		bug369814.zip \
 		bug369814.jar \
@@ -98,16 +96,15 @@ include $(topsrcdir)/config/rules.mk
 		bug691547_frame.html \
 		test_bug694612.html \
 		test_bug713825.html \
 		test_bug728939.html \
 		file_bug728939.html \
 		$(NULL)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_bug511449.html \
 		file_bug511449.html \
 		$(NULL)
 endif
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/docshell/test/browser/Makefile.in
+++ b/docshell/test/browser/Makefile.in
@@ -4,19 +4,18 @@
 
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= docshell/test/browser 
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_BROWSER_TEST_FILES =	\
+MOCHITEST_BROWSER_FILES =	\
 		browser_bug92473.js \
 		test-form_sjis.html \
 		browser_bug134911.js \
 		browser_bug349769.js \
 		browser_bug388121-1.js \
 		browser_bug388121-2.js \
 		browser_bug435325.js \
 		browser_bug441169.js \
@@ -30,10 +29,9 @@ include $(topsrcdir)/config/rules.mk
 		browser_bug655270.js \
 		file_bug655270.html \
 		favicon_bug655270.ico \
 		browser_bug670318.js \
 		file_bug670318.html \
 		browser_bug673467.js \
 		$(NULL)
 
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/docshell/test/chrome/Makefile.in
+++ b/docshell/test/chrome/Makefile.in
@@ -4,36 +4,35 @@
 
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= docshell/test/chrome 
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_HTTP_FILES =	\
+MOCHITEST_FILES =	\
                 bug89419.sjs \
                 blue.png \
                 red.png \
 		92598_nostore.html \
 		92598_nostore.html^headers^ \
 		112564_nocache.html \
 		112564_nocache.html^headers^ \
 		215405_nostore.html \
 		215405_nostore.html^headers^ \
 		215405_nocache.html \
 		215405_nocache.html^headers^ \
 		582176_dummy.html \
 		582176_xml.xml \
 		582176_xslt.xsl \
 		$(NULL)
 
-_TEST_FILES =	\
+MOCHITEST_CHROME_FILES =	\
                 test_bug89419.xul \
                 bug89419_window.xul \
                 89419.html \
 		test_bug92598.xul \
 		bug92598_window.xul \
 		92598_nostore.html \
 		test_bug112564.xul \
 		bug112564_window.xul \
@@ -92,21 +91,14 @@ include $(topsrcdir)/config/rules.mk
 		bug690056_window.xul \
 		test_bug311007.xul \
 		bug311007_window.xul \
 		test_principalInherit.xul \
 		test_mozFrameType.xul \
 		mozFrameType_window.xul \
 		$(NULL)
 
-_DOCSHELL_SUBHARNESS = \
+MOCHITEST_CHROME_FILES += \
     docshell_helpers.js \
     generic.html \
     $(NULL)
 
-libs:: $(_HTTP_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
-
-libs:: $(_DOCSHELL_SUBHARNESS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/docshell/test/navigation/Makefile.in
+++ b/docshell/test/navigation/Makefile.in
@@ -6,25 +6,24 @@ DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = docshell/test/navigation
 
 MODULE = test_docshell
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
 		test_bug13871.html \
 		test_bug270414.html \
 		test_bug278916.html \
 		test_bug279495.html \
 		test_bug386782.html \
- 		test_bug430624.html \
+		test_bug430624.html \
 		test_bug430723.html \
 		test_child.html \
 		test_grandchild.html \
 		test_sibling-off-domain.html \
 		test_sibling-matching-parent.html \
 		test_opener.html \
 		test_not-opener.html \
 		test_popup-navigates-children.html \
@@ -46,26 +45,20 @@ include $(topsrcdir)/config/rules.mk
 		frame1.html \
 		frame2.html \
 		frame3.html \
 		goback.html \
 		file_bug534178.html \
 		$(NULL)
 
 ifneq (mobile,$(MOZ_BUILD_APP))
-_BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_FILES = \
 		browser_bug343515.js \
 		bug343515_pg1.html \
 		bug343515_pg2.html \
 		bug343515_pg3.html \
 		bug343515_pg3_1.html \
 		bug343515_pg3_2.html \
 		bug343515_pg3_1_1.html \
 		$(NULL)
 endif
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-ifneq (mobile,$(MOZ_BUILD_APP))
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
-endif
+include $(topsrcdir)/config/rules.mk
--- a/dom/alarm/test/Makefile.in
+++ b/dom/alarm/test/Makefile.in
@@ -9,17 +9,14 @@ VPATH            = @srcdir@
 
 relativesrcdir   = dom/alarm/test
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = \
   $(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES = \
+MOCHITEST_FILES = \
   test_alarm_permitted_app.html \
   test_alarm_non_permitted_app.html \
   $(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/apps/src/AppsService.js
+++ b/dom/apps/src/AppsService.js
@@ -23,16 +23,21 @@ function AppsService()
 }
 
 AppsService.prototype = {
   getAppByManifestURL: function getAppByManifestURL(aManifestURL) {
     debug("GetAppByManifestURL( " + aManifestURL + " )");
     return DOMApplicationRegistry.getAppByManifestURL(aManifestURL)
   },
 
+  getAppLocalIdByManifestURL: function getAppLocalIdByManifestURL(aManifestURL) {
+    debug("getAppLocalIdByManifestURL( " + aManifestURL + " )");
+    return DOMApplicationRegistry.getAppLocalIdByManifestURL(aManifestURL);
+  },
+
   classID : APPS_SERVICE_CID,
   QueryInterface : XPCOMUtils.generateQI([Ci.nsIAppsService]),
 
   classInfo : XPCOMUtils.generateCI({classID: APPS_SERVICE_CID,
                                      contractID: APPS_SERVICE_CONTRACTID,
                                      classDescription: "AppsService",
                                      interfaces: [Ci.nsIAppsService],
                                      flags: Ci.nsIClassInfo.DOM_OBJECT})
--- a/dom/apps/src/Webapps.jsm
+++ b/dom/apps/src/Webapps.jsm
@@ -55,21 +55,24 @@ let DOMApplicationRegistry = {
 
     Services.obs.addObserver(this, "xpcom-shutdown", false);
 
     this.appsFile = FileUtils.getFile(DIRECTORY_NAME, ["webapps", "webapps.json"], true);
 
     if (this.appsFile.exists()) {
       this._loadJSONAsync(this.appsFile, (function(aData) {
         this.webapps = aData;
+        for (let id in this.webapps) {
 #ifdef MOZ_SYS_MSG
-        for (let id in this.webapps) {
           this._registerSystemMessagesForId(id);
+#endif
+          if (!this.webapps[id].localId) {
+            this.webapps[id].localId = this._nextLocalId();
+          }
         };
-#endif
       }).bind(this));
     }
 
     try {
       let hosts = Services.prefs.getCharPref("dom.mozApps.whitelist");
       hosts.split(",").forEach(function(aHost) {
         Services.perms.add(Services.io.newURI(aHost, null, null), "webapps-manage",
                            Ci.nsIPermissionManager.ALLOW_ACTION);
@@ -207,33 +210,37 @@ let DOMApplicationRegistry = {
 
   denyInstall: function(aData) {
     ppmm.sendAsyncMessage("Webapps:Install:Return:KO", aData);
   },
 
   confirmInstall: function(aData, aFromSync, aProfileDir, aOfflineCacheObserver) {
     let app = aData.app;
     let id = app.syncId || this._appId(app.origin);
+    let localId = this.getAppLocalIdByManifestURL(app.manifestURL);
 
     // install an application again is considered as an update
     if (id) {
       let dir = FileUtils.getDir(DIRECTORY_NAME, ["webapps", id], true, true);
       try {
         dir.remove(true);
       } catch(e) {
       }
     } else {
       id = this.makeAppId();
+      localId = this._nextLocalId();
     }
 
     let appObject = this._cloneAppObject(app);
     appObject.installTime = app.installTime = Date.now();
     let appNote = JSON.stringify(appObject);
     appNote.id = id;
 
+    appObject.localId = localId;
+
     let dir = FileUtils.getDir(DIRECTORY_NAME, ["webapps", id], true, true);
     let manFile = dir.clone();
     manFile.append("manifest.webapp");
     this._writeFile(manFile, JSON.stringify(app.manifest));
     this.webapps[id] = appObject;
 
     appObject.status = "installed";
     
@@ -259,16 +266,27 @@ let DOMApplicationRegistry = {
                                     : updateService.scheduleUpdate(appcacheURI, docURI, null);
       cacheUpdate.addObserver(new AppcacheObserver(appObject), false);
       if (aOfflineCacheObserver) {
         cacheUpdate.addObserver(aOfflineCacheObserver, false);
       }
     }
   },
 
+  _nextLocalId: function() {
+    let maxLocalId = 0;
+    for (let id in this.webapps) {
+      if (this.webapps[id].localId > maxLocalId) {
+        maxLocalId = this.webapps[id].localId;
+      }
+    }
+
+    return maxLocalId + 1;
+  },
+
   _appId: function(aURI) {
     for (let id in this.webapps) {
       if (this.webapps[id].origin == aURI)
         return id;
     }
     return null;
   },
 
@@ -449,17 +467,27 @@ let DOMApplicationRegistry = {
       let app = this.webapps[id];
       if (app.manifestURL == aManifestURL) {
         return this._cloneAppObject(app);
       }
     }
 
     return null;
   },
-  
+
+  getAppLocalIdByManifestURL: function(aManifestURL) {
+    for (let id in this.webapps) {
+      if (this.webapps[id].manifestURL == aManifestURL) {
+        return this.webapps[id].localId;
+      }
+    }
+
+    return 0;
+  },
+
   getAllWithoutManifests: function(aCallback) {
     let result = {};
     for (let id in this.webapps) {
       let app = this._cloneAppObject(this.webapps[id]);
       result[id] = app;
     }
     aCallback(result);
   },
--- a/dom/apps/tests/Makefile.in
+++ b/dom/apps/tests/Makefile.in
@@ -9,26 +9,13 @@ VPATH            = @srcdir@
 
 relativesrcdir   = dom/apps/tests
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = \
   $(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES = \
-  $(NULL)
-
-_CHROME_TEST_FILES = \
+MOCHITEST_CHROME_FILES = \
   test_apps_service.xul \
   $(NULL)
 
-ifneq (,$(_TEST_FILES))
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-endif
-
-ifneq (,$(_CHROME_TEST_FILES))
-libs:: $(_CHROME_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
-endif
+include $(topsrcdir)/config/rules.mk
--- a/dom/base/test/Makefile.in
+++ b/dom/base/test/Makefile.in
@@ -4,29 +4,24 @@
 
 DEPTH = ../../..
 topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/base/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-TEST_FILES = \
+MOCHITEST_FILES = \
   test_domrequest.html \
   test_gsp-standards.html \
   test_gsp-quirks.html \
   test_nondomexception.html \
   test_screen_orientation.html \
   $(NULL)
 
-CHROME_TEST_FILES = \
+MOCHITEST_CHROME_FILES = \
    test_bug715041.xul \
    test_bug715041_removal.xul \
    $(NULL)
 
-libs:: $(TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
 
-libs:: $(CHROME_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
-
--- a/dom/battery/test/Makefile.in
+++ b/dom/battery/test/Makefile.in
@@ -9,22 +9,14 @@ VPATH            = @srcdir@
 
 relativesrcdir   = dom/battery/test
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = \
   $(NULL)
 
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
   test_battery_basics.html \
   $(NULL)
 
-_CHROME_TEST_FILES = \
-  $(NULL)
-
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-#libs:: $(_CHROME_TEST_FILES)
-#	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/bindings/test/Makefile.in
+++ b/dom/bindings/test/Makefile.in
@@ -29,17 +29,16 @@ test_webidl_files := $(addprefix ../,$(t
 CPPSRCS := $(subst .webidl,Binding.cpp,$(test_webidl_files))
 
 LOCAL_INCLUDES += \
   -I$(topsrcdir)/js/xpconnect/src \
   -I$(topsrcdir)/js/xpconnect/wrappers \
   -I$(topsrcdir)/dom/bindings \
   $(NULL)
 
-include $(topsrcdir)/config/rules.mk
 
 # If you change bindinggen_dependencies here, change it in
 # dom/bindings/Makefile.in too.  But note that we include ../Makefile
 # here manually, since $(GLOBAL_DEPS) won't cover it.
 bindinggen_dependencies := \
   ../BindingGen.py \
   ../Bindings.conf \
   ../Configuration.py \
@@ -51,28 +50,27 @@ bindinggen_dependencies := \
   $(NULL)
 
 $(CPPSRCS): ../%Binding.cpp: $(bindinggen_dependencies) \
                              ../%.webidl \
                              $(NULL)
 	$(MAKE) -C .. $*Binding.h
 	$(MAKE) -C .. $*Binding.cpp
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
   test_enums.html \
   test_integers.html \
   test_interfaceToString.html \
   test_lookupGetter.html \
   test_InstanceOf.html \
   test_traceProtos.html \
   $(NULL)
 
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
 
 check::
 	PYTHONDONTWRITEBYTECODE=1 $(PYTHON) $(topsrcdir)/config/pythonpath.py \
 	  $(PLY_INCLUDE) $(srcdir)/../parser/runtests.py
 
 check-interactive:
 	PYTHONDONTWRITEBYTECODE=1 $(PYTHON) $(topsrcdir)/config/pythonpath.py \
 	  $(PLY_INCLUDE) $(srcdir)/../parser/runtests.py -q
--- a/dom/browser-element/mochitest/Makefile.in
+++ b/dom/browser-element/mochitest/Makefile.in
@@ -5,23 +5,22 @@
 
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = dom/browser-element/mochitest
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
 # Note: browserElementTestHelpers.js looks at the test's filename to determine
 # whether the test should be OOP.  "_oop_" signals OOP, "_inproc_" signals in
 # process.  Default is OOP.
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
 		file_empty_script.js \
 		file_empty.html \
 		file_focus.html \
 		browserElementTestHelpers.js \
 		test_browserElement_NoAttr.html \
 		test_browserElement_NoPref.html \
 		test_browserElement_NoWhitelist.html \
 		browserElement_LoadEvents.js \
@@ -71,17 +70,17 @@ include $(topsrcdir)/config/rules.mk
                 browserElement_ContextmenuEvents.js \
                 test_browserElement_inproc_ContextmenuEvents.html \
 		$(NULL)
 
 # OOP tests don't work on Windows (bug 763081).
 #
 # Note that there's no inproc equivalent of BackForward; that's intentional.
 ifneq ($(OS_ARCH),WINNT)
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_browserElement_oop_LoadEvents.html \
 		test_browserElement_oop_DataURI.html \
 		test_browserElement_oop_ErrorSecurity.html \
 		test_browserElement_oop_Titlechange.html \
 		test_browserElement_oop_TopBarrier.html \
 		test_browserElement_oop_Iconchange.html \
 		test_browserElement_oop_GetScreenshot.html \
 		test_browserElement_oop_SetVisible.html \
@@ -96,10 +95,9 @@ ifneq ($(OS_ARCH),WINNT)
 		test_browserElement_oop_OpenWindowRejected.html \
 		test_browserElement_oop_SecurityChange.html \
 		test_browserElement_oop_BackForward.html \
                 test_browserElement_oop_ContextmenuEvents.html \
 		$(NULL)
 endif
 
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/createNewTest.py
@@ -0,0 +1,121 @@
+"""A script to generate the browser-element test boilerplate.
+
+This script requires Python 2.7."""
+
+from __future__ import print_function
+
+import sys
+import os
+import stat
+import argparse
+import textwrap
+import subprocess
+
+html_template = textwrap.dedent("""\
+    <!DOCTYPE HTML>
+    <html>
+    <head>
+      <title>Test for Bug {bug}</title>
+      <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+      <script type="application/javascript" src="browserElementTestHelpers.js"></script>
+      <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+    </head>
+    <body>
+    <script type="application/javascript;version=1.7" src="browserElement_{test}.js">
+    </script>
+    </body>
+    </html>""")
+
+# Note: Curly braces are escaped as "{{".
+js_template = textwrap.dedent("""\
+    /* Any copyright is dedicated to the public domain.
+       http://creativecommons.org/publicdomain/zero/1.0/ */
+
+    // Bug {bug} - FILL IN TEST DESCRIPTION
+    "use strict";
+
+    SimpleTest.waitForExplicitFinish();
+
+    function runTest() {{
+      browserElementTestHelpers.setEnabledPref(true);
+      browserElementTestHelpers.addToWhitelist();
+
+      var iframe = document.createElement('iframe');
+      iframe.mozbrowser = true;
+
+      // FILL IN TEST
+
+      document.body.appendChild(iframe);
+    }}
+
+    runTest();""")
+
+def print_fill(s):
+    print(textwrap.fill(textwrap.dedent(s)))
+
+def add_to_makefile(filenames):
+    """Add a list of filenames to this directory's Makefile.in, then open
+    $EDITOR and let the user move the filenames to their appropriate places in
+    the file.
+
+    """
+    lines_to_write = ['', '# MOVE THESE:'] + [n + ' \\' for n in filenames]
+    with open('Makefile.in', 'a') as f:
+        f.write('\n'.join(lines_to_write))
+
+    if 'EDITOR' not in os.environ or not os.environ['EDITOR']:
+        print_fill("""\
+            Now open Makefile.in and move the filenames to their correct places.")
+            (Define $EDITOR and I'll open your editor for you next time.)""")
+        return
+
+    # Count the number of lines in Makefile.in.
+    with open('Makefile.in', 'r') as f:
+        num_lines = len(f.readlines())
+
+    try:
+        subprocess.call([os.environ['EDITOR'],
+                         '+%d' % (num_lines - len(lines_to_write) + 2),
+                         'Makefile.in'])
+    except Exception as e:
+        print_fill("Error opening $EDITOR: %s." % str(e))
+        print()
+        print_fill("""\
+            Please open Makefile.in and move the filenames at the bottom of the
+            file to their correct places.""")
+
+def main(test_name, bug_number):
+    global html_template, js_template
+
+    def format(str):
+        return str.format(bug=bug_number, test=test_name)
+
+    def create_file(filename, template):
+        path = os.path.join(os.path.dirname(sys.argv[0]), format(filename))
+        # Create a new file, bailing with an error if the file exists.
+        fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL)
+
+        try:
+            # This file has 777 permission when created, for whatever reason.  Make it rw-rw-r---.
+            os.fchmod(fd, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH)
+        except:
+            # fchmod doesn't work on Windows.
+            pass
+
+        with os.fdopen(fd, 'w') as file:
+            file.write(format(template))
+
+    create_file('browserElement_{test}.js', js_template)
+    create_file('test_browserElement_inproc_{test}.html', html_template)
+    create_file('test_browserElement_oop_{test}.html', html_template)
+
+    add_to_makefile([format(x) for x in ['browserElement_{test}.js',
+                                         'test_browserElement_inproc_{test}.html',
+                                         'test_browserElement_oop_{test}.html']])
+
+if __name__ == '__main__':
+    parser = argparse.ArgumentParser(description="Create a new browser-element testcase.")
+    parser.add_argument('test_name')
+    parser.add_argument('bug_number', type=int)
+    args = parser.parse_args()
+    main(args.test_name, args.bug_number)
--- a/dom/contacts/tests/Makefile.in
+++ b/dom/contacts/tests/Makefile.in
@@ -9,20 +9,14 @@ VPATH            = @srcdir@
 
 relativesrcdir   = dom/contacts/tests
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = \
   $(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES = \
+MOCHITEST_FILES = \
   test_contacts_basics.html \
   $(NULL)
 
-_CHROME_TEST_FILES = \
-  $(NULL)
+include $(topsrcdir)/config/rules.mk
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
--- a/dom/devicestorage/test/Makefile.in
+++ b/dom/devicestorage/test/Makefile.in
@@ -5,25 +5,21 @@
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/devicestorage/test/
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 		test_sanity.html \
 		test_basic.html \
 		test_enumerate.html \
 		test_enumerateMultipleContinue.html \
 		test_overwrite.html \
 		test_dotdot.html \
 		test_enumerateOptions.html \
 		test_lastModificationFilter.html \
 		devicestorage_common.js \
 		$(NULL)
 
-libs:: 	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
+include $(topsrcdir)/config/rules.mk
--- a/dom/file/test/Makefile.in
+++ b/dom/file/test/Makefile.in
@@ -5,19 +5,18 @@
 DEPTH            = ../../..
 topsrcdir        = @top_srcdir@
 srcdir           = @srcdir@
 VPATH            = @srcdir@
 relativesrcdir   = dom/file/test
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
 
-TEST_FILES = \
+MOCHITEST_FILES = \
   helpers.js \
   test_append_read_data.html \
   test_getFileId.html \
   test_location.html \
   test_lockedfile_lifetimes.html \
   test_lockedfile_lifetimes_nested.html \
   test_lockedfile_ordering.html \
   test_overlapping_lockedfiles.html \
@@ -25,10 +24,9 @@ TEST_FILES = \
   test_readonly_lockedfiles.html \
   test_request_readyState.html \
   test_stream_tracking.html \
   test_success_events_after_abort.html \
   test_truncate.html \
   test_write_read_data.html \
   $(NULL)
 
-libs:: $(TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/editing/Makefile.in
+++ b/dom/imptests/editing/Makefile.in
@@ -9,20 +9,18 @@ relativesrcdir = dom/imptests/editing
 
 DIRS = \
   css \
   conformancetest \
   selecttest \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   $(NULL)
 
-_TESTS += \
+MOCHITEST_FILES += \
   implementation.js \
   tests.js \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/editing/conformancetest/Makefile.in
+++ b/dom/imptests/editing/conformancetest/Makefile.in
@@ -6,21 +6,19 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/editing/conformancetest
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   test_runtest.html \
   test_event.html \
   $(NULL)
 
-_TESTS += \
+MOCHITEST_FILES += \
   data.js \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/editing/css/Makefile.in
+++ b/dom/imptests/editing/css/Makefile.in
@@ -6,19 +6,17 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/editing/css
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   $(NULL)
 
-_TESTS += \
+MOCHITEST_FILES += \
   reset.css \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/editing/selecttest/Makefile.in
+++ b/dom/imptests/editing/selecttest/Makefile.in
@@ -6,32 +6,30 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/editing/selecttest
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   test_addRange.html \
   test_collapse.html \
   test_collapseToStartEnd.html \
   test_deleteFromDocument.html \
   test_Document-open.html \
   test_extend.html \
   test_getRangeAt.html \
   test_getSelection.html \
   test_interfaces.html \
   test_isCollapsed.html \
   test_removeAllRanges.html \
   test_selectAllChildren.html \
   $(NULL)
 
-_TESTS += \
+MOCHITEST_FILES += \
   common.js \
   test-iframe.html \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/failures/editing/conformancetest/Makefile.in
+++ b/dom/imptests/failures/editing/conformancetest/Makefile.in
@@ -4,17 +4,15 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/failures/editing/conformancetest
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   test_event.html.json \
   test_runtest.html.json \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/failures/editing/selecttest/Makefile.in
+++ b/dom/imptests/failures/editing/selecttest/Makefile.in
@@ -4,19 +4,17 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/failures/editing/selecttest
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   test_addRange.html.json \
   test_Document-open.html.json \
   test_getSelection.html.json \
   test_interfaces.html.json \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/failures/html/tests/submission/Opera/microdata/Makefile.in
+++ b/dom/imptests/failures/html/tests/submission/Opera/microdata/Makefile.in
@@ -4,16 +4,14 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/failures/html/tests/submission/Opera/microdata 
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   test_001.html.json \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/failures/webapps/DOMCore/tests/approved/Makefile.in
+++ b/dom/imptests/failures/webapps/DOMCore/tests/approved/Makefile.in
@@ -4,27 +4,25 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/failures/webapps/DOMCore/tests/approved
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   test_Range-cloneContents.html.json \
   test_Range-cloneRange.html.json \
   test_Range-collapse.html.json \
   test_Range-commonAncestorContainer.html.json \
   test_Range-compareBoundaryPoints.html.json \
   test_Range-comparePoint.html.json \
   test_Range-deleteContents.html.json \
   test_Range-extractContents.html.json \
   test_Range-intersectsNode.html.json \
   test_Range-isPointInRange.html.json \
   test_Range-set.html.json \
   test_interfaces.html.json \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/failures/webapps/DOMCore/tests/submissions/Opera/Makefile.in
+++ b/dom/imptests/failures/webapps/DOMCore/tests/submissions/Opera/Makefile.in
@@ -4,17 +4,15 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/failures/webapps/DOMCore/tests/submissions/Opera
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   test_getElementsByClassName-10.xml.json \
   test_getElementsByClassName-11.xml.json \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/failures/webapps/WebStorage/tests/submissions/Infraware/Makefile.in
+++ b/dom/imptests/failures/webapps/WebStorage/tests/submissions/Infraware/Makefile.in
@@ -4,16 +4,14 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/failures/webapps/WebStorage/tests/submissions/Infraware
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   test_storage_local_security.html.json \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/failures/webapps/WebStorage/tests/submissions/Ms2ger/Makefile.in
+++ b/dom/imptests/failures/webapps/WebStorage/tests/submissions/Ms2ger/Makefile.in
@@ -4,20 +4,18 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/failures/webapps/WebStorage/tests/submissions/Ms2ger
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   test_missing_arguments.html.json \
   test_storage_local_in_js.html.json \
   test_storage_local_removeitem_js.html.json \
   test_storage_session_in_js.html.json \
   test_storage_session_removeitem_js.html.json \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/failures/webapps/XMLHttpRequest/tests/submissions/Ms2ger/Makefile.in
+++ b/dom/imptests/failures/webapps/XMLHttpRequest/tests/submissions/Ms2ger/Makefile.in
@@ -4,17 +4,15 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/failures/webapps/XMLHttpRequest/tests/submissions/Ms2ger
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   test_interfaces.html.json \
   test_setrequestheader-invalid-arguments.htm.json \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/html/tests/submission/Mozilla/Makefile.in
+++ b/dom/imptests/html/tests/submission/Mozilla/Makefile.in
@@ -6,26 +6,24 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/html/tests/submission/Mozilla
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   test_body-onload.html \
   test_pageload-image.html \
   test_pageload-video.html \
   test_script-for-onload.html \
   test_window-onerror-parse-error.html \
   test_window-onerror-runtime-error.html \
   test_window-onerror-runtime-error-throw.html \
   $(NULL)
 
-_TESTS += \
+MOCHITEST_FILES += \
   nested-document-write-external.js \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/html/tests/submission/Opera/microdata/Makefile.in
+++ b/dom/imptests/html/tests/submission/Opera/microdata/Makefile.in
@@ -6,19 +6,17 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/html/tests/submission/Opera/microdata
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   test_001.html \
   $(NULL)
 
-_TESTS += \
+MOCHITEST_FILES += \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/webapps/DOMCore/tests/approved/Makefile.in
+++ b/dom/imptests/webapps/DOMCore/tests/approved/Makefile.in
@@ -6,19 +6,18 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/webapps/DOMCore/tests/approved
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   test_interfaces.html \
   test_Range-cloneContents.html \
   test_Range-cloneRange.html \
   test_Range-collapse.html \
   test_Range-commonAncestorContainer.html \
   test_Range-compareBoundaryPoints.html \
   test_Range-comparePoint.html \
   test_Range-deleteContents.html \
@@ -27,15 +26,14 @@ include $(topsrcdir)/config/rules.mk
   test_Range-intersectsNode.html \
   test_Range-isPointInRange.html \
   test_Range-mutations.html \
   test_Range-selectNode.html \
   test_Range-set.html \
   test_Range-surroundContents.html \
   $(NULL)
 
-_TESTS += \
+MOCHITEST_FILES += \
   common.js \
   Range-test-iframe.html \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/webapps/DOMCore/tests/submissions/Opera/Makefile.in
+++ b/dom/imptests/webapps/DOMCore/tests/submissions/Opera/Makefile.in
@@ -6,19 +6,18 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/webapps/DOMCore/tests/submissions/Opera
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   test_getElementsByClassName-01.htm \
   test_getElementsByClassName-02.htm \
   test_getElementsByClassName-03.htm \
   test_getElementsByClassName-04.htm \
   test_getElementsByClassName-05.htm \
   test_getElementsByClassName-06.htm \
   test_getElementsByClassName-07.htm \
   test_getElementsByClassName-08.htm \
@@ -29,13 +28,12 @@ include $(topsrcdir)/config/rules.mk
   test_getElementsByClassName-13.htm \
   test_getElementsByClassName-14.htm \
   test_getElementsByClassName-15.htm \
   test_getElementsByClassName-16.htm \
   test_getElementsByClassName-17.htm \
   test_getElementsByClassName-18.htm \
   $(NULL)
 
-_TESTS += \
+MOCHITEST_FILES += \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/webapps/WebStorage/tests/submissions/Infraware/Makefile.in
+++ b/dom/imptests/webapps/WebStorage/tests/submissions/Infraware/Makefile.in
@@ -7,19 +7,18 @@ srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/webapps/WebStorage/tests/submissions/Infraware
 
 DIRS = \
   iframe \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   test_event_constructor.html \
   test_event_local_key.html \
   test_event_local_newvalue.html \
   test_event_local_oldvalue.html \
   test_event_local_storagearea.html \
   test_event_local_storageeventinit.html \
   test_event_local_url.html \
   test_event_session_key.html \
@@ -38,13 +37,12 @@ include $(topsrcdir)/config/rules.mk
   test_storage_session_clear.html \
   test_storage_session_getitem.html \
   test_storage_session_key.html \
   test_storage_session_length.html \
   test_storage_session_removeitem.html \
   test_storage_session_setitem.html \
   $(NULL)
 
-_TESTS += \
+MOCHITEST_FILES += \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/webapps/WebStorage/tests/submissions/Infraware/iframe/Makefile.in
+++ b/dom/imptests/webapps/WebStorage/tests/submissions/Infraware/iframe/Makefile.in
@@ -6,25 +6,23 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/webapps/WebStorage/tests/submissions/Infraware/iframe
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   $(NULL)
 
-_TESTS += \
+MOCHITEST_FILES += \
   local_change_item_iframe.html \
   local_security_iframe.html \
   local_set_item_clear_iframe.html \
   local_set_item_iframe.html \
   session_change_item_iframe.html \
   session_set_item_clear_iframe.html \
   session_set_item_iframe.html \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/webapps/WebStorage/tests/submissions/Ms2ger/Makefile.in
+++ b/dom/imptests/webapps/WebStorage/tests/submissions/Ms2ger/Makefile.in
@@ -6,19 +6,18 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/webapps/WebStorage/tests/submissions/Ms2ger
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   test_event_constructor_js.html \
   test_missing_arguments.html \
   test_storage_local_clear_js.html \
   test_storage_local_getitem_js.html \
   test_storage_local_index_js.html \
   test_storage_local_in_js.html \
   test_storage_local_length_js.html \
   test_storage_local_removeitem_js.html \
@@ -27,13 +26,12 @@ include $(topsrcdir)/config/rules.mk
   test_storage_session_getitem_js.html \
   test_storage_session_index_js.html \
   test_storage_session_in_js.html \
   test_storage_session_length_js.html \
   test_storage_session_removeitem_js.html \
   test_storage_session_setitem_js.html \
   $(NULL)
 
-_TESTS += \
+MOCHITEST_FILES += \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/imptests/webapps/XMLHttpRequest/tests/submissions/Ms2ger/Makefile.in
+++ b/dom/imptests/webapps/XMLHttpRequest/tests/submissions/Ms2ger/Makefile.in
@@ -6,20 +6,18 @@ topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/imptests/webapps/XMLHttpRequest/tests/submissions/Ms2ger
 
 DIRS = \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TESTS = \
+MOCHITEST_FILES = \
   test_interfaces.html \
   test_setrequestheader-invalid-arguments.htm \
   $(NULL)
 
-_TESTS += \
+MOCHITEST_FILES += \
   $(NULL)
 
-libs:: $(_TESTS)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/indexedDB/ipc/Makefile.in
+++ b/dom/indexedDB/ipc/Makefile.in
@@ -26,19 +26,15 @@ EXPORTS_mozilla/dom/indexedDB = Serializ
 
 LOCAL_INCLUDES += \
   -I$(topsrcdir)/dom/indexedDB \
   -I$(topsrcdir)/content/events/src \
   $(NULL)
 
 DEFINES += -D_IMPL_NS_LAYOUT
 
-TEST_FILES = \
+MOCHITEST_FILES = \
   test_ipc.html \
   $(NULL)
 
 include $(topsrcdir)/config/config.mk
 include $(topsrcdir)/ipc/chromium/chromium-config.mk
 include $(topsrcdir)/config/rules.mk
-
-libs:: $(TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") \
-    $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
--- a/dom/indexedDB/test/Makefile.in
+++ b/dom/indexedDB/test/Makefile.in
@@ -8,19 +8,17 @@ srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/indexedDB/test
 DIRS += unit
 
 include $(DEPTH)/config/autoconf.mk
 
 XPCSHELL_TESTS = unit
 
-include $(topsrcdir)/config/rules.mk
-
-TEST_FILES = \
+MOCHITEST_FILES = \
   bfcache_iframe1.html \
   bfcache_iframe2.html \
   error_events_abort_transactions_iframe.html \
   event_propagation_iframe.html \
   exceptions_in_events_iframe.html \
   file.js \
   helpers.js \
   leaving_page_iframe.html \
@@ -101,17 +99,17 @@ TEST_FILES = \
   test_unique_index_update.html \
   third_party_iframe1.html \
   third_party_iframe2.html \
   $(NULL)
 
 #   test_writer_starvation.html  disabled for infinite loops, bug 595368
 
 ifeq (browser,$(MOZ_BUILD_APP))
-BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_FILES = \
   browser_forgetThisSite.js \
   browser_forgetThisSiteAdd.html \
   browser_forgetThisSiteGet.html \
   browserHelpers.js \
   browser_permissionsPrompt.html \
   browser_permissionsPromptAllow.js \
   browser_permissionsPromptDeny.js \
   browser_privateBrowsing.js \
@@ -119,16 +117,12 @@ BROWSER_TEST_FILES = \
   browser_quotaPromptAllow.js \
   browser_quotaPromptDeny.js \
   browser_quotaPromptDatabases.html \
   browser_quotaPromptDatabases.js \
   browser_quotaPromptDelete.html \
   browser_quotaPromptDelete.js \
   head.js \
   $(NULL)
-
-libs:: $(BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
 endif
 
-libs:: $(TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
 
--- a/dom/indexedDB/test/unit/Makefile.in
+++ b/dom/indexedDB/test/unit/Makefile.in
@@ -4,19 +4,18 @@
 
 DEPTH = ../../../..
 topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 relativesrcdir = dom/indexedDB/test/unit
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-TEST_FILES = \
+MOCHITEST_FILES = \
   test_add_put.js \
   test_add_twice_failure.js \
   test_advance.js \
   test_autoIncrement_indexes.js \
   test_clear.js \
   test_complex_keyPaths.js \
   test_count.js \
   test_create_index.js \
@@ -61,11 +60,10 @@ TEST_FILES = \
   test_success_events_after_abort.js \
   test_traffic_jam.js \
   test_transaction_abort.js \
   test_transaction_lifetimes.js \
   test_transaction_lifetimes_nested.js \
   test_transaction_ordering.js \
   $(NULL)
 
-libs:: $(TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
 
--- a/dom/interfaces/apps/nsIAppsService.idl
+++ b/dom/interfaces/apps/nsIAppsService.idl
@@ -10,13 +10,14 @@ interface mozIDOMApplication;
 #define APPS_SERVICE_CID { 0x05072afa, 0x92fe, 0x45bf, { 0xae, 0x22, 0x39, 0xb6, 0x9c, 0x11, 0x70, 0x58 } }
 #define APPS_SERVICE_CONTRACTID "@mozilla.org/AppsService;1"
 %}
 
 /*
  * This service allows accessing some DOMApplicationRegistry methods from
  * non-javascript code.
  */
-[scriptable, uuid(8a4d9921-58ae-41da-a6f1-5f842c3a050f)]
+[scriptable, uuid(40e580e7-8891-4eb8-b514-0b5796af4df1)]
 interface nsIAppsService : nsISupports
 {
   mozIDOMApplication getAppByManifestURL(in DOMString manifestURL);
+  unsigned long getAppLocalIdByManifestURL(in DOMString manifestURL);
 };
--- a/dom/ipc/tests/Makefile.in
+++ b/dom/ipc/tests/Makefile.in
@@ -4,18 +4,16 @@
 
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = dom/ipc/tests
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-MOCHICHROME_FILES = \
+MOCHITEST_CHROME_FILES = \
   test_process_error.xul \
   process_error.xul \
   process_error_contentscript.js \
   $(NULL)
 
-libs:: $(MOCHICHROME_FILES)
-	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/network/tests/Makefile.in
+++ b/dom/network/tests/Makefile.in
@@ -9,22 +9,13 @@ VPATH            = @srcdir@
 
 relativesrcdir   = dom/network/tests
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = \
   $(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES = \
+MOCHITEST_FILES = \
   test_network_basics.html \
   $(NULL)
 
-_CHROME_TEST_FILES = \
-  $(NULL)
-
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-#libs:: $(_CHROME_TEST_FILES)
-#	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/plugins/test/mochitest/Makefile.in
+++ b/dom/plugins/test/mochitest/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = dom/plugins/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_MOCHITEST_FILES = \
+MOCHITEST_FILES = \
   utils.js \
   test_defaultValue.html \
   test_getauthenticationinfo.html \
   test_npobject_getters.html \
   test_npruntime_npnevaluate.html \
   test_npruntime_npninvoke.html \
   test_npruntime_npninvokedefault.html \
   test_npruntime_identifiers.html \
@@ -81,73 +80,69 @@ include $(topsrcdir)/config/rules.mk
   test_pluginstream_src_referer.html \
   plugin-stream-referer.sjs \
   test_src_url_change.html \
   $(NULL)
 
 #  test_plugin_scroll_painting.html \ bug 596491
 
 ifeq ($(OS_ARCH),WINNT)
-_MOCHITEST_FILES += \
+MOCHITEST_FILES += \
   test_windowed_invalidate.html \
   $(NULL)
 
 # test_positioning.html \ disabled due to oddness, perhaps scrolling of the
 # mochitest window?
 endif
 
-_MOCHICHROME_FILES = \
+MOCHITEST_CHROME_FILES = \
   utils.js \
   test_clear_site_data.html \
   test_npruntime.xul   \
   test_privatemode.xul \
   test_wmode.xul \
   test_bug479979.xul \
   $(NULL)
 
 ifneq ($(MOZ_WIDGET_TOOLKIT),cocoa)
-_MOCHITEST_FILES += \
+MOCHITEST_FILES += \
   test_instance_re-parent-windowed.html \
   test_visibility.html \
   $(NULL)
 
 ifneq ($(OS_ARCH),WINNT)
-_MOCHICHROME_FILES += \
+MOCHITEST_CHROME_FILES += \
   test_xulbrowser_plugin_visibility.xul \
   xulbrowser_plugin_visibility.xul \
   plugin_visibility_loader.html \
   $(NULL)
 endif
 endif
 
 ifdef MOZ_CRASHREPORTER
-_MOCHICHROME_FILES += \
+MOCHITEST_CHROME_FILES += \
   test_crash_notify.xul \
   test_crash_notify_no_report.xul \
   test_crash_submit.xul \
   $(NULL)
 endif
 
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
-_MOCHICHROME_FILES += \
+MOCHITEST_CHROME_FILES += \
   test_convertpoint.xul \
   $(NULL)
 
-_MOCHITEST_FILES += \
+MOCHITEST_FILES += \
   test_cocoa_window_focus.html \
   cocoa_window_focus.html \
   test_cocoa_focus.html \
   cocoa_focus.html \
   $(NULL)
 endif
 
 ifeq (gtk2,$(MOZ_WIDGET_TOOLKIT))
-_MOCHITEST_FILES += \
+MOCHITEST_FILES += \
 		test_copyText.html \
 		test_crash_nested_loop.html \
 		$(NULL)
 endif
 
-libs:: $(_MOCHICHROME_FILES)
-	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
-
-libs:: $(_MOCHITEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/power/test/Makefile.in
+++ b/dom/power/test/Makefile.in
@@ -9,26 +9,17 @@ VPATH            = @srcdir@
 
 relativesrcdir   = dom/power/test
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = \
   $(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES = \
+MOCHITEST_FILES = \
   test_power_basics.html \
   $(NULL)
 
-_BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_FILES = \
   browser_bug697132.js \
   $(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
-
-#libs:: $(_CHROME_TEST_FILES)
-#	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/settings/tests/Makefile.in
+++ b/dom/settings/tests/Makefile.in
@@ -6,20 +6,18 @@ DEPTH            = ../../..
 topsrcdir        = @top_srcdir@
 srcdir           = @srcdir@
 VPATH            = @srcdir@
 
 relativesrcdir   = dom/settings/tests
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
   test_settings_basics.html \
   test_settings_events.html \
   $(NULL)
 
-_CHROME_TEST_FILES = \
+_CHROMEMOCHITEST_FILES = \
   $(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/sms/tests/Makefile.in
+++ b/dom/sms/tests/Makefile.in
@@ -9,31 +9,20 @@ VPATH            = @srcdir@
 
 relativesrcdir   = dom/sms/tests
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = \
   $(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES = \
+MOCHITEST_FILES = \
   test_sms_basics.html \
   test_smsfilter.html \
   $(NULL)
 
-_CHROME_TEST_FILES = \
-  $(NULL)
-
 ifdef MOZ_B2G_RIL
-_CHROME_TEST_FILES += \
+MOCHITEST_CHROME_FILES = \
   test_smsdatabaseservice.xul \
   $(NULL)
 endif
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-ifneq (,$(_CHROME_TEST_FILES))
-libs:: $(_CHROME_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
-endif
+include $(topsrcdir)/config/rules.mk
--- a/dom/src/foo/Makefile.in
+++ b/dom/src/foo/Makefile.in
@@ -6,16 +6,13 @@ DEPTH            = ../../..
 topsrcdir        = @top_srcdir@
 srcdir           = @srcdir@
 VPATH            = @srcdir@
 
 relativesrcdir   = dom/src/foo
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES = \
+MOCHITEST_FILES = \
   test_foo.html \
   $(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/src/json/test/Makefile.in
+++ b/dom/src/json/test/Makefile.in
@@ -10,16 +10,13 @@ VPATH          = @srcdir@
 relativesrcdir  = dom/src/json/test
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE         = json_test
 
 XPCSHELL_TESTS = unit
 
+ MOCHITEST_FILES =	test_json.html \
+		$(NULL)
+
 include $(topsrcdir)/config/rules.mk
 
- _TEST_FILES =	test_json.html \
-		$(NULL)
-
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
--- a/dom/src/jsurl/test/Makefile.in
+++ b/dom/src/jsurl/test/Makefile.in
@@ -5,26 +5,24 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = dom/src/jsurl/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = 	pass.html \
+MOCHITEST_FILES = 	pass.html \
 		fail.html \
 		test_bug351633-1.html \
 		form-submit.html \
 		test_bug351633-2.html \
 		load-stopping-1a.html \
 		load-stopping-1b.html \
 		load-stopping-1c.html \
 		load-stopping-1d.html \
 		test_bug351633-3.html \
 		test_bug351633-4.html \
 		test_bug384981.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/system/tests/Makefile.in
+++ b/dom/system/tests/Makefile.in
@@ -1,16 +1,13 @@
 DEPTH           = ../../..
 topsrcdir       = @top_srcdir@
 srcdir          = @srcdir@
 VPATH           = @srcdir@
 relativesrcdir  = dom/system/tests
 
 MODULE          = test_domsystem
-_CHROME_TEST_FILES = \
+MOCHITEST_CHROME_FILES = \
 	test_constants.xul \
 	worker_constants.js \
         $(NULL)
 
 include $(topsrcdir)/config/rules.mk
-
-libs:: $(_CHROME_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
--- a/dom/tests/mochitest/ajax/jquery/Makefile.in
+++ b/dom/tests/mochitest/ajax/jquery/Makefile.in
@@ -11,17 +11,14 @@ relativesrcdir	= dom/tests/mochitest/aja
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS	= \
 	dist \
 	test \
 	$(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 	manifest.json \
 	test_jQuery.html \
 	$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/jquery/dist/Makefile.in
+++ b/dom/tests/mochitest/ajax/jquery/dist/Makefile.in
@@ -9,16 +9,13 @@ srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/jquery/dist
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS	= \
 	$(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 	jquery.js \
 	$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/jquery/test/Makefile.in
+++ b/dom/tests/mochitest/ajax/jquery/test/Makefile.in
@@ -11,19 +11,16 @@ relativesrcdir	= dom/tests/mochitest/aja
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS	= \
 	data \
 	unit \
 	$(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 	index.html \
 	offset.html \
 	test.js \
 	fix.html \
 	$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/jquery/test/data/Makefile.in
+++ b/dom/tests/mochitest/ajax/jquery/test/data/Makefile.in
@@ -10,28 +10,25 @@ VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/jquery/test/data
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS	= \
 	offset \
 	$(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 	cow.jpg \
 	dashboard.xml \
 	iframe.html \
 	json_assigned_obj.js \
 	json_obj.js \
 	name.html \
 	test.html \
 	test.js \
 	test2.html \
 	test3.html \
 	testrunner.js \
 	testsuite.css \
 	with_fries.xml \
 	$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/jquery/test/data/offset/Makefile.in
+++ b/dom/tests/mochitest/ajax/jquery/test/data/offset/Makefile.in
@@ -9,21 +9,18 @@ srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/jquery/test/data/offset
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS	= \
 	$(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 	absolute.html \
 	fixed.html \
 	relative.html \
 	scroll.html \
 	static.html \
 	table.html \
 	$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/jquery/test/unit/Makefile.in
+++ b/dom/tests/mochitest/ajax/jquery/test/unit/Makefile.in
@@ -9,22 +9,19 @@ srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/jquery/test/unit
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS	= \
 	$(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 	ajax.js \
 	core.js \
 	dimensions.js \
 	event.js \
 	fx.js \
 	offset.js \
 	selector.js \
 	$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/lib/Makefile.in
+++ b/dom/tests/mochitest/ajax/lib/Makefile.in
@@ -5,17 +5,15 @@
 
 DEPTH		= ../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/lib
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 		AJAX_setup.js \
 		test.css \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/mochikit/Makefile.in
+++ b/dom/tests/mochitest/ajax/mochikit/Makefile.in
@@ -11,17 +11,14 @@ relativesrcdir	= dom/tests/mochitest/aja
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS	= \
 	MochiKit \
 	tests \
 	$(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 	test_Mochikit.html \
 	manifest.json \
 	$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/mochikit/MochiKit/Makefile.in
+++ b/dom/tests/mochitest/ajax/mochikit/MochiKit/Makefile.in
@@ -6,19 +6,17 @@
 DEPTH		= ../../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/mochikit/MochiKit
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 		Async.js \
 		Base.js \
 		Color.js \
 		Controls.js \
 		DOM.js \
 		DateTime.js \
 		DragAndDrop.js \
 		Format.js \
@@ -32,10 +30,9 @@ include $(topsrcdir)/config/rules.mk
 		Signal.js \
 		Sortable.js \
 		Style.js \
 		Test.js \
 		Visual.js \
 		__package__.js \
 		$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/mochikit/tests/Makefile.in
+++ b/dom/tests/mochitest/ajax/mochikit/tests/Makefile.in
@@ -10,19 +10,17 @@ VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/mochikit/tests
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS		= \
 		SimpleTest \
 		$(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 		FakeJSAN.js \
 		cli.js \
 		index.html \
 		standalone.js \
 		test_Base.js \
 		test_Color.js \
 		test_DateTime.js \
 		test_DragAndDrop.js \
@@ -43,10 +41,9 @@ include $(topsrcdir)/config/rules.mk
 		MochiKit-MochiKit.html \
 		MochiKit-Selector.html \
 		MochiKit-Signal.html \
 		MochiKit-Style.html \
 		MochiKit-Visual.html \
 		test_Signal.js \
 		$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/mochikit/tests/SimpleTest/Makefile.in
+++ b/dom/tests/mochitest/ajax/mochikit/tests/SimpleTest/Makefile.in
@@ -8,18 +8,15 @@ topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/mochikit/tests/SimpleTest
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = $(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 		SimpleTest.js \
 		TestRunner.js \
 		test.css \
 		$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/offline/Makefile.in
+++ b/dom/tests/mochitest/ajax/offline/Makefile.in
@@ -8,41 +8,39 @@ topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/offline
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = namespace1 namespace2
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 	offlineTests.js \
 	test_badManifestMagic.html \
 	test_badManifestMime.html \
 	test_bypass.html \
 	test_missingFile.html \
 	test_noManifest.html \
 	test_simpleManifest.html \
 	test_identicalManifest.html \
 	test_changingManifest.html \
 	test_refetchManifest.html \
 	test_offlineIFrame.html \
 	test_bug445544.html \
 	test_bug460353.html \
 	test_bug474696.html \
 	test_bug544462.html \
-  test_bug744719.html \
-  744719.cacheManifest \
-  744719.cacheManifest^headers^ \
-  test_bug744719-cancel.html \
-  744719-cancel.cacheManifest \
-  744719-cancel.cacheManifest^headers^ \
-  subresource744719.html \
+	test_bug744719.html \
+	744719.cacheManifest \
+	744719.cacheManifest^headers^ \
+	test_bug744719-cancel.html \
+	744719-cancel.cacheManifest \
+	744719-cancel.cacheManifest^headers^ \
+	subresource744719.html \
 	test_foreign.html \
 	test_fallback.html \
 	test_overlap.html \
 	test_redirectManifest.html \
 	test_redirectUpdateItem.html \
 	overlap.cacheManifest \
 	overlap.cacheManifest^headers^ \
 	test_updatingManifest.html \
@@ -95,10 +93,9 @@ include $(topsrcdir)/config/rules.mk
 	test_xhtmlManifest.xhtml \
 	test_missingManifest.html \
 	missing.html \
 	jupiter.jpg \
 	$(NULL)
 
 # test_offlineMode.html disabled due to bug 656943
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/offline/namespace1/Makefile.in
+++ b/dom/tests/mochitest/ajax/offline/namespace1/Makefile.in
@@ -8,18 +8,15 @@ topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/offline/namespace1
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = sub sub2
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
         opp.html \
         script.js \
         redirectToDifferentOrigin.sjs \
         $(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/offline/namespace1/sub/Makefile.in
+++ b/dom/tests/mochitest/ajax/offline/namespace1/sub/Makefile.in
@@ -6,17 +6,14 @@
 DEPTH		= ../../../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/offline/namespace1/sub
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
         opp.html \
         script1.js \
         $(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/offline/namespace1/sub2/Makefile.in
+++ b/dom/tests/mochitest/ajax/offline/namespace1/sub2/Makefile.in
@@ -6,16 +6,13 @@
 DEPTH		= ../../../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/offline/namespace1/sub2
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
         script2.js \
         $(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/offline/namespace2/Makefile.in
+++ b/dom/tests/mochitest/ajax/offline/namespace2/Makefile.in
@@ -6,16 +6,13 @@
 DEPTH		= ../../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/offline/namespace2
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
         script3.js \
         $(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/prototype/Makefile.in
+++ b/dom/tests/mochitest/ajax/prototype/Makefile.in
@@ -11,17 +11,14 @@ relativesrcdir	= dom/tests/mochitest/aja
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS	= \
 	dist \
 	test \
 	$(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
         test_Prototype.html \
         manifest.json \
         $(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/prototype/dist/Makefile.in
+++ b/dom/tests/mochitest/ajax/prototype/dist/Makefile.in
@@ -5,16 +5,14 @@
 
 DEPTH		= ../../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/prototype/dist
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 	prototype.js \
         $(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/prototype/test/Makefile.in
+++ b/dom/tests/mochitest/ajax/prototype/test/Makefile.in
@@ -12,18 +12,15 @@ relativesrcdir	= dom/tests/mochitest/aja
 include $(DEPTH)/config/autoconf.mk
 
 DIRS	= \
 	unit \
 	lib \
 	functional \
 	$(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 		test.css \
 		browser.html \
 		console.html \
 		$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/prototype/test/functional/Makefile.in
+++ b/dom/tests/mochitest/ajax/prototype/test/functional/Makefile.in
@@ -5,16 +5,14 @@
 
 DEPTH		= ../../../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/prototype/test/functional
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 	event.html \
 	$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/prototype/test/lib/Makefile.in
+++ b/dom/tests/mochitest/ajax/prototype/test/lib/Makefile.in
@@ -6,16 +6,13 @@
 DEPTH		= ../../../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/prototype/test/lib
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 		unittest.js \
 		$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/prototype/test/unit/Makefile.in
+++ b/dom/tests/mochitest/ajax/prototype/test/unit/Makefile.in
@@ -11,19 +11,17 @@ relativesrcdir	= dom/tests/mochitest/aja
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = 	\
 	fixtures \
 	tmp \
 	$(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 	ajax_test.js \
 	array_test.js \
 	base_test.js \
 	dom_test.js \
 	element_mixins_test.js \
 	enumerable_test.js \
 	event_test.js \
 	form_test.js \
@@ -31,10 +29,9 @@ include $(topsrcdir)/config/rules.mk
 	number_test.js \
 	position_test.js \
 	range_test.js \
 	selector_test.js \
 	string_test.js \
 	unittest_test.js \
 	$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/prototype/test/unit/fixtures/Makefile.in
+++ b/dom/tests/mochitest/ajax/prototype/test/unit/fixtures/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/prototype/test/unit/fixtures
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES= \
+MOCHITEST_FILES= \
 	ajax.html \
 	ajax.js \
 	array.html \
 	base.html \
 	base.js \
 	content.html \
 	data.json \
 	dom.css \
@@ -35,10 +34,9 @@ include $(topsrcdir)/config/rules.mk
 	hello.js \
 	logo.gif \
 	position.html \
 	selector.html \
 	string.js \
 	unittest.html \
 	$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/prototype/test/unit/tmp/Makefile.in
+++ b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/prototype/test/unit/tmp
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES= \
+MOCHITEST_FILES= \
 	ajax_test.html \
 	array_test.html \
 	base_test.html \
 	dom_test.html \
 	element_mixins_test.html \
 	enumerable_test.html \
 	event_test.html \
 	form_test.html \
@@ -25,10 +24,9 @@ include $(topsrcdir)/config/rules.mk
 	number_test.html \
 	position_test.html \
 	range_test.html \
 	selector_test.html \
 	string_test.html \
 	unit_test.html \
 	$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/scriptaculous/Makefile.in
+++ b/dom/tests/mochitest/ajax/scriptaculous/Makefile.in
@@ -12,17 +12,14 @@ relativesrcdir	= dom/tests/mochitest/aja
 include $(DEPTH)/config/autoconf.mk
 
 DIRS	= \
 	lib \
 	src \
 	test/unit \
 	$(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 	manifest.json \
 	test_Scriptaculous.html \
 	$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/scriptaculous/lib/Makefile.in
+++ b/dom/tests/mochitest/ajax/scriptaculous/lib/Makefile.in
@@ -9,16 +9,13 @@ srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/scriptaculous/lib
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS	= \
 	$(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 	prototype.js \
 	$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/scriptaculous/src/Makefile.in
+++ b/dom/tests/mochitest/ajax/scriptaculous/src/Makefile.in
@@ -9,23 +9,20 @@ srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/scriptaculous/src
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS	= \
 	$(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 	builder.js \
 	controls.js \
 	dragdrop.js \
 	effects.js \
 	scriptaculous.js \
 	slider.js \
 	sound.js \
 	unittest.js \
 	$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/ajax/scriptaculous/test/unit/Makefile.in
+++ b/dom/tests/mochitest/ajax/scriptaculous/test/unit/Makefile.in
@@ -9,19 +9,17 @@ srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/scriptaculous/test/unit
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS	= \
 	$(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 	_ajax_inplaceeditor_result.html \
 	_ajax_inplaceeditor_text.html \
 	_ajax_updater_result.html \
 	_autocomplete_result.html \
 	_autocomplete_result_nobr.html \
 	ajax_autocompleter_test.html \
 	ajax_inplaceeditor_test.html \
 	bdd_test.html \
@@ -33,10 +31,9 @@ include $(topsrcdir)/config/rules.mk
 	loading_test.html \
 	position_clone_test.html \
 	slider_test.html \
 	sortable_test.html \
 	string_test.html \
 	unit_test.html \
 	$(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/bugs/Makefile.in
+++ b/dom/tests/mochitest/bugs/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/bugs
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 		test_bug42976.html \
 		test_bug49312.html \
 		iframe_bug49312.html \
 		test_bug132255.html \
 		test_bug159849.html \
 		test_bug265203.html \
 		test_bug291377.html \
 		file_bug291653.html \
@@ -127,10 +126,9 @@ include $(topsrcdir)/config/rules.mk
 		test_bug740811.html \
 		test_bug743615.html \
 		utils_bug743615.js \
 		worker_bug743615.js \
 		test_bug750051.html \
 		test_bug755320.html \
 		$(NULL)
 
-libs:: 	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/chrome/Makefile.in
+++ b/dom/tests/mochitest/chrome/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = dom/tests/mochitest/chrome
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_CHROME_FILES = \
 		test_MozEnteredDomFullscreen_event.xul \
 		MozEnteredDomFullscreen_chrome.xul \
 		test_fullscreen.xul \
 		fullscreen.xul \
 		test_fullscreen_preventdefault.xul \
 		fullscreen_preventdefault.xul \
 		focus_window2.xul \
 		focus_frameset.html \
@@ -45,16 +44,15 @@ include $(topsrcdir)/config/rules.mk
 		test_moving_nodeList.xul \
 		test_callback_wrapping.xul \
 		window_callback_wrapping.xul \
 		test_sandbox_postMessage.html \
 		test_sandbox_bindings.xul \
 		$(NULL)
 
 ifeq (WINNT,$(OS_ARCH))
-_TEST_FILES += \
+MOCHITEST_CHROME_FILES += \
 		test_sizemode_attribute.xul \
 		sizemode_attribute.xul \
 		$(NULL)
 endif
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/dom-level0/Makefile.in
+++ b/dom/tests/mochitest/dom-level0/Makefile.in
@@ -5,26 +5,24 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/dom-level0
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 		test_crossdomainprops.html \
 		file_crossdomainprops_inner.html \
 		test_setting_document.domain_to_shortened_ipaddr.html \
 		child_ip_address.html \
 		test_setting_document.domain_idn.html \
 		idn_child.html \
 		file_location.html \
 		test_location.html \
 		test_innerWidthHeight_script.html \
 		innerWidthHeight_script.html \
 		test_location_setters.html \
 		$(NULL)
 
-libs:: 	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/dom-level1-core/Makefile.in
+++ b/dom/tests/mochitest/dom-level1-core/Makefile.in
@@ -8,19 +8,17 @@ topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/dom-level1-core
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = files
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES_A	= \
+MOCHITEST_FILES_A	= \
 		DOMTestCase.js \
 		activity-home.css \
 		exclusions.js \
 		test_attrcreatedocumentfragment.html \
 		test_attrcreatetextnode.html \
 		test_attrcreatetextnode2.html \
 		test_attrdefaultvalue.html \
 		test_attreffectivevalue.html \
@@ -77,17 +75,17 @@ include $(topsrcdir)/config/rules.mk
 		test_characterdatareplacedatanomodificationallowederrEE.html \
 		test_characterdatasetdatanomodificationallowederr.html \
 		test_characterdatasetdatanomodificationallowederrEE.html \
 		test_characterdatasetnodevalue.html \
 		test_characterdatasubstringexceedsvalue.html \
 		test_characterdatasubstringvalue.html \
 		$(NULL)
 
-_TEST_FILES_B	= \
+MOCHITEST_FILES_B	= \
 		test_commentgetcomment.html \
 		test_documentcreateattribute.html \
 		test_documentcreatecdatasection.html \
 		test_documentcreatecomment.html \
 		test_documentcreatedocumentfragment.html \
 		test_documentcreateelement.html \
 		test_documentcreateelementcasesensitive.html \
 		test_documentcreateelementdefaultattr.html \
@@ -153,17 +151,17 @@ include $(topsrcdir)/config/rules.mk
 		test_elementsetattributenomodificationallowederr.html \
 		test_elementsetattributenomodificationallowederrEE.html \
 		test_elementwrongdocumenterr.html \
 		test_entitygetentityname.html \
 		test_entitygetpublicid.html \
 		test_entitygetpublicidnull.html \
 		$(NULL)
 
-_TEST_FILES_C	= \
+MOCHITEST_FILES_C	= \
 		test_hc_attrappendchild1.html \
 		test_hc_attrappendchild2.html \
 		test_hc_attrappendchild3.html \
 		test_hc_attrappendchild4.html \
 		test_hc_attrappendchild5.html \
 		test_hc_attrappendchild6.html \
 		test_hc_attrchildnodes1.html \
 		test_hc_attrchildnodes2.html \
@@ -194,17 +192,17 @@ include $(topsrcdir)/config/rules.mk
 		test_hc_attrreplacechild1.html \
 		test_hc_attrreplacechild2.html \
 		test_hc_attrsetvalue1.html \
 		test_hc_attrsetvalue2.html \
 		test_hc_attrspecifiedvalue.html \
 		test_hc_attrspecifiedvaluechanged.html \
 		$(NULL)
 
-_TEST_FILES_D	= \
+MOCHITEST_FILES_D	= \
 		test_hc_characterdataappenddata.html \
 		test_hc_characterdataappenddatagetdata.html \
 		test_hc_characterdatadeletedatabegining.html \
 		test_hc_characterdatadeletedataend.html \
 		test_hc_characterdatadeletedataexceedslength.html \
 		test_hc_characterdatadeletedatagetlengthanddata.html \
 		test_hc_characterdatadeletedatamiddle.html \
 		test_hc_characterdatagetdata.html \
@@ -277,17 +275,17 @@ include $(topsrcdir)/config/rules.mk
 		test_hc_elementreplaceexistingattributegevalue.html \
 		test_hc_elementretrieveallattributes.html \
 		test_hc_elementretrieveattrvalue.html \
 		test_hc_elementretrievetagname.html \
 		test_hc_elementsetattributenodenull.html \
 		test_hc_elementwrongdocumenterr.html \
 		$(NULL)
 
-_TEST_FILES_E	= \
+MOCHITEST_FILES_E	= \
 		test_hc_entitiesremovenameditem1.html \
 		test_hc_entitiessetnameditem1.html \
 		test_hc_namednodemapchildnoderange.html \
 		test_hc_namednodemapgetnameditem.html \
 		test_hc_namednodemapinuseattributeerr.html \
 		test_hc_namednodemapnotfounderr.html \
 		test_hc_namednodemapnumberofnodes.html \
 		test_hc_namednodemapremovenameditem.html \
@@ -395,17 +393,17 @@ include $(topsrcdir)/config/rules.mk
 		test_hc_textparseintolistofelements.html \
 		test_hc_textsplittextfour.html \
 		test_hc_textsplittextone.html \
 		test_hc_textsplittextthree.html \
 		test_hc_textsplittexttwo.html \
 		test_hc_textwithnomarkup.html \
 		$(NULL)
 
-_TEST_FILES_F	= \
+MOCHITEST_FILES_F	= \
 		test_namednodemapchildnoderange.html \
 		test_namednodemapgetnameditem.html \
 		test_namednodemapinuseattributeerr.html \
 		test_namednodemapnotfounderr.html \
 		test_namednodemapnumberofnodes.html \
 		test_namednodemapremovenameditem.html \
 		test_namednodemapremovenameditemgetvalue.html \
 		test_namednodemapremovenameditemreturnnodevalue.html \
@@ -498,17 +496,17 @@ include $(topsrcdir)/config/rules.mk
 		test_nodelistindexgetlength.html \
 		test_nodelistindexgetlengthofemptylist.html \
 		test_nodelistindexnotzero.html \
 		test_nodelistreturnfirstitem.html \
 		test_nodelistreturnlastitem.html \
 		test_nodelisttraverselist.html \
 		$(NULL)
 
-_TEST_FILES_G	= \
+MOCHITEST_FILES_G	= \
 		test_nodenotationnodeattributes.html \
 		test_nodenotationnodename.html \
 		test_nodenotationnodetype.html \
 		test_nodenotationnodevalue.html \
 		test_nodeparentnode.html \
 		test_nodeparentnodenull.html \
 		test_nodeprocessinginstructionnodeattributes.html \
 		test_nodeprocessinginstructionnodename.html \
@@ -565,29 +563,11 @@ include $(topsrcdir)/config/rules.mk
 		test_textsplittexttwo.html \
 		test_textwithnomarkup.html \
 		$(NULL)
 
 # test_PIsetdatanomodificationallowederrEE.html was originally
 # test_processinginstructionsetdatanomodificationallowederrEE.html, but that
 # name is too long for Windows little brain.
 
-# work around command-line length limits by splitting into groups
-libs:: 	$(_TEST_FILES_A)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs::	$(_TEST_FILES_B)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs::	$(_TEST_FILES_C)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+MOCHITEST_FILES_PARTS := $(foreach part,A B C D E F G,MOCHITEST_FILES_$(part))
 
-libs::	$(_TEST_FILES_D)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs::	$(_TEST_FILES_E)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs::	$(_TEST_FILES_F)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs::	$(_TEST_FILES_G)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/dom-level1-core/files/Makefile.in
+++ b/dom/tests/mochitest/dom-level1-core/files/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/dom-level1-core/files
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 		hc_nodtdstaff.html \
 		hc_nodtdstaff.xhtml \
 		hc_staff.html \
 		hc_staff.xhtml \
 		staff.dtd \
 		staff.xml \
 		svgunit.js \
 		xhtml-special.ent \
@@ -29,10 +28,9 @@ include $(topsrcdir)/config/rules.mk
 		hc_staff.xml \
 		staff.svg \
 		svgtest.js \
 		xhtml-lat1.ent \
 		xhtml-symbol.ent \
 		xhtml1-strict.dtd \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/dom-level2-core/Makefile.in
+++ b/dom/tests/mochitest/dom-level2-core/Makefile.in
@@ -8,19 +8,17 @@ topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/dom-level2-core
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = files
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES_A	= \
+MOCHITEST_FILES_A	= \
 		DOMTestCase.js \
 		exclusions.js \
 		test_attrgetownerelement01.html \
 		test_attrgetownerelement02.html \
 		test_attrgetownerelement03.html \
 		test_attrgetownerelement04.html \
 		test_attrgetownerelement05.html \
 		test_createAttributeNS01.html \
@@ -59,17 +57,17 @@ include $(topsrcdir)/config/rules.mk
 		test_documentgetelementbyid01.html \
 		test_documentgetelementsbytagnameNS01.html \
 		test_documentgetelementsbytagnameNS02.html \
 		test_documentgetelementsbytagnameNS03.html \
 		test_documentgetelementsbytagnameNS04.html \
 		test_documentgetelementsbytagnameNS05.html \
 		$(NULL)
 
-_TEST_FILES_B	= \
+MOCHITEST_FILES_B	= \
 		test_documentimportnode01.html \
 		test_documentimportnode02.html \
 		test_documentimportnode03.html \
 		test_documentimportnode04.html \
 		test_documentimportnode05.html \
 		test_documentimportnode06.html \
 		test_documentimportnode07.html \
 		test_documentimportnode08.html \
@@ -97,17 +95,17 @@ include $(topsrcdir)/config/rules.mk
 		test_domimplementationcreatedocumenttype02.html \
 		test_domimplementationcreatedocumenttype04.html \
 		test_domimplementationfeaturecore.html \
 		test_domimplementationfeaturexmlversion2.html \
 		test_domimplementationhasfeature01.html \
 		test_domimplementationhasfeature02.html \
 		$(NULL)
 
-_TEST_FILES_C	= \
+MOCHITEST_FILES_C	= \
 		test_elementgetattributenodens01.html \
 		test_elementgetattributenodens02.html \
 		test_elementgetattributenodens03.html \
 		test_elementgetattributens02.html \
 		test_elementgetelementsbytagnamens02.html \
 		test_elementgetelementsbytagnamens04.html \
 		test_elementgetelementsbytagnamens05.html \
 		test_elementhasattribute01.html \
@@ -144,17 +142,17 @@ include $(topsrcdir)/config/rules.mk
 		test_getElementsByTagNameNS02.html \
 		test_getElementsByTagNameNS03.html \
 		test_getElementsByTagNameNS04.html \
 		test_getElementsByTagNameNS05.html \
 		test_getElementsByTagNameNS06.html \
 		test_getElementsByTagNameNS07.html \
 		$(NULL)
 
-_TEST_FILES_D	= \
+MOCHITEST_FILES_D	= \
 		test_getElementsByTagNameNS08.html \
 		test_getElementsByTagNameNS09.html \
 		test_getElementsByTagNameNS10.html \
 		test_getElementsByTagNameNS11.html \
 		test_getElementsByTagNameNS12.html \
 		test_getElementsByTagNameNS13.html \
 		test_getElementsByTagNameNS14.html \
 		test_getNamedItemNS01.html \
@@ -202,17 +200,17 @@ include $(topsrcdir)/config/rules.mk
 		test_isSupported09.html \
 		test_isSupported10.html \
 		test_isSupported11.html \
 		test_isSupported12.html \
 		test_isSupported13.html \
 		test_isSupported14.html \
 		$(NULL)
 
-_TEST_FILES_E	= \
+MOCHITEST_FILES_E	= \
 		test_localName01.html \
 		test_localName02.html \
 		test_localName03.html \
 		test_localName04.html \
 		test_namednodemapgetnameditemns01.html \
 		test_namednodemapgetnameditemns02.html \
 		test_namednodemapgetnameditemns03.html \
 		test_namednodemapgetnameditemns04.html \
@@ -253,17 +251,17 @@ include $(topsrcdir)/config/rules.mk
 		test_nodehasattributes04.html \
 		test_nodeissupported01.html \
 		test_nodeissupported02.html \
 		test_nodeissupported03.html \
 		test_nodeissupported04.html \
 		test_nodeissupported05.html \
 		$(NULL)
 
-_TEST_FILES_F	= \
+MOCHITEST_FILES_F	= \
 		test_nodenormalize01.html \
 		test_normalize01.html \
 		test_ownerDocument01.html \
 		test_ownerElement01.html \
 		test_ownerElement02.html \
 		test_prefix01.html \
 		test_prefix02.html \
 		test_prefix03.html \
@@ -291,26 +289,11 @@ include $(topsrcdir)/config/rules.mk
 		test_setNamedItemNS01.html \
 		test_setNamedItemNS02.html \
 		test_setNamedItemNS03.html \
 		test_setNamedItemNS04.html \
 		test_setNamedItemNS05.html \
 		test_systemId01.html \
 		$(NULL)
 
-# work around nsinstall limits on windows by splitting into groups
-libs:: 	$(_TEST_FILES_A)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs::	$(_TEST_FILES_B)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+MOCHITEST_FILES_PARTS := $(foreach part,A B C D E F,MOCHITEST_FILES_$(part))
 
-libs::	$(_TEST_FILES_C)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs:: 	$(_TEST_FILES_D)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs::	$(_TEST_FILES_E)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs::	$(_TEST_FILES_F)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/dom-level2-core/files/Makefile.in
+++ b/dom/tests/mochitest/dom-level2-core/files/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/dom-level2-core/files
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 		hc_staff.html \
 		hc_staff.svg \
 		hc_staff.xhtml \
 		hc_staff.xml \
 		internalSubset01.js \
 		nodtdstaff.svg \
 		nodtdstaff.xml \
 		staff.dtd \
@@ -34,10 +33,9 @@ include $(topsrcdir)/config/rules.mk
 		xhtml-lat1.ent \
 		xhtml-special.ent \
 		xhtml-symbol.ent \
 		xhtml1-frameset.dtd \
 		xhtml1-strict.dtd \
 		xhtml1-transitional.dtd \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/dom-level2-html/Makefile.in
+++ b/dom/tests/mochitest/dom-level2-html/Makefile.in
@@ -8,19 +8,17 @@ topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/dom-level2-html
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = files
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES_A	= \
+MOCHITEST_FILES_A	= \
 		DOMTestCase.js \
 		test_anchor01.html \
 		test_anchor02.html \
 		test_anchor03.html \
 		test_anchor04.html \
 		test_anchor05.html \
 		test_anchor06.html \
 		test_area01.html \
@@ -96,17 +94,17 @@ include $(topsrcdir)/config/rules.mk
 		test_HTMLCollection10.html \
 		test_HTMLCollection11.html \
 		test_HTMLCollection12.html \
 		$(NULL)
 
 # This test is failing on all platforms -- bug 471139
 #		test_HTMLDocument12.html \
 #
-_TEST_FILES_B	= \
+MOCHITEST_FILES_B	= \
 		test_HTMLDirectoryElement01.html \
 		test_HTMLDivElement01.html \
 		test_HTMLDlistElement01.html \
 		test_HTMLDocument01.html \
 		test_HTMLDocument02.html \
 		test_HTMLDocument03.html \
 		test_HTMLDocument04.html \
 		test_HTMLDocument05.html \
@@ -271,17 +269,17 @@ include $(topsrcdir)/config/rules.mk
 		test_HTMLElement93.html \
 		test_HTMLElement94.html \
 		test_HTMLElement95.html \
 		test_HTMLElement96.html \
 		test_HTMLElement97.html \
 		test_HTMLElement98.html \
 		test_HTMLElement99.html \
 		$(NULL)
-_TEST_FILES_C	= \
+MOCHITEST_FILES_C	= \
 		test_HTMLFieldSetElement01.html \
 		test_HTMLFieldSetElement02.html \
 		test_HTMLFontElement01.html \
 		test_HTMLFontElement02.html \
 		test_HTMLFontElement03.html \
 		test_HTMLFormElement01.html \
 		test_HTMLFormElement02.html \
 		test_HTMLFormElement03.html \
@@ -386,17 +384,17 @@ include $(topsrcdir)/config/rules.mk
 		test_HTMLMetaElement03.html \
 		test_HTMLMetaElement04.html \
 		test_HTMLModElement01.html \
 		test_HTMLModElement02.html \
 		test_HTMLModElement03.html \
 		test_HTMLModElement04.html \
 		$(NULL)
 
-_TEST_FILES_D	= \
+MOCHITEST_FILES_D	= \
 		test_HTMLObjectElement01.html \
 		test_HTMLObjectElement02.html \
 		test_HTMLObjectElement03.html \
 		test_HTMLObjectElement04.html \
 		test_HTMLObjectElement05.html \
 		test_HTMLObjectElement06.html \
 		test_HTMLObjectElement07.html \
 		test_HTMLObjectElement08.html \
@@ -620,17 +618,17 @@ include $(topsrcdir)/config/rules.mk
 		test_HTMLTextAreaElement12.html \
 		test_HTMLTextAreaElement13.html \
 		test_HTMLTextAreaElement14.html \
 		test_HTMLTextAreaElement15.html \
 		test_HTMLTitleElement01.html \
 		test_HTMLUListElement01.html \
 		test_HTMLUListElement02.html \
 		$(NULL)
-_TEST_FILES_E	= \
+MOCHITEST_FILES_E	= \
 		test_object01.html \
 		test_object02.html \
 		test_object03.html \
 		test_object04.html \
 		test_object05.html \
 		test_object06.html \
 		test_object07.html \
 		test_object08.html \
@@ -692,35 +690,25 @@ include $(topsrcdir)/config/rules.mk
                 test_hasFeature01.html \
 		test_hasFeature02.html \
 		test_hasFeature03.html \
 		test_hasFeature04.html \
 		test_hasFeature05.html \
 		test_hasFeature06.html \
 		$(NULL)
 
-_TEST_FILES_F	= \
+MOCHITEST_FILES_F	= \
 		test_HTMLAppletElement01.html \
 		test_HTMLAppletElement02.html \
 		test_HTMLAppletElement03.html \
 		test_HTMLAppletElement04.html \
 		test_HTMLAppletElement05.html \
 		test_HTMLAppletElement06.html \
 		test_HTMLAppletElement07.html \
 		test_HTMLAppletElement08.html \
 		test_HTMLAppletElement09.html \
 		test_HTMLAppletElement10.html \
 		test_HTMLAppletElement11.html \
 		$(NULL)
 
-# work around nsinstall limits on windows by splitting into groups
-libs:: 	$(_TEST_FILES_A)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-libs:: 	$(_TEST_FILES_B)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-libs:: 	$(_TEST_FILES_C)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-libs:: 	$(_TEST_FILES_D)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-libs:: 	$(_TEST_FILES_E)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-#libs:: 	$(_TEST_FILES_F)
-#	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+MOCHITEST_FILES_PARTS := $(foreach part,A B C D E,MOCHITEST_FILES_$(part))
+
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/dom-level2-html/files/Makefile.in
+++ b/dom/tests/mochitest/dom-level2-html/files/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/dom-level2-html/files
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 		anchor.html \
 		anchor.xhtml \
 		anchor.xml \
 		anchor2.html \
 		anchor2.xhtml \
 		anchor2.xml \
 		applet.html \
 		applet.xhtml \
@@ -215,16 +214,15 @@ include $(topsrcdir)/config/rules.mk
 		w3c_main.png \
 		xhtml-lat1.ent \
 		xhtml-special.ent \
 		xhtml-symbol.ent \
 		xhtml1-frameset.dtd \
 		xhtml1-strict.dtd \
 		xhtml1-transitional.dtd \
 		$(NULL)
-_TEST_FILES_J   = \
+MOCHITEST_FILES_J   = \
 		applets/org/w3c/domts/DOMTSApplet.class \
 		$(NULL)
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-libs:: $(_TEST_FILES_J)
+include $(topsrcdir)/config/rules.mk
+libs:: $(MOCHITEST_FILES_J)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)/applets/org/w3c/domts
 
--- a/dom/tests/mochitest/general/Makefile.in
+++ b/dom/tests/mochitest/general/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = dom/tests/mochitest/general
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
 		file_MozEnteredDomFullscreen.html \
 		test_outerHTML.html \
 		test_outerHTML.xhtml \
 		497633.html \
 		historyframes.html \
 		test_497898.html \
 		test_bug504220.html \
 		test_bug628069_1.html \
@@ -44,19 +43,15 @@ include $(topsrcdir)/config/rules.mk
 		test_for_of.html \
 		test_focus_legend_noparent.html \
 		file_clonewrapper.html \
 		file_moving_nodeList.html \
 		test_performance_now.html \
 		test_interfaces.html \
 		$(NULL)
 
-_CHROME_FILES = \
+MOCHITEST_CHROME_FILES = \
 		test_innerScreen.xul \
 		test_offsets.xul \
 		test_offsets.js \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs:: $(_CHROME_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/geolocation/Makefile.in
+++ b/dom/tests/mochitest/geolocation/Makefile.in
@@ -5,19 +5,17 @@
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/geolocation
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 		test_allowCurrent.html \
 		test_allowWatch.html \
 		test_cancelCurrent.html \
 		test_cancelWatch.html \
 		test_clearWatch.html \
 		test_clearWatch_invalid.html \
 		test_manyCurrentConcurrent.html \
 		test_manyCurrentSerial.html \
@@ -30,11 +28,9 @@ include $(topsrcdir)/config/rules.mk
 		test_timerRestartWatch.html \
 		test_worseAccuracyDoesNotBlockCallback.html \
 		geolocation.html \
 		geolocation_common.js  \
 		network_geolocation.sjs \
 		windowTest.html \
 		$(NULL)
 
-libs:: 	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/localstorage/Makefile.in
+++ b/dom/tests/mochitest/localstorage/Makefile.in
@@ -6,19 +6,17 @@
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/localstorage
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
     frameBug624047.html \
     frameChromeSlave.html \
     frameKeySync.html \
     frameMasterEqual.html \
     frameMasterNotEqual.html \
     frameSlaveEqual.html \
     frameSlaveNotEqual.html \
     frameReplace.html \
@@ -53,17 +51,14 @@ include $(topsrcdir)/config/rules.mk
     test_localStorageQuotaPrivateBrowsing.html \
     test_localStorageQuotaSessionOnly.html \
     test_localStorageQuotaSessionOnly2.html \
     test_localStorageKeyOrder.html \
     test_removeOwnersAPI.html \
     test_removeOwnersAPISessionOnly.html \
     test_storageConstructor.html \
     $(NULL)
-    
-_CHROME_FILES = \
+
+MOCHITEST_CHROME_FILES = \
     test_localStorageFromChrome.xhtml \
     $(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-libs::	$(_CHROME_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/notification/Makefile.in
+++ b/dom/tests/mochitest/notification/Makefile.in
@@ -5,20 +5,16 @@
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/notification
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 		test_basic_notification.html \
 		test_basic_notification_click.html \
 		test_leak_windowClose.html \
 		notification_common.js \
 		$(NULL)
 
-libs:: 	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/orientation/Makefile.in
+++ b/dom/tests/mochitest/orientation/Makefile.in
@@ -5,18 +5,14 @@
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/orientation
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 		bug507902-frame.html \
 		test_bug507902.html \
 		$(NULL)
 
-libs:: 	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/pointerlock/Makefile.in
+++ b/dom/tests/mochitest/pointerlock/Makefile.in
@@ -5,19 +5,17 @@
 DEPTH	= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir	= @srcdir@
 VPATH	= @srcdir@
 relativesrcdir	= dom/tests/mochitest/pointerlock
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 		test_pointerlock-api.html \
 		pointerlock_utils.js \
 		file_approval.html \
 		file_pointerlock-api.html \
 		file_pointerlockerror.html \
 		file_escapeKey.html \
 		file_withoutDOM.html \
 		file_removedFromDOM.html \
@@ -30,10 +28,9 @@ include $(topsrcdir)/config/rules.mk
 		file_retargetMouseEvents.html \
 		file_targetOutOfFocus.html \
 		file_screenClientXYConst.html \
 		file_suppressSomeMouseEvents.html \
 		file_locksvgelement.html \
 		iframe_differentDOM.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/sessionstorage/Makefile.in
+++ b/dom/tests/mochitest/sessionstorage/Makefile.in
@@ -6,32 +6,27 @@
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/sessionstorage
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
     frameReplace.html \
     frameEqual.html \
     frameNotEqual.html \
     file_http.html \
     file_https.html \
     test_sessionStorageBase.html \
     test_sessionStorageClone.html \
     test_sessionStorageReplace.html \
     test_sessionStorageHttpHttps.html \
     interOriginSlave.js \
     interOriginTest.js \
     $(NULL)
 
-_CHROME_FILES = \
+MOCHITEST_CHROME_FILES = \
     test_sessionStorageFromChrome.xhtml \
     $(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-libs::	$(_CHROME_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/storageevent/Makefile.in
+++ b/dom/tests/mochitest/storageevent/Makefile.in
@@ -6,28 +6,25 @@
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/storageevent
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
     frameLocalStorageMaster.html \
     frameLocalStorageSlaveEqual.html \
     frameLocalStorageSlaveNotEqual.html \
     frameSessionStorageMasterEqual.html \
     frameSessionStorageMasterNotEqual.html \
     frameSessionStorageSlaveEqual.html \
     frameSessionStorageSlaveNotEqual.html \
     test_storageLocalStorageEventCheckNoPropagation.html \
     test_storageLocalStorageEventCheckPropagation.html \
     test_storageSessionStorageEventCheckPropagation.html \
     test_storageSessionStorageEventCheckNoPropagation.html \
     interOriginFrame.js \
     interOriginTest2.js \
     $(NULL)
 
-libs::	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/webapps/Makefile.in
+++ b/dom/tests/mochitest/webapps/Makefile.in
@@ -9,25 +9,21 @@ VPATH	 = @srcdir@
 relativesrcdir	= dom/tests/mochitest/webapps
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = \
     apps \
     $(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_CHROME_FILES	= \
     test_bug_765063.xul \
     test_install_app.xul \
     test_list_api.xul \
     test_install_errors.xul \
     test_cross_domain.xul \
     test_install_utf8.xul \
     test_install_receipts.xul \
     jshelper.js \
     apphelper.js \
     $(NULL)
 
-libs:: 	$(_TEST_FILES)
-	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
-
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/webapps/apps/Makefile.in
+++ b/dom/tests/mochitest/webapps/apps/Makefile.in
@@ -5,19 +5,17 @@
 DEPTH	 = ../../../../..
 topsrcdir	 = @top_srcdir@
 srcdir	= @srcdir@
 VPATH	 = @srcdir@
 relativesrcdir	= dom/tests/mochitest/webapps/apps
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES	= \
+MOCHITEST_CHROME_FILES	= \
     bug_765063.xul \
     include.html \
     wild_crazy.webapp \
     wild_crazy.webapp^headers^ \
     super_crazy.webapp \
     super_crazy.webapp^headers^ \
     missing_required_field.webapp \
     missing_required_field.webapp^headers^ \
@@ -25,11 +23,9 @@ include $(topsrcdir)/config/rules.mk
     json_syntax_error.webapp^headers^ \
     no_delegated_install.webapp \
     no_delegated_install.webapp^headers^ \
     bad_content_type.webapp \
     manifest_with_bom.webapp \
     manifest_with_bom.webapp^headers^ \
     $(NULL)
 
-libs:: 	$(_TEST_FILES)
-	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
-
+include $(topsrcdir)/config/rules.mk
--- a/dom/tests/mochitest/whatwg/Makefile.in
+++ b/dom/tests/mochitest/whatwg/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/whatwg
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES	= \
+MOCHITEST_FILES	= \
 		browserFu.js \
 		test_MessageEvent.html \
 		test_postMessage.html \
 		postMessage_helper.html \
 		test_postMessage_joined.html \
 		postMessage_joined_helper.html \
 		postMessage_joined_helper2.html \
 		test_postMessage_onOther.html \
@@ -48,17 +47,13 @@ include $(topsrcdir)/config/rules.mk
 		file_bug500328_1.html \
 		file_bug500328_2.html \
 		test_document_scripts.html \
 		test_postMessage_structured_clone.html \
 		postMessage_structured_clone_helper.js \
 		postMessage_structured_clone_helper.html \
 		$(NULL)
 
-_CHROME_FILES	= \
+MOCHITEST_CHROME_FILES	= \
 		test_postMessage_chrome.html \
 		$(NULL)		
 
-libs:: 	$(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs:: $(_CHROME_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/dom/workers/test/Makefile.in
+++ b/dom/workers/test/Makefile.in
@@ -10,19 +10,17 @@ VPATH            = @srcdir@
 relativesrcdir   = dom/workers/test
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = \
   extensions \
   $(NULL)
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES = \
+MOCHITEST_FILES = \
   test_404.html \
   test_atob.html \
   atob_worker.js \
   test_blobWorkers.html \
   test_clearTimeouts.html \
   clearTimeouts_worker.js \
   test_close.html \
   close_worker.js \
@@ -89,23 +87,23 @@ include $(topsrcdir)/config/rules.mk
   test_workersDisabled.html \
   workersDisabled_worker.js \
   test_xhr_implicit_cancel.html \
   xhr_implicit_cancel_worker.js \
   test_xhr_timeout.html \
   test_blobConstructor.html \
   $(NULL)
 
-_SUBDIR_TEST_FILES = \
+_SUBDIRMOCHITEST_FILES = \
   relativeLoad_sub_worker.js \
   relativeLoad_sub_worker2.js \
   relativeLoad_sub_import.js \
   $(NULL)
 
-_CHROME_TEST_FILES = \
+MOCHITEST_CHROME_FILES = \
   test_chromeWorker.xul \
   test_chromeWorkerJSM.xul \
   test_extension.xul \
   test_extensionBootstrap.xul \
   test_file.xul \
   test_fileSlice.xul \
   test_fileBlobPosting.xul \
   test_filePosting.xul \
@@ -128,16 +126,12 @@ include $(topsrcdir)/config/rules.mk
   WorkerTest_subworker.js \
   chromeWorker_worker.js \
   chromeWorker_subworker.js \
   test_workersDisabled.xul \
   workersDisabled_worker.js \
   dom_worker_helper.js \
   $(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs:: $(_SUBDIR_TEST_FILES)
+libs:: $(_SUBDIRMOCHITEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)/subdir
 
-libs:: $(_CHROME_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/editor/composer/test/Makefile.in
+++ b/editor/composer/test/Makefile.in
@@ -5,30 +5,25 @@
 
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = editor/composer/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
 		test_bug348497.html \
 		test_bug384147.html \
 		test_bug389350.html \
 		test_bug519928.html \
 		bug678842_subframe.html \
 		test_bug738440.html \
 		$(NULL)
 
-_CHROME_TEST_FILES = \
+MOCHITEST_CHROME_FILES = \
 		test_bug434998.xul \
 		test_bug338427.html \
 		test_bug678842.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs:: $(_CHROME_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/editor/libeditor/base/tests/Makefile.in
+++ b/editor/libeditor/base/tests/Makefile.in
@@ -5,35 +5,30 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = editor/libeditor/base/tests
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
 		test_bug408231.html \
 		test_bug502673.html \
 		test_bug514156.html \
 		test_bug567213.html \
 		file_bug586662.html \
 		test_bug586662.html \
 		test_bug599983.html \
 		test_bug742261.html \
 		$(NULL)
 
-_CHROME_TEST_FILES = \
+MOCHITEST_CHROME_FILES = \
 		test_selection_move_commands.xul \
                 test_bug46555.html \
 		test_bug646194.xul \
 		test_dragdrop.html \
 		test_bug599983.xul \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
 
-libs:: $(_CHROME_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
-
--- a/editor/libeditor/html/tests/Makefile.in
+++ b/editor/libeditor/html/tests/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = editor/libeditor/html/tests
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
 		green.png \
 		test_bug290026.html \
 		test_bug291780.html \
 		test_bug316447.html \
 		test_bug332636.html \
 		test_bug332636.html^headers^ \
 		test_bug372345.html \
 		test_bug404320.html \
@@ -78,41 +77,38 @@ include $(topsrcdir)/config/rules.mk
 		file_select_all_without_body.html \
 		test_root_element_replacement.html \
 		test_bug738366.html \
 		test_bug757371.html \
 		test_bug767684.html \
 		$(NULL)
 
 ifneq (mobile,$(MOZ_BUILD_APP))
-_TEST_FILES +=  test_spellcheck_pref.html \
+MOCHITEST_FILES +=  test_spellcheck_pref.html \
 		$(NULL)
 endif
 
 _DATA_FILES = \
 		data/cfhtml-chromium.txt \
 		data/cfhtml-firefox.txt \
 		data/cfhtml-ie.txt \
 		data/cfhtml-ooo.txt \
 		data/cfhtml-nocontext.txt \
 		$(NULL)
 
-_CHROME_TEST_FILES = \
+MOCHITEST_CHROME_FILES = \
 		test_contenteditable_text_input_handling.html \
 		test_bug366682.html \
 		test_bug489202.xul \
 		test_bug490879.xul \
 		test_bug607584.xul \
 		test_bug616590.xul \
 		test_bug635636.html \
 		green.png \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
+
+libs::
 	(cd $(srcdir) && tar $(TAR_CREATE_FLAGS) - browserscope 2> /dev/null) | (cd $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir) && tar -xf -)
 
 libs:: $(_DATA_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)/data
-
-libs:: $(_CHROME_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
-
--- a/editor/libeditor/text/tests/Makefile.in
+++ b/editor/libeditor/text/tests/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = editor/libeditor/text/tests
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
 		test_bug318065.html \
 		test_bug471722.html \
 		test_bug527935.html \
 		test_bug569988.html \
 		test_bug590554.html \
 		test_bug596001.html \
 		test_bug596333.html \
 		test_bug596506.html \
@@ -36,25 +35,21 @@ include $(topsrcdir)/config/rules.mk
 		test_bug740784.html \
 		test_bug757771.html \
 		test_dom_input_event_on_texteditor.html \
 		$(NULL)
 
 # disables the key handling test on gtk2 because gtk2 overrides some key events
 # on our editor, and the combinations depend on the system.
 ifneq ($(MOZ_WIDGET_TOOLKIT),gtk2)
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_texteditor_keyevent_handling.html \
 		$(NULL)
 endif
 
-_CHROME_TEST_FILES = \
+MOCHITEST_CHROME_FILES = \
 		test_bug471319.html \
 		test_bug483651.html \
 		test_bug636465.xul \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
 
-libs:: $(_CHROME_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
-
--- a/embedding/test/Makefile.in
+++ b/embedding/test/Makefile.in
@@ -5,23 +5,21 @@
 
 DEPTH		= ../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = embedding/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
 	test_bug293834.html \
 	bug293834_form.html \
 	320x240.ogv \
 	test_bug449141.html \
 	bug449141_page.html \
 	test_bug499115.html \
 	test_nsFind.html \
 	test_window_open_units.html \
 	$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/extensions/cookie/nsPermissionManager.cpp
+++ b/extensions/cookie/nsPermissionManager.cpp
@@ -15,16 +15,17 @@
 #include "nsTArray.h"
 #include "nsReadableUtils.h"
 #include "nsILineInputStream.h"
 #include "nsIIDNService.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "prprf.h"
 #include "mozilla/storage.h"
 #include "nsXULAppAPI.h"
+#include "nsIPrincipal.h"
 
 static nsPermissionManager *gPermissionManager = nsnull;
 
 using mozilla::dom::ContentParent;
 using mozilla::dom::ContentChild;
 using mozilla::unused; // ha!
 
 static bool
@@ -497,16 +498,29 @@ nsPermissionManager::Add(nsIURI     *aUR
   nsCAutoString host;
   rv = GetHost(aURI, host);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return AddInternal(host, nsDependentCString(aType), aPermission, 0, 
                      aExpireType, aExpireTime, eNotify, eWriteToDB);
 }
 
+NS_IMETHODIMP
+nsPermissionManager::AddFromPrincipal(nsIPrincipal* aPrincipal,
+                                      const char* aType, PRUint32 aPermission,
+                                      PRUint32 aExpireType, PRInt64 aExpireTime)
+{
+  NS_ENSURE_ARG_POINTER(aPrincipal);
+
+  nsCOMPtr<nsIURI> uri;
+  aPrincipal->GetURI(getter_AddRefs(uri));
+
+  return Add(uri, aType, aPermission, aExpireType, aExpireTime);
+}
+
 nsresult
 nsPermissionManager::AddInternal(const nsAFlatCString &aHost,
                                  const nsAFlatCString &aType,
                                  PRUint32              aPermission,
                                  PRInt64               aID,
                                  PRUint32              aExpireType,
                                  PRInt64               aExpireTime,
                                  NotifyOperationType   aNotifyOperation,
@@ -676,16 +690,32 @@ nsPermissionManager::Remove(const nsACSt
                      0,
                      nsIPermissionManager::EXPIRE_NEVER,
                      0,
                      eNotify,
                      eWriteToDB);
 }
 
 NS_IMETHODIMP
+nsPermissionManager::RemoveFromPrincipal(nsIPrincipal* aPrincipal,
+                                         const char* aType)
+{
+  NS_ENSURE_ARG_POINTER(aPrincipal);
+
+  nsCOMPtr<nsIURI> uri;
+  aPrincipal->GetURI(getter_AddRefs(uri));
+  NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);
+
+  nsCAutoString host;
+  uri->GetHost(host);
+
+  return Remove(host, aType);
+}
+
+NS_IMETHODIMP
 nsPermissionManager::RemoveAll()
 {
   ENSURE_NOT_CHILD_PROCESS;
   return RemoveAllInternal(true);
 }
 
 void
 nsPermissionManager::CloseDB(bool aRebuildOnSuccess)
@@ -747,16 +777,42 @@ nsPermissionManager::TestExactPermission
 NS_IMETHODIMP
 nsPermissionManager::TestPermission(nsIURI     *aURI,
                                     const char *aType,
                                     PRUint32   *aPermission)
 {
   return CommonTestPermission(aURI, aType, aPermission, false);
 }
 
+NS_IMETHODIMP
+nsPermissionManager::TestPermissionFromPrincipal(nsIPrincipal* aPrincipal,
+                                                 const char* aType,
+                                                 PRUint32* aPermission)
+{
+  NS_ENSURE_ARG_POINTER(aPrincipal);
+
+  nsCOMPtr<nsIURI> uri;
+  aPrincipal->GetURI(getter_AddRefs(uri));
+
+  return TestPermission(uri, aType, aPermission);
+}
+
+NS_IMETHODIMP
+nsPermissionManager::TestExactPermissionFromPrincipal(nsIPrincipal* aPrincipal,
+                                                      const char* aType,
+                                                      PRUint32* aPermission)
+{
+  NS_ENSURE_ARG_POINTER(aPrincipal);
+
+  nsCOMPtr<nsIURI> uri;
+  aPrincipal->GetURI(getter_AddRefs(uri));
+
+  return TestExactPermission(uri, aType, aPermission);
+}
+
 nsresult
 nsPermissionManager::CommonTestPermission(nsIURI     *aURI,
                                           const char *aType,
                                           PRUint32   *aPermission,
                                           bool        aExactHostMatch)
 {
   NS_ENSURE_ARG_POINTER(aURI);
   NS_ENSURE_ARG_POINTER(aType);
--- a/extensions/cookie/test/Makefile.in
+++ b/extensions/cookie/test/Makefile.in
@@ -8,17 +8,17 @@ topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = extensions/cookie/test
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE          = test_cookies
 
-_TEST_FILES = \
+MOCHITEST_FILES = \
   test_samedomain.html \
   file_testcommon.js \
   file_domain_inner.html \
   file_domain_inner_inner.html \
   test_differentdomain.html \
   test_different_domain_in_hierarchy.html \
   file_domain_hierarchy_inner.html \
   file_domain_hierarchy_inner_inner.html \
@@ -47,26 +47,20 @@ MODULE          = test_cookies
   test_same_base_domain_3.html \
   test_same_base_domain_4.html \
   file_localhost_inner.html \
   test_same_base_domain_5.html \
   test_same_base_domain_6.html \
   file_loopback_inner.html \
   $(NULL)
 
-_BROWSER_TEST_FILES = \
+MOCHITEST_BROWSER_FILES = \
   browser_test_favicon.js \
   $(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs:: $(_BROWSER_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
-
 XPCSHELL_TESTS = unit
 
 # FIXME/bug 575918: out-of-process xpcshell is broken on OS X
 ifneq ($(OS_ARCH),Darwin)
 XPCSHELL_TESTS += unit_ipc
 endif
 
 include $(topsrcdir)/config/rules.mk
--- a/extensions/spellcheck/tests/chrome/Makefile.in
+++ b/extensions/spellcheck/tests/chrome/Makefile.in
@@ -8,15 +8,12 @@ topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = extensions/spellcheck/tests/chrome
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = base map
 
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES = 	test_add_remove_dictionaries.xul \
+MOCHITEST_CHROME_FILES = 	test_add_remove_dictionaries.xul \
 				$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/extensions/spellcheck/tests/chrome/base/Makefile.in
+++ b/extensions/spellcheck/tests/chrome/base/Makefile.in
@@ -5,16 +5,14 @@
 
 DEPTH		= ../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = extensions/spellcheck/tests/chrome/base
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = 	base_utf.dic \
+MOCHITEST_CHROME_FILES = 	base_utf.dic \
 				base_utf.aff \
 				$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/extensions/spellcheck/tests/chrome/map/Makefile.in
+++ b/extensions/spellcheck/tests/chrome/map/Makefile.in
@@ -5,16 +5,14 @@
 
 DEPTH		= ../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = extensions/spellcheck/tests/chrome/map
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = 	maputf.dic \
+MOCHITEST_CHROME_FILES = 	maputf.dic \
 				maputf.aff \
 				$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/extensions/universalchardet/tests/Makefile.in
+++ b/extensions/universalchardet/tests/Makefile.in
@@ -5,21 +5,19 @@
 
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
-include $(topsrcdir)/config/rules.mk
-
 relativesrcdir = extensions/universalchardet/tests
 
-_TEST_FILES =	\
+MOCHITEST_CHROME_FILES =	\
 		CharsetDetectionTests.js \
 		bug9357_text.html \
 		test_bug9357.html \
 		bug171813_text.html \
 		test_bug171813.html \
 		bug306272_text.html \
 		test_bug306272.html \
 		bug421271_text.html \
@@ -40,10 +38,9 @@ relativesrcdir = extensions/universalcha
 		bug631751le_text.html \
 		test_bug631751le.html \
 		bug631751be_text.html \
 		test_bug631751be.html \
 		bug638318_text.html \
 		test_bug638318.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/gfx/tests/Makefile.in
+++ b/gfx/tests/Makefile.in
@@ -11,17 +11,17 @@ relativesrcdir = gfx/tests
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE		= gfx
 MOZILLA_INTERNAL_API = 1
 
 XPCSHELL_TESTS = unit
 
-_TEST_FILES = $(addprefix mochitest/, \
+MOCHITEST_FILES = $(addprefix mochitest/, \
 	test_bug509244.html \
 	test_bug513439.html \
 	test_acceleration.html \
 )
 
 # CPP_UNIT_TESTS disabled for now because they dont work in libxul builds.
 #ifndef BUILD_STATIC_LIBS
 #
@@ -76,13 +76,8 @@ endif
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
 OS_LIBS		+= -framework Cocoa
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
 OS_LIBS		+= $(MOZ_PANGO_LIBS) $(XLIBS)
 CXXFLAGS	+= $(MOZ_PANGO_CFLAGS)
 endif
-
-
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") \
-	    $(DEPTH)/_tests/testing/mochitest/tests/gfx
--- a/image/test/mochitest/Makefile.in
+++ b/image/test/mochitest/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = image/test/mochitest
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =   imgutils.js \
+MOCHITEST_FILES =   imgutils.js \
                 lime100x100.svg \
                 test_bug399925.html \
                 bug399925.gif \
                 schrep.png \
                 bug468160.sjs \
                 test_bug468160.html \
                 red.png \
                 test_bug466586.html \
@@ -62,17 +61,17 @@ include $(topsrcdir)/config/rules.mk
 		error-early.png \
 		test_drawDiscardedImage.html \
                 $(NULL)
 
 # Tests disabled due to intermittent orange
 # test_bug435296.html disabled - See bug 578591
 # test_bug478398.html disabled - See bug 579139
 
-_CHROME_FILES = imgutils.js \
+MOCHITEST_CHROME_FILES = imgutils.js \
                 animationPolling.js \
                 lime-anim-100x100.svg \
                 animation.svg \
                 test_animSVGImage.html \
                 test_animation.html \
                 test_animation2.html \
                 animated-gif-finalframe.gif \
                 animated-gif.gif \
@@ -90,13 +89,9 @@ include $(topsrcdir)/config/rules.mk
                 test_undisplayed_iframe.html \
                 iframe.html \
                 ref-iframe.html \
                 test_net_failedtoprocess.html \
                 invalid.jpg \
                 damon.jpg \
                 $(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs:: $(_CHROME_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/intl/uconv/tests/Makefile.in
+++ b/intl/uconv/tests/Makefile.in
@@ -27,21 +27,19 @@ XPCSHELL_TESTS	= unit
 #ifeq ($(OS_ARCH),WINNT)
 #CPPSRCS		+= convperf.cpp
 #endif
 #
 #SIMPLE_PROGRAMS	= $(CPPSRCS:.cpp=$(BIN_SUFFIX))
 
 relativesrcdir	= intl/uconv/tests
 
-_TEST_FILES =	\
+MOCHITEST_FILES =	\
 		test_bug335816.html \
 		test_long_doc.html \
 		test_singlebyte_overconsumption.html \
 		test_unicode_noncharacterescapes.html \
 		test_unicode_noncharacters_gb18030.html \
 		test_unicode_noncharacters_utf8.html \
 		test_utf8_overconsumption.html \
 		$(NULL)
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
 
 include $(topsrcdir)/config/rules.mk
--- a/js/jsd/test/Makefile.in
+++ b/js/jsd/test/Makefile.in
@@ -8,17 +8,15 @@ topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = js/jsd/test
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE = jsdebug
 
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES = 	test_bug507448.html bug507448.js \
+MOCHITEST_FILES = 	test_bug507448.html bug507448.js \
 		test_bug617870-callhooks.html test-bug617870-callhooks.js jsd-test.js \
 		test_bug638178-execlines.html test-bug638178-execlines.js \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/js/public/TemplateLib.h
+++ b/js/public/TemplateLib.h
@@ -136,16 +136,19 @@ template <> struct IsPodType<bool>      
 template <> struct IsPodType<float>                 { static const bool result = true; };
 template <> struct IsPodType<double>                { static const bool result = true; };
 template <> struct IsPodType<wchar_t>               { static const bool result = true; };
 template <typename T> struct IsPodType<T *>         { static const bool result = true; };
 
 template <bool cond, typename T, T v1, T v2> struct If        { static const T result = v1; };
 template <typename T, T v1, T v2> struct If<false, T, v1, v2> { static const T result = v2; };
 
+template <class T> struct IsPointerType             { static const bool result = false; };
+template <class T> struct IsPointerType<T *>        { static const bool result = true; };
+
 /*
  * Traits class for identifying types that are implicitly barriered.
  */
 template <class T> struct IsRelocatableHeapType { static const bool result = true; };
 
 } /* namespace tl */
 } /* namespace js */
 
new file mode 100644
--- /dev/null
+++ b/js/src/config/makefiles/mochitest.mk
@@ -0,0 +1,60 @@
+# -*- makefile -*-
+# vim:set ts=8 sw=8 sts=8 noet:
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+ifndef INCLUDED_TESTS_MOCHITEST_MK #{
+
+ifdef relativesrcdir
+  mochitestdir = $(DEPTH)/_tests/testing/mochitest/$1/$(relativesrcdir)
+else
+  mochitestdir = $(DEPTH)/_tests/testing/mochitest/$1/$(subst $(topsrcdir),,$(srcdir))
+endif
+
+define mochitest-libs-rule-template
+libs:: $$($(1))
+	$$(INSTALL) $$(foreach f,$$^,"$$(f)") $$(call mochitestdir,$(2))
+endef
+
+# Provide support for modules with such a large number of tests that
+# installing them with a single $(INSTALL) invocation would overflow
+# command-line length limits on some operating systems.
+ifdef MOCHITEST_FILES_PARTS
+ifdef MOCHITEST_FILES
+$(error You must define only one of MOCHITEST_FILES_PARTS or MOCHITEST_FILES)
+endif
+$(foreach part,$(MOCHITEST_FILES_PARTS),$(eval $(call mochitest-libs-rule-template,$(part),tests)))
+endif
+
+ifdef MOCHITEST_FILES
+$(eval $(call mochitest-libs-rule-template,MOCHITEST_FILES,tests))
+endif
+
+ifdef MOCHITEST_CHROME_FILES
+$(eval $(call mochitest-libs-rule-template,MOCHITEST_CHROME_FILES,chrome))
+endif
+
+ifdef MOCHITEST_BROWSER_FILES_PARTS
+ifdef MOCHITEST_BROWSER_FILES
+$(error You must define only one of MOCHITEST_BROWSER_FILES_PARTS or MOCHITEST_BROWSER_FILES)
+endif
+$(foreach part,$(MOCHITEST_BROWSER_FILES_PARTS),$(eval $(call mochitest-libs-rule-template,$(part),browser)))
+endif
+
+ifdef MOCHITEST_BROWSER_FILES
+$(eval $(call mochitest-libs-rule-template,MOCHITEST_BROWSER_FILES,browser))
+endif
+
+ifdef MOCHITEST_A11Y_FILES
+$(eval $(call mochitest-libs-rule-template,MOCHITEST_A11Y_FILES,a11y))
+endif
+
+ifdef MOCHITEST_WEBAPPRT_CHROME_FILES
+$(eval $(call mochitest-libs-rule-template,MOCHITEST_WEBAPPRT_CHROME_FILES,webapprtChrome))
+endif
+
+INCLUDED_TESTS_MOCHITEST_MK := 1
+
+endif #} INCLUDED_TESTS_MOCHITEST_MK
--- a/js/src/config/rules.mk
+++ b/js/src/config/rules.mk
@@ -84,16 +84,20 @@ ifdef ENABLE_TESTS
 # that changes to tests may not be updated and code could assume to pass
 # locally against non-current test code.
 DIRS += $(TEST_DIRS)
 
 ifndef INCLUDED_TESTS_XPCSHELL_MK #{
   include $(topsrcdir)/config/makefiles/xpcshell.mk
 endif #}
 
+ifndef INCLUDED_TESTS_MOCHITEST_MK #{
+  include $(topsrcdir)/config/makefiles/mochitest.mk
+endif #}
+
 ifdef CPP_UNIT_TESTS
 
 # Compile the tests to $(DIST)/bin.  Make lots of niceties available by default
 # through TestHarness.h, by modifying the list of includes and the libs against
 # which stuff links.
 CPPSRCS += $(CPP_UNIT_TESTS)
 SIMPLE_PROGRAMS += $(CPP_UNIT_TESTS:.cpp=$(BIN_SUFFIX))
 INCLUDES += -I$(DIST)/include/testing
@@ -1156,17 +1160,17 @@ ifndef NO_MAKEFILE_RULE
 Makefile: Makefile.in
 	@$(PERL) $(AUTOCONF_TOOLS)/make-makefile -t $(topsrcdir) -d $(DEPTH)
 endif
 
 ifndef NO_SUBMAKEFILES_RULE
 ifdef SUBMAKEFILES
 # VPATH does not work on some machines in this case, so add $(srcdir)
 $(SUBMAKEFILES): % : $(srcdir)/%.in
-	$(PERL) $(AUTOCONF_TOOLS)/make-makefile -t $(topsrcdir) -d $(DEPTH) $@
+	$(if $(subsrcdir),cd $(subsrcdir) && )$(PERL) $(AUTOCONF_TOOLS)/make-makefile -t $(topsrcdir)$(addprefix /,$(subsrcdir)) -d $(DEPTH) $(@:$(subsrcdir)/%=%)
 endif
 endif
 
 ifdef AUTOUPDATE_CONFIGURE
 $(topsrcdir)/configure: $(topsrcdir)/configure.in
 	(cd $(topsrcdir) && $(AUTOCONF)) && (cd $(DEPTH) && ./config.status --recheck)
 endif
 
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -104,19 +104,25 @@ frontend::CompileScript(JSContext *cx, H
     SharedContext sc(cx, scopeChain, /* fun = */ NULL, /* funbox = */ NULL);
 
     TreeContext tc(&parser, &sc, staticLevel, /* bodyid = */ 0);
     if (!tc.init())
         return NULL;
 
     bool savedCallerFun = compileAndGo && callerFrame && callerFrame->isFunctionFrame();
     GlobalObject *globalObject = needScriptGlobal ? GetCurrentGlobal(cx) : NULL;
-    Rooted<JSScript*> script(cx);
-    script = JSScript::Create(cx, savedCallerFun, principals, originPrincipals, compileAndGo,
-                              noScriptRval, globalObject, version, staticLevel);
+    Rooted<JSScript*> script(cx, JSScript::Create(cx,
+                                                  savedCallerFun,
+                                                  principals,
+                                                  originPrincipals,
+                                                  compileAndGo,
+                                                  noScriptRval,
+                                                  globalObject,
+                                                  version,
+                                                  staticLevel));
     if (!script)
         return NULL;
 
     // We can specialize a bit for the given scope chain if that scope chain is the global object.
     JSObject *globalScope = scopeChain && scopeChain == &scopeChain->global() ? (JSObject*) scopeChain : NULL;
     JS_ASSERT_IF(globalScope, globalScope->isNative());
     JS_ASSERT_IF(globalScope, JSCLASS_HAS_GLOBAL_FLAG_AND_SLOTS(globalScope->getClass()));
 
@@ -262,20 +268,25 @@ frontend::CompileFunctionBody(JSContext 
     fun->setArgCount(funsc.bindings.numArgs());
 
     unsigned staticLevel = 0;
     TreeContext funtc(&parser, &funsc, staticLevel, /* bodyid = */ 0);
     if (!funtc.init())
         return false;
 
     GlobalObject *globalObject = fun->getParent() ? &fun->getParent()->global() : NULL;
-    Rooted<JSScript*> script(cx);
-    script = JSScript::Create(cx, /* savedCallerFun = */ false, principals, originPrincipals,
-                              /* compileAndGo = */ false, /* noScriptRval = */ false,
-                              globalObject, version, staticLevel);
+    Rooted<JSScript*> script(cx, JSScript::Create(cx,
+                                                  /* savedCallerFun = */ false,
+                                                  principals,
+                                                  originPrincipals,
+                                                  /* compileAndGo = */ false,
+                                                  /* noScriptRval = */ false,
+                                                  globalObject,
+                                                  version,
+                                                  staticLevel));
     if (!script)
         return false;
 
     StackFrame *nullCallerFrame = NULL;
     BytecodeEmitter funbce(/* parent = */ NULL, &parser, &funsc, script, nullCallerFrame,
                            /* hasGlobalScope = */ false, lineno);
     if (!funbce.init())
         return false;
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -4819,27 +4819,26 @@ EmitFunc(JSContext *cx, BytecodeEmitter 
         SharedContext sc(cx, /* scopeChain = */ NULL, fun, funbox);
         sc.cxFlags = funbox->cxFlags;
         if (bce->sc->funMightAliasLocals())
             sc.setFunMightAliasLocals();  // inherit funMightAliasLocals from parent
         sc.bindings.transfer(&funbox->bindings);
 
         // Inherit most things (principals, version, etc) from the parent.
         GlobalObject *globalObject = fun->getParent() ? &fun->getParent()->global() : NULL;
-        Rooted<JSScript*> script(cx);
         Rooted<JSScript*> parent(cx, bce->script);
-        script = JSScript::Create(cx,
-                                  /* savedCallerFun = */ false,
-                                  parent->principals,
-                                  parent->originPrincipals,
-                                  parent->compileAndGo,
-                                  /* noScriptRval = */ false,
-                                  globalObject,
-                                  parent->getVersion(),
-                                  parent->staticLevel + 1);
+        Rooted<JSScript*> script(cx, JSScript::Create(cx,
+                                                      /* savedCallerFun = */ false,
+                                                      parent->principals,
+                                                      parent->originPrincipals,
+                                                      parent->compileAndGo,
+                                                      /* noScriptRval = */ false,
+                                                      globalObject,
+                                                      parent->getVersion(),
+                                                      parent->staticLevel + 1));
         if (!script)
             return false;
 
         BytecodeEmitter bce2(bce, bce->parser, &sc, script, bce->callerFrame, bce->hasGlobalScope,
                              pn->pn_pos.begin.lineno);
         if (!bce2.init())
             return false;
 
--- a/js/src/gc/Marking.cpp
+++ b/js/src/gc/Marking.cpp
@@ -12,16 +12,18 @@
 #include "gc/Marking.h"
 #include "methodjit/MethodJIT.h"
 
 #include "jsobjinlines.h"
 #include "jsscopeinlines.h"
 
 #include "vm/String-inl.h"
 
+void * const js::NullPtr::constNullValue = NULL;
+
 /*
  * There are two mostly separate mark paths. The first is a fast path used
  * internally in the GC. The second is a slow path used for root marking and
  * for API consumers like the cycle collector or Class::trace implementations.
  *
  * The fast path uses explicit stacks. The basic marking process during a GC is
  * that all roots are pushed on to a mark stack, and then each item on the
  * stack is scanned (possibly pushing more stuff) until the stack is empty.
--- a/js/src/gc/Root.h
+++ b/js/src/gc/Root.h
@@ -9,16 +9,17 @@
 #define jsgc_root_h__
 
 #ifdef __cplusplus
 
 #include "mozilla/TypeTraits.h"
 
 #include "jspubtd.h"
 
+#include "js/TemplateLib.h"
 #include "js/Utility.h"
 
 namespace JS {
 
 /*
  * Moving GC Stack Rooting
  *
  * A moving GC may change the physical location of GC allocated things, even
@@ -62,32 +63,51 @@ namespace JS {
  */
 
 template <typename T> class Rooted;
 
 template <typename T>
 struct RootMethods { };
 
 /*
+ * Handle provides an implicit constructor for NullPtr so that, given:
+ *   foo(Handle<JSObject*> h);
+ * callers can simply write:
+ *   foo(NullPtr());
+ * which avoids creating a Rooted<JSObject*> just to pass NULL.
+ */
+struct NullPtr
+{
+    static void * const constNullValue;
+};
+
+/*
  * Reference to a T that has been rooted elsewhere. This is most useful
  * as a parameter type, which guarantees that the T lvalue is properly
  * rooted. See "Move GC Stack Rooting" above.
  */
 template <typename T>
 class Handle
 {
   public:
     /* Creates a handle from a handle of a type convertible to T. */
     template <typename S>
     Handle(Handle<S> handle,
            typename mozilla::EnableIf<mozilla::IsConvertible<S, T>::value, int>::Type dummy = 0)
     {
         ptr = reinterpret_cast<const T *>(handle.address());
     }
 
+    /* Create a handle for a NULL pointer. */
+    Handle(NullPtr)
+    {
+        typedef typename js::tl::StaticAssert<js::tl::IsPointerType<T>::result>::result _;
+        ptr = reinterpret_cast<const T *>(&NullPtr::constNullValue);
+    }
+
     /*
      * This may be called only if the location of the T is guaranteed
      * to be marked (for some reason other than being a Rooted),
      * e.g., if it is guaranteed to be reachable from an implicit root.
      *
      * Create a Handle from a raw location of a T.
      */
     static Handle fromMarkedLocation(const T *p) {
@@ -358,26 +378,30 @@ public:
 
     ~AssertRootingUnnecessary() {
 #ifdef DEBUG
         SetRootingUnnecessaryForContext(cx, prev);
 #endif
     }
 };
 
+#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
+extern void
+CheckStackRoots(JSContext *cx);
+#endif
+
 /*
  * Hook for dynamic root analysis. Checks the native stack and poisons
  * references to GC things which have not been rooted.
  */
 inline void MaybeCheckStackRoots(JSContext *cx)
 {
 #ifdef DEBUG
     JS_ASSERT(!IsRootingUnnecessaryForContext(cx));
 # if defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
-    void CheckStackRoots(JSContext *cx);
     CheckStackRoots(cx);
 # endif
 #endif
 }
 
 }  /* namespace JS */
 
 #endif  /* __cplusplus */
--- a/js/src/jsarray.cpp
+++ b/js/src/jsarray.cpp
@@ -475,17 +475,16 @@ SetArrayElement(JSContext *cx, HandleObj
         if (result == JSObject::ED_FAILED)
             return false;
         JS_ASSERT(result == JSObject::ED_SPARSE);
         if (!JSObject::makeDenseArraySlow(cx, obj))
             return JS_FALSE;
     }
 
     RootedId id(cx);
-
     if (!IndexToId(cx, obj, index, NULL, id.address(), JS_TRUE))
         return JS_FALSE;
     JS_ASSERT(!JSID_IS_VOID(id));
 
     RootedValue tmp(cx, v);
     return obj->setGeneric(cx, obj, id, tmp.address(), true);
 }
 
@@ -1812,48 +1811,16 @@ InitArrayElements(JSContext *cx, HandleO
             return false;
         }
         idval.getDoubleRef() += 1;
     } while (vector != end);
 
     return true;
 }
 
-#if 0
-static JSBool
-InitArrayObject(JSContext *cx, JSObject *obj, uint32_t length, const Value *vector)
-{
-    JS_ASSERT(obj->isArray());
-
-    JS_ASSERT(obj->isDenseArray());
-    obj->setArrayLength(cx, length);
-    if (!vector || !length)
-        return true;
-
-    if (!InitArrayTypes(cx, obj->getType(cx), vector, length))
-        return false;
-
-    /* Avoid ensureDenseArrayElements to skip sparse array checks there. */
-    if (!obj->ensureElements(cx, length))
-        return false;
-
-    obj->setDenseArrayInitializedLength(length);
-
-    bool hole = false;
-    for (uint32_t i = 0; i < length; i++) {
-        obj->setDenseArrayElement(i, vector[i]);
-        hole |= vector[i].isMagic(JS_ARRAY_HOLE);
-    }
-    if (hole)
-        obj->markDenseArrayNotPacked(cx);
-
-    return true;
-}
-#endif
-
 /*
  * Perl-inspired join, reverse, and sort.
  */
 static JSBool
 array_join(JSContext *cx, unsigned argc, Value *vp)
 {
     JS_CHECK_RECURSION(cx, return false);
 
@@ -3682,27 +3649,24 @@ js_Array(JSContext *cx, unsigned argc, V
     return true;
 }
 
 JSObject *
 js_InitArrayClass(JSContext *cx, JSObject *obj)
 {
     JS_ASSERT(obj->isNative());
 
-    Rooted<GlobalObject*> global(cx);
-    global = &obj->asGlobal();
-
-    RootedObject arrayProto(cx);
-    arrayProto = global->createBlankPrototype(cx, &SlowArrayClass);
+    Rooted<GlobalObject*> global(cx, &obj->asGlobal());
+
+    RootedObject arrayProto(cx, global->createBlankPrototype(cx, &SlowArrayClass));
     if (!arrayProto || !AddLengthProperty(cx, arrayProto))
         return NULL;
     arrayProto->setArrayLength(cx, 0);
 
-    RootedFunction ctor(cx);
-    ctor = global->createConstructor(cx, js_Array, CLASS_NAME(cx, Array), 1);
+    RootedFunction ctor(cx, global->createConstructor(cx, js_Array, CLASS_NAME(cx, Array), 1));
     if (!ctor)
         return NULL;
 
     /*
      * The default 'new' type of Array.prototype is required by type inference
      * to have unknown properties, to simplify handling of e.g. heterogenous
      * arrays in JSON and script literals and allows setDenseArrayElement to
      * be used without updating the indexed type set for such default arrays.
@@ -3773,29 +3737,26 @@ NewArray(JSContext *cx, uint32_t length,
     }
 
     Rooted<GlobalObject*> parent(cx, parent_);
     RootedObject proto(cx, proto_);
 
     if (!proto && !FindProto(cx, &ArrayClass, parent, &proto))
         return NULL;
 
-    RootedTypeObject type(cx);
-
-    type = proto->getNewType(cx);
+    RootedTypeObject type(cx, proto->getNewType(cx));
     if (!type)
         return NULL;
 
     /*
      * Get a shape with zero fixed slots, regardless of the size class.
      * See JSObject::createDenseArray.
      */
-    RootedShape shape(cx);
-    shape = EmptyShape::getInitialShape(cx, &ArrayClass, proto,
-                                        parent, gc::FINALIZE_OBJECT0);
+    RootedShape shape(cx, EmptyShape::getInitialShape(cx, &ArrayClass, proto,
+                                                      parent, gc::FINALIZE_OBJECT0));
     if (!shape)
         return NULL;
 
     JSObject* obj = JSObject::createDenseArray(cx, kind, shape, type, length);
     if (!obj)
         return NULL;
 
     if (entry != -1)
--- a/js/src/jsbool.cpp
+++ b/js/src/jsbool.cpp
@@ -128,18 +128,17 @@ js_InitBooleanClass(JSContext *cx, JSObj
 
     Rooted<GlobalObject*> global(cx, &obj->asGlobal());
 
     RootedObject booleanProto (cx, global->createBlankPrototype(cx, &BooleanClass));
     if (!booleanProto)
         return NULL;
     booleanProto->setFixedSlot(BooleanObject::PRIMITIVE_VALUE_SLOT, BooleanValue(false));
 
-    RootedFunction ctor(cx);
-    ctor = global->createConstructor(cx, Boolean, CLASS_NAME(cx, Boolean), 1);
+    RootedFunction ctor(cx, global->createConstructor(cx, Boolean, CLASS_NAME(cx, Boolean), 1));
     if (!ctor)
         return NULL;
 
     if (!LinkConstructorAndPrototype(cx, ctor, booleanProto))
         return NULL;
 
     if (!DefinePropertiesAndBrand(cx, booleanProto, NULL, boolean_methods))
         return NULL;
--- a/js/src/jscntxtinlines.h
+++ b/js/src/jscntxtinlines.h
@@ -473,22 +473,16 @@ CallSetter(JSContext *cx, HandleObject o
     if (!(attrs & JSPROP_SHORTID))
         return CallJSPropertyOpSetter(cx, op, obj, id, strict, vp);
 
     RootedId nid(cx, INT_TO_JSID(shortid));
 
     return CallJSPropertyOpSetter(cx, op, obj, nid, strict, vp);
 }
 
-static inline HeapPtrAtom *
-FrameAtomBase(JSContext *cx, js::StackFrame *fp)
-{
-    return fp->script()->atoms;
-}
-
 }  /* namespace js */
 
 inline JSVersion
 JSContext::findVersion() const
 {
     if (hasVersionOverride)
         return versionOverride;
 
--- a/js/src/jscompartment.cpp
+++ b/js/src/jscompartment.cpp
@@ -171,19 +171,18 @@ JSCompartment::wrap(JSContext *cx, Value
     if (vp->isObject()) {
         Rooted<JSObject*> obj(cx, &vp->toObject());
 
         if (obj->compartment() == this)
             return WrapForSameCompartment(cx, obj, vp);
 
         /* Translate StopIteration singleton. */
         if (obj->isStopIteration()) {
-            RootedObject null(cx);
             RootedValue vvp(cx, *vp);
-            bool result = js_FindClassObject(cx, null, JSProto_StopIteration, &vvp);
+            bool result = js_FindClassObject(cx, NullPtr(), JSProto_StopIteration, &vvp);
             *vp = vvp;
             return result;
         }
 
         /* Unwrap the object, but don't unwrap outer windows. */
         obj = UnwrapObject(&vp->toObject(), /* stopAtOuter = */ true, &flags);
 
         if (obj->compartment() == this)
--- a/js/src/jsdate.cpp
+++ b/js/src/jsdate.cpp
@@ -3057,18 +3057,17 @@ js_InitDateClass(JSContext *cx, JSObject
 
     Rooted<GlobalObject*> global(cx, &obj->asGlobal());
 
     RootedObject dateProto(cx, global->createBlankPrototype(cx, &DateClass));
     if (!dateProto)
         return NULL;
     SetDateToNaN(cx, dateProto);
 
-    RootedFunction ctor(cx);
-    ctor = global->createConstructor(cx, js_Date, CLASS_NAME(cx, Date), MAXARGS);
+    RootedFunction ctor(cx, global->createConstructor(cx, js_Date, CLASS_NAME(cx, Date), MAXARGS));
     if (!ctor)
         return NULL;
 
     if (!LinkConstructorAndPrototype(cx, ctor, dateProto))
         return NULL;
 
     if (!DefinePropertiesAndBrand(cx, ctor, NULL, date_static_methods))
         return NULL;
--- a/js/src/jsexn.cpp
+++ b/js/src/jsexn.cpp
@@ -792,19 +792,18 @@ InitErrorClass(JSContext *cx, Handle<Glo
                               JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE, 0, 0) ||
         !DefineNativeProperty(cx, errorProto, lineNumberId, Int32Value(0),
                               JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE, 0, 0))
     {
         return NULL;
     }
 
     /* Create the corresponding constructor. */
-    RootedFunction ctor(cx);
-    ctor = global->createConstructor(cx, Exception, name, 1,
-                                     JSFunction::ExtendedFinalizeKind);
+    RootedFunction ctor(cx, global->createConstructor(cx, Exception, name, 1,
+                                                      JSFunction::ExtendedFinalizeKind));
     if (!ctor)
         return NULL;
     ctor->setExtendedSlot(0, Int32Value(int32_t(type)));
 
     if (!LinkConstructorAndPrototype(cx, ctor, errorProto))
         return NULL;
 
     if (!DefineConstructorAndPrototype(cx, global, key, ctor, errorProto))
@@ -823,18 +822,17 @@ js_InitExceptionClasses(JSContext *cx, J
 
     Rooted<GlobalObject*> global(cx, &obj->asGlobal());
 
     RootedObject objectProto(cx, global->getOrCreateObjectPrototype(cx));
     if (!objectProto)
         return NULL;
 
     /* Initialize the base Error class first. */
-    RootedObject errorProto(cx);
-    errorProto = InitErrorClass(cx, global, JSEXN_ERR, objectProto);
+    RootedObject errorProto(cx, InitErrorClass(cx, global, JSEXN_ERR, objectProto));
     if (!errorProto)
         return NULL;
 
     /* |Error.prototype| alone has method properties. */
     if (!DefinePropertiesAndBrand(cx, errorProto, NULL, exception_methods))
         return NULL;
 
     /* Define all remaining *Error constructors. */
@@ -958,19 +956,18 @@ js_ErrorToException(JSContext *cx, const
     PodArrayZero(tv);
     AutoArrayRooter tvr(cx, ArrayLength(tv), tv);
 
     /*
      * Try to get an appropriate prototype by looking up the corresponding
      * exception constructor name in the scope chain of the current context's
      * top stack frame, or in the global object if no frame is active.
      */
-    RootedObject null(cx);
     RootedObject errProto(cx);
-    if (!js_GetClassPrototype(cx, null, GetExceptionProtoKey(exn), &errProto))
+    if (!js_GetClassPrototype(cx, NullPtr(), GetExceptionProtoKey(exn), &errProto))
         return false;
     tv[0] = OBJECT_TO_JSVAL(errProto);
 
     RootedObject errObject(cx, NewObjectWithGivenProto(cx, &ErrorClass, errProto, NULL));
     if (!errObject)
         return false;
     tv[1] = OBJECT_TO_JSVAL(errObject);
 
@@ -1018,17 +1015,16 @@ IsDuckTypedErrorObject(JSContext *cx, Ha
     return true;
 }
 
 JSBool
 js_ReportUncaughtException(JSContext *cx)
 {
     jsval roots[6];
     JSErrorReport *reportp, report;
-    RootedString str(cx);
 
     if (!JS_IsExceptionPending(cx))
         return true;
 
     RootedValue exn(cx);
     if (!JS_GetPendingException(cx, exn.address()))
         return false;
 
@@ -1048,17 +1044,17 @@ js_ReportUncaughtException(JSContext *cx
         exnObject = JSVAL_TO_OBJECT(exn);
         roots[0] = exn;
     }
 
     JS_ClearPendingException(cx);
     reportp = js_ErrorFromException(cx, exn);
 
     /* XXX L10N angels cry once again. see also everywhere else */
-    str = ToString(cx, exn);
+    RootedString str(cx, ToString(cx, exn));
     if (str)
         roots[1] = StringValue(str);
 
     const char *filename_str = js_fileName_str;
     JSAutoByteString filename;
     if (!reportp && exnObject &&
         (exnObject->isError() ||
          IsDuckTypedErrorObject(cx, exnObject, &filename_str)))
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -243,19 +243,18 @@ JS_DefineFunctionsWithHelp(JSContext *cx
 
     CHECK_REQUEST(cx);
     assertSameCompartment(cx, obj);
     for (; fs->name; fs++) {
         JSAtom *atom = js_Atomize(cx, fs->name, strlen(fs->name));
         if (!atom)
             return false;
 
-        RootedFunction fun(cx);
         Rooted<jsid> id(cx, AtomToId(atom));
-        fun = js_DefineFunction(cx, obj, id, fs->call, fs->nargs, fs->flags);
+        RootedFunction fun(cx, js_DefineFunction(cx, obj, id, fs->call, fs->nargs, fs->flags));
         if (!fun)
             return false;
 
         if (fs->usage) {
             if (!DefineHelpProperty(cx, fun, "usage", fs->usage))
                 return false;
         }
 
--- a/js/src/jsfun.cpp
+++ b/js/src/jsfun.cpp
@@ -255,18 +255,17 @@ ResolveInterpretedFunctionPrototype(JSCo
 
 static JSBool
 fun_resolve(JSContext *cx, HandleObject obj, HandleId id, unsigned flags,
             MutableHandleObject objp)
 {
     if (!JSID_IS_ATOM(id))
         return true;
 
-    RootedFunction fun(cx);
-    fun = obj->toFunction();
+    RootedFunction fun(cx, obj->toFunction());
 
     if (JSID_IS_ATOM(id, cx->runtime->atomState.classPrototypeAtom)) {
         /*
          * Native or "built-in" functions do not have a .prototype property per
          * ECMA-262, or (Object.prototype, Function.prototype, etc.) have that
          * property created eagerly.
          *
          * ES5 15.3.4: the non-native function object named Function.prototype
@@ -905,30 +904,27 @@ fun_bind(JSContext *cx, unsigned argc, V
     Value &thisv = args.thisv();
 
     /* Step 2. */
     if (!js_IsCallable(thisv)) {
         ReportIncompatibleMethod(cx, args, &FunctionClass);
         return false;
     }
 
-    RootedObject target(cx);
-    target = &thisv.toObject();
-
     /* Step 3. */
     Value *boundArgs = NULL;
     unsigned argslen = 0;
     if (args.length() > 1) {
         boundArgs = args.array() + 1;
         argslen = args.length() - 1;
     }
 
     /* Steps 7-9. */
     RootedValue thisArg(cx, args.length() >= 1 ? args[0] : UndefinedValue());
-
+    RootedObject target(cx, &thisv.toObject());
     JSObject *boundFunction = js_fun_bind(cx, target, thisArg, boundArgs, argslen);
     if (!boundFunction)
         return false;
 
     /* Step 22. */
     args.rval().setObject(*boundFunction);
     return true;
 }
@@ -943,19 +939,18 @@ js_fun_bind(JSContext *cx, HandleObject 
         unsigned nargs = target->toFunction()->nargs;
         if (nargs > argslen)
             length = nargs - argslen;
     }
 
     /* Step 4-6, 10-11. */
     JSAtom *name = target->isFunction() ? target->toFunction()->atom.get() : NULL;
 
-    RootedObject funobj(cx);
-    funobj = js_NewFunction(cx, NULL, CallOrConstructBoundFunction, length,
-                            JSFUN_CONSTRUCTOR, target, name);
+    RootedObject funobj(cx, js_NewFunction(cx, NULL, CallOrConstructBoundFunction, length,
+                                           JSFUN_CONSTRUCTOR, target, name));
     if (!funobj)
         return NULL;
 
     /* NB: Bound functions abuse |parent| to store their target. */
     if (!JSObject::setParent(cx, funobj, target))
         return NULL;
 
     if (!funobj->toFunction()->initBoundFunction(cx, thisArg, boundArgs, argslen))
@@ -997,18 +992,17 @@ JSFunctionSpec function_methods[] = {
 };
 
 JSBool
 Function(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     /* Block this call if security callbacks forbid it. */
-    Rooted<GlobalObject*> global(cx);
-    global = &args.callee().global();
+    Rooted<GlobalObject*> global(cx, &args.callee().global());
     if (!global->isRuntimeCodeGenEnabled(cx)) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CSP_BLOCKED_FUNCTION);
         return false;
     }
 
     Bindings bindings;
     Bindings::AutoRooter bindingsRoot(cx, &bindings);
 
@@ -1207,27 +1201,26 @@ JSFunction *
 js_NewFunction(JSContext *cx, JSObject *funobj, Native native, unsigned nargs,
                unsigned flags, HandleObject parent, JSAtom *atom_, js::gc::AllocKind kind)
 {
     JS_ASSERT(kind == JSFunction::FinalizeKind || kind == JSFunction::ExtendedFinalizeKind);
     JS_ASSERT(sizeof(JSFunction) <= gc::Arena::thingSize(JSFunction::FinalizeKind));
     JS_ASSERT(sizeof(FunctionExtended) <= gc::Arena::thingSize(JSFunction::ExtendedFinalizeKind));
 
     RootedAtom atom(cx, atom_);
-    RootedFunction fun(cx);
 
     if (funobj) {
         JS_ASSERT(funobj->isFunction());
         JS_ASSERT(funobj->getParent() == parent);
     } else {
         funobj = NewObjectWithClassProto(cx, &FunctionClass, NULL, SkipScopeParent(parent), kind);
         if (!funobj)
             return NULL;
     }
-    fun = static_cast<JSFunction *>(funobj);
+    RootedFunction fun(cx, static_cast<JSFunction *>(funobj));
 
     /* Initialize all function members. */
     fun->nargs = uint16_t(nargs);
     fun->flags = flags & (JSFUN_FLAGS_MASK | JSFUN_KINDMASK);
     if ((flags & JSFUN_KINDMASK) >= JSFUN_INTERPRETED) {
         JS_ASSERT(!native);
         fun->mutableScript().init(NULL);
         fun->initEnvironment(parent);
--- a/js/src/jsinfer.cpp
+++ b/js/src/jsinfer.cpp
@@ -4565,18 +4565,17 @@ AnalyzePoppedThis(JSContext *cx, Vector<
  */
 static void
 CheckNewScriptProperties(JSContext *cx, HandleTypeObject type, JSFunction *fun)
 {
     if (type->unknownProperties() || fun->script()->isInnerFunction)
         return;
 
     /* Strawman object to add properties to and watch for duplicates. */
-    RootedObject baseobj(cx);
-    baseobj = NewBuiltinClassInstance(cx, &ObjectClass, gc::FINALIZE_OBJECT16);
+    RootedObject baseobj(cx, NewBuiltinClassInstance(cx, &ObjectClass, gc::FINALIZE_OBJECT16));
     if (!baseobj) {
         if (type->newScript)
             type->clearNewScript(cx);
         return;
     }
 
     Vector<TypeNewScript::Initializer> initializerList(cx);
     AnalyzeNewScriptProperties(cx, type, fun, baseobj.address(), &initializerList);
--- a/js/src/jsinterp.cpp
+++ b/js/src/jsinterp.cpp
@@ -1145,30 +1145,16 @@ js::Interpret(JSContext *cx, StackFrame 
 # define END_VARLEN_CASE    goto advance_pc;
 # define ADD_EMPTY_CASE(OP) BEGIN_CASE(OP)
 # define END_EMPTY_CASES    goto advance_pc_by_one;
 
 #endif /* !JS_THREADED_INTERP */
 
 #define ENABLE_INTERRUPTS() (interruptEnabler.enableInterrupts())
 
-#define LOAD_ATOM(PCOFF, atom)                                                \
-    JS_BEGIN_MACRO                                                            \
-        JS_ASSERT((size_t)(atoms - script->atoms) <                           \
-                  (size_t)(script->natoms - GET_UINT32_INDEX(regs.pc + PCOFF)));\
-        atom = atoms[GET_UINT32_INDEX(regs.pc + PCOFF)];                      \
-    JS_END_MACRO
-
-#define LOAD_NAME(PCOFF, name)                                                \
-    JS_BEGIN_MACRO                                                            \
-        JSAtom *atom;                                                         \
-        LOAD_ATOM((PCOFF), atom);                                             \
-        name = atom->asPropertyName();                                        \
-    JS_END_MACRO
-
 #define LOAD_DOUBLE(PCOFF, dbl)                                               \
     (dbl = script->getConst(GET_UINT32_INDEX(regs.pc + (PCOFF))).toDouble())
 
 #if defined(JS_METHODJIT)
     bool useMethodJIT = false;
 #endif
 
 #ifdef JS_METHODJIT
@@ -1184,43 +1170,30 @@ js::Interpret(JSContext *cx, StackFrame 
 #define CHECK_PARTIAL_METHODJIT(status)                                       \
     JS_BEGIN_MACRO                                                            \
         switch (status) {                                                     \
           case mjit::Jaeger_UnfinishedAtTrap:                                 \
             interpMode = JSINTERP_SKIP_TRAP;                                  \
             /* FALLTHROUGH */                                                 \
           case mjit::Jaeger_Unfinished:                                       \
             op = (JSOp) *regs.pc;                                             \
-            RESTORE_INTERP_VARS_CHECK_EXCEPTION();                            \
+            SET_SCRIPT(regs.fp()->script());                                  \
+            if (cx->isExceptionPending())                                     \
+                goto error;                                                   \
             DO_OP();                                                          \
           default:;                                                           \
         }                                                                     \
     JS_END_MACRO
 
 #else
 
 #define RESET_USE_METHODJIT() ((void) 0)
 
 #endif
 
-#define RESTORE_INTERP_VARS()                                                 \
-    JS_BEGIN_MACRO                                                            \
-        SET_SCRIPT(regs.fp()->script());                                      \
-        atoms = FrameAtomBase(cx, regs.fp());                                 \
-        JS_ASSERT(&cx->regs() == &regs);                                      \
-    JS_END_MACRO
-
-#define RESTORE_INTERP_VARS_CHECK_EXCEPTION()                                 \
-    JS_BEGIN_MACRO                                                            \
-        RESTORE_INTERP_VARS();                                                \
-        if (cx->isExceptionPending())                                         \
-            goto error;                                                       \
-        CHECK_INTERRUPT_HANDLER();                                            \
-    JS_END_MACRO
-
     /*
      * Prepare to call a user-supplied branch handler, and abort the script
      * if it returns false.
      */
 #define CHECK_BRANCH()                                                        \
     JS_BEGIN_MACRO                                                            \
         if (cx->runtime->interrupt && !js_HandleExecutionInterrupt(cx))       \
             goto error;                                                       \
@@ -1285,25 +1258,16 @@ js::Interpret(JSContext *cx, StackFrame 
     RootedShape rootShape0(cx);
 
     if (rt->profilingScripts)
         ENABLE_INTERRUPTS();
 
     if (!entryFrame)
         entryFrame = regs.fp();
 
-    /*
-     * Initialize the index segment register used by LOAD_ATOM and
-     * GET_FULL_INDEX macros below. As a register we use a pointer based on
-     * the atom map to turn frequently executed LOAD_ATOM into simple array
-     * access. For less frequent object loads we have to recover the segment
-     * from atoms pointer first.
-     */
-    HeapPtrAtom *atoms = script->atoms;
-
 #if JS_HAS_GENERATORS
     if (JS_UNLIKELY(regs.fp()->isGeneratorFrame())) {
         JS_ASSERT(size_t(regs.pc - script->code) <= script->length);
         JS_ASSERT(regs.stackDepth() <= script->nslots);
 
         /*
          * To support generator_throw and to catch ignored exceptions,
          * fail if cx->isExceptionPending() is true.
@@ -1622,18 +1586,17 @@ BEGIN_CASE(JSOP_STOP)
 #ifdef JS_METHODJIT
   jit_return:
 #endif
 
         /* The results of lowered call/apply frames need to be shifted. */
         bool shiftResult = regs.fp()->loweredCallOrApply();
 
         cx->stack.popInlineFrame(regs);
-
-        RESTORE_INTERP_VARS();
+        SET_SCRIPT(regs.fp()->script());
 
         JS_ASSERT(*regs.pc == JSOP_NEW || *regs.pc == JSOP_CALL ||
                   *regs.pc == JSOP_FUNCALL || *regs.pc == JSOP_FUNAPPLY);
 
         /* Resume execution in the calling frame. */
         RESET_USE_METHODJIT();
         if (JS_LIKELY(interpReturnOK)) {
             TypeScript::Monitor(cx, script, regs.pc, regs.sp[-1]);
@@ -1845,18 +1808,19 @@ BEGIN_CASE(JSOP_PICK)
     Value lval = regs.sp[-int(i + 1)];
     memmove(regs.sp - (i + 1), regs.sp - i, sizeof(Value) * i);
     regs.sp[-1] = lval;
 }
 END_CASE(JSOP_PICK)
 
 BEGIN_CASE(JSOP_SETCONST)
 {
-    PropertyName *name;
-    LOAD_NAME(0, name);
+    RootedPropertyName &name = rootName0;
+    name = script->getName(regs.pc);
+
     JSObject &obj = regs.fp()->varObj();
     const Value &ref = regs.sp[-1];
     if (!obj.defineProperty(cx, name, ref,
                             JS_PropertyStub, JS_StrictPropertyStub,
                             JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY)) {
         goto error;
     }
 }
@@ -1904,17 +1868,17 @@ BEGIN_CASE(JSOP_BINDNAME)
          * the rhs. We desire such resolve hook equivalence between the two
          * forms.
          */
         obj = regs.fp()->scopeChain();
         if (obj->isGlobal())
             break;
 
         RootedPropertyName &name = rootName0;
-        LOAD_NAME(0, name);
+        name = script->getName(regs.pc);
 
         RootedObject &scopeChain = rootObject0;
         scopeChain = regs.fp()->scopeChain();
 
         obj = FindIdentifierBase(cx, scopeChain, name);
         if (!obj)
             goto error;
     } while (0);
@@ -2204,17 +2168,17 @@ BEGIN_CASE(JSOP_POS)
         goto error;
     if (!regs.sp[-1].isInt32())
         TypeScript::MonitorOverflow(cx, script, regs.pc);
 END_CASE(JSOP_POS)
 
 BEGIN_CASE(JSOP_DELNAME)
 {
     RootedPropertyName &name = rootName0;
-    LOAD_NAME(0, name);
+    name = script->getName(regs.pc);
 
     RootedObject &scopeObj = rootObject0;
     scopeObj = cx->stack.currentScriptedScopeChain();
 
     RootedObject &obj = rootObject1;
     RootedObject &obj2 = rootObject2;
     RootedShape &prop = rootShape0;
     if (!FindProperty(cx, name, scopeObj, &obj, &obj2, &prop))
@@ -2230,17 +2194,17 @@ BEGIN_CASE(JSOP_DELNAME)
             goto error;
     }
 }
 END_CASE(JSOP_DELNAME)
 
 BEGIN_CASE(JSOP_DELPROP)
 {
     RootedPropertyName &name = rootName0;
-    LOAD_NAME(0, name);
+    name = script->getName(regs.pc);
 
     JSObject *obj;
     FETCH_OBJECT(cx, -1, obj);
 
     RootedValue &rval = rootValue0;
     if (!obj->deleteProperty(cx, name, rval.address(), script->strictModeCode))
         goto error;
 
@@ -2493,17 +2457,17 @@ BEGIN_CASE(JSOP_FUNCALL)
     if (newScript->compileAndGo && newScript->hasClearedGlobal()) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CLEARED_SCOPE);
         goto error;
     }
 
     if (!cx->stack.pushInlineFrame(cx, regs, args, *fun, newScript, initial))
         goto error;
 
-    RESTORE_INTERP_VARS();
+    SET_SCRIPT(regs.fp()->script());
     RESET_USE_METHODJIT();
 
     bool newType = cx->typeInferenceEnabled() && UseNewType(cx, script, regs.pc);
 
 #ifdef JS_METHODJIT
     if (!newType) {
         /* Try to ensure methods are method JIT'd.  */
         mjit::CompileStatus status = mjit::CanMethodJIT(cx, script, script->code,
@@ -2550,17 +2514,17 @@ BEGIN_CASE(JSOP_SETCALL)
     JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_LEFTSIDE_OF_ASS);
     goto error;
 }
 END_CASE(JSOP_SETCALL)
 
 BEGIN_CASE(JSOP_IMPLICITTHIS)
 {
     RootedPropertyName &name = rootName0;
-    LOAD_NAME(0, name);
+    name = script->getName(regs.pc);
 
     RootedObject &scopeObj = rootObject0;
     scopeObj = cx->stack.currentScriptedScopeChain();
 
     RootedObject &obj = rootObject1;
     RootedObject &obj2 = rootObject2;
     RootedShape &prop = rootShape0;
     if (!FindPropertyHelper(cx, name, false, scopeObj, &obj, &obj2, &prop))
@@ -2608,27 +2572,21 @@ BEGIN_CASE(JSOP_DOUBLE)
 {
     double dbl;
     LOAD_DOUBLE(0, dbl);
     PUSH_DOUBLE(dbl);
 }
 END_CASE(JSOP_DOUBLE)
 
 BEGIN_CASE(JSOP_STRING)
-{
-    JSAtom *atom;
-    LOAD_ATOM(0, atom);
-    PUSH_STRING(atom);
-}
+    PUSH_STRING(script->getAtom(regs.pc));
 END_CASE(JSOP_STRING)
 
 BEGIN_CASE(JSOP_OBJECT)
-{
-    PUSH_OBJECT(*script->getObject(GET_UINT32_INDEX(regs.pc)));
-}
+    PUSH_OBJECT(*script->getObject(regs.pc));
 END_CASE(JSOP_OBJECT)
 
 BEGIN_CASE(JSOP_REGEXP)
 {
     /*
      * Push a regexp object cloned from the regexp literal object mapped by the
      * bytecode at pc.
      */
@@ -2706,17 +2664,16 @@ BEGIN_CASE(JSOP_LOOKUPSWITCH)
 {
     int32_t off;
     off = JUMP_OFFSET_LEN;
 
     /*
      * JSOP_LOOKUPSWITCH are never used if any atom index in it would exceed
      * 64K limit.
      */
-    JS_ASSERT(atoms == script->atoms);
     jsbytecode *pc2 = regs.pc;
 
     Value lval = regs.sp[-1];
     regs.sp--;
 
     int npairs;
     if (!lval.isPrimitive())
         goto end_lookup_switch;
@@ -2857,30 +2814,28 @@ BEGIN_CASE(JSOP_SETLOCAL)
     unsigned i = GET_SLOTNO(regs.pc);
     regs.fp()->unaliasedLocal(i) = regs.sp[-1];
 }
 END_CASE(JSOP_SETLOCAL)
 
 BEGIN_CASE(JSOP_DEFCONST)
 BEGIN_CASE(JSOP_DEFVAR)
 {
-    PropertyName *dn = atoms[GET_UINT32_INDEX(regs.pc)]->asPropertyName();
-
     /* ES5 10.5 step 8 (with subsequent errata). */
     unsigned attrs = JSPROP_ENUMERATE;
     if (!regs.fp()->isEvalFrame())
         attrs |= JSPROP_PERMANENT;
     if (op == JSOP_DEFCONST)
         attrs |= JSPROP_READONLY;
 
     /* Step 8b. */
     RootedObject &obj = rootObject0;
     obj = &regs.fp()->varObj();
 
-    if (!DefVarOrConstOperation(cx, obj, dn, attrs))
+    if (!DefVarOrConstOperation(cx, obj, script->getName(regs.pc), attrs))
         goto error;
 }
 END_CASE(JSOP_DEFVAR)
 
 BEGIN_CASE(JSOP_DEFFUN)
 {
     /*
      * A top-level function defined in Global or Eval code (see ECMA-262
@@ -3010,42 +2965,34 @@ BEGIN_CASE(JSOP_SETTER)
     JSOp op2 = JSOp(*++regs.pc);
     RootedId &id = rootId0;
     Value rval;
     int i;
     JSObject *obj;
     switch (op2) {
       case JSOP_SETNAME:
       case JSOP_SETPROP:
-      {
-        PropertyName *name;
-        LOAD_NAME(0, name);
-        id = NameToId(name);
+        id = NameToId(script->getName(regs.pc));
         rval = regs.sp[-1];
         i = -1;
         goto gs_pop_lval;
-      }
       case JSOP_SETELEM:
         rval = regs.sp[-1];
         id = JSID_VOID;
         i = -2;
       gs_pop_lval:
         FETCH_OBJECT(cx, i - 1, obj);
         break;
 
       case JSOP_INITPROP:
-      {
         JS_ASSERT(regs.stackDepth() >= 2);
         rval = regs.sp[-1];
         i = -1;
-        PropertyName *name;
-        LOAD_NAME(0, name);
-        id = NameToId(name);
+        id = NameToId(script->getName(regs.pc));
         goto gs_get_lval;
-      }
       default:
         JS_ASSERT(op2 == JSOP_INITELEM);
         JS_ASSERT(regs.stackDepth() >= 3);
         rval = regs.sp[-1];
         id = JSID_VOID;
         i = -2;
       gs_get_lval:
       {
@@ -3140,17 +3087,17 @@ BEGIN_CASE(JSOP_NEWARRAY)
 
     CHECK_INTERRUPT_HANDLER();
 }
 END_CASE(JSOP_NEWARRAY)
 
 BEGIN_CASE(JSOP_NEWOBJECT)
 {
     RootedObject &baseobj = rootObject0;
-    baseobj = script->getObject(GET_UINT32_INDEX(regs.pc));
+    baseobj = script->getObject(regs.pc);
 
     RootedObject &obj = rootObject1;
     obj = CopyInitializerObject(cx, baseobj);
     if (!obj || !SetInitializerObjectType(cx, script, regs.pc, obj))
         goto error;
 
     PUSH_OBJECT(*obj);
     TypeScript::Monitor(cx, script, regs.pc, regs.sp[-1]);
@@ -3173,20 +3120,19 @@ BEGIN_CASE(JSOP_INITPROP)
     JS_ASSERT(regs.stackDepth() >= 2);
     Value rval = regs.sp[-1];
 
     /* Load the object being initialized into lval/obj. */
     RootedObject &obj = rootObject0;
     obj = &regs.sp[-2].toObject();
     JS_ASSERT(obj->isObject());
 
+    PropertyName *name = script->getName(regs.pc);
+
     RootedId &id = rootId0;
-
-    PropertyName *name;
-    LOAD_NAME(0, name);
     id = NameToId(name);
 
     if (JS_UNLIKELY(name == cx->runtime->atomState.protoAtom)
         ? !baseops::SetPropertyHelper(cx, obj, obj, id, 0, &rval, script->strictModeCode)
         : !DefineNativeProperty(cx, obj, id, rval, NULL, NULL,
                                 JSPROP_ENUMERATE, 0, 0, 0)) {
         goto error;
     }
@@ -3394,37 +3340,29 @@ BEGIN_CASE(JSOP_ANYNAME)
     if (!js_GetAnyName(cx, &id))
         goto error;
     PUSH_COPY(IdToValue(id));
 }
 END_CASE(JSOP_ANYNAME)
 #endif
 
 BEGIN_CASE(JSOP_QNAMEPART)
-{
     /*
      * We do not JS_ASSERT(!script->strictModeCode) here because JSOP_QNAMEPART
      * is used for __proto__ and (in contexts where we favor JSOP_*ELEM instead
      * of JSOP_*PROP) obj.prop compiled as obj['prop'].
      */
-
-    JSAtom *atom;
-    LOAD_ATOM(0, atom);
-    PUSH_STRING(atom);
-}
+    PUSH_STRING(script->getAtom(regs.pc));
 END_CASE(JSOP_QNAMEPART)
 
 #if JS_HAS_XML_SUPPORT
 BEGIN_CASE(JSOP_QNAMECONST)
 {
     JS_ASSERT(!script->strictModeCode);
-
-    JSAtom *atom;
-    LOAD_ATOM(0, atom);
-    Value rval = StringValue(atom);
+    Value rval = StringValue(script->getAtom(regs.pc));
     Value lval = regs.sp[-1];
     JSObject *obj = js_ConstructXMLQNameObject(cx, lval, rval);
     if (!obj)
         goto error;
     regs.sp[-1].setObject(*obj);
 }
 END_CASE(JSOP_QNAMECONST)
 
@@ -3661,41 +3599,41 @@ BEGIN_CASE(JSOP_XMLELTEXPR)
     regs.sp[-1].setString(str);
 }
 END_CASE(JSOP_XMLELTEXPR)
 
 BEGIN_CASE(JSOP_XMLCDATA)
 {
     JS_ASSERT(!script->strictModeCode);
 
-    JSAtom *atom = script->getAtom(GET_UINT32_INDEX(regs.pc));
+    JSAtom *atom = script->getAtom(regs.pc);
     JSObject *obj = js_NewXMLSpecialObject(cx, JSXML_CLASS_TEXT, NULL, atom);
     if (!obj)
         goto error;
     PUSH_OBJECT(*obj);
 }
 END_CASE(JSOP_XMLCDATA)
 
 BEGIN_CASE(JSOP_XMLCOMMENT)
 {
     JS_ASSERT(!script->strictModeCode);
 
-    JSAtom *atom = script->getAtom(GET_UINT32_INDEX(regs.pc));
+    JSAtom *atom = script->getAtom(regs.pc);
     JSObject *obj = js_NewXMLSpecialObject(cx, JSXML_CLASS_COMMENT, NULL, atom);
     if (!obj)
         goto error;
     PUSH_OBJECT(*obj);
 }
 END_CASE(JSOP_XMLCOMMENT)
 
 BEGIN_CASE(JSOP_XMLPI)
 {
     JS_ASSERT(!script->strictModeCode);
 
-    JSAtom *atom = script->getAtom(GET_UINT32_INDEX(regs.pc));
+    JSAtom *atom = script->getAtom(regs.pc);
     Value rval = regs.sp[-1];
     JSString *str2 = rval.toString();
     JSObject *obj = js_NewXMLSpecialObject(cx, JSXML_CLASS_PROCESSING_INSTRUCTION, atom, str2);
     if (!obj)
         goto error;
     regs.sp[-1].setObject(*obj);
 }
 END_CASE(JSOP_XMLPI)
@@ -3711,17 +3649,17 @@ BEGIN_CASE(JSOP_GETFUNNS)
 }
 END_CASE(JSOP_GETFUNNS)
 #endif /* JS_HAS_XML_SUPPORT */
 
 BEGIN_CASE(JSOP_ENTERBLOCK)
 BEGIN_CASE(JSOP_ENTERLET0)
 BEGIN_CASE(JSOP_ENTERLET1)
 {
-    StaticBlockObject &blockObj = script->getObject(GET_UINT32_INDEX(regs.pc))->asStaticBlock();
+    StaticBlockObject &blockObj = script->getObject(regs.pc)->asStaticBlock();
 
     if (op == JSOP_ENTERBLOCK) {
         JS_ASSERT(regs.stackDepth() == blockObj.stackDepth());
         JS_ASSERT(regs.stackDepth() + blockObj.slotCount() <= script->nslots);
         Value *vp = regs.sp + blockObj.slotCount();
         SetValueRangeToUndefined(regs.sp, vp);
         regs.sp = vp;
     }
@@ -3866,19 +3804,16 @@ END_CASE(JSOP_ARRAYPUSH)
   error:
     JS_ASSERT(&cx->regs() == &regs);
     JS_ASSERT(uint32_t(regs.pc - script->code) < script->length);
 
     /* When rejoining, we must not err before finishing Interpret's prologue. */
     JS_ASSERT(interpMode != JSINTERP_REJOIN);
 
     if (cx->isExceptionPending()) {
-        /* Restore atoms local in case we will resume. */
-        atoms = script->atoms;
-
         /* Call debugger throw hook if set. */
         if (cx->runtime->debugHooks.throwHook || !cx->compartment->getDebuggees().empty()) {
             Value rval;
             JSTrapStatus st = Debugger::onExceptionUnwind(cx, &rval);
             if (st == JSTRAP_CONTINUE) {
                 if (JSThrowHook handler = cx->runtime->debugHooks.throwHook)
                     st = handler(cx, script, regs.pc, &rval, cx->runtime->debugHooks.throwHookData);
             }
--- a/js/src/jsiter.cpp
+++ b/js/src/jsiter.cpp
@@ -478,29 +478,26 @@ Compare(T *a, T *b, size_t c)
     }
     return true;
 }
 
 static inline JSObject *
 NewIteratorObject(JSContext *cx, unsigned flags)
 {
     if (flags & JSITER_ENUMERATE) {
-        RootedTypeObject type(cx);
-        type = cx->compartment->getEmptyType(cx);
+        RootedTypeObject type(cx, cx->compartment->getEmptyType(cx));
         if (!type)
             return NULL;
 
-        RootedShape emptyEnumeratorShape(cx);
-        emptyEnumeratorShape = EmptyShape::getInitialShape(cx, &IteratorClass, NULL, NULL,
-                                                           ITERATOR_FINALIZE_KIND);
-        if (!emptyEnumeratorShape)
+        RootedShape shape(cx, EmptyShape::getInitialShape(cx, &IteratorClass, NULL, NULL,
+                                                          ITERATOR_FINALIZE_KIND));
+        if (!shape)
             return NULL;
 
-        JSObject *obj = JSObject::create(cx, ITERATOR_FINALIZE_KIND,
-                                         emptyEnumeratorShape, type, NULL);
+        JSObject *obj = JSObject::create(cx, ITERATOR_FINALIZE_KIND, shape, type, NULL);
         if (!obj)
             return NULL;
 
         JS_ASSERT(obj->numFixedSlots() == JSObject::ITER_CLASS_NFIXED_SLOTS);
         return obj;
     }
 
     return NewBuiltinClassInstance(cx, &IteratorClass);
@@ -812,18 +809,17 @@ Iterator(JSContext *cx, unsigned argc, V
     return true;
 }
 
 JSBool
 js_ThrowStopIteration(JSContext *cx)
 {
     JS_ASSERT(!JS_IsExceptionPending(cx));
     RootedValue v(cx);
-    RootedObject null(cx);
-    if (js_FindClassObject(cx, null, JSProto_StopIteration, &v))
+    if (js_FindClassObject(cx, NullPtr(), JSProto_StopIteration, &v))
         cx->setPendingException(v);
     return JS_FALSE;
 }
 
 static JSBool
 iterator_next(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
@@ -1710,18 +1706,17 @@ InitIteratorClass(JSContext *cx, Handle<
     AutoIdVector blank(cx);
     NativeIterator *ni = NativeIterator::allocateIterator(cx, 0, blank);
     if (!ni)
         return false;
     ni->init(NULL, 0 /* flags */, 0, 0);
 
     iteratorProto->setNativeIterator(ni);
 
-    RootedFunction ctor(cx);
-    ctor = global->createConstructor(cx, Iterator, CLASS_NAME(cx, Iterator), 2);
+    RootedFunction ctor(cx, global->createConstructor(cx, Iterator, CLASS_NAME(cx, Iterator), 2));
     if (!ctor)
         return false;
 
     if (!LinkConstructorAndPrototype(cx, ctor, iteratorProto))
         return false;
 
     if (!DefinePropertiesAndBrand(cx, iteratorProto, NULL, iterator_methods))
         return false;
--- a/js/src/jsnum.cpp
+++ b/js/src/jsnum.cpp
@@ -1051,18 +1051,17 @@ js_InitNumberClass(JSContext *cx, JSObje
 
     Rooted<GlobalObject*> global(cx, &obj->asGlobal());
 
     RootedObject numberProto(cx, global->createBlankPrototype(cx, &NumberClass));
     if (!numberProto)
         return NULL;
     numberProto->asNumber().setPrimitiveValue(0);
 
-    RootedFunction ctor(cx);
-    ctor = global->createConstructor(cx, Number, CLASS_NAME(cx, Number), 1);
+    RootedFunction ctor(cx, global->createConstructor(cx, Number, CLASS_NAME(cx, Number), 1));
     if (!ctor)
         return NULL;
 
     if (!LinkConstructorAndPrototype(cx, ctor, numberProto))
         return NULL;
 
     /* Add numeric constants (MAX_VALUE, NaN, &c.) to the Number constructor. */
     if (!JS_DefineConstDoubles(cx, ctor, number_constants))
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -2001,18 +2001,17 @@ obj_create(JSContext *cx, unsigned argc,
         return false;
     }
 #endif
 
     /*
      * Use the callee's global as the parent of the new object to avoid dynamic
      * scoping (i.e., using the caller's global).
      */
-    RootedObject obj(cx);
-    obj = NewObjectWithGivenProto(cx, &ObjectClass, proto, &args.callee().global());
+    RootedObject obj(cx, NewObjectWithGivenProto(cx, &ObjectClass, proto, &args.callee().global()));
     if (!obj)
         return false;
 
     /* Don't track types or array-ness for objects created here. */
     MarkTypeObjectUnknownProperties(cx, obj->type());
 
     /* 15.2.3.5 step 4. */
     if (args.hasDefined(1)) {
@@ -2347,18 +2346,17 @@ NewObject(JSContext *cx, Class *clasp, t
 {
     JS_ASSERT(clasp != &ArrayClass);
     JS_ASSERT_IF(clasp == &FunctionClass,
                  kind == JSFunction::FinalizeKind || kind == JSFunction::ExtendedFinalizeKind);
     JS_ASSERT_IF(parent, &parent->global() == cx->compartment->maybeGlobal());
 
     RootedTypeObject type(cx, type_);
 
-    RootedShape shape(cx);
-    shape = EmptyShape::getInitialShape(cx, clasp, type->proto, parent, kind);
+    RootedShape shape(cx, EmptyShape::getInitialShape(cx, clasp, type->proto, parent, kind));
     if (!shape)
         return NULL;
 
     HeapSlot *slots;
     if (!PreallocateObjectDynamicSlots(cx, shape, &slots))
         return NULL;
 
     JSObject *obj = JSObject::create(cx, kind, shape, type, slots);
@@ -3244,18 +3242,17 @@ DefineConstructorAndPrototype(JSContext 
 
     /*
      * Create the prototype object.  (GlobalObject::createBlankPrototype isn't
      * used because it parents the prototype object to the global and because
      * it uses WithProto::Given.  FIXME: Undo dependencies on this parentage
      * [which already needs to happen for bug 638316], figure out nicer
      * semantics for null-protoProto, and use createBlankPrototype.)
      */
-    RootedObject proto(cx);
-    proto = NewObjectWithClassProto(cx, clasp, protoProto, obj);
+    RootedObject proto(cx, NewObjectWithClassProto(cx, clasp, protoProto, obj));
     if (!proto)
         return NULL;
 
     if (!proto->setSingletonType(cx))
         return NULL;
 
     if (clasp == &ArrayClass && !JSObject::makeDenseArraySlow(cx, proto))
         return NULL;
@@ -3282,19 +3279,18 @@ DefineConstructorAndPrototype(JSContext 
         ctor = proto;
     } else {
         /*
          * Create the constructor, not using GlobalObject::createConstructor
          * because the constructor currently must have |obj| as its parent.
          * (FIXME: remove this dependency on the exact identity of the parent,
          * perhaps as part of bug 638316.)
          */
-        RootedFunction fun(cx);
-        fun = js_NewFunction(cx, NULL, constructor, nargs, JSFUN_CONSTRUCTOR, obj, atom,
-                             ctorKind);
+        RootedFunction fun(cx, js_NewFunction(cx, NULL, constructor, nargs, JSFUN_CONSTRUCTOR,
+                                              obj, atom, ctorKind));
         if (!fun)
             goto bad;
 
         /*
          * Set the class object early for standard class constructors. Type
          * inference may need to access these, and js_GetClassPrototype will
          * fail if it tries to do a reentrant reconstruction of the class.
          */
@@ -3390,18 +3386,17 @@ JSObject *
 js_InitClass(JSContext *cx, HandleObject obj, JSObject *protoProto_,
              Class *clasp, Native constructor, unsigned nargs,
              JSPropertySpec *ps, JSFunctionSpec *fs,
              JSPropertySpec *static_ps, JSFunctionSpec *static_fs,
              JSObject **ctorp, AllocKind ctorKind)
 {
     RootedObject protoProto(cx, protoProto_);
 
-    RootedAtom atom(cx);
-    atom = js_Atomize(cx, clasp->name, strlen(clasp->name));
+    RootedAtom atom(cx, js_Atomize(cx, clasp->name, strlen(clasp->name)));
     if (!atom)
         return NULL;
 
     /*
      * All instances of the class will inherit properties from the prototype
      * object we are about to create (in DefineConstructorAndPrototype), which
      * in turn will inherit from protoProto.
      *
@@ -4082,29 +4077,28 @@ CallAddPropertyHook(JSContext *cx, Class
         }
     }
     return true;
 }
 
 namespace js {
 
 Shape *
-DefineNativeProperty(JSContext *cx, HandleObject obj, HandleId id, const Value &value_,
+DefineNativeProperty(JSContext *cx, HandleObject obj, HandleId id, const Value &valueArg,
                      PropertyOp getter, StrictPropertyOp setter, unsigned attrs,
                      unsigned flags, int shortid, unsigned defineHow /* = 0 */)
 {
     JS_ASSERT((defineHow & ~(DNP_CACHE_RESULT | DNP_DONT_PURGE |
                              DNP_SKIP_TYPE)) == 0);
     JS_ASSERT(!(attrs & JSPROP_NATIVE_ACCESSORS));
 
     AutoRooterGetterSetter gsRoot(cx, attrs, &getter, &setter);
 
     /* Make a local copy of value so addProperty can mutate its inout parameter. */
-    RootedValue value(cx);
-    value = value_;
+    RootedValue value(cx, valueArg);
 
     /*
      * If defining a getter or setter, we must check for its counterpart and
      * update the attributes and property ops.  A getter or setter is really
      * only half of a property.
      */
     RootedShape shape(cx);
     if (attrs & (JSPROP_GETTER | JSPROP_SETTER)) {
--- a/js/src/jsscope.cpp
+++ b/js/src/jsscope.cpp
@@ -407,19 +407,17 @@ JSObject::toDictionaryMode(JSContext *cx
      * Clone the shapes into a new dictionary list. Don't update the
      * last property of this object until done, otherwise a GC
      * triggered while creating the dictionary will get the wrong
      * slot span for this object.
      */
     RootedShape root(cx);
     RootedShape dictionaryShape(cx);
 
-    RootedShape shape(cx);
-    shape = lastProperty();
-
+    RootedShape shape(cx, lastProperty());
     while (shape) {
         JS_ASSERT(!shape->inDictionary());
 
         Shape *dprop = js_NewGCShape(cx);
         if (!dprop) {
             js_ReportOutOfMemory(cx);
             return false;
         }
@@ -799,20 +797,18 @@ JSObject::changeProperty(JSContext *cx, 
 }
 
 bool
 JSObject::removeProperty(JSContext *cx, jsid id_)
 {
     RootedId id(cx, id_);
     RootedObject self(cx, this);
 
-    RootedShape shape(cx);
-
     Shape **spp;
-    shape = Shape::search(cx, lastProperty(), id, &spp);
+    RootedShape shape(cx, Shape::search(cx, lastProperty(), id, &spp));
     if (!shape)
         return true;
 
     /*
      * If shape is not the last property added, or the last property cannot
      * be removed, switch to dictionary mode.
      */
     if (!self->inDictionaryMode() && (shape != self->lastProperty() || !self->canRemoveLastProperty())) {
@@ -1290,20 +1286,18 @@ EmptyShape::getInitialShape(JSContext *c
     InitialShapeSet::AddPtr p = table.lookupForAdd(lookup);
 
     if (p)
         return p->shape;
 
     RootedObject protoRoot(cx, lookup.proto);
     RootedObject parentRoot(cx, lookup.parent);
 
-    Rooted<UnownedBaseShape*> nbase(cx);
-
     StackBaseShape base(clasp, parent, objectFlags);
-    nbase = BaseShape::getUnowned(cx, base);
+    Rooted<UnownedBaseShape*> nbase(cx, BaseShape::getUnowned(cx, base));
     if (!nbase)
         return NULL;
 
     Shape *shape = cx->propertyTree().newShape(cx);
     if (!shape)
         return NULL;
     new (shape) EmptyShape(nbase, nfixed);
 
--- a/js/src/jsscript.cpp
+++ b/js/src/jsscript.cpp
@@ -168,18 +168,17 @@ Bindings::callObjectShape(JSContext *cx)
             if (!shapes.append(&s))
                 return NULL;
         }
     }
 
     /*
      * Now build the Shape without duplicate properties.
      */
-    RootedShape shape(cx);
-    shape = initialShape(cx);
+    RootedShape shape(cx, initialShape(cx));
     for (int i = shapes.length() - 1; i >= 0; --i) {
         shape = shape->getChildBinding(cx, shapes[i]);
         if (!shape)
             return NULL;
     }
 
     return shape;
 }
--- a/js/src/jsscript.h
+++ b/js/src/jsscript.h
@@ -779,26 +779,41 @@ struct JSScript : public js::gc::Cell
         return hasClosedVars() ? closedVars()->length : 0;
     }
 
     js::HeapPtrAtom &getAtom(size_t index) const {
         JS_ASSERT(index < natoms);
         return atoms[index];
     }
 
+    js::HeapPtrAtom &getAtom(jsbytecode *pc) const {
+        JS_ASSERT(pc >= code && pc + sizeof(uint32_t) < code + length);
+        return getAtom(GET_UINT32_INDEX(pc));
+    }
+
     js::PropertyName *getName(size_t index) {
         return getAtom(index)->asPropertyName();
     }
 
+    js::PropertyName *getName(jsbytecode *pc) const {
+        JS_ASSERT(pc >= code && pc + sizeof(uint32_t) < code + length);
+        return getAtom(GET_UINT32_INDEX(pc))->asPropertyName();
+    }
+
     JSObject *getObject(size_t index) {
         js::ObjectArray *arr = objects();
         JS_ASSERT(index < arr->length);
         return arr->vector[index];
     }
 
+    JSObject *getObject(jsbytecode *pc) {
+        JS_ASSERT(pc >= code && pc + sizeof(uint32_t) < code + length);
+        return getObject(GET_UINT32_INDEX(pc));
+    }
+
     JSVersion getVersion() const {
         return JSVersion(version);
     }
 
     inline JSFunction *getFunction(size_t index);
     inline JSFunction *getCallerFunction();
 
     inline JSObject *getRegExp(size_t index);
--- a/js/src/jsstr.cpp
+++ b/js/src/jsstr.cpp
@@ -1956,47 +1956,44 @@ BuildFlatReplacement(JSContext *cx, Hand
                  */
                 if (match >= pos) {
                     /*
                      * If this part of the rope overlaps with the left side of
                      * the pattern, then it must be the only one to overlap with
                      * the first character in the pattern, so we include the
                      * replacement string here.
                      */
-                    RootedString leftSide(cx);
-                    leftSide = js_NewDependentString(cx, str, 0, match - pos);
+                    RootedString leftSide(cx, js_NewDependentString(cx, str, 0, match - pos));
                     if (!leftSide ||
                         !builder.append(leftSide) ||
                         !builder.append(repstr)) {
                         return false;
                     }
                 }
 
                 /*
                  * If str runs off the end of the matched string, append the
                  * last part of str.
                  */
                 if (strEnd > matchEnd) {
-                    RootedString rightSide(cx);
-                    rightSide = js_NewDependentString(cx, str, matchEnd - pos,
-                                                      strEnd - matchEnd);
+                    RootedString rightSide(cx, js_NewDependentString(cx, str, matchEnd - pos,
+                                                                     strEnd - matchEnd));
                     if (!rightSide || !builder.append(rightSide))
                         return false;
                 }
             } else {
                 if (!builder.append(str))
                     return false;
             }
             pos += str->length();
             if (!r.popFront())
                 return false;
         }
     } else {
-        RootedString leftSide(cx);
-        leftSide = js_NewDependentString(cx, textstr, 0, match);
+        RootedString leftSide(cx, js_NewDependentString(cx, textstr, 0, match));
         if (!leftSide)
             return false;
         RootedString rightSide(cx);
         rightSide = js_NewDependentString(cx, textstr, match + fm.patternLength(),
                                           textstr->length() - match - fm.patternLength());
         if (!rightSide ||
             !builder.append(leftSide) ||
             !builder.append(repstr) ||
@@ -2208,18 +2205,17 @@ LambdaIsGetElem(JSObject &lambda, JSCont
     GET_NAME_FROM_BYTECODE(script, pc, 0, bname);
     pc += JSOP_NAME_LENGTH;
 
     /*
      * Do a conservative search for 'b' in the enclosing scope. Avoid using a
      * real name lookup since this can trigger observable effects.
      */
     Value b;
-    RootedObject scope(cx);
-    scope = cx->stack.currentScriptedScopeChain();
+    RootedObject scope(cx, cx->stack.currentScriptedScopeChain());
     while (true) {
         if (!scope->isCall() && !scope->isBlock())
             return NULL;
         if (HasDataProperty(cx, scope, bname, &b))
             break;
         scope = &scope->asScope().enclosingScope();
     }
 
@@ -3064,18 +3060,17 @@ js_InitStringClass(JSContext *cx, JSObje
     Rooted<GlobalObject*> global(cx, &obj->asGlobal());
 
     Rooted<JSString*> empty(cx, cx->runtime->emptyString);
     RootedObject proto(cx, global->createBlankPrototype(cx, &StringClass));
     if (!proto || !proto->asString().init(cx, empty))
         return NULL;
 
     /* Now create the String function. */
-    RootedFunction ctor(cx);
-    ctor = global->createConstructor(cx, js_String, CLASS_NAME(cx, String), 1);
+    RootedFunction ctor(cx, global->createConstructor(cx, js_String, CLASS_NAME(cx, String), 1));
     if (!ctor)
         return NULL;
 
     if (!LinkConstructorAndPrototype(cx, ctor, proto))
         return NULL;
 
     if (!DefinePropertiesAndBrand(cx, proto, NULL, string_methods) ||
         !DefinePropertiesAndBrand(cx, ctor, NULL, string_static_methods))
--- a/js/src/jstypedarray.cpp
+++ b/js/src/jstypedarray.cpp
@@ -3029,18 +3029,16 @@ InitTypedArrayClass(JSContext *cx)
         !proto->defineProperty(cx, cx->runtime->atomState.BYTES_PER_ELEMENTAtom,
                                Int32Value(ArrayType::BYTES_PER_ELEMENT),
                                JS_PropertyStub, JS_StrictPropertyStub,
                                JSPROP_PERMANENT | JSPROP_READONLY))
     {
         return NULL;
     }
 
-    RootedObject foo(cx);
-
     if (!ArrayType::defineGetters(cx, proto))
         return NULL;
 
     if (!JS_DefineFunctions(cx, proto, ArrayType::jsfuncs))
         return NULL;
 
     if (!DefineConstructorAndPrototype(cx, global, ArrayType::key, ctor, proto))
         return NULL;
@@ -3085,19 +3083,18 @@ Class TypedArray::protoClasses[TYPE_MAX]
 static JSObject *
 InitArrayBufferClass(JSContext *cx)
 {
     Rooted<GlobalObject*> global(cx, cx->compartment->maybeGlobal());
     RootedObject arrayBufferProto(cx, global->createBlankPrototype(cx, &ArrayBufferObject::protoClass));
     if (!arrayBufferProto)
         return NULL;
 
-    RootedFunction ctor(cx);
-    ctor = global->createConstructor(cx, ArrayBufferObject::class_constructor,
-                                     CLASS_NAME(cx, ArrayBuffer), 1);
+    RootedFunction ctor(cx, global->createConstructor(cx, ArrayBufferObject::class_constructor,
+                                                      CLASS_NAME(cx, ArrayBuffer), 1));
     if (!ctor)
         return NULL;
 
     if (!LinkConstructorAndPrototype(cx, ctor, arrayBufferProto))
         return NULL;
 
     RootedId byteLengthId(cx, NameToId(cx->runtime->atomState.byteLengthAtom));
     unsigned flags = JSPROP_PERMANENT | JSPROP_READONLY | JSPROP_SHARED | JSPROP_GETTER;
--- a/js/src/jsweakmap.cpp
+++ b/js/src/jsweakmap.cpp
@@ -363,19 +363,18 @@ js_InitWeakMapClass(JSContext *cx, JSObj
     JS_ASSERT(obj->isNative());
 
     Rooted<GlobalObject*> global(cx, &obj->asGlobal());
 
     RootedObject weakMapProto(cx, global->createBlankPrototype(cx, &WeakMapClass));
     if (!weakMapProto)
         return NULL;
 
-    RootedFunction ctor(cx);
-    ctor = global->createConstructor(cx, WeakMap_construct,
-                                     CLASS_NAME(cx, WeakMap), 0);
+    RootedFunction ctor(cx, global->createConstructor(cx, WeakMap_construct,
+                                                      CLASS_NAME(cx, WeakMap), 0));
     if (!ctor)
         return NULL;
 
     if (!LinkConstructorAndPrototype(cx, ctor, weakMapProto))
         return NULL;
 
     if (!DefinePropertiesAndBrand(cx, weakMapProto, NULL, weak_map_methods))
         return NULL;
--- a/js/src/vm/ArgumentsObject.cpp
+++ b/js/src/vm/ArgumentsObject.cpp
@@ -25,30 +25,27 @@ using namespace js::gc;
 ArgumentsObject *
 ArgumentsObject::create(JSContext *cx, StackFrame *fp)
 {
     JSFunction &callee = fp->callee();
     RootedObject proto(cx, callee.global().getOrCreateObjectPrototype(cx));
     if (!proto)
         return NULL;
 
-    RootedTypeObject type(cx);
-    type = proto->getNewType(cx);
+    RootedTypeObject type(cx, proto->getNewType(cx));
     if (!type)
         return NULL;
 
     bool strict = callee.inStrictMode();
     Class *clasp = strict ? &StrictArgumentsObjectClass : &NormalArgumentsObjectClass;
 
-    RootedShape emptyArgumentsShape(cx);
-    emptyArgumentsShape =
-        EmptyShape::getInitialShape(cx, clasp, proto,
-                                    proto->getParent(), FINALIZE_KIND,
-                                    BaseShape::INDEXED);
-    if (!emptyArgumentsShape)
+    RootedShape shape(cx, EmptyShape::getInitialShape(cx, clasp, proto,
+                                                      proto->getParent(), FINALIZE_KIND,
+                                                      BaseShape::INDEXED));
+    if (!shape)
         return NULL;
 
     unsigned numActuals = fp->numActualArgs();
     unsigned numFormals = fp->numFormalArgs();
     unsigned numDeletedWords = NumWordsForBitArrayOfLength(numActuals);
     unsigned numArgs = Max(numActuals, numFormals);
     unsigned numBytes = offsetof(ArgumentsData, args) +
                         numDeletedWords * sizeof(size_t) +
@@ -72,17 +69,17 @@ ArgumentsObject::create(JSContext *cx, S
     } else if (numActuals < numFormals) {
         for (; dst != dstEnd; ++dst)
             dst->init(UndefinedValue());
     }
 
     data->deletedBits = reinterpret_cast<size_t *>(dstEnd);
     ClearAllBitArrayElements(data->deletedBits, numDeletedWords);
 
-    JSObject *obj = JSObject::create(cx, FINALIZE_KIND, emptyArgumentsShape, type, NULL);
+    JSObject *obj = JSObject::create(cx, FINALIZE_KIND, shape, type, NULL);
     if (!obj)
         return NULL;
 
     obj->initFixedSlot(INITIAL_LENGTH_SLOT, Int32Value(numActuals << PACKED_BITS_COUNT));
     obj->initFixedSlot(DATA_SLOT, PrivateValue(data));
 
     /*
      * If it exists and the arguments object aliases formals, the call object
--- a/js/src/vm/GlobalObject.cpp
+++ b/js/src/vm/GlobalObject.cpp
@@ -108,26 +108,25 @@ GlobalObject::initFunctionAndObjectClass
          */
         JSObject *proto = js_NewFunction(cx, functionProto,
                                          NULL, 0, JSFUN_INTERPRETED, self, NULL);
         if (!proto)
             return NULL;
         JS_ASSERT(proto == functionProto);
         functionProto->flags |= JSFUN_PROTOTYPE;
 
-        Rooted<JSScript*> script(cx);
-        script = JSScript::Create(cx,
-                                  /* savedCallerFun = */ false,
-                                  /* principals = */ NULL,
-                                  /* originPrincipals = */ NULL,
-                                  /* compileAndGo = */ false,
-                                  /* noScriptRval = */ true,
-                                  /* globalObject = */ NULL,
-                                  JSVERSION_DEFAULT,
-                                  /* staticLevel = */ 0);
+        Rooted<JSScript*> script(cx, JSScript::Create(cx,
+                                                      /* savedCallerFun = */ false,
+                                                      /* principals = */ NULL,
+                                                      /* originPrincipals = */ NULL,
+                                                      /* compileAndGo = */ false,
+                                                      /* noScriptRval = */ true,
+                                                      /* globalObject = */ NULL,
+                                                      JSVERSION_DEFAULT,
+                                                      /* staticLevel = */ 0));
         if (!script || !script->fullyInitTrivial(cx))
             return NULL;
 
         functionProto->initScript(script);
         functionProto->getType(cx)->interpretedFunction = functionProto;
         script->setFunction(functionProto);
 
         if (!functionProto->setSingletonType(cx))
--- a/js/src/vm/ScopeObject.cpp
+++ b/js/src/vm/ScopeObject.cpp
@@ -86,27 +86,25 @@ js::ScopeCoordinateToFrameIndex(JSScript
  * Construct a call object for the given bindings.  If this is a call object
  * for a function invocation, callee should be the function being called.
  * Otherwise it must be a call object for eval of strict mode code, and callee
  * must be null.
  */
 CallObject *
 CallObject::create(JSContext *cx, JSScript *script, HandleObject enclosing, HandleFunction callee)
 {
-    RootedShape shape(cx);
-    shape = script->bindings.callObjectShape(cx);
+    RootedShape shape(cx, script->bindings.callObjectShape(cx));
     if (shape == NULL)
         return NULL;
 
     gc::AllocKind kind = gc::GetGCObjectKind(shape->numFixedSlots());
     JS_ASSERT(CanBeFinalizedInBackground(kind, &CallClass));
     kind = gc::GetBackgroundAllocKind(kind);
 
-    RootedTypeObject type(cx);
-    type = cx->compartment->getEmptyType(cx);
+    RootedTypeObject type(cx, cx->compartment->getEmptyType(cx));
     if (!type)
         return NULL;
 
     HeapSlot *slots;
     if (!PreallocateObjectDynamicSlots(cx, shape, &slots))
         return NULL;
 
     RootedObject obj(cx, JSObject::create(cx, kind, shape, type, slots));
@@ -283,18 +281,17 @@ Class js::DeclEnvClass = {
     JS_EnumerateStub,
     JS_ResolveStub,
     JS_ConvertStub
 };
 
 DeclEnvObject *
 DeclEnvObject::create(JSContext *cx, StackFrame *fp)
 {
-    RootedTypeObject type(cx);
-    type = cx->compartment->getEmptyType(cx);
+    RootedTypeObject type(cx, cx->compartment->getEmptyType(cx));
     if (!type)
         return NULL;
 
     RootedShape emptyDeclEnvShape(cx);
     emptyDeclEnvShape = EmptyShape::getInitialShape(cx, &DeclEnvClass, NULL,
                                                     &fp->global(), FINALIZE_KIND);
     if (!emptyDeclEnvShape)
         return NULL;
@@ -315,28 +312,26 @@ DeclEnvObject::create(JSContext *cx, Sta
     }
 
     return &obj->asDeclEnv();
 }
 
 WithObject *
 WithObject::create(JSContext *cx, HandleObject proto, HandleObject enclosing, uint32_t depth)
 {
-    RootedTypeObject type(cx);
-    type = proto->getNewType(cx);
+    RootedTypeObject type(cx, proto->getNewType(cx));
     if (!type)
         return NULL;
 
-    RootedShape emptyWithShape(cx);
-    emptyWithShape = EmptyShape::getInitialShape(cx, &WithClass, proto,
-                                                 &enclosing->global(), FINALIZE_KIND);
-    if (!emptyWithShape)
+    RootedShape shape(cx, EmptyShape::getInitialShape(cx, &WithClass, proto,
+                                                      &enclosing->global(), FINALIZE_KIND));
+    if (!shape)
         return NULL;
 
-    RootedObject obj(cx, JSObject::create(cx, FINALIZE_KIND, emptyWithShape, type, NULL));
+    RootedObject obj(cx, JSObject::create(cx, FINALIZE_KIND, shape, type, NULL));
     if (!obj)
         return NULL;
 
     if (!obj->asScope().setEnclosingScope(cx, enclosing))
         return NULL;
 
     obj->setReservedSlot(DEPTH_SLOT, PrivateUint32Value(depth));
 
@@ -578,27 +573,25 @@ Class js::WithClass = {
     }
 };
 
 /*****************************************************************************/
 
 ClonedBlockObject *
 ClonedBlockObject::create(JSContext *cx, Handle<StaticBlockObject *> block, StackFrame *fp)
 {
-    RootedTypeObject type(cx);
-    type = block->getNewType(cx);
+    RootedTypeObject type(cx, block->getNewType(cx));
     if (!type)
         return NULL;
 
     HeapSlot *slots;
     if (!PreallocateObjectDynamicSlots(cx, block->lastProperty(), &slots))
         return NULL;
 
-    RootedShape shape(cx);
-    shape = block->lastProperty();
+    RootedShape shape(cx, block->lastProperty());
 
     RootedObject obj(cx, JSObject::create(cx, FINALIZE_KIND, shape, type, slots));
     if (!obj)
         return NULL;
 
     /* Set the parent if necessary, as for call objects. */
     if (&fp->global() != obj->getParent()) {
         JS_ASSERT(obj->getParent() == NULL);
@@ -639,27 +632,25 @@ ClonedBlockObject::copyUnaliasedValues(S
         if (!block.isAliased(i))
             setVar(i, fp->unaliasedLocal(base + i), DONT_CHECK_ALIASING);
     }
 }
 
 StaticBlockObject *
 StaticBlockObject::create(JSContext *cx)
 {
-    RootedTypeObject type(cx);
-    type = cx->compartment->getEmptyType(cx);
+    RootedTypeObject type(cx, cx->compartment->getEmptyType(cx));
     if (!type)
         return NULL;
 
-    RootedShape emptyBlockShape(cx);
-    emptyBlockShape = EmptyShape::getInitialShape(cx, &BlockClass, NULL, NULL, FINALIZE_KIND);
-    if (!emptyBlockShape)
+    RootedShape shape(cx, EmptyShape::getInitialShape(cx, &BlockClass, NULL, NULL, FINALIZE_KIND));
+    if (!shape)
         return NULL;
 
-    JSObject *obj = JSObject::create(cx, FINALIZE_KIND, emptyBlockShape, type, NULL);
+    JSObject *obj = JSObject::create(cx, FINALIZE_KIND, shape, type, NULL);
     if (!obj)
         return NULL;
 
     return &obj->asStaticBlock();
 }
 
 Shape *
 StaticBlockObject::addVar(JSContext *cx, jsid id, int index, bool *redeclared)
--- a/js/xpconnect/tests/chrome/Makefile.in
+++ b/js/xpconnect/tests/chrome/Makefile.in
@@ -4,19 +4,18 @@
 
 DEPTH     = ../../../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
 relativesrcdir  = js/xpconnect/tests/chrome
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_CHROME_FILES = \
+MOCHITEST_CHROME_FILES = \
 		test_bug448587.xul \
 		test_bug500931.xul \
 		bug503926.xul \
 		test_bug503926.xul \
 		test_bug533596.xul \
 		test_doublewrappedcompartments.xul \
 		test_evalInSandbox.xul \
 		file_evalInSandbox.html \
@@ -55,10 +54,9 @@ include $(topsrcdir)/config/rules.mk
 
 # Disabled until this test gets updated to test the new proxy based
 # wrappers.
 #		test_wrappers-2.xul \
 
 # Disabled due to apparent conservative stack scanner false positives on Linux64 debug.
 #		test_watchpoints.xul \
 
-libs:: $(_CHROME_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/js/xpconnect/tests/mochitest/Makefile.in
+++ b/js/xpconnect/tests/mochitest/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = js/xpconnect/tests/mochitest
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =	bug500931_helper.html \
+MOCHITEST_FILES =	bug500931_helper.html \
 		inner.html \
 		bug92773_helper.html \
 		bug504877_helper.html \
 		bug571849_helper.html \
 		chrome_wrappers_helper.html \
 		file_doublewrappedcompartments.html \
 		file_evalInSandbox.html \
 		file_wrappers-2.html \
@@ -68,29 +67,22 @@ include $(topsrcdir)/config/rules.mk
 		file_nodelists.html \
 		file_bug706301.html \
 		file_exnstack.html \
 		file_expandosharing.html \
 		file_bug760131.html \
 		file_empty.html \
 		$(NULL)
 
-_CHROME_FILES	= \
+MOCHITEST_CHROME_FILES	= \
 		test_bug361111.xul \
 		test_bug760131.html \
 		$(NULL)
 
 ifneq ($(OS_TARGET),Android)
 ifndef MOZ_PLATFORM_MAEMO
-_TEST_FILES +=	test_bug657267.html \
+MOCHITEST_FILES +=	test_bug657267.html \
 		bug657267.jar
 endif
 endif
 
-
-		#test_bug484107.html \
+include $(topsrcdir)/config/rules.mk
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs:: $(_CHROME_FILES)
-	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
-
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -5896,16 +5896,57 @@ PresShell::HandleEvent(nsIFrame        *
       }
 
       return NS_OK;
     }
 
     PresShell* shell =
         static_cast<PresShell*>(frame->PresContext()->PresShell());
 
+    switch (aEvent->message) {
+      case NS_TOUCH_MOVE:
+      case NS_TOUCH_CANCEL:
+      case NS_TOUCH_END: {
+        // Remove the changed touches
+        // need to make sure we only remove touches that are ending here
+        nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
+        nsTArray<nsCOMPtr<nsIDOMTouch> >  &touches = touchEvent->touches;
+        for (PRUint32 i = 0; i < touches.Length(); ++i) {
+          nsIDOMTouch *touch = touches[i];
+          if (!touch) {
+            break;
+          }
+  
+          PRInt32 id;
+          touch->GetIdentifier(&id);
+          nsCOMPtr<nsIDOMTouch> oldTouch;
+          gCaptureTouchList.Get(id, getter_AddRefs(oldTouch));
+          if (!oldTouch) {
+            break;
+          }
+  
+          nsCOMPtr<nsPIDOMEventTarget> targetPtr;
+          oldTouch->GetTarget(getter_AddRefs(targetPtr));
+          nsCOMPtr<nsIContent> content = do_QueryInterface(targetPtr);
+          if (!content) {
+            break;
+          }
+
+          nsIFrame* contentFrame = content->GetPrimaryFrame();
+          if (!contentFrame) {
+            break;
+          }
+
+          shell = static_cast<PresShell*>(
+                      contentFrame->PresContext()->PresShell());
+        }
+        break;
+      }
+    }
+
     // Check if we have an active EventStateManager which isn't the
     // EventStateManager of the current PresContext.
     // If that is the case, and mouse is over some ancestor document,
     // forward event handling to the active document.
     // This way content can get mouse events even when
     // mouse is over the chrome or outside the window.
     //
     // Note, currently for backwards compatibility we don't forward mouse events
@@ -6472,27 +6513,45 @@ PresShell::DispatchTouchEvent(nsEvent *a
         continue;
       }
 
       nsTouchEvent newEvent(NS_IS_TRUSTED_EVENT(touchEvent) ?
                               true : false,
                             touchEvent);
       newEvent.target = targetPtr;
 
-      nsCOMPtr<nsIContent> content(do_QueryInterface(targetPtr));
+      // If someone is capturing, all touch events are filtered to their target
+      nsCOMPtr<nsIContent> content = GetCapturingContent();
+
+      // if no one is capturing, set the capturing target
+      if (!content) {
+        content = do_QueryInterface(targetPtr);
+      }
+      PresShell* contentPresShell = nsnull;
+      if (content && content->OwnerDoc() == mDocument) {
+        contentPresShell = static_cast<PresShell*>
+            (content->OwnerDoc()->GetShell());
+        if (contentPresShell) {
+          contentPresShell->PushCurrentEventInfo(
+              content->GetPrimaryFrame(), content);
+        }
+      }
       nsPresContext *context = nsContentUtils::GetContextForContent(content);
       if (!context) {
         context = mPresContext;
       }
       tmpStatus = nsEventStatus_eIgnore;
       nsEventDispatcher::Dispatch(targetPtr, context,
                                   &newEvent, nsnull, &tmpStatus, aEventCB);
       if (nsEventStatus_eConsumeNoDefault == tmpStatus) {
         preventDefault = true;
       }
+      if (contentPresShell) {
+        contentPresShell->PopCurrentEventInfo();
+      }
     }
   } else {
     // touchevents need to have the target attribute set on each touch
     nsTArray<nsCOMPtr<nsIDOMTouch> >  touches = touchEvent->touches;
     for (PRUint32 i = 0; i < touches.Length(); ++i) {
       nsIDOMTouch *touch = touches[i];
       if (touch->mChanged) {
         touch->SetTarget(mCurrentEventContent);
--- a/layout/base/tests/Makefile.in
+++ b/layout/base/tests/Makefile.in
@@ -20,21 +20,17 @@ PARALLEL_DIRS += \
 
 BARE_UNIT_TESTS = \
 		TestPoisonArea.cpp \
 		$(NULL)
 
 CPPSRCS += $(BARE_UNIT_TESTS)
 SIMPLE_PROGRAMS += $(BARE_UNIT_TESTS:.cpp=$(BIN_SUFFIX))
 
-include $(topsrcdir)/config/rules.mk
-
-DEFINES += -D_IMPL_NS_LAYOUT
-
-_TEST_FILES =	\
+MOCHITEST_FILES =	\
 		border_radius_hit_testing_iframe.html \
 		test_preserve3d_sorting_hit_testing.html \
 		preserve3d_sorting_hit_testing_iframe.html \
 		test_image_layers.html \
 		image_rgrg-256x256.png \
 		image_rrgg-256x256.png \
 		bug369950-subframe.xml \
 		test_after_paint_pref.html \
@@ -154,26 +150,26 @@ DEFINES += -D_IMPL_NS_LAYOUT
 		test_bug725426.html \
 		test_bug731777.html \
 		test_bug761572.html \
 		$(NULL)
 
 # Tests for bugs 441782, 467672 and 570378 don't pass reliably on Windows, because of bug 469208
 ifeq (,$(filter windows,$(MOZ_WIDGET_TOOLKIT)))
 # THESE TESTS (BELOW) DO NOT RUN ON WINDOWS
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		bidi_numeral_test.js \
 		$(NULL)
 # THESE TESTS (ABOVE AND BELOW) DO NOT RUN ON WINDOWS
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_bug332655-1.html \
 		test_bug332655-2.html \
 		$(NULL)
 # THESE TESTS (ABOVE AND BELOW) DO NOT RUN ON WINDOWS
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_bug441782-1a.html \
 		test_bug441782-1b.html \
 		test_bug441782-1c.html \
 		test_bug441782-1d.html \
 		test_bug441782-1e.html \
 		bug441782-1.html \
 		bug441782-1-ref.html \
 		test_bug441782-2a.html \
@@ -201,17 +197,17 @@ ifeq (,$(filter windows,$(MOZ_WIDGET_TOO
 		test_bug441782-5b.html \
 		test_bug441782-5c.html \
 		test_bug441782-5d.html \
 		test_bug441782-5e.html \
 		bug441782-5.html \
 		bug441782-5-ref.html \
 		$(NULL)
 # THESE TESTS (ABOVE AND BELOW) DO NOT RUN ON WINDOWS
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_bug467672-1a.html \
 		test_bug467672-1b.html \
 		test_bug467672-1c.html \
 		test_bug467672-1d.html \
 		test_bug467672-1e.html \
 		test_bug467672-1f.html \
 		test_bug467672-1g.html \
 		bug467672-1.html \
@@ -249,21 +245,21 @@ ifeq (,$(filter windows,$(MOZ_WIDGET_TOO
 		test_bug467672-5d.html \
 		test_bug467672-5e.html \
 		test_bug467672-5f.html \
 		test_bug467672-5g.html \
 		bug467672-5.html \
 		bug467672-5-ref.html \
 		$(NULL)
 # THESE TESTS (ABOVE AND BELOW) DO NOT RUN ON WINDOWS
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_bug499538-1.html \
 		$(NULL)
 # THESE TESTS (ABOVE AND BELOW) DO NOT RUN ON WINDOWS
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_bug570378-arabic-1a.html \
 		test_bug570378-arabic-1b.html \
 		test_bug570378-arabic-1c.html \
 		test_bug570378-arabic-1d.html \
 		test_bug570378-arabic-1e.html \
 		bug570378-arabic-1.html \
 		bug570378-arabic-1-ref.html \
 		test_bug570378-arabic-2a.html \
@@ -337,37 +333,36 @@ ifeq (,$(filter windows,$(MOZ_WIDGET_TOO
 		test_bug570378-persian-5e.html \
 		test_bug570378-persian-5f.html \
 		test_bug570378-persian-5g.html \
 		bug570378-persian-5.html \
 		bug570378-persian-5-ref.html \
                 test_bug749186.html \
 		$(NULL)
 # THESE TESTS (ABOVE AND BELOW) DO NOT RUN ON WINDOWS
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_bug644768.html \
 		$(NULL)
 # THESE TESTS (ABOVE) DO NOT RUN ON WINDOWS
 endif
 
 # test_flush_on_paint.html fails frequently on Mac, bug 688128
 ifeq (,$(filter cocoa,$(MOZ_WIDGET_TOOLKIT)))
 # THESE TESTS (BELOW) DO NOT RUN ON MAC
-_TEST_FILES += \
+MOCHITEST_FILES += \
 		test_flush_on_paint.html \
 		$(NULL)
 # THESE TESTS (ABOVE) DO NOT RUN ON MAC
 endif
 
-_BROWSER_FILES = \
+MOCHITEST_BROWSER_FILES = \
 	browser_bug617076.js \
 	$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-libs:: $(_BROWSER_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
+
+DEFINES += -D_IMPL_NS_LAYOUT
 
 check::
 	@$(EXIT_ON_ERROR) \
 	  for f in $(subst .cpp,$(BIN_SUFFIX),$(BARE_UNIT_TESTS)); do \
 	    $(RUN_TEST_PROGRAM) $(DIST)/bin/$$f; \
 	  done
--- a/layout/base/tests/chrome/Makefile.in
+++ b/layout/base/tests/chrome/Makefile.in
@@ -4,19 +4,18 @@
 
 DEPTH     = ../../../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
 relativesrcdir  = layout/base/test/chrome
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_CHROME_FILES = \
+MOCHITEST_CHROME_FILES = \
 	paint_listener.js \
 	test_bug370436.html \
 	test_bug396367-1.html \
 	test_bug396367-2.html \
 	test_bug420499.xul \
 	test_bug495648.xul \
 	bug495648.rdf \
 	test_bug504311.xul \
@@ -41,15 +40,14 @@ include $(topsrcdir)/config/rules.mk
 	     printpreview_bug396024_helper.xul \
 	test_printpreview_bug482976.xul \
 	     printpreview_bug482976_helper.xul \
 	test_transformed_scrolling_repaints.html \
 	test_transformed_scrolling_repaints_2.html \
 	$(NULL)
 
 ifdef MOZ_DEBUG
-_CHROME_FILES += \
+MOCHITEST_CHROME_FILES += \
 	test_leaf_layers_partition_browser_window.xul \
 	$(NULL)
 endif
 
-libs:: $(_CHROME_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/layout/forms/test/Makefile.in
+++ b/layout/forms/test/Makefile.in
@@ -5,19 +5,18 @@
 
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = layout/forms/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =	test_bug231389.html \
+MOCHITEST_FILES =	test_bug231389.html \
 		test_bug287446.html \
 		     bug287446_subframe.html \
 		test_bug345267.html \
 		test_bug348236.html \
 		test_bug353539.html \
 		test_bug365410.html \
 		test_bug378670.html \
 		test_bug402198.html \
@@ -42,20 +41,16 @@ include $(topsrcdir)/config/rules.mk
 		test_bug36619.html \
 		test_bug620936.html \
 		test_bug595310.html \
 		test_bug644542.html \
 		test_bug672810.html \
 		test_bug704049.html \
 		$(NULL)
 
-_CHROME_FILES = \
+MOCHITEST_CHROME_FILES = \
 		test_bug536567.html \
 		     bug536567_subframe.html \
 		test_bug665540.html \
 		     bug665540_window.xul \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs:: $(_CHROME_FILES)
-	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -2252,25 +2252,26 @@ nsFrame::FireDOMEvent(const nsAString& a
 }
 
 NS_IMETHODIMP
 nsFrame::HandleEvent(nsPresContext* aPresContext, 
                      nsGUIEvent*     aEvent,
                      nsEventStatus*  aEventStatus)
 {
 
-  if (aEvent->message == NS_MOUSE_MOVE) {
+  if (aEvent->message == NS_MOUSE_MOVE || aEvent->message == NS_TOUCH_MOVE) {
     return HandleDrag(aPresContext, aEvent, aEventStatus);
   }
 
-  if (aEvent->eventStructType == NS_MOUSE_EVENT &&
-      static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton) {
-    if (aEvent->message == NS_MOUSE_BUTTON_DOWN) {
+  if ((aEvent->eventStructType == NS_MOUSE_EVENT &&
+      static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton) ||
+      aEvent->eventStructType == NS_TOUCH_EVENT) {
+    if (aEvent->message == NS_MOUSE_BUTTON_DOWN || aEvent->message == NS_TOUCH_START) {
       HandlePress(aPresContext, aEvent, aEventStatus);
-    } else if (aEvent->message == NS_MOUSE_BUTTON_UP) {
+    } else if (aEvent->message == NS_MOUSE_BUTTON_UP || aEvent->message == NS_TOUCH_END) {
       HandleRelease(aPresContext, aEvent, aEventStatus);
     }
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFrame::GetDataForTableSelection(const nsFrameSelection *aFrameSelection,
--- a/layout/generic/test/Makefile.in
+++ b/layout/generic/test/Makefile.in
@@ -5,21 +5,20 @@
 
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = layout/generic/test
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
 # in the list below, we make sure that the tests that require focus
 # run before test_plugin_clipping, which can steal focus for its window.
-_TEST_FILES = \
+MOCHITEST_FILES = \
   bug344830_testembed.svg \
   plugin_clipping_helper.xhtml \
   plugin_clipping_helper2.xhtml \
   plugin_clipping_helper_transformed.xhtml \
   plugin_clipping_helper_table.xhtml \
   plugin_clipping_lib.js \
   plugin_focus_helper.html \
   test_bug240933.html \
@@ -95,27 +94,23 @@ include $(topsrcdir)/config/rules.mk
   test_bug719503.html \
   test_bug719515.html \
   test_bug719518.html \
   test_bug719523.html \
   test_bug735641.html \
   test_bug748961.html \
   $(NULL)
 
-_CHROME_FILES = \
+MOCHITEST_CHROME_FILES = \
   frame_selection_underline.xhtml \
   frame_selection_underline-ref.xhtml \
   frame_selection_underline.css \
   test_selection_underline.html \
   test_bug632379.xul \
   test_bug508115.xul \
   test_bug469613.xul \
   test_bug469774.xul \
   test_backspace_delete.xul \
   test_bug514732-2.xul \
   file_bug514732_window.xul \
   $(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
-
-libs:: $(_CHROME_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/layout/inspector/tests/Makefile.in
+++ b/layout/inspector/tests/Makefile.in
@@ -5,23 +5,21 @@
 
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= layout/inspector/tests
 
 include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
 
-_TEST_FILES =\
+MOCHITEST_FILES =\
 		test_bug462787.html \
 		test_bug462789.html \
 		test_bug522601.xhtml \
 		test_bug536379.html \
 		test_bug536379-2.html \
 		test_bug557726.html \
 		test_bug609549.xhtml \
 		test_isinheritableproperty.html \
 		$(NULL)
 
-libs:: $(_TEST_FILES)
-	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
+include $(topsrcdir)/config/rules.mk
--- a/layout/inspector/tests/chrome/Makefile.in
+++ b/layout/inspector/tests/chrome/Makefile.in
@@ -5,24 +5,22 @@