From 0e0865f4fc6ba6b205488f1125a7b881a503d32e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Qu=C3=A8ze?= Date: Wed, 25 Jan 2017 07:01:52 +0100 Subject: [PATCH] Bug 1331599 - script-generated patch to replace removeEventListener calls with the once option when possible, r=jaws. --- addon-sdk/source/lib/sdk/addon/window.js | 5 +- .../source/lib/sdk/deprecated/unit-test.js | 5 +- addon-sdk/source/lib/sdk/preferences/utils.js | 5 +- addon-sdk/source/lib/sdk/ui/frame/view.js | 6 +- addon-sdk/source/lib/sdk/window/utils.js | 5 +- .../test/addons/content-permissions/main.js | 5 +- .../e10s-content/lib/test-content-script.js | 20 ++---- .../e10s-content/lib/test-content-worker.js | 10 ++- .../leak/test-leak-event-dom-closed-window.js | 5 +- .../source/test/leak/test-leak-tab-events.js | 20 +++--- .../test/leak/test-leak-window-events.js | 10 ++- addon-sdk/source/test/tabs/utils.js | 5 +- addon-sdk/source/test/test-content-script.js | 20 ++---- .../source/test/test-content-sync-worker.js | 10 ++- addon-sdk/source/test/test-content-worker.js | 10 ++- addon-sdk/source/test/test-frame-utils.js | 10 ++- addon-sdk/source/test/test-page-mod.js | 15 ++-- addon-sdk/source/test/test-ui-sidebar.js | 10 ++- addon-sdk/source/test/test-window-utils.js | 5 +- addon-sdk/source/test/test-xhr.js | 5 +- b2g/components/OrientationChangeHandler.jsm | 5 +- .../test/mochitest/systemapp_helper.js | 5 +- .../mochitest/test_sandbox_permission.html | 5 +- .../content/aboutaccounts/aboutaccounts.js | 5 +- browser/base/content/abouthome/aboutHome.js | 5 +- browser/base/content/browser.js | 5 +- browser/base/content/contentSearchUI.js | 5 +- browser/base/content/newtab/customize.js | 5 +- browser/base/content/sync/utils.js | 4 +- browser/base/content/tabbrowser.xml | 5 +- browser/base/content/test/alerts/head.js | 5 +- .../content/test/general/browser_aboutHome.js | 6 +- .../test/general/browser_backButtonFitts.js | 5 +- .../content/test/general/browser_bug321000.js | 3 +- .../content/test/general/browser_bug406216.js | 6 +- .../content/test/general/browser_bug432599.js | 5 +- .../content/test/general/browser_bug460146.js | 7 +- .../content/test/general/browser_bug479408.js | 4 +- .../content/test/general/browser_bug491431.js | 6 +- .../content/test/general/browser_bug517902.js | 7 +- .../content/test/general/browser_bug553455.js | 10 ++- .../content/test/general/browser_bug581242.js | 3 +- .../content/test/general/browser_bug581253.js | 4 +- .../content/test/general/browser_bug592338.js | 3 +- .../content/test/general/browser_bug623893.js | 8 +-- .../content/test/general/browser_bug664672.js | 4 +- .../content/test/general/browser_bug678392.js | 5 +- .../content/test/general/browser_bug734076.js | 5 +- .../content/test/general/browser_bug749738.js | 5 +- .../general/browser_bug767836_perwindowpb.js | 5 +- .../content/test/general/browser_bug817947.js | 5 +- .../content/test/general/browser_bug832435.js | 5 +- .../general/browser_clipboard_pastefile.js | 11 ++- .../general/browser_close_dependent_tabs.js | 5 +- .../browser_datachoices_notification.js | 5 +- .../content/test/general/browser_discovery.js | 6 +- .../general/browser_documentnavigation.js | 6 +- .../test/general/browser_focusonkeydown.js | 10 ++- .../test/general/browser_hide_removing.js | 4 +- .../general/browser_keywordBookmarklets.js | 5 +- .../test/general/browser_keywordSearch.js | 3 +- .../test/general/browser_newwindow_focus.js | 5 +- .../browser_offlineQuotaNotification.js | 10 ++- .../content/test/general/browser_pageInfo.js | 6 +- .../test/general/browser_sanitizeDialog.js | 4 +- ...browser_save_link_when_window_navigates.js | 6 +- .../test/general/browser_selectpopup.js | 10 ++- .../browser_subframe_favicons_not_used.js | 4 +- .../content/test/general/browser_tabfocus.js | 10 ++- .../test/general/browser_tabs_isActive.js | 5 +- .../browser_visibleTabs_bookmarkAllTabs.js | 3 +- .../content/test/general/contentSearchUI.js | 5 +- .../general/file_fullscreen-window-open.html | 6 +- browser/base/content/test/general/head.js | 25 +++---- browser/base/content/test/newtab/head.js | 5 +- browser/base/content/test/plugins/head.js | 5 +- .../content/test/popupNotifications/head.js | 5 +- ...ser_referrer_open_link_in_container_tab.js | 11 ++- ...er_referrer_open_link_in_container_tab3.js | 11 ++- .../content/test/social/browser_blocklist.js | 11 ++- .../base/content/test/social/browser_share.js | 5 +- .../test/social/browser_social_activation.js | 5 +- .../test/urlbar/browser_URLBarSetURI.js | 10 ++- .../browser_bug1104165-switchtab-decodeuri.js | 5 +- .../content/test/urlbar/browser_bug304198.js | 3 +- .../test/urlbar/browser_locationBarCommand.js | 5 +- .../urlbar/browser_locationBarExternalLoad.js | 5 +- .../urlbar/browser_urlbarAboutHomeLoading.js | 10 ++- ...ser_urlbarSearchSuggestionsNotification.js | 5 +- .../webrtc/browser_devices_get_user_media.js | 6 +- .../browser_devices_get_user_media_anim.js | 6 +- ...browser_devices_get_user_media_in_frame.js | 6 +- .../browser_devices_get_user_media_screen.js | 6 +- ...ser_devices_get_user_media_tear_off_tab.js | 6 +- ...evices_get_user_media_unprompted_access.js | 6 +- ...t_user_media_unprompted_access_in_frame.js | 6 +- ...er_media_unprompted_access_tear_off_tab.js | 6 +- .../test/webrtc/browser_webrtc_hooks.js | 6 +- browser/base/content/test/webrtc/head.js | 12 ++-- .../test/browser/browser_middleClick.js | 5 +- .../customizableui/CustomizableUI.jsm | 5 +- .../customizableui/ScrollbarSampler.jsm | 5 +- .../customizableui/content/panelUI.js | 5 +- .../browser_947914_button_newPrivateWindow.js | 5 +- .../test/browser_947914_button_newWindow.js | 5 +- .../test/browser_967000_button_sync.js | 5 +- .../components/customizableui/test/head.js | 10 ++- .../components/downloads/DownloadsCommon.jsm | 5 +- .../browser/browser_downloads_panel_block.js | 5 +- .../components/downloads/test/browser/head.js | 10 ++- browser/components/extensions/ext-tabs.js | 10 ++- browser/components/extensions/ext-utils.js | 5 +- browser/components/extensions/ext-windows.js | 5 +- .../extensions/test/browser/head.js | 5 +- .../tests/browser/browser_PreviewProvider.js | 5 +- .../originattributes/test/browser/head.js | 5 +- .../places/tests/browser/browser_555547.js | 5 +- .../browser/browser_bookmarksProperties.js | 12 ++-- .../browser/browser_forgetthissite_single.js | 5 +- .../browser/browser_sidebarpanels_click.js | 3 +- .../tests/browser/browser_views_liveupdate.js | 3 +- .../components/places/tests/browser/head.js | 15 ++-- ...g1020245_openPreferences_to_paneContent.js | 10 ++- .../preferences/in-content/tests/head.js | 18 ++--- .../browser/browser_privatebrowsing_cache.js | 6 +- ...rowser_privatebrowsing_certexceptionsui.js | 5 +- .../browser_privatebrowsing_opendir.js | 5 +- .../browser_privatebrowsing_popupblocker.js | 4 +- .../browser_privatebrowsing_theming.js | 5 +- .../browser/browser_privatebrowsing_ui.js | 11 ++- .../privatebrowsing/test/browser/head.js | 5 +- .../search/test/browser_abouthome_behavior.js | 5 +- .../search/test/browser_amazon_behavior.js | 5 +- .../search/test/browser_bing_behavior.js | 5 +- .../search/test/browser_contextmenu.js | 5 +- .../search/test/browser_ddg_behavior.js | 5 +- .../search/test/browser_google_behavior.js | 5 +- .../search/test/browser_yahoo_behavior.js | 5 +- .../sessionstore/test/browser_464620_b.html | 3 +- .../test/browser_466937_sample.html | 3 +- .../sessionstore/test/browser_514751.js | 4 +- .../sessionstore/test/browser_580512.js | 3 +- ...rowser_586068-browser_state_interrupted.js | 5 +- .../test/browser_586068-multi_window.js | 5 +- .../sessionstore/test/browser_588426.js | 11 ++- .../sessionstore/test/browser_589246.js | 19 ++--- .../sessionstore/test/browser_590563.js | 11 ++- .../browser_615394-SSWindowState_events.js | 8 +-- .../sessionstore/test/browser_628270.js | 5 +- .../sessionstore/test/browser_636279.js | 6 +- .../test/browser_644409-scratchpads.js | 6 +- .../sessionstore/test/browser_659591.js | 10 ++- .../sessionstore/test/browser_662812.js | 17 ++--- .../test/browser_grouped_session_store.js | 5 +- .../test/browser_windowRestore_perwindowpb.js | 5 +- browser/components/sessionstore/test/head.js | 19 ++--- .../browser/browser_sidebar_syncedtabslist.js | 5 +- .../tests/browser/browser_bug538331.js | 3 +- .../test/browser_translation_exceptions.js | 15 ++-- .../test/browser_translation_infobar.js | 5 +- .../translation/translation-infobar.xml | 6 +- browser/components/uitour/UITour.jsm | 15 ++-- .../components/uitour/test/browser_UITour.js | 10 ++- .../test/browser_UITour_resetProfile.js | 5 +- browser/components/uitour/test/head.js | 6 +- .../mortar/host/pdf/chrome/js/l20n.js | 5 +- .../mortar/host/pdf/chrome/js/toolbar.js | 5 +- .../pdfjs/test/browser_pdfjs_navigation.js | 10 ++- browser/modules/test/browser_ContentSearch.js | 5 +- .../test/browser_ProcessHangNotifications.js | 5 +- browser/modules/webrtcUI.jsm | 5 +- .../extension/configurations/Preferences.jsm | 5 +- devtools/client/aboutdebugging/initializer.js | 10 ++- devtools/client/canvasdebugger/test/head.js | 5 +- .../test/browser_cmd_screenshot.js | 5 +- .../mochitest/browser_dbg_on-pause-raise.js | 5 +- .../browser_dbg_sources-contextmenu-02.js | 10 ++- .../test/mochitest/code_frame-script.js | 15 ++-- .../mochitest/doc_closure-optimized-out.html | 5 +- .../debugger/test/mochitest/doc_closures.html | 5 +- .../mochitest/doc_event-listeners-01.html | 5 +- .../mochitest/doc_event-listeners-02.html | 5 +- .../mochitest/doc_event-listeners-03.html | 5 +- .../client/debugger/test/mochitest/head.js | 6 +- .../debugger/views/global-search-view.js | 5 +- devtools/client/framework/connect/connect.js | 5 +- ...ble_serviceworkers_testing_frame_script.js | 5 +- .../client/framework/test/browser_two_tabs.js | 12 ++-- devtools/client/inspector/local-toolbox.js | 6 +- .../test/service-workers/status-codes.html | 5 +- .../plugins/app-manager/app-project-editor.js | 5 +- devtools/client/projecteditor/test/head.js | 10 ++- devtools/client/responsive.html/index.js | 5 +- .../test/browser/browser_touch_simulation.js | 5 +- ..._scratchpad_browser_last_window_closing.js | 5 +- .../browser_scratchpad_chrome_context_pref.js | 6 +- .../test/browser_scratchpad_contexts.js | 5 +- ...scratchpad_display_non_error_exceptions.js | 5 +- ...owser_scratchpad_display_outputs_errors.js | 5 +- .../browser_scratchpad_edit_ui_updates.js | 15 ++-- .../test/browser_scratchpad_eval_func.js | 5 +- .../test/browser_scratchpad_execute_print.js | 5 +- .../test/browser_scratchpad_falsy.js | 5 +- .../test/browser_scratchpad_files.js | 5 +- .../test/browser_scratchpad_goto_line_ui.js | 5 +- .../test/browser_scratchpad_help_key.js | 6 +- .../test/browser_scratchpad_initialization.js | 6 +- .../test/browser_scratchpad_inspect.js | 5 +- .../test/browser_scratchpad_long_string.js | 5 +- .../test/browser_scratchpad_modeline.js | 5 +- .../browser_scratchpad_open_error_console.js | 5 +- .../test/browser_scratchpad_pprint-02.js | 5 +- .../test/browser_scratchpad_pprint.js | 5 +- ...owser_scratchpad_pprint_error_goto_line.js | 5 +- .../test/browser_scratchpad_recent_files.js | 5 +- .../test/browser_scratchpad_reload_and_run.js | 17 ++--- ...rowser_scratchpad_remember_view_options.js | 5 +- .../test/browser_scratchpad_reset_undo.js | 5 +- .../browser_scratchpad_revert_to_saved.js | 5 +- .../browser_scratchpad_run_error_goto_line.js | 5 +- .../scratchpad/test/browser_scratchpad_tab.js | 6 +- .../test/browser_scratchpad_tab_switch.js | 11 ++- .../test/browser_scratchpad_throw_output.js | 5 +- .../scratchpad/test/browser_scratchpad_ui.js | 5 +- .../browser_scratchpad_wrong_window_focus.js | 12 ++-- devtools/client/scratchpad/test/head.js | 5 +- devtools/client/shadereditor/test/head.js | 5 +- devtools/client/shared/frame-script-utils.js | 5 +- ...rowser_tableWidget_keyboard_interaction.js | 6 +- .../browser_tableWidget_mouse_interaction.js | 6 +- .../browser_telemetry_button_scratchpad.js | 6 +- ...browser_treeWidget_keyboard_interaction.js | 20 +++--- devtools/client/shared/test/test-actor.js | 6 +- devtools/client/shared/widgets/Graphs.js | 5 +- .../test/browser_editor_find_again.js | 5 +- devtools/client/sourceeditor/test/head.js | 6 +- .../test/browser_styleeditor_opentab.js | 10 ++- devtools/client/styleeditor/test/head.js | 5 +- devtools/client/webaudioeditor/test/head.js | 5 +- devtools/client/webconsole/console-output.js | 10 ++- devtools/client/webconsole/hudservice.js | 6 +- devtools/client/webconsole/jsterm.js | 5 +- ...rowser_webconsole_context_menu_open_url.js | 10 ++- devtools/client/webconsole/panel.js | 5 +- .../browser_bug_871156_ctrlw_close_tab.js | 10 ++- ...ser_netmonitor_shows_reqs_in_webconsole.js | 5 +- ...ebconsole_bug_595934_message_categories.js | 5 +- ...e_bug_653531_highlighter_console_helper.js | 5 +- ...r_webconsole_bug_764572_output_open_url.js | 5 +- ...webconsole_dont_navigate_on_doubleclick.js | 5 +- ...owser_webconsole_output_dom_elements_04.js | 5 +- ...ser_webconsole_shows_reqs_in_netmonitor.js | 5 +- devtools/client/webconsole/test/head.js | 10 ++- .../test/test-closure-optimized-out.html | 5 +- .../client/webconsole/test/test-error.html | 5 +- devtools/client/webide/content/addons.js | 15 ++-- devtools/client/webide/content/details.js | 10 ++- .../webide/content/devicepreferences.js | 10 ++- devtools/client/webide/content/logs.js | 12 ++-- devtools/client/webide/content/monitor.js | 5 +- devtools/client/webide/content/newapp.js | 5 +- devtools/client/webide/content/prefs.js | 11 ++- .../client/webide/content/project-listing.js | 10 ++- .../client/webide/content/runtime-listing.js | 10 ++- .../client/webide/content/runtimedetails.js | 10 ++- devtools/client/webide/content/webide.js | 10 ++- devtools/client/webide/content/wifi-auth.js | 5 +- devtools/client/webide/modules/runtimes.js | 5 +- devtools/client/webide/test/head.js | 20 +++--- .../tests/browser/browser_navigateEvents.js | 6 +- .../browser_webextension_inspected_window.js | 5 +- .../test_saveHeapSnapshot_e10s_01.html | 5 +- devtools/shared/security/prompt.js | 5 +- devtools/shared/webconsole/test/common.js | 5 +- .../test_console_serviceworker_cached.html | 5 +- docshell/test/browser/browser_bug554155.js | 4 +- ...owser_grouped_shistory_bfcache_cleaning.js | 10 ++- .../browser_grouped_shistory_crossproc.js | 10 ++- .../browser_grouped_shistory_dead_navigate.js | 5 +- docshell/test/browser/head.js | 10 ++- .../chrome/test_private_hidden_window.html | 5 +- docshell/test/navigation/test_bug430723.html | 10 +-- dom/base/test/browser_bug1058164.js | 5 +- dom/base/test/browser_bug593387.js | 12 ++-- .../test/browser_pagehide_on_tab_close.js | 6 +- dom/base/test/iframe_bug962251.html | 5 +- dom/base/test/test_bug564863.xhtml | 15 ++-- dom/base/test/test_bug588990.html | 12 ++-- dom/base/test/test_bug962251.html | 70 ++++++++----------- dom/base/test/test_bug976673.html | 6 +- dom/base/test/test_domwindowutils.html | 10 ++- .../tests/browser_private_browsing.js | 10 ++- .../mochitest/browserElement_Alert.js | 10 ++- .../mochitest/browserElement_Auth.js | 30 ++++---- .../mochitest/browserElement_CopyPaste.js | 16 ++--- .../mochitest/browserElement_DataURI.js | 5 +- .../mochitest/browserElement_ExecuteScript.js | 5 +- .../mochitest/browserElement_OpenNamed.js | 6 +- .../browserElement_SetVisibleFrames2.js | 5 +- .../browserElement_getWebManifest.js | 5 +- ...browserElement_XFrameOptionsAllowFrom.html | 10 ++- ...file_browserElement_XFrameOptionsDeny.html | 10 ++- .../mochitest/priority/test_HighPriority.html | 5 +- dom/crypto/test/test_indexedDB.html | 5 +- .../mochitest_support_external.js | 5 +- dom/events/test/test_bug1128787-1.html | 3 +- dom/events/test/test_bug1128787-2.html | 3 +- dom/events/test/test_bug1128787-3.html | 3 +- dom/events/test/test_bug534833.html | 3 +- dom/events/test/test_bug822898.html | 21 ++---- dom/events/test/test_bug930374-chrome.html | 3 +- dom/events/test/test_bug930374-content.html | 6 +- dom/events/test/test_error_events.html | 5 +- .../compat/tests/test_formSubmission.html | 5 +- .../tests/test_webkitdirectory.html | 5 +- dom/html/test/file_fullscreen-navigation.html | 5 +- .../test/forms/test_formaction_attribute.html | 24 +++---- dom/html/test/forms/test_meter_element.html | 9 +-- .../test/forms/test_novalidate_attribute.html | 9 +-- .../test/forms/test_progress_element.html | 9 +-- .../forms/test_save_restore_radio_groups.html | 7 +- dom/html/test/test_bug369370.html | 10 ++- dom/html/test/test_bug557087-1.html | 3 +- dom/html/test/test_bug561636.html | 19 ++--- dom/html/test/test_bug566046.html | 24 +++---- dom/html/test/test_bug567938-4.html | 3 +- dom/html/test/test_bug582412-1.html | 30 +++----- dom/html/test/test_bug582412-2.html | 30 +++----- dom/html/test/test_bug592802.html | 3 +- dom/html/test/test_bug601030.html | 6 +- dom/html/test/test_bug612730.html | 4 +- dom/html/test/test_bug615833.html | 45 ++++-------- dom/html/test/test_bug619278.html | 4 +- dom/html/test/test_bug622558.html | 12 +--- dom/html/test/test_bug622597.html | 20 ++---- dom/html/test/test_bug633058.html | 4 +- dom/html/test/test_bug651956.html | 6 +- dom/html/test/test_fullscreen-api.html | 5 +- dom/html/test/test_ignoreuserfocus.html | 11 ++- dom/indexedDB/test/browser_forgetThisSite.js | 16 ++--- .../test/browser_permissionsPromptAllow.js | 8 +-- .../test/browser_permissionsPromptDeny.js | 5 +- .../test/browser_permissionsPromptWorker.js | 8 +-- .../test/browser_perwindow_privateBrowsing.js | 5 +- .../test_window_onappinstalled_event.html | 5 +- .../test/test_HaveMetadataUnbufferedSeek.html | 5 +- .../test_HaveMetadataUnbufferedSeek_mp4.html | 5 +- .../test_SeekableBeforeEndOfStreamSplit.html | 3 +- ...st_SeekableBeforeEndOfStreamSplit_mp4.html | 3 +- dom/media/test/test_texttrackcue.html | 5 +- dom/media/test/test_webvtt_positionalign.html | 3 +- dom/network/tests/file_udpsocket_iframe.html | 5 +- dom/network/tests/test_udpsocket.html | 40 +++++------ dom/plugins/test/mochitest/head.js | 10 ++- dom/plugins/test/mochitest/plugin-utils.js | 5 +- .../mochitest/test_pluginstream_3rdparty.html | 5 +- dom/power/test/browser_wakelocks.js | 35 ++++------ .../file_presentation_1ua_receiver.html | 20 +++--- ..._presentation_mixed_security_contexts.html | 5 +- .../mochitest/file_presentation_receiver.html | 5 +- ...e_presentation_sandboxed_presentation.html | 5 +- ...st_presentation_1ua_connection_wentaway.js | 5 +- ...st_presentation_1ua_sender_and_receiver.js | 20 +++--- .../test_presentation_dc_receiver_oop.html | 5 +- .../test_presentation_dc_sender.html | 5 +- .../test_presentation_device_info.html | 15 ++-- .../test_presentation_reconnect.html | 5 +- .../test_presentation_tcp_sender.html | 5 +- .../mochitest/test_presentation_terminate.js | 5 +- ...on_terminate_establish_connection_error.js | 5 +- dom/smil/test/test_smilHyperlinking.xhtml | 10 ++- ...rowser_ConsoleStoragePBTest_perwindowpb.js | 11 ++- ...rowser_localStorage_privatestorageevent.js | 10 ++- dom/tests/browser/browser_prerendering.js | 10 ++- dom/tests/browser/prevent_return_key.html | 6 +- dom/tests/mochitest/bugs/test_bug1171215.html | 5 +- .../mochitest/bugs/test_errorReporting.html | 5 +- .../mochitest/general/file_clonewrapper.html | 5 +- .../test_contentViewer_overrideDPPX.html | 6 +- ...torageBasePrivateBrowsing_perwindowpb.html | 5 +- ...orageQuotaPrivateBrowsing_perwindowpb.html | 5 +- dom/workers/test/head.js | 5 +- .../test/serviceworkers/browser_download.js | 5 +- .../test_file_blob_response.html | 5 +- .../serviceworkers/test_file_blob_upload.html | 10 ++- .../serviceworkers/test_privateBrowsing.html | 5 +- .../test_sharedWorker_privateBrowsing.html | 5 +- dom/xbl/test/file_bug944407.xml | 5 +- editor/composer/test/test_bug519928.html | 8 +-- .../tests/test_CF_HTML_clipboard.html | 6 +- editor/libeditor/tests/test_bug289384.html | 5 +- editor/libeditor/tests/test_bug597331.html | 4 +- editor/libeditor/tests/test_bug600570.html | 4 +- editor/libeditor/tests/test_bug611182.html | 4 +- editor/libeditor/tests/test_bug966155.html | 5 +- editor/libeditor/tests/test_bug966552.html | 5 +- .../tests/test_keypress_untrusted_event.html | 9 +-- .../mochitest/apz_test_native_event_utils.js | 10 ++- image/test/browser/browser_image.js | 9 +-- .../mochitest/test_crossOriginObjects.html | 5 +- layout/base/tests/bug970964_inner.html | 3 +- layout/forms/test/test_bug1305282.html | 6 +- layout/forms/test/test_bug572649.html | 3 +- ...t-opacity-removing-animation-in-delay.html | 5 +- ...transform-removing-animation-in-delay.html | 5 +- .../layers/component-alpha-exit-1.html | 5 +- layout/tools/reftest/bootstrap.js | 9 +-- layout/xul/test/browser_bug1163304.js | 6 +- .../chrome/content/WebcompatReporter.js | 6 +- .../android/chrome/content/aboutAccounts.js | 5 +- mobile/android/chrome/content/browser.js | 6 +- mobile/android/extensions/flyweb/bootstrap.js | 5 +- .../tests/browser/chrome/test_awsy_lite.html | 5 +- .../browser/chrome/test_video_discovery.html | 5 +- .../tests/browser/robocop/robocop_input.html | 6 +- .../browser/robocop/roboextender/bootstrap.js | 3 +- .../browser/robocop/testBrowserDiscovery.js | 10 ++- .../browser/robocop/testHistoryService.js | 5 +- .../browser/robocop/testTrackingProtection.js | 10 ++- .../browser/robocop/testVideoControls.js | 5 +- netwerk/test/browser/browser_NetUtil.js | 4 +- .../mochitest/test_img_picture_preload.html | 5 +- .../browser/browser_bug627234_perwindowpb.js | 10 ++- .../browser/browser_clientAuth_ui.js | 5 +- .../browser/browser_deleteCert_ui.js | 5 +- .../browser/browser_downloadCert_ui.js | 5 +- .../browser/browser_editCACertTrust.js | 5 +- .../browser/browser_exportP12_passwordUI.js | 5 +- .../tps/resource/modules/windows.jsm | 5 +- testing/marionette/components/marionette.js | 6 +- .../BrowserTestUtils/BrowserTestUtils.jsm | 16 ++--- testing/mochitest/bootstrap.js | 5 +- testing/mochitest/browser-test.js | 10 ++- testing/mochitest/redirect.html | 5 +- .../Harness_sanity/test_sanityEventUtils.html | 6 +- .../addoncompat/tests/addon/bootstrap.js | 11 ++- .../test/test_alerts_requireinteraction.html | 5 +- .../alerts/test/test_multiple_alerts.html | 11 ++- .../components/extensions/ExtensionUtils.jsm | 5 +- .../extensions/test/mochitest/head.js | 5 +- .../formautofill/test/chrome/loader.js | 6 +- .../passwordmgr/LoginManagerContent.jsm | 5 +- .../chrome/test_privbrowsing_perwindowpb.html | 5 +- .../test_autocomplete_https_upgrade.html | 5 +- .../test/mochitest/test_autofocus_js.html | 5 +- .../test_formless_submit_navigation.html | 5 +- ...t_formless_submit_navigation_negative.html | 5 +- ...ser_favicon_privatebrowsing_perwindowpb.js | 5 +- .../tests/browser/browser_history_post.js | 5 +- .../components/prompts/test/prompt_common.js | 5 +- .../browser/browser_RemoteWebNavigation.js | 10 ++- .../satchel/test/test_form_autocomplete.html | 3 +- .../test_form_autocomplete_with_list.html | 3 +- .../tests/browser/browser_bug511456.js | 6 +- .../tests/browser/browser_bug537449.js | 5 +- .../test/browser_thumbnails_bug726727.js | 5 +- toolkit/components/thumbnails/test/head.js | 5 +- .../tests/browser_input_file_tooltips.js | 5 +- .../tests/mochitest/test_donottrack.html | 5 +- ...st_privatebrowsing_trackingprotection.html | 5 +- .../test_trackingprotection_bug1157081.html | 5 +- .../test_trackingprotection_whitelist.html | 5 +- .../viewsource/test/browser/head.js | 5 +- .../test/test_storage_copied.html | 5 +- toolkit/content/aboutNetworking.js | 5 +- toolkit/content/aboutProfiles.js | 5 +- toolkit/content/aboutServiceWorkers.js | 5 +- toolkit/content/aboutTelemetry.js | 5 +- .../tests/browser/browser_bug1170531.js | 10 ++- .../content/tests/browser/browser_findbar.js | 5 +- .../tests/chrome/test_about_networking.html | 5 +- .../test_autocomplete_change_after_focus.html | 5 +- .../test_videocontrols_standalone.html | 20 +++--- .../widgets/videocontrols_direction_test.js | 3 +- .../browser/browser_WebRequest_cookies.js | 5 +- .../browser/browser_WebRequest_filtering.js | 5 +- .../mozapps/extensions/content/extensions.js | 10 ++- .../test/browser/browser_bug523784.js | 10 +-- .../test/browser/browser_bug557956.js | 13 ++-- .../test/browser/browser_bug586574.js | 6 +- .../test/browser/browser_bug591465.js | 68 +++++------------- .../test/browser/browser_cancelCompatCheck.js | 9 +-- .../test/browser/browser_details.js | 6 +- .../test/browser/browser_manualupdates.js | 21 ++---- .../test/browser/browser_metadataTimeout.js | 6 +- .../test/browser/browser_newaddon.js | 4 +- .../test/browser/browser_purchase.js | 10 ++- .../test/browser/browser_recentupdates.js | 3 +- .../test/browser/browser_tabsettings.js | 3 +- .../mozapps/extensions/test/browser/head.js | 12 ++-- toolkit/mozapps/update/tests/chrome/utils.js | 5 +- 491 files changed, 1353 insertions(+), 2307 deletions(-) diff --git a/addon-sdk/source/lib/sdk/addon/window.js b/addon-sdk/source/lib/sdk/addon/window.js index 93bb36525d2c..8c099e2de485 100644 --- a/addon-sdk/source/lib/sdk/addon/window.js +++ b/addon-sdk/source/lib/sdk/addon/window.js @@ -51,10 +51,9 @@ window.location = "data:application/vnd.mozilla.xul+xml;charset=utf-8," // Create a promise that is delivered once add-on window is interactive, // used by add-on runner to defer add-on loading until window is ready. var { promise, resolve } = defer(); -eventTarget.addEventListener("DOMContentLoaded", function handler(event) { - eventTarget.removeEventListener("DOMContentLoaded", handler); +eventTarget.addEventListener("DOMContentLoaded", function(event) { resolve(); -}); +}, {once: true}); exports.ready = promise; exports.window = window; diff --git a/addon-sdk/source/lib/sdk/deprecated/unit-test.js b/addon-sdk/source/lib/sdk/deprecated/unit-test.js index e5016f2b5acb..39c7759da923 100644 --- a/addon-sdk/source/lib/sdk/deprecated/unit-test.js +++ b/addon-sdk/source/lib/sdk/deprecated/unit-test.js @@ -317,10 +317,9 @@ TestRunner.prototype = { resolve() } else { - win.addEventListener("DOMContentLoaded", function onLoad() { - win.removeEventListener("DOMContentLoaded", onLoad); + win.addEventListener("DOMContentLoaded", function() { resolve(); - }); + }, {once: true}); } }); }); diff --git a/addon-sdk/source/lib/sdk/preferences/utils.js b/addon-sdk/source/lib/sdk/preferences/utils.js index 1d5769c37def..7f46dd19c675 100644 --- a/addon-sdk/source/lib/sdk/preferences/utils.js +++ b/addon-sdk/source/lib/sdk/preferences/utils.js @@ -19,8 +19,7 @@ const open = ({ id }) => new Promise((resolve, reject) => { let browser = getBrowserForTab(tab); // waiting for the about:addons page to load - browser.addEventListener("load", function onPageLoad() { - browser.removeEventListener("load", onPageLoad, true); + browser.addEventListener("load", function() { let window = browser.contentWindow; // wait for the add-on's "addon-options-displayed" @@ -37,6 +36,6 @@ const open = ({ id }) => new Promise((resolve, reject) => { // display the add-on inline preferences page window.gViewController.commands.cmd_showItemDetails.doCommand({ id: id }, true); - }, true); + }, {capture: true, once: true}); }); exports.open = open; diff --git a/addon-sdk/source/lib/sdk/ui/frame/view.js b/addon-sdk/source/lib/sdk/ui/frame/view.js index 2eb4df2b709b..3eb4013ca752 100644 --- a/addon-sdk/source/lib/sdk/ui/frame/view.js +++ b/addon-sdk/source/lib/sdk/ui/frame/view.js @@ -74,9 +74,7 @@ const registerFrame = ({id, url}) => { outerFrame.setAttribute("scrolling", "no"); outerFrame.setAttribute("disablehistory", true); outerFrame.setAttribute("seamless", "seamless"); - outerFrame.addEventListener("load", function onload() { - outerFrame.removeEventListener("load", onload, true); - + outerFrame.addEventListener("load", function() { let doc = outerFrame.contentDocument; let innerFrame = doc.createElementNS(HTML_NS, "iframe"); @@ -91,7 +89,7 @@ const registerFrame = ({id, url}) => { "left: 0", "overflow: hidden"].join(";")); doc.body.appendChild(innerFrame); - }, true); + }, {capture: true, once: true}); view.appendChild(outerFrame); diff --git a/addon-sdk/source/lib/sdk/window/utils.js b/addon-sdk/source/lib/sdk/window/utils.js index ce4ef2841a84..e48d07e0dde4 100644 --- a/addon-sdk/source/lib/sdk/window/utils.js +++ b/addon-sdk/source/lib/sdk/window/utils.js @@ -213,10 +213,9 @@ function onFocus(window) { resolve(window); } else { - window.addEventListener("focus", function focusListener() { - window.removeEventListener("focus", focusListener, true); + window.addEventListener("focus", function() { resolve(window); - }, true); + }, {capture: true, once: true}); } return promise; diff --git a/addon-sdk/source/test/addons/content-permissions/main.js b/addon-sdk/source/test/addons/content-permissions/main.js index e26ba0614d8b..3de23c5ab4d1 100644 --- a/addon-sdk/source/test/addons/content-permissions/main.js +++ b/addon-sdk/source/test/addons/content-permissions/main.js @@ -21,10 +21,9 @@ exports.testCrossDomainIframe = function(assert, done) { contentScript: "new " + function ContentScriptScope() { self.on("message", function (url) { let iframe = document.createElement("iframe"); - iframe.addEventListener("load", function onload() { - iframe.removeEventListener("load", onload); + iframe.addEventListener("load", function() { self.postMessage(iframe.contentWindow.document.body.innerHTML); - }); + }, {once: true}); iframe.setAttribute("src", url); document.documentElement.appendChild(iframe); }); diff --git a/addon-sdk/source/test/addons/e10s-content/lib/test-content-script.js b/addon-sdk/source/test/addons/e10s-content/lib/test-content-script.js index 99c781ac5b53..4e99257837cd 100644 --- a/addon-sdk/source/test/addons/e10s-content/lib/test-content-script.js +++ b/addon-sdk/source/test/addons/e10s-content/lib/test-content-script.js @@ -173,8 +173,7 @@ exports["test postMessage"] = createProxyTest(html, function (helper, assert) { let ifWindow = helper.xrayWindow.document.getElementById("iframe").contentWindow; // Listen without proxies, to check that it will work in regular case // simulate listening from a web document. - ifWindow.addEventListener("message", function listener(event) { - ifWindow.removeEventListener("message", listener); + ifWindow.addEventListener("message", function(event) { // As we are in system principal, event is an XrayWrapper // xrays use current compartments when calling postMessage method. // Whereas js proxies was using postMessage method compartment, @@ -187,7 +186,7 @@ exports["test postMessage"] = createProxyTest(html, function (helper, assert) { "message data is correct"); helper.done(); - }); + }, {once: true}); helper.createWorker( 'new ' + function ContentScriptScope() { @@ -659,8 +658,6 @@ exports["test Listeners"] = createProxyTest(html, function (helper) { let addEventListenerCalled = false; let expandoCalled = false; input.addEventListener("click", function onclick(event) { - input.removeEventListener("click", onclick, true); - assert(!addEventListenerCalled, "closure given to addEventListener is called once"); if (addEventListenerCalled) return; @@ -689,7 +686,7 @@ exports["test Listeners"] = createProxyTest(html, function (helper) { input.click(); }, 0); - }, true); + }, {capture: true, once: true}); input.click(); } @@ -747,21 +744,18 @@ exports["test Cross Domain Iframe"] = createProxyTest("", function (helper) { self.on("message", function (url) { // Creates an iframe with this page let iframe = document.createElement("iframe"); - iframe.addEventListener("load", function onload() { - iframe.removeEventListener("load", onload, true); + iframe.addEventListener("load", function() { try { // Try to communicate with iframe's content - window.addEventListener("message", function onmessage(event) { - window.removeEventListener("message", onmessage, true); - + window.addEventListener("message", function(event) { assert(event.data == "hello world", "COW works properly"); self.port.emit("end"); - }, true); + }, {capture: true, once: true}); iframe.contentWindow.postMessage("hello", "*"); } catch(e) { assert(false, "COW fails : "+e.message); } - }, true); + }, {capture: true, once: true}); iframe.setAttribute("src", url); document.body.appendChild(iframe); }); diff --git a/addon-sdk/source/test/addons/e10s-content/lib/test-content-worker.js b/addon-sdk/source/test/addons/e10s-content/lib/test-content-worker.js index 70cb2ec68d73..b876ec66fa8c 100644 --- a/addon-sdk/source/test/addons/e10s-content/lib/test-content-worker.js +++ b/addon-sdk/source/test/addons/e10s-content/lib/test-content-worker.js @@ -75,8 +75,7 @@ function loadAndWait(browser, url, callback) { function WorkerTest(url, callback) { return function testFunction(assert, done) { let chromeWindow = makeWindow(); - chromeWindow.addEventListener("load", function onload() { - chromeWindow.removeEventListener("load", onload, true); + chromeWindow.addEventListener("load", function() { let browser = chromeWindow.document.createElement("browser"); browser.setAttribute("type", "content"); chromeWindow.document.documentElement.appendChild(browser); @@ -90,7 +89,7 @@ function WorkerTest(url, callback) { }); }); }); - }, true); + }, {capture: true, once: true}); }; } @@ -767,8 +766,7 @@ exports["test:check worker API with page history"] = WorkerTest( }, 0); // Wait for the document to be hidden - browser.addEventListener("pagehide", function onpagehide() { - browser.removeEventListener("pagehide", onpagehide); + browser.addEventListener("pagehide", function() { // Now any event sent to this worker should be cached worker.postMessage("message"); @@ -808,7 +806,7 @@ exports["test:check worker API with page history"] = WorkerTest( browser.goForward(); }, 500); - }); + }, {once: true}); }); } diff --git a/addon-sdk/source/test/leak/test-leak-event-dom-closed-window.js b/addon-sdk/source/test/leak/test-leak-event-dom-closed-window.js index c398462ab4c7..5209ff73953a 100644 --- a/addon-sdk/source/test/leak/test-leak-event-dom-closed-window.js +++ b/addon-sdk/source/test/leak/test-leak-event-dom-closed-window.js @@ -13,14 +13,13 @@ exports["test sdk/event/dom does not leak when attached to closed window"] = fun let loader = Loader(module); let { open } = loader.require('sdk/event/dom'); let w = openWindow(); - w.addEventListener("DOMWindowClose", function windowClosed(evt) { - w.removeEventListener("DOMWindowClose", windowClosed); + w.addEventListener("DOMWindowClose", function(evt) { // The sdk/event/dom module tries to clean itself up when DOMWindowClose // is fired. Verify that it doesn't leak if its attached to an // already closed window either. (See bug 1268898.) open(w.document, "TestEvent1"); resolve(loader); - }); + }, {once: true}); w.close(); }); }); diff --git a/addon-sdk/source/test/leak/test-leak-tab-events.js b/addon-sdk/source/test/leak/test-leak-tab-events.js index 4266c04fc079..536c8cec310f 100644 --- a/addon-sdk/source/test/leak/test-leak-tab-events.js +++ b/addon-sdk/source/test/leak/test-leak-tab-events.js @@ -13,14 +13,12 @@ exports["test sdk/tab/events does not leak new window"] = function*(assert) { let loader = Loader(module); let { events } = loader.require('sdk/tab/events'); let w = openWindow(); - w.addEventListener("load", function windowLoaded(evt) { - w.removeEventListener("load", windowLoaded); - w.addEventListener("DOMWindowClose", function windowClosed(evt) { - w.removeEventListener("DOMWindowClose", windowClosed); + w.addEventListener("load", function(evt) { + w.addEventListener("DOMWindowClose", function(evt) { resolve(loader); - }); + }, {once: true}); w.close(); - }); + }, {once: true}); }); }); } @@ -30,15 +28,13 @@ exports["test sdk/tab/events does not leak when attached to existing window"] = return new Promise(resolve => { let loader = Loader(module); let w = openWindow(); - w.addEventListener("load", function windowLoaded(evt) { - w.removeEventListener("load", windowLoaded); + w.addEventListener("load", function(evt) { let { events } = loader.require('sdk/tab/events'); - w.addEventListener("DOMWindowClose", function windowClosed(evt) { - w.removeEventListener("DOMWindowClose", windowClosed); + w.addEventListener("DOMWindowClose", function(evt) { resolve(loader); - }); + }, {once: true}); w.close(); - }); + }, {once: true}); }); }); } diff --git a/addon-sdk/source/test/leak/test-leak-window-events.js b/addon-sdk/source/test/leak/test-leak-window-events.js index ceb20f47556b..df3836484fdd 100644 --- a/addon-sdk/source/test/leak/test-leak-window-events.js +++ b/addon-sdk/source/test/leak/test-leak-window-events.js @@ -49,15 +49,13 @@ exports["test window/events for leaks with existing window"] = function*(assert) return new Promise((resolve, reject) => { let loader = Loader(module); let w = open(); - w.addEventListener("load", function windowLoaded(evt) { - w.removeEventListener("load", windowLoaded); + w.addEventListener("load", function(evt) { let { events } = loader.require("sdk/window/events"); - w.addEventListener("DOMWindowClose", function windowClosed(evt) { - w.removeEventListener("DOMWindowClose", windowClosed); + w.addEventListener("DOMWindowClose", function(evt) { resolve(loader); - }); + }, {once: true}); w.close(); - }); + }, {once: true}); }); }); }; diff --git a/addon-sdk/source/test/tabs/utils.js b/addon-sdk/source/test/tabs/utils.js index 4981a4d087bb..a3a7f5cf33c0 100644 --- a/addon-sdk/source/test/tabs/utils.js +++ b/addon-sdk/source/test/tabs/utils.js @@ -13,10 +13,9 @@ function openTab(rawWindow, url) { return resolve(); } - window.addEventListener("load", function onLoad() { - window.removeEventListener("load", onLoad, true); + window.addEventListener("load", function() { resolve(); - }, true); + }, {capture: true, once: true}); return null; }) diff --git a/addon-sdk/source/test/test-content-script.js b/addon-sdk/source/test/test-content-script.js index a9bcc697e9ac..a180ec241ce8 100644 --- a/addon-sdk/source/test/test-content-script.js +++ b/addon-sdk/source/test/test-content-script.js @@ -173,8 +173,7 @@ exports["test postMessage"] = createProxyTest(html, function (helper, assert) { let ifWindow = helper.xrayWindow.document.getElementById("iframe").contentWindow; // Listen without proxies, to check that it will work in regular case // simulate listening from a web document. - ifWindow.addEventListener("message", function listener(event) { - ifWindow.removeEventListener("message", listener); + ifWindow.addEventListener("message", function(event) { // As we are in system principal, event is an XrayWrapper // xrays use current compartments when calling postMessage method. // Whereas js proxies was using postMessage method compartment, @@ -187,7 +186,7 @@ exports["test postMessage"] = createProxyTest(html, function (helper, assert) { "message data is correct"); helper.done(); - }); + }, {once: true}); helper.createWorker( 'new ' + function ContentScriptScope() { @@ -659,8 +658,6 @@ exports["test Listeners"] = createProxyTest(html, function (helper) { let addEventListenerCalled = false; let expandoCalled = false; input.addEventListener("click", function onclick(event) { - input.removeEventListener("click", onclick, true); - assert(!addEventListenerCalled, "closure given to addEventListener is called once"); if (addEventListenerCalled) return; @@ -689,7 +686,7 @@ exports["test Listeners"] = createProxyTest(html, function (helper) { input.click(); }, 0); - }, true); + }, {capture: true, once: true}); input.click(); } @@ -747,21 +744,18 @@ exports["test Cross Domain Iframe"] = createProxyTest("", function (helper) { self.on("message", function (url) { // Creates an iframe with this page let iframe = document.createElement("iframe"); - iframe.addEventListener("load", function onload() { - iframe.removeEventListener("load", onload, true); + iframe.addEventListener("load", function() { try { // Try to communicate with iframe's content - window.addEventListener("message", function onmessage(event) { - window.removeEventListener("message", onmessage, true); - + window.addEventListener("message", function(event) { assert(event.data == "hello world", "COW works properly"); self.port.emit("end"); - }, true); + }, {capture: true, once: true}); iframe.contentWindow.postMessage("hello", "*"); } catch(e) { assert(false, "COW fails : "+e.message); } - }, true); + }, {capture: true, once: true}); iframe.setAttribute("src", url); document.body.appendChild(iframe); }); diff --git a/addon-sdk/source/test/test-content-sync-worker.js b/addon-sdk/source/test/test-content-sync-worker.js index f68a43fcff2d..258be6fab26b 100644 --- a/addon-sdk/source/test/test-content-sync-worker.js +++ b/addon-sdk/source/test/test-content-sync-worker.js @@ -74,8 +74,7 @@ function loadAndWait(browser, url, callback) { function WorkerTest(url, callback) { return function testFunction(assert, done) { let chromeWindow = makeWindow(); - chromeWindow.addEventListener("load", function onload() { - chromeWindow.removeEventListener("load", onload, true); + chromeWindow.addEventListener("load", function() { let browser = chromeWindow.document.createElement("browser"); browser.setAttribute("type", "content"); chromeWindow.document.documentElement.appendChild(browser); @@ -89,7 +88,7 @@ function WorkerTest(url, callback) { }); }); }); - }, true); + }, {capture: true, once: true}); }; } @@ -751,8 +750,7 @@ exports["test:check worker API with page history"] = WorkerTest( }, 0); // Wait for the document to be hidden - browser.addEventListener("pagehide", function onpagehide() { - browser.removeEventListener("pagehide", onpagehide); + browser.addEventListener("pagehide", function() { // Now any event sent to this worker should throw assert.throws( @@ -781,7 +779,7 @@ exports["test:check worker API with page history"] = WorkerTest( browser.goForward(); }, 500); - }); + }, {once: true}); }); } diff --git a/addon-sdk/source/test/test-content-worker.js b/addon-sdk/source/test/test-content-worker.js index 4409b25c6417..6bc3d9d89e2c 100644 --- a/addon-sdk/source/test/test-content-worker.js +++ b/addon-sdk/source/test/test-content-worker.js @@ -75,8 +75,7 @@ function loadAndWait(browser, url, callback) { function WorkerTest(url, callback) { return function testFunction(assert, done) { let chromeWindow = makeWindow(); - chromeWindow.addEventListener("load", function onload() { - chromeWindow.removeEventListener("load", onload, true); + chromeWindow.addEventListener("load", function() { let browser = chromeWindow.document.createElement("browser"); browser.setAttribute("type", "content"); chromeWindow.document.documentElement.appendChild(browser); @@ -90,7 +89,7 @@ function WorkerTest(url, callback) { }); }); }); - }, true); + }, {capture: true, once: true}); }; } @@ -768,8 +767,7 @@ exports["test:check worker API with page history"] = WorkerTest( }, 0); // Wait for the document to be hidden - browser.addEventListener("pagehide", function onpagehide() { - browser.removeEventListener("pagehide", onpagehide); + browser.addEventListener("pagehide", function() { // Now any event sent to this worker should be cached worker.postMessage("message"); @@ -809,7 +807,7 @@ exports["test:check worker API with page history"] = WorkerTest( browser.goForward(); }, 500); - }); + }, {once: true}); }); } diff --git a/addon-sdk/source/test/test-frame-utils.js b/addon-sdk/source/test/test-frame-utils.js index bffdcd06a749..3b9311204e5e 100644 --- a/addon-sdk/source/test/test-frame-utils.js +++ b/addon-sdk/source/test/test-frame-utils.js @@ -29,13 +29,12 @@ exports['test fram has js disabled by default'] = function(assert, done) { uri: 'data:text/html;charset=utf-8,', }); - frame.contentWindow.addEventListener('DOMContentLoaded', function ready() { - frame.contentWindow.removeEventListener('DOMContentLoaded', ready); + frame.contentWindow.addEventListener('DOMContentLoaded', function() { assert.ok(!~frame.contentDocument.documentElement.innerHTML.indexOf('JS'), 'JS was executed'); close(window).then(done); - }); + }, {once: true}); }); }; @@ -46,13 +45,12 @@ exports['test frame with js enabled'] = function(assert, done) { '= "J" + "S"', allowJavascript: true }); - frame.contentWindow.addEventListener('DOMContentLoaded', function ready() { - frame.contentWindow.removeEventListener('DOMContentLoaded', ready); + frame.contentWindow.addEventListener('DOMContentLoaded', function() { assert.ok(~frame.contentDocument.documentElement.innerHTML.indexOf('JS'), 'JS was executed'); close(window).then(done); - }); + }, {once: true}); }); }; diff --git a/addon-sdk/source/test/test-page-mod.js b/addon-sdk/source/test/test-page-mod.js index 19e79be25cfd..d17378313c85 100644 --- a/addon-sdk/source/test/test-page-mod.js +++ b/addon-sdk/source/test/test-page-mod.js @@ -1027,8 +1027,7 @@ exports.testAttachToTabsOnly = function(assert, done) { let hiddenFrame = hiddenFrames.add(hiddenFrames.HiddenFrame({ onReady: function () { let element = this.element; - element.addEventListener('DOMContentLoaded', function onload() { - element.removeEventListener('DOMContentLoaded', onload); + element.addEventListener('DOMContentLoaded', function() { hiddenFrames.remove(hiddenFrame); if (!xulApp.is("Fennec")) { @@ -1037,7 +1036,7 @@ exports.testAttachToTabsOnly = function(assert, done) { else { openBrowserIframe(); } - }); + }, {once: true}); element.setAttribute('src', 'data:text/html;charset=utf-8,foo'); } })); @@ -1046,11 +1045,10 @@ exports.testAttachToTabsOnly = function(assert, done) { function openToplevelWindow() { assert.pass('Open toplevel window'); let win = open('data:text/html;charset=utf-8,bar'); - win.addEventListener('DOMContentLoaded', function onload() { - win.removeEventListener('DOMContentLoaded', onload); + win.addEventListener('DOMContentLoaded', function() { win.close(); openBrowserIframe(); - }); + }, {once: true}); } function openBrowserIframe() { @@ -1060,11 +1058,10 @@ exports.testAttachToTabsOnly = function(assert, done) { let iframe = document.createElement('iframe'); iframe.setAttribute('type', 'content'); iframe.setAttribute('src', 'data:text/html;charset=utf-8,foobar'); - iframe.addEventListener('DOMContentLoaded', function onload() { - iframe.removeEventListener('DOMContentLoaded', onload); + iframe.addEventListener('DOMContentLoaded', function() { iframe.parentNode.removeChild(iframe); openTabWithIframes(); - }); + }, {once: true}); document.documentElement.appendChild(iframe); } diff --git a/addon-sdk/source/test/test-ui-sidebar.js b/addon-sdk/source/test/test-ui-sidebar.js index a92cc3c43cb9..1d5f6ad64175 100644 --- a/addon-sdk/source/test/test-ui-sidebar.js +++ b/addon-sdk/source/test/test-ui-sidebar.js @@ -1095,10 +1095,9 @@ exports.testSidebarLeakCheckDestroyAfterAttach = function*(assert) { yield new Promise(resolve => { let panelBrowser = window.document.getElementById('sidebar').contentDocument.getElementById('web-panels-browser'); - panelBrowser.contentWindow.addEventListener('unload', function onUnload() { - panelBrowser.contentWindow.removeEventListener('unload', onUnload); + panelBrowser.contentWindow.addEventListener('unload', function() { resolve(); - }); + }, {once: true}); sidebar.destroy(); }); @@ -1137,10 +1136,9 @@ exports.testSidebarLeakCheckUnloadAfterAttach = function*(assert) { let panelBrowser = window.document.getElementById('sidebar').contentDocument.getElementById('web-panels-browser'); yield new Promise(resolve => { - panelBrowser.contentWindow.addEventListener('unload', function onUnload() { - panelBrowser.contentWindow.removeEventListener('unload', onUnload); + panelBrowser.contentWindow.addEventListener('unload', function() { resolve(); - }); + }, {once: true}); loader.unload(); }); diff --git a/addon-sdk/source/test/test-window-utils.js b/addon-sdk/source/test/test-window-utils.js index f2104c6145b6..34b3ccb868ce 100644 --- a/addon-sdk/source/test/test-window-utils.js +++ b/addon-sdk/source/test/test-window-utils.js @@ -41,8 +41,7 @@ exports.testWindowTracker = function(assert, done) { var myWindow = makeEmptyWindow(); assert.pass('window was created'); - myWindow.addEventListener("load", function onload() { - myWindow.removeEventListener("load", onload); + myWindow.addEventListener("load", function() { assert.pass("test window has opened"); // test bug 638007 (new is optional), using new @@ -61,7 +60,7 @@ exports.testWindowTracker = function(assert, done) { } } }); - }); + }, {once: true}); }; exports['test window watcher untracker'] = function(assert, done) { diff --git a/addon-sdk/source/test/test-xhr.js b/addon-sdk/source/test/test-xhr.js index 30ee8e3621d2..3f243400a5e7 100644 --- a/addon-sdk/source/test/test-xhr.js +++ b/addon-sdk/source/test/test-xhr.js @@ -51,12 +51,11 @@ exports.testLocalXhr = function(assert, done) { assert.equal(req.responseText, '{}\n', 'XMLHttpRequest should get local files'); } }; - req.addEventListener('load', function onload() { - req.removeEventListener('load', onload); + req.addEventListener('load', function() { assert.pass('addEventListener for load event worked'); assert.ok(ready, 'onreadystatechange listener worked'); done(); - }); + }, {once: true}); req.send(null); }; diff --git a/b2g/components/OrientationChangeHandler.jsm b/b2g/components/OrientationChangeHandler.jsm index 5007b70e08f6..d2df6f115666 100644 --- a/b2g/components/OrientationChangeHandler.jsm +++ b/b2g/components/OrientationChangeHandler.jsm @@ -60,10 +60,9 @@ var OrientationChangeHandler = { return; } - window.addEventListener("resize", function waitForResize(e) { - window.removeEventListener("resize", waitForResize); + window.addEventListener("resize", function(e) { trigger(); - }); + }, {once: true}); } }; diff --git a/b2g/components/test/mochitest/systemapp_helper.js b/b2g/components/test/mochitest/systemapp_helper.js index 88e0d8d50976..8204686f1dd8 100644 --- a/b2g/components/test/mochitest/systemapp_helper.js +++ b/b2g/components/test/mochitest/systemapp_helper.js @@ -113,8 +113,7 @@ var steps = [ SystemAppProxy.registerFrame(frame); assert.ok(true, "Frame created and registered"); - frame.contentWindow.addEventListener("load", function onload() { - frame.contentWindow.removeEventListener("load", onload); + frame.contentWindow.addEventListener("load", function() { assert.ok(true, "Frame document loaded"); // Declare that the iframe is now loaded. @@ -128,7 +127,7 @@ var steps = [ // Once pending events are received, // we will run checkEventDispatching from `listener` function - }); + }, {once: true}); frame.setAttribute("src", "data:text/html,system app"); }, diff --git a/b2g/components/test/mochitest/test_sandbox_permission.html b/b2g/components/test/mochitest/test_sandbox_permission.html index 7d56b83bb60d..dec3161004ec 100644 --- a/b2g/components/test/mochitest/test_sandbox_permission.html +++ b/b2g/components/test/mochitest/test_sandbox_permission.html @@ -50,10 +50,9 @@ function loadBrowser() { iframe.src = 'about:blank'; document.body.appendChild(iframe); - iframe.addEventListener("load", function onLoad() { - iframe.removeEventListener("load", onLoad); + iframe.addEventListener("load", function() { runNext(); - }); + }, {once: true}); } gScript.addMessageListener("permission-request", function (detail) { diff --git a/browser/base/content/aboutaccounts/aboutaccounts.js b/browser/base/content/aboutaccounts/aboutaccounts.js index 5baac940836a..acfaa1f8a0cc 100644 --- a/browser/base/content/aboutaccounts/aboutaccounts.js +++ b/browser/base/content/aboutaccounts/aboutaccounts.js @@ -497,8 +497,7 @@ function getDefaultProfilePath() { return defaultProfile.rootDir.path; } -document.addEventListener("DOMContentLoaded", function onload() { - document.removeEventListener("DOMContentLoaded", onload, true); +document.addEventListener("DOMContentLoaded", function() { init(); var buttonGetStarted = document.getElementById("buttonGetStarted"); buttonGetStarted.addEventListener("click", getStarted); @@ -511,7 +510,7 @@ document.addEventListener("DOMContentLoaded", function onload() { var buttonOpenPrefs = document.getElementById("buttonOpenPrefs") buttonOpenPrefs.addEventListener("click", openPrefs); -}, true); +}, {capture: true, once: true}); function initObservers() { function observe(subject, topic, data) { diff --git a/browser/base/content/abouthome/aboutHome.js b/browser/base/content/abouthome/aboutHome.js index 3c139b6f96a7..a88eb522410f 100644 --- a/browser/base/content/abouthome/aboutHome.js +++ b/browser/base/content/abouthome/aboutHome.js @@ -226,10 +226,9 @@ function setupSearch() { // immediately when the element is first drawn, so the // attribute is also used for styling when the page first loads. searchText = document.getElementById("searchText"); - searchText.addEventListener("blur", function searchText_onBlur() { - searchText.removeEventListener("blur", searchText_onBlur); + searchText.addEventListener("blur", function() { searchText.removeAttribute("autofocus"); - }); + }, {once: true}); if (!gContentSearchController) { gContentSearchController = diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 77601e90518c..88a634bfae3d 100755 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -1943,10 +1943,9 @@ function focusAndSelectUrlBar() { // We can't focus it when it's disabled, so we need to re-run ourselves when // we've finished leaving customize mode. if (CustomizationHandler.isExitingCustomizeMode) { - gNavToolbox.addEventListener("aftercustomization", function afterCustomize() { - gNavToolbox.removeEventListener("aftercustomization", afterCustomize); + gNavToolbox.addEventListener("aftercustomization", function() { focusAndSelectUrlBar(); - }); + }, {once: true}); return true; } diff --git a/browser/base/content/contentSearchUI.js b/browser/base/content/contentSearchUI.js index 509532a885a7..8833e6ccffa4 100644 --- a/browser/base/content/contentSearchUI.js +++ b/browser/base/content/contentSearchUI.js @@ -853,10 +853,9 @@ ContentSearchUIController.prototype = { "chrome://browser/skin/search-engine-placeholder.png"); } img.setAttribute("src", uri); - img.addEventListener("load", function imgLoad() { - img.removeEventListener("load", imgLoad); + img.addEventListener("load", function() { URL.revokeObjectURL(uri); - }); + }, {once: true}); button.appendChild(img); button.style.width = buttonWidth + "px"; button.setAttribute("title", engine.name); diff --git a/browser/base/content/newtab/customize.js b/browser/base/content/newtab/customize.js index 28a52373c686..95d46c2ebd88 100644 --- a/browser/base/content/newtab/customize.js +++ b/browser/base/content/newtab/customize.js @@ -32,10 +32,9 @@ var gCustomize = { }, hidePanel: function() { - this._nodes.overlay.addEventListener("transitionend", function onTransitionEnd() { - gCustomize._nodes.overlay.removeEventListener("transitionend", onTransitionEnd); + this._nodes.overlay.addEventListener("transitionend", function() { gCustomize._nodes.overlay.style.display = "none"; - }); + }, {once: true}); this._nodes.overlay.style.opacity = 0; this._nodes.button.removeAttribute("active"); this._nodes.panel.removeAttribute("open"); diff --git a/browser/base/content/sync/utils.js b/browser/base/content/sync/utils.js index 0d608dffcb77..2c868791cb6e 100644 --- a/browser/base/content/sync/utils.js +++ b/browser/base/content/sync/utils.js @@ -111,8 +111,6 @@ var gSyncUtils = { iframe.collapsed = true; document.documentElement.appendChild(iframe); iframe.contentWindow.addEventListener("load", function() { - iframe.contentWindow.removeEventListener("load", arguments.callee); - // Insert the Sync Key into the page. let el = iframe.contentDocument.getElementById("synckey"); el.firstChild.nodeValue = pp; @@ -129,7 +127,7 @@ var gSyncUtils = { el.firstChild.nodeValue = privacyURL; callback(iframe); - }); + }, {once: true}); }, /** diff --git a/browser/base/content/tabbrowser.xml b/browser/base/content/tabbrowser.xml index 2e68cb6f8107..97c4b4e39f40 100644 --- a/browser/base/content/tabbrowser.xml +++ b/browser/base/content/tabbrowser.xml @@ -1114,10 +1114,9 @@ var forwardButtonContainer = document.getElementById("urlbar-wrapper"); if (forwardButtonContainer) { forwardButtonContainer.setAttribute("switchingtabs", "true"); - window.addEventListener("MozAfterPaint", function removeSwitchingtabsAttr() { - window.removeEventListener("MozAfterPaint", removeSwitchingtabsAttr); + window.addEventListener("MozAfterPaint", function() { forwardButtonContainer.removeAttribute("switchingtabs"); - }); + }, {once: true}); } this._appendStatusPanel(); diff --git a/browser/base/content/test/alerts/head.js b/browser/base/content/test/alerts/head.js index cb818a209b20..f357e836f82b 100644 --- a/browser/base/content/test/alerts/head.js +++ b/browser/base/content/test/alerts/head.js @@ -3,15 +3,14 @@ function promiseAlertWindow() { let listener = { onOpenWindow(window) { let alertWindow = window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow); - alertWindow.addEventListener("load", function onLoad() { - alertWindow.removeEventListener("load", onLoad); + alertWindow.addEventListener("load", function() { let windowType = alertWindow.document.documentElement.getAttribute("windowtype"); if (windowType != "alert:alert") { return; } Services.wm.removeListener(listener); resolve(alertWindow); - }); + }, {once: true}); }, }; Services.wm.addListener(listener); diff --git a/browser/base/content/test/general/browser_aboutHome.js b/browser/base/content/test/general/browser_aboutHome.js index cf9ed841e481..e8febd35d01f 100644 --- a/browser/base/content/test/general/browser_aboutHome.js +++ b/browser/base/content/test/general/browser_aboutHome.js @@ -565,9 +565,7 @@ function* withSnippetsMap(setupFn, testFn, testArgs = null, parentFn = null) { let document = content.document; // We're not using Promise-based listeners, because they resolve asynchronously. // The snippets test setup code relies on synchronous behaviour here. - document.addEventListener("AboutHomeLoadSnippets", function loadSnippets() { - document.removeEventListener("AboutHomeLoadSnippets", loadSnippets); - + document.addEventListener("AboutHomeLoadSnippets", function() { let updateSnippets; if (args.setupFnSource) { updateSnippets = eval(`(() => (${args.setupFnSource}))()`); @@ -594,7 +592,7 @@ function* withSnippetsMap(setupFn, testFn, testArgs = null, parentFn = null) { resolve(); }); - }); + }, {once: true}); }); }); }; diff --git a/browser/base/content/test/general/browser_backButtonFitts.js b/browser/base/content/test/general/browser_backButtonFitts.js index b749f97651e6..f5b98ef5c36a 100644 --- a/browser/base/content/test/general/browser_backButtonFitts.js +++ b/browser/base/content/test/general/browser_backButtonFitts.js @@ -12,10 +12,9 @@ add_task(function* () { // While in the child process, add a listener for the popstate event here. This // event will fire when the mouse click happens. - content.addEventListener("popstate", function onPopState() { - content.removeEventListener("popstate", onPopState); + content.addEventListener("popstate", function() { sendAsyncMessage("Test:PopStateOccurred", { location: content.document.location.href }); - }); + }, {once: true}); }); window.maximize(); diff --git a/browser/base/content/test/general/browser_bug321000.js b/browser/base/content/test/general/browser_bug321000.js index feb5c195b81d..6150f636bae7 100644 --- a/browser/base/content/test/general/browser_bug321000.js +++ b/browser/base/content/test/general/browser_bug321000.js @@ -68,13 +68,12 @@ function test_paste(aCurrentTest) { // Focus the element and wait for focus event. info("About to focus " + element.id); element.addEventListener("focus", function() { - element.removeEventListener("focus", arguments.callee); executeSoon(function() { // Pasting is async because the Accel+V codepath ends up going through // nsDocumentViewer::FireClipboardEvent. info("Pasting into " + element.id); EventUtils.synthesizeKey("v", { accelKey: true }); }); - }); + }, {once: true}); element.focus(); } diff --git a/browser/base/content/test/general/browser_bug406216.js b/browser/base/content/test/general/browser_bug406216.js index b31ccae4f87a..551e73bf73e0 100644 --- a/browser/base/content/test/general/browser_bug406216.js +++ b/browser/base/content/test/general/browser_bug406216.js @@ -25,10 +25,9 @@ function addTab(aURI, aIndex) { gBrowser.removeTab(gBrowser.tabs[0], {skipPermitUnload: true}); tab.linkedBrowser.addEventListener("load", function(event) { - event.currentTarget.removeEventListener("load", arguments.callee, true); if (++count == URIS.length) executeSoon(doTabsTest); - }, true); + }, {capture: true, once: true}); } function doTabsTest() { @@ -36,14 +35,13 @@ function doTabsTest() { // sample of "close related tabs" feature gBrowser.tabContainer.addEventListener("TabClose", function(event) { - event.currentTarget.removeEventListener("TabClose", arguments.callee, true); var closedTab = event.originalTarget; var scheme = closedTab.linkedBrowser.currentURI.scheme; Array.slice(gBrowser.tabs).forEach(function(aTab) { if (aTab != closedTab && aTab.linkedBrowser.currentURI.scheme == scheme) gBrowser.removeTab(aTab, {skipPermitUnload: true}); }); - }, true); + }, {capture: true, once: true}); gBrowser.removeTab(gBrowser.tabs[0], {skipPermitUnload: true}); is(gBrowser.tabs.length, 1, "Related tabs are not closed unexpectedly"); diff --git a/browser/base/content/test/general/browser_bug432599.js b/browser/base/content/test/general/browser_bug432599.js index 3912dea87e86..ce420a717528 100644 --- a/browser/base/content/test/general/browser_bug432599.js +++ b/browser/base/content/test/general/browser_bug432599.js @@ -44,10 +44,9 @@ function test() { waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function() { waitForStarChange(false, initTest); - }, true); + }, {capture: true, once: true}); content.location = testURL; } diff --git a/browser/base/content/test/general/browser_bug460146.js b/browser/base/content/test/general/browser_bug460146.js index e88ea987cd19..fad4d3638ee9 100644 --- a/browser/base/content/test/general/browser_bug460146.js +++ b/browser/base/content/test/general/browser_bug460146.js @@ -6,13 +6,10 @@ function test() { gBrowser.selectedTab = gBrowser.addTab(); gBrowser.selectedBrowser.addEventListener("load", function() { - gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); - var pageInfo = BrowserPageInfo(gBrowser.selectedBrowser.currentURI.spec, "mediaTab"); pageInfo.addEventListener("load", function() { - pageInfo.removeEventListener("load", arguments.callee, true); pageInfo.onFinished.push(function() { executeSoon(function() { var imageTree = pageInfo.document.getElementById("imagetree"); @@ -28,8 +25,8 @@ function test() { finish(); }); }); - }, true); - }, true); + }, {capture: true, once: true}); + }, {capture: true, once: true}); content.location = "data:text/html," + diff --git a/browser/base/content/test/general/browser_bug479408.js b/browser/base/content/test/general/browser_bug479408.js index 0dfa96f2ef23..4603d8197477 100644 --- a/browser/base/content/test/general/browser_bug479408.js +++ b/browser/base/content/test/general/browser_bug479408.js @@ -4,8 +4,6 @@ function test() { "http://mochi.test:8888/browser/browser/base/content/test/general/browser_bug479408_sample.html"); gBrowser.addEventListener("DOMLinkAdded", function(aEvent) { - gBrowser.removeEventListener("DOMLinkAdded", arguments.callee, true); - executeSoon(function() { ok(!tab.linkedBrowser.engines, "the subframe's search engine wasn't detected"); @@ -13,5 +11,5 @@ function test() { gBrowser.removeTab(tab); finish(); }); - }, true); + }, {capture: true, once: true}); } diff --git a/browser/base/content/test/general/browser_bug491431.js b/browser/base/content/test/general/browser_bug491431.js index d270e912eeb5..959eb893dbdc 100644 --- a/browser/base/content/test/general/browser_bug491431.js +++ b/browser/base/content/test/general/browser_bug491431.js @@ -12,13 +12,11 @@ function test() { // test normal close tabA = gBrowser.addTab(testPage); gBrowser.tabContainer.addEventListener("TabClose", function(firstTabCloseEvent) { - gBrowser.tabContainer.removeEventListener("TabClose", arguments.callee, true); ok(!firstTabCloseEvent.detail.adoptedBy, "This was a normal tab close"); // test tab close by moving tabB = gBrowser.addTab(testPage); gBrowser.tabContainer.addEventListener("TabClose", function(secondTabCloseEvent) { - gBrowser.tabContainer.removeEventListener("TabClose", arguments.callee, true); executeSoon(function() { ok(secondTabCloseEvent.detail.adoptedBy, "This was a tab closed by moving"); @@ -26,9 +24,9 @@ function test() { newWin.close(); executeSoon(finish); }); - }, true); + }, {capture: true, once: true}); newWin = gBrowser.replaceTabWithWindow(tabB); - }, true); + }, {capture: true, once: true}); gBrowser.removeTab(tabA); } diff --git a/browser/base/content/test/general/browser_bug517902.js b/browser/base/content/test/general/browser_bug517902.js index 5304af639a34..fb25f2a5994c 100644 --- a/browser/base/content/test/general/browser_bug517902.js +++ b/browser/base/content/test/general/browser_bug517902.js @@ -6,15 +6,12 @@ function test() { gBrowser.selectedTab = gBrowser.addTab(); gBrowser.selectedBrowser.addEventListener("load", function() { - gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); - var doc = gBrowser.contentDocument; var testImg = doc.getElementById("test-image"); var pageInfo = BrowserPageInfo(gBrowser.selectedBrowser.currentURI.spec, "mediaTab", testImg); pageInfo.addEventListener("load", function() { - pageInfo.removeEventListener("load", arguments.callee, true); pageInfo.onFinished.push(function() { executeSoon(function() { var pageInfoImg = pageInfo.document.getElementById("thepreviewimage"); @@ -28,8 +25,8 @@ function test() { finish(); }); }); - }, true); - }, true); + }, {capture: true, once: true}); + }, {capture: true, once: true}); content.location = "data:text/html," + diff --git a/browser/base/content/test/general/browser_bug553455.js b/browser/base/content/test/general/browser_bug553455.js index 7354f9788d96..96a2f12db603 100644 --- a/browser/base/content/test/general/browser_bug553455.js +++ b/browser/base/content/test/general/browser_bug553455.js @@ -61,10 +61,9 @@ function waitForProgressNotification(aPanelOpen = false, aExpectedCount = 1) { panelEventPromise = Promise.resolve(); } else { panelEventPromise = new Promise(resolve => { - PopupNotifications.panel.addEventListener("popupshowing", function eventListener() { - PopupNotifications.panel.removeEventListener("popupshowing", eventListener); + PopupNotifications.panel.addEventListener("popupshowing", function() { resolve(); - }); + }, {once: true}); }); } @@ -134,10 +133,9 @@ function waitForNotification(aId, aExpectedCount = 1) { function waitForNotificationClose() { return new Promise(resolve => { info("Waiting for notification to close"); - PopupNotifications.panel.addEventListener("popuphidden", function listener() { - PopupNotifications.panel.removeEventListener("popuphidden", listener); + PopupNotifications.panel.addEventListener("popuphidden", function() { resolve(); - }); + }, {once: true}); }); } diff --git a/browser/base/content/test/general/browser_bug581242.js b/browser/base/content/test/general/browser_bug581242.js index 668c0cd41966..25f1329574e0 100644 --- a/browser/base/content/test/general/browser_bug581242.js +++ b/browser/base/content/test/general/browser_bug581242.js @@ -12,10 +12,9 @@ function test() { // Verify that about:addons loads waitForExplicitFinish(); gBrowser.selectedBrowser.addEventListener("load", function() { - gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); let browser = blanktab.linkedBrowser; is(browser.currentURI.spec, "about:addons", "about:addons should load into blank tab."); gBrowser.removeTab(blanktab); finish(); - }, true); + }, {capture: true, once: true}); } diff --git a/browser/base/content/test/general/browser_bug581253.js b/browser/base/content/test/general/browser_bug581253.js index 3a9dc8951f6b..d7cd1fd6a37d 100644 --- a/browser/base/content/test/general/browser_bug581253.js +++ b/browser/base/content/test/general/browser_bug581253.js @@ -17,8 +17,6 @@ function test() { let tab = gBrowser.selectedTab = gBrowser.addTab(); tab.linkedBrowser.addEventListener("load", (function(event) { - tab.linkedBrowser.removeEventListener("load", arguments.callee, true); - let uri = makeURI(testURL); let bmTxn = new PlacesCreateBookmarkTransaction(uri, @@ -28,7 +26,7 @@ function test() { ok(PlacesUtils.bookmarks.isBookmarked(uri), "the test url is bookmarked"); waitForStarChange(true, onStarred); - }), true); + }), {capture: true, once: true}); content.location = testURL; } diff --git a/browser/base/content/test/general/browser_bug592338.js b/browser/base/content/test/general/browser_bug592338.js index 30c1461f368f..80177abdc791 100644 --- a/browser/base/content/test/general/browser_bug592338.js +++ b/browser/base/content/test/general/browser_bug592338.js @@ -10,9 +10,8 @@ var LightweightThemeManager = tempScope.LightweightThemeManager; function wait_for_notification(aCallback) { PopupNotifications.panel.addEventListener("popupshown", function() { - PopupNotifications.panel.removeEventListener("popupshown", arguments.callee); aCallback(PopupNotifications.panel); - }); + }, {once: true}); } var TESTS = [ diff --git a/browser/base/content/test/general/browser_bug623893.js b/browser/base/content/test/general/browser_bug623893.js index f165c8848081..fea92517f8bc 100644 --- a/browser/base/content/test/general/browser_bug623893.js +++ b/browser/base/content/test/general/browser_bug623893.js @@ -30,18 +30,16 @@ function duplicate(delta, msg, cb) { duplicateTabIn(gBrowser.selectedTab, "tab", delta); let tab = gBrowser.selectedTab; - tab.addEventListener("SSTabRestored", function tabRestoredListener() { - tab.removeEventListener("SSTabRestored", tabRestoredListener); + tab.addEventListener("SSTabRestored", function() { is(gBrowser.sessionHistory.index, start + delta, msg); executeSoon(cb); - }); + }, {once: true}); } function loadAndWait(url, cb) { gBrowser.selectedBrowser.addEventListener("load", function() { - gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); executeSoon(cb); - }, true); + }, {capture: true, once: true}); gBrowser.loadURI(url); } diff --git a/browser/base/content/test/general/browser_bug664672.js b/browser/base/content/test/general/browser_bug664672.js index ef40dfac2404..22858c048104 100644 --- a/browser/base/content/test/general/browser_bug664672.js +++ b/browser/base/content/test/general/browser_bug664672.js @@ -4,8 +4,6 @@ function test() { var tab = gBrowser.addTab(); tab.addEventListener("TabClose", function() { - tab.removeEventListener("TabClose", arguments.callee); - ok(tab.linkedBrowser, "linkedBrowser should still exist during the TabClose event"); executeSoon(function() { @@ -13,7 +11,7 @@ function test() { finish(); }); - }); + }, {once: true}); gBrowser.removeTab(tab); } diff --git a/browser/base/content/test/general/browser_bug678392.js b/browser/base/content/test/general/browser_bug678392.js index 5a995217daf4..6d13a410f742 100644 --- a/browser/base/content/test/general/browser_bug678392.js +++ b/browser/base/content/test/general/browser_bug678392.js @@ -35,10 +35,9 @@ function test() { } function load(aTab, aUrl, aCallback) { - aTab.linkedBrowser.addEventListener("load", function onload(aEvent) { - aEvent.currentTarget.removeEventListener("load", onload, true); + aTab.linkedBrowser.addEventListener("load", function(aEvent) { waitForFocus(aCallback, content); - }, true); + }, {capture: true, once: true}); aTab.linkedBrowser.loadURI(aUrl); } diff --git a/browser/base/content/test/general/browser_bug734076.js b/browser/base/content/test/general/browser_bug734076.js index c4606bb0a19b..c8722476224d 100644 --- a/browser/base/content/test/general/browser_bug734076.js +++ b/browser/base/content/test/general/browser_bug734076.js @@ -65,10 +65,9 @@ add_task(function* () { // Wait for the iframe to load. return new Promise(resolve => { - iframe.addEventListener("load", function onload() { - iframe.removeEventListener("load", onload, true); + iframe.addEventListener("load", function() { resolve("context-showonlythisframe"); - }, true); + }, {capture: true, once: true}); }); }); }, diff --git a/browser/base/content/test/general/browser_bug749738.js b/browser/base/content/test/general/browser_bug749738.js index 3d56176867b0..8ab464f5eaf1 100644 --- a/browser/base/content/test/general/browser_bug749738.js +++ b/browser/base/content/test/general/browser_bug749738.js @@ -28,9 +28,8 @@ function test() { } function load(aTab, aUrl, aCallback) { - aTab.linkedBrowser.addEventListener("load", function onload(aEvent) { - aEvent.currentTarget.removeEventListener("load", onload, true); + aTab.linkedBrowser.addEventListener("load", function(aEvent) { waitForFocus(aCallback, content); - }, true); + }, {capture: true, once: true}); aTab.linkedBrowser.loadURI(aUrl); } diff --git a/browser/base/content/test/general/browser_bug767836_perwindowpb.js b/browser/base/content/test/general/browser_bug767836_perwindowpb.js index 54451ec54531..1d32bf019281 100644 --- a/browser/base/content/test/general/browser_bug767836_perwindowpb.js +++ b/browser/base/content/test/general/browser_bug767836_perwindowpb.js @@ -83,8 +83,7 @@ function openNewTab(aWindow, aCallback) { return; } - browser.addEventListener("load", function onLoad() { - browser.removeEventListener("load", onLoad, true); + browser.addEventListener("load", function() { executeSoon(aCallback); - }, true); + }, {capture: true, once: true}); } diff --git a/browser/base/content/test/general/browser_bug817947.js b/browser/base/content/test/general/browser_bug817947.js index db15843f3b14..979c1a75ff52 100644 --- a/browser/base/content/test/general/browser_bug817947.js +++ b/browser/base/content/test/general/browser_bug817947.js @@ -48,8 +48,7 @@ function preparePendingTab(aCallback) { } function whenLoaded(aElement, aCallback) { - aElement.addEventListener("load", function onLoad() { - aElement.removeEventListener("load", onLoad, true); + aElement.addEventListener("load", function() { executeSoon(aCallback); - }, true); + }, {capture: true, once: true}); } diff --git a/browser/base/content/test/general/browser_bug832435.js b/browser/base/content/test/general/browser_bug832435.js index 6be2604cdd0a..8de022b4d795 100644 --- a/browser/base/content/test/general/browser_bug832435.js +++ b/browser/base/content/test/general/browser_bug832435.js @@ -7,8 +7,7 @@ function test() { ok(true, "Starting up"); gBrowser.selectedBrowser.focus(); - gURLBar.addEventListener("focus", function onFocus() { - gURLBar.removeEventListener("focus", onFocus); + gURLBar.addEventListener("focus", function() { ok(true, "Invoked onfocus handler"); EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true }); @@ -17,7 +16,7 @@ function test() { ok(true, "Evaluated without crashing"); finish(); }); - }); + }, {once: true}); gURLBar.inputField.value = "javascript: var foo = '11111111'; "; gURLBar.focus(); } diff --git a/browser/base/content/test/general/browser_clipboard_pastefile.js b/browser/base/content/test/general/browser_clipboard_pastefile.js index 0badb48ea197..63da67b9377e 100644 --- a/browser/base/content/test/general/browser_clipboard_pastefile.js +++ b/browser/base/content/test/general/browser_clipboard_pastefile.js @@ -10,14 +10,13 @@ add_task(function*() { textbox.select(); yield new Promise((resolve, reject) => { - textbox.addEventListener("copy", function copyEvent(event) { - textbox.removeEventListener("copy", copyEvent, true); + textbox.addEventListener("copy", function(event) { event.clipboardData.setData("text/plain", "Alternate"); // For this test, it doesn't matter that the file isn't actually a file. event.clipboardData.setData("application/x-moz-file", "Sample"); event.preventDefault(); resolve(); - }, true) + }, {capture: true, once: true}) EventUtils.synthesizeKey("c", { accelKey: true }); }); @@ -40,9 +39,7 @@ add_task(function*() { textbox.focus(); yield new Promise((resolve, reject) => { - textbox.addEventListener("paste", function copyEvent(event) { - textbox.removeEventListener("paste", copyEvent, true); - + textbox.addEventListener("paste", function(event) { let dt = event.clipboardData; is(dt.types.length, 3, "number of types"); ok(dt.types.includes("text/plain"), "text/plain exists in types"); @@ -51,7 +48,7 @@ add_task(function*() { is(dt.mozGetDataAt("text/plain", 0), "Alternate", "text/plain returned in mozGetDataAt"); resolve(); - }, true); + }, {capture: true, once: true}); EventUtils.synthesizeKey("v", { accelKey: true }); }); diff --git a/browser/base/content/test/general/browser_close_dependent_tabs.js b/browser/base/content/test/general/browser_close_dependent_tabs.js index c10968cb5619..5ff5be803e40 100644 --- a/browser/base/content/test/general/browser_close_dependent_tabs.js +++ b/browser/base/content/test/general/browser_close_dependent_tabs.js @@ -7,11 +7,10 @@ add_task(function* () { // Wait for a process change and then fulfil the promise. function awaitProcessChange(browser) { return new Promise(resolve => { - browser.addEventListener("BrowserChangedProcess", function bcp(e) { - browser.removeEventListener("BrowserChangedProcess", bcp); + browser.addEventListener("BrowserChangedProcess", function(e) { ok(true, "The browser changed process!"); resolve(); - }); + }, {once: true}); }); } diff --git a/browser/base/content/test/general/browser_datachoices_notification.js b/browser/base/content/test/general/browser_datachoices_notification.js index 360728b4c536..184a576cfa4d 100644 --- a/browser/base/content/test/general/browser_datachoices_notification.js +++ b/browser/base/content/test/general/browser_datachoices_notification.js @@ -45,10 +45,9 @@ function promiseNextTick() { */ function promiseWaitForAlertActive(aNotificationBox) { let deferred = PromiseUtils.defer(); - aNotificationBox.addEventListener("AlertActive", function onActive() { - aNotificationBox.removeEventListener("AlertActive", onActive, true); + aNotificationBox.addEventListener("AlertActive", function() { deferred.resolve(); - }); + }, {once: true}); return deferred.promise; } diff --git a/browser/base/content/test/general/browser_discovery.js b/browser/base/content/test/general/browser_discovery.js index bf4d1bca0d7c..bf30a42192bb 100644 --- a/browser/base/content/test/general/browser_discovery.js +++ b/browser/base/content/test/general/browser_discovery.js @@ -6,9 +6,8 @@ function doc() { function setHandlerFunc(aResultFunc) { gBrowser.addEventListener("DOMLinkAdded", function(event) { - gBrowser.removeEventListener("DOMLinkAdded", arguments.callee); executeSoon(aResultFunc); - }); + }, {once: true}); } function test() { @@ -17,9 +16,8 @@ function test() { gBrowser.selectedTab = gBrowser.addTab(); browser = gBrowser.selectedBrowser; browser.addEventListener("load", function(event) { - event.currentTarget.removeEventListener("load", arguments.callee, true); iconDiscovery(); - }, true); + }, {capture: true, once: true}); var rootDir = getRootDirectory(gTestPath); content.location = rootDir + "discovery.html"; } diff --git a/browser/base/content/test/general/browser_documentnavigation.js b/browser/base/content/test/general/browser_documentnavigation.js index 15b91aa2efe3..e52022693e39 100644 --- a/browser/base/content/test/general/browser_documentnavigation.js +++ b/browser/base/content/test/general/browser_documentnavigation.js @@ -48,9 +48,7 @@ function* expectFocusOnF6(backward, expectedDocument, expectedElement, onContent return; } - contentExpectedElement.addEventListener("focus", function focusReceived() { - contentExpectedElement.removeEventListener("focus", focusReceived, true); - + contentExpectedElement.addEventListener("focus", function() { const contentFM = Components.classes["@mozilla.org/focus-manager;1"]. getService(Components.interfaces.nsIFocusManager); let details = contentFM.focusedWindow.document.documentElement.id; @@ -59,7 +57,7 @@ function* expectFocusOnF6(backward, expectedDocument, expectedElement, onContent } sendSyncMessage("BrowserTest:FocusChanged", { details }); - }, true); + }, {capture: true, once: true}); }); } diff --git a/browser/base/content/test/general/browser_focusonkeydown.js b/browser/base/content/test/general/browser_focusonkeydown.js index 6df14c34afb7..62dfdb89ae59 100644 --- a/browser/base/content/test/general/browser_focusonkeydown.js +++ b/browser/base/content/test/general/browser_focusonkeydown.js @@ -5,17 +5,15 @@ add_task(function *() { gURLBar.focus(); - window.addEventListener("keyup", function countKeyUps(event) { - window.removeEventListener("keyup", countKeyUps, true); + window.addEventListener("keyup", function(event) { if (event.originalTarget == gURLBar.inputField) { keyUps++; } - }, true); + }, {capture: true, once: true}); - gURLBar.addEventListener("keydown", function redirectFocus(event) { - gURLBar.removeEventListener("keydown", redirectFocus, true); + gURLBar.addEventListener("keydown", function(event) { gBrowser.selectedBrowser.focus(); - }, true); + }, {capture: true, once: true}); EventUtils.synthesizeKey("v", { }); diff --git a/browser/base/content/test/general/browser_hide_removing.js b/browser/base/content/test/general/browser_hide_removing.js index 91647f3e0b63..00f6db8fb43e 100644 --- a/browser/base/content/test/general/browser_hide_removing.js +++ b/browser/base/content/test/general/browser_hide_removing.js @@ -14,13 +14,11 @@ function test() { let numVisBeforeHide, numVisAfterHide; gBrowser.tabContainer.addEventListener("TabSelect", function() { - gBrowser.tabContainer.removeEventListener("TabSelect", arguments.callee); - // While the next tab is being selected, hide the removing tab numVisBeforeHide = gBrowser.visibleTabs.length; gBrowser.hideTab(testTab); numVisAfterHide = gBrowser.visibleTabs.length; - }); + }, {once: true}); gBrowser.removeTab(testTab, {animate: true}); // Make sure the tab gets removed at the end of the animation by polling diff --git a/browser/base/content/test/general/browser_keywordBookmarklets.js b/browser/base/content/test/general/browser_keywordBookmarklets.js index 52089c8fef8d..c76cb915bbf8 100644 --- a/browser/base/content/test/general/browser_keywordBookmarklets.js +++ b/browser/base/content/test/general/browser_keywordBookmarklets.js @@ -46,9 +46,8 @@ add_task(function* test_keyword_bookmarklet() { function* promisePageShow() { return new Promise(resolve => { - gBrowser.selectedBrowser.addEventListener("pageshow", function listen() { - gBrowser.selectedBrowser.removeEventListener("pageshow", listen); + gBrowser.selectedBrowser.addEventListener("pageshow", function() { resolve(); - }); + }, {once: true}); }); } diff --git a/browser/base/content/test/general/browser_keywordSearch.js b/browser/base/content/test/general/browser_keywordSearch.js index 161ddd4e9a22..65a5a6dabb8e 100644 --- a/browser/base/content/test/general/browser_keywordSearch.js +++ b/browser/base/content/test/general/browser_keywordSearch.js @@ -25,9 +25,8 @@ function test() { ok(false, "Alert window opened"); let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget); win.addEventListener("load", function() { - win.removeEventListener("load", arguments.callee); win.close(); - }); + }, {once: true}); executeSoon(finish); } } diff --git a/browser/base/content/test/general/browser_newwindow_focus.js b/browser/base/content/test/general/browser_newwindow_focus.js index 7880db0bdf23..c6a6e00d649c 100644 --- a/browser/base/content/test/general/browser_newwindow_focus.js +++ b/browser/base/content/test/general/browser_newwindow_focus.js @@ -23,10 +23,9 @@ function promiseNewWindow() { if (topic == "domwindowopened") { Services.ww.unregisterNotification(observer); let win = subject.QueryInterface(Ci.nsIDOMWindow); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); + win.addEventListener("load", function() { resolve(win); - }); + }, {once: true}); } }; diff --git a/browser/base/content/test/general/browser_offlineQuotaNotification.js b/browser/base/content/test/general/browser_offlineQuotaNotification.js index 9152255c4b97..4a4ea6024a47 100644 --- a/browser/base/content/test/general/browser_offlineQuotaNotification.js +++ b/browser/base/content/test/general/browser_offlineQuotaNotification.js @@ -68,12 +68,11 @@ function test() { // tab to open - which we track via an "Initialized" event. PopupNotifications.panel.firstElementChild.button.click(); let newTabBrowser = gBrowser.getBrowserForTab(gBrowser.selectedTab); - newTabBrowser.addEventListener("Initialized", function PrefInit() { - newTabBrowser.removeEventListener("Initialized", PrefInit, true); + newTabBrowser.addEventListener("Initialized", function() { executeSoon(function() { checkInContentPreferences(newTabBrowser.contentWindow); }) - }, true); + }, {capture: true, once: true}); }); onCachedAttached.then(function() { Services.prefs.setIntPref("offline-apps.quota.warn", 1); @@ -87,9 +86,8 @@ function test() { function promiseNotification() { return new Promise(resolve => { - PopupNotifications.panel.addEventListener("popupshown", function onShown() { - PopupNotifications.panel.removeEventListener("popupshown", onShown); + PopupNotifications.panel.addEventListener("popupshown", function() { resolve(); - }); + }, {once: true}); }); } diff --git a/browser/base/content/test/general/browser_pageInfo.js b/browser/base/content/test/general/browser_pageInfo.js index 90fe2e17f507..ee974dc1e763 100644 --- a/browser/base/content/test/general/browser_pageInfo.js +++ b/browser/base/content/test/general/browser_pageInfo.js @@ -4,12 +4,10 @@ function test() { var pageInfo; gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function loadListener() { - gBrowser.selectedBrowser.removeEventListener("load", loadListener, true); - + gBrowser.selectedBrowser.addEventListener("load", function() { Services.obs.addObserver(observer, "page-info-dialog-loaded", false); pageInfo = BrowserPageInfo(); - }, true); + }, {capture: true, once: true}); content.location = "https://example.com/browser/browser/base/content/test/general/feed_tab.html"; diff --git a/browser/base/content/test/general/browser_sanitizeDialog.js b/browser/base/content/test/general/browser_sanitizeDialog.js index 4d2704bf9c2f..6dee59cceb75 100644 --- a/browser/base/content/test/general/browser_sanitizeDialog.js +++ b/browser/base/content/test/general/browser_sanitizeDialog.js @@ -786,15 +786,13 @@ WindowHelper.prototype = { let win = aSubject.QueryInterface(Ci.nsIDOMWindow); win.addEventListener("load", function onload(event) { - win.removeEventListener("load", onload); - if (win.name !== "SanitizeDialog") return; wh.win = win; loaded = true; executeSoon(() => wh.onload()); - }); + }, {once: true}); win.addEventListener("unload", function onunload(event) { if (win.name !== "SanitizeDialog") { diff --git a/browser/base/content/test/general/browser_save_link_when_window_navigates.js b/browser/base/content/test/general/browser_save_link_when_window_navigates.js index eaebb28d134f..9e9b1c3a73cc 100644 --- a/browser/base/content/test/general/browser_save_link_when_window_navigates.js +++ b/browser/base/content/test/general/browser_save_link_when_window_navigates.js @@ -104,9 +104,7 @@ var windowObserver = { let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget); - win.addEventListener("load", function onLoad(event) { - win.removeEventListener("load", onLoad); - + win.addEventListener("load", function(event) { if (win.location == UCT_URI) { SimpleTest.executeSoon(function() { if (windowObserver._callback) { @@ -117,7 +115,7 @@ var windowObserver = { } }); } - }); + }, {once: true}); } }; diff --git a/browser/base/content/test/general/browser_selectpopup.js b/browser/base/content/test/general/browser_selectpopup.js index e16327257c6a..af7f96f8b8f7 100644 --- a/browser/base/content/test/general/browser_selectpopup.js +++ b/browser/base/content/test/general/browser_selectpopup.js @@ -329,10 +329,9 @@ add_task(function*() { elem = content.document.getElementById(contentStep[0]); } - changedWin.addEventListener("MozAfterPaint", function onPaint() { - changedWin.removeEventListener("MozAfterPaint", onPaint); + changedWin.addEventListener("MozAfterPaint", function() { resolve(); - }); + }, {once: true}); elem.style = contentStep[1]; elem.getBoundingClientRect(); @@ -675,11 +674,10 @@ add_task(function* test_mousemove_correcttarget() { yield popupShownPromise; yield new Promise(resolve => { - window.addEventListener("mousemove", function checkForMouseMove(event) { - window.removeEventListener("mousemove", checkForMouseMove, true); + window.addEventListener("mousemove", function(event) { is(event.target.localName.indexOf("menu"), 0, "mouse over menu"); resolve(); - }, true); + }, {capture: true, once: true}); EventUtils.synthesizeMouseAtCenter(selectPopup.firstChild, { type: "mousemove" }); }); diff --git a/browser/base/content/test/general/browser_subframe_favicons_not_used.js b/browser/base/content/test/general/browser_subframe_favicons_not_used.js index 7efe78d9b983..a03ac22d1bc4 100644 --- a/browser/base/content/test/general/browser_subframe_favicons_not_used.js +++ b/browser/base/content/test/general/browser_subframe_favicons_not_used.js @@ -8,13 +8,11 @@ function test() { let tab = gBrowser.addTab(testPath + "file_bug970276_popup1.html"); tab.linkedBrowser.addEventListener("load", function() { - tab.linkedBrowser.removeEventListener("load", arguments.callee, true); - let expectedIcon = testPath + "file_bug970276_favicon1.ico"; is(gBrowser.getIcon(tab), expectedIcon, "Correct icon."); gBrowser.removeTab(tab); finish(); - }, true); + }, {capture: true, once: true}); } diff --git a/browser/base/content/test/general/browser_tabfocus.js b/browser/base/content/test/general/browser_tabfocus.js index b0e934a7c537..1221457251a5 100644 --- a/browser/base/content/test/general/browser_tabfocus.js +++ b/browser/base/content/test/general/browser_tabfocus.js @@ -224,10 +224,9 @@ add_task(function*() { let switchWaiter; if (gMultiProcessBrowser) { switchWaiter = new Promise((resolve, reject) => { - gBrowser.addEventListener("TabSwitchDone", function listener() { - gBrowser.removeEventListener("TabSwitchDone", listener); + gBrowser.addEventListener("TabSwitchDone", function() { executeSoon(resolve); - }); + }, {once: true}); }); } @@ -326,10 +325,9 @@ add_task(function*() { gURLBar.focus(); yield new Promise((resolve, reject) => { - window.addEventListener("pageshow", function navigationOccured(event) { - window.removeEventListener("pageshow", navigationOccured, true); + window.addEventListener("pageshow", function(event) { resolve(); - }, true); + }, {capture: true, once: true}); document.getElementById("Browser:Back").doCommand(); }); diff --git a/browser/base/content/test/general/browser_tabs_isActive.js b/browser/base/content/test/general/browser_tabs_isActive.js index 0725757e7097..7be2ae6dd4af 100644 --- a/browser/base/content/test/general/browser_tabs_isActive.js +++ b/browser/base/content/test/general/browser_tabs_isActive.js @@ -7,10 +7,9 @@ const kTestPage = "http://example.org/browser/browser/base/content/test/general/ function promiseNewTabSwitched() { return new Promise(resolve => { - gBrowser.addEventListener("TabSwitchDone", function onSwitch() { - gBrowser.removeEventListener("TabSwitchDone", onSwitch); + gBrowser.addEventListener("TabSwitchDone", function() { executeSoon(resolve); - }); + }, {once: true}); }); } diff --git a/browser/base/content/test/general/browser_visibleTabs_bookmarkAllTabs.js b/browser/base/content/test/general/browser_visibleTabs_bookmarkAllTabs.js index daf432f4fa8a..f051cc0d58c3 100644 --- a/browser/base/content/test/general/browser_visibleTabs_bookmarkAllTabs.js +++ b/browser/base/content/test/general/browser_visibleTabs_bookmarkAllTabs.js @@ -19,7 +19,6 @@ function test() { is(gBrowser.visibleTabs.length, 3, "3 tabs should be open"); // Wait for tab load, the code checks for currentURI. testTab2.linkedBrowser.addEventListener("load", function() { - testTab2.linkedBrowser.removeEventListener("load", arguments.callee, true); is(Disabled(), false, "Bookmark All Tabs should be enabled since there are two tabs with different addresses"); // Hide the original tab @@ -52,7 +51,7 @@ function test() { is(gBrowser.selectedTab, origTab, "got the orig tab"); is(origTab.hidden, false, "and it's not hidden -- visible!"); finish(); - }, true); + }, {capture: true, once: true}); } function Disabled() { diff --git a/browser/base/content/test/general/contentSearchUI.js b/browser/base/content/test/general/contentSearchUI.js index 115b4ed0177f..12fd5a9a019b 100644 --- a/browser/base/content/test/general/contentSearchUI.js +++ b/browser/base/content/test/general/contentSearchUI.js @@ -94,10 +94,9 @@ var messageHandlers = { type: "mousemove", clickcount: 0, } - row.addEventListener("mousemove", function handler() { - row.removeEventListener("mousemove", handler); + row.addEventListener("mousemove", function() { ack("mousemove"); - }); + }, {once: true}); content.synthesizeMouseAtCenter(row, event); }, diff --git a/browser/base/content/test/general/file_fullscreen-window-open.html b/browser/base/content/test/general/file_fullscreen-window-open.html index 1584f4c98d52..44ac3196a06b 100644 --- a/browser/base/content/test/general/file_fullscreen-window-open.html +++ b/browser/base/content/test/general/file_fullscreen-window-open.html @@ -5,11 +5,9 @@ diff --git a/browser/components/sessionstore/test/browser_514751.js b/browser/components/sessionstore/test/browser_514751.js index 97489d0e1dcb..f24364d8beaa 100644 --- a/browser/components/sessionstore/test/browser_514751.js +++ b/browser/components/sessionstore/test/browser_514751.js @@ -20,8 +20,6 @@ function test() { var theWin = openDialog(location, "", "chrome,all,dialog=no"); theWin.addEventListener("load", function () { - theWin.removeEventListener("load", arguments.callee); - executeSoon(function () { var gotError = false; try { @@ -33,6 +31,6 @@ function test() { ok(!gotError, "Didn't get a malformed URI error."); BrowserTestUtils.closeWindow(theWin).then(finish); }); - }); + }, {once: true}); } diff --git a/browser/components/sessionstore/test/browser_580512.js b/browser/components/sessionstore/test/browser_580512.js index ffd8a6c23eb8..9e00e80198ad 100644 --- a/browser/components/sessionstore/test/browser_580512.js +++ b/browser/components/sessionstore/test/browser_580512.js @@ -56,7 +56,6 @@ function openWinWithCb(cb, argURIs, expectedURIs) { "chrome,all,dialog=no", argURIs.join("|")); win.addEventListener("load", function () { - win.removeEventListener("load", arguments.callee); info("the window loaded"); var expectedLoads = expectedURIs.length; @@ -77,5 +76,5 @@ function openWinWithCb(cb, argURIs, expectedURIs) { } } }); - }); + }, {once: true}); } diff --git a/browser/components/sessionstore/test/browser_586068-browser_state_interrupted.js b/browser/components/sessionstore/test/browser_586068-browser_state_interrupted.js index de8f1aba0034..7305e3103ddc 100644 --- a/browser/components/sessionstore/test/browser_586068-browser_state_interrupted.js +++ b/browser/components/sessionstore/test/browser_586068-browser_state_interrupted.js @@ -95,11 +95,10 @@ add_task(function* test() { Services.ww.registerNotification(function observer(aSubject, aTopic, aData) { if (aTopic == "domwindowopened") { let win = aSubject.QueryInterface(Ci.nsIDOMWindow); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); + win.addEventListener("load", function() { Services.ww.unregisterNotification(observer); win.gBrowser.addTabsProgressListener(gProgressListener); - }); + }, {once: true}); } }); diff --git a/browser/components/sessionstore/test/browser_586068-multi_window.js b/browser/components/sessionstore/test/browser_586068-multi_window.js index 03337568e1f0..56280dc6b5f3 100644 --- a/browser/components/sessionstore/test/browser_586068-multi_window.js +++ b/browser/components/sessionstore/test/browser_586068-multi_window.js @@ -52,11 +52,10 @@ add_task(function* test() { Services.ww.registerNotification(function observer(aSubject, aTopic, aData) { if (aTopic == "domwindowopened") { let win = aSubject.QueryInterface(Ci.nsIDOMWindow); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); + win.addEventListener("load", function() { Services.ww.unregisterNotification(observer); win.gBrowser.addTabsProgressListener(gProgressListener); - }); + }, {once: true}); } }); diff --git a/browser/components/sessionstore/test/browser_588426.js b/browser/components/sessionstore/test/browser_588426.js index 92705e6cf5a3..6dfe6ac9d9fc 100644 --- a/browser/components/sessionstore/test/browser_588426.js +++ b/browser/components/sessionstore/test/browser_588426.js @@ -26,16 +26,13 @@ function newWindowWithState(state, callback) { let opts = "chrome,all,dialog=no,height=800,width=800"; let win = window.openDialog(getBrowserURL(), "_blank", opts); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); - + win.addEventListener("load", function() { executeSoon(function () { - win.addEventListener("SSWindowStateReady", function onReady() { - win.removeEventListener("SSWindowStateReady", onReady); + win.addEventListener("SSWindowStateReady", function() { promiseTabRestored(win.gBrowser.tabs[0]).then(() => callback(win)); - }); + }, {once: true}); ss.setWindowState(win, JSON.stringify(state), true); }); - }); + }, {once: true}); } diff --git a/browser/components/sessionstore/test/browser_589246.js b/browser/components/sessionstore/test/browser_589246.js index 2f52aa01e7ef..d4122b4d4540 100644 --- a/browser/components/sessionstore/test/browser_589246.js +++ b/browser/components/sessionstore/test/browser_589246.js @@ -161,17 +161,14 @@ function onStateRestored(aSubject, aTopic, aData) { let newWin = openDialog(location, "_blank", "chrome,all,dialog=no", "http://example.com"); newWin.addEventListener("load", function(aEvent) { - newWin.removeEventListener("load", arguments.callee); - promiseBrowserLoaded(newWin.gBrowser.selectedBrowser).then(() => { // pin this tab if (shouldPinTab) newWin.gBrowser.pinTab(newWin.gBrowser.selectedTab); newWin.addEventListener("unload", function () { - newWin.removeEventListener("unload", arguments.callee); onWindowUnloaded(); - }); + }, {once: true}); // Open a new tab as well. On Windows/Linux this will be restored when the // new window is opened below (in onWindowUnloaded). On OS X we'll just // restore the pinned tabs, leaving the unpinned tab in the closedWindowsData. @@ -180,8 +177,6 @@ function onStateRestored(aSubject, aTopic, aData) { let newTab2 = newWin.gBrowser.addTab("about:buildconfig"); newTab.linkedBrowser.addEventListener("load", function() { - newTab.linkedBrowser.removeEventListener("load", arguments.callee, true); - if (shouldCloseTab == "one") { newWin.gBrowser.removeTab(newTab2); } @@ -190,13 +185,13 @@ function onStateRestored(aSubject, aTopic, aData) { newWin.gBrowser.removeTab(newTab2); } newWin.BrowserTryToCloseWindow(); - }, true); + }, {capture: true, once: true}); } else { newWin.BrowserTryToCloseWindow(); } }); - }); + }, {once: true}); } // This will be called before the window is actually closed @@ -219,17 +214,13 @@ function onWindowUnloaded() { // Now we want to open a new window let newWin = openDialog(location, "_blank", "chrome,all,dialog=no", "about:mozilla"); newWin.addEventListener("load", function(aEvent) { - newWin.removeEventListener("load", arguments.callee); - newWin.gBrowser.selectedBrowser.addEventListener("load", function () { - newWin.gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); - // Good enough for checking the state afterTestCallback(previousClosedWindowData, ss.getClosedWindowData()); afterTestCleanup(newWin); - }, true); + }, {capture: true, once: true}); - }); + }, {once: true}); } function afterTestCleanup(aNewWin) { diff --git a/browser/components/sessionstore/test/browser_590563.js b/browser/components/sessionstore/test/browser_590563.js index 8ac201706384..a4e12ff69801 100644 --- a/browser/components/sessionstore/test/browser_590563.js +++ b/browser/components/sessionstore/test/browser_590563.js @@ -55,20 +55,17 @@ function newWindowWithState(state, callback) { let opts = "chrome,all,dialog=no,height=800,width=800"; let win = window.openDialog(getBrowserURL(), "_blank", opts); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); - + win.addEventListener("load", function() { let tab = win.gBrowser.selectedTab; // The form data will be restored before SSTabRestored, so we want to listen // for that on the currently selected tab (it will be reused) - tab.addEventListener("SSTabRestored", function onRestored() { - tab.removeEventListener("SSTabRestored", onRestored, true); + tab.addEventListener("SSTabRestored", function() { callback(win); - }, true); + }, {capture: true, once: true}); executeSoon(function () { ss.setWindowState(win, JSON.stringify(state), true); }); - }); + }, {once: true}); } diff --git a/browser/components/sessionstore/test/browser_615394-SSWindowState_events.js b/browser/components/sessionstore/test/browser_615394-SSWindowState_events.js index 17d8cf0a4bdf..6699bedd87de 100644 --- a/browser/components/sessionstore/test/browser_615394-SSWindowState_events.js +++ b/browser/components/sessionstore/test/browser_615394-SSWindowState_events.js @@ -261,15 +261,13 @@ function test_setBrowserState() { if (aTopic == "domwindowopened") { newWindow = aSubject.QueryInterface(Ci.nsIDOMWindow); newWindow.addEventListener("load", function() { - newWindow.removeEventListener("load", arguments.callee); - Services.ww.unregisterNotification(windowObserver); windowEvents[getOuterWindowID(newWindow)] = { busyEventCount: 0, readyEventCount: 0 }; newWindow.addEventListener("SSWindowStateBusy", onSSWindowStateBusy); newWindow.addEventListener("SSWindowStateReady", onSSWindowStateReady); - }); + }, {once: true}); } } @@ -326,10 +324,8 @@ function test_undoCloseWindow() { reopenedWindow.addEventListener("SSWindowStateReady", onSSWindowStateReady); reopenedWindow.addEventListener("load", function() { - reopenedWindow.removeEventListener("load", arguments.callee); - reopenedWindow.gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored); - }); + }, {once: true}); }); }); diff --git a/browser/components/sessionstore/test/browser_628270.js b/browser/components/sessionstore/test/browser_628270.js index f552cbfdac1c..f1416314a877 100644 --- a/browser/components/sessionstore/test/browser_628270.js +++ b/browser/components/sessionstore/test/browser_628270.js @@ -45,8 +45,7 @@ function test() { } function whenTabIsLoaded(tab, callback) { - tab.linkedBrowser.addEventListener("load", function onLoad() { - tab.linkedBrowser.removeEventListener("load", onLoad, true); + tab.linkedBrowser.addEventListener("load", function() { callback(); - }, true); + }, {capture: true, once: true}); } diff --git a/browser/components/sessionstore/test/browser_636279.js b/browser/components/sessionstore/test/browser_636279.js index 1cc3c6b88d73..cae9dc6bf7a1 100644 --- a/browser/components/sessionstore/test/browser_636279.js +++ b/browser/components/sessionstore/test/browser_636279.js @@ -25,9 +25,7 @@ function test() { TabsProgressListener.init(); - window.addEventListener("SSWindowStateReady", function onReady() { - window.removeEventListener("SSWindowStateReady", onReady); - + window.addEventListener("SSWindowStateReady", function() { let firstProgress = true; TabsProgressListener.setCallback(function (needsRestore, isRestoring) { @@ -45,7 +43,7 @@ function test() { }); ss.setBrowserState(JSON.stringify(state)); - }); + }, {once: true}); ss.setBrowserState(JSON.stringify(statePinned)); } diff --git a/browser/components/sessionstore/test/browser_644409-scratchpads.js b/browser/components/sessionstore/test/browser_644409-scratchpads.js index fdca31b7764b..685067eb5197 100644 --- a/browser/components/sessionstore/test/browser_644409-scratchpads.js +++ b/browser/components/sessionstore/test/browser_644409-scratchpads.js @@ -38,9 +38,7 @@ function test() { function windowObserver(aSubject, aTopic, aData) { if (aTopic == "domwindowopened") { let win = aSubject.QueryInterface(Ci.nsIDOMWindow); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); - + win.addEventListener("load", function() { if (win.Scratchpad) { win.Scratchpad.addObserver({ onReady: function() { @@ -53,7 +51,7 @@ function windowObserver(aSubject, aTopic, aData) { }, }); } - }); + }, {once: true}); } } diff --git a/browser/components/sessionstore/test/browser_659591.js b/browser/components/sessionstore/test/browser_659591.js index 1d32e3ac748e..ec2e79ee821f 100644 --- a/browser/components/sessionstore/test/browser_659591.js +++ b/browser/components/sessionstore/test/browser_659591.js @@ -11,10 +11,9 @@ function test() { }); newWindow(function (win) { - win.addEventListener("SSWindowClosing", function onWindowClosing() { - win.removeEventListener("SSWindowClosing", onWindowClosing); + win.addEventListener("SSWindowClosing", function() { eventReceived = true; - }); + }, {once: true}); BrowserTestUtils.closeWindow(win).then(() => { waitForFocus(finish); @@ -26,8 +25,7 @@ function newWindow(callback) { let opts = "chrome,all,dialog=no,height=800,width=800"; let win = window.openDialog(getBrowserURL(), "_blank", opts); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); + win.addEventListener("load", function() { executeSoon(() => callback(win)); - }); + }, {once: true}); } diff --git a/browser/components/sessionstore/test/browser_662812.js b/browser/components/sessionstore/test/browser_662812.js index 572a584e841b..9980964dd4d6 100644 --- a/browser/components/sessionstore/test/browser_662812.js +++ b/browser/components/sessionstore/test/browser_662812.js @@ -4,15 +4,11 @@ function test() { waitForExplicitFinish(); - window.addEventListener("SSWindowStateBusy", function onBusy() { - window.removeEventListener("SSWindowStateBusy", onBusy); - + window.addEventListener("SSWindowStateBusy", function() { let state = JSON.parse(ss.getWindowState(window)); ok(state.windows[0].busy, "window is busy"); - window.addEventListener("SSWindowStateReady", function onReady() { - window.removeEventListener("SSWindowStateReady", onReady); - + window.addEventListener("SSWindowStateReady", function() { let state = JSON.parse(ss.getWindowState(window)); ok(!state.windows[0].busy, "window is not busy"); @@ -20,17 +16,16 @@ function test() { gBrowser.removeTab(gBrowser.tabs[1]); finish(); }); - }); - }); + }, {once: true}); + }, {once: true}); // create a new tab let tab = gBrowser.addTab("about:mozilla"); let browser = tab.linkedBrowser; // close and restore it - browser.addEventListener("load", function onLoad() { - browser.removeEventListener("load", onLoad, true); + browser.addEventListener("load", function() { gBrowser.removeTab(tab); ss.undoCloseTab(window, 0); - }, true); + }, {capture: true, once: true}); } diff --git a/browser/components/sessionstore/test/browser_grouped_session_store.js b/browser/components/sessionstore/test/browser_grouped_session_store.js index dd80d4703dd5..f5ee28f6cfb8 100644 --- a/browser/components/sessionstore/test/browser_grouped_session_store.js +++ b/browser/components/sessionstore/test/browser_grouped_session_store.js @@ -44,10 +44,9 @@ add_task(function* () { }, }; - browser.addEventListener("BrowserChangedProcess", function bcp(e) { - browser.removeEventListener("BrowserChangedProcess", bcp); + browser.addEventListener("BrowserChangedProcess", function(e) { gBrowser.addProgressListener(locChangeListener); - }); + }, {once: true}); }); } diff --git a/browser/components/sessionstore/test/browser_windowRestore_perwindowpb.js b/browser/components/sessionstore/test/browser_windowRestore_perwindowpb.js index 78fd296d1c0c..082b67c48218 100644 --- a/browser/components/sessionstore/test/browser_windowRestore_perwindowpb.js +++ b/browser/components/sessionstore/test/browser_windowRestore_perwindowpb.js @@ -14,13 +14,12 @@ function test() { // and verify it doesn't get remembered for restoring whenNewWindowLoaded({private: true}, function (win) { info("The private window got loaded"); - win.addEventListener("SSWindowClosing", function onclosing() { - win.removeEventListener("SSWindowClosing", onclosing); + win.addEventListener("SSWindowClosing", function() { executeSoon(function () { is(ss.getClosedWindowCount(), 0, "The private window should not have been stored"); }); - }); + }, {once: true}); BrowserTestUtils.closeWindow(win).then(finish); }); } diff --git a/browser/components/sessionstore/test/head.js b/browser/components/sessionstore/test/head.js index be56d47ff24d..4a539dbcef50 100644 --- a/browser/components/sessionstore/test/head.js +++ b/browser/components/sessionstore/test/head.js @@ -68,10 +68,9 @@ function provideWindow(aCallback, aURL, aFeatures) { return; } - aWin.gBrowser.selectedBrowser.addEventListener("load", function selectedBrowserLoadListener() { - aWin.gBrowser.selectedBrowser.removeEventListener("load", selectedBrowserLoadListener, true); + aWin.gBrowser.selectedBrowser.addEventListener("load", function() { callbackSoon(aWin); - }, true); + }, {capture: true, once: true}); }); } @@ -123,8 +122,6 @@ function waitForBrowserState(aState, aSetStateCallback) { if (aTopic == "domwindowopened") { let newWindow = aSubject.QueryInterface(Ci.nsIDOMWindow); newWindow.addEventListener("load", function() { - newWindow.removeEventListener("load", arguments.callee); - if (++windowsOpen == expectedWindows) { Services.ww.unregisterNotification(windowObserver); windowObserving = false; @@ -134,7 +131,7 @@ function waitForBrowserState(aState, aSetStateCallback) { windows.push(newWindow); // Add the progress listener newWindow.gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored, true); - }); + }, {once: true}); } } @@ -288,12 +285,11 @@ function promiseBrowserLoaded(aBrowser, ignoreSubFrames = true, wantLoad = null) } function whenWindowLoaded(aWindow, aCallback = next) { - aWindow.addEventListener("load", function windowLoadListener() { - aWindow.removeEventListener("load", windowLoadListener); + aWindow.addEventListener("load", function() { executeSoon(function executeWhenWindowLoaded() { aCallback(aWindow); }); - }); + }, {once: true}); } function promiseWindowLoaded(aWindow) { return new Promise(resolve => whenWindowLoaded(aWindow, resolve)); @@ -438,11 +434,10 @@ function whenNewWindowLoaded(aOptions, aCallback) { return; } - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); + win.addEventListener("load", function() { let browser = win.gBrowser.selectedBrowser; promiseBrowserLoaded(browser).then(resolve); - }); + }, {once: true}); }); Promise.all([delayedStartup, browserLoaded]).then(() => aCallback(win)); diff --git a/browser/components/syncedtabs/test/browser/browser_sidebar_syncedtabslist.js b/browser/components/syncedtabs/test/browser/browser_sidebar_syncedtabslist.js index 96bda5d5ad40..3677f08ac311 100644 --- a/browser/components/syncedtabs/test/browser/browser_sidebar_syncedtabslist.js +++ b/browser/components/syncedtabs/test/browser/browser_sidebar_syncedtabslist.js @@ -69,10 +69,9 @@ function* testClean() { SyncedTabs._internal = originalSyncedTabsInternal; yield new Promise(resolve => { - window.SidebarUI.browser.contentWindow.addEventListener("unload", function listener() { - window.SidebarUI.browser.contentWindow.removeEventListener("unload", listener); + window.SidebarUI.browser.contentWindow.addEventListener("unload", function() { resolve(); - }); + }, {once: true}); SidebarUI.hide(); }); } diff --git a/browser/components/tests/browser/browser_bug538331.js b/browser/components/tests/browser/browser_bug538331.js index 77866b485fb2..9cd720daee39 100644 --- a/browser/components/tests/browser/browser_bug538331.js +++ b/browser/components/tests/browser/browser_bug538331.js @@ -168,9 +168,8 @@ var gWindowCatcher = { let win = subject.QueryInterface(Ci.nsIDOMWindow); info("window catcher caught window opening: " + win.document.documentURI); win.addEventListener("load", function() { - win.removeEventListener("load", arguments.callee); gWindowCatcher.windowLoad(win); - }); + }, {once: true}); } }; diff --git a/browser/components/translation/test/browser_translation_exceptions.js b/browser/components/translation/test/browser_translation_exceptions.js index 4c0f11a500e0..27a1af400785 100644 --- a/browser/components/translation/test/browser_translation_exceptions.js +++ b/browser/components/translation/test/browser_translation_exceptions.js @@ -22,8 +22,7 @@ function test() { gBrowser.removeTab(tab); Services.prefs.clearUserPref(kShowUIPref); }); - tab.linkedBrowser.addEventListener("load", function onload() { - tab.linkedBrowser.removeEventListener("load", onload, true); + tab.linkedBrowser.addEventListener("load", function() { Task.spawn(function* () { for (let testCase of gTests) { info(testCase.desc); @@ -33,7 +32,7 @@ function test() { ok(false, "Unexpected Exception: " + ex); finish(); }); - }, true); + }, {capture: true, once: true}); content.location = "http://example.com/"; } @@ -76,10 +75,9 @@ function getInfoBar() { function openPopup(aPopup) { let deferred = Promise.defer(); - aPopup.addEventListener("popupshown", function popupShown() { - aPopup.removeEventListener("popupshown", popupShown); + aPopup.addEventListener("popupshown", function() { deferred.resolve(); - }); + }, {once: true}); aPopup.focus(); // One down event to open the popup. @@ -92,10 +90,9 @@ function openPopup(aPopup) { function waitForWindowLoad(aWin) { let deferred = Promise.defer(); - aWin.addEventListener("load", function onload() { - aWin.removeEventListener("load", onload, true); + aWin.addEventListener("load", function() { deferred.resolve(); - }, true); + }, {capture: true, once: true}); return deferred.promise; } diff --git a/browser/components/translation/test/browser_translation_infobar.js b/browser/components/translation/test/browser_translation_infobar.js index 9b6917b3fe31..355d6cbab26e 100644 --- a/browser/components/translation/test/browser_translation_infobar.js +++ b/browser/components/translation/test/browser_translation_infobar.js @@ -77,8 +77,7 @@ function test() { Services.prefs.setBoolPref(kShowUIPref, true); let tab = gBrowser.addTab(); gBrowser.selectedTab = tab; - tab.linkedBrowser.addEventListener("load", function onload() { - tab.linkedBrowser.removeEventListener("load", onload, true); + tab.linkedBrowser.addEventListener("load", function() { TranslationStub.browser = gBrowser.selectedBrowser; registerCleanupFunction(function() { gBrowser.removeTab(tab); @@ -87,7 +86,7 @@ function test() { run_tests(() => { finish(); }); - }, true); + }, {capture: true, once: true}); content.location = "data:text/plain,test page"; } diff --git a/browser/components/translation/translation-infobar.xml b/browser/components/translation/translation-infobar.xml index f4eabd952236..b6bdd0ad4763 100644 --- a/browser/components/translation/translation-infobar.xml +++ b/browser/components/translation/translation-infobar.xml @@ -232,9 +232,7 @@ this.translation.browser != gBrowser.selectedBrowser) return; - this.addEventListener("transitionend", function onShown() { - this.removeEventListener("transitionend", onShown); - + this.addEventListener("transitionend", function() { // These strings are hardcoded because they need to reach beta // without riding the trains. let localizedStrings = { @@ -281,7 +279,7 @@ "bottomcenter topleft"); Services.prefs.setBoolPref(kWelcomePref, true); - }); + }, {once: true}); ]]> diff --git a/browser/components/uitour/UITour.jsm b/browser/components/uitour/UITour.jsm index 975d2b52c6c2..a06cd5839896 100644 --- a/browser/components/uitour/UITour.jsm +++ b/browser/components/uitour/UITour.jsm @@ -1573,13 +1573,12 @@ this.UITour = { aAnchor.addTargetListener(document, targetCallback); } - tooltip.addEventListener("popuphiding", function tooltipHiding(event) { - tooltip.removeEventListener("popuphiding", tooltipHiding); + tooltip.addEventListener("popuphiding", function(event) { tooltipClose.removeEventListener("command", closeButtonCallback); if (aOptions.targetCallback && aAnchor.removeTargetListener) { aAnchor.removeTargetListener(document, targetCallback); } - }); + }, {once: true}); tooltip.setAttribute("targetName", aAnchor.targetName); tooltip.hidden = false; @@ -1593,10 +1592,9 @@ this.UITour = { this._addAnnotationPanelMutationObserver(tooltip); tooltip.openPopup(aAnchorEl, alignment, xOffset || 0, yOffset || 0); if (tooltip.state == "closed") { - document.defaultView.addEventListener("endmodalstate", function endModalStateHandler() { - document.defaultView.removeEventListener("endmodalstate", endModalStateHandler); + document.defaultView.addEventListener("endmodalstate", function() { tooltip.openPopup(aAnchorEl, alignment); - }); + }, {once: true}); } } @@ -1714,10 +1712,9 @@ this.UITour = { return; } - aWindow.PanelUI.panel.addEventListener("popupshown", function onShown() { - aWindow.PanelUI.panel.removeEventListener("popupshown", onShown); + aWindow.PanelUI.panel.addEventListener("popupshown", function() { resolve(); - }); + }, {once: true}); aWindow.PanelUI.show(); }); diff --git a/browser/components/uitour/test/browser_UITour.js b/browser/components/uitour/test/browser_UITour.js index 792917f325e5..501756557ae2 100644 --- a/browser/components/uitour/test/browser_UITour.js +++ b/browser/components/uitour/test/browser_UITour.js @@ -184,11 +184,10 @@ var tests = [ function checkSameEffectOnDifferentTarget() { gContentAPI.showHighlight("appMenu", "wobble"); waitForHighlightWithEffect(highlight, "wobble", () => { - highlight.addEventListener("animationstart", function onAnimationStart(aEvent) { - highlight.removeEventListener("animationstart", onAnimationStart); + highlight.addEventListener("animationstart", function(aEvent) { ok(true, "Animation occurred again even though the effect was the same"); checkRandomEffect(); - }); + }, {once: true}); gContentAPI.showHighlight("backForward", "wobble"); }, "There should be a wobble effect"); } @@ -235,8 +234,7 @@ var tests = [ let icon = document.getElementById("UITourTooltipIcon"); let buttons = document.getElementById("UITourTooltipButtons"); - popup.addEventListener("popupshown", function onPopupShown() { - popup.removeEventListener("popupshown", onPopupShown); + popup.addEventListener("popupshown", function() { is(popup.popupBoxObject.anchorNode, document.getElementById("urlbar"), "Popup should be anchored to the urlbar"); is(title.textContent, "test title", "Popup should have correct title"); is(desc.textContent, "test text", "Popup should have correct description text"); @@ -252,7 +250,7 @@ var tests = [ }, {once: true}); gContentAPI.hideInfo(); - }); + }, {once: true}); gContentAPI.showInfo("urlbar", "test title", "test text"); }, diff --git a/browser/components/uitour/test/browser_UITour_resetProfile.js b/browser/components/uitour/test/browser_UITour_resetProfile.js index c91d0a4f270f..e373fbf1b109 100644 --- a/browser/components/uitour/test/browser_UITour_resetProfile.js +++ b/browser/components/uitour/test/browser_UITour_resetProfile.js @@ -15,8 +15,7 @@ add_UITour_task(function* test_resetFirefox() { getService(Ci.nsIWindowWatcher); winWatcher.registerNotification(function onOpen(subj, topic, data) { if (topic == "domwindowopened" && subj instanceof Ci.nsIDOMWindow) { - subj.addEventListener("load", function onLoad() { - subj.removeEventListener("load", onLoad); + subj.addEventListener("load", function() { if (subj.document.documentURI == "chrome://global/content/resetProfile.xul") { winWatcher.unregisterNotification(onOpen); @@ -26,7 +25,7 @@ add_UITour_task(function* test_resetFirefox() { subj.close(); resolve(); } - }); + }, {once: true}); } }); }); diff --git a/browser/components/uitour/test/head.js b/browser/components/uitour/test/head.js index 2d87f4377aca..978b7c8fe375 100644 --- a/browser/components/uitour/test/head.js +++ b/browser/components/uitour/test/head.js @@ -252,9 +252,7 @@ function loadUITourTestPage(callback, host = "https://example.org/") { gTestTab = gBrowser.addTab(url); gBrowser.selectedTab = gTestTab; - gTestTab.linkedBrowser.addEventListener("load", function onLoad() { - gTestTab.linkedBrowser.removeEventListener("load", onLoad, true); - + gTestTab.linkedBrowser.addEventListener("load", function() { if (gMultiProcessBrowser) { // When e10s is enabled, make gContentAPI and gContentWindow proxies which has every property // return a function which calls the method of the same name on @@ -343,7 +341,7 @@ function loadUITourTestPage(callback, host = "https://example.org/") { } waitForFocus(callback, gTestTab.linkedBrowser); - }, true); + }, {capture: true, once: true}); } // Wrapper for UITourTest to be used by add_task tests. diff --git a/browser/extensions/mortar/host/pdf/chrome/js/l20n.js b/browser/extensions/mortar/host/pdf/chrome/js/l20n.js index 5fc40df96c64..7ff7f600d7c8 100644 --- a/browser/extensions/mortar/host/pdf/chrome/js/l20n.js +++ b/browser/extensions/mortar/host/pdf/chrome/js/l20n.js @@ -2381,10 +2381,9 @@ } return new Promise(resolve => { - document.addEventListener('readystatechange', function onrsc() { - document.removeEventListener('readystatechange', onrsc); + document.addEventListener('readystatechange', function() { resolve(); - }); + }, {once: true}); }); } diff --git a/browser/extensions/mortar/host/pdf/chrome/js/toolbar.js b/browser/extensions/mortar/host/pdf/chrome/js/toolbar.js index 3e3c9ca53b58..9c040cc5901c 100644 --- a/browser/extensions/mortar/host/pdf/chrome/js/toolbar.js +++ b/browser/extensions/mortar/host/pdf/chrome/js/toolbar.js @@ -23,10 +23,9 @@ class ProgressBar { if (!waitForTransition) { doHide(); } else { - percentage.addEventListener('transitionend', function handler() { - percentage.removeEventListener('transitionend', handler); + percentage.addEventListener('transitionend', function() { doHide(); - }); + }, {once: true}); } } diff --git a/browser/extensions/pdfjs/test/browser_pdfjs_navigation.js b/browser/extensions/pdfjs/test/browser_pdfjs_navigation.js index bf580b108b46..37bcd73b17f6 100644 --- a/browser/extensions/pdfjs/test/browser_pdfjs_navigation.js +++ b/browser/extensions/pdfjs/test/browser_pdfjs_navigation.js @@ -182,8 +182,7 @@ function* contentSetUp() { */ function waitForOutlineItems(document) { return new Promise((resolve, reject) => { - document.addEventListener("outlineloaded", function outlineLoaded(evt) { - document.removeEventListener("outlineloaded", outlineLoaded); + document.addEventListener("outlineloaded", function(evt) { var outlineCount = evt.detail.outlineCount; if (document.querySelectorAll(".outlineItem").length === outlineCount) { @@ -191,7 +190,7 @@ function* contentSetUp() { } else { reject(); } - }); + }, {once: true}); }); } @@ -204,11 +203,10 @@ function* contentSetUp() { */ function setZoomToPageFit(document) { return new Promise((resolve) => { - document.addEventListener("pagerendered", function onZoom(e) { - document.removeEventListener("pagerendered", onZoom); + document.addEventListener("pagerendered", function(e) { document.querySelector("#viewer").click(); resolve(); - }); + }, {once: true}); var select = document.querySelector("select#scaleSelect"); select.selectedIndex = 2; diff --git a/browser/modules/test/browser_ContentSearch.js b/browser/modules/test/browser_ContentSearch.js index 87176f9e6385..b84954b4554d 100644 --- a/browser/modules/test/browser_ContentSearch.js +++ b/browser/modules/test/browser_ContentSearch.js @@ -350,8 +350,7 @@ function addTab() { let deferred = Promise.defer(); let tab = gBrowser.addTab(); gBrowser.selectedTab = tab; - tab.linkedBrowser.addEventListener("load", function load() { - tab.linkedBrowser.removeEventListener("load", load, true); + tab.linkedBrowser.addEventListener("load", function() { let url = getRootDirectory(gTestPath) + TEST_CONTENT_SCRIPT_BASENAME; gMsgMan = tab.linkedBrowser.messageManager; gMsgMan.sendAsyncMessage(CONTENT_SEARCH_MSG, { @@ -362,7 +361,7 @@ function addTab() { gMsgMan.loadFrameScript(url, false); deferred.resolve(); }); - }, true); + }, {capture: true, once: true}); registerCleanupFunction(() => gBrowser.removeTab(tab)); return deferred.promise; } diff --git a/browser/modules/test/browser_ProcessHangNotifications.js b/browser/modules/test/browser_ProcessHangNotifications.js index 87a7c8811a8c..0551661d3626 100644 --- a/browser/modules/test/browser_ProcessHangNotifications.js +++ b/browser/modules/test/browser_ProcessHangNotifications.js @@ -8,11 +8,10 @@ function getNotificationBox(aWindow) { function promiseNotificationShown(aWindow, aName) { return new Promise((resolve) => { let notification = getNotificationBox(aWindow); - notification.addEventListener("AlertActive", function active() { - notification.removeEventListener("AlertActive", active, true); + notification.addEventListener("AlertActive", function() { is(notification.allNotifications.length, 1, "Notification Displayed."); resolve(notification); - }); + }, {once: true}); }); } diff --git a/browser/modules/webrtcUI.jsm b/browser/modules/webrtcUI.jsm index 133a2d2e6ee6..4bf2bbe3a34c 100644 --- a/browser/modules/webrtcUI.jsm +++ b/browser/modules/webrtcUI.jsm @@ -164,12 +164,11 @@ this.webrtcUI = { browserWindow.focus(); let identityBox = browserWindow.document.getElementById("identity-box"); if (AppConstants.platform == "macosx" && !Services.focus.activeWindow) { - browserWindow.addEventListener("activate", function onActivate() { - browserWindow.removeEventListener("activate", onActivate); + browserWindow.addEventListener("activate", function() { Services.tm.mainThread.dispatch(function() { identityBox.click(); }, Ci.nsIThread.DISPATCH_NORMAL); - }); + }, {once: true}); Cc["@mozilla.org/widget/macdocksupport;1"].getService(Ci.nsIMacDockSupport) .activateApplication(true); return; diff --git a/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/Preferences.jsm b/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/Preferences.jsm index aa2b3f2a7cae..087f2595f3cb 100644 --- a/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/Preferences.jsm +++ b/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/Preferences.jsm @@ -89,10 +89,9 @@ let prefHelper = Task.async(function*(primary, advanced = null, customFn = null) function paintPromise(browserWindow) { return new Promise((resolve) => { - browserWindow.addEventListener("MozAfterPaint", function onPaint() { - browserWindow.removeEventListener("MozAfterPaint", onPaint); + browserWindow.addEventListener("MozAfterPaint", function() { resolve(); - }); + }, {once: true}); }); } diff --git a/devtools/client/aboutdebugging/initializer.js b/devtools/client/aboutdebugging/initializer.js index 8a7665eb9756..967b76ad13bc 100644 --- a/devtools/client/aboutdebugging/initializer.js +++ b/devtools/client/aboutdebugging/initializer.js @@ -58,12 +58,10 @@ var AboutDebugging = { }, }; -window.addEventListener("DOMContentLoaded", function load() { - window.removeEventListener("DOMContentLoaded", load); +window.addEventListener("DOMContentLoaded", function () { AboutDebugging.init(); -}); +}, {once: true}); -window.addEventListener("unload", function unload() { - window.removeEventListener("unload", unload); +window.addEventListener("unload", function () { AboutDebugging.destroy(); -}); +}, {once: true}); diff --git a/devtools/client/canvasdebugger/test/head.js b/devtools/client/canvasdebugger/test/head.js index ae349526f9d7..f822281aa678 100644 --- a/devtools/client/canvasdebugger/test/head.js +++ b/devtools/client/canvasdebugger/test/head.js @@ -98,11 +98,10 @@ function removeTab(aTab, aWindow) { let targetBrowser = targetWindow.gBrowser; let tabContainer = targetBrowser.tabContainer; - tabContainer.addEventListener("TabClose", function onClose(aEvent) { - tabContainer.removeEventListener("TabClose", onClose); + tabContainer.addEventListener("TabClose", function (aEvent) { info("Tab removed and finished closing."); deferred.resolve(); - }); + }, {once: true}); targetBrowser.removeTab(aTab); return deferred.promise; diff --git a/devtools/client/commandline/test/browser_cmd_screenshot.js b/devtools/client/commandline/test/browser_cmd_screenshot.js index e7f3d058745e..78eb56d83c63 100644 --- a/devtools/client/commandline/test/browser_cmd_screenshot.js +++ b/devtools/client/commandline/test/browser_cmd_screenshot.js @@ -356,10 +356,9 @@ let getImageSizeFromClipboard = Task.async(function* () { let img = document.createElementNS("http://www.w3.org/1999/xhtml", "img"); let loaded = new Promise(resolve => { - img.addEventListener("load", function onLoad() { - img.removeEventListener("load", onLoad); + img.addEventListener("load", function () { resolve(); - }); + }, {once: true}); }); img.src = dataURI; diff --git a/devtools/client/debugger/test/mochitest/browser_dbg_on-pause-raise.js b/devtools/client/debugger/test/mochitest/browser_dbg_on-pause-raise.js index 8cf8fb80162d..4dd589436bf5 100644 --- a/devtools/client/debugger/test/mochitest/browser_dbg_on-pause-raise.js +++ b/devtools/client/debugger/test/mochitest/browser_dbg_on-pause-raise.js @@ -50,10 +50,9 @@ add_task(function *() { let onFocus, onTabSelect; if (toolbox.hostType == Toolbox.HostType.WINDOW) { onFocus = new Promise(done => { - toolbox.win.parent.addEventListener("focus", function onFocus() { - toolbox.win.parent.removeEventListener("focus", onFocus, true); + toolbox.win.parent.addEventListener("focus", function () { done(); - }, true); + }, {capture: true, once: true}); }); } else { onTabSelect = new Promise(done => { diff --git a/devtools/client/debugger/test/mochitest/browser_dbg_sources-contextmenu-02.js b/devtools/client/debugger/test/mochitest/browser_dbg_sources-contextmenu-02.js index 94b97b03ae06..2d140cc3e35d 100644 --- a/devtools/client/debugger/test/mochitest/browser_dbg_sources-contextmenu-02.js +++ b/devtools/client/debugger/test/mochitest/browser_dbg_sources-contextmenu-02.js @@ -40,16 +40,14 @@ function test() { function waitForTabOpen() { return new Promise(resolve => { - gBrowser.tabContainer.addEventListener("TabOpen", function onOpen(e) { - gBrowser.tabContainer.removeEventListener("TabOpen", onOpen); + gBrowser.tabContainer.addEventListener("TabOpen", function (e) { ok(true, "A new tab loaded"); - gBrowser.addEventListener("DOMContentLoaded", function onTabLoad(e) { - gBrowser.removeEventListener("DOMContentLoaded", onTabLoad); + gBrowser.addEventListener("DOMContentLoaded", function (e) { // Pass along the new tab's URI. resolve(gBrowser.currentURI.spec); - }); - }); + }, {once: true}); + }, {once: true}); }); } diff --git a/devtools/client/debugger/test/mochitest/code_frame-script.js b/devtools/client/debugger/test/mochitest/code_frame-script.js index 35a950b01aa9..fb07fcc80ae2 100644 --- a/devtools/client/debugger/test/mochitest/code_frame-script.js +++ b/devtools/client/debugger/test/mochitest/code_frame-script.js @@ -46,11 +46,10 @@ this.createWorker = function (url) { return new Promise(function (resolve, reject) { let worker = new content.Worker(url); - worker.addEventListener("message", function listener() { - worker.removeEventListener("message", listener); + worker.addEventListener("message", function () { workers[url] = worker; resolve(); - }); + }, {once: true}); }); }; @@ -67,10 +66,9 @@ this.postMessageToWorker = function (url, message) { return new Promise(function (resolve) { let worker = workers[url]; worker.postMessage(message); - worker.addEventListener("message", function listener() { - worker.removeEventListener("message", listener); + worker.addEventListener("message", function () { resolve(); - }); + }, {once: true}); }); }; @@ -99,8 +97,7 @@ addMessageListener("test:postMessageToWorker", function (message) { let worker = workers[message.data.url]; worker.postMessage(message.data.message); - worker.addEventListener("message", function listener() { - worker.removeEventListener("message", listener); + worker.addEventListener("message", function () { sendAsyncMessage("test:postMessageToWorker"); - }); + }, {once: true}); }); diff --git a/devtools/client/debugger/test/mochitest/doc_closure-optimized-out.html b/devtools/client/debugger/test/mochitest/doc_closure-optimized-out.html index b4f262cd40f5..3489b94d4926 100644 --- a/devtools/client/debugger/test/mochitest/doc_closure-optimized-out.html +++ b/devtools/client/debugger/test/mochitest/doc_closure-optimized-out.html @@ -6,8 +6,7 @@ diff --git a/devtools/client/debugger/test/mochitest/doc_closures.html b/devtools/client/debugger/test/mochitest/doc_closures.html index 247621b6931e..9f3880ba9d33 100644 --- a/devtools/client/debugger/test/mochitest/doc_closures.html +++ b/devtools/client/debugger/test/mochitest/doc_closures.html @@ -6,8 +6,7 @@ diff --git a/devtools/client/debugger/test/mochitest/doc_event-listeners-01.html b/devtools/client/debugger/test/mochitest/doc_event-listeners-01.html index b44400311baf..5d518ba86b6b 100644 --- a/devtools/client/debugger/test/mochitest/doc_event-listeners-01.html +++ b/devtools/client/debugger/test/mochitest/doc_event-listeners-01.html @@ -12,8 +12,7 @@ diff --git a/devtools/client/debugger/test/mochitest/doc_event-listeners-02.html b/devtools/client/debugger/test/mochitest/doc_event-listeners-02.html index 6a4649de9df8..d59859ebe321 100644 --- a/devtools/client/debugger/test/mochitest/doc_event-listeners-02.html +++ b/devtools/client/debugger/test/mochitest/doc_event-listeners-02.html @@ -12,8 +12,7 @@ diff --git a/devtools/client/debugger/test/mochitest/head.js b/devtools/client/debugger/test/mochitest/head.js index 48ba0752a1e6..2c93c72d3057 100644 --- a/devtools/client/debugger/test/mochitest/head.js +++ b/devtools/client/debugger/test/mochitest/head.js @@ -108,12 +108,10 @@ this.removeTab = function removeTab(aTab, aWindow) { let targetBrowser = targetWindow.gBrowser; let tabContainer = targetBrowser.tabContainer; - tabContainer.addEventListener("TabClose", function onClose(aEvent) { - tabContainer.removeEventListener("TabClose", onClose); - + tabContainer.addEventListener("TabClose", function (aEvent) { info("Tab removed and finished closing."); deferred.resolve(); - }); + }, {once: true}); targetBrowser.removeTab(aTab); return deferred.promise; diff --git a/devtools/client/debugger/views/global-search-view.js b/devtools/client/debugger/views/global-search-view.js index 8788102bb186..6b8b6e43c8e2 100644 --- a/devtools/client/debugger/views/global-search-view.js +++ b/devtools/client/debugger/views/global-search-view.js @@ -333,10 +333,9 @@ GlobalSearchView.prototype = Heritage.extend(WidgetMethods, { */ _bounceMatch: function (aMatch) { Services.tm.currentThread.dispatch({ run: () => { - aMatch.addEventListener("transitionend", function onEvent() { - aMatch.removeEventListener("transitionend", onEvent); + aMatch.addEventListener("transitionend", function () { aMatch.removeAttribute("focused"); - }); + }, {once: true}); aMatch.setAttribute("focused", ""); }}, 0); aMatch.setAttribute("focusing", ""); diff --git a/devtools/client/framework/connect/connect.js b/devtools/client/framework/connect/connect.js index d713231f9df2..49bcd93ce1f8 100644 --- a/devtools/client/framework/connect/connect.js +++ b/devtools/client/framework/connect/connect.js @@ -24,8 +24,7 @@ var gConnectionTimeout; * Once DOM is ready, we prefil the host/port inputs with * pref-stored values. */ -window.addEventListener("DOMContentLoaded", function onDOMReady() { - window.removeEventListener("DOMContentLoaded", onDOMReady, true); +window.addEventListener("DOMContentLoaded", function () { let host = Services.prefs.getCharPref("devtools.debugger.remote-host"); let port = Services.prefs.getIntPref("devtools.debugger.remote-port"); @@ -45,7 +44,7 @@ window.addEventListener("DOMContentLoaded", function onDOMReady() { showError("unexpected"); }); }); -}, true); +}, {capture: true, once: true}); /** * Called when the "connect" button is clicked. diff --git a/devtools/client/framework/test/browser_toolbox_options_enable_serviceworkers_testing_frame_script.js b/devtools/client/framework/test/browser_toolbox_options_enable_serviceworkers_testing_frame_script.js index ec5ab3762464..c24d3b203680 100644 --- a/devtools/client/framework/test/browser_toolbox_options_enable_serviceworkers_testing_frame_script.js +++ b/devtools/client/framework/test/browser_toolbox_options_enable_serviceworkers_testing_frame_script.js @@ -27,8 +27,7 @@ addMessageListener("devtools:sw-test:unregister", function (msg) { addMessageListener("devtools:sw-test:iframe:register-and-unregister", function (msg) { var frame = content.document.createElement("iframe"); - frame.addEventListener("load", function onLoad() { - frame.removeEventListener("load", onLoad); + frame.addEventListener("load", function () { frame.contentWindow.navigator.serviceWorker.register("serviceworker.js") .then(swr => { return swr.unregister(); @@ -40,7 +39,7 @@ addMessageListener("devtools:sw-test:iframe:register-and-unregister", function ( sendAsyncMessage("devtools:sw-test:iframe:register-and-unregister", {success: false}); }); - }); + }, {once: true}); frame.src = "browser_toolbox_options_enabled_serviceworkers_testing.html"; content.document.body.appendChild(frame); }); diff --git a/devtools/client/framework/test/browser_two_tabs.js b/devtools/client/framework/test/browser_two_tabs.js index 08d5f2391b3c..b65fe36b5edb 100644 --- a/devtools/client/framework/test/browser_two_tabs.js +++ b/devtools/client/framework/test/browser_two_tabs.js @@ -120,11 +120,9 @@ function checkSelectedTabActor() { function closeSecondTab() { // Close the second tab, currently selected let container = gBrowser.tabContainer; - container.addEventListener("TabClose", function onTabClose() { - container.removeEventListener("TabClose", onTabClose); - + container.addEventListener("TabClose", function () { checkFirstTabActor(); - }); + }, {once: true}); gBrowser.removeTab(gTab2); } @@ -140,10 +138,8 @@ function checkFirstTabActor() { function cleanup() { let container = gBrowser.tabContainer; - container.addEventListener("TabClose", function onTabClose() { - container.removeEventListener("TabClose", onTabClose); - + container.addEventListener("TabClose", function () { gClient.close().then(finish); - }); + }, {once: true}); gBrowser.removeTab(gTab1); } diff --git a/devtools/client/inspector/local-toolbox.js b/devtools/client/inspector/local-toolbox.js index aa8efb2567b9..e63c568ef3ca 100644 --- a/devtools/client/inspector/local-toolbox.js +++ b/devtools/client/inspector/local-toolbox.js @@ -92,9 +92,7 @@ function fixStylesheetsOnMutation() { } } -window.addEventListener("DOMContentLoaded", function onInspectorDOMLoaded() { - window.removeEventListener("DOMContentLoaded", onInspectorDOMLoaded); - +window.addEventListener("DOMContentLoaded", function () { // Add styling for the main document. fixStylesheets(document); @@ -118,4 +116,4 @@ window.addEventListener("DOMContentLoaded", function onInspectorDOMLoaded() { // required after DOMContentLoaded. const { bootstrap } = require("devtools-launchpad"); bootstrap(React, ReactDOM).then(onConnect); -}); +}, {once: true}); diff --git a/devtools/client/netmonitor/test/service-workers/status-codes.html b/devtools/client/netmonitor/test/service-workers/status-codes.html index 36c8e1c70ae9..975535dc627b 100644 --- a/devtools/client/netmonitor/test/service-workers/status-codes.html +++ b/devtools/client/netmonitor/test/service-workers/status-codes.html @@ -31,10 +31,9 @@ if (sw.controller) { resolve(); } else { - sw.addEventListener('controllerchange', function onControllerChange() { - sw.removeEventListener('controllerchange', onControllerChange); + sw.addEventListener('controllerchange', function () { resolve(); - }); + }, {once: true}); } }); }).catch(err => { diff --git a/devtools/client/projecteditor/lib/plugins/app-manager/app-project-editor.js b/devtools/client/projecteditor/lib/plugins/app-manager/app-project-editor.js index 9a66770b0d21..470be6871ef3 100644 --- a/devtools/client/projecteditor/lib/plugins/app-manager/app-project-editor.js +++ b/devtools/client/projecteditor/lib/plugins/app-manager/app-project-editor.js @@ -36,10 +36,9 @@ var AppProjectEditor = Class({ let iframe = this.iframe = this.elt.ownerDocument.createElement("iframe"); let iframeLoaded = this.iframeLoaded = promise.defer(); - iframe.addEventListener("load", function onLoad() { - iframe.removeEventListener("load", onLoad); + iframe.addEventListener("load", function () { iframeLoaded.resolve(); - }); + }, {once: true}); iframe.setAttribute("flex", "1"); iframe.setAttribute("src", appManagerOpts.projectOverviewURL); diff --git a/devtools/client/projecteditor/test/head.js b/devtools/client/projecteditor/test/head.js index 4cafcab44246..b5f16e6fc67d 100644 --- a/devtools/client/projecteditor/test/head.js +++ b/devtools/client/projecteditor/test/head.js @@ -366,19 +366,17 @@ function onceProjectRefreshed(projecteditor) { function onPopupShow(menu) { let defer = promise.defer(); - menu.addEventListener("popupshown", function onpopupshown() { - menu.removeEventListener("popupshown", onpopupshown); + menu.addEventListener("popupshown", function () { defer.resolve(); - }); + }, {once: true}); return defer.promise; } function onPopupHidden(menu) { let defer = promise.defer(); - menu.addEventListener("popuphidden", function onpopuphidden() { - menu.removeEventListener("popuphidden", onpopuphidden); + menu.addEventListener("popuphidden", function () { defer.resolve(); - }); + }, {once: true}); return defer.promise; } diff --git a/devtools/client/responsive.html/index.js b/devtools/client/responsive.html/index.js index 0f42baa31463..bb3ca7d252df 100644 --- a/devtools/client/responsive.html/index.js +++ b/devtools/client/responsive.html/index.js @@ -82,10 +82,9 @@ message.wait(window, "init").then(() => bootstrap.init()); // startup work that shouldn't block initial load message.wait(window, "post-init").then(() => bootstrap.dispatch(loadDevices())); -window.addEventListener("unload", function onUnload() { - window.removeEventListener("unload", onUnload); +window.addEventListener("unload", function () { bootstrap.destroy(); -}); +}, {once: true}); // Allows quick testing of actions from the console window.dispatch = action => bootstrap.dispatch(action); diff --git a/devtools/client/responsive.html/test/browser/browser_touch_simulation.js b/devtools/client/responsive.html/test/browser/browser_touch_simulation.js index 12a718306065..442dc7c6625c 100644 --- a/devtools/client/responsive.html/test/browser/browser_touch_simulation.js +++ b/devtools/client/responsive.html/test/browser/browser_touch_simulation.js @@ -211,10 +211,9 @@ function* injectEventUtils(ui) { EventUtils.KeyboardEvent = content.KeyboardEvent; EventUtils.synthesizeClick = element => new Promise(resolve => { - element.addEventListener("click", function onClick() { - element.removeEventListener("click", onClick); + element.addEventListener("click", function () { resolve(); - }); + }, {once: true}); EventUtils.synthesizeMouseAtCenter(element, { type: "mousedown", isSynthesized: false }, content); diff --git a/devtools/client/scratchpad/test/browser_scratchpad_browser_last_window_closing.js b/devtools/client/scratchpad/test/browser_scratchpad_browser_last_window_closing.js index 53489085a246..cc16e0f9b424 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_browser_last_window_closing.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_browser_last_window_closing.js @@ -14,10 +14,9 @@ function test() CloseObserver.init(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html;charset=utf8,

test browser last window closing

"; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_chrome_context_pref.js b/devtools/client/scratchpad/test/browser_scratchpad_chrome_context_pref.js index 08528d2c2731..59644ea1f3e9 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_chrome_context_pref.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_chrome_context_pref.js @@ -12,11 +12,9 @@ function test() Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, true); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); - + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,Scratchpad test for bug 646070 - chrome context preference"; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_contexts.js b/devtools/client/scratchpad/test/browser_scratchpad_contexts.js index ae1933b4d5d3..5277a1dde9be 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_contexts.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_contexts.js @@ -7,10 +7,9 @@ function test() { waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,test context switch in Scratchpad"; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_display_non_error_exceptions.js b/devtools/client/scratchpad/test/browser_scratchpad_display_non_error_exceptions.js index d1f2cb513a8d..5aa9c1ad2a16 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_display_non_error_exceptions.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_display_non_error_exceptions.js @@ -8,10 +8,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function browserLoad() { - gBrowser.selectedBrowser.removeEventListener("load", browserLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests, {"state":{"text":""}}); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html, test that exceptions are output as " + "comments correctly in Scratchpad"; diff --git a/devtools/client/scratchpad/test/browser_scratchpad_display_outputs_errors.js b/devtools/client/scratchpad/test/browser_scratchpad_display_outputs_errors.js index 3855a873d2ba..9cbfb613edbe 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_display_outputs_errors.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_display_outputs_errors.js @@ -8,10 +8,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function browserLoad() { - gBrowser.selectedBrowser.removeEventListener("load", browserLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests, {"state":{"text":""}}); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,

test that exceptions are output as " + "comments for 'display' and not sent to the console in Scratchpad"; diff --git a/devtools/client/scratchpad/test/browser_scratchpad_edit_ui_updates.js b/devtools/client/scratchpad/test/browser_scratchpad_edit_ui_updates.js index 7a50d380b06e..00578d32228e 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_edit_ui_updates.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_edit_ui_updates.js @@ -13,10 +13,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, false); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,test Edit menu updates Scratchpad - bug 699130"; } @@ -76,10 +75,9 @@ function runTests() let openMenu = function (aX, aY, aCallback) { if (!editMenu || OS != "Darwin") { - menuPopup.addEventListener("popupshown", function onPopupShown() { - menuPopup.removeEventListener("popupshown", onPopupShown); + menuPopup.addEventListener("popupshown", function () { executeSoon(aCallback); - }); + }, {once: true}); } executeSoon(function () { @@ -98,10 +96,9 @@ function runTests() let closeMenu = function (aCallback) { if (!editMenu || OS != "Darwin") { - menuPopup.addEventListener("popuphidden", function onPopupHidden() { - menuPopup.removeEventListener("popuphidden", onPopupHidden); + menuPopup.addEventListener("popuphidden", function () { executeSoon(aCallback); - }); + }, {once: true}); } executeSoon(function () { diff --git a/devtools/client/scratchpad/test/browser_scratchpad_eval_func.js b/devtools/client/scratchpad/test/browser_scratchpad_eval_func.js index 3753b5a35261..00a75f110ea4 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_eval_func.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_eval_func.js @@ -7,10 +7,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html;charset=utf8,test Scratchpad eval function."; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_execute_print.js b/devtools/client/scratchpad/test/browser_scratchpad_execute_print.js index 0299165074ed..065fdfed4e30 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_execute_print.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_execute_print.js @@ -7,10 +7,9 @@ function test() { waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,

test run() and display() in Scratchpad"; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_falsy.js b/devtools/client/scratchpad/test/browser_scratchpad_falsy.js index 9eb7efb945b3..54753e5da37e 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_falsy.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_falsy.js @@ -8,10 +8,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(testFalsy); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,

test falsy display() values in Scratchpad"; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_files.js b/devtools/client/scratchpad/test/browser_scratchpad_files.js index d52718a81f5a..4df9128838cb 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_files.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_files.js @@ -16,10 +16,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,

test file open and save in Scratchpad"; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_goto_line_ui.js b/devtools/client/scratchpad/test/browser_scratchpad_goto_line_ui.js index 34c71ac0c08d..c2f60644dedf 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_goto_line_ui.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_goto_line_ui.js @@ -8,10 +8,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function browserLoad() { - gBrowser.selectedBrowser.removeEventListener("load", browserLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,

test the 'Jump to line' feature in Scratchpad"; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_help_key.js b/devtools/client/scratchpad/test/browser_scratchpad_help_key.js index d5383db57c39..1e0e6a8d6124 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_help_key.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_help_key.js @@ -9,11 +9,9 @@ function test() gBrowser.selectedTab = gBrowser.addTab(); content.location = "data:text/html,Test keybindings for opening Scratchpad MDN Documentation, bug 650760"; - gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true); - + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTest); - }, true); + }, {capture: true, once: true}); } function runTest() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_initialization.js b/devtools/client/scratchpad/test/browser_scratchpad_initialization.js index 387bcb08cd73..80a306ad07c7 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_initialization.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_initialization.js @@ -10,11 +10,9 @@ function test() Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, false); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); - + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,initialization test for Scratchpad"; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_inspect.js b/devtools/client/scratchpad/test/browser_scratchpad_inspect.js index 23194f05ee45..6ae81b41de3a 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_inspect.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_inspect.js @@ -7,10 +7,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html;charset=utf8,

test inspect() in Scratchpad

"; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_long_string.js b/devtools/client/scratchpad/test/browser_scratchpad_long_string.js index d85a7df1cb52..d111cc7152ae 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_long_string.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_long_string.js @@ -7,10 +7,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html;charset=utf8,

test long string in Scratchpad

"; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_modeline.js b/devtools/client/scratchpad/test/browser_scratchpad_modeline.js index 20a4e844961c..f7fb4d081f4f 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_modeline.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_modeline.js @@ -15,10 +15,9 @@ function test() { Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, false); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,

test file open and save in Scratchpad"; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_open_error_console.js b/devtools/client/scratchpad/test/browser_scratchpad_open_error_console.js index 4da2a2dafa9e..a03ca961a903 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_open_error_console.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_open_error_console.js @@ -9,10 +9,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html;charset=utf8,test Scratchpad." + "openErrorConsole()"; diff --git a/devtools/client/scratchpad/test/browser_scratchpad_pprint-02.js b/devtools/client/scratchpad/test/browser_scratchpad_pprint-02.js index c7cd2927ef42..d85a156b9de2 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_pprint-02.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_pprint-02.js @@ -7,10 +7,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html;charset=utf8,test Scratchpad pretty print."; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_pprint.js b/devtools/client/scratchpad/test/browser_scratchpad_pprint.js index 1ba9a2cdad73..0955dba076f2 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_pprint.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_pprint.js @@ -7,10 +7,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html;charset=utf8,test Scratchpad pretty print."; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_pprint_error_goto_line.js b/devtools/client/scratchpad/test/browser_scratchpad_pprint_error_goto_line.js index 21f266f615e3..4b1bc33cb0a2 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_pprint_error_goto_line.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_pprint_error_goto_line.js @@ -10,10 +10,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html;charset=utf8," + "test Scratchpad pretty print error goto line."; diff --git a/devtools/client/scratchpad/test/browser_scratchpad_recent_files.js b/devtools/client/scratchpad/test/browser_scratchpad_recent_files.js index 66a4e7cd14c9..842698dbdfb4 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_recent_files.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_recent_files.js @@ -336,10 +336,9 @@ function test() PreferenceObserver.init(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(startTest); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,

test recent files in Scratchpad"; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_reload_and_run.js b/devtools/client/scratchpad/test/browser_scratchpad_reload_and_run.js index 19e360b2028a..614ec56e75ed 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_reload_and_run.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_reload_and_run.js @@ -17,10 +17,9 @@ function test() Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, true); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,Scratchpad test for bug 740948"; } @@ -55,19 +54,15 @@ function runTests() let browser = gBrowser.selectedBrowser; let deferred = promise.defer(); - browser.addEventListener("DOMWindowCreated", function onWindowCreated() { - browser.removeEventListener("DOMWindowCreated", onWindowCreated, true); - - browser.contentWindow.addEventListener("foo", function onFoo() { - browser.contentWindow.removeEventListener("foo", onFoo, true); - + browser.addEventListener("DOMWindowCreated", function () { + browser.contentWindow.addEventListener("foo", function () { is(browser.contentWindow.document.body.innerHTML, "Modified text", "After reloading, HTML is different."); Services.prefs.clearUserPref(DEVTOOLS_CHROME_ENABLED); deferred.resolve(); - }, true); - }, true); + }, {capture: true, once: true}); + }, {capture: true, once: true}); ok(browser.contentWindow.document.body.innerHTML !== "Modified text", "Before reloading, HTML is intact."); diff --git a/devtools/client/scratchpad/test/browser_scratchpad_remember_view_options.js b/devtools/client/scratchpad/test/browser_scratchpad_remember_view_options.js index 67073c52f150..5ef1e7dd753d 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_remember_view_options.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_remember_view_options.js @@ -13,10 +13,9 @@ function test() // preference value with the expected value. gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,Bug 1140839" + "

test Scratchpad should remember View options"; diff --git a/devtools/client/scratchpad/test/browser_scratchpad_reset_undo.js b/devtools/client/scratchpad/test/browser_scratchpad_reset_undo.js index a1b60cd336ce..f47d16c07b56 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_reset_undo.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_reset_undo.js @@ -25,10 +25,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function browserLoad() { - gBrowser.selectedBrowser.removeEventListener("load", browserLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,

test that undo get's reset after file load in Scratchpad"; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_revert_to_saved.js b/devtools/client/scratchpad/test/browser_scratchpad_revert_to_saved.js index 92c6c37200d6..67ffe77dd1be 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_revert_to_saved.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_revert_to_saved.js @@ -124,10 +124,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(startTest); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,

test reverting to last saved state of" + " a file

"; diff --git a/devtools/client/scratchpad/test/browser_scratchpad_run_error_goto_line.js b/devtools/client/scratchpad/test/browser_scratchpad_run_error_goto_line.js index a5d3d516382d..f717b911cc7b 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_run_error_goto_line.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_run_error_goto_line.js @@ -10,10 +10,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html;charset=utf8,test Scratchpad pretty print."; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_tab.js b/devtools/client/scratchpad/test/browser_scratchpad_tab.js index 67057f206589..f174efaf317f 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_tab.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_tab.js @@ -8,13 +8,11 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true); - + gBrowser.selectedBrowser.addEventListener("load", function () { Services.prefs.setIntPref("devtools.editor.tabsize", 5); openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,Scratchpad test for the Tab key, bug 660560"; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_tab_switch.js b/devtools/client/scratchpad/test/browser_scratchpad_tab_switch.js index c2419a1e1a1a..1f49fe66c9c8 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_tab_switch.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_tab_switch.js @@ -12,17 +12,14 @@ function test() tab1 = gBrowser.addTab(); gBrowser.selectedTab = tab1; - gBrowser.selectedBrowser.addEventListener("load", function onLoad1() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad1, true); - + gBrowser.selectedBrowser.addEventListener("load", function () { tab2 = gBrowser.addTab(); gBrowser.selectedTab = tab2; - gBrowser.selectedBrowser.addEventListener("load", function onLoad2() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad2, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,test context switch in Scratchpad tab 2"; - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,test context switch in Scratchpad tab 1"; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_throw_output.js b/devtools/client/scratchpad/test/browser_scratchpad_throw_output.js index cfcd5e049f00..e595aa85e45c 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_throw_output.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_throw_output.js @@ -8,10 +8,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(testThrowOutput); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html;charset=utf8,

Test throw outputs in Scratchpad

"; } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_ui.js b/devtools/client/scratchpad/test/browser_scratchpad_ui.js index 5d8af1068e3f..038eda6b1be2 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_ui.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_ui.js @@ -7,10 +7,9 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(runTests); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html,foobarBug636725" + "

test inspect() in Scratchpad"; diff --git a/devtools/client/scratchpad/test/browser_scratchpad_wrong_window_focus.js b/devtools/client/scratchpad/test/browser_scratchpad_wrong_window_focus.js index 0d094ba98b92..d106e806e49b 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_wrong_window_focus.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_wrong_window_focus.js @@ -26,9 +26,7 @@ function test() // is currently active (it should be the older one). gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); - + gBrowser.selectedBrowser.addEventListener("load", function () { openScratchpad(function () { let sw = gScratchpadWindow; let {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); @@ -43,7 +41,7 @@ function test() }); }); }); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html;charset=utf8,

test window focus for Scratchpad."; } @@ -61,9 +59,7 @@ function testFocus(sw, hud) { is(loc.getAttribute("data-line"), "1", "line value is correct"); is(loc.getAttribute("data-column"), "1", "column value is correct"); - sw.addEventListener("focus", function onFocus() { - sw.removeEventListener("focus", onFocus, true); - + sw.addEventListener("focus", function () { let win = Services.wm.getMostRecentWindow("devtools:scratchpad"); ok(win, "there are active Scratchpad windows"); @@ -74,7 +70,7 @@ function testFocus(sw, hud) { // close the second window ourselves. sw.close(); finish(); - }, true); + }, {capture: true, once: true}); // Simulate a click on the "Scratchpad/N:1" link. EventUtils.synthesizeMouse(loc, 2, 2, {}, hud.iframeWindow); diff --git a/devtools/client/scratchpad/test/head.js b/devtools/client/scratchpad/test/head.js index 293529fa15ff..ab3ebce6d48e 100644 --- a/devtools/client/scratchpad/test/head.js +++ b/devtools/client/scratchpad/test/head.js @@ -91,10 +91,9 @@ function openTabAndScratchpad(aOptions = {}) return new promise(resolve => { gBrowser.selectedTab = gBrowser.addTab(); let {selectedBrowser} = gBrowser; - selectedBrowser.addEventListener("load", function onLoad() { - selectedBrowser.removeEventListener("load", onLoad, true); + selectedBrowser.addEventListener("load", function () { openScratchpad((win, sp) => resolve([win, sp]), aOptions); - }, true); + }, {capture: true, once: true}); content.location = "data:text/html;charset=utf8," + (aOptions.tabContent || ""); }); } diff --git a/devtools/client/shadereditor/test/head.js b/devtools/client/shadereditor/test/head.js index bb17000733c6..a9f04532856a 100644 --- a/devtools/client/shadereditor/test/head.js +++ b/devtools/client/shadereditor/test/head.js @@ -92,11 +92,10 @@ function removeTab(aTab, aWindow) { let targetBrowser = targetWindow.gBrowser; let tabContainer = targetBrowser.tabContainer; - tabContainer.addEventListener("TabClose", function onClose(aEvent) { - tabContainer.removeEventListener("TabClose", onClose); + tabContainer.addEventListener("TabClose", function (aEvent) { info("Tab removed and finished closing."); deferred.resolve(); - }); + }, {once: true}); targetBrowser.removeTab(aTab); return deferred.promise; diff --git a/devtools/client/shared/frame-script-utils.js b/devtools/client/shared/frame-script-utils.js index 3db7ed9ab09b..69336b207bee 100644 --- a/devtools/client/shared/frame-script-utils.js +++ b/devtools/client/shared/frame-script-utils.js @@ -62,10 +62,9 @@ function promiseXHR(data) { } let deferred = defer(); - xhr.addEventListener("loadend", function loadend(event) { - xhr.removeEventListener("loadend", loadend); + xhr.addEventListener("loadend", function (event) { deferred.resolve({ status: xhr.status, response: xhr.response }); - }); + }, {once: true}); xhr.open(method, url); diff --git a/devtools/client/shared/test/browser_tableWidget_keyboard_interaction.js b/devtools/client/shared/test/browser_tableWidget_keyboard_interaction.js index f1d54f0ef5ad..7a249bb35bf6 100644 --- a/devtools/client/shared/test/browser_tableWidget_keyboard_interaction.js +++ b/devtools/client/shared/test/browser_tableWidget_keyboard_interaction.js @@ -27,9 +27,7 @@ function test() { waitForExplicitFinish(); let win = Services.ww.openWindow(null, TEST_URI, "_blank", TEST_OPT, null); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); - + win.addEventListener("load", function () { waitForFocus(function () { doc = win.document; table = new TableWidget(doc.querySelector("box"), { @@ -46,7 +44,7 @@ function test() { }); startTests(); }); - }); + }, {once: true}); } function endTests() { diff --git a/devtools/client/shared/test/browser_tableWidget_mouse_interaction.js b/devtools/client/shared/test/browser_tableWidget_mouse_interaction.js index 796bb00226d4..ccf8bdfb14bd 100644 --- a/devtools/client/shared/test/browser_tableWidget_mouse_interaction.js +++ b/devtools/client/shared/test/browser_tableWidget_mouse_interaction.js @@ -27,9 +27,7 @@ function test() { waitForExplicitFinish(); let win = Services.ww.openWindow(null, TEST_URI, "_blank", TEST_OPT, null); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); - + win.addEventListener("load", function () { waitForFocus(function () { doc = win.document; table = new TableWidget(doc.querySelector("box"), { @@ -47,7 +45,7 @@ function test() { }); startTests(); }); - }); + }, {once: true}); } function endTests() { diff --git a/devtools/client/shared/test/browser_telemetry_button_scratchpad.js b/devtools/client/shared/test/browser_telemetry_button_scratchpad.js index 51fa12bee4f4..10b096ffa6de 100644 --- a/devtools/client/shared/test/browser_telemetry_button_scratchpad.js +++ b/devtools/client/shared/test/browser_telemetry_button_scratchpad.js @@ -42,9 +42,7 @@ function trackScratchpadWindows() { Services.ww.registerNotification(function observer(subject, topic) { if (topic == "domwindowopened") { let win = subject.QueryInterface(Ci.nsIDOMWindow); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); - + win.addEventListener("load", function () { if (win.Scratchpad) { win.Scratchpad.addObserver({ onReady: function () { @@ -63,7 +61,7 @@ function trackScratchpadWindows() { }, }); } - }); + }, {once: true}); } }); }); diff --git a/devtools/client/shared/test/browser_treeWidget_keyboard_interaction.js b/devtools/client/shared/test/browser_treeWidget_keyboard_interaction.js index 9b214fe3f606..4ec67443d245 100644 --- a/devtools/client/shared/test/browser_treeWidget_keyboard_interaction.js +++ b/devtools/client/shared/test/browser_treeWidget_keyboard_interaction.js @@ -140,11 +140,10 @@ function* testKeyboardInteraction(tree, win) { // pressing left to check expand collapse feature. // This does not emit any event, so listening for keypress - tree.root.children.addEventListener("keypress", function onClick() { - tree.root.children.removeEventListener("keypress", onClick); + tree.root.children.addEventListener("keypress", function () { // executeSoon so that other listeners on the same method are executed first executeSoon(() => event.resolve(null)); - }); + }, {once: true}); info("Pressing left key to collapse the item"); event = defer(); node = tree._selectedLabel; @@ -183,10 +182,9 @@ function* testKeyboardInteraction(tree, win) { // collapsing the item to check expand feature. - tree.root.children.addEventListener("keypress", function onClick() { - tree.root.children.removeEventListener("keypress", onClick); + tree.root.children.addEventListener("keypress", function () { executeSoon(() => event.resolve(null)); - }); + }, {once: true}); info("Pressing left key to collapse the item"); event = defer(); node = tree._selectedLabel; @@ -197,10 +195,9 @@ function* testKeyboardInteraction(tree, win) { // pressing right should expand this now. - tree.root.children.addEventListener("keypress", function onClick() { - tree.root.children.removeEventListener("keypress", onClick); + tree.root.children.addEventListener("keypress", function () { executeSoon(() => event.resolve(null)); - }); + }, {once: true}); info("Pressing right key to expend the collapsed item"); event = defer(); node = tree._selectedLabel; @@ -215,10 +212,9 @@ function* testKeyboardInteraction(tree, win) { node = tree._selectedLabel; // pressing down again should not change selection event = defer(); - tree.root.children.addEventListener("keypress", function onClick() { - tree.root.children.removeEventListener("keypress", onClick); + tree.root.children.addEventListener("keypress", function () { executeSoon(() => event.resolve(null)); - }); + }, {once: true}); info("Pressing down key on last item of the tree"); EventUtils.sendKey("DOWN", win); yield event.promise; diff --git a/devtools/client/shared/test/test-actor.js b/devtools/client/shared/test/test-actor.js index 3aab5287b328..5bae90ed1f89 100644 --- a/devtools/client/shared/test/test-actor.js +++ b/devtools/client/shared/test/test-actor.js @@ -692,12 +692,10 @@ var TestActor = exports.TestActor = protocol.ActorClassWithSpec(testSpec, { } let deferred = defer(); - this.content.addEventListener("scroll", function onScroll(event) { - this.removeEventListener("scroll", onScroll); - + this.content.addEventListener("scroll", function (event) { let data = {x: this.content.scrollX, y: this.content.scrollY}; deferred.resolve(data); - }); + }, {once: true}); this.content[relative ? "scrollBy" : "scrollTo"](x, y); diff --git a/devtools/client/shared/widgets/Graphs.js b/devtools/client/shared/widgets/Graphs.js index 485da2b1b5e4..40d36f2b6bee 100644 --- a/devtools/client/shared/widgets/Graphs.js +++ b/devtools/client/shared/widgets/Graphs.js @@ -1243,10 +1243,9 @@ AbstractCanvasGraph.prototype = { AbstractCanvasGraph.createIframe = function (url, parent, callback) { let iframe = parent.ownerDocument.createElementNS(HTML_NS, "iframe"); - iframe.addEventListener("DOMContentLoaded", function onLoad() { - iframe.removeEventListener("DOMContentLoaded", onLoad); + iframe.addEventListener("DOMContentLoaded", function () { callback(iframe); - }); + }, {once: true}); // Setting 100% width on the frame and flex on the parent allows the graph // to properly shrink when the window is resized to be smaller. diff --git a/devtools/client/sourceeditor/test/browser_editor_find_again.js b/devtools/client/sourceeditor/test/browser_editor_find_again.js index 5426cadf2f34..47f0e19c2a7d 100644 --- a/devtools/client/sourceeditor/test/browser_editor_find_again.js +++ b/devtools/client/sourceeditor/test/browser_editor_find_again.js @@ -27,10 +27,9 @@ const REPLACE_KEY = OS == "Darwin" ? L10N.getStr("replaceAllMac.key") // Using a timeout could also work, but that is more precise, ensuring also // the execution of the listeners added to the 's focus. const dispatchAndWaitForFocus = (target) => new Promise((resolve) => { - target.addEventListener("focus", function listener() { - target.removeEventListener("focus", listener); + target.addEventListener("focus", function () { resolve(target); - }); + }, {once: true}); target.dispatchEvent(new UIEvent("focus")); }); diff --git a/devtools/client/sourceeditor/test/head.js b/devtools/client/sourceeditor/test/head.js index 4b41212a4aa4..201b1c697d38 100644 --- a/devtools/client/sourceeditor/test/head.js +++ b/devtools/client/sourceeditor/test/head.js @@ -50,9 +50,7 @@ function setup(cb, additionalOpts = {}) { opts[o] = additionalOpts[o]; } - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); - + win.addEventListener("load", function () { waitForFocus(function () { let box = win.document.querySelector("box"); let editor = new Editor(opts); @@ -67,7 +65,7 @@ function setup(cb, additionalOpts = {}) { cb(editor, win); }, err => ok(false, err.message)); }, win); - }); + }, {once: true}); return def.promise; } diff --git a/devtools/client/styleeditor/test/browser_styleeditor_opentab.js b/devtools/client/styleeditor/test/browser_styleeditor_opentab.js index c16e9d51b0bb..f2782b239d82 100644 --- a/devtools/client/styleeditor/test/browser_styleeditor_opentab.js +++ b/devtools/client/styleeditor/test/browser_styleeditor_opentab.js @@ -50,19 +50,17 @@ add_task(function* () { function onPopupShow(contextMenu) { let deferred = defer(); - contextMenu.addEventListener("popupshown", function onpopupshown() { - contextMenu.removeEventListener("popupshown", onpopupshown); + contextMenu.addEventListener("popupshown", function () { deferred.resolve(); - }); + }, {once: true}); return deferred.promise; } function onPopupHide(contextMenu) { let deferred = defer(); - contextMenu.addEventListener("popuphidden", function popuphidden() { - contextMenu.removeEventListener("popuphidden", popuphidden); + contextMenu.addEventListener("popuphidden", function () { deferred.resolve(); - }); + }, {once: true}); return deferred.promise; } diff --git a/devtools/client/styleeditor/test/head.js b/devtools/client/styleeditor/test/head.js index c7abaa43570c..795d1d0286e6 100644 --- a/devtools/client/styleeditor/test/head.js +++ b/devtools/client/styleeditor/test/head.js @@ -48,10 +48,9 @@ var navigateTo = Task.async(function* (url) { let browser = gBrowser.selectedBrowser; let navigating = defer(); - browser.addEventListener("load", function onload() { - browser.removeEventListener("load", onload, true); + browser.addEventListener("load", function () { navigating.resolve(); - }, true); + }, {capture: true, once: true}); browser.loadURI(url); diff --git a/devtools/client/webaudioeditor/test/head.js b/devtools/client/webaudioeditor/test/head.js index 18993dc783c7..5eae176fe37f 100644 --- a/devtools/client/webaudioeditor/test/head.js +++ b/devtools/client/webaudioeditor/test/head.js @@ -89,11 +89,10 @@ function removeTab(aTab, aWindow) { let targetBrowser = targetWindow.gBrowser; let tabContainer = targetBrowser.tabContainer; - tabContainer.addEventListener("TabClose", function onClose(aEvent) { - tabContainer.removeEventListener("TabClose", onClose); + tabContainer.addEventListener("TabClose", function (aEvent) { info("Tab removed and finished closing."); deferred.resolve(); - }); + }, {once: true}); targetBrowser.removeTab(aTab); return deferred.promise; diff --git a/devtools/client/webconsole/console-output.js b/devtools/client/webconsole/console-output.js index 1b03859a35c9..21dbb2d93b42 100644 --- a/devtools/client/webconsole/console-output.js +++ b/devtools/client/webconsole/console-output.js @@ -2520,11 +2520,10 @@ Widgets.JSObject.prototype = extend(Widgets.BaseWidget.prototype, { let openVarView = this.openObjectInVariablesView.bind(this); openInVarViewCmd.addEventListener("command", openVarView); openInVarViewCmd.removeAttribute("disabled"); - cmPopup.addEventListener("popuphiding", function onPopupHiding() { - cmPopup.removeEventListener("popuphiding", onPopupHiding); + cmPopup.addEventListener("popuphiding", function () { openInVarViewCmd.removeEventListener("command", openVarView); openInVarViewCmd.setAttribute("disabled", "true"); - }); + }, {once: true}); // 'Store as global variable' command isn't supported on pre-44 servers, // so remove it from the menu in that case. @@ -2535,11 +2534,10 @@ Widgets.JSObject.prototype = extend(Widgets.BaseWidget.prototype, { let storeObjectInWindow = this.storeObjectInWindow.bind(this); storeInGlobalCmd.addEventListener("command", storeObjectInWindow); storeInGlobalCmd.removeAttribute("disabled"); - cmPopup.addEventListener("popuphiding", function onPopupHiding() { - cmPopup.removeEventListener("popuphiding", onPopupHiding); + cmPopup.addEventListener("popuphiding", function () { storeInGlobalCmd.removeEventListener("command", storeObjectInWindow); storeInGlobalCmd.setAttribute("disabled", "true"); - }); + }, {once: true}); } }, diff --git a/devtools/client/webconsole/hudservice.js b/devtools/client/webconsole/hudservice.js index 46b4f2a139c8..e8ac92ac6da9 100644 --- a/devtools/client/webconsole/hudservice.js +++ b/devtools/client/webconsole/hudservice.js @@ -213,15 +213,13 @@ HUD_SERVICE.prototype = let win = Services.ww.openWindow(null, Tools.webConsole.url, "_blank", BROWSER_CONSOLE_WINDOW_FEATURES, null); - win.addEventListener("DOMContentLoaded", function onLoad() { - win.removeEventListener("DOMContentLoaded", onLoad); - + win.addEventListener("DOMContentLoaded", function () { // Set the correct Browser Console title. let root = win.document.documentElement; root.setAttribute("title", root.getAttribute("browserConsoleTitle")); deferred.resolve(win); - }); + }, {once: true}); return deferred.promise; } diff --git a/devtools/client/webconsole/jsterm.js b/devtools/client/webconsole/jsterm.js index 3d2cc1936a8b..5c323ebe908b 100644 --- a/devtools/client/webconsole/jsterm.js +++ b/devtools/client/webconsole/jsterm.js @@ -612,11 +612,10 @@ JSTerm.prototype = { let document = options.targetElement.ownerDocument; let iframe = document.createElementNS(XHTML_NS, "iframe"); - iframe.addEventListener("load", function onIframeLoad() { - iframe.removeEventListener("load", onIframeLoad, true); + iframe.addEventListener("load", function () { iframe.style.visibility = "visible"; deferred.resolve(iframe.contentWindow); - }, true); + }, {capture: true, once: true}); iframe.flex = 1; iframe.style.visibility = "hidden"; diff --git a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_context_menu_open_url.js b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_context_menu_open_url.js index 2a1ae60c96a7..98f9dc7379dd 100644 --- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_context_menu_open_url.js +++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_context_menu_open_url.js @@ -68,13 +68,11 @@ add_task(function* () { */ function listenToTabLoad() { return new Promise((resolve) => { - gBrowser.tabContainer.addEventListener("TabOpen", function onTabOpen(evt) { - gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, true); + gBrowser.tabContainer.addEventListener("TabOpen", function (evt) { let newTab = evt.target; - newTab.linkedBrowser.addEventListener("load", function onTabLoad() { - newTab.linkedBrowser.removeEventListener("load", onTabLoad, true); + newTab.linkedBrowser.addEventListener("load", function () { resolve(newTab); - }, true); - }, true); + }, {capture: true, once: true}); + }, {capture: true, once: true}); }); } diff --git a/devtools/client/webconsole/panel.js b/devtools/client/webconsole/panel.js index 3e3a4f4b988d..ff0f1e11a6f3 100644 --- a/devtools/client/webconsole/panel.js +++ b/devtools/client/webconsole/panel.js @@ -52,10 +52,9 @@ WebConsolePanel.prototype = { doc.readyState == "complete") { deferredIframe.resolve(null); } else { - iframe.addEventListener("load", function onIframeLoad() { - iframe.removeEventListener("load", onIframeLoad, true); + iframe.addEventListener("load", function () { deferredIframe.resolve(null); - }, true); + }, {capture: true, once: true}); } // Local debugging needs to make the target remote. diff --git a/devtools/client/webconsole/test/browser_bug_871156_ctrlw_close_tab.js b/devtools/client/webconsole/test/browser_bug_871156_ctrlw_close_tab.js index c1698cf9196f..1e15ba6b9f35 100644 --- a/devtools/client/webconsole/test/browser_bug_871156_ctrlw_close_tab.js +++ b/devtools/client/webconsole/test/browser_bug_871156_ctrlw_close_tab.js @@ -30,19 +30,17 @@ add_task(function* () { let target = TargetFactory.forTab(gBrowser.selectedTab); let toolbox = gDevTools.getToolbox(target); - gBrowser.tabContainer.addEventListener("TabClose", function onTabClose() { - gBrowser.tabContainer.removeEventListener("TabClose", onTabClose); + gBrowser.tabContainer.addEventListener("TabClose", function () { info("tab closed"); tabClosed.resolve(null); - }); + }, {once: true}); - gBrowser.tabContainer.addEventListener("TabSelect", function onTabSelect() { - gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect); + gBrowser.tabContainer.addEventListener("TabSelect", function () { if (gBrowser.selectedTab == firstTab) { info("tab selected"); tabSelected.resolve(null); } - }); + }, {once: true}); toolbox.once("destroyed", () => { info("toolbox destroyed"); diff --git a/devtools/client/webconsole/test/browser_netmonitor_shows_reqs_in_webconsole.js b/devtools/client/webconsole/test/browser_netmonitor_shows_reqs_in_webconsole.js index 9a15f5b0b118..c2b65ee56582 100644 --- a/devtools/client/webconsole/test/browser_netmonitor_shows_reqs_in_webconsole.js +++ b/devtools/client/webconsole/test/browser_netmonitor_shows_reqs_in_webconsole.js @@ -52,10 +52,9 @@ add_task(function* () { function loadDocument(browser) { let deferred = promise.defer(); - browser.addEventListener("load", function onLoad() { - browser.removeEventListener("load", onLoad, true); + browser.addEventListener("load", function () { deferred.resolve(); - }, true); + }, {capture: true, once: true}); BrowserTestUtils.loadURI(gBrowser.selectedBrowser, TEST_PATH); return deferred.promise; diff --git a/devtools/client/webconsole/test/browser_webconsole_bug_595934_message_categories.js b/devtools/client/webconsole/test/browser_webconsole_bug_595934_message_categories.js index 855cfbb8852f..689c94841460 100644 --- a/devtools/client/webconsole/test/browser_webconsole_bug_595934_message_categories.js +++ b/devtools/client/webconsole/test/browser_webconsole_bug_595934_message_categories.js @@ -162,11 +162,10 @@ function testNext() { test.onload && test.onload(evt); if (test.expectError) { - content.addEventListener("error", function _onError() { - content.removeEventListener("error", _onError); + content.addEventListener("error", function () { pageError = true; startNextTest(); - }); + }, {once: true}); // On e10s, the exception is triggered in child process // and is ignored by test harness if (!Services.appinfo.browserTabsRemoteAutostart) { diff --git a/devtools/client/webconsole/test/browser_webconsole_bug_653531_highlighter_console_helper.js b/devtools/client/webconsole/test/browser_webconsole_bug_653531_highlighter_console_helper.js index 217d481e25d5..e3ec30afa356 100644 --- a/devtools/client/webconsole/test/browser_webconsole_bug_653531_highlighter_console_helper.js +++ b/devtools/client/webconsole/test/browser_webconsole_bug_653531_highlighter_console_helper.js @@ -99,10 +99,9 @@ function test() { waitForExplicitFinish(); gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + gBrowser.selectedBrowser.addEventListener("load", function () { waitForFocus(createDocument, content); - }, true); + }, {capture: true, once: true}); BrowserTestUtils.loadURI(gBrowser.selectedBrowser, "data:text/html;charset=utf-8,test for highlighter helper in web console"); diff --git a/devtools/client/webconsole/test/browser_webconsole_bug_764572_output_open_url.js b/devtools/client/webconsole/test/browser_webconsole_bug_764572_output_open_url.js index 731e79d8b23c..bb4504a47cb1 100644 --- a/devtools/client/webconsole/test/browser_webconsole_bug_764572_output_open_url.js +++ b/devtools/client/webconsole/test/browser_webconsole_bug_764572_output_open_url.js @@ -99,11 +99,10 @@ function onNetworkMessage(results) { let currentTab = gBrowser.selectedTab; let newTab = null; - gBrowser.tabContainer.addEventListener("TabOpen", function onOpen(evt) { - gBrowser.tabContainer.removeEventListener("TabOpen", onOpen, true); + gBrowser.tabContainer.addEventListener("TabOpen", function (evt) { newTab = evt.target; newTab.linkedBrowser.addEventListener("load", onTabLoaded, true); - }, true); + }, {capture: true, once: true}); function onTabLoaded() { newTab.linkedBrowser.removeEventListener("load", onTabLoaded, true); diff --git a/devtools/client/webconsole/test/browser_webconsole_dont_navigate_on_doubleclick.js b/devtools/client/webconsole/test/browser_webconsole_dont_navigate_on_doubleclick.js index 61ac68208a25..58eca84b234e 100644 --- a/devtools/client/webconsole/test/browser_webconsole_dont_navigate_on_doubleclick.js +++ b/devtools/client/webconsole/test/browser_webconsole_dont_navigate_on_doubleclick.js @@ -41,12 +41,11 @@ function test() { let urlNode = networkEventMessage.querySelector(".url"); let deferred = promise.defer(); - urlNode.addEventListener("click", function onClick(event) { - urlNode.removeEventListener("click", onClick); + urlNode.addEventListener("click", function (event) { ok(event.defaultPrevented, "The default action was prevented."); deferred.resolve(); - }); + }, {once: true}); EventUtils.synthesizeMouseAtCenter(urlNode, {clickCount: 2}, hud.iframeWindow); diff --git a/devtools/client/webconsole/test/browser_webconsole_output_dom_elements_04.js b/devtools/client/webconsole/test/browser_webconsole_output_dom_elements_04.js index c7eb9490224d..09afd5238c6e 100644 --- a/devtools/client/webconsole/test/browser_webconsole_output_dom_elements_04.js +++ b/devtools/client/webconsole/test/browser_webconsole_output_dom_elements_04.js @@ -104,10 +104,9 @@ function* getWidgetAndMessage(result) { function reloadPage() { let def = promise.defer(); - gBrowser.selectedBrowser.addEventListener("load", function onload() { - gBrowser.selectedBrowser.removeEventListener("load", onload, true); + gBrowser.selectedBrowser.addEventListener("load", function () { def.resolve(); - }, true); + }, {capture: true, once: true}); content.location.reload(); return def.promise; } diff --git a/devtools/client/webconsole/test/browser_webconsole_shows_reqs_in_netmonitor.js b/devtools/client/webconsole/test/browser_webconsole_shows_reqs_in_netmonitor.js index 86255b0784da..dae6a34cced0 100644 --- a/devtools/client/webconsole/test/browser_webconsole_shows_reqs_in_netmonitor.js +++ b/devtools/client/webconsole/test/browser_webconsole_shows_reqs_in_netmonitor.js @@ -52,10 +52,9 @@ add_task(function* () { function loadDocument(browser) { let deferred = promise.defer(); - browser.addEventListener("load", function onLoad() { - browser.removeEventListener("load", onLoad, true); + browser.addEventListener("load", function () { deferred.resolve(); - }, true); + }, {capture: true, once: true}); BrowserTestUtils.loadURI(gBrowser.selectedBrowser, TEST_PATH); return deferred.promise; diff --git a/devtools/client/webconsole/test/head.js b/devtools/client/webconsole/test/head.js index bd705ffa04b2..44e95fd31e7f 100644 --- a/devtools/client/webconsole/test/head.js +++ b/devtools/client/webconsole/test/head.js @@ -52,10 +52,9 @@ function loadTab(url, preferredRemoteType) { let tab = gBrowser.selectedTab = gBrowser.addTab(url, { preferredRemoteType }); let browser = gBrowser.getBrowserForTab(tab); - browser.addEventListener("load", function onLoad() { - browser.removeEventListener("load", onLoad, true); + browser.addEventListener("load", function () { deferred.resolve({tab: tab, browser: browser}); - }, true); + }, {capture: true, once: true}); return deferred.promise; } @@ -69,10 +68,9 @@ function closeTab(tab) { let container = gBrowser.tabContainer; - container.addEventListener("TabClose", function onTabClose() { - container.removeEventListener("TabClose", onTabClose, true); + container.addEventListener("TabClose", function () { deferred.resolve(null); - }, true); + }, {capture: true, once: true}); gBrowser.removeTab(tab); diff --git a/devtools/client/webconsole/test/test-closure-optimized-out.html b/devtools/client/webconsole/test/test-closure-optimized-out.html index b4f262cd40f5..3489b94d4926 100644 --- a/devtools/client/webconsole/test/test-closure-optimized-out.html +++ b/devtools/client/webconsole/test/test-closure-optimized-out.html @@ -6,8 +6,7 @@ diff --git a/devtools/client/webconsole/test/test-error.html b/devtools/client/webconsole/test/test-error.html index a604bbe26b05..e52cfdf9599c 100644 --- a/devtools/client/webconsole/test/test-error.html +++ b/devtools/client/webconsole/test/test-error.html @@ -11,10 +11,9 @@ diff --git a/devtools/client/webide/content/addons.js b/devtools/client/webide/content/addons.js index 3948b040f1a2..913f83b330f0 100644 --- a/devtools/client/webide/content/addons.js +++ b/devtools/client/webide/content/addons.js @@ -9,8 +9,7 @@ const {gDevTools} = require("devtools/client/framework/devtools"); const {GetAvailableAddons, ForgetAddonsList} = require("devtools/client/webide/modules/addons"); const Strings = Services.strings.createBundle("chrome://devtools/locale/webide.properties"); -window.addEventListener("load", function onLoad() { - window.removeEventListener("load", onLoad); +window.addEventListener("load", function () { document.querySelector("#aboutaddons").onclick = function () { let browserWin = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType); if (browserWin && browserWin.BrowserOpenAddonsMgr) { @@ -22,12 +21,11 @@ window.addEventListener("load", function onLoad() { console.error(e); window.alert(Strings.formatStringFromName("error_cantFetchAddonsJSON", [e], 1)); }); -}, true); +}, {capture: true, once: true}); -window.addEventListener("unload", function onUnload() { - window.removeEventListener("unload", onUnload); +window.addEventListener("unload", function () { ForgetAddonsList(); -}, true); +}, {capture: true, once: true}); function CloseUI() { window.parent.UI.openProject(); @@ -67,12 +65,11 @@ function BuildItem(addon, type) { for (let e of events) { addon.on(e, onAddonUpdate); } - window.addEventListener("unload", function onUnload() { - window.removeEventListener("unload", onUnload); + window.addEventListener("unload", function () { for (let e of events) { addon.off(e, onAddonUpdate); } - }); + }, {once: true}); let li = document.createElement("li"); li.setAttribute("status", addon.status); diff --git a/devtools/client/webide/content/details.js b/devtools/client/webide/content/details.js index 9097cd8c5fd1..a8da37093f5c 100644 --- a/devtools/client/webide/content/details.js +++ b/devtools/client/webide/content/details.js @@ -8,17 +8,15 @@ const Services = require("Services"); const {AppManager} = require("devtools/client/webide/modules/app-manager"); const {ProjectBuilding} = require("devtools/client/webide/modules/build"); -window.addEventListener("load", function onLoad() { - window.removeEventListener("load", onLoad); +window.addEventListener("load", function () { document.addEventListener("visibilitychange", updateUI, true); AppManager.on("app-manager-update", onAppManagerUpdate); updateUI(); -}, true); +}, {capture: true, once: true}); -window.addEventListener("unload", function onUnload() { - window.removeEventListener("unload", onUnload); +window.addEventListener("unload", function () { AppManager.off("app-manager-update", onAppManagerUpdate); -}, true); +}, {capture: true, once: true}); function onAppManagerUpdate(event, what, details) { if (what == "project" || diff --git a/devtools/client/webide/content/devicepreferences.js b/devtools/client/webide/content/devicepreferences.js index 14c020f120fb..30e3de4c15c8 100644 --- a/devtools/client/webide/content/devicepreferences.js +++ b/devtools/client/webide/content/devicepreferences.js @@ -10,8 +10,7 @@ const ConfigView = require("devtools/client/webide/modules/config-view"); var configView = new ConfigView(window); -window.addEventListener("load", function onLoad() { - window.removeEventListener("load", onLoad); +window.addEventListener("load", function () { AppManager.on("app-manager-update", OnAppManagerUpdate); document.getElementById("close").onclick = CloseUI; document.getElementById("device-fields").onchange = UpdateField; @@ -21,12 +20,11 @@ window.addEventListener("load", function onLoad() { document.getElementById("custom-value-type").onchange = ClearNewFields; document.getElementById("add-custom-field").onkeyup = CheckNewFieldSubmit; BuildUI(); -}, true); +}, {capture: true, once: true}); -window.addEventListener("unload", function onUnload() { - window.removeEventListener("unload", onUnload); +window.addEventListener("unload", function () { AppManager.off("app-manager-update", OnAppManagerUpdate); -}); +}, {once: true}); function CloseUI() { window.parent.UI.openProject(); diff --git a/devtools/client/webide/content/logs.js b/devtools/client/webide/content/logs.js index 157d83b67698..b0847bd0cdc8 100644 --- a/devtools/client/webide/content/logs.js +++ b/devtools/client/webide/content/logs.js @@ -6,17 +6,13 @@ var Cu = Components.utils; const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); const {AppManager} = require("devtools/client/webide/modules/app-manager"); -window.addEventListener("load", function onLoad() { - window.removeEventListener("load", onLoad); - +window.addEventListener("load", function () { Logs.init(); -}); - -window.addEventListener("unload", function onUnload() { - window.removeEventListener("unload", onUnload); +}, {once: true}); +window.addEventListener("unload", function () { Logs.uninit(); -}); +}, {once: true}); const Logs = { init: function () { diff --git a/devtools/client/webide/content/monitor.js b/devtools/client/webide/content/monitor.js index a5d80d460e8e..f14ba02c3f5c 100644 --- a/devtools/client/webide/content/monitor.js +++ b/devtools/client/webide/content/monitor.js @@ -10,8 +10,7 @@ const {AppActorFront} = require("devtools/shared/apps/app-actor-front"); const {Connection} = require("devtools/shared/client/connection-manager"); const EventEmitter = require("devtools/shared/event-emitter"); -window.addEventListener("load", function onLoad() { - window.removeEventListener("load", onLoad); +window.addEventListener("load", function () { window.addEventListener("resize", Monitor.resize); window.addEventListener("unload", Monitor.unload); @@ -20,7 +19,7 @@ window.addEventListener("load", function onLoad() { }; Monitor.load(); -}); +}, {once: true}); /** diff --git a/devtools/client/webide/content/newapp.js b/devtools/client/webide/content/newapp.js index d47bfabecddd..5e52e3417bb8 100644 --- a/devtools/client/webide/content/newapp.js +++ b/devtools/client/webide/content/newapp.js @@ -28,12 +28,11 @@ console.log = console.log.bind(console); console.warn = console.warn.bind(console); console.error = console.error.bind(console); -window.addEventListener("load", function onLoad() { - window.removeEventListener("load", onLoad); +window.addEventListener("load", function () { let projectNameNode = document.querySelector("#project-name"); projectNameNode.addEventListener("input", canValidate, true); getTemplatesJSON(); -}, true); +}, {capture: true, once: true}); function getTemplatesJSON() { getJSON(TEMPLATES_URL).then(list => { diff --git a/devtools/client/webide/content/prefs.js b/devtools/client/webide/content/prefs.js index 59dedcdb13d6..70ca1f47d6cf 100644 --- a/devtools/client/webide/content/prefs.js +++ b/devtools/client/webide/content/prefs.js @@ -7,9 +7,7 @@ const Cu = Components.utils; const {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); -window.addEventListener("load", function onLoad() { - window.removeEventListener("load", onLoad); - +window.addEventListener("load", function () { // Listen to preference changes let inputs = document.querySelectorAll("[data-pref]"); for (let i of inputs) { @@ -26,17 +24,16 @@ window.addEventListener("load", function onLoad() { // Initialize the controls FillForm(); -}, true); +}, {capture: true, once: true}); -window.addEventListener("unload", function onUnload() { - window.removeEventListener("unload", onUnload); +window.addEventListener("unload", function () { let inputs = document.querySelectorAll("[data-pref]"); for (let i of inputs) { let pref = i.dataset.pref; i.removeEventListener("change", SaveForm); Services.prefs.removeObserver(pref, FillForm); } -}, true); +}, {capture: true, once: true}); function CloseUI() { window.parent.UI.openProject(); diff --git a/devtools/client/webide/content/project-listing.js b/devtools/client/webide/content/project-listing.js index 5641f6c0cb74..06c8de97d996 100644 --- a/devtools/client/webide/content/project-listing.js +++ b/devtools/client/webide/content/project-listing.js @@ -10,20 +10,18 @@ const ProjectList = require("devtools/client/webide/modules/project-list"); var projectList = new ProjectList(window, window.parent); -window.addEventListener("load", function onLoad() { - window.removeEventListener("load", onLoad, true); +window.addEventListener("load", function () { document.getElementById("new-app").onclick = CreateNewApp; document.getElementById("hosted-app").onclick = ImportHostedApp; document.getElementById("packaged-app").onclick = ImportPackagedApp; document.getElementById("refresh-tabs").onclick = RefreshTabs; projectList.update(); projectList.updateCommands(); -}, true); +}, {capture: true, once: true}); -window.addEventListener("unload", function onUnload() { - window.removeEventListener("unload", onUnload); +window.addEventListener("unload", function () { projectList.destroy(); -}); +}, {once: true}); function RefreshTabs() { projectList.refreshTabs(); diff --git a/devtools/client/webide/content/runtime-listing.js b/devtools/client/webide/content/runtime-listing.js index eb04f11316a1..6e92e7f191af 100644 --- a/devtools/client/webide/content/runtime-listing.js +++ b/devtools/client/webide/content/runtime-listing.js @@ -8,8 +8,7 @@ const RuntimeList = require("devtools/client/webide/modules/runtime-list"); var runtimeList = new RuntimeList(window, window.parent); -window.addEventListener("load", function onLoad() { - window.removeEventListener("load", onLoad, true); +window.addEventListener("load", function () { document.getElementById("runtime-screenshot").onclick = TakeScreenshot; document.getElementById("runtime-details").onclick = ShowRuntimeDetails; document.getElementById("runtime-disconnect").onclick = DisconnectRuntime; @@ -21,12 +20,11 @@ window.addEventListener("load", function onLoad() { document.getElementById("refresh-devices").onclick = RefreshScanners; runtimeList.update(); runtimeList.updateCommands(); -}, true); +}, {capture: true, once: true}); -window.addEventListener("unload", function onUnload() { - window.removeEventListener("unload", onUnload); +window.addEventListener("unload", function () { runtimeList.destroy(); -}); +}, {once: true}); function TakeScreenshot() { runtimeList.takeScreenshot(); diff --git a/devtools/client/webide/content/runtimedetails.js b/devtools/client/webide/content/runtimedetails.js index dea423e81008..80f54e5ff804 100644 --- a/devtools/client/webide/content/runtimedetails.js +++ b/devtools/client/webide/content/runtimedetails.js @@ -12,8 +12,7 @@ const Strings = Services.strings.createBundle("chrome://devtools/locale/webide.p const UNRESTRICTED_HELP_URL = "https://developer.mozilla.org/docs/Tools/WebIDE/Running_and_debugging_apps#Unrestricted_app_debugging_%28including_certified_apps_main_process_etc.%29"; -window.addEventListener("load", function onLoad() { - window.removeEventListener("load", onLoad); +window.addEventListener("load", function () { document.querySelector("#close").onclick = CloseUI; document.querySelector("#devtools-check button").onclick = EnableCertApps; document.querySelector("#adb-check button").onclick = RootADB; @@ -23,12 +22,11 @@ window.addEventListener("load", function onLoad() { AppManager.on("app-manager-update", OnAppManagerUpdate); BuildUI(); CheckLockState(); -}, true); +}, {capture: true, once: true}); -window.addEventListener("unload", function onUnload() { - window.removeEventListener("unload", onUnload); +window.addEventListener("unload", function () { AppManager.off("app-manager-update", OnAppManagerUpdate); -}); +}, {once: true}); function CloseUI() { window.parent.UI.openProject(); diff --git a/devtools/client/webide/content/webide.js b/devtools/client/webide/content/webide.js index db544f90708a..153cf9c1d332 100644 --- a/devtools/client/webide/content/webide.js +++ b/devtools/client/webide/content/webide.js @@ -56,15 +56,13 @@ console.log = console.log.bind(console); console.warn = console.warn.bind(console); console.error = console.error.bind(console); -window.addEventListener("load", function onLoad() { - window.removeEventListener("load", onLoad); +window.addEventListener("load", function () { UI.init(); -}); +}, {once: true}); -window.addEventListener("unload", function onUnload() { - window.removeEventListener("unload", onUnload); +window.addEventListener("unload", function () { UI.destroy(); -}); +}, {once: true}); var UI = { init: function () { diff --git a/devtools/client/webide/content/wifi-auth.js b/devtools/client/webide/content/wifi-auth.js index 5ae5d824c399..b6ad158d84b6 100644 --- a/devtools/client/webide/content/wifi-auth.js +++ b/devtools/client/webide/content/wifi-auth.js @@ -10,13 +10,12 @@ const { require } = const Services = require("Services"); const QR = require("devtools/shared/qrcode/index"); -window.addEventListener("load", function onLoad() { - window.removeEventListener("load", onLoad); +window.addEventListener("load", function () { document.getElementById("close").onclick = () => window.close(); document.getElementById("no-scanner").onclick = showToken; document.getElementById("yes-scanner").onclick = hideToken; buildUI(); -}); +}, {once: true}); function buildUI() { let { oob } = window.arguments[0]; diff --git a/devtools/client/webide/modules/runtimes.js b/devtools/client/webide/modules/runtimes.js index 06f8a302e546..398850919883 100644 --- a/devtools/client/webide/modules/runtimes.js +++ b/devtools/client/webide/modules/runtimes.js @@ -545,15 +545,14 @@ WiFiRuntime.prototype = { onOpenWindow(xulWindow) { let win = xulWindow.QueryInterface(Ci.nsIInterfaceRequestor) .getInterface(Ci.nsIDOMWindow); - win.addEventListener("load", function listener() { - win.removeEventListener("load", listener); + win.addEventListener("load", function () { if (win.document.documentElement.getAttribute("id") != WINDOW_ID) { return; } // Found the window promptWindow = win; Services.wm.removeListener(windowListener); - }); + }, {once: true}); }, onCloseWindow() {}, onWindowTitleChange() {} diff --git a/devtools/client/webide/test/head.js b/devtools/client/webide/test/head.js index 46f9b751bab5..c0d8c2ed3769 100644 --- a/devtools/client/webide/test/head.js +++ b/devtools/client/webide/test/head.js @@ -57,11 +57,10 @@ var openWebIDE = Task.async(function* (autoInstallAddons) { let win = ww.openWindow(null, "chrome://webide/content/", "webide", "chrome,centerscreen,resizable", null); yield new Promise(resolve => { - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); + win.addEventListener("load", function () { SimpleTest.requestCompleteLog(); SimpleTest.executeSoon(resolve); - }); + }, {once: true}); }); info("WebIDE open"); @@ -76,13 +75,12 @@ function closeWebIDE(win) { Services.prefs.clearUserPref("devtools.webide.widget.enabled"); - win.addEventListener("unload", function onUnload() { - win.removeEventListener("unload", onUnload); + win.addEventListener("unload", function () { info("WebIDE closed"); SimpleTest.executeSoon(() => { deferred.resolve(); }); - }); + }, {once: true}); win.close(); @@ -149,10 +147,9 @@ function documentIsLoaded(doc) { function lazyIframeIsLoaded(iframe) { let deferred = promise.defer(); - iframe.addEventListener("load", function onLoad() { - iframe.removeEventListener("load", onLoad, true); + iframe.addEventListener("load", function () { deferred.resolve(nextTick()); - }, true); + }, {capture: true, once: true}); return deferred.promise; } @@ -183,11 +180,10 @@ function removeTab(aTab, aWindow) { let targetBrowser = targetWindow.gBrowser; let tabContainer = targetBrowser.tabContainer; - tabContainer.addEventListener("TabClose", function onClose(aEvent) { - tabContainer.removeEventListener("TabClose", onClose); + tabContainer.addEventListener("TabClose", function (aEvent) { info("Tab removed and finished closing."); deferred.resolve(); - }); + }, {once: true}); targetBrowser.removeTab(aTab); return deferred.promise; diff --git a/devtools/server/tests/browser/browser_navigateEvents.js b/devtools/server/tests/browser/browser_navigateEvents.js index f8652f197ea7..80b9d3fa661a 100644 --- a/devtools/server/tests/browser/browser_navigateEvents.js +++ b/devtools/server/tests/browser/browser_navigateEvents.js @@ -66,16 +66,14 @@ function assertEvent(event, data) { } function waitForOnBeforeUnloadDialog(browser, callback) { - browser.addEventListener("DOMWillOpenModalDialog", function onModalDialog() { - browser.removeEventListener("DOMWillOpenModalDialog", onModalDialog, true); - + browser.addEventListener("DOMWillOpenModalDialog", function () { executeSoon(() => { let stack = browser.parentNode; let dialogs = stack.getElementsByTagName("tabmodalprompt"); let {button0, button1} = dialogs[0].ui; callback(button0, button1); }); - }, true); + }, {capture: true, once: true}); } var httpObserver = function (subject, topic, state) { diff --git a/devtools/server/tests/browser/browser_webextension_inspected_window.js b/devtools/server/tests/browser/browser_webextension_inspected_window.js index 1a21e08fb4fb..ae42e828e81c 100644 --- a/devtools/server/tests/browser/browser_webextension_inspected_window.js +++ b/devtools/server/tests/browser/browser_webextension_inspected_window.js @@ -62,12 +62,11 @@ function consoleEvalJS(consoleClient, jsCode) { // Script used as the injectedScript option in the inspectedWindow.reload tests. function injectedScript() { if (!window.pageScriptExecutedFirst) { - window.addEventListener("DOMContentLoaded", function listener() { - window.removeEventListener("DOMContentLoaded", listener); + window.addEventListener("DOMContentLoaded", function () { if (document.querySelector("pre")) { document.querySelector("pre").textContent = "injected script executed first"; } - }); + }, {once: true}); } } diff --git a/devtools/shared/heapsnapshot/tests/mochitest/test_saveHeapSnapshot_e10s_01.html b/devtools/shared/heapsnapshot/tests/mochitest/test_saveHeapSnapshot_e10s_01.html index 15f88f8e01be..3dd067988147 100644 --- a/devtools/shared/heapsnapshot/tests/mochitest/test_saveHeapSnapshot_e10s_01.html +++ b/devtools/shared/heapsnapshot/tests/mochitest/test_saveHeapSnapshot_e10s_01.html @@ -51,8 +51,7 @@ Bug 1201597 - Sanity test that we can take a heap snapshot in an e10s child proc iframe.src = childFrameURL; - iframe.addEventListener("mozbrowserloadend", function onLoadEnd() { - iframe.removeEventListener("mozbrowserloadend", onLoadEnd); + iframe.addEventListener("mozbrowserloadend", function () { info("iframe done loading"); var mm = SpecialPowers.getBrowserFrameMessageManager(iframe); @@ -72,7 +71,7 @@ Bug 1201597 - Sanity test that we can take a heap snapshot in an e10s child proc info("Loading frame script to save heap snapshot"); mm.loadFrameScript("data:,(" + encodeURI(childFrameScript.toString()) + ")();", false); - }); + }, {once: true}); info("Loading iframe"); document.body.appendChild(iframe); diff --git a/devtools/shared/security/prompt.js b/devtools/shared/security/prompt.js index b19cd515e17c..912634b2efca 100644 --- a/devtools/shared/security/prompt.js +++ b/devtools/shared/security/prompt.js @@ -64,15 +64,14 @@ Client.defaultSendOOB = ({ authResult, oob }) => { onOpenWindow(xulWindow) { let win = xulWindow.QueryInterface(Ci.nsIInterfaceRequestor) .getInterface(Ci.nsIDOMWindow); - win.addEventListener("load", function listener() { - win.removeEventListener("load", listener); + win.addEventListener("load", function () { if (win.document.documentElement.getAttribute("id") != "commonDialog") { return; } // Found the window promptWindow = win; Services.wm.removeListener(windowListener); - }); + }, {once: true}); }, onCloseWindow() {}, onWindowTitleChange() {} diff --git a/devtools/shared/webconsole/test/common.js b/devtools/shared/webconsole/test/common.js index c0cb629364ba..e2f604a55ede 100644 --- a/devtools/shared/webconsole/test/common.js +++ b/devtools/shared/webconsole/test/common.js @@ -100,8 +100,7 @@ function _attachConsole(aListeners, aCallback, aAttachToTab, aAttachToWorker) // Keep a strong reference to the Worker to avoid it being // GCd during the test (bug 1237492). aState._worker_ref = worker; - worker.addEventListener("message", function listener() { - worker.removeEventListener("message", listener); + worker.addEventListener("message", function () { tabClient.listWorkers(function (response) { let worker = response.workers.filter(w => w.url == workerName)[0]; if (!worker) { @@ -122,7 +121,7 @@ function _attachConsole(aListeners, aCallback, aAttachToTab, aAttachToWorker) }); }); }); - }); + }, {once: true}); } else { aState.actor = tab.consoleActor; aState.dbgClient.attachConsole(tab.consoleActor, aListeners, diff --git a/devtools/shared/webconsole/test/test_console_serviceworker_cached.html b/devtools/shared/webconsole/test/test_console_serviceworker_cached.html index 5aab64d7ff96..8cf8a3abf5cb 100644 --- a/devtools/shared/webconsole/test/test_console_serviceworker_cached.html +++ b/devtools/shared/webconsole/test/test_console_serviceworker_cached.html @@ -104,11 +104,10 @@ function addTab(url) { info("Adding a new tab with URL: '" + url + "'"); return new Promise(resolve => { let tab = gBrowser.selectedTab = gBrowser.addTab(url); - gBrowser.selectedBrowser.addEventListener("load", function onload() { - gBrowser.selectedBrowser.removeEventListener("load", onload, true); + gBrowser.selectedBrowser.addEventListener("load", function () { info("URL '" + url + "' loading complete"); resolve(tab); - }, true); + }, {capture: true, once: true}); }); } diff --git a/docshell/test/browser/browser_bug554155.js b/docshell/test/browser/browser_bug554155.js index eb0a8873b8a0..3ce511b006af 100644 --- a/docshell/test/browser/browser_bug554155.js +++ b/docshell/test/browser/browser_bug554155.js @@ -4,8 +4,6 @@ function test() { let tab = gBrowser.addTab("http://example.com"); tab.linkedBrowser.addEventListener("load", function() { - tab.linkedBrowser.removeEventListener("load", arguments.callee, true); - let numLocationChanges = 0; let listener = { @@ -29,5 +27,5 @@ function test() { finish(); }); - }, true); + }, {capture: true, once: true}); } diff --git a/docshell/test/browser/browser_grouped_shistory_bfcache_cleaning.js b/docshell/test/browser/browser_grouped_shistory_bfcache_cleaning.js index e85791b87ba6..79c8d2c6be8b 100644 --- a/docshell/test/browser/browser_grouped_shistory_bfcache_cleaning.js +++ b/docshell/test/browser/browser_grouped_shistory_bfcache_cleaning.js @@ -6,11 +6,10 @@ add_task(function* () { // Wait for a process change and then fulfil the promise. function awaitProcessChange(browser) { return new Promise(resolve => { - browser.addEventListener("BrowserChangedProcess", function bcp(e) { - browser.removeEventListener("BrowserChangedProcess", bcp); + browser.addEventListener("BrowserChangedProcess", function(e) { ok(true, "The browser changed process!"); resolve(); - }); + }, {once: true}); }); } @@ -47,11 +46,10 @@ add_task(function* () { // The 4th navigation should kill the frameloader browser1.loadURI("data:text/html,f", null, null); yield new Promise(resolve => { - tab2.addEventListener("TabClose", function f() { - tab2.removeEventListener("TabClose", f); + tab2.addEventListener("TabClose", function() { ok(true, "The tab is being closed!\n"); resolve(); - }); + }, {once: true}); }); // We don't check for !isAlive() as TabClose is called during // _beginRemoveTab, which means that the frameloader may not be dead yet. We diff --git a/docshell/test/browser/browser_grouped_shistory_crossproc.js b/docshell/test/browser/browser_grouped_shistory_crossproc.js index 9f040b681350..ab212bfc181b 100644 --- a/docshell/test/browser/browser_grouped_shistory_crossproc.js +++ b/docshell/test/browser/browser_grouped_shistory_crossproc.js @@ -6,22 +6,20 @@ add_task(function* () { // Wait for a process change and then fulfil the promise. function awaitProcessChange(browser) { return new Promise(resolve => { - browser.addEventListener("BrowserChangedProcess", function bcp(e) { - browser.removeEventListener("BrowserChangedProcess", bcp); + browser.addEventListener("BrowserChangedProcess", function(e) { ok(true, "The browser changed process!"); resolve(); - }); + }, {once: true}); }); } // Wait for the given tab being closed. function awaitTabClose(tab) { return new Promise(resolve => { - tab.addEventListener("TabClose", function f() { - tab.removeEventListener("TabClose", f); + tab.addEventListener("TabClose", function() { ok(true, "The tab is being closed!\n"); resolve(); - }); + }, {once: true}); }); } diff --git a/docshell/test/browser/browser_grouped_shistory_dead_navigate.js b/docshell/test/browser/browser_grouped_shistory_dead_navigate.js index 467f5ba825f6..691ca70b5314 100644 --- a/docshell/test/browser/browser_grouped_shistory_dead_navigate.js +++ b/docshell/test/browser/browser_grouped_shistory_dead_navigate.js @@ -7,11 +7,10 @@ add_task(function* () { // Wait for a process change and then fulfil the promise. function awaitProcessChange(browser) { return new Promise(resolve => { - browser.addEventListener("BrowserChangedProcess", function bcp(e) { - browser.removeEventListener("BrowserChangedProcess", bcp); + browser.addEventListener("BrowserChangedProcess", function(e) { ok(true, "The browser changed process!"); resolve(); - }); + }, {once: true}); }); } diff --git a/docshell/test/browser/head.js b/docshell/test/browser/head.js index 24ca8f45b395..0337d067f64a 100644 --- a/docshell/test/browser/head.js +++ b/docshell/test/browser/head.js @@ -42,20 +42,18 @@ function timelineTestOpenUrl(url) { window.focus(); let tabSwitchPromise = new Promise((resolve, reject) => { - window.gBrowser.addEventListener("TabSwitchDone", function listener() { - window.gBrowser.removeEventListener("TabSwitchDone", listener); + window.gBrowser.addEventListener("TabSwitchDone", function() { resolve(); - }); + }, {once: true}); }); let loadPromise = new Promise(function(resolve, reject) { let tab = window.gBrowser.selectedTab = window.gBrowser.addTab(url); let linkedBrowser = tab.linkedBrowser; - linkedBrowser.addEventListener("load", function onload() { - linkedBrowser.removeEventListener("load", onload, true); + linkedBrowser.addEventListener("load", function() { resolve(tab); - }, true); + }, {capture: true, once: true}); }); return Promise.all([tabSwitchPromise, loadPromise]).then(([_, tab]) => tab); diff --git a/docshell/test/chrome/test_private_hidden_window.html b/docshell/test/chrome/test_private_hidden_window.html index 6592d4d13c10..534152776545 100644 --- a/docshell/test/chrome/test_private_hidden_window.html +++ b/docshell/test/chrome/test_private_hidden_window.html @@ -51,11 +51,10 @@ function onHiddenPrivateWindowReady() { hidden.document.body.appendChild(iframe); var win = mainWindow.OpenBrowserWindow({private: true}); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); + win.addEventListener("load", function() { win.close(); win = null; - }); + }, {once: true}); } function observer(aSubject, aTopic, aData) { diff --git a/docshell/test/navigation/test_bug430723.html b/docshell/test/navigation/test_bug430723.html index eb53e0d220d5..49c534fa727e 100644 --- a/docshell/test/navigation/test_bug430723.html +++ b/docshell/test/navigation/test_bug430723.html @@ -65,22 +65,20 @@ var step1 =function() { is(testWindow.document.body.scrollTop, 0, "Page1: Ensure the scrollpane is at the top before we start scrolling."); testWindow.addEventListener("scroll", function () { - testWindow.removeEventListener("scroll", arguments.callee, true); isnot(testWindow.document.body.scrollTop, 0, "Page1: Ensure we can scroll down."); SimpleTest.executeSoon(step1_2); - }, true); + }, {capture: true, once: true}); sendKey('DOWN', testWindow); function step1_2() { testWindow.addEventListener("scroll", function () { - testWindow.removeEventListener("scroll", arguments.callee, true); is(testWindow.document.body.scrollTop, 0, "Page1: Ensure we can scroll up, back to the top."); // Nav to blue box page. This should fire step2. testWindow.location = gTallBlueBoxURI; - }, true); + }, {capture: true, once: true}); sendKey('UP', testWindow); } } @@ -118,14 +116,12 @@ var step3 =function() { is(testWindow.document.body.scrollTop, 0, "Page1Again: Ensure scroll pane at top before we scroll."); testWindow.addEventListener("scroll", function () { - testWindow.removeEventListener("scroll", arguments.callee, true); - isnot(testWindow.document.body.scrollTop, 0, "Page2Again: Ensure we can still scroll."); testWindow.close(); window.SimpleTest.finish(); - }, true); + }, {capture: true, once: true}); sendKey('DOWN', testWindow); } diff --git a/dom/base/test/browser_bug1058164.js b/dom/base/test/browser_bug1058164.js index 1ee01ca4081e..9730d0d21162 100644 --- a/dom/base/test/browser_bug1058164.js +++ b/dom/base/test/browser_bug1058164.js @@ -90,10 +90,9 @@ add_task(function* test_swap_frameloader_pagevisibility_events() { // and tabs fast enough to attach the event handlers before they were // fired. yield new Promise((resolve) => { - emptyBrowser.addEventListener("pageshow", function onPageShow() { - emptyBrowser.removeEventListener("pageshow", onPageShow); + emptyBrowser.addEventListener("pageshow", function() { resolve(); - }); + }, {once: true}); }); // The empty tab we just added show now fire a pagehide as its replaced, diff --git a/dom/base/test/browser_bug593387.js b/dom/base/test/browser_bug593387.js index aa4f9dc0f7b6..a936276b1b74 100644 --- a/dom/base/test/browser_bug593387.js +++ b/dom/base/test/browser_bug593387.js @@ -31,15 +31,13 @@ function testXFOFrameInChrome(newBrowser) { var frame = newBrowser.contentDocument.createElement("iframe"); frame.src = "http://mochi.test:8888/tests/dom/base/test/file_x-frame-options_page.sjs?testid=deny&xfo=deny"; - frame.addEventListener("load", function loaded() { - frame.removeEventListener("load", loaded, true); - + frame.addEventListener("load", function() { // Test that the frame loaded var test = this.contentDocument.getElementById("test"); is(test.tagName, "H1", "wrong element type"); is(test.textContent, "deny", "wrong textContent"); deferred.resolve(); - }, true); + }, {capture: true, once: true}); newBrowser.contentDocument.body.appendChild(frame); return deferred.promise; @@ -55,15 +53,13 @@ function testXFOFrameInContent(newBrowser) { var frame = content.document.createElement("iframe"); frame.src = "http://mochi.test:8888/tests/dom/base/test/file_x-frame-options_page.sjs?testid=deny&xfo=deny"; - frame.addEventListener("load", function loaded() { - frame.removeEventListener("load", loaded, true); - + frame.addEventListener("load", function() { // Test that the frame DID NOT load var test = this.contentDocument.getElementById("test"); Assert.equal(test, null, "should be about:blank"); deferred.resolve(); - }, true); + }, {capture: true, once: true}); content.document.body.appendChild(frame); return deferred.promise; diff --git a/dom/base/test/browser_pagehide_on_tab_close.js b/dom/base/test/browser_pagehide_on_tab_close.js index 0da7617e16d2..cfc52f90df6c 100644 --- a/dom/base/test/browser_pagehide_on_tab_close.js +++ b/dom/base/test/browser_pagehide_on_tab_close.js @@ -4,14 +4,12 @@ function test() { var tab = gBrowser.addTab(); gBrowser.selectedTab = tab; - tab.linkedBrowser.addEventListener("load", function onload() { - tab.linkedBrowser.removeEventListener("load", onload); - + tab.linkedBrowser.addEventListener("load", function() { tab.linkedBrowser.addEventListener("pagehide", function() { ok(true, "got page hide event"); finish(); }); executeSoon(() => { gBrowser.removeTab(tab); }); - }, true); + }, {capture: true, once: true}); } diff --git a/dom/base/test/iframe_bug962251.html b/dom/base/test/iframe_bug962251.html index 1ecad0fd489a..2fa3a50dcf86 100644 --- a/dom/base/test/iframe_bug962251.html +++ b/dom/base/test/iframe_bug962251.html @@ -15,12 +15,11 @@ var finish = SimpleTest.finish.bind(SimpleTest); var input = document.getElementById("textinput"); - input.addEventListener("focus", function onFocus(aEvent) { - input.removeEventListener("focus", onFocus); + input.addEventListener("focus", function(aEvent) { is(aEvent.target.id, "textinput", "Input should be focused."); ok(aEvent.relatedTarget === null, "The relatedTarget should be null."); parent.postMessage("runNextTest", "*"); - }); + }, {once: true}); input.focus(); \ No newline at end of file diff --git a/dom/base/test/test_bug564863.xhtml b/dom/base/test/test_bug564863.xhtml index 9a2d9d676be0..87397499f6c5 100644 --- a/dom/base/test/test_bug564863.xhtml +++ b/dom/base/test/test_bug564863.xhtml @@ -259,14 +259,13 @@ is(div.id, "div_id", "div still has id set"); var mutateFired = false; root.appendChild(div); div.addEventListener("DOMAttrModified", function(e) { - div.removeEventListener("DOMAttrModified", arguments.callee); is(e.target, div, "target is div"); is(div.id, "", "div no longer has id"); is(div.getAttribute("id"), null, "div no longer has id attr"); removeNode(div); is(div.parentNode, null, "div was removed"); mutateFired = true; -}); +}, {once: true}); div.removeAttribute("id"); ok(mutateFired, "mutation event fired"); @@ -275,13 +274,12 @@ is(nsx.getAttribute("id"), "ns_id", "nsx still has id set"); mutateFired = false; root.appendChild(nsx); nsx.addEventListener("DOMAttrModified", function(e) { - nsx.removeEventListener("DOMAttrModified", arguments.callee); is(e.target, nsx, "target is nsx"); is(nsx.getAttribute("id"), null, "nsx no longer has id attr"); removeNode(nsx); is(nsx.parentNode, null, "nsx was removed"); mutateFired = true; -}); +}, {once: true}); nsx.removeAttribute("id"); ok(mutateFired, "mutation event fired"); @@ -295,12 +293,11 @@ root.appendChild(nsx); is($("ns_id"), nsx, "new nsx is set up"); mutateFired = false; nsx.addEventListener("DOMAttrModified", function(e) { - nsx.removeEventListener("DOMAttrModified", arguments.callee); is(e.target, nsx, "target is nsx"); is(nsx.getAttribute("id"), null, "nsx no longer has id attr"); nsx.setAttribute("id", "other_id"); mutateFired = true; -}); +}, {once: true}); nsx.removeAttribute("id"); ok(mutateFired, "mutation event fired"); is($("ns_id"), null, "ns_id was removed from table"); @@ -316,13 +313,12 @@ root.appendChild(div); is($("div_id"), div, "new div is set up"); mutateFired = false; div.addEventListener("DOMAttrModified", function(e) { - div.removeEventListener("DOMAttrModified", arguments.callee); is(e.target, div, "target is div"); is(div.getAttribute("id"), null, "div no longer has id attr"); is(div.id, "", "div no longer has id"); div.id = "other_div_id"; mutateFired = true; -}); +}, {once: true}); div.removeAttribute("id"); ok(mutateFired, "mutation event fired"); is($("div_id"), null, "div_id was removed from table"); @@ -338,13 +334,12 @@ root.appendChild(xul); is($("xul_id"), xul, "new xul is set up"); mutateFired = false; xul.addEventListener("DOMAttrModified", function(e) { - xul.removeEventListener("DOMAttrModified", arguments.callee); is(e.target, xul, "target is xul"); is(xul.getAttribute("id"), "", "xul no longer has id attr"); is(xul.id, "", "xul no longer has id"); xul.id = "other_xul_id"; mutateFired = true; -}); +}, {once: true}); xul.removeAttribute("id"); ok(mutateFired, "mutation event fired"); is($("xul_id"), null, "xul_id was removed from table"); diff --git a/dom/base/test/test_bug588990.html b/dom/base/test/test_bug588990.html index d4e0ca313b4c..ea7e69168354 100644 --- a/dom/base/test/test_bug588990.html +++ b/dom/base/test/test_bug588990.html @@ -263,14 +263,13 @@ is(i1_1.name, "n1", "i1_1 has name set"); var mutateFired = false; root.appendChild(i1_1); i1_1.addEventListener("DOMAttrModified", function(e) { - i1_1.removeEventListener("DOMAttrModified", arguments.callee); is(e.target, i1_1, "target is i1_1"); is(i1_1.name, "", "i1_1 no longer has name"); is(i1_1.getAttribute("name"), null, "i1_1 no longer has name attr"); removeNode(i1_1); is(i1_1.parentNode, null, "i1_1 was removed"); mutateFired = true; -}); +}, {once: true}); i1_1.removeAttribute("name"); ok(mutateFired, "mutation event fired"); SpecialPowers.gc(); @@ -280,14 +279,13 @@ i2_1.name = ""; mutateFired = false; root.appendChild(i2_1); i2_1.addEventListener("DOMAttrModified", function(e) { - i2_1.removeEventListener("DOMAttrModified", arguments.callee); is(e.target, i2_1, "target is i2_1"); is(i2_1.name, "n2", "i2_1 no longer has name"); is(i2_1.getAttribute("name"), "n2", "i2_1 no longer has name attr"); removeNode(i2_1); is(i2_1.parentNode, null, "i2_1 was removed"); mutateFired = true; -}); +}, {once: true}); i2_1.name = "n2"; ok(mutateFired, "mutation event fired"); SpecialPowers.gc(); @@ -298,13 +296,12 @@ root.appendChild(i2_2); mutateFired = false; root.appendChild(i2_2); i2_2.addEventListener("DOMAttrModified", function(e) { - i2_2.removeEventListener("DOMAttrModified", arguments.callee); is(e.target, i2_2, "target is i2_2"); is(i2_2.name, "", "i2_2 no longer has name"); is(i2_2.getAttribute("name"), "", "i2_2 has empty name attr"); i2_2.name = "n2"; mutateFired = true; -}); +}, {once: true}); i2_2.name = ""; ok(mutateFired, "mutation event fired"); is(document.n2, i2_2, "named was readded during mutation"); @@ -317,13 +314,12 @@ root.appendChild(i3_1); mutateFired = false; root.appendChild(i3_1); i3_1.addEventListener("DOMAttrModified", function(e) { - i3_1.removeEventListener("DOMAttrModified", arguments.callee); is(e.target, i3_1, "target is i3_1"); is(i3_1.name, "n3", "i3_1 no longer has name"); is(i3_1.getAttribute("name"), "n3", "i3_1 has empty name attr"); i3_1.removeAttribute("name"); mutateFired = true; -}); +}, {once: true}); i3_1.name = "n3"; ok(mutateFired, "mutation event fired"); is(document.n3, undefined, "named was readded during mutation"); diff --git a/dom/base/test/test_bug962251.html b/dom/base/test/test_bug962251.html index 8b870d899b41..6a95c22e02da 100644 --- a/dom/base/test/test_bug962251.html +++ b/dom/base/test/test_bug962251.html @@ -22,29 +22,26 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=962251 " not become the active element?"); var getBlurEvent = false; - button1.addEventListener("blur", function onBlur(aEvent) { - button1.removeEventListener("blur", onBlur); + button1.addEventListener("blur", function(aEvent) { is(aEvent.target.id, "button1", "Button1 should lose focus."); ok(aEvent.relatedTarget, "The relatedTarget should not be null."); is(aEvent.relatedTarget.id, "button2", "The relatedTarget should be button2."); getBlurEvent = true; - }); + }, {once: true}); - button2.addEventListener("focus", function onFocus(aEvent) { - button2.removeEventListener("focus", onFocus); + button2.addEventListener("focus", function(aEvent) { ok(getBlurEvent, "Must get blur event first."); is(aEvent.target.id, "button2", "Button2 should be focused."); ok(aEvent.relatedTarget, "The relatedTarget should not be null."); is(aEvent.relatedTarget.id, "button1", "The relatedTarget should be button1."); button2.blur(); - }); + }, {once: true}); - button2.addEventListener("blur", function onBlur(aEvent) { - button2.removeEventListener("blur", onBlur); + button2.addEventListener("blur", function(aEvent) { is(aEvent.target.id, "button2", "Button2 should lose focus."); ok(aEvent.relatedTarget === null, "The relatedTarget should be null."); runTests(); - }); + }, {once: true}); button2.focus(); } @@ -52,21 +49,19 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=962251 function Test_ElementsInDifferentDocument() { var button2 = document.getElementById("button2"); button2.focus(); - button2.addEventListener("blur", function onBlur(aEvent) { - button2.removeEventListener("blur", onBlur); + button2.addEventListener("blur", function(aEvent) { is(aEvent.target.id, "button2", "Button2 should lose focus."); ok(aEvent.relatedTarget === null, "The relatedTarget should be null, since it's in another document."); - }); + }, {once: true}); var iframe = document.createElement("iframe"); iframe.id = "iframe"; iframe.src = "iframe_bug962251.html"; - window.addEventListener("message", function onMessage(aEvent) { - window.removeEventListener("message", onMessage); + window.addEventListener("message", function(aEvent) { if (aEvent.data == "runNextTest") { runTests(); } - }); + }, {once: true}); document.getElementById("content").appendChild(iframe); } @@ -120,36 +115,30 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=962251 button1.focus(); is(button1.id, document.activeElement.id, "document.activeElement.id is button1"); - button1.addEventListener("blur", function onBlur(aEvent) { - button1.removeEventListener("blur", onBlur); + button1.addEventListener("blur", function(aEvent) { info("button1 blur"); is(aEvent.relatedTarget.id, button2.id, "relatedTarget.id should be button2."); button3.focus(); - }); - button1.addEventListener("focus", function onFocus(aEvent) { - button1.removeEventListener("focus", onFocus); + }, {once: true}); + button1.addEventListener("focus", function(aEvent) { info("button1 focus"); - }); + }, {once: true}); - button2.addEventListener("blur", function onBlur(aEvent) { - button2.removeEventListener("blur", onBlur); + button2.addEventListener("blur", function(aEvent) { info("button2 blur"); - }); - button2.addEventListener("focus", function onFocus(aEvent) { - button2.removeEventListener("focus", onFocus); + }, {once: true}); + button2.addEventListener("focus", function(aEvent) { info("button2 focus"); - }); + }, {once: true}); - button3.addEventListener("blur", function onBlur(aEvent) { - button3.removeEventListener("blur", onBlur); + button3.addEventListener("blur", function(aEvent) { info("button3 blur"); - }); - button3.addEventListener("focus", function onFocus(aEvent) { - button3.removeEventListener("focus", onFocus); + }, {once: true}); + button3.addEventListener("focus", function(aEvent) { info("button3 focus"); ok(aEvent.relatedTarget === null, "aEvent.relatedTarget is null."); runTests(); - }); + }, {once: true}); button2.focus(); } @@ -189,17 +178,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=962251 var input1 = iframe.contentDocument.getElementById("textinput1"); ok(iframe.contentDocument.activeElement === input, "Current focused element should be input."); - iframe.contentWindow.addEventListener("focus", function onFocus(aEvent) { - iframe.contentWindow.removeEventListener("focus", onFocus, true); + iframe.contentWindow.addEventListener("focus", function(aEvent) { ok(aEvent.target === input1, "Input1 is focused."); ok(aEvent.relatedTarget === input, "relatedTarget should be input."); runTests(); - }, true); - iframe.contentWindow.addEventListener("blur", function onBlur(aEvent) { - iframe.contentWindow.removeEventListener("blur", onBlur, true); + }, {capture: true, once: true}); + iframe.contentWindow.addEventListener("blur", function(aEvent) { ok(aEvent.target === input, "Input is not focused."); ok(aEvent.relatedTarget === input1, "relatedTarget should be input1."); - }, true); + }, {capture: true, once: true}); input1.focus(); } @@ -209,12 +196,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=962251 var input1 = iframe.contentDocument.getElementById("textinput1"); ok(iframe.contentDocument.activeElement === input1, "Current focused element should be input1."); - iframe.contentWindow.addEventListener("blur", function onBlur(aEvent) { - iframe.contentWindow.removeEventListener("blur", onBlur, true); + iframe.contentWindow.addEventListener("blur", function(aEvent) { ok(aEvent.target === input1, "Input1 is not focused."); ok(aEvent.relatedTarget === null, "relatedTarget should be null."); runTests(); - }, true); + }, {capture: true, once: true}); input1.blur(); } diff --git a/dom/base/test/test_bug976673.html b/dom/base/test/test_bug976673.html index 9ea358b112d4..372f857dd0e7 100644 --- a/dom/base/test/test_bug976673.html +++ b/dom/base/test/test_bug976673.html @@ -41,7 +41,6 @@ function testSetFocus(aEventType, aCallback) iframe.contentWindow.focus(); window.addEventListener("message", function (aEvent) { - window.removeEventListener("message", arguments.callee); is(aEvent.data, "input-value: focus", description + " in the iframe should get focus"); @@ -63,7 +62,6 @@ function testSetFocus(aEventType, aCallback) synthesizeMouseAtCenter(button, {}); window.addEventListener("message", function (aEvent) { - window.removeEventListener("message", arguments.callee); if (movingFocus) { is(aEvent.data, "input-value: blur", description + " in the iframe should get blur"); @@ -75,10 +73,10 @@ function testSetFocus(aEventType, aCallback) } setTimeout(aCallback, 0); - }); + }, {once: true}); iframe.contentWindow.postMessage("check", "*"); - }); + }, {once: true}); iframe.contentWindow.postMessage("init", "*"); } diff --git a/dom/base/test/test_domwindowutils.html b/dom/base/test/test_domwindowutils.html index 218f510ffa38..6692df207916 100644 --- a/dom/base/test/test_domwindowutils.html +++ b/dom/base/test/test_domwindowutils.html @@ -17,8 +17,7 @@ function test_sendMouseEventDefaults() { var x = 1, y = 2, button = 1, clickCount = 2, modifiers = SpecialPowers.Ci.nsIDOMNSEvent.SHIFT_MASK; - window.addEventListener("mousedown", function listener(evt) { - window.removeEventListener("mousedown", listener); + window.addEventListener("mousedown", function(evt) { // Mandatory args // coordinates may change slightly due to rounding ok((evt.clientX <= x+2) && (evt.clientX >= x-2), "check x"); @@ -33,7 +32,7 @@ function test_sendMouseEventDefaults() { is(evt.isSynthesized, undefined, "check isSynthesized is undefined in content"); is(SpecialPowers.wrap(evt).isSynthesized, true, "check isSynthesized is true from chrome"); SimpleTest.executeSoon(next); - }); + }, {once: true}); // Only pass mandatory arguments and check default values utils.sendMouseEvent("mousedown", x, y, button, clickCount, modifiers); @@ -45,12 +44,11 @@ function test_sendMouseEventOptionals() { pressure = 0.5, source = SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_KEYBOARD; - window.addEventListener("mouseup", function listener(evt) { - window.removeEventListener("mouseup", listener); + window.addEventListener("mouseup", function(evt) { is(evt.mozInputSource, source, "explicit input source is valid"); is(SpecialPowers.wrap(evt).isSynthesized, false, "we can dispatch event that don't look synthesized"); SimpleTest.executeSoon(next); - }); + }, {once: true}); // Check explicit value for optional args utils.sendMouseEvent("mouseup", x, y, button, clickCount, modifiers, diff --git a/dom/broadcastchannel/tests/browser_private_browsing.js b/dom/broadcastchannel/tests/browser_private_browsing.js index 71cf6288581f..ebf6cc3e5d02 100644 --- a/dom/broadcastchannel/tests/browser_private_browsing.js +++ b/dom/broadcastchannel/tests/browser_private_browsing.js @@ -6,19 +6,17 @@ const URL = "http://mochi.test:8888/browser/dom/broadcastchannel/tests/blank.htm add_task(function*() { var win1 = OpenBrowserWindow({private: true}); var win1Promise = new win1.Promise(resolve => { - win1.addEventListener("load", function onLoad() { - win1.removeEventListener("load", onLoad); + win1.addEventListener("load", function() { resolve(); - }); + }, {once: true}); }); yield win1Promise; var win2 = OpenBrowserWindow({private: false}); var win2Promise = new win2.Promise(resolve => { - win2.addEventListener("load", function onLoad() { - win2.removeEventListener("load", onLoad); + win2.addEventListener("load", function() { resolve(); - }); + }, {once: true}); }); yield win2Promise; diff --git a/dom/browser-element/mochitest/browserElement_Alert.js b/dom/browser-element/mochitest/browserElement_Alert.js index 3c7c507205e8..2147f790f3b8 100644 --- a/dom/browser-element/mochitest/browserElement_Alert.js +++ b/dom/browser-element/mochitest/browserElement_Alert.js @@ -29,15 +29,13 @@ function runTest() { // Wait for the initial load to finish, then navigate the page, then wait // for that load to finish, then start test1. - iframe.addEventListener('mozbrowserloadend', function loadend() { - iframe.removeEventListener('mozbrowserloadend', loadend); + iframe.addEventListener('mozbrowserloadend', function() { iframe.src = browserElementTestHelpers.emptyPage1; - iframe.addEventListener('mozbrowserloadend', function loadend2() { - iframe.removeEventListener('mozbrowserloadend', loadend2); + iframe.addEventListener('mozbrowserloadend', function() { SimpleTest.executeSoon(test1); - }); - }); + }, {once: true}); + }, {once: true}); } diff --git a/dom/browser-element/mochitest/browserElement_Auth.js b/dom/browser-element/mochitest/browserElement_Auth.js index 8685cd08907e..c5cbaf31ef62 100644 --- a/dom/browser-element/mochitest/browserElement_Auth.js +++ b/dom/browser-element/mochitest/browserElement_Auth.js @@ -23,14 +23,13 @@ function runTest() { // Wait for the initial load to finish, then navigate the page, then start test // by loading SJS with http 401 response. - iframe.addEventListener('mozbrowserloadend', function loadend() { - iframe.removeEventListener('mozbrowserloadend', loadend); + iframe.addEventListener('mozbrowserloadend', function() { iframe.addEventListener('mozbrowserusernameandpasswordrequired', testHttpAuthCancel); SimpleTest.executeSoon(function() { // Use absolute path because we need to specify host. iframe.src = 'http://test/tests/dom/browser-element/mochitest/file_http_401_response.sjs'; }); - }); + }, {once: true}); } function testHttpAuthCancel(e) { @@ -38,8 +37,7 @@ function testHttpAuthCancel(e) { // Will cancel authentication, but prompt should not be shown again. Instead, // we will be led to fail message iframe.addEventListener("mozbrowserusernameandpasswordrequired", testFail); - iframe.addEventListener("mozbrowsertitlechange", function onTitleChange(e) { - iframe.removeEventListener("mozbrowsertitlechange", onTitleChange); + iframe.addEventListener("mozbrowsertitlechange", function(e) { iframe.removeEventListener("mozbrowserusernameandpasswordrequired", testFail); is(e.detail, 'http auth failed', 'expected authentication to fail'); iframe.addEventListener('mozbrowserusernameandpasswordrequired', testHttpAuth); @@ -47,7 +45,7 @@ function testHttpAuthCancel(e) { // Use absolute path because we need to specify host. iframe.src = 'http://test/tests/dom/browser-element/mochitest/file_http_401_response.sjs'; }); - }); + }, {once: true}); is(e.detail.realm, 'http_realm', 'expected realm matches'); is(e.detail.host, 'http://test', 'expected host matches'); @@ -67,12 +65,11 @@ function testHttpAuth(e) { // Will authenticate with correct password, prompt should not be // called again. iframe.addEventListener("mozbrowserusernameandpasswordrequired", testFail); - iframe.addEventListener("mozbrowsertitlechange", function onTitleChange(e) { - iframe.removeEventListener("mozbrowsertitlechange", onTitleChange); + iframe.addEventListener("mozbrowsertitlechange", function(e) { iframe.removeEventListener("mozbrowserusernameandpasswordrequired", testFail); is(e.detail, 'http auth success', 'expect authentication to succeed'); SimpleTest.executeSoon(testProxyAuth); - }); + }, {once: true}); is(e.detail.realm, 'http_realm', 'expected realm matches'); is(e.detail.host, 'http://test', 'expected host matches'); @@ -97,12 +94,11 @@ function testProxyAuth(e) { function onUserNameAndPasswordRequired(e) { iframe.removeEventListener("mozbrowserusernameandpasswordrequired", onUserNameAndPasswordRequired); - iframe.addEventListener("mozbrowsertitlechange", function onTitleChange(e) { - iframe.removeEventListener("mozbrowsertitlechange", onTitleChange); + iframe.addEventListener("mozbrowsertitlechange", function(e) { iframe.removeEventListener("mozbrowserusernameandpasswordrequired", testFail); is(e.detail, 'http auth success', 'expect authentication to succeed'); SimpleTest.executeSoon(testAuthJarNoInterfere); - }); + }, {once: true}); is(e.detail.realm, 'http_realm', 'expected realm matches'); is(e.detail.host, mozproxy, 'expected host matches'); @@ -181,12 +177,11 @@ function testAuthJarNoInterfere(e) { // Will authenticate with correct password, prompt should not be // called again. iframe.addEventListener("mozbrowserusernameandpasswordrequired", testFail); - iframe.addEventListener("mozbrowsertitlechange", function onTitleChange(e) { - iframe.removeEventListener("mozbrowsertitlechange", onTitleChange); + iframe.addEventListener("mozbrowsertitlechange", function(e) { iframe.removeEventListener("mozbrowserusernameandpasswordrequired", testFail); is(e.detail, 'http auth success', 'expected authentication success'); SimpleTest.executeSoon(testAuthJarInterfere); - }); + }, {once: true}); // Once more with feeling. Ensure that our new auth data doesn't interfere with this mozbrowser's // auth data. @@ -216,14 +211,13 @@ function testAuthJarInterfere(e) { } iframe.addEventListener("mozbrowserusernameandpasswordrequired", onUserNameAndPasswordRequired); - iframe.addEventListener("mozbrowsertitlechange", function onTitleChange(e) { - iframe.removeEventListener("mozbrowsertitlechange", onTitleChange); + iframe.addEventListener("mozbrowsertitlechange", function(e) { iframe.removeEventListener("mozbrowserusernameandpasswordrequired", onUserNameAndPasswordRequired); ok(gotusernamepasswordrequired, "Should have dispatched mozbrowserusernameandpasswordrequired event"); testFinish(); - }); + }, {once: true}); // Once more with feeling. Ensure that our new auth data interferes with this mozbrowser's // auth data. diff --git a/dom/browser-element/mochitest/browserElement_CopyPaste.js b/dom/browser-element/mochitest/browserElement_CopyPaste.js index b23feef590db..a91bd7277a99 100644 --- a/dom/browser-element/mochitest/browserElement_CopyPaste.js +++ b/dom/browser-element/mochitest/browserElement_CopyPaste.js @@ -60,9 +60,7 @@ function runTest() { gTextarea = document.createElement('textarea'); document.body.appendChild(gTextarea); - iframeOuter.addEventListener("mozbrowserloadend", function onloadend(e) { - iframeOuter.removeEventListener("mozbrowserloadend", onloadend); - + iframeOuter.addEventListener("mozbrowserloadend", function(e) { if (createEmbededFrame) { var contentWin = SpecialPowers.wrap(iframeOuter) .QueryInterface(SpecialPowers.Ci.nsIFrameLoaderOwner) @@ -72,17 +70,16 @@ function runTest() { iframeInner.setAttribute('mozbrowser', true); iframeInner.setAttribute('remote', 'false'); contentDoc.body.appendChild(iframeInner); - iframeInner.addEventListener("mozbrowserloadend", function onloadendinner(e) { - iframeInner.removeEventListener("mozbrowserloadend", onloadendinner); + iframeInner.addEventListener("mozbrowserloadend", function(e) { mm = SpecialPowers.getBrowserFrameMessageManager(iframeInner); dispatchTest(e); - }); + }, {once: true}); } else { iframeInner = iframeOuter; mm = SpecialPowers.getBrowserFrameMessageManager(iframeInner); dispatchTest(e); } - }); + }, {once: true}); } function doCommand(cmd) { @@ -97,11 +94,10 @@ function doCommand(cmd) { } function dispatchTest(e) { - iframeInner.addEventListener("mozbrowserloadend", function onloadend2(e) { - iframeInner.removeEventListener("mozbrowserloadend", onloadend2); + iframeInner.addEventListener("mozbrowserloadend", function(e) { iframeInner.focus(); SimpleTest.executeSoon(function() { testSelectAll(e); }); - }); + }, {once: true}); switch (state) { case 0: // test for textarea diff --git a/dom/browser-element/mochitest/browserElement_DataURI.js b/dom/browser-element/mochitest/browserElement_DataURI.js index f57f4566a936..0f67898d5190 100644 --- a/dom/browser-element/mochitest/browserElement_DataURI.js +++ b/dom/browser-element/mochitest/browserElement_DataURI.js @@ -12,11 +12,10 @@ function runTest() { var iframe1 = document.createElement('iframe'); iframe1.setAttribute('mozbrowser', 'true'); iframe1.id = 'iframe1'; - iframe1.addEventListener('mozbrowserloadend', function if1_loadend() { - iframe1.removeEventListener('mozbrowserloadend', if1_loadend); + iframe1.addEventListener('mozbrowserloadend', function() { ok(true, 'Got first loadend event.'); SimpleTest.executeSoon(runTest2); - }); + }, {once: true}); iframe1.src = browserElementTestHelpers.emptyPage1; document.body.appendChild(iframe1); diff --git a/dom/browser-element/mochitest/browserElement_ExecuteScript.js b/dom/browser-element/mochitest/browserElement_ExecuteScript.js index 901964999253..8e0c7457e6dc 100644 --- a/dom/browser-element/mochitest/browserElement_ExecuteScript.js +++ b/dom/browser-element/mochitest/browserElement_ExecuteScript.js @@ -28,10 +28,9 @@ function runTest() { ], function() { let iframe = document.createElement('iframe'); iframe.setAttribute('mozbrowser', 'true'); - iframe.addEventListener('mozbrowserloadend', function onload() { - iframe.removeEventListener('mozbrowserloadend', onload); + iframe.addEventListener('mozbrowserloadend', function() { onReady(iframe); - }); + }, {once: true}); iframe.src = url; document.body.appendChild(iframe); }); diff --git a/dom/browser-element/mochitest/browserElement_OpenNamed.js b/dom/browser-element/mochitest/browserElement_OpenNamed.js index aed5617e92ac..76387a839715 100644 --- a/dom/browser-element/mochitest/browserElement_OpenNamed.js +++ b/dom/browser-element/mochitest/browserElement_OpenNamed.js @@ -23,13 +23,11 @@ function runTest() { is(popupFrame.getAttribute('name'), 'OpenNamed'); // Called when file_browserElement_OpenNamed2.html loads into popupFrame. - popupFrame.addEventListener('mozbrowsershowmodalprompt', function promptlistener(e) { - popupFrame.removeEventListener('mozbrowsershowmodalprompt', promptlistener); - + popupFrame.addEventListener('mozbrowsershowmodalprompt', function(e) { ok(gotPopup, 'Got openwindow event before showmodalprompt event.'); is(e.detail.message, 'success: loaded'); SimpleTest.executeSoon(test2); - }); + }, {once: true}); document.body.appendChild(popupFrame); }); diff --git a/dom/browser-element/mochitest/browserElement_SetVisibleFrames2.js b/dom/browser-element/mochitest/browserElement_SetVisibleFrames2.js index cf841a4707b0..c9e1bc2bdfb2 100644 --- a/dom/browser-element/mochitest/browserElement_SetVisibleFrames2.js +++ b/dom/browser-element/mochitest/browserElement_SetVisibleFrames2.js @@ -17,11 +17,10 @@ function runTest() { // SetVisibleFrames.js for an explanation. iframe.remote = false; - iframe.addEventListener('mozbrowserloadend', function loadEnd(e) { - iframe.removeEventListener('mozbrowserloadend', loadEnd); + iframe.addEventListener('mozbrowserloadend', function(e) { iframe.setVisible(false); iframe.src = 'file_browserElement_SetVisibleFrames2_Outer.html'; - }); + }, {once: true}); iframe.addEventListener('mozbrowsershowmodalprompt', function(e) { if (e.detail.message == 'parent:finish') { diff --git a/dom/browser-element/mochitest/browserElement_getWebManifest.js b/dom/browser-element/mochitest/browserElement_getWebManifest.js index c2b8f96f35ec..4c69106bc7a5 100644 --- a/dom/browser-element/mochitest/browserElement_getWebManifest.js +++ b/dom/browser-element/mochitest/browserElement_getWebManifest.js @@ -46,8 +46,7 @@ function requestManifest(url) { iframe.src = url; document.body.appendChild(iframe); return new Promise((resolve, reject) => { - iframe.addEventListener('mozbrowserloadend', function loadend() { - iframe.removeEventListener('mozbrowserloadend', loadend); + iframe.addEventListener('mozbrowserloadend', function() { SimpleTest.executeSoon(() => { var req = iframe.getWebManifest(); req.onsuccess = () => { @@ -59,6 +58,6 @@ function requestManifest(url) { reject(new Error(req.error)); }; }); - }); + }, {once: true}); }); } diff --git a/dom/browser-element/mochitest/file_browserElement_XFrameOptionsAllowFrom.html b/dom/browser-element/mochitest/file_browserElement_XFrameOptionsAllowFrom.html index 12a6fd31ede6..84126f3f3ae2 100644 --- a/dom/browser-element/mochitest/file_browserElement_XFrameOptionsAllowFrom.html +++ b/dom/browser-element/mochitest/file_browserElement_XFrameOptionsAllowFrom.html @@ -20,20 +20,18 @@ var iframe2 = document.createElement('iframe'); iframe2.height = '300px'; document.body.appendChild(iframe1); -iframe1.addEventListener('load', function iframe1Load() { - iframe1.removeEventListener('load', iframe1Load); +iframe1.addEventListener('load', function() { // This causes our embedder to take a screenshot (and blocks until the // screenshot is completed). var iframe2Loaded = false; - iframe2.addEventListener('load', function iframe2Load() { - iframe2.removeEventListener('load', iframe2Load); + iframe2.addEventListener('load', function() { iframe2Loaded = true; alert('finish'); - }); + }, {once: true}); document.body.appendChild(iframe2); iframe2.src = frame_src; -}); +}, {once: true}); iframe1.src = frame_src + '?iframe1'; diff --git a/dom/browser-element/mochitest/file_browserElement_XFrameOptionsDeny.html b/dom/browser-element/mochitest/file_browserElement_XFrameOptionsDeny.html index 338275aa3330..02862324a0b6 100644 --- a/dom/browser-element/mochitest/file_browserElement_XFrameOptionsDeny.html +++ b/dom/browser-element/mochitest/file_browserElement_XFrameOptionsDeny.html @@ -24,18 +24,16 @@ alert('step 1'); // Wait for both iframes to load. var iframe1Loaded = false; -iframe1.addEventListener('load', function iframe1Load() { - iframe1.removeEventListener('load', iframe1Load); +iframe1.addEventListener('load', function() { iframe1Loaded = true; waitForBothLoads(); -}); +}, {once: true}); var iframe2Loaded = false; -iframe2.addEventListener('load', function iframe2Load() { - iframe2.removeEventListener('load', iframe2Load); +iframe2.addEventListener('load', function() { iframe2Loaded = true; waitForBothLoads(); -}); +}, {once: true}); function waitForBothLoads() { if (iframe1Loaded && iframe2Loaded) { diff --git a/dom/browser-element/mochitest/priority/test_HighPriority.html b/dom/browser-element/mochitest/priority/test_HighPriority.html index d3396d65b6d6..68fa6cdac4c1 100644 --- a/dom/browser-element/mochitest/priority/test_HighPriority.html +++ b/dom/browser-element/mochitest/priority/test_HighPriority.html @@ -91,10 +91,9 @@ function runTest() { return Promise.all([ new Promise(function(resolve, reject) { - iframe.addEventListener('mozbrowsershowmodalprompt', function check(e) { - iframe.removeEventListener('mozbrowsershowmodalprompt', check); + iframe.addEventListener('mozbrowsershowmodalprompt', function(e) { resolve(checkAlertInfo(e)); - }); + }, {once: true}); }), expectPriorityChange(childID, priority).then(checkGracePeriod) ]).then(function(results) { diff --git a/dom/crypto/test/test_indexedDB.html b/dom/crypto/test/test_indexedDB.html index 630c16e0e875..5fe5c150b23c 100644 --- a/dom/crypto/test/test_indexedDB.html +++ b/dom/crypto/test/test_indexedDB.html @@ -25,10 +25,9 @@ SpecialPowers.wrap(frame).mozbrowser = true; frame.src = TEST_URI; - frame.addEventListener("mozbrowsershowmodalprompt", function onPrompt(e) { - frame.removeEventListener("mozbrowsershowmodalprompt", onPrompt); + frame.addEventListener("mozbrowsershowmodalprompt", function(e) { cb(frame, e.detail.message); - }); + }, {once: true}); document.body.appendChild(frame); } diff --git a/dom/events/test/pointerevents/mochitest_support_external.js b/dom/events/test/pointerevents/mochitest_support_external.js index 0d7350852d11..39d150cf5857 100644 --- a/dom/events/test/pointerevents/mochitest_support_external.js +++ b/dom/events/test/pointerevents/mochitest_support_external.js @@ -200,14 +200,13 @@ function runTestInNewWindow(aFile) { // We start testing when receiving load event. Inject the mochitest helper js // to the test case after DOM elements are constructed and before the load // event is fired. - testWindow.addEventListener("DOMContentLoaded", function scriptInjector() { - testWindow.removeEventListener("DOMContentLoaded", scriptInjector); + testWindow.addEventListener("DOMContentLoaded", function() { const PARENT_ORIGIN = "http://mochi.test:8888/"; var e = testWindow.document.createElement('script'); e.type = 'text/javascript'; e.src = "mochitest_support_internal.js"; testWindow.document.getElementsByTagName('head')[0].appendChild(e); - }); + }, {once: true}); window.addEventListener("message", function(aEvent) { switch(aEvent.data.type) { diff --git a/dom/events/test/test_bug1128787-1.html b/dom/events/test/test_bug1128787-1.html index 947bace3865a..ae9ebf64165c 100644 --- a/dom/events/test/test_bug1128787-1.html +++ b/dom/events/test/test_bug1128787-1.html @@ -18,7 +18,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1128787 var blurEventFired = false; var input = document.getElementsByTagName("input")[0]; input.addEventListener("blur", function (aEvent) { - input.removeEventListener("blur", arguments.callee); ok(true, "input element gets blur event correctly"); var utils = SpecialPowers.getDOMWindowUtils(window); @@ -32,7 +31,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1128787 SimpleTest.finish(); }); - }); + }, {once: true}); document.designMode = "on"; } diff --git a/dom/events/test/test_bug1128787-2.html b/dom/events/test/test_bug1128787-2.html index 3e2a6cadaa1d..e4e80479807f 100644 --- a/dom/events/test/test_bug1128787-2.html +++ b/dom/events/test/test_bug1128787-2.html @@ -18,7 +18,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1128787 var blurEventFired = false; var input = document.getElementsByTagName("input")[0]; input.addEventListener("blur", function (aEvent) { - input.removeEventListener("blur", arguments.callee); ok(true, "input element gets blur event correctly"); var utils = SpecialPowers.getDOMWindowUtils(window); @@ -32,7 +31,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1128787 SimpleTest.finish(); }); - }); + }, {once: true}); document.designMode = "on"; } diff --git a/dom/events/test/test_bug1128787-3.html b/dom/events/test/test_bug1128787-3.html index a7b86cdb6749..1ac2c8e5adf5 100644 --- a/dom/events/test/test_bug1128787-3.html +++ b/dom/events/test/test_bug1128787-3.html @@ -18,7 +18,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1128787 var blurEventFired = false; var input = document.getElementsByTagName("input")[0]; input.addEventListener("blur", function (aEvent) { - input.removeEventListener("blur", arguments.callee); ok(true, "input element gets blur event correctly"); var utils = SpecialPowers.getDOMWindowUtils(window); @@ -32,7 +31,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1128787 todo_is(utils.IMEStatus, utils.IME_STATUS_DISABLED, "IME should be disabled"); SimpleTest.finish(); - }); + }, {once: true}); document.designMode = "on"; } diff --git a/dom/events/test/test_bug534833.html b/dom/events/test/test_bug534833.html index 39d0907bb46e..3848b6721b5f 100644 --- a/dom/events/test/test_bug534833.html +++ b/dom/events/test/test_bug534833.html @@ -62,9 +62,8 @@ function nextTest() { var el = document.getElementById("initialfocus"); el.addEventListener("focus", function() { - el.removeEventListener("focus", arguments.callee); setTimeout(nextTest_, 0); - }); + }, {once: true}); el.focus(); } diff --git a/dom/events/test/test_bug822898.html b/dom/events/test/test_bug822898.html index a4d20a537b4f..12531a1c2962 100644 --- a/dom/events/test/test_bug822898.html +++ b/dom/events/test/test_bug822898.html @@ -93,9 +93,8 @@ function testDefaultArg() { let event = getDefaultArgEvent("pointerdown"); testTarget.addEventListener("pointerdown", function(ev) { - testTarget.removeEventListener("pointerdown", arguments.callee); is(ev.pointerId, 0, "Correct default pointerId"); - }); + }, {once: true}); testTarget.dispatchEvent(event); nextTest(); @@ -111,18 +110,16 @@ function testStopPropagation() { // Capturing phase let captured = false; parent.addEventListener("pointerdown", function() { - parent.removeEventListener("pointerdown", arguments.callee, true); captured = true; - }, true); // Capturing phase + }, {capture: true, once: true}); // Capturing phase // Bubbling phase parent.addEventListener("pointerdown", unreachableListener); testTarget.addEventListener("pointerdown", function(ev) { - testTarget.removeEventListener("pointerdown", arguments.callee); is(captured, true, "Event should have been captured"); ev.stopPropagation(); - }); + }, {once: true}); testTarget.dispatchEvent(event); @@ -135,15 +132,13 @@ function testPreventDefault() { let event = getDefaultArgEvent("pointerdown"); parent.addEventListener("pointerdown", function(ev) { - parent.removeEventListener("pointerdown", arguments.callee); is(ev.defaultPrevented, true, "preventDefault can be called"); nextTest(); - }); + }, {once: true}); testTarget.addEventListener("pointerdown", function(ev) { - testTarget.removeEventListener("pointerdown", arguments.callee); ev.preventDefault(); - }); + }, {once: true}); testTarget.dispatchEvent(event); } @@ -157,15 +152,13 @@ function testBlockPreventDefault() { }); parent.addEventListener("pointerdown", function(ev) { - parent.removeEventListener("pointerdown", arguments.callee); is(ev.defaultPrevented, false, "aCancelableArg works"); nextTest(); - }); + }, {once: true}); testTarget.addEventListener("pointerdown", function(ev) { - testTarget.removeEventListener("pointerdown", arguments.callee); ev.preventDefault(); - }); + }, {once: true}); testTarget.dispatchEvent(event); } diff --git a/dom/events/test/test_bug930374-chrome.html b/dom/events/test/test_bug930374-chrome.html index 5375d377196b..d9bae55347e0 100644 --- a/dom/events/test/test_bug930374-chrome.html +++ b/dom/events/test/test_bug930374-chrome.html @@ -36,7 +36,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=930374 input.focus(); input.addEventListener("input", function (aEvent) { - input.removeEventListener("input", arguments.callee); ok(gKeyPress, "Test1: keypress event must be fired before an input event"); ok(gKeyPress.defaultPrevented, @@ -46,7 +45,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=930374 "Test2: keypress event's defaultPrevented should be true after event dispatching finished"); SimpleTest.finish(); }, 0); - }); + }, {once: true}); sendChar("a"); } diff --git a/dom/events/test/test_bug930374-content.html b/dom/events/test/test_bug930374-content.html index 2ed4f9126692..74f23b1e7f75 100644 --- a/dom/events/test/test_bug930374-content.html +++ b/dom/events/test/test_bug930374-content.html @@ -36,7 +36,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=930374 input.focus(); input.addEventListener("input", function (aEvent) { - input.removeEventListener("input", arguments.callee); ok(gKeyPress, "Test1: keypress event must be fired before an input event"); ok(!gKeyPress.defaultPrevented, @@ -44,13 +43,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=930374 gKeyPress.preventDefault(); ok(gKeyPress.defaultPrevented, "Test1: keypress event's defaultPrevented should become true because of a call of preventDefault()"); - }); + }, {once: true}); sendChar("a"); gKeyPress = null; input.addEventListener("input", function (aEvent) { - input.removeEventListener("input", arguments.callee); ok(gKeyPress, "Test2: keypress event must be fired before an input event"); ok(!gKeyPress.defaultPrevented, @@ -60,7 +58,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=930374 "Test2: keypress event's defaultPrevented should not become true after event dispatching finished"); SimpleTest.finish(); }, 0); - }); + }, {once: true}); sendChar("b"); } diff --git a/dom/events/test/test_error_events.html b/dom/events/test/test_error_events.html index 62cbb68dea4e..51a19506b81d 100644 --- a/dom/events/test/test_error_events.html +++ b/dom/events/test/test_error_events.html @@ -12,10 +12,9 @@ var msg; var column; var error; - window.addEventListener("error", function errorListener(e) { - window.removeEventListener("error", errorListener); + window.addEventListener("error", function(e) { errorEvent = e; - }); + }, {once: true}); var oldOnerror = window.onerror; window.onerror = function(message, filename, lineno, columnno, errorObject) { window.onerror = oldOnerror; diff --git a/dom/filesystem/compat/tests/test_formSubmission.html b/dom/filesystem/compat/tests/test_formSubmission.html index cca2aeb194aa..9fa22bea5353 100644 --- a/dom/filesystem/compat/tests/test_formSubmission.html +++ b/dom/filesystem/compat/tests/test_formSubmission.html @@ -55,10 +55,9 @@ function populate_entries(webkitDirectory) { var script = SpecialPowers.loadChromeScript(url); function onOpened(message) { - input.addEventListener("change", function onChange() { - input.removeEventListener("change", onChange); + input.addEventListener("change", function() { next(); - }); + }, {once: true}); SpecialPowers.wrap(input).mozSetDndFilesAndDirectories([message.data[0]]); script.destroy(); diff --git a/dom/filesystem/tests/test_webkitdirectory.html b/dom/filesystem/tests/test_webkitdirectory.html index 825f5e8fbaf4..5f81f6221c06 100644 --- a/dom/filesystem/tests/test_webkitdirectory.html +++ b/dom/filesystem/tests/test_webkitdirectory.html @@ -26,12 +26,11 @@ function populateInputFile(aInputFile) { var input = document.getElementById(aInputFile); input.setAttribute('data-name', message.name); - input.addEventListener('change', function change() { - input.removeEventListener('change', change); + input.addEventListener('change', function() { MockFilePicker.cleanup(); script.destroy(); next(); - }); + }, {once: true}); input.click(); } diff --git a/dom/html/test/file_fullscreen-navigation.html b/dom/html/test/file_fullscreen-navigation.html index 547f7c4990fc..e0420e89ffb1 100644 --- a/dom/html/test/file_fullscreen-navigation.html +++ b/dom/html/test/file_fullscreen-navigation.html @@ -31,11 +31,10 @@ function begin() { frameWin = document.getElementById("f").contentWindow; e1 = frameWin.document.body; - document.addEventListener("fullscreenchange", function onfullscreen() { - document.removeEventListener("fullscreenchange", onfullscreen); + document.addEventListener("fullscreenchange", function() { opener.ok(document.fullscreenElement, "[navigation] Request should be granted"); frameWin.location = "data:text/html,2"; - }); + }, {once: true}); e1.requestFullscreen(); } diff --git a/dom/html/test/forms/test_formaction_attribute.html b/dom/html/test/forms/test_formaction_attribute.html index e4138254176a..97b9b17ebb8e 100644 --- a/dom/html/test/forms/test_formaction_attribute.html +++ b/dom/html/test/forms/test_formaction_attribute.html @@ -111,51 +111,43 @@ function runTests() * Focusing the first element (id='is') is launching the tests. */ document.getElementById('is').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeMouse(document.getElementById('is'), 5, 5, {}); document.getElementById('ii').focus(); - }); + }, {once: true}); document.getElementById('ii').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeMouse(document.getElementById('ii'), 5, 5, {}); document.getElementById('bs').focus(); - }); + }, {once: true}); document.getElementById('bs').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeMouse(document.getElementById('bs'), 5, 5, {}); document.getElementById('bsbis').focus(); - }); + }, {once: true}); document.getElementById('bsbis').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); document.getElementById('bsbis').click(); document.getElementById('is2').focus(); - }); + }, {once: true}); document.getElementById('is2').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); document.getElementById('ii2').focus(); - }); + }, {once: true}); document.getElementById('ii2').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); document.getElementById('bs2').focus(); - }); + }, {once: true}); document.getElementById('bs2').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); document.getElementById('enter').focus(); - }); + }, {once: true}); document.getElementById('enter').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); - }); + }, {once: true}); document.getElementById('is').focus(); } diff --git a/dom/html/test/forms/test_meter_element.html b/dom/html/test/forms/test_meter_element.html index e6dcb015439b..ca98e054a512 100644 --- a/dom/html/test/forms/test_meter_element.html +++ b/dom/html/test/forms/test_meter_element.html @@ -312,19 +312,12 @@ function checkNotResetableAndFormSubmission(aElement) aElement.max = 100.0; document.getElementsByName('submit_frame')[0].addEventListener("load", function() { - document.getElementsByName('submit_frame')[0].removeEventListener("load", arguments.callee); - - /** - * All elements values have been set just before the submission. - * The input element value should be in the submit url but the meter - * element value should not appear. - */ is(frames['submit_frame'].location.href, 'http://mochi.test:8888/tests/dom/html/test/forms/foo?a=tulip', "The meter element value should not be submitted"); checkNotResetable(); - }); + }, {once: true}); form.submit(); } diff --git a/dom/html/test/forms/test_novalidate_attribute.html b/dom/html/test/forms/test_novalidate_attribute.html index 7ec5e7dba8be..4a5924e3ad0b 100644 --- a/dom/html/test/forms/test_novalidate_attribute.html +++ b/dom/html/test/forms/test_novalidate_attribute.html @@ -39,24 +39,21 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=556013 * be a problem. */ document.forms[0].addEventListener("submit", function(aEvent) { - aEvent.target.removeEventListener("submit", arguments.callee); ok(true, "novalidate has been correctly used for first form"); document.getElementById('b').click(); -}); +}, {once: true}); document.forms[1].addEventListener("submit", function(aEvent) { - aEvent.target.removeEventListener("submit", arguments.callee); ok(true, "novalidate has been correctly used for second form"); var c = document.getElementById('c'); c.focus(); synthesizeKey("KEY_Enter", { code: "Enter" }); -}); +}, {once: true}); document.forms[2].addEventListener("submit", function(aEvent) { - aEvent.target.removeEventListener("submit", arguments.callee); ok(true, "novalidate has been correctly used for third form"); SimpleTest.executeSoon(SimpleTest.finish); -}); +}, {once: true}); /** * We have to be sure invalid events are not send too. diff --git a/dom/html/test/forms/test_progress_element.html b/dom/html/test/forms/test_progress_element.html index 1756cd65b571..8099b6a2772a 100644 --- a/dom/html/test/forms/test_progress_element.html +++ b/dom/html/test/forms/test_progress_element.html @@ -247,19 +247,12 @@ function checkNotResetableAndFormSubmission(aElement) aElement.max = 100.0; document.getElementsByName('submit_frame')[0].addEventListener("load", function() { - document.getElementsByName('submit_frame')[0].removeEventListener("load", arguments.callee); - - /** - * All elements values have been set just before the submission. - * The input element value should be in the submit url but the progress - * element value should not appear. - */ is(frames['submit_frame'].location.href, 'http://mochi.test:8888/tests/dom/html/test/forms/foo?a=tulip', "The progress element value should not be submitted"); checkNotResetable(); - }); + }, {once: true}); form.submit(); } diff --git a/dom/html/test/forms/test_save_restore_radio_groups.html b/dom/html/test/forms/test_save_restore_radio_groups.html index 310b63dc12bb..21c3c2573b9f 100644 --- a/dom/html/test/forms/test_save_restore_radio_groups.html +++ b/dom/html/test/forms/test_save_restore_radio_groups.html @@ -51,18 +51,15 @@ addLoadEvent(function() { framesElts = document.getElementsByTagName('iframe'); framesElts[0].addEventListener("load", function() { - framesElts[0].removeEventListener("load", arguments.callee); checkRadioGroup(0, [false, false, true]); framesElts[1].addEventListener("load", function() { - framesElts[1].removeEventListener("load", arguments.callee); - checkRadioGroup(1, [false, true, false]); SimpleTest.finish(); - }); + }, {once: true}); frames[1].location.reload(); - }); + }, {once: true}); frames[0].location.reload(); }); diff --git a/dom/html/test/test_bug369370.html b/dom/html/test/test_bug369370.html index 6b27b38496bd..af91ae95fa58 100644 --- a/dom/html/test/test_bug369370.html +++ b/dom/html/test/test_bug369370.html @@ -102,15 +102,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=369370 // ========== test 6 ========== // Now try resizing the window so the image fits vertically. function test6() { - kidWin.addEventListener("resize", function resizeListener() { - kidWin.removeEventListener("resize", resizeListener); + kidWin.addEventListener("resize", function() { // Give the image document time to respond SimpleTest.executeSoon(function() { is(img.height, 600, "image height"); is(img.getBoundingClientRect().top, 25, "Image is vertically centered"); test7(); }); - }); + }, {once: true}); var decorationSize = kidWin.outerHeight - kidWin.innerHeight; kidWin.resizeTo(400, 600 + 50 + decorationSize); @@ -119,8 +118,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=369370 // ========== test 7 ========== // Now try resizing the window so the image no longer fits vertically. function test7() { - kidWin.addEventListener("resize", function resizeListener() { - kidWin.removeEventListener("resize", resizeListener); + kidWin.addEventListener("resize", function() { // Give the image document time to respond SimpleTest.executeSoon(function() { is(img.height, 600, "image height"); @@ -128,7 +126,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=369370 kidWin.close(); SimpleTest.finish(); }); - }); + }, {once: true}); var decorationSize = kidWin.outerHeight - kidWin.innerHeight; kidWin.resizeTo(400, 300 + decorationSize); diff --git a/dom/html/test/test_bug557087-1.html b/dom/html/test/test_bug557087-1.html index 10a26b9a5e8b..6f485a0e48c3 100644 --- a/dom/html/test/test_bug557087-1.html +++ b/dom/html/test/test_bug557087-1.html @@ -97,9 +97,8 @@ function checkClickEvent(aFieldset) aFieldset.disabled = true; aFieldset.addEventListener("click", function(aEvent) { - aEvent.target.removeEventListener("click", arguments.callee); clickHandled = true; - }); + }, {once: true}); sendMouseEvent({type:'click'}, aFieldset); SimpleTest.executeSoon(function() { diff --git a/dom/html/test/test_bug561636.html b/dom/html/test/test_bug561636.html index dedb64159dad..41eace42ac30 100644 --- a/dom/html/test/test_bug561636.html +++ b/dom/html/test/test_bug561636.html @@ -61,22 +61,18 @@ function runTest() // Initialize document.forms[0].addEventListener('submit', function(aEvent) { - aEvent.target.removeEventListener('submit', arguments.callee); formSubmitted[0] = true; - }); + }, {once: true}); document.forms[1].addEventListener('submit', function(aEvent) { - aEvent.target.removeEventListener('submit', arguments.callee); formSubmitted[1] = true; - }); + }, {once: true}); document.forms[2].addEventListener('submit', function(aEvent) { - aEvent.target.removeEventListener('submit', arguments.callee); formSubmitted[2] = true; - }); + }, {once: true}); document.forms[3].addEventListener('submit', function(aEvent) { - aEvent.target.removeEventListener('submit', arguments.callee); formSubmitted[3] = true; ok(!formSubmitted[0], "Form 1 should not have been submitted because invalid"); @@ -86,23 +82,20 @@ function runTest() // Next test. document.forms[4].submit(); - }); + }, {once: true}); document.forms[4].elements[0].addEventListener('invalid', function(aEvent) { - aEvent.target.removeEventListener('invalid', arguments.callee); invalidHandled = true; - }); + }, {once: true}); document.getElementById('i').addEventListener('load', function(aEvent) { - aEvent.target.removeEventListener('load', arguments.callee); - SimpleTest.executeSoon(function () { ok(true, "Form 5 should have been submitted because submit() has been used even if invalid"); ok(!invalidHandled, "Invalid event should not have been sent"); SimpleTest.finish(); }); - }); + }, {once: true}); document.getElementById('a').click(); document.getElementById('b').click(); diff --git a/dom/html/test/test_bug566046.html b/dom/html/test/test_bug566046.html index ae874683d408..88ea47f3ebf9 100644 --- a/dom/html/test/test_bug566046.html +++ b/dom/html/test/test_bug566046.html @@ -141,51 +141,43 @@ function runTests() * Focusing the first element (id='is') is launching the tests. */ document.getElementById('is').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeMouse(document.getElementById('is'), 5, 5, {}); document.getElementById('ii').focus(); - }); + }, {once: true}); document.getElementById('ii').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeMouse(document.getElementById('ii'), 5, 5, {}); document.getElementById('bs').focus(); - }); + }, {once: true}); document.getElementById('bs').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeMouse(document.getElementById('bs'), 5, 5, {}); document.getElementById('bsbis').focus(); - }); + }, {once: true}); document.getElementById('bsbis').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); document.getElementById('bsbis').click(); document.getElementById('is2').focus(); - }); + }, {once: true}); document.getElementById('is2').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); document.getElementById('ii2').focus(); - }); + }, {once: true}); document.getElementById('ii2').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); document.getElementById('bs2').focus(); - }); + }, {once: true}); document.getElementById('bs2').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); document.getElementById('enter').focus(); - }); + }, {once: true}); document.getElementById('enter').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); - }); + }, {once: true}); document.getElementById('is').focus(); } diff --git a/dom/html/test/test_bug567938-4.html b/dom/html/test/test_bug567938-4.html index dd32b7a1d248..96d6404f433e 100644 --- a/dom/html/test/test_bug567938-4.html +++ b/dom/html/test/test_bug567938-4.html @@ -28,12 +28,11 @@ function runTests() document.getElementById('i').checked = false; document.getElementById('i').addEventListener('click', function(aEvent) { - aEvent.target.removeEventListener('click', arguments.callee); SimpleTest.executeSoon(function() { ok(!aEvent.target.checked, "the input should not be checked"); SimpleTest.finish(); }); - }); + }, {once: true}); sendMouseEvent({type: 'click'}, 'i'); } diff --git a/dom/html/test/test_bug582412-1.html b/dom/html/test/test_bug582412-1.html index a82ef003ce85..172a3e4319b1 100644 --- a/dom/html/test/test_bug582412-1.html +++ b/dom/html/test/test_bug582412-1.html @@ -132,63 +132,53 @@ function runTests() * Focusing the first element (id='is') is launching the tests. */ document.getElementById('is').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeMouse(document.getElementById('is'), 5, 5, {}); document.getElementById('ii').focus(); - }); + }, {once: true}); document.getElementById('ii').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeMouse(document.getElementById('ii'), 5, 5, {}); document.getElementById('bs').focus(); - }); + }, {once: true}); document.getElementById('bs').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeMouse(document.getElementById('bs'), 5, 5, {}); document.getElementById('bsbis').focus(); - }); + }, {once: true}); document.getElementById('bsbis').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); document.getElementById('bsbis').click(); document.getElementById('is2').focus(); - }); + }, {once: true}); document.getElementById('is2').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); document.getElementById('ii2').focus(); - }); + }, {once: true}); document.getElementById('ii2').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); document.getElementById('bs2').focus(); - }); + }, {once: true}); document.getElementById('bs2').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); document.getElementById('enter').focus(); - }); + }, {once: true}); document.getElementById('enter').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); document.getElementById('i8').focus(); - }); + }, {once: true}); document.getElementById('i8').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); document.getElementById('i9').focus(); - }); + }, {once: true}); document.getElementById('i9').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); - }); + }, {once: true}); document.getElementById('is').focus(); } diff --git a/dom/html/test/test_bug582412-2.html b/dom/html/test/test_bug582412-2.html index 19b35ce4044f..c1160067628d 100644 --- a/dom/html/test/test_bug582412-2.html +++ b/dom/html/test/test_bug582412-2.html @@ -132,63 +132,53 @@ function runTests() * Focusing the first element (id='is') is launching the tests. */ document.getElementById('is').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeMouse(document.getElementById('is'), 5, 5, {}); document.getElementById('ii').focus(); - }); + }, {once: true}); document.getElementById('ii').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeMouse(document.getElementById('ii'), 5, 5, {}); document.getElementById('bs').focus(); - }); + }, {once: true}); document.getElementById('bs').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeMouse(document.getElementById('bs'), 5, 5, {}); document.getElementById('bsbis').focus(); - }); + }, {once: true}); document.getElementById('bsbis').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); document.getElementById('bsbis').click(); document.getElementById('is2').focus(); - }); + }, {once: true}); document.getElementById('is2').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); document.getElementById('ii2').focus(); - }); + }, {once: true}); document.getElementById('ii2').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); document.getElementById('bs2').focus(); - }); + }, {once: true}); document.getElementById('bs2').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); document.getElementById('enter').focus(); - }); + }, {once: true}); document.getElementById('enter').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); document.getElementById('i8').focus(); - }); + }, {once: true}); document.getElementById('i8').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); document.getElementById('i9').focus(); - }); + }, {once: true}); document.getElementById('i9').addEventListener('focus', function(aEvent) { - aEvent.target.removeEventListener('focus', arguments.callee); synthesizeKey("VK_RETURN", {}); - }); + }, {once: true}); document.getElementById('is').focus(); } diff --git a/dom/html/test/test_bug592802.html b/dom/html/test/test_bug592802.html index 55db115ff26e..3adc2260358f 100644 --- a/dom/html/test/test_bug592802.html +++ b/dom/html/test/test_bug592802.html @@ -54,9 +54,8 @@ SimpleTest.waitForFocus(function() { var b2 = document.getElementById('b2'); b2.focus(); // Be sure the element is visible. document.getElementById('b2').addEventListener("change", function(aEvent) { - aEvent.target.removeEventListener("change", arguments.callee); ok(false, "When cancel is received, change should not fire"); - }); + }, {once: true}); b2.click(); // Now, we can launch tests when file picker isn't canceled. diff --git a/dom/html/test/test_bug601030.html b/dom/html/test/test_bug601030.html index 44d59238c40c..c57a4772a048 100644 --- a/dom/html/test/test_bug601030.html +++ b/dom/html/test/test_bug601030.html @@ -25,7 +25,6 @@ addLoadEvent(function() { var content = document.getElementById('content'); f.addEventListener("load", function() { - f.removeEventListener("load", arguments.callee); SimpleTest.executeSoon(function() { isnot(document.activeElement, f, "autofocus should not work when another frame is inserted in the document"); @@ -34,15 +33,14 @@ addLoadEvent(function() { content.removeChild(document.getElementsByTagName('iframe')[0]); f = document.createElement('iframe'); f.addEventListener("load", function() { - f.removeEventListener("load", arguments.callee); isnot(document.activeElement, f, "autofocus should not work in a frame if the top document is already loaded"); SimpleTest.finish(); - }); + }, {once: true}); f.src = "data:text/html,"; content.appendChild(f); }); - }); + }, {once: true}); f.src = "data:text/html,"; content.appendChild(f); diff --git a/dom/html/test/test_bug612730.html b/dom/html/test/test_bug612730.html index 3ba647f1751d..0b196f3b3f7c 100644 --- a/dom/html/test/test_bug612730.html +++ b/dom/html/test/test_bug612730.html @@ -30,8 +30,6 @@ function runTest() var select = document.getElementsByTagName('select')[0]; select.addEventListener("focus", function() { - select.removeEventListener("focus", arguments.callee); - isnot(select.selectedIndex, -1, "Something should have been selected"); ok(!select.matches(":-moz-ui-invalid"), @@ -40,7 +38,7 @@ function runTest() ":-moz-ui-valid should not apply"); SimpleTest.finish(); - }); + }, {once: true}); synthesizeMouse(select, 5, 5, {}); } diff --git a/dom/html/test/test_bug615833.html b/dom/html/test/test_bug615833.html index 3dab409ff073..6d3177a195d1 100644 --- a/dom/html/test/test_bug615833.html +++ b/dom/html/test/test_bug615833.html @@ -53,97 +53,82 @@ function checkChangeEvent(aEvent) } selectMultiple.addEventListener("change", function(aEvent) { - selectMultiple.removeEventListener("change", arguments.callee); checkChangeEvent(aEvent); SimpleTest.finish(); -}); +}, {once: true}); selectMultiple.addEventListener("focus", function() { - selectMultiple.removeEventListener("focus", arguments.callee); SimpleTest.executeSoon(function () { synthesizeMouseAtCenter(selectMultiple, {}); }); -}); +}, {once: true}); select.addEventListener("change", function(aEvent) { - select.removeEventListener("change", arguments.callee); checkChangeEvent(aEvent); selectMultiple.focus(); -}); +}, {once: true}); select.addEventListener("keyup", function() { - select.removeEventListener("keyup", arguments.callee); select.blur(); -}); +}, {once: true}); select.addEventListener("focus", function() { - select.removeEventListener("focus", arguments.callee); SimpleTest.executeSoon(function () { synthesizeKey("VK_DOWN", {}); }); -}); +}, {once: true}); checkbox.addEventListener("change", function(aEvent) { - checkbox.removeEventListener("change", arguments.callee); checkChangeEvent(aEvent); select.focus(); -}); +}, {once: true}); checkbox.addEventListener("focus", function() { - checkbox.removeEventListener("focus", arguments.callee); SimpleTest.executeSoon(function () { synthesizeMouseAtCenter(checkbox, {}); }); -}); +}, {once: true}); radio.addEventListener("change", function(aEvent) { - radio.removeEventListener("change", arguments.callee); checkChangeEvent(aEvent); checkbox.focus(); -}); +}, {once: true}); radio.addEventListener("focus", function() { - radio.removeEventListener("focus", arguments.callee); SimpleTest.executeSoon(function () { synthesizeMouseAtCenter(radio, {}); }); -}); +}, {once: true}); textarea.addEventListener("change", function(aEvent) { - textarea.removeEventListener("change", arguments.callee); checkChangeEvent(aEvent); radio.focus(); -}); +}, {once: true}); textarea.addEventListener("input", function() { - textarea.removeEventListener("input", arguments.callee); textarea.blur(); -}); +}, {once: true}); textarea.addEventListener("focus", function() { - textarea.removeEventListener("focus", arguments.callee); SimpleTest.executeSoon(function () { synthesizeKey('f', {}); }); -}); +}, {once: true}); input.addEventListener("change", function(aEvent) { - input.removeEventListener("change", arguments.callee); checkChangeEvent(aEvent); textarea.focus(); -}); +}, {once: true}); input.addEventListener("input", function() { - input.removeEventListener("input", arguments.callee); input.blur(); -}); +}, {once: true}); input.addEventListener("focus", function() { - input.removeEventListener("focus", arguments.callee); SimpleTest.executeSoon(function () { synthesizeKey('f', {}); }); -}); +}, {once: true}); SimpleTest.waitForExplicitFinish(); SimpleTest.waitForFocus(function() { diff --git a/dom/html/test/test_bug619278.html b/dom/html/test/test_bug619278.html index a20fc6df072d..49814e20a94f 100644 --- a/dom/html/test/test_bug619278.html +++ b/dom/html/test/test_bug619278.html @@ -40,12 +40,10 @@ e.addEventListener("invalid", function(event) { }); e.addEventListener("focus", function() { - e.removeEventListener("focus", arguments.callee); - SimpleTest.executeSoon(function() { synthesizeKey("VK_RETURN", {}); }); -}); +}, {once: true}); SimpleTest.waitForExplicitFinish(); SimpleTest.waitForFocus(function() { diff --git a/dom/html/test/test_bug622558.html b/dom/html/test/test_bug622558.html index c94371d4ba44..1222437a133c 100644 --- a/dom/html/test/test_bug622558.html +++ b/dom/html/test/test_bug622558.html @@ -40,8 +40,6 @@ var textarea = document.getElementsByTagName('textarea')[0]; var select = document.getElementsByTagName('select')[0]; select.addEventListener("focus", function() { - select.removeEventListener("focus", arguments.callee); - SimpleTest.executeSoon(function() { select.setCustomValidity('foo'); @@ -50,11 +48,9 @@ select.addEventListener("focus", function() { SimpleTest.finish(); }); }); -}); +}, {once: true}); textarea.addEventListener("focus", function() { - textarea.removeEventListener("focus", arguments.callee); - SimpleTest.executeSoon(function() { textarea.setCustomValidity('foo'); @@ -63,11 +59,9 @@ textarea.addEventListener("focus", function() { select.focus(); }); }); -}); +}, {once: true}); input.addEventListener("focus", function() { - input.removeEventListener("focus", arguments.callee); - SimpleTest.executeSoon(function() { input.setCustomValidity('foo'); @@ -76,7 +70,7 @@ input.addEventListener("focus", function() { textarea.focus(); }); }); -}); +}, {once: true}); SimpleTest.waitForExplicitFinish(); SimpleTest.waitForFocus(function() { diff --git a/dom/html/test/test_bug622597.html b/dom/html/test/test_bug622597.html index 887cf34ade21..3adb63ae4327 100644 --- a/dom/html/test/test_bug622597.html +++ b/dom/html/test/test_bug622597.html @@ -46,8 +46,6 @@ function checkPseudoClasses(aElement, aValid, aInvalid) } select.addEventListener("focus", function() { - select.removeEventListener("focus", arguments.callee); - SimpleTest.executeSoon(function() { form.noValidate = false; SimpleTest.executeSoon(function() { @@ -55,11 +53,9 @@ select.addEventListener("focus", function() { SimpleTest.finish(); }); }); -}); +}, {once: true}); textarea.addEventListener("focus", function() { - textarea.removeEventListener("focus", arguments.callee); - SimpleTest.executeSoon(function() { form.noValidate = false; SimpleTest.executeSoon(function() { @@ -69,14 +65,10 @@ textarea.addEventListener("focus", function() { select.focus(); }); }); -}); +}, {once: true}); input.addEventListener("invalid", function() { - input.removeEventListener("invalid", arguments.callee); - input.addEventListener("focus", function() { - input.removeEventListener("focus", arguments.callee); - SimpleTest.executeSoon(function() { form.noValidate = false; SimpleTest.executeSoon(function() { @@ -86,7 +78,7 @@ input.addEventListener("invalid", function() { textarea.focus(); }); }); - }); + }, {once: true}); SimpleTest.executeSoon(function() { form.noValidate = true; @@ -94,15 +86,13 @@ input.addEventListener("invalid", function() { input.value = ''; input.focus(); }); -}); +}, {once: true}); button.addEventListener("focus", function() { - button.removeEventListener("focus", arguments.callee); - SimpleTest.executeSoon(function() { synthesizeKey("VK_RETURN", {}); }); -}); +}, {once: true}); SimpleTest.waitForExplicitFinish(); SimpleTest.waitForFocus(function() { diff --git a/dom/html/test/test_bug633058.html b/dom/html/test/test_bug633058.html index c7547616e52b..d4e6b452ed9d 100644 --- a/dom/html/test/test_bug633058.html +++ b/dom/html/test/test_bug633058.html @@ -49,8 +49,6 @@ function startTest() { }); input.addEventListener('focus', function() { - input.removeEventListener('focus', arguments.callee); - synthesizeKey('VK_UP', {}); synthesizeKey('VK_LEFT', {}); synthesizeKey('VK_RIGHT', {}); @@ -59,7 +57,7 @@ function startTest() { synthesizeKey('VK_DELETE', {}); synthesizeKey('VK_ESCAPE', {}); synthesizeKey('VK_RETURN', {}); - }); + }, {once: true}); input.focus(); } diff --git a/dom/html/test/test_bug651956.html b/dom/html/test/test_bug651956.html index c77281531e0c..9e9fe5a264fb 100644 --- a/dom/html/test/test_bug651956.html +++ b/dom/html/test/test_bug651956.html @@ -26,19 +26,17 @@ var input = document.getElementsByTagName('input')[0]; var gotInputEvent = false; input.addEventListener("input", function() { - input.removeEventListener("input", arguments.callee); gotInputEvent = true; -}); +}, {once: true}); input.addEventListener("focus", function() { - input.removeEventListener("focus", arguments.callee); synthesizeKey("VK_ESCAPE", {}); setTimeout(function() { ok(!gotInputEvent, "No input event should have been sent."); SimpleTest.finish(); }); -}); +}, {once: true}); SimpleTest.waitForExplicitFinish(); SimpleTest.waitForFocus(function() { diff --git a/dom/html/test/test_fullscreen-api.html b/dom/html/test/test_fullscreen-api.html index 92a370942678..32496c10927a 100644 --- a/dom/html/test/test_fullscreen-api.html +++ b/dom/html/test/test_fullscreen-api.html @@ -70,12 +70,11 @@ function runNextTest() { // before starting the test, which will get kicked off on "focus". // This ensures that we're essentially back on the primary "desktop" on // OS X Lion before we run the test. - testWindow.addEventListener("load", function onload() { - testWindow.removeEventListener("load", onload); + testWindow.addEventListener("load", function() { SimpleTest.waitForFocus(function() { SimpleTest.waitForFocus(testWindow.begin, testWindow); }); - }); + }, {once: true}); gTestIndex++; } else { SimpleTest.finish(); diff --git a/dom/html/test/test_ignoreuserfocus.html b/dom/html/test/test_ignoreuserfocus.html index 6297901829d9..092cf0448c3a 100644 --- a/dom/html/test/test_ignoreuserfocus.html +++ b/dom/html/test/test_ignoreuserfocus.html @@ -48,9 +48,7 @@ // Get privileged iframe because mozbrowser iframe is not same origin // with the parent. We need to access its content through the wrapper. var privilegedIframe = SpecialPowers.wrap(iframe); - privilegedIframe.contentWindow.addEventListener("MozAfterPaint", function afterPaint(e) { - privilegedIframe.contentWindow.removeEventListener("MozAfterPaint", afterPaint); - + privilegedIframe.contentWindow.addEventListener("MozAfterPaint", function(e) { privilegedIframe.contentWindow.addEventListener("focus", function(e) { ok(!iframe.hasAttribute("ignoreuserfocus"), "Shouldn't get a focus event in ignoreuserfocus iframe!"); @@ -106,8 +104,7 @@ // Wait for paint to setup frame for area. Currently the area frame // map is reset for each paint. If we are in the middle of a paint // then the area will not be focusable. - privilegedIframe.contentWindow.addEventListener("MozAfterPaint", function afterPaintArea(e) { - privilegedIframe.contentWindow.removeEventListener("MozAfterPaint", afterPaintArea); + privilegedIframe.contentWindow.addEventListener("MozAfterPaint", function(e) { var innerArea = privilegedIframe.contentDocument.getElementsByTagName("area")[0]; innerArea.focus(); isnot(document.activeElement, iframe, "[explicit innerArea.focus()] iframe should not have the focus"); @@ -124,11 +121,11 @@ is(document.activeElement, witness2, "witness2 should have the focus"); SimpleTest.finish(); - }); + }, {once: true}); witness.focus(); // force reflow iframe.setAttribute("height", "298px"); - }); + }, {once: true}); // force reflow iframe.setAttribute("height", "299px"); }); diff --git a/dom/indexedDB/test/browser_forgetThisSite.js b/dom/indexedDB/test/browser_forgetThisSite.js index c1177908f4d7..a6309971fc4f 100644 --- a/dom/indexedDB/test/browser_forgetThisSite.js +++ b/dom/indexedDB/test/browser_forgetThisSite.js @@ -33,8 +33,6 @@ function test1() // Set database version for domain 1 gBrowser.selectedTab = gBrowser.addTab(); gBrowser.selectedBrowser.addEventListener("load", function () { - gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); - setFinishedCallback(function(result, exception) { ok(result == 11, "Set version on database in " + testPageURL1); ok(!exception, "No exception"); @@ -42,7 +40,7 @@ function test1() executeSoon(test2); }); - }, true); + }, {capture: true, once: true}); content.location = testPageURL1; } @@ -51,8 +49,6 @@ function test2() // Set database version for domain 2 gBrowser.selectedTab = gBrowser.addTab(); gBrowser.selectedBrowser.addEventListener("load", function () { - gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); - setFinishedCallback(function(result, exception) { ok(result == 11, "Set version on database in " + testPageURL2); ok(!exception, "No exception"); @@ -60,7 +56,7 @@ function test2() executeSoon(test3); }); - }, true); + }, {capture: true, once: true}); content.location = testPageURL2; } @@ -77,8 +73,6 @@ function test4() // Get database version for domain 1 gBrowser.selectedTab = gBrowser.addTab(); gBrowser.selectedBrowser.addEventListener("load", function () { - gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); - setFinishedCallback(function(result, exception) { ok(result == 11, "Got correct version on database in " + testPageURL3); ok(!exception, "No exception"); @@ -86,7 +80,7 @@ function test4() executeSoon(test5); }); - }, true); + }, {capture: true, once: true}); content.location = testPageURL3; } @@ -95,8 +89,6 @@ function test5() // Get database version for domain 2 gBrowser.selectedTab = gBrowser.addTab(); gBrowser.selectedBrowser.addEventListener("load", function () { - gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); - setFinishedCallback(function(result, exception) { ok(result == 1, "Got correct version on database in " + testPageURL4); ok(!exception, "No exception"); @@ -104,6 +96,6 @@ function test5() executeSoon(finish); }); - }, true); + }, {capture: true, once: true}); content.location = testPageURL4; } diff --git a/dom/indexedDB/test/browser_permissionsPromptAllow.js b/dom/indexedDB/test/browser_permissionsPromptAllow.js index dd0921872571..8c6dd61138bb 100644 --- a/dom/indexedDB/test/browser_permissionsPromptAllow.js +++ b/dom/indexedDB/test/browser_permissionsPromptAllow.js @@ -22,8 +22,6 @@ function test1() gBrowser.selectedTab = gBrowser.addTab(); gBrowser.selectedBrowser.addEventListener("load", function () { - gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); - setFinishedCallback(function(isIDBDatabase, exception) { ok(isIDBDatabase, "First database creation was successful"); @@ -46,7 +44,7 @@ function test1() ok(true, "prompt hidden"); }); - }, true); + }, {capture: true, once: true}); info("loading test page: " + testPageURL); content.location = testPageURL; @@ -58,8 +56,6 @@ function test2() gBrowser.selectedTab = gBrowser.addTab(); gBrowser.selectedBrowser.addEventListener("load", function () { - gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); - setFinishedCallback(function(isIDBDatabase, exception) { ok(isIDBDatabase, "First database creation was successful"); @@ -83,7 +79,7 @@ function test2() ok(false, "Shouldn't show a popup this time"); }); - }, true); + }, {capture: true, once: true}); info("loading test page: " + testPageURL); content.location = testPageURL; diff --git a/dom/indexedDB/test/browser_permissionsPromptDeny.js b/dom/indexedDB/test/browser_permissionsPromptDeny.js index 4d8b4476b0d3..fb0193c46461 100644 --- a/dom/indexedDB/test/browser_permissionsPromptDeny.js +++ b/dom/indexedDB/test/browser_permissionsPromptDeny.js @@ -10,14 +10,13 @@ const notificationID = "indexedDB-permissions-prompt"; function promiseMessage(aMessage, browser) { return ContentTask.spawn(browser.selectedBrowser, aMessage, function* (aMessage) { yield new Promise((resolve, reject) => { - content.addEventListener("message", function messageListener(event) { - content.removeEventListener("message", messageListener); + content.addEventListener("message", function(event) { is(event.data, aMessage, "received " + aMessage); if (event.data == aMessage) resolve(); else reject(); - }); + }, {once: true}); }); }); } diff --git a/dom/indexedDB/test/browser_permissionsPromptWorker.js b/dom/indexedDB/test/browser_permissionsPromptWorker.js index a60704e69087..640c4190e620 100644 --- a/dom/indexedDB/test/browser_permissionsPromptWorker.js +++ b/dom/indexedDB/test/browser_permissionsPromptWorker.js @@ -24,8 +24,6 @@ function test1() gBrowser.selectedTab = gBrowser.addTab(); gBrowser.selectedBrowser.addEventListener("load", function () { - gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); - setFinishedCallback(function(isIDBDatabase, exception) { ok(isIDBDatabase, "First database creation was successful"); ok(!exception, "No exception"); @@ -47,7 +45,7 @@ function test1() ok(true, "prompt hidden"); }); - }, true); + }, {capture: true, once: true}); info("loading test page: " + testWorkerURL); content.location = testWorkerURL; @@ -62,8 +60,6 @@ function test2() gBrowser.selectedTab = gBrowser.addTab(); gBrowser.selectedBrowser.addEventListener("load", function () { - gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); - setFinishedCallback(function(isIDBDatabase, exception) { ok(!isIDBDatabase, "First database creation was successful"); ok(exception, "No exception"); @@ -84,7 +80,7 @@ function test2() ok(false, "prompt hidden"); }); - }, true); + }, {capture: true, once: true}); info("loading test page: " + testSharedWorkerURL); content.location = testSharedWorkerURL; diff --git a/dom/indexedDB/test/browser_perwindow_privateBrowsing.js b/dom/indexedDB/test/browser_perwindow_privateBrowsing.js index 3fba7304869d..97a7a5162a19 100644 --- a/dom/indexedDB/test/browser_perwindow_privateBrowsing.js +++ b/dom/indexedDB/test/browser_perwindow_privateBrowsing.js @@ -40,10 +40,9 @@ function test1() function test2() { var win = OpenBrowserWindow({private: true}); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); + win.addEventListener("load", function() { executeSoon(() => test3(win)); - }); + }, {once: true}); registerCleanupFunction(() => win.close()); } diff --git a/dom/manifest/test/test_window_onappinstalled_event.html b/dom/manifest/test/test_window_onappinstalled_event.html index af57fbf770d5..db2df8484d1a 100644 --- a/dom/manifest/test/test_window_onappinstalled_event.html +++ b/dom/manifest/test/test_window_onappinstalled_event.html @@ -86,11 +86,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1265279 function checkAddEventListenerFires(ifrWindow) { const customEv = new CustomEvent("appinstalled"); return new Promise((resolve) => { - ifrWindow.addEventListener("appinstalled", function handler(ev) { - ifrWindow.removeEventListener("appinstalled", handler); + ifrWindow.addEventListener("appinstalled", function(ev) { is(ev, customEv, "The events should be the same"); resolve(ifrWindow); - }); + }, {once: true}); ifrWindow.dispatchEvent(customEv); }); } diff --git a/dom/media/mediasource/test/test_HaveMetadataUnbufferedSeek.html b/dom/media/mediasource/test/test_HaveMetadataUnbufferedSeek.html index f6192074a5b7..99a3809f58cd 100644 --- a/dom/media/mediasource/test/test_HaveMetadataUnbufferedSeek.html +++ b/dom/media/mediasource/test/test_HaveMetadataUnbufferedSeek.html @@ -22,11 +22,10 @@ runWithMSE(function (ms, v) { var target = 2; - v.addEventListener("loadeddata", function onloadeddata() { - v.removeEventListener("loadeddata", onloadeddata); + v.addEventListener("loadeddata", function() { ok(v.readyState >= v.HAVE_CURRENT_DATA, "readyState is >= CURRENT_DATA"); v.currentTime = target; - }); + }, {once: true}); v.addEventListener("seeking", function () { is(v.readyState, v.HAVE_METADATA, "readyState is HAVE_METADATA"); diff --git a/dom/media/mediasource/test/test_HaveMetadataUnbufferedSeek_mp4.html b/dom/media/mediasource/test/test_HaveMetadataUnbufferedSeek_mp4.html index fc3ef06ebf9c..78e50e45d20f 100644 --- a/dom/media/mediasource/test/test_HaveMetadataUnbufferedSeek_mp4.html +++ b/dom/media/mediasource/test/test_HaveMetadataUnbufferedSeek_mp4.html @@ -23,11 +23,10 @@ runWithMSE(function (ms, v) { var target = 1.3; - v.addEventListener("loadeddata", function onloadeddata() { - v.removeEventListener("loadeddata", onloadeddata); + v.addEventListener("loadeddata", function() { ok(v.readyState >= v.HAVE_CURRENT_DATA, "readyState is >= CURRENT_DATA"); v.currentTime = target; - }); + }, {once: true}); v.addEventListener("seeking", function () { is(v.readyState, v.HAVE_METADATA, "readyState is HAVE_METADATA"); diff --git a/dom/media/mediasource/test/test_SeekableBeforeEndOfStreamSplit.html b/dom/media/mediasource/test/test_SeekableBeforeEndOfStreamSplit.html index 2013fb4e6155..63672a2ef051 100644 --- a/dom/media/mediasource/test/test_SeekableBeforeEndOfStreamSplit.html +++ b/dom/media/mediasource/test/test_SeekableBeforeEndOfStreamSplit.html @@ -19,9 +19,8 @@ runWithMSE(function (ms, v) { fetchWithXHR("seek.webm", function (arrayBuffer) { sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 25523)); sb.addEventListener("updateend", function () { - sb.removeEventListener('updateend', arguments.callee); sb.appendBuffer(new Uint8Array(arrayBuffer, 25523)); - }); + }, {once: true}); }); var target = 2; diff --git a/dom/media/mediasource/test/test_SeekableBeforeEndOfStreamSplit_mp4.html b/dom/media/mediasource/test/test_SeekableBeforeEndOfStreamSplit_mp4.html index f146696655a7..0703afdf3dab 100644 --- a/dom/media/mediasource/test/test_SeekableBeforeEndOfStreamSplit_mp4.html +++ b/dom/media/mediasource/test/test_SeekableBeforeEndOfStreamSplit_mp4.html @@ -20,10 +20,9 @@ runWithMSE(function (ms, v) { // 25819 is the offset of the first media segment's end sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 25819)); sb.addEventListener("updateend", function () { - sb.removeEventListener('updateend', arguments.callee); // 25819 is the offset of the first media segment's end sb.appendBuffer(new Uint8Array(arrayBuffer, 25819)); - }); + }, {once: true}); }); var target = 1.3; diff --git a/dom/media/test/test_texttrackcue.html b/dom/media/test/test_texttrackcue.html index 2b034e5faba1..04a9c7058bfc 100644 --- a/dom/media/test/test_texttrackcue.html +++ b/dom/media/test/test_texttrackcue.html @@ -83,10 +83,9 @@ SpecialPowers.pushPrefEnv({"set": [["media.webvtt.regions.enabled", true]]}, is(cue.endTime, 0.71, "Cue's end time should be 0.71."); cue.pauseOnExit = true; is(cue.pauseOnExit, true, "Cue's pause on exit flag should be true."); - video.addEventListener("pause", function pauseOnExit() { - video.removeEventListener("pause", pauseOnExit); + video.addEventListener("pause", function() { video.play(); - }); + }, {once: true}); var exceptionHappened; function checkPercentageValue(prop, initialVal) { diff --git a/dom/media/test/test_webvtt_positionalign.html b/dom/media/test/test_webvtt_positionalign.html index 47593bdf90c3..09ea0efc9a42 100644 --- a/dom/media/test/test_webvtt_positionalign.html +++ b/dom/media/test/test_webvtt_positionalign.html @@ -84,9 +84,8 @@ function setupTest() { document.getElementById("content").appendChild(video); video.appendChild(trackElement); video.addEventListener("loadedmetadata", function() { - video.removeEventListener("loadedmetadata", runTest); isTrackElemenLoaded(); - }); + }, {once: true}); } onload = setupTest; diff --git a/dom/network/tests/file_udpsocket_iframe.html b/dom/network/tests/file_udpsocket_iframe.html index 1e124552dda0..7a4af699856c 100644 --- a/dom/network/tests/file_udpsocket_iframe.html +++ b/dom/network/tests/file_udpsocket_iframe.html @@ -6,8 +6,7 @@ diff --git a/dom/network/tests/test_udpsocket.html b/dom/network/tests/test_udpsocket.html index f1d03824a6b5..df2b6c85c793 100644 --- a/dom/network/tests/test_udpsocket.html +++ b/dom/network/tests/test_udpsocket.html @@ -75,13 +75,12 @@ function testSendString(socket) { socket.send(HELLO_WORLD, '127.0.0.1', socket.localPort); return new Promise(function(resolve, reject) { - socket.addEventListener('message', function recv_callback(msg) { - socket.removeEventListener('message', recv_callback); + socket.addEventListener('message', function(msg) { let recvData= String.fromCharCode.apply(null, new Uint8Array(msg.data)); is(msg.remotePort, socket.localPort, 'expected packet from ' + socket.localPort); is(recvData, HELLO_WORLD, 'expected same string data'); resolve(socket); - }); + }, {once: true}); }); } @@ -91,12 +90,11 @@ function testSendArrayBuffer(socket) { socket.send(DATA_ARRAY_BUFFER, '127.0.0.1', socket.localPort); return new Promise(function(resolve, reject) { - socket.addEventListener('message', function recv_callback(msg) { - socket.removeEventListener('message', recv_callback); + socket.addEventListener('message', function(msg) { is(msg.remotePort, socket.localPort, 'expected packet from ' + socket.localPort); ok(is_same_buffer(msg.data, DATA_ARRAY_BUFFER), 'expected same buffer data'); resolve(socket); - }); + }, {once: true}); }); } @@ -106,12 +104,11 @@ function testSendArrayBufferView(socket) { socket.send(TYPED_DATA_ARRAY, '127.0.0.1', socket.localPort); return new Promise(function(resolve, reject) { - socket.addEventListener('message', function recv_callback(msg) { - socket.removeEventListener('message', recv_callback); + socket.addEventListener('message', function(msg) { is(msg.remotePort, socket.localPort, 'expected packet from ' + socket.localPort); ok(is_same_buffer(msg.data, TYPED_DATA_ARRAY), 'expected same buffer data'); resolve(socket); - }); + }, {once: true}); }); } @@ -122,13 +119,12 @@ function testSendBlob(socket) { socket.send(blob, '127.0.0.1', socket.localPort); return new Promise(function(resolve, reject) { - socket.addEventListener('message', function recv_callback(msg) { - socket.removeEventListener('message', recv_callback); + socket.addEventListener('message', function(msg) { let recvData= String.fromCharCode.apply(null, new Uint8Array(msg.data)); is(msg.remotePort, socket.localPort, 'expected packet from ' + socket.localPort); is(recvData, HELLO_WORLD, 'expected same string data'); resolve(socket); - }); + }, {once: true}); }); } @@ -190,13 +186,12 @@ function testUDPOptions(socket) { return remoteSocket.opened.then(function() { remoteSocket.send(HELLO_WORLD); return new Promise(function(resolve, reject) { - socket.addEventListener('message', function recv_callback(msg) { - socket.removeEventListener('message', recv_callback); + socket.addEventListener('message', function(msg) { let recvData= String.fromCharCode.apply(null, new Uint8Array(msg.data)); is(msg.remotePort, remoteSocket.localPort, 'expected packet from ' + remoteSocket.localPort); is(recvData, HELLO_WORLD, 'expected same string data'); resolve(socket); - }); + }, {once: true}); }); }); } @@ -230,14 +225,13 @@ function testMulticast() { socket.send(HELLO_WORLD, MCAST_ADDRESS, socket.localPort); return new Promise(function(resolve, reject) { - socket.addEventListener('message', function recv_callback(msg) { - socket.removeEventListener('message', recv_callback); + socket.addEventListener('message', function(msg) { let recvData= String.fromCharCode.apply(null, new Uint8Array(msg.data)); is(msg.remotePort, socket.localPort, 'expected packet from ' + socket.localPort); is(recvData, HELLO_WORLD, 'expected same string data'); socket.leaveMulticastGroup(MCAST_ADDRESS); resolve(); - }); + }, {once: true}); }); }); } @@ -338,11 +332,9 @@ function testBFCache() { iframe.src = 'file_udpsocket_iframe.html?' + socket.localPort; return new Promise(function(resolve, reject) { - socket.addEventListener('message', function recv_callback(msg) { - socket.removeEventListener('message', recv_callback); + socket.addEventListener('message', function(msg) { iframe.src = 'about:blank'; - iframe.addEventListener('load', function onload() { - iframe.removeEventListener('load', onload); + iframe.addEventListener('load', function() { socket.send(HELLO_WORLD, '127.0.0.1', msg.remotePort); function recv_again_callback(msg) { @@ -357,8 +349,8 @@ function testBFCache() { socket.close(); resolve(); }, 5000); - }); - }); + }, {once: true}); + }, {once: true}); }); }); } diff --git a/dom/plugins/test/mochitest/head.js b/dom/plugins/test/mochitest/head.js index 42143b84bd4b..200d64a05200 100644 --- a/dom/plugins/test/mochitest/head.js +++ b/dom/plugins/test/mochitest/head.js @@ -4,10 +4,9 @@ */ function waitTabSwitched() { return new Promise(resolve => { - gBrowser.addEventListener("TabSwitchDone", function onSwitch() { - gBrowser.removeEventListener("TabSwitchDone", onSwitch); + gBrowser.addEventListener("TabSwitchDone", function() { executeSoon(resolve); - }); + }, {once: true}); }); } @@ -64,10 +63,9 @@ function nativeVerticalWheelEventMsg() { */ function waitScrollStart(aTarget) { return new Promise((resolve, reject) => { - aTarget.addEventListener("scroll", function listener(event) { - aTarget.removeEventListener("scroll", listener, true); + aTarget.addEventListener("scroll", function(event) { resolve(event); - }, true); + }, {capture: true, once: true}); }); } diff --git a/dom/plugins/test/mochitest/plugin-utils.js b/dom/plugins/test/mochitest/plugin-utils.js index 8e9ebddf288a..4c1d2e572875 100644 --- a/dom/plugins/test/mochitest/plugin-utils.js +++ b/dom/plugins/test/mochitest/plugin-utils.js @@ -99,10 +99,9 @@ function crashAndGetCrashServiceRecord(crashMethodName, callback) { */ function promiseFullScreenChange(){ return new Promise(resolve => { - document.addEventListener("fullscreenchange", function onFullScreen(e) { - document.removeEventListener("fullscreenchange", onFullScreen); + document.addEventListener("fullscreenchange", function(e) { resolve(); - }); + }, {once: true}); }); } diff --git a/dom/plugins/test/mochitest/test_pluginstream_3rdparty.html b/dom/plugins/test/mochitest/test_pluginstream_3rdparty.html index aa7dbb5a1c07..59f3e97ba979 100644 --- a/dom/plugins/test/mochitest/test_pluginstream_3rdparty.html +++ b/dom/plugins/test/mochitest/test_pluginstream_3rdparty.html @@ -50,10 +50,9 @@ document.body.appendChild(e); return new Promise(resolve => { - $('testframe').addEventListener("load", function loaded() { - $('testframe').removeEventListener("load", loaded); + $('testframe').addEventListener("load", function() { resolve(); - }); + }, {once: true}); }); } diff --git a/dom/power/test/browser_wakelocks.js b/dom/power/test/browser_wakelocks.js index 5bd4de67c9f4..8fd97762f2bb 100644 --- a/dom/power/test/browser_wakelocks.js +++ b/dom/power/test/browser_wakelocks.js @@ -20,8 +20,7 @@ var gSteps = [ gWin = gBrowser.getBrowserForTab(gTab).contentWindow; let browser = gBrowser.getBrowserForTab(gTab); - browser.addEventListener("load", function onLoad(e) { - browser.removeEventListener("load", onLoad, true); + browser.addEventListener("load", function(e) { let nav = gWin.navigator; let power = nav.mozPower; gLock = nav.requestWakeLock("test"); @@ -51,15 +50,14 @@ var gSteps = [ gBrowser.removeTab(gTab); executeSoon(runNextStep); - }, true); + }, {capture: true, once: true}); }, function multiWakeLock() { gTab = gBrowser.addTab(kUrlSource); gWin = gBrowser.getBrowserForTab(gTab).contentWindow; let browser = gBrowser.getBrowserForTab(gTab); - browser.addEventListener("load", function onLoad(e) { - browser.removeEventListener("load", onLoad, true); + browser.addEventListener("load", function(e) { let nav = gWin.navigator; let power = nav.mozPower; let count = 0; @@ -100,7 +98,7 @@ var gSteps = [ "topic is locked"); gLock2.unlock(); - }, true); + }, {capture: true, once: true}); }, function crossTabWakeLock1() { gTab1 = gBrowser.addTab(kUrlSource); @@ -111,8 +109,7 @@ var gSteps = [ gBrowser.selectedTab = gTab1; let browser = gBrowser.getBrowserForTab(gTab2); - browser.addEventListener("load", function onLoad(e) { - browser.removeEventListener("load", onLoad, true); + browser.addEventListener("load", function(e) { gLock2 = gWin2.navigator.requestWakeLock("test"); is(gWin2.document.hidden, true, "window is background") @@ -126,21 +123,19 @@ var gSteps = [ } }); gBrowser.selectedTab = gTab2; - }, true); + }, {capture: true, once: true}); }, function crossTabWakeLock2() { is(gWin2.document.hidden, false, "window is foreground") is(gWin2.navigator.mozPower.getWakeLockState("test"), "locked-foreground", "wake lock is foreground"); - gWin2.addEventListener("pagehide", function onPageHide(e) { - gWin2.removeEventListener("pagehide", onPageHide, true); + gWin2.addEventListener("pagehide", function(e) { executeSoon(runNextStep); - }, true); - gWin2.addEventListener("pageshow", function onPageShow(e) { - gWin2.removeEventListener("pageshow", onPageShow, true); + }, {capture: true, once: true}); + gWin2.addEventListener("pageshow", function(e) { executeSoon(runNextStep); - }, true); + }, {capture: true, once: true}); gWin2.location = kDataSource; }, function crossTabWakeLock3() { @@ -161,14 +156,12 @@ var gSteps = [ "window is background") is(gWin2.navigator.mozPower.getWakeLockState("test"), "locked-background", "wake lock is background"); - gWin2.addEventListener("pagehide", function onPageHide(e) { - gWin2.removeEventListener("pagehide", onPageHide, true); + gWin2.addEventListener("pagehide", function(e) { executeSoon(runNextStep); - }, true); - gWin2.addEventListener("pageshow", function onPageShow(e) { - gWin2.removeEventListener("pageshow", onPageShow, true); + }, {capture: true, once: true}); + gWin2.addEventListener("pageshow", function(e) { executeSoon(runNextStep); - }, true); + }, {capture: true, once: true}); gWin2.location = kDataSource; }, function crossTabWakeLock6() { diff --git a/dom/presentation/tests/mochitest/file_presentation_1ua_receiver.html b/dom/presentation/tests/mochitest/file_presentation_1ua_receiver.html index cf02d2b2c87a..14fc1c6e43a8 100644 --- a/dom/presentation/tests/mochitest/file_presentation_1ua_receiver.html +++ b/dom/presentation/tests/mochitest/file_presentation_1ua_receiver.html @@ -100,13 +100,12 @@ function testConnectionReady() { function testIncomingMessage() { return new Promise(function(aResolve, aReject) { info('Receiver: --- testIncomingMessage ---'); - connection.addEventListener('message', function messageHandler(evt) { - connection.removeEventListener('message', messageHandler); + connection.addEventListener('message', function(evt) { let msg = evt.data; is(msg, 'msg-sender-to-receiver', 'Receiver: Receiver should receive message from sender.'); command('forward-command', JSON.stringify({ name: 'message-from-sender-received' })); aResolve(); - }); + }, {once: true}); command('forward-command', JSON.stringify({ name: 'trigger-message-from-sender' })); }); } @@ -131,12 +130,11 @@ function testIncomingBlobMessage() { return new Promise(function(aResolve, aReject) { info('Receiver: --- testIncomingBlobMessage ---'); connection.send('testIncomingBlobMessage'); - connection.addEventListener('message', function messageHandler(evt) { - connection.removeEventListener('message', messageHandler); + connection.addEventListener('message', function(evt) { let recvData= String.fromCharCode.apply(null, new Uint8Array(evt.data)); is(recvData, "Hello World", 'expected same string data'); aResolve(); - }); + }, {once: true}); }); } @@ -175,15 +173,14 @@ function testIncomingArrayBuffer() { info('Receiver: --- testIncomingArrayBuffer ---'); connection.binaryType = "blob"; connection.send('testIncomingArrayBuffer'); - connection.addEventListener('message', function messageHandler(evt) { - connection.removeEventListener('message', messageHandler); + connection.addEventListener('message', function(evt) { var fileReader = new FileReader(); fileReader.onload = function() { ok(is_same_buffer(DATA_ARRAY_BUFFER, this.result), "expected same buffer data"); aResolve(); }; fileReader.readAsArrayBuffer(evt.data); - }); + }, {once: true}); }); } @@ -192,11 +189,10 @@ function testIncomingArrayBufferView() { info('Receiver: --- testIncomingArrayBufferView ---'); connection.binaryType = "arraybuffer"; connection.send('testIncomingArrayBufferView'); - connection.addEventListener('message', function messageHandler(evt) { - connection.removeEventListener('message', messageHandler); + connection.addEventListener('message', function(evt) { ok(is_same_buffer(evt.data, TYPED_DATA_ARRAY), "expected same buffer data"); aResolve(); - }); + }, {once: true}); }); } diff --git a/dom/presentation/tests/mochitest/file_presentation_mixed_security_contexts.html b/dom/presentation/tests/mochitest/file_presentation_mixed_security_contexts.html index 86df5359df48..5f37f7570b35 100644 --- a/dom/presentation/tests/mochitest/file_presentation_mixed_security_contexts.html +++ b/dom/presentation/tests/mochitest/file_presentation_mixed_security_contexts.html @@ -141,12 +141,11 @@ function runTest() { .then(finish); } -window.addEventListener("message", function onMessage(evt) { - window.removeEventListener("message", onMessage); +window.addEventListener("message", function(evt) { if (evt.data === "start") { runTest(); } -}); +}, {once: true}); window.setTimeout(function() { command("ready-to-start"); diff --git a/dom/presentation/tests/mochitest/file_presentation_receiver.html b/dom/presentation/tests/mochitest/file_presentation_receiver.html index 46a330b5fcc8..915c0f43e512 100644 --- a/dom/presentation/tests/mochitest/file_presentation_receiver.html +++ b/dom/presentation/tests/mochitest/file_presentation_receiver.html @@ -103,11 +103,10 @@ function testIncomingMessage() { return new Promise(function(aResolve, aReject) { const incomingMessage = "test incoming message"; - connection.addEventListener('message', function messageHandler(aEvent) { - connection.removeEventListener('message', messageHandler); + connection.addEventListener('message', function(aEvent) { is(aEvent.data, incomingMessage, "An incoming message should be received."); aResolve(); - }); + }, {once: true}); command({ name: 'trigger-incoming-message', data: incomingMessage }); diff --git a/dom/presentation/tests/mochitest/file_presentation_sandboxed_presentation.html b/dom/presentation/tests/mochitest/file_presentation_sandboxed_presentation.html index 34815cead553..e768e83705ef 100644 --- a/dom/presentation/tests/mochitest/file_presentation_sandboxed_presentation.html +++ b/dom/presentation/tests/mochitest/file_presentation_sandboxed_presentation.html @@ -96,12 +96,11 @@ function runTest() { .then(finish); } -window.addEventListener("message", function onMessage(evt) { - window.removeEventListener("message", onMessage); +window.addEventListener("message", function(evt) { if (evt.data === "start") { runTest(); } -}); +}, {once: true}); window.setTimeout(function() { command("ready-to-start"); diff --git a/dom/presentation/tests/mochitest/test_presentation_1ua_connection_wentaway.js b/dom/presentation/tests/mochitest/test_presentation_1ua_connection_wentaway.js index 7acccfda3ca6..21541b2d57f2 100644 --- a/dom/presentation/tests/mochitest/test_presentation_1ua_connection_wentaway.js +++ b/dom/presentation/tests/mochitest/test_presentation_1ua_connection_wentaway.js @@ -37,10 +37,9 @@ function setup() { receiverIframe.setAttribute("remote", oop); receiverIframe.setAttribute('src', receiverUrl); - receiverIframe.addEventListener("mozbrowserloadend", function mozbrowserloadendHander() { - receiverIframe.removeEventListener("mozbrowserloadend", mozbrowserloadendHander); + receiverIframe.addEventListener("mozbrowserloadend", function() { info("Receiver loaded."); - }); + }, {once: true}); // This event is triggered when the iframe calls "alert". receiverIframe.addEventListener("mozbrowsershowmodalprompt", function receiverListener(evt) { diff --git a/dom/presentation/tests/mochitest/test_presentation_1ua_sender_and_receiver.js b/dom/presentation/tests/mochitest/test_presentation_1ua_sender_and_receiver.js index 8d9410320435..8aa6d3c656e0 100644 --- a/dom/presentation/tests/mochitest/test_presentation_1ua_sender_and_receiver.js +++ b/dom/presentation/tests/mochitest/test_presentation_1ua_sender_and_receiver.js @@ -159,13 +159,12 @@ function testSendMessage() { function testIncomingMessage() { return new Promise(function(aResolve, aReject) { info('Sender: --- testIncomingMessage ---'); - connection.addEventListener('message', function messageHandler(evt) { - connection.removeEventListener('message', messageHandler); + connection.addEventListener('message', function(evt) { let msg = evt.data; is(msg, "msg-receiver-to-sender", "Sender: Sender should receive message from Receiver"); postMessageToIframe('message-from-receiver-received'); aResolve(); - }); + }, {once: true}); postMessageToIframe('trigger-message-from-receiver'); }); } @@ -173,40 +172,37 @@ function testIncomingMessage() { function testSendBlobMessage() { return new Promise(function(aResolve, aReject) { info('Sender: --- testSendBlobMessage ---'); - connection.addEventListener('message', function messageHandler(evt) { - connection.removeEventListener('message', messageHandler); + connection.addEventListener('message', function(evt) { let msg = evt.data; is(msg, "testIncomingBlobMessage", "Sender: Sender should receive message from Receiver"); let blob = new Blob(["Hello World"], {type : 'text/plain'}); connection.send(blob); aResolve(); - }); + }, {once: true}); }); } function testSendArrayBuffer() { return new Promise(function(aResolve, aReject) { info('Sender: --- testSendArrayBuffer ---'); - connection.addEventListener('message', function messageHandler(evt) { - connection.removeEventListener('message', messageHandler); + connection.addEventListener('message', function(evt) { let msg = evt.data; is(msg, "testIncomingArrayBuffer", "Sender: Sender should receive message from Receiver"); connection.send(DATA_ARRAY_BUFFER); aResolve(); - }); + }, {once: true}); }); } function testSendArrayBufferView() { return new Promise(function(aResolve, aReject) { info('Sender: --- testSendArrayBufferView ---'); - connection.addEventListener('message', function messageHandler(evt) { - connection.removeEventListener('message', messageHandler); + connection.addEventListener('message', function(evt) { let msg = evt.data; is(msg, "testIncomingArrayBufferView", "Sender: Sender should receive message from Receiver"); connection.send(TYPED_DATA_ARRAY); aResolve(); - }); + }, {once: true}); }); } diff --git a/dom/presentation/tests/mochitest/test_presentation_dc_receiver_oop.html b/dom/presentation/tests/mochitest/test_presentation_dc_receiver_oop.html index da6ed88c810b..7412f3066203 100644 --- a/dom/presentation/tests/mochitest/test_presentation_dc_receiver_oop.html +++ b/dom/presentation/tests/mochitest/test_presentation_dc_receiver_oop.html @@ -71,11 +71,10 @@ function setup() { var promise = new Promise(function(aResolve, aReject) { document.body.appendChild(receiverIframe); - receiverIframe.addEventListener("mozbrowserloadstart", function onLoadEnd() { - receiverIframe.removeEventListener("mozbrowserloadstart", onLoadEnd); + receiverIframe.addEventListener("mozbrowserloadstart", function() { var mm = SpecialPowers.getBrowserFrameMessageManager(receiverIframe); mm.loadFrameScript("data:,(" + loadPrivilegedScriptTest.toString() + ")();", false); - }); + }, {once: true}); aResolve(receiverIframe); }); diff --git a/dom/presentation/tests/mochitest/test_presentation_dc_sender.html b/dom/presentation/tests/mochitest/test_presentation_dc_sender.html index 97e252e84069..73c35552db14 100644 --- a/dom/presentation/tests/mochitest/test_presentation_dc_sender.html +++ b/dom/presentation/tests/mochitest/test_presentation_dc_sender.html @@ -148,11 +148,10 @@ function testIncomingMessage() { return new Promise(function(aResolve, aReject) { const incomingMessage = "test incoming message"; - connection.addEventListener('message', function messageHandler(aEvent) { - connection.removeEventListener('message', messageHandler); + connection.addEventListener('message', function(aEvent) { is(aEvent.data, incomingMessage, "An incoming message should be received."); aResolve(); - }); + }, {once: true}); frameScript.sendAsyncMessage('trigger-incoming-message', incomingMessage); }); diff --git a/dom/presentation/tests/mochitest/test_presentation_device_info.html b/dom/presentation/tests/mochitest/test_presentation_device_info.html index 77253e41dba3..44efae7a274f 100644 --- a/dom/presentation/tests/mochitest/test_presentation_device_info.html +++ b/dom/presentation/tests/mochitest/test_presentation_device_info.html @@ -48,8 +48,7 @@ function testForceDiscovery() { function testDeviceAdd() { info('test device add'); return new Promise(function(resolve, reject) { - navigator.mozPresentationDeviceInfo.addEventListener('devicechange', function deviceChangeHandler(e) { - navigator.mozPresentationDeviceInfo.removeEventListener('devicechange', deviceChangeHandler); + navigator.mozPresentationDeviceInfo.addEventListener('devicechange', function(e) { let detail = e.detail; is(detail.type, 'add', 'expected update type'); is(detail.deviceInfo.id, testDevice.id, 'expected device id'); @@ -64,7 +63,7 @@ function testDeviceAdd() { is(devices[0].type, testDevice.type, 'expected device type'); resolve(); }); - }); + }, {once: true}); gScript.sendAsyncMessage('trigger-device-add', testDevice); }); } @@ -74,8 +73,7 @@ function testDeviceUpdate() { return new Promise(function(resolve, reject) { testDevice.name = 'name-update'; - navigator.mozPresentationDeviceInfo.addEventListener('devicechange', function deviceChangeHandler(e) { - navigator.mozPresentationDeviceInfo.removeEventListener('devicechange', deviceChangeHandler); + navigator.mozPresentationDeviceInfo.addEventListener('devicechange', function(e) { let detail = e.detail; is(detail.type, 'update', 'expected update type'); is(detail.deviceInfo.id, testDevice.id, 'expected device id'); @@ -90,7 +88,7 @@ function testDeviceUpdate() { is(devices[0].type, testDevice.type, 'expected device type'); resolve(); }); - }); + }, {once: true}); gScript.sendAsyncMessage('trigger-device-update', testDevice); }); } @@ -98,8 +96,7 @@ function testDeviceUpdate() { function testDeviceRemove() { info('test device remove'); return new Promise(function(resolve, reject) { - navigator.mozPresentationDeviceInfo.addEventListener('devicechange', function deviceChangeHandler(e) { - navigator.mozPresentationDeviceInfo.removeEventListener('devicechange', deviceChangeHandler); + navigator.mozPresentationDeviceInfo.addEventListener('devicechange', function(e) { let detail = e.detail; is(detail.type, 'remove', 'expected update type'); is(detail.deviceInfo.id, testDevice.id, 'expected device id'); @@ -111,7 +108,7 @@ function testDeviceRemove() { is(devices.length, 0, 'expected 0 available device'); resolve(); }); - }); + }, {once: true}); gScript.sendAsyncMessage('trigger-device-remove'); }); } diff --git a/dom/presentation/tests/mochitest/test_presentation_reconnect.html b/dom/presentation/tests/mochitest/test_presentation_reconnect.html index 079b7f5c5ad9..2d14a0d5f7b5 100644 --- a/dom/presentation/tests/mochitest/test_presentation_reconnect.html +++ b/dom/presentation/tests/mochitest/test_presentation_reconnect.html @@ -318,11 +318,10 @@ function testReconnect() { is(aConnection.state, "connected", "Connection should be connected."); const incomingMessage = "test incoming message"; - aConnection.addEventListener('message', function messageHandler(aEvent) { - aConnection.removeEventListener('message', messageHandler); + aConnection.addEventListener('message', function(aEvent) { is(aEvent.data, incomingMessage, "An incoming message should be received."); aResolve(); - }); + }, {once: true}); frameScript.sendAsyncMessage('trigger-incoming-message', incomingMessage); }; diff --git a/dom/presentation/tests/mochitest/test_presentation_tcp_sender.html b/dom/presentation/tests/mochitest/test_presentation_tcp_sender.html index 8df34c884fdd..a57b5bd46d8e 100644 --- a/dom/presentation/tests/mochitest/test_presentation_tcp_sender.html +++ b/dom/presentation/tests/mochitest/test_presentation_tcp_sender.html @@ -142,11 +142,10 @@ function testIncomingMessage() { return new Promise(function(aResolve, aReject) { const incomingMessage = "test incoming message"; - connection.addEventListener('message', function messageHandler(aEvent) { - connection.removeEventListener('message', messageHandler); + connection.addEventListener('message', function(aEvent) { is(aEvent.data, incomingMessage, "An incoming message should be received."); aResolve(); - }); + }, {once: true}); gScript.sendAsyncMessage('trigger-incoming-message', incomingMessage); }); diff --git a/dom/presentation/tests/mochitest/test_presentation_terminate.js b/dom/presentation/tests/mochitest/test_presentation_terminate.js index 62ed9cf5b23d..e259568001a2 100644 --- a/dom/presentation/tests/mochitest/test_presentation_terminate.js +++ b/dom/presentation/tests/mochitest/test_presentation_terminate.js @@ -37,10 +37,9 @@ function setup() { receiverIframe.setAttribute('remote', oop); receiverIframe.setAttribute('src', receiverUrl); - receiverIframe.addEventListener('mozbrowserloadend', function mozbrowserloadendHander() { - receiverIframe.removeEventListener('mozbrowserloadend', mozbrowserloadendHander); + receiverIframe.addEventListener('mozbrowserloadend', function() { info('Receiver loaded.'); - }); + }, {once: true}); // This event is triggered when the iframe calls 'alert'. receiverIframe.addEventListener('mozbrowsershowmodalprompt', function receiverListener(evt) { diff --git a/dom/presentation/tests/mochitest/test_presentation_terminate_establish_connection_error.js b/dom/presentation/tests/mochitest/test_presentation_terminate_establish_connection_error.js index b7fffd7fb9fd..69d0d26be49b 100644 --- a/dom/presentation/tests/mochitest/test_presentation_terminate_establish_connection_error.js +++ b/dom/presentation/tests/mochitest/test_presentation_terminate_establish_connection_error.js @@ -42,10 +42,9 @@ function setup() { receiverIframe.setAttribute('remote', oop); receiverIframe.setAttribute('src', receiverUrl); - receiverIframe.addEventListener('mozbrowserloadend', function mozbrowserloadendHander() { - receiverIframe.removeEventListener('mozbrowserloadend', mozbrowserloadendHander); + receiverIframe.addEventListener('mozbrowserloadend', function() { info('Receiver loaded.'); - }); + }, {once: true}); // This event is triggered when the iframe calls 'alert'. receiverIframe.addEventListener('mozbrowsershowmodalprompt', function receiverListener(evt) { diff --git a/dom/smil/test/test_smilHyperlinking.xhtml b/dom/smil/test/test_smilHyperlinking.xhtml index 5d8970b6930b..9b18ba6e8285 100644 --- a/dom/smil/test/test_smilHyperlinking.xhtml +++ b/dom/smil/test/test_smilHyperlinking.xhtml @@ -207,19 +207,17 @@ function fireLink(callback) { } else { window.location.hash = ''; window.addEventListener("hashchange", - function clearHash() { - window.removeEventListener("hashchange", clearHash); + function() { window.setTimeout(fireLinkPart2, 0, callback); - }); + }, {once: true}); } } function fireLinkPart2(callback) { window.addEventListener("hashchange", - function triggerCallback() { - window.removeEventListener("hashchange", triggerCallback); + function() { window.setTimeout(callback, 0); - }); + }, {once: true}); window.location.hash = '#anim'; } diff --git a/dom/tests/browser/browser_ConsoleStoragePBTest_perwindowpb.js b/dom/tests/browser/browser_ConsoleStoragePBTest_perwindowpb.js index 169c68cce58f..6044a4114f48 100644 --- a/dom/tests/browser/browser_ConsoleStoragePBTest_perwindowpb.js +++ b/dom/tests/browser/browser_ConsoleStoragePBTest_perwindowpb.js @@ -23,16 +23,13 @@ function test() { function whenNewWindowLoaded(aOptions, aCallback) { let win = OpenBrowserWindow(aOptions); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); + win.addEventListener("load", function() { aCallback(win); - }); + }, {once: true}); } function doTest(aIsPrivateMode, aWindow, aCallback) { - aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); - + aWindow.gBrowser.selectedBrowser.addEventListener("load", function() { consoleObserver = { observe: function(aSubject, aTopic, aData) { if (aTopic == "console-api-log-event") { @@ -51,7 +48,7 @@ function test() { aWindow.Services.obs.addObserver( consoleObserver, "console-api-log-event", false); aWindow.nativeConsole.log("foo bar baz (private: " + aIsPrivateMode + ")"); - }, true); + }, {capture: true, once: true}); // We expect that console API messages are always stored. storageShouldOccur = true; diff --git a/dom/tests/browser/browser_localStorage_privatestorageevent.js b/dom/tests/browser/browser_localStorage_privatestorageevent.js index 814726e84bb0..0439a16ed4e1 100644 --- a/dom/tests/browser/browser_localStorage_privatestorageevent.js +++ b/dom/tests/browser/browser_localStorage_privatestorageevent.js @@ -1,18 +1,16 @@ add_task(function *() { var privWin = OpenBrowserWindow({private: true}); yield new privWin.Promise(resolve => { - privWin.addEventListener('load', function onLoad() { - privWin.removeEventListener('load', onLoad); + privWin.addEventListener('load', function() { resolve(); - }); + }, {once: true}); }); var pubWin = OpenBrowserWindow({private: false}); yield new pubWin.Promise(resolve => { - pubWin.addEventListener('load', function onLoad() { - pubWin.removeEventListener('load', onLoad); + pubWin.addEventListener('load', function() { resolve(); - }); + }, {once: true}); }); var URL = "http://mochi.test:8888/browser/dom/tests/browser/page_privatestorageevent.html"; diff --git a/dom/tests/browser/browser_prerendering.js b/dom/tests/browser/browser_prerendering.js index e92c7d32fa3a..213339f177d0 100644 --- a/dom/tests/browser/browser_prerendering.js +++ b/dom/tests/browser/browser_prerendering.js @@ -17,11 +17,10 @@ function prerenderedVisited() { // Wait for a process change and then fulfil the promise. function awaitProcessChange(browser) { return new Promise(resolve => { - browser.addEventListener("BrowserChangedProcess", function bcp(e) { - browser.removeEventListener("BrowserChangedProcess", bcp); + browser.addEventListener("BrowserChangedProcess", function(e) { info("The browser changed process!"); resolve(); - }); + }, {once: true}); }); } @@ -158,14 +157,13 @@ add_task(function* () { BrowserTestUtils.browserLoaded(tab.linkedBrowser), new Promise(resolve => { let seen = false; - gBrowser.tabContainer.addEventListener("TabClose", function f() { - gBrowser.tabContainer.removeEventListener("TabClose", f); + gBrowser.tabContainer.addEventListener("TabClose", function() { if (!seen) { seen = true; info("The tab was closed"); resolve(); } - }); + }, {once: true}); }), ]); diff --git a/dom/tests/browser/prevent_return_key.html b/dom/tests/browser/prevent_return_key.html index 20351438ca3c..d7dcee62ec89 100644 --- a/dom/tests/browser/prevent_return_key.html +++ b/dom/tests/browser/prevent_return_key.html @@ -7,20 +7,18 @@ function init() { let input = document.getElementById("input"); input.addEventListener("keydown", function(aEvent) { - input.removeEventListener("keydown", arguments.callee); if (aEvent.keyCode == 13) { // return key alert("Hello!"); aEvent.preventDefault(); return false; } - }); + }, {once: true}); let form = document.getElementById("form"); form.addEventListener("submit", function() { - form.removeEventListener("submit", arguments.callee); let result = document.getElementById("result"); result.innerHTML = "submitted"; - }); + }, {once: true}); } diff --git a/dom/tests/mochitest/bugs/test_bug1171215.html b/dom/tests/mochitest/bugs/test_bug1171215.html index d989fb62e548..774f3a5ae4ff 100644 --- a/dom/tests/mochitest/bugs/test_bug1171215.html +++ b/dom/tests/mochitest/bugs/test_bug1171215.html @@ -34,11 +34,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1022869 function waitForLoad() { return new Promise((resolve) => { - window.addEventListener("message", function received(msg) { - window.removeEventListener("message", received); + window.addEventListener("message", function(msg) { info(`got message ${msg.data}`); resolve(msg.data); - }); + }, {once: true}); }); } diff --git a/dom/tests/mochitest/bugs/test_errorReporting.html b/dom/tests/mochitest/bugs/test_errorReporting.html index 8ca001f9a416..8a83ea6f9c3e 100644 --- a/dom/tests/mochitest/bugs/test_errorReporting.html +++ b/dom/tests/mochitest/bugs/test_errorReporting.html @@ -15,8 +15,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1070842 function testErrorReportingHelper(f, rgxp, preventDefault) { return new Promise(function(resolve, reject) { - window.addEventListener('error', function l(e) { - window.removeEventListener('error', l); + window.addEventListener('error', function(e) { ok(rgxp.test(e.message), "Should get message matching " + rgxp + ". Got: " + e.message); var expectedMessages; if (preventDefault) { @@ -27,7 +26,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1070842 } SimpleTest.monitorConsole(resolve, expectedMessages, /* forbidUnexpectedMsgs = */ true); setTimeout(SimpleTest.endMonitorConsole.bind(SimpleTest), 0); - }); + }, {once: true}); // Notify the test harness to avoid treating the next exception as a test failure. SimpleTest.expectUncaughtException(); diff --git a/dom/tests/mochitest/general/file_clonewrapper.html b/dom/tests/mochitest/general/file_clonewrapper.html index 811147d7804d..18e0505d869b 100644 --- a/dom/tests/mochitest/general/file_clonewrapper.html +++ b/dom/tests/mochitest/general/file_clonewrapper.html @@ -5,10 +5,9 @@ function waitForMessage() { return new Promise(function(resolve) { - window.addEventListener('message', function l(evt) { - window.removeEventListener('message', l); + window.addEventListener('message', function(evt) { resolve(evt.data); - }); + }, {once: true}); }); } diff --git a/dom/tests/mochitest/general/test_contentViewer_overrideDPPX.html b/dom/tests/mochitest/general/test_contentViewer_overrideDPPX.html index f7e2024f6264..01696b09a3f4 100644 --- a/dom/tests/mochitest/general/test_contentViewer_overrideDPPX.html +++ b/dom/tests/mochitest/general/test_contentViewer_overrideDPPX.html @@ -306,9 +306,7 @@ const gTests = { is(frameCurrentFontSize, "32px", "frame's font size has the expected value."); - frameWindow.frameElement.addEventListener("load", function listener() { - this.removeEventListener("load", listener); - + frameWindow.frameElement.addEventListener("load", function() { frameStyle = createFontStyleForDPPX(frameWindow.document, dppx, "32"); frameCurrentFontSize = getBodyFontSize(frameWindow); @@ -325,7 +323,7 @@ const gTests = { setOverrideDPPX(0); done(); - }); + }, {once: true}); frameWindow.location.reload(true); } diff --git a/dom/tests/mochitest/localstorage/test_localStorageBasePrivateBrowsing_perwindowpb.html b/dom/tests/mochitest/localstorage/test_localStorageBasePrivateBrowsing_perwindowpb.html index 94478f63b809..65d1aae188f9 100644 --- a/dom/tests/mochitest/localstorage/test_localStorageBasePrivateBrowsing_perwindowpb.html +++ b/dom/tests/mochitest/localstorage/test_localStorageBasePrivateBrowsing_perwindowpb.html @@ -30,8 +30,7 @@ var contentPage = "http://mochi.test:8888/chrome/dom/tests/mochitest/localstorag function testOnWindow(aIsPrivate, aCallback) { var win = mainWindow.OpenBrowserWindow({private: aIsPrivate}); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); + win.addEventListener("load", function() { win.addEventListener("DOMContentLoaded", function onInnerLoad() { if (win.content.location.href == "about:privatebrowsing") { win.gBrowser.loadURI(contentPage); @@ -41,7 +40,7 @@ function testOnWindow(aIsPrivate, aCallback) { SimpleTest.executeSoon(function() { aCallback(win); }); }, true); win.gBrowser.loadURI(contentPage); - }, true); + }, {capture: true, once: true}); } function doTest() { diff --git a/dom/tests/mochitest/localstorage/test_localStorageQuotaPrivateBrowsing_perwindowpb.html b/dom/tests/mochitest/localstorage/test_localStorageQuotaPrivateBrowsing_perwindowpb.html index 15b1c863f3ab..fd5861db29e4 100644 --- a/dom/tests/mochitest/localstorage/test_localStorageQuotaPrivateBrowsing_perwindowpb.html +++ b/dom/tests/mochitest/localstorage/test_localStorageQuotaPrivateBrowsing_perwindowpb.html @@ -164,10 +164,9 @@ function whenDelayedStartupFinished(aWindow, aCallback) { } if (aWindow.content == null || aWindow.content.location.href != CONTENT_PAGE ) { - aWindow.addEventListener("DOMContentLoaded", function onInnerLoad() { - aWindow.removeEventListener("DOMContentLoaded", onInnerLoad, true); + aWindow.addEventListener("DOMContentLoaded", function() { SimpleTest.executeSoon(function() { aCallback(aWindow); }); - }, true); + }, {capture: true, once: true}); aWindow.gBrowser.loadURI(CONTENT_PAGE); } diff --git a/dom/workers/test/head.js b/dom/workers/test/head.js index 5f0c5c26ecbf..3aa6df500784 100644 --- a/dom/workers/test/head.js +++ b/dom/workers/test/head.js @@ -16,10 +16,9 @@ function addTab(url) { let linkedBrowser = tab.linkedBrowser; linkedBrowser.messageManager.loadFrameScript(FRAME_SCRIPT_URL, false); return new Promise(function (resolve) { - linkedBrowser.addEventListener("load", function onload() { - linkedBrowser.removeEventListener("load", onload, true); + linkedBrowser.addEventListener("load", function() { resolve(tab); - }, true); + }, {capture: true, once: true}); }); } diff --git a/dom/workers/test/serviceworkers/browser_download.js b/dom/workers/test/serviceworkers/browser_download.js index 79fb4e53cdca..f9a7b524e9ee 100644 --- a/dom/workers/test/serviceworkers/browser_download.js +++ b/dom/workers/test/serviceworkers/browser_download.js @@ -25,8 +25,7 @@ function windowObserver(win, topic) { return; } - win.addEventListener('load', function onLoadWindow() { - win.removeEventListener('load', onLoadWindow); + win.addEventListener('load', function() { if (win.document.documentURI === 'chrome://mozapps/content/downloads/unknownContentType.xul') { executeSoon(function() { @@ -35,7 +34,7 @@ function windowObserver(win, topic) { win.document.documentElement.acceptDialog(); }); } - }); + }, {once: true}); } function test() { diff --git a/dom/workers/test/serviceworkers/test_file_blob_response.html b/dom/workers/test/serviceworkers/test_file_blob_response.html index 6db0656c666e..366271c8dc5e 100644 --- a/dom/workers/test/serviceworkers/test_file_blob_response.html +++ b/dom/workers/test/serviceworkers/test_file_blob_response.html @@ -49,10 +49,9 @@ frame.setAttribute('src', url); content.appendChild(frame); - frame.addEventListener('load', function loadCallback(evt) { - frame.removeEventListener('load', loadCallback); + frame.addEventListener('load', function(evt) { resolve(frame); - }); + }, {once: true}); }); } diff --git a/dom/workers/test/serviceworkers/test_file_blob_upload.html b/dom/workers/test/serviceworkers/test_file_blob_upload.html index 30a31eb7e854..3106d6211073 100644 --- a/dom/workers/test/serviceworkers/test_file_blob_upload.html +++ b/dom/workers/test/serviceworkers/test_file_blob_upload.html @@ -44,21 +44,19 @@ content.appendChild(iframe); return new Promise(function(resolve, reject) { - window.addEventListener('message', function readyCallback(evt) { - window.removeEventListener('message', readyCallback); + window.addEventListener('message', function(evt) { if (evt.data.status === 'READY') { resolve(); } else { reject(evt.data.result); } - }); + }, {once: true}); }); } function postBlob(body) { return new Promise(function(resolve, reject) { - window.addEventListener('message', function postBlobCallback(evt) { - window.removeEventListener('message', postBlobCallback); + window.addEventListener('message', function(evt) { if (evt.data.status === 'OK') { is(JSON.stringify(body), JSON.stringify(evt.data.result), 'body echoed back correctly'); @@ -66,7 +64,7 @@ } else { reject(evt.data.result); } - }); + }, {once: true}); iframe.contentWindow.postMessage({ type: 'TEST', body: body }, '*'); }); diff --git a/dom/workers/test/serviceworkers/test_privateBrowsing.html b/dom/workers/test/serviceworkers/test_privateBrowsing.html index 7d4706560569..785aab585a3e 100644 --- a/dom/workers/test/serviceworkers/test_privateBrowsing.html +++ b/dom/workers/test/serviceworkers/test_privateBrowsing.html @@ -17,8 +17,7 @@ var workerURL = workerScope + "worker.js"; function testOnWindow(aIsPrivate, aCallback) { var win = mainWindow.OpenBrowserWindow({private: aIsPrivate}); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); + win.addEventListener("load", function() { win.addEventListener("DOMContentLoaded", function onInnerLoad() { if (win.content.location.href != contentPage) { win.gBrowser.loadURI(contentPage); @@ -32,7 +31,7 @@ function testOnWindow(aIsPrivate, aCallback) { if (!aIsPrivate) { win.gBrowser.loadURI(contentPage); } - }, true); + }, {capture: true, once: true}); } function setupWindow() { diff --git a/dom/workers/test/test_sharedWorker_privateBrowsing.html b/dom/workers/test/test_sharedWorker_privateBrowsing.html index cab1d3850c6a..84c0d6e1830c 100644 --- a/dom/workers/test/test_sharedWorker_privateBrowsing.html +++ b/dom/workers/test/test_sharedWorker_privateBrowsing.html @@ -15,8 +15,7 @@ var contentPage = "http://mochi.test:8888/chrome/dom/workers/test/empty.html"; function testOnWindow(aIsPrivate, aCallback) { var win = mainWindow.OpenBrowserWindow({private: aIsPrivate}); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); + win.addEventListener("load", function() { win.addEventListener("DOMContentLoaded", function onInnerLoad() { if (win.content.location.href != contentPage) { win.gBrowser.loadURI(contentPage); @@ -30,7 +29,7 @@ function testOnWindow(aIsPrivate, aCallback) { if (!aIsPrivate) { win.gBrowser.loadURI(contentPage); } - }, true); + }, {capture: true, once: true}); } function setupWindow() { diff --git a/dom/xbl/test/file_bug944407.xml b/dom/xbl/test/file_bug944407.xml index e48271b9f3d4..5fb55dfde4b5 100644 --- a/dom/xbl/test/file_bug944407.xml +++ b/dom/xbl/test/file_bug944407.xml @@ -55,15 +55,14 @@ info("Invoked constructor for " + this.id); var t = this; - window.addEventListener('load', function loadListener() { - window.removeEventListener('load', loadListener); + window.addEventListener('load', function() { // Wait two refresh-driver ticks to make sure that the constructor runs // for both |allow| and |deny| if it's ever going to. // // See bug 944407 comment 37. info("Invoked load listener for " + t.id); window.requestAnimationFrame(function() { window.requestAnimationFrame(t.startTest.bind(t)); }); - }); + }, {once: true}); ]]> diff --git a/editor/composer/test/test_bug519928.html b/editor/composer/test/test_bug519928.html index 66115afba0fe..a46045d5b91a 100644 --- a/editor/composer/test/test_bug519928.html +++ b/editor/composer/test/test_bug519928.html @@ -38,12 +38,10 @@ function expectJSAllowed(allowed, testCondition, callback) { doc.body.innerHTML = ""; var innerFrame = doc.querySelector("iframe"); innerFrame.addEventListener("load", function() { - innerFrame.removeEventListener("load", arguments.callee); - var msg = "The inner iframe should" + (allowed ? "" : " not") + " be able to run Javascript"; is(self_.ICanRunMyJS, allowed, msg); callback(); - }); + }, {once: true}); var iframeSrc = "data:text/html, diff --git a/layout/reftests/css-animations/no-stacking-context-transform-removing-animation-in-delay.html b/layout/reftests/css-animations/no-stacking-context-transform-removing-animation-in-delay.html index 23631e452a19..2e4cd9abe27f 100644 --- a/layout/reftests/css-animations/no-stacking-context-transform-removing-animation-in-delay.html +++ b/layout/reftests/css-animations/no-stacking-context-transform-removing-animation-in-delay.html @@ -29,8 +29,7 @@ window.addEventListener("load", () => { // We need to wait for MozAfterPaint instead of requestAnimationFrame to // ensure the stacking context has been updated on the compositor. - window.addEventListener("MozAfterPaint", function firstPaint() { - window.removeEventListener("MozAfterPaint", firstPaint); + window.addEventListener("MozAfterPaint", function() { // Here we have CSS animation on transform:none style element, so // there should be a stacking context. @@ -42,6 +41,6 @@ window.addEventListener("load", () => { // stacking context. document.documentElement.classList.remove("reftest-wait"); }); - }); + }, {once: true}); }); diff --git a/layout/reftests/layers/component-alpha-exit-1.html b/layout/reftests/layers/component-alpha-exit-1.html index adebf2994a54..cda3d740a45f 100644 --- a/layout/reftests/layers/component-alpha-exit-1.html +++ b/layout/reftests/layers/component-alpha-exit-1.html @@ -4,11 +4,10 @@ diff --git a/layout/tools/reftest/bootstrap.js b/layout/tools/reftest/bootstrap.js index 2fddad26ddc1..1328a8eb054d 100644 --- a/layout/tools/reftest/bootstrap.js +++ b/layout/tools/reftest/bootstrap.js @@ -13,8 +13,6 @@ var WindowListener = { win = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow); win.addEventListener("load", function listener() { - win.removeEventListener("load", listener); - // Load into any existing windows. let windows = Services.wm.getEnumerator("navigator:browser"); while (windows.hasMoreElements()) { @@ -23,12 +21,11 @@ var WindowListener = { } Cu.import("chrome://reftest/content/reftest.jsm"); - win.addEventListener("pageshow", function listener() { - win.removeEventListener("pageshow", listener); + win.addEventListener("pageshow", function() { // Add setTimeout here because windows.innerWidth/Height are not set yet. win.setTimeout(function() {OnRefTestLoad(win);}, 0); - }); - }); + }, {once: true}); + }, {once: true}); } }; diff --git a/layout/xul/test/browser_bug1163304.js b/layout/xul/test/browser_bug1163304.js index b8e9409ddf3a..554bbc4dc1e5 100644 --- a/layout/xul/test/browser_bug1163304.js +++ b/layout/xul/test/browser_bug1163304.js @@ -10,12 +10,10 @@ function test() { let searchPopup = document.getElementById("PopupSearchAutoComplete"); searchPopup.addEventListener("popupshown", function (aEvent) { - searchPopup.removeEventListener("popupshown", arguments.callee); setTimeout(function () { is(DOMWindowUtils.IMEStatus, DOMWindowUtils.IME_STATUS_ENABLED, "IME should be available even when the popup of searchbar is open"); searchPopup.addEventListener("popuphidden", function (aEvent) { - searchPopup.removeEventListener("popuphidden", arguments.callee); setTimeout(function () { is(DOMWindowUtils.IMEStatus, DOMWindowUtils.IME_STATUS_DISABLED, "IME should not be available when menubar is active"); @@ -25,11 +23,11 @@ function test() { "IME should be available after focus is back to the searchbar"); finish(); }, 0); - }); + }, {once: true}); // Activate the menubar, then, the popup should be closed EventUtils.synthesizeKey("VK_ALT", {}); }, 0); - }); + }, {once: true}); // Open popup of the searchbar EventUtils.synthesizeKey("VK_F4", {}); } diff --git a/mobile/android/chrome/content/WebcompatReporter.js b/mobile/android/chrome/content/WebcompatReporter.js index 6f39f1b648a1..251080ce94be 100644 --- a/mobile/android/chrome/content/WebcompatReporter.js +++ b/mobile/android/chrome/content/WebcompatReporter.js @@ -121,15 +121,13 @@ var WebcompatReporter = { let webcompatURL = `${WEBCOMPAT_ORIGIN}/issues/new?url=${url}&src=mobile-reporter`; if (tabData.data && typeof tabData.data === "string") { - BrowserApp.deck.addEventListener("DOMContentLoaded", function sendDataToTab(event) { - BrowserApp.deck.removeEventListener("DOMContentLoaded", sendDataToTab); - + BrowserApp.deck.addEventListener("DOMContentLoaded", function(event) { if (event.target.defaultView.location.origin === WEBCOMPAT_ORIGIN) { // Waive Xray vision so event.origin is not chrome://browser on the other side. let win = Cu.waiveXrays(event.target.defaultView); win.postMessage(tabData.data, WEBCOMPAT_ORIGIN); } - }); + }, {once: true}); } let isPrivateTab = PrivateBrowsingUtils.isBrowserPrivate(tabData.tab.browser); diff --git a/mobile/android/chrome/content/aboutAccounts.js b/mobile/android/chrome/content/aboutAccounts.js index 4801a76a1e74..ac541bfd922e 100644 --- a/mobile/android/chrome/content/aboutAccounts.js +++ b/mobile/android/chrome/content/aboutAccounts.js @@ -298,15 +298,14 @@ function init() { }); } -document.addEventListener("DOMContentLoaded", function onload() { - document.removeEventListener("DOMContentLoaded", onload, true); +document.addEventListener("DOMContentLoaded", function() { init(); var buttonRetry = document.getElementById('buttonRetry'); buttonRetry.addEventListener('click', retry); var buttonOpenPrefs = document.getElementById('buttonOpenPrefs'); buttonOpenPrefs.addEventListener('click', openPrefs); -}, true); +}, {capture: true, once: true}); // This window is contained in a XUL element. Return the // messageManager of that element, or null. diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index bc79f2b2db3f..155f93dba57a 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -521,9 +521,7 @@ var BrowserApp = { // Notify Java that Gecko has loaded. GlobalEventDispatcher.sendRequest({ type: "Gecko:Ready" }); - this.deck.addEventListener("DOMContentLoaded", function BrowserApp_delayedStartup() { - BrowserApp.deck.removeEventListener("DOMContentLoaded", BrowserApp_delayedStartup); - + this.deck.addEventListener("DOMContentLoaded", function() { InitLater(() => Cu.import("resource://gre/modules/NotificationDB.jsm")); InitLater(() => Services.obs.notifyObservers(window, "browser-delayed-startup-finished", "")); @@ -552,7 +550,7 @@ var BrowserApp = { InitLater(() => Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager)); InitLater(() => LoginManagerParent.init(), window, "LoginManagerParent"); - }); + }, {once: true}); // Pass caret StateChanged events to ActionBarHandler. window.addEventListener("mozcaretstatechanged", e => { diff --git a/mobile/android/extensions/flyweb/bootstrap.js b/mobile/android/extensions/flyweb/bootstrap.js index dd3755f912bc..bf437bc7be3d 100644 --- a/mobile/android/extensions/flyweb/bootstrap.js +++ b/mobile/android/extensions/flyweb/bootstrap.js @@ -63,10 +63,9 @@ let windowListener = { onOpenWindow: function(aWindow) { // Wait for the window to finish loading let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow); - domWindow.addEventListener("UIReady", function onLoad() { - domWindow.removeEventListener("UIReady", onLoad); + domWindow.addEventListener("UIReady", function() { loadIntoWindow(domWindow); - }); + }, {once: true}); }, onCloseWindow: function(aWindow) {}, diff --git a/mobile/android/tests/browser/chrome/test_awsy_lite.html b/mobile/android/tests/browser/chrome/test_awsy_lite.html index 9d17eac08100..6b9bca8e24e9 100644 --- a/mobile/android/tests/browser/chrome/test_awsy_lite.html +++ b/mobile/android/tests/browser/chrome/test_awsy_lite.html @@ -50,10 +50,9 @@ var browserListener = { onOpenWindow: function(aWindow) { var win = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow); - win.addEventListener("UIReady", function listener(aEvent) { - win.removeEventListener("UIReady", listener); + win.addEventListener("UIReady", function(aEvent) { attachTo(win); - }); + }, {once: true}); }, onCloseWindow: function(aWindow) { diff --git a/mobile/android/tests/browser/chrome/test_video_discovery.html b/mobile/android/tests/browser/chrome/test_video_discovery.html index f6fb60bbe56b..4e6ba90b81e1 100644 --- a/mobile/android/tests/browser/chrome/test_video_discovery.html +++ b/mobile/android/tests/browser/chrome/test_video_discovery.html @@ -69,10 +69,9 @@ Migrated from Robocop: https://bugzilla.mozilla.org/show_bug.cgi?id=1184186 // Load our test web page with