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

Unified Diff: chrome/test/media_router/resources/common.js

Issue 595663002: Put chromoting isolate targets under chromoting_swarm_tests=1 GYP variable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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: chrome/test/media_router/resources/common.js
diff --git a/chrome/test/media_router/resources/common.js b/chrome/test/media_router/resources/common.js
new file mode 100644
index 0000000000000000000000000000000000000000..c03ed2c65b21b6a43ad4c2c665077f8592ce1887
--- /dev/null
+++ b/chrome/test/media_router/resources/common.js
@@ -0,0 +1,79 @@
+/**
+ * Copyright 2015 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.
+ *
+ * @fileoverview Common APIs for presentation integration tests.
+ *
+ */
+
+var startSessionPromise = null;
+var currentSession = null;
+var presentation = window.navigator.presentation;
+
+
+/**
+ * Waits until one device is available then starts session.
+ */
+function startSession() {
+ presentation.onavailablechange = function (e) {
+ console.log('onavailablechange ' + e.available + '\n');
+ if (!e.available) {
+ sendResult(false, 'device unavailable');
+ } else {
+ var presId = Math.random().toFixed(6).substr(2);
+ // Start new session
+ startSessionPromise = presentation.startSession(
+ "http://www.google.com/#__testprovider__=true", presId)
+ sendResult(true, '');
+ }
+ };
+}
+
+/**
+ * Checks if the session has been started successfully.
+ */
+function checkSession() {
+ if (!startSessionPromise) {
+ sendResult(false, 'Failed to start session');
+ } else {
+ startSessionPromise.then(function (currentSession) {
+ if(!currentSession) {
+ sendResult(false, 'Failed to start session');
+ } else {
+ // set the new session
+ currentSession = currentSession;
+ sendResult(true, '');
+ }
+ }).catch(function() {
+ // close old session if exists
+ currentSession && currentSession.close();
+ sendResult(false, 'Failed to start session');
+ })
+ }
+}
+
+
+/**
+ * Stops current session.
+ */
+function stopSession() {
+ if (currentSession) {
+ currentSession.close();
+ }
+ sendResult(true, '');
+}
+
+
+/**
+ * Sends the test result back to browser test.
+ * @param passed true if test passes, otherwise false.
+ * @param errorMessage empty string if test passes, error message if test
+ * fails.
+ */
+function sendResult(passed, errorMessage) {
+ window.domAutomationController.send(JSON.stringify({
+ passed: passed,
+ errorMessage: errorMessage
+ }));
+}
« no previous file with comments | « chrome/test/media_router/resources/basic_test.html ('k') | chrome/test/media_router/test_media_sinks_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698