Index: chrome/test/data/extensions/api_test/native_bindings/background.js |
diff --git a/chrome/test/data/extensions/api_test/native_bindings/background.js b/chrome/test/data/extensions/api_test/native_bindings/background.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9ec8032cbf407b34a45ca9928cf52f12d8999597 |
--- /dev/null |
+++ b/chrome/test/data/extensions/api_test/native_bindings/background.js |
@@ -0,0 +1,40 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+if (!chrome || !chrome.test) |
+ throw new Error('chrome.test is undefined'); |
+ |
+// This is a good end-to-end test for two reasons. The first is obvious - it |
+// tests a simple API and makes sure it behaves as expected, as well as testing |
+// that other APIs are unavailable. |
+// The second is that chrome.test is itself an extension API, and a rather |
+// complex one. It requires both traditional bindings (renderer parses args, |
+// passes info to browser process, browser process does work and responds, re- |
+// enters JS) and custom JS bindings (in order to have our runTests, assert* |
+// methods, etc). If any of these stages failed, the test itself would also |
+// fail. |
+chrome.test.runTests([ |
+ function idleApi() { |
+ chrome.test.assertTrue(!!chrome.idle); |
+ chrome.test.assertTrue(!!chrome.idle.queryState); |
+ chrome.idle.queryState(1000, function(state) { |
+ // Depending on the machine, this could come back as either idle or |
+ // active. However, all we're curious about is the bindings themselves |
+ // (not the API implementation), so as long as it's a possible response, |
+ // it's a success for our purposes. |
+ // TODO(devlin): Update this to use chrome.idle.IdleState.[ACTIVE|IDLE] |
+ // when we have enums in native bindings. |
+ chrome.test.assertTrue(state == 'idle' || state == 'active', state); |
+ chrome.test.succeed(); |
+ }); |
+ }, |
+ function nonexistentApi() { |
+ chrome.test.assertFalse(!!chrome.nonexistent); |
+ chrome.test.succeed(); |
+ }, |
+ function disallowedApi() { |
+ chrome.test.assertFalse(!!chrome.power); |
+ chrome.test.succeed(); |
+ }, |
+]); |