{"action":"created","comment":{"url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/pulls/comments/49494355","id":49494355,"diff_hunk":"@@ -0,0 +1,194 @@\n+/**\n+ * Copyright 2015 Google Inc. All rights reserved.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ *\n+ */\n+\n+/* eslint-env browser */\n+\n+// Each service worker that is registered should be given a unique\n+// scope. To achieve this we register it with a scope the same as\n+// an iframe's src that is unique for each test.\n+// Service workers will then be made to claim pages on this scope -\n+// i.e. the iframe\n+var getIframe = function() {\n+  return new Promise(resolve => {\n+    var existingIframe = document.querySelector('.js-test-iframe');\n+    if (existingIframe) {\n+      return resolve(existingIframe);\n+    }\n+\n+    var newIframe = document.createElement('iframe');\n+    newIframe.classList.add('js-test-iframe');\n+    newIframe.src = '/test/iframe/' + Math.random();\n+    newIframe.addEventListener('load', () => {\n+      resolve(newIframe);\n+    });\n+    document.body.appendChild(newIframe);\n+  });\n+};\n+\n+window.testHelper = {\n+  unregisterAllRegistrations: function() {\n+    return navigator.serviceWorker.getRegistrations()\n+      .then(registrations => {\n+        if (registrations.length === 0) {\n+          return Promise.resolve();\n+        }\n+\n+        var unregisterPromises = [];\n+        for (var i = 0; i < registrations.length; i++) {\n+          unregisterPromises.push(\n+            registrations[i].unregister()\n+          );\n+        }\n+        return Promise.all(unregisterPromises);\n+      });\n+  },\n+\n+  clearAllCaches: function() {\n+    return window.caches.keys()\n+      .then(cacheNames => {\n+        if (cacheNames.length === 0) {\n+          return Promise.resolve();\n+        }\n+\n+        var cacheTaskPromises = [];\n+        for (var i = 0; i < cacheNames.length; i++) {\n+          cacheTaskPromises.push(window.caches.delete(cacheNames[i]));\n+        }\n+        return Promise.all(cacheTaskPromises);\n+      });\n+  },\n+\n+  // Waiting for a service worker to install is handy if you only care\n+  // about testing events that have occured in the install event\n+  installSW: function(swUrl) {\n+    return new Promise((resolve, reject) => {\n+      var iframe;\n+      getIframe()\n+      .then(newIframe => {\n+        var options = null;\n+        if (newIframe) {\n+          options = {scope: iframe.contentWindow.location.pathname};\n+          iframe = newIframe;\n+        }\n+\n+        return navigator.serviceWorker.register(swUrl, options);\n+      })\n+      .then(registration => {\n+        if (registration.installing === null) {\n+          throw new Error(swUrl + ' already installed.');\n+        }\n+\n+        // We unregister all service workers after each test - this should\n+        // always trigger an install state change\n+        registration.installing.onstatechange = function() {\n+          if (this.state !== 'installed') {\n+            return;\n+          }\n+\n+          resolve(iframe);\n+        };\n+      })\n+      .catch(err => {","path":"test/libs/helper-functions.js","position":96,"original_position":105,"commit_id":"5d1a3e418826a7c527fef77db1f5853ca7156fb0","original_commit_id":"6a6194c0d63e86e207b95cd72e748f1ecfc59104","user":{"login":"jeffposnick","id":1749548,"avatar_url":"https://avatars.githubusercontent.com/u/1749548?v=3","gravatar_id":"","url":"https://api.github.com/users/jeffposnick","html_url":"https://github.com/jeffposnick","followers_url":"https://api.github.com/users/jeffposnick/followers","following_url":"https://api.github.com/users/jeffposnick/following{/other_user}","gists_url":"https://api.github.com/users/jeffposnick/gists{/gist_id}","starred_url":"https://api.github.com/users/jeffposnick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeffposnick/subscriptions","organizations_url":"https://api.github.com/users/jeffposnick/orgs","repos_url":"https://api.github.com/users/jeffposnick/repos","events_url":"https://api.github.com/users/jeffposnick/events{/privacy}","received_events_url":"https://api.github.com/users/jeffposnick/received_events","type":"User","site_admin":false},"body":"Was that behavior an expected edge case, or a bug? Can you reproduce it?\r\n\r\nAlternatively, you can just return a promise chain that starts with `getIframe()` instead of constructing a new `Promise` wrapper.","created_at":"2016-01-12T18:38:11Z","updated_at":"2016-01-12T18:38:11Z","html_url":"https://github.com/GoogleChrome/sw-toolbox/pull/70#discussion_r49494355","pull_request_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/pulls/70","_links":{"self":{"href":"https://api.github.com/repos/GoogleChrome/sw-toolbox/pulls/comments/49494355"},"html":{"href":"https://github.com/GoogleChrome/sw-toolbox/pull/70#discussion_r49494355"},"pull_request":{"href":"https://api.github.com/repos/GoogleChrome/sw-toolbox/pulls/70"}}},"pull_request":{"url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/pulls/70","id":55750471,"html_url":"https://github.com/GoogleChrome/sw-toolbox/pull/70","diff_url":"https://github.com/GoogleChrome/sw-toolbox/pull/70.diff","patch_url":"https://github.com/GoogleChrome/sw-toolbox/pull/70.patch","issue_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/issues/70","number":70,"state":"open","locked":false,"title":"Adding first take on mocha tests","user":{"login":"gauntface","id":139760,"avatar_url":"https://avatars.githubusercontent.com/u/139760?v=3","gravatar_id":"","url":"https://api.github.com/users/gauntface","html_url":"https://github.com/gauntface","followers_url":"https://api.github.com/users/gauntface/followers","following_url":"https://api.github.com/users/gauntface/following{/other_user}","gists_url":"https://api.github.com/users/gauntface/gists{/gist_id}","starred_url":"https://api.github.com/users/gauntface/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gauntface/subscriptions","organizations_url":"https://api.github.com/users/gauntface/orgs","repos_url":"https://api.github.com/users/gauntface/repos","events_url":"https://api.github.com/users/gauntface/events{/privacy}","received_events_url":"https://api.github.com/users/gauntface/received_events","type":"User","site_admin":false},"body":"This a reduced and slightly tidier version of the wider-test-coverage.\r\n\r\nBreaking up into smaller PR's so it's a bit more manageable to review.\r\n\r\ncc @wibblymat @jeffposnick @addyosmani ","created_at":"2016-01-12T12:21:01Z","updated_at":"2016-01-12T18:38:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"142c117da3978fccef65455620f1d1d9abda80be","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/pulls/70/commits","review_comments_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/pulls/70/comments","review_comment_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/pulls/comments{/number}","comments_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/issues/70/comments","statuses_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/statuses/5d1a3e418826a7c527fef77db1f5853ca7156fb0","head":{"label":"GoogleChrome:mocha-tests","ref":"mocha-tests","sha":"5d1a3e418826a7c527fef77db1f5853ca7156fb0","user":{"login":"GoogleChrome","id":1778935,"avatar_url":"https://avatars.githubusercontent.com/u/1778935?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleChrome","html_url":"https://github.com/GoogleChrome","followers_url":"https://api.github.com/users/GoogleChrome/followers","following_url":"https://api.github.com/users/GoogleChrome/following{/other_user}","gists_url":"https://api.github.com/users/GoogleChrome/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleChrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleChrome/subscriptions","organizations_url":"https://api.github.com/users/GoogleChrome/orgs","repos_url":"https://api.github.com/users/GoogleChrome/repos","events_url":"https://api.github.com/users/GoogleChrome/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleChrome/received_events","type":"Organization","site_admin":false},"repo":{"id":34268206,"name":"sw-toolbox","full_name":"GoogleChrome/sw-toolbox","owner":{"login":"GoogleChrome","id":1778935,"avatar_url":"https://avatars.githubusercontent.com/u/1778935?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleChrome","html_url":"https://github.com/GoogleChrome","followers_url":"https://api.github.com/users/GoogleChrome/followers","following_url":"https://api.github.com/users/GoogleChrome/following{/other_user}","gists_url":"https://api.github.com/users/GoogleChrome/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleChrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleChrome/subscriptions","organizations_url":"https://api.github.com/users/GoogleChrome/orgs","repos_url":"https://api.github.com/users/GoogleChrome/repos","events_url":"https://api.github.com/users/GoogleChrome/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleChrome/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleChrome/sw-toolbox","description":"A collection of tools for service workers.","fork":false,"url":"https://api.github.com/repos/GoogleChrome/sw-toolbox","forks_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/forks","keys_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/teams","hooks_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/hooks","issue_events_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/events","assignees_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/tags","blobs_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/languages","stargazers_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/stargazers","contributors_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/contributors","subscribers_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/subscribers","subscription_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/subscription","commits_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/merges","archive_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/downloads","issues_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/labels{/name}","releases_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/releases{/id}","created_at":"2015-04-20T15:18:05Z","updated_at":"2016-01-12T18:02:10Z","pushed_at":"2016-01-12T18:04:19Z","git_url":"git://github.com/GoogleChrome/sw-toolbox.git","ssh_url":"git@github.com:GoogleChrome/sw-toolbox.git","clone_url":"https://github.com/GoogleChrome/sw-toolbox.git","svn_url":"https://github.com/GoogleChrome/sw-toolbox","homepage":"https://googlechrome.github.io/sw-toolbox/recipes/","size":425,"stargazers_count":489,"watchers_count":489,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":35,"mirror_url":null,"open_issues_count":18,"forks":35,"open_issues":18,"watchers":489,"default_branch":"master"}},"base":{"label":"GoogleChrome:master","ref":"master","sha":"28b5f781612833703e4f7bb93b456436331f58d4","user":{"login":"GoogleChrome","id":1778935,"avatar_url":"https://avatars.githubusercontent.com/u/1778935?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleChrome","html_url":"https://github.com/GoogleChrome","followers_url":"https://api.github.com/users/GoogleChrome/followers","following_url":"https://api.github.com/users/GoogleChrome/following{/other_user}","gists_url":"https://api.github.com/users/GoogleChrome/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleChrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleChrome/subscriptions","organizations_url":"https://api.github.com/users/GoogleChrome/orgs","repos_url":"https://api.github.com/users/GoogleChrome/repos","events_url":"https://api.github.com/users/GoogleChrome/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleChrome/received_events","type":"Organization","site_admin":false},"repo":{"id":34268206,"name":"sw-toolbox","full_name":"GoogleChrome/sw-toolbox","owner":{"login":"GoogleChrome","id":1778935,"avatar_url":"https://avatars.githubusercontent.com/u/1778935?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleChrome","html_url":"https://github.com/GoogleChrome","followers_url":"https://api.github.com/users/GoogleChrome/followers","following_url":"https://api.github.com/users/GoogleChrome/following{/other_user}","gists_url":"https://api.github.com/users/GoogleChrome/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleChrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleChrome/subscriptions","organizations_url":"https://api.github.com/users/GoogleChrome/orgs","repos_url":"https://api.github.com/users/GoogleChrome/repos","events_url":"https://api.github.com/users/GoogleChrome/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleChrome/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleChrome/sw-toolbox","description":"A collection of tools for service workers.","fork":false,"url":"https://api.github.com/repos/GoogleChrome/sw-toolbox","forks_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/forks","keys_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/teams","hooks_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/hooks","issue_events_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/events","assignees_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/tags","blobs_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/languages","stargazers_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/stargazers","contributors_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/contributors","subscribers_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/subscribers","subscription_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/subscription","commits_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/merges","archive_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/downloads","issues_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/labels{/name}","releases_url":"https://api.github.com/repos/GoogleChrome/sw-toolbox/releases{/id}","created_at":"2015-04-20T15:18:05Z","updated_at":"2016-01-12T18:02:10Z","pushed_at":"2016-01-12T18:04:19Z","git_url":"git://github.com/GoogleChrome/sw-toolbox.git","ssh_url":"git@github.com:GoogleChrome/sw-toolbox.git","clone_url":"https://github.com/GoogleChrome/sw-toolbox.git","svn_url":"https://github.com/GoogleChrome/sw-toolbox","homepage":"https://googlechrome.github.io/sw-toolbox/recipes/","size":425,"stargazers_count":489,"watchers_count":489,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":35,"mirror_url":null,"open_issues_count":18,"forks":35,"open_issues":18,"watchers":489,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/GoogleChrome/sw-toolbox/pulls/70"},"html":{"href":"https://github.com/GoogleChrome/sw-toolbox/pull/70"},"issue":{"href":"https://api.github.com/repos/GoogleChrome/sw-toolbox/issues/70"},"comments":{"href":"https://api.github.com/repos/GoogleChrome/sw-toolbox/issues/70/comments"},"review_comments":{"href":"https://api.github.com/repos/GoogleChrome/sw-toolbox/pulls/70/comments"},"review_comment":{"href":"https://api.github.com/repos/GoogleChrome/sw-toolbox/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/GoogleChrome/sw-toolbox/pulls/70/commits"},"statuses":{"href":"https://api.github.com/repos/GoogleChrome/sw-toolbox/statuses/5d1a3e418826a7c527fef77db1f5853ca7156fb0"}}}}