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

Unified Diff: extensions/renderer/resources/browser_test_environment_specific_bindings.js

Issue 399363002: Add support for writing unit tests for Mojo-backed apps/extensions APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 5 months 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: extensions/renderer/resources/browser_test_environment_specific_bindings.js
diff --git a/extensions/renderer/resources/browser_test_environment_specific_bindings.js b/extensions/renderer/resources/browser_test_environment_specific_bindings.js
new file mode 100644
index 0000000000000000000000000000000000000000..906556d53a2b3ec9035a312349c89f50898abab0
--- /dev/null
+++ b/extensions/renderer/resources/browser_test_environment_specific_bindings.js
@@ -0,0 +1,53 @@
+// Copyright 2014 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.
+
+var chrome = requireNative('chrome').GetChrome();
+var GetExtensionAPIDefinitionsForTest =
+ requireNative('apiDefinitions').GetExtensionAPIDefinitionsForTest;
+var GetAPIFeatures = requireNative('test_features').GetAPIFeatures;
+var userGestures = requireNative('user_gestures');
+
+var RunWithNativesEnabledModuleSystem =
+ requireNative('v8_context').RunWithNativesEnabledModuleSystem;
+
+function registerHooks(api) {
+ var chromeTest = api.compiledApi;
+ var apiFunctions = api.apiFunctions;
+
+ apiFunctions.setHandleRequest('runWithModuleSystem', function(callback) {
+ RunWithNativesEnabledModuleSystem(callback);
+ });
+
+ apiFunctions.setHandleRequest('getApiDefinitions', function() {
+ return GetExtensionAPIDefinitionsForTest();
+ });
+
+ apiFunctions.setHandleRequest('getApiFeatures', function() {
+ return GetAPIFeatures();
+ });
+
+ apiFunctions.setHandleRequest('isProcessingUserGesture', function() {
+ return userGestures.IsProcessingUserGesture();
+ });
+
+ apiFunctions.setHandleRequest('runWithUserGesture', function(callback) {
+ chromeTest.assertEq(typeof(callback), 'function');
+ return userGestures.RunWithUserGesture(callback);
+ });
+
+ apiFunctions.setHandleRequest('runWithoutUserGesture', function(callback) {
+ chromeTest.assertEq(typeof(callback), 'function');
+ return userGestures.RunWithoutUserGesture(callback);
+ });
+
+}
+
+function testDone(runNextTest) {
+ // Use setTimeout here to allow previous test contexts to be
+ // eligible for garbage collection.
+ setTimeout(runNextTest, 0);
+}
+
+exports.registerHooks = registerHooks;
+exports.testDone = testDone;

Powered by Google App Engine
This is Rietveld 408576698