From e1b1f205473fc47198d57b256c949b17b3ddfe9e Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 20 Apr 2020 20:11:46 +0000 Subject: [PATCH] Bug 1614462: Part 2e - Migrate desktop-only CrashService_crash test to browser test. r=mconley Differential Revision: https://phabricator.services.mozilla.com/D70746 --- dom/base/MessageManagerGlobal.cpp | 8 -- dom/base/MessageManagerGlobal.h | 1 - dom/chrome-webidl/MessageManager.webidl | 7 -- dom/ipc/tests/browser.ini | 2 + dom/ipc/tests/browser_CrashService_crash.js | 71 +++++++++++++++ dom/ipc/tests/mochitest.ini | 2 - dom/ipc/tests/test_CrashService_crash.html | 90 ------------------- .../browser/browser_content_url_annotation.js | 2 +- .../lib/configs/browser-test.js | 1 - .../lib/environments/frame-script.js | 1 - 10 files changed, 74 insertions(+), 111 deletions(-) create mode 100644 dom/ipc/tests/browser_CrashService_crash.js delete mode 100644 dom/ipc/tests/test_CrashService_crash.html diff --git a/dom/base/MessageManagerGlobal.cpp b/dom/base/MessageManagerGlobal.cpp index a29d51641657..f8bd98629912 100644 --- a/dom/base/MessageManagerGlobal.cpp +++ b/dom/base/MessageManagerGlobal.cpp @@ -37,14 +37,6 @@ void MessageManagerGlobal::Dump(const nsAString& aStr) { fflush(stdout); } -void MessageManagerGlobal::PrivateNoteIntentionalCrash(ErrorResult& aError) { - if (XRE_IsContentProcess()) { - NoteIntentionalCrash("tab"); - return; - } - aError.Throw(NS_ERROR_NOT_IMPLEMENTED); -} - void MessageManagerGlobal::Atob(const nsAString& aAsciiString, nsAString& aBase64Data, ErrorResult& aError) { aError = nsContentUtils::Atob(aAsciiString, aBase64Data); diff --git a/dom/base/MessageManagerGlobal.h b/dom/base/MessageManagerGlobal.h index a43f2e6d152d..44b77737e5ca 100644 --- a/dom/base/MessageManagerGlobal.h +++ b/dom/base/MessageManagerGlobal.h @@ -110,7 +110,6 @@ class MessageManagerGlobal { // MessageManagerGlobal void Dump(const nsAString& aStr); - void PrivateNoteIntentionalCrash(ErrorResult& aError); void Atob(const nsAString& aAsciiString, nsAString& aBase64Data, ErrorResult& aError); void Btoa(const nsAString& aBase64Data, nsAString& aAsciiString, diff --git a/dom/chrome-webidl/MessageManager.webidl b/dom/chrome-webidl/MessageManager.webidl index 110c2ced334e..54094490e7ea 100644 --- a/dom/chrome-webidl/MessageManager.webidl +++ b/dom/chrome-webidl/MessageManager.webidl @@ -388,13 +388,6 @@ interface mixin MessageManagerGlobal */ void dump(DOMString str); - /** - * If leak detection is enabled, print a note to the leak log that this - * process will intentionally crash. - */ - [Throws] - void privateNoteIntentionalCrash(); - /** * Ascii base64 data to binary data and vice versa */ diff --git a/dom/ipc/tests/browser.ini b/dom/ipc/tests/browser.ini index e8198cd43a3e..cc54c21dc0ca 100644 --- a/dom/ipc/tests/browser.ini +++ b/dom/ipc/tests/browser.ini @@ -6,6 +6,8 @@ support-files = ../../media/test/short.mp4 ../../media/test/owl.mp3 +[browser_CrashService_crash.js] +skip-if = !crashreporter [browser_ProcessPriorityManager.js] skip-if = os != "win" # The Process Priority Manager is only enabled for Windows so far. Bug 1522879. [browser_crash_oopiframe.js] diff --git a/dom/ipc/tests/browser_CrashService_crash.js b/dom/ipc/tests/browser_CrashService_crash.js new file mode 100644 index 000000000000..17fa6d2d3861 --- /dev/null +++ b/dom/ipc/tests/browser_CrashService_crash.js @@ -0,0 +1,71 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Ensures that content crashes are reported to the crash service +// (nsICrashService and CrashManager.jsm). + +/* eslint-disable mozilla/no-arbitrary-setTimeout */ +SimpleTest.requestFlakyTimeout("untriaged"); + +add_task(async function() { + let tab = await BrowserTestUtils.openNewForegroundTab({ + gBrowser, + forceNewProcess: true, + }); + + SimpleTest.expectChildProcessCrash(); + + let crashMan = Services.crashmanager; + + // First, clear the crash record store. + info("Waiting for pruneOldCrashes"); + var future = new Date(Date.now() + 1000 * 60 * 60 * 24); + await crashMan.pruneOldCrashes(future); + + var crashDateMS = Date.now(); + + let crashPromise = BrowserTestUtils.crashFrame(tab.linkedBrowser); + + // Finally, poll for the new crash record. + await new Promise((resolve, reject) => { + function tryGetCrash() { + info("Waiting for getCrashes"); + crashMan.getCrashes().then( + function(crashes) { + if (crashes.length) { + is(crashes.length, 1, "There should be only one record"); + var crash = crashes[0]; + ok( + crash.isOfType( + crashMan.PROCESS_TYPE_CONTENT, + crashMan.CRASH_TYPE_CRASH + ), + "Record should be a content crash" + ); + ok(!!crash.id, "Record should have an ID"); + ok(!!crash.crashDate, "Record should have a crash date"); + var dateMS = crash.crashDate.valueOf(); + var twoMin = 1000 * 60 * 2; + ok( + crashDateMS - twoMin <= dateMS && dateMS <= crashDateMS + twoMin, + `Record's crash date should be nowish: ` + + `now=${crashDateMS} recordDate=${dateMS}` + ); + resolve(); + } else { + setTimeout(tryGetCrash, 1000); + } + }, + function(err) { + reject(err); + } + ); + } + setTimeout(tryGetCrash, 1000); + }); + + await crashPromise; + + await BrowserTestUtils.removeTab(tab); +}); diff --git a/dom/ipc/tests/mochitest.ini b/dom/ipc/tests/mochitest.ini index d3adfaca53e0..37cdd9d48eff 100644 --- a/dom/ipc/tests/mochitest.ini +++ b/dom/ipc/tests/mochitest.ini @@ -1,7 +1,5 @@ [DEFAULT] -[test_CrashService_crash.html] -skip-if = !(crashreporter && !e10s && (toolkit == 'gtk' || toolkit == 'cocoa' || toolkit == 'windows')) [test_temporaryfile_stream.html] skip-if = !e10s || toolkit == 'android' || (os == "win" && processor == "aarch64") # Bug 1525959, aarch64 due to 1531150 support-files = diff --git a/dom/ipc/tests/test_CrashService_crash.html b/dom/ipc/tests/test_CrashService_crash.html deleted file mode 100644 index 44756b3e820f..000000000000 --- a/dom/ipc/tests/test_CrashService_crash.html +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - - - - - - - diff --git a/toolkit/content/tests/browser/browser_content_url_annotation.js b/toolkit/content/tests/browser/browser_content_url_annotation.js index 7e4887b40e85..72180ec2d060 100644 --- a/toolkit/content/tests/browser/browser_content_url_annotation.js +++ b/toolkit/content/tests/browser/browser_content_url_annotation.js @@ -1,7 +1,7 @@ /* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ /* global Services, requestLongerTimeout, TestUtils, BrowserTestUtils, - ok, info, dump, is, Ci, Cu, Components, ctypes, privateNoteIntentionalCrash, + ok, info, dump, is, Ci, Cu, Components, ctypes, gBrowser, add_task, addEventListener, removeEventListener, ContentTask */ "use strict"; diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.js index e78c6f0b6641..596815c85020 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.js @@ -41,7 +41,6 @@ module.exports = { is: false, isnot: false, ok: false, - privateNoteIntentionalCrash: false, record: false, registerCleanupFunction: false, requestLongerTimeout: false, diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/frame-script.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/frame-script.js index f90292204a1d..5c80dd792138 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/frame-script.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/frame-script.js @@ -17,7 +17,6 @@ module.exports = { chromeOuterWindowID: false, content: false, docShell: false, - privateNoteIntentionalCrash: false, processMessageManager: false, removeMessageListener: false, removeWeakMessageListener: false,