Reland "idle-detection: Implement requestPermission() method"

This reverts commit b49f79c472eefc9c51973be205e07cb397f68589.

Reason for revert: https://crbug.com/1129639

Original change's description:
> Revert "idle-detection: Implement requestPermission() method"
>
> This reverts commit 67a8dbc31af629c51d6661c1b1d6da4218258ad8.
>
> Reason for revert: https://crbug.com/1129639
>
> Original change's description:
> > idle-detection: Implement requestPermission() method
> >
> > This change implements a static requestPermission() method on the
> > IdleDetector interface and switches the API from requiring the
> > "notifications" permission to the new "idle-detector" permission.
> >
> > Bug: 878979
> > Change-Id: If2162f6a1f770544aeb82f98fcc65a76059b7d13
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2359539
> > Auto-Submit: Reilly Grant <reillyg@chromium.org>
> > Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
> > Reviewed-by: Ayu Ishii <ayui@chromium.org>
> > Commit-Queue: Reilly Grant <reillyg@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#808019}
>
> TBR=reillyg@chromium.org,arthursonzogni@chromium.org,ayui@chromium.org
>
> Change-Id: I41401a81e0e75613340ebe8aa5665c3d1a45414c
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: 878979
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2417473
> Reviewed-by: Shik Chen <shik@chromium.org>
> Commit-Queue: Shik Chen <shik@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#808208}

TBR=shik@chromium.org,reillyg@chromium.org,arthursonzogni@chromium.org,ayui@chromium.org

Bug: 878979
Change-Id: I4f409d8f37091f384883c22a39e08f7e45762aa9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2417779
Commit-Queue: Wei Lee <wtlee@chromium.org>
Reviewed-by: Wei Lee <wtlee@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808280}
diff --git a/idle-detection/basics.tentative.https.window.js b/idle-detection/basics.tentative.https.window.js
index 8abbbb7..7fa8578 100644
--- a/idle-detection/basics.tentative.https.window.js
+++ b/idle-detection/basics.tentative.https.window.js
@@ -5,7 +5,7 @@
 'use strict';
 
 promise_setup(async t => {
-  await test_driver.set_permission({ name: 'notifications' }, 'granted', false);
+  await test_driver.set_permission({name: 'idle-detection'}, 'granted', false);
 })
 
 promise_test(async t => {
diff --git a/idle-detection/idle-detection-allowed-by-feature-policy-attribute-redirect-on-load.https.sub.html b/idle-detection/idle-detection-allowed-by-feature-policy-attribute-redirect-on-load.https.sub.html
index 5f5b5a8..6c6ff6f 100644
--- a/idle-detection/idle-detection-allowed-by-feature-policy-attribute-redirect-on-load.https.sub.html
+++ b/idle-detection/idle-detection-allowed-by-feature-policy-attribute-redirect-on-load.https.sub.html
@@ -21,7 +21,7 @@
   relative_worker_frame_path;
 
 promise_setup(async () => {
-  await test_driver.set_permission({ name: 'notifications' }, 'granted', false);
+  await test_driver.set_permission({ name: 'idle-detection' }, 'granted', false);
 });
 
 promise_test(async t => {
diff --git a/idle-detection/idle-detection-allowed-by-feature-policy-attribute.https.sub.html b/idle-detection/idle-detection-allowed-by-feature-policy-attribute.https.sub.html
index 06d58bc..f3cfa0e 100644
--- a/idle-detection/idle-detection-allowed-by-feature-policy-attribute.https.sub.html
+++ b/idle-detection/idle-detection-allowed-by-feature-policy-attribute.https.sub.html
@@ -17,7 +17,7 @@
 const cross_origin_worker_frame_src = sub + same_origin_worker_frame_src;
 
 promise_setup(async () => {
-  await test_driver.set_permission({ name: 'notifications' }, 'granted', false);
+  await test_driver.set_permission({ name: 'idle-detection' }, 'granted', false);
 });
 
 promise_test(async t => {
diff --git a/idle-detection/idle-detection-allowed-by-feature-policy.https.sub.html b/idle-detection/idle-detection-allowed-by-feature-policy.https.sub.html
index 10cce8b..75d1540 100644
--- a/idle-detection/idle-detection-allowed-by-feature-policy.https.sub.html
+++ b/idle-detection/idle-detection-allowed-by-feature-policy.https.sub.html
@@ -17,7 +17,7 @@
 const cross_origin_worker_frame_src = sub + same_origin_worker_frame_src;
 
 promise_setup(async () => {
-  await test_driver.set_permission({ name: 'notifications' }, 'granted', false);
+  await test_driver.set_permission({ name: 'idle-detection' }, 'granted', false);
 });
 
 promise_test(async t => {
diff --git a/idle-detection/idle-detection-default-feature-policy.https.sub.html b/idle-detection/idle-detection-default-feature-policy.https.sub.html
index 4eaf6c3..f0766ae 100644
--- a/idle-detection/idle-detection-default-feature-policy.https.sub.html
+++ b/idle-detection/idle-detection-default-feature-policy.https.sub.html
@@ -14,7 +14,7 @@
   same_origin_src;
 
 promise_setup(async () => {
-  await test_driver.set_permission({ name: 'notifications' }, 'granted', false);
+  await test_driver.set_permission({ name: 'idle-detection' }, 'granted', false);
 });
 
 promise_test(async t => {
diff --git a/idle-detection/idle-permission.tentative.https.window.js b/idle-detection/idle-permission.tentative.https.window.js
index af83876..b6c66e9 100644
--- a/idle-detection/idle-permission.tentative.https.window.js
+++ b/idle-detection/idle-permission.tentative.https.window.js
@@ -3,22 +3,32 @@
 'use strict';
 
 promise_test(async t => {
-    await test_driver.set_permission(
-        { name: 'notifications' }, 'denied', false);
+  await test_driver.set_permission({name: 'idle-detection'}, 'denied', false);
 
-    let detector = new IdleDetector();
-    await promise_rejects_dom(t, 'NotAllowedError', detector.start());
-}, "Deny notifications permission should work.");
+  let detector = new IdleDetector();
+  await promise_rejects_dom(t, 'NotAllowedError', detector.start());
+}, 'Denying idle-detection permission should block access.');
 
 promise_test(async t => {
-    await test_driver.set_permission(
-        { name: 'notifications' }, 'granted', false);
+  await test_driver.set_permission({name: 'idle-detection'}, 'granted', false);
 
-    let detector = new IdleDetector();
-    await detector.start();
+  let detector = new IdleDetector();
+  await detector.start();
 
-    assert_true(['active', 'idle'].includes(detector.userState),
-                  'has a valid user state');
-    assert_true(['locked', 'unlocked'].includes(detector.screenState),
-                  'has a valid screen state');
-}, "Grant notifications permission should work.");
+  assert_true(
+      ['active', 'idle'].includes(detector.userState),
+      'has a valid user state');
+  assert_true(
+      ['locked', 'unlocked'].includes(detector.screenState),
+      'has a valid screen state');
+}, 'Granting idle-detection permission should allow access.');
+
+promise_test(async t => {
+  await test_driver.set_permission({name: 'idle-detection'}, 'prompt', false);
+
+  await promise_rejects_dom(t, 'NotAllowedError', IdleDetector.requestPermission());
+
+  await test_driver.bless('request permission');
+  let state = await IdleDetector.requestPermission();
+  assert_equals(state, 'prompt');
+}, 'The idle-detection permission cannot be requested without a user gesture');
diff --git a/idle-detection/idlharness-worker.https.window.js b/idle-detection/idlharness-worker.https.window.js
index 9619864..5464e99 100644
--- a/idle-detection/idlharness-worker.https.window.js
+++ b/idle-detection/idlharness-worker.https.window.js
@@ -4,7 +4,7 @@
 'use strict';
 
 promise_test(async t => {
-  await test_driver.set_permission({ name: 'notifications' }, 'granted', false);
+  await test_driver.set_permission({name: 'idle-detection'}, 'granted', false);
 
   await fetch_tests_from_worker(new Worker('resources/idlharness-worker.js'));
 }, 'Run idlharness tests in a worker.');
diff --git a/idle-detection/idlharness.https.window.js b/idle-detection/idlharness.https.window.js
index f2b32d8..98c590f 100644
--- a/idle-detection/idlharness.https.window.js
+++ b/idle-detection/idlharness.https.window.js
@@ -11,7 +11,7 @@
     ['idle-detection.tentative'],
     ['dom', 'html'],
     async (idl_array, t) => {
-      await test_driver.set_permission({ name: 'notifications' }, 'granted', false);
+      await test_driver.set_permission({ name: 'idle-detection' }, 'granted', false);
 
       self.idle = new IdleDetector();
       let watcher = new EventWatcher(t, self.idle, ["change"]);
diff --git a/idle-detection/interceptor.https.html b/idle-detection/interceptor.https.html
index e597bd3..25dea12 100644
--- a/idle-detection/interceptor.https.html
+++ b/idle-detection/interceptor.https.html
@@ -11,7 +11,7 @@
 'use strict';
 
 promise_setup(async t => {
-  await test_driver.set_permission({ name: 'notifications' }, 'granted', false);
+  await test_driver.set_permission({ name: 'idle-detection' }, 'granted', false);
   if (isChromiumBased) {
     await loadChromiumResources();
   }
diff --git a/interfaces/idle-detection.tentative.idl b/interfaces/idle-detection.tentative.idl
index 066e1ed..865370a 100644
--- a/interfaces/idle-detection.tentative.idl
+++ b/interfaces/idle-detection.tentative.idl
@@ -21,5 +21,6 @@
   readonly attribute UserIdleState? userState;
   readonly attribute ScreenIdleState? screenState;
   attribute EventHandler onchange;
+  [Exposed=Window] static Promise<PermissionState> requestPermission();
   Promise<any> start(optional IdleOptions options = {});
 };