Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | // This tests our recovery if a child content process hosting providers |
michael@0 | 6 | // crashes. |
michael@0 | 7 | |
michael@0 | 8 | // A content script we inject into one of our browsers |
michael@0 | 9 | const TEST_CONTENT_HELPER = "chrome://mochitests/content/browser/browser/base/content/test/social/social_crash_content_helper.js"; |
michael@0 | 10 | |
michael@0 | 11 | let {getFrameWorkerHandle} = Cu.import("resource://gre/modules/FrameWorker.jsm", {}); |
michael@0 | 12 | let {Promise} = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise; |
michael@0 | 13 | |
michael@0 | 14 | function test() { |
michael@0 | 15 | waitForExplicitFinish(); |
michael@0 | 16 | |
michael@0 | 17 | // We need to ensure all our workers are in the same content process. |
michael@0 | 18 | Services.prefs.setIntPref("dom.ipc.processCount", 1); |
michael@0 | 19 | |
michael@0 | 20 | // This test generates many uncaught promises that should not cause failures. |
michael@0 | 21 | Promise.Debugging.clearUncaughtErrorObservers(); |
michael@0 | 22 | |
michael@0 | 23 | runSocialTestWithProvider(gProviders, function (finishcb) { |
michael@0 | 24 | runSocialTests(tests, undefined, undefined, function() { |
michael@0 | 25 | Services.prefs.clearUserPref("dom.ipc.processCount"); |
michael@0 | 26 | finishcb(); |
michael@0 | 27 | }); |
michael@0 | 28 | }); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | let gProviders = [ |
michael@0 | 32 | { |
michael@0 | 33 | name: "provider 1", |
michael@0 | 34 | origin: "https://example.com", |
michael@0 | 35 | sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html?provider1", |
michael@0 | 36 | workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js", |
michael@0 | 37 | iconURL: "chrome://branding/content/icon48.png" |
michael@0 | 38 | }, |
michael@0 | 39 | { |
michael@0 | 40 | name: "provider 2", |
michael@0 | 41 | origin: "https://test1.example.com", |
michael@0 | 42 | sidebarURL: "https://test1.example.com/browser/browser/base/content/test/social/social_sidebar.html?provider2", |
michael@0 | 43 | workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js", |
michael@0 | 44 | iconURL: "chrome://branding/content/icon48.png" |
michael@0 | 45 | } |
michael@0 | 46 | ]; |
michael@0 | 47 | |
michael@0 | 48 | var tests = { |
michael@0 | 49 | testCrash: function(next) { |
michael@0 | 50 | // open the sidebar, then crash the child. |
michael@0 | 51 | let sbrowser = document.getElementById("social-sidebar-browser"); |
michael@0 | 52 | onSidebarLoad(function() { |
michael@0 | 53 | // get the browser element for our provider. |
michael@0 | 54 | let fw = getFrameWorkerHandle(gProviders[0].workerURL); |
michael@0 | 55 | fw.port.close(); |
michael@0 | 56 | fw._worker.browserPromise.then(browser => { |
michael@0 | 57 | let mm = browser.messageManager; |
michael@0 | 58 | mm.loadFrameScript(TEST_CONTENT_HELPER, false); |
michael@0 | 59 | // add an observer for the crash - after it sees the crash we attempt |
michael@0 | 60 | // a reload. |
michael@0 | 61 | let observer = new crashObserver(function() { |
michael@0 | 62 | info("Saw the process crash.") |
michael@0 | 63 | Services.obs.removeObserver(observer, 'ipc:content-shutdown'); |
michael@0 | 64 | // Add another sidebar load listener - it should be the error page. |
michael@0 | 65 | onSidebarLoad(function() { |
michael@0 | 66 | ok(sbrowser.contentDocument.location.href.indexOf("about:socialerror?")==0, "is on social error page"); |
michael@0 | 67 | // after reloading, the sidebar should reload |
michael@0 | 68 | onSidebarLoad(function() { |
michael@0 | 69 | // now ping both workers - they should both be alive. |
michael@0 | 70 | ensureWorkerLoaded(gProviders[0], function() { |
michael@0 | 71 | ensureWorkerLoaded(gProviders[1], function() { |
michael@0 | 72 | // and we are done! |
michael@0 | 73 | next(); |
michael@0 | 74 | }); |
michael@0 | 75 | }); |
michael@0 | 76 | }); |
michael@0 | 77 | // click the try-again button. |
michael@0 | 78 | sbrowser.contentDocument.getElementById("btnTryAgain").click(); |
michael@0 | 79 | }); |
michael@0 | 80 | }); |
michael@0 | 81 | Services.obs.addObserver(observer, 'ipc:content-shutdown', false); |
michael@0 | 82 | // and cause the crash. |
michael@0 | 83 | mm.sendAsyncMessage("social-test:crash"); |
michael@0 | 84 | }); |
michael@0 | 85 | }) |
michael@0 | 86 | SocialSidebar.show(); |
michael@0 | 87 | }, |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | function onSidebarLoad(callback) { |
michael@0 | 91 | let sbrowser = document.getElementById("social-sidebar-browser"); |
michael@0 | 92 | sbrowser.addEventListener("load", function load() { |
michael@0 | 93 | sbrowser.removeEventListener("load", load, true); |
michael@0 | 94 | callback(); |
michael@0 | 95 | }, true); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | function ensureWorkerLoaded(manifest, callback) { |
michael@0 | 99 | let fw = getFrameWorkerHandle(manifest.workerURL); |
michael@0 | 100 | // once the worker responds to a ping we know it must be up. |
michael@0 | 101 | let port = fw.port; |
michael@0 | 102 | port.onmessage = function(msg) { |
michael@0 | 103 | if (msg.data.topic == "pong") { |
michael@0 | 104 | port.close(); |
michael@0 | 105 | callback(); |
michael@0 | 106 | } |
michael@0 | 107 | } |
michael@0 | 108 | port.postMessage({topic: "ping"}) |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | // More duplicated code from browser_thumbnails_brackground_crash. |
michael@0 | 112 | // Bug 915518 exists to unify these. |
michael@0 | 113 | |
michael@0 | 114 | // This observer is needed so we can clean up all evidence of the crash so |
michael@0 | 115 | // the testrunner thinks things are peachy. |
michael@0 | 116 | let crashObserver = function(callback) { |
michael@0 | 117 | this.callback = callback; |
michael@0 | 118 | } |
michael@0 | 119 | crashObserver.prototype = { |
michael@0 | 120 | observe: function(subject, topic, data) { |
michael@0 | 121 | is(topic, 'ipc:content-shutdown', 'Received correct observer topic.'); |
michael@0 | 122 | ok(subject instanceof Components.interfaces.nsIPropertyBag2, |
michael@0 | 123 | 'Subject implements nsIPropertyBag2.'); |
michael@0 | 124 | // we might see this called as the process terminates due to previous tests. |
michael@0 | 125 | // We are only looking for "abnormal" exits... |
michael@0 | 126 | if (!subject.hasKey("abnormal")) { |
michael@0 | 127 | info("This is a normal termination and isn't the one we are looking for..."); |
michael@0 | 128 | return; |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | var dumpID; |
michael@0 | 132 | if ('nsICrashReporter' in Components.interfaces) { |
michael@0 | 133 | dumpID = subject.getPropertyAsAString('dumpID'); |
michael@0 | 134 | ok(dumpID, "dumpID is present and not an empty string"); |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | if (dumpID) { |
michael@0 | 138 | var minidumpDirectory = getMinidumpDirectory(); |
michael@0 | 139 | removeFile(minidumpDirectory, dumpID + '.dmp'); |
michael@0 | 140 | removeFile(minidumpDirectory, dumpID + '.extra'); |
michael@0 | 141 | } |
michael@0 | 142 | this.callback(); |
michael@0 | 143 | } |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | function getMinidumpDirectory() { |
michael@0 | 147 | var dir = Services.dirsvc.get('ProfD', Components.interfaces.nsIFile); |
michael@0 | 148 | dir.append("minidumps"); |
michael@0 | 149 | return dir; |
michael@0 | 150 | } |
michael@0 | 151 | function removeFile(directory, filename) { |
michael@0 | 152 | var file = directory.clone(); |
michael@0 | 153 | file.append(filename); |
michael@0 | 154 | if (file.exists()) { |
michael@0 | 155 | file.remove(false); |
michael@0 | 156 | } |
michael@0 | 157 | } |