{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/addon-sdk/pulls/comments/25186397","id":25186397,"diff_hunk":"@@ -0,0 +1,581 @@\n+/* This Source Code Form is subject to the terms of the Mozilla Public\n+ * License, v. 2.0. If a copy of the MPL was not distributed with this\n+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */\n+const LOCAL_URI = \"about:robots\";\n+const REMOTE_URI = \"about:home\";\n+const REMOTE_MODULE = \"./remote-module\";\n+\n+const { Loader } = require('sdk/test/loader');\n+const { getTabs, openTab, closeTab, setTabURL, getBrowserForTab, getURI } = require('sdk/tabs/utils');\n+const { getMostRecentBrowserWindow } = require('sdk/window/utils');\n+const { cleanUI } = require(\"sdk/test/utils\");\n+const { setTimeout } = require(\"sdk/timers\");\n+\n+const { Cu } = require('chrome');\n+const { async } = Cu.import('resource://gre/modules/Task.jsm', {}).Task;\n+\n+const { set } = require('sdk/preferences/service');\n+const mainWindow = getMostRecentBrowserWindow();\n+const isE10S = mainWindow.gMultiProcessBrowser;\n+\n+// The hidden preload browser messes up our frame counts\n+set('browser.newtab.preload', false);\n+\n+function promiseEvent(emitter, event) {\n+  console.log(\"Waiting for \" + event);\n+  return new Promise(resolve => {\n+    emitter.once(event, (...args) => {\n+      console.log(\"Saw \" + event);\n+      resolve(args);\n+    });\n+  });\n+}\n+\n+function promiseDOMEvent(target, event, isCapturing = false) {\n+  console.log(\"Waiting for \" + event);\n+  return new Promise(resolve => {\n+    let listener = (event) => {\n+      target.removeEventListener(event, listener, isCapturing);\n+      resolve(event);\n+    };\n+    target.addEventListener(event, listener, isCapturing);\n+  })\n+}\n+\n+promiseEventOnItemAndContainer = async(function*(assert, itemport, container, event, item = itemport) {\n+  let itemEvent = promiseEvent(itemport, event);\n+  let containerEvent = promiseEvent(container, event);\n+\n+  let itemArgs = yield itemEvent;\n+  let [target, ...containerArgs] = yield containerEvent;\n+\n+  assert.equal(target, item, \"Should have seen a container event for the right item\");\n+  assert.equal(JSON.stringify(itemArgs), JSON.stringify(containerArgs), \"Arguments should have matched\");\n+\n+  return itemArgs;\n+});\n+\n+let waitForProcesses = async(function*(loader) {\n+  console.log(\"Starting remote\");\n+  let { processes, frames, remoteRequire } = loader.require('sdk/remote/parent');\n+  remoteRequire(REMOTE_MODULE, module);\n+\n+  let events = [];\n+\n+  // In e10s we should expect to see two processes\n+  let expectedCount = isE10S ? 2 : 1;\n+\n+  yield new Promise(resolve => {\n+    let count = 0;\n+\n+    // Wait for a process to be detected\n+    let listener = process => {\n+      console.log(\"Saw a process attach\");\n+      // Wait for the remote module to load in this process\n+      process.port.once('sdk/test/load', () => {\n+        console.log(\"Saw a remote module load\");\n+        count++;\n+        if (count == expectedCount) {\n+          processes.off('attach', listener);\n+          resolve();\n+        }\n+      });\n+    }\n+    processes.on('attach', listener);\n+  });\n+\n+  console.log(\"Remote ready\");\n+  return { processes, frames, remoteRequire };\n+});\n+\n+if (isE10S) {\n+  console.log(\"Testing in E10S mode\");\n+  // We expect a child process to already be present, make sure that is the case\n+  mainWindow.XULBrowserWindow.forceInitialBrowserRemote();\n+\n+  // Check that we see a process stop and start\n+  exports[\"test process restart\"] = function*(assert) {\n+    let window = getMostRecentBrowserWindow();\n+\n+    let tabs = getTabs(window);\n+    assert.equal(tabs.length, 1, \"Should have just the one tab to start with\");\n+    let tab = tabs[0];\n+\n+    let loader = new Loader(module);\n+    let { processes, frames, remoteRequire } = yield waitForProcesses(loader);\n+\n+    let remoteProcess = Array.filter(processes, p => p.isRemote)[0];\n+    let localProcess = Array.filter(processes, p => !p.isRemote)[0];\n+    let remoteFrame = Array.filter(frames, f => f.process == remoteProcess)[0];\n+\n+    // Switch the remote tab to a local URI which should kill the remote process\n+\n+    let frameDetach = promiseEventOnItemAndContainer(assert, remoteFrame, frames, 'detach');\n+    let frameAttach = promiseEvent(frames, 'attach');\n+    let processDetach = promiseEventOnItemAndContainer(assert, remoteProcess, processes, 'detach');\n+    setTabURL(tab, LOCAL_URI);\n+    // The load should kill the remote frame\n+    yield frameDetach;\n+    // And create a new frame in the local process\n+    let [newFrame] = yield frameAttach;\n+    assert.equal(newFrame.process, localProcess, \"New frame should be in the local process\");\n+    // And kill the process\n+    yield processDetach;\n+\n+    frameDetach = promiseEventOnItemAndContainer(assert, newFrame, frames, 'detach');\n+    processAttach = promiseEvent(processes, 'attach');\n+    frameAttach = promiseEvent(frames, 'attach');\n+    setTabURL(tab, REMOTE_URI);\n+    // The load should kill the remote frame\n+    yield frameDetach;\n+    // And create a new remote process\n+    [remoteProcess] = yield processAttach;\n+    assert.ok(remoteProcess.isRemote, \"Process should be remote\");\n+    // And create a new frame in the remote process\n+    [newFrame] = yield frameAttach;\n+    assert.equal(newFrame.process, remoteProcess, \"New frame should be in the remote process\");\n+\n+    setTabURL(tab, \"about:blank\");\n+\n+    loader.unload();\n+    yield cleanUI();\n+  };\n+}\n+else {\n+  console.log(\"Testing in non-E10S mode\");\n+}\n+\n+// Test that we find the right number of processes and that messaging between\n+// them works and none of the streams cross\n+exports[\"test process list\"] = function*(assert) {\n+  let loader = new Loader(module);\n+  let { processes, frames, remoteRequire } = loader.require('sdk/remote/parent');","path":"test/addons/e10s-remote/main.js","position":152,"original_position":152,"commit_id":"3dd59f7302f867991cb830b11eaaedaa94bf56f6","original_commit_id":"3dd59f7302f867991cb830b11eaaedaa94bf56f6","user":{"login":"erikvold","id":27379,"avatar_url":"https://avatars.githubusercontent.com/u/27379?v=3","gravatar_id":"","url":"https://api.github.com/users/erikvold","html_url":"https://github.com/erikvold","followers_url":"https://api.github.com/users/erikvold/followers","following_url":"https://api.github.com/users/erikvold/following{/other_user}","gists_url":"https://api.github.com/users/erikvold/gists{/gist_id}","starred_url":"https://api.github.com/users/erikvold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikvold/subscriptions","organizations_url":"https://api.github.com/users/erikvold/orgs","repos_url":"https://api.github.com/users/erikvold/repos","events_url":"https://api.github.com/users/erikvold/events{/privacy}","received_events_url":"https://api.github.com/users/erikvold/received_events","type":"User","site_admin":false},"body":"`remoteRequire` doesn't appear to be used in this test.","created_at":"2015-02-23T18:11:37Z","updated_at":"2015-02-23T18:11:37Z","html_url":"https://github.com/mozilla/addon-sdk/pull/1862#discussion_r25186397","pull_request_url":"https://api.github.com/repos/mozilla/addon-sdk/pulls/1862","_links":{"self":{"href":"https://api.github.com/repos/mozilla/addon-sdk/pulls/comments/25186397"},"html":{"href":"https://github.com/mozilla/addon-sdk/pull/1862#discussion_r25186397"},"pull_request":{"href":"https://api.github.com/repos/mozilla/addon-sdk/pulls/1862"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/addon-sdk/pulls/1862","id":29232779,"html_url":"https://github.com/mozilla/addon-sdk/pull/1862","diff_url":"https://github.com/mozilla/addon-sdk/pull/1862.diff","patch_url":"https://github.com/mozilla/addon-sdk/pull/1862.patch","issue_url":"https://api.github.com/repos/mozilla/addon-sdk/issues/1862","number":1862,"state":"open","locked":false,"title":"Bug 1129003: Make page-mod e10s safe and add e10s support modules","user":{"login":"Mossop","id":437326,"avatar_url":"https://avatars.githubusercontent.com/u/437326?v=3","gravatar_id":"","url":"https://api.github.com/users/Mossop","html_url":"https://github.com/Mossop","followers_url":"https://api.github.com/users/Mossop/followers","following_url":"https://api.github.com/users/Mossop/following{/other_user}","gists_url":"https://api.github.com/users/Mossop/gists{/gist_id}","starred_url":"https://api.github.com/users/Mossop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mossop/subscriptions","organizations_url":"https://api.github.com/users/Mossop/orgs","repos_url":"https://api.github.com/users/Mossop/repos","events_url":"https://api.github.com/users/Mossop/events{/privacy}","received_events_url":"https://api.github.com/users/Mossop/received_events","type":"User","site_admin":false},"body":"The first commit adds the remote/parent and remote/child e10s support modules that make it possible to load a module in the child processes (remoteRequire) and hooks up add-on specific event emitters for communication.\r\nThe second commit uses these to make page-mod e10s safe by moving the bulk of the module into the child process.\r\n\r\nThere is one main change here that probably shouldn't affect anyone but is unavoidable. When a page is hidden in history (frozen) its worker no longer throws exceptions when trying to send it messages, there is no way to know if a worker is frozen when the message is first sent. Instead we just queue the messages and they are delivered when the worker thaws.","created_at":"2015-02-13T01:16:45Z","updated_at":"2015-02-23T18:11:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"800cda284618fc93b853f8c7eb94c2c6769074df","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/addon-sdk/pulls/1862/commits","review_comments_url":"https://api.github.com/repos/mozilla/addon-sdk/pulls/1862/comments","review_comment_url":"https://api.github.com/repos/mozilla/addon-sdk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/addon-sdk/issues/1862/comments","statuses_url":"https://api.github.com/repos/mozilla/addon-sdk/statuses/3dd59f7302f867991cb830b11eaaedaa94bf56f6","head":{"label":"Mossop:bug1129003","ref":"bug1129003","sha":"3dd59f7302f867991cb830b11eaaedaa94bf56f6","user":{"login":"Mossop","id":437326,"avatar_url":"https://avatars.githubusercontent.com/u/437326?v=3","gravatar_id":"","url":"https://api.github.com/users/Mossop","html_url":"https://github.com/Mossop","followers_url":"https://api.github.com/users/Mossop/followers","following_url":"https://api.github.com/users/Mossop/following{/other_user}","gists_url":"https://api.github.com/users/Mossop/gists{/gist_id}","starred_url":"https://api.github.com/users/Mossop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mossop/subscriptions","organizations_url":"https://api.github.com/users/Mossop/orgs","repos_url":"https://api.github.com/users/Mossop/repos","events_url":"https://api.github.com/users/Mossop/events{/privacy}","received_events_url":"https://api.github.com/users/Mossop/received_events","type":"User","site_admin":false},"repo":{"id":2672572,"name":"addon-sdk","full_name":"Mossop/addon-sdk","owner":{"login":"Mossop","id":437326,"avatar_url":"https://avatars.githubusercontent.com/u/437326?v=3","gravatar_id":"","url":"https://api.github.com/users/Mossop","html_url":"https://github.com/Mossop","followers_url":"https://api.github.com/users/Mossop/followers","following_url":"https://api.github.com/users/Mossop/following{/other_user}","gists_url":"https://api.github.com/users/Mossop/gists{/gist_id}","starred_url":"https://api.github.com/users/Mossop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mossop/subscriptions","organizations_url":"https://api.github.com/users/Mossop/orgs","repos_url":"https://api.github.com/users/Mossop/repos","events_url":"https://api.github.com/users/Mossop/events{/privacy}","received_events_url":"https://api.github.com/users/Mossop/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Mossop/addon-sdk","description":"The Add-on SDK repository.","fork":true,"url":"https://api.github.com/repos/Mossop/addon-sdk","forks_url":"https://api.github.com/repos/Mossop/addon-sdk/forks","keys_url":"https://api.github.com/repos/Mossop/addon-sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Mossop/addon-sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Mossop/addon-sdk/teams","hooks_url":"https://api.github.com/repos/Mossop/addon-sdk/hooks","issue_events_url":"https://api.github.com/repos/Mossop/addon-sdk/issues/events{/number}","events_url":"https://api.github.com/repos/Mossop/addon-sdk/events","assignees_url":"https://api.github.com/repos/Mossop/addon-sdk/assignees{/user}","branches_url":"https://api.github.com/repos/Mossop/addon-sdk/branches{/branch}","tags_url":"https://api.github.com/repos/Mossop/addon-sdk/tags","blobs_url":"https://api.github.com/repos/Mossop/addon-sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Mossop/addon-sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Mossop/addon-sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/Mossop/addon-sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Mossop/addon-sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/Mossop/addon-sdk/languages","stargazers_url":"https://api.github.com/repos/Mossop/addon-sdk/stargazers","contributors_url":"https://api.github.com/repos/Mossop/addon-sdk/contributors","subscribers_url":"https://api.github.com/repos/Mossop/addon-sdk/subscribers","subscription_url":"https://api.github.com/repos/Mossop/addon-sdk/subscription","commits_url":"https://api.github.com/repos/Mossop/addon-sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/Mossop/addon-sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/Mossop/addon-sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/Mossop/addon-sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/Mossop/addon-sdk/contents/{+path}","compare_url":"https://api.github.com/repos/Mossop/addon-sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Mossop/addon-sdk/merges","archive_url":"https://api.github.com/repos/Mossop/addon-sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Mossop/addon-sdk/downloads","issues_url":"https://api.github.com/repos/Mossop/addon-sdk/issues{/number}","pulls_url":"https://api.github.com/repos/Mossop/addon-sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/Mossop/addon-sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/Mossop/addon-sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Mossop/addon-sdk/labels{/name}","releases_url":"https://api.github.com/repos/Mossop/addon-sdk/releases{/id}","created_at":"2011-10-29T21:10:44Z","updated_at":"2015-02-07T07:07:08Z","pushed_at":"2015-02-17T20:14:43Z","git_url":"git://github.com/Mossop/addon-sdk.git","ssh_url":"git@github.com:Mossop/addon-sdk.git","clone_url":"https://github.com/Mossop/addon-sdk.git","svn_url":"https://github.com/Mossop/addon-sdk","homepage":"https://wiki.mozilla.org/Labs/Jetpack","size":18703,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":4,"default_branch":"master"}},"base":{"label":"mozilla:master","ref":"master","sha":"0aa270ada80c70c1690c9befedf917eca7555d7b","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":748030,"name":"addon-sdk","full_name":"mozilla/addon-sdk","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/addon-sdk","description":"The Add-on SDK repository.","fork":false,"url":"https://api.github.com/repos/mozilla/addon-sdk","forks_url":"https://api.github.com/repos/mozilla/addon-sdk/forks","keys_url":"https://api.github.com/repos/mozilla/addon-sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/addon-sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/addon-sdk/teams","hooks_url":"https://api.github.com/repos/mozilla/addon-sdk/hooks","issue_events_url":"https://api.github.com/repos/mozilla/addon-sdk/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/addon-sdk/events","assignees_url":"https://api.github.com/repos/mozilla/addon-sdk/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/addon-sdk/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/addon-sdk/tags","blobs_url":"https://api.github.com/repos/mozilla/addon-sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/addon-sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/addon-sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/addon-sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/addon-sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/addon-sdk/languages","stargazers_url":"https://api.github.com/repos/mozilla/addon-sdk/stargazers","contributors_url":"https://api.github.com/repos/mozilla/addon-sdk/contributors","subscribers_url":"https://api.github.com/repos/mozilla/addon-sdk/subscribers","subscription_url":"https://api.github.com/repos/mozilla/addon-sdk/subscription","commits_url":"https://api.github.com/repos/mozilla/addon-sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/addon-sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/addon-sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/addon-sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/addon-sdk/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/addon-sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/addon-sdk/merges","archive_url":"https://api.github.com/repos/mozilla/addon-sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/addon-sdk/downloads","issues_url":"https://api.github.com/repos/mozilla/addon-sdk/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/addon-sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/addon-sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/addon-sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/addon-sdk/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/addon-sdk/releases{/id}","created_at":"2010-06-30T00:38:20Z","updated_at":"2015-02-23T11:43:15Z","pushed_at":"2015-02-20T19:07:48Z","git_url":"git://github.com/mozilla/addon-sdk.git","ssh_url":"git@github.com:mozilla/addon-sdk.git","clone_url":"https://github.com/mozilla/addon-sdk.git","svn_url":"https://github.com/mozilla/addon-sdk","homepage":"https://wiki.mozilla.org/Labs/Jetpack","size":40026,"stargazers_count":565,"watchers_count":565,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":289,"mirror_url":null,"open_issues_count":72,"forks":289,"open_issues":72,"watchers":565,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/addon-sdk/pulls/1862"},"html":{"href":"https://github.com/mozilla/addon-sdk/pull/1862"},"issue":{"href":"https://api.github.com/repos/mozilla/addon-sdk/issues/1862"},"comments":{"href":"https://api.github.com/repos/mozilla/addon-sdk/issues/1862/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/addon-sdk/pulls/1862/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/addon-sdk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/addon-sdk/pulls/1862/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/addon-sdk/statuses/3dd59f7302f867991cb830b11eaaedaa94bf56f6"}}}}