Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8435)

Unified Diff: chrome/test/data/extensions/api_test/native_bindings/background.js

Issue 2575173002: [Extensions Bindings] Add a bridge to use current custom bindings (Closed)
Patch Set: . Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();
+ },
+]);

Powered by Google App Engine
This is Rietveld 408576698