1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 window.runTest = function(testName, appToEmbed) {
9 if (!embedder.test.testList[testName]) {
10 window.console.log('Incorrect testName: ' + testName);
16 embedder.test.testList[testName](appToEmbed);
19 var LOG = function(msg) {
20 window.console.log(msg);
24 embedder.test.succeed = function() {
25 chrome.test.sendMessage('TEST_PASSED');
28 embedder.test.fail = function() {
29 chrome.test.sendMessage('TEST_FAILED');
32 embedder.test.assertEq = function(a, b) {
34 console.log('Assertion failed: ' + a + ' != ' + b);
39 embedder.test.assertTrue = function(condition) {
41 console.log('Assertion failed: true != ' + condition);
46 embedder.test.assertFalse = function(condition) {
48 console.log('Assertion failed: false != ' + condition);
54 function testAppViewGoodDataShouldSucceed(appToEmbed) {
55 var appview = new AppView();
56 LOG('appToEmbed ' + appToEmbed);
57 document.body.appendChild(appview);
58 LOG('Attempting to connect to app with good params.');
59 // Step 2: Attempt to connect to an app with good params.
60 appview.connect(appToEmbed, {'foo': 'bleep'}, function(success) {
61 // Make sure we don't fail.
63 LOG('FAILED TO CONNECT.');
68 embedder.test.succeed();
72 function testAppViewMediaRequest(appToEmbed) {
73 var appview = new AppView();
74 window.console.log('appToEmbed ' + appToEmbed);
75 document.body.appendChild(appview);
76 window.console.log('Attempting to connect to app.');
77 appview.connect(appToEmbed, {}, function(success) {
78 // Make sure we don't fail.
80 window.console.log('Failed to connect.');
84 window.console.log('Connected.');
85 embedder.test.succeed();
89 function testAppViewRefusedDataShouldFail(appToEmbed) {
90 var appview = new AppView();
91 LOG('appToEmbed ' + appToEmbed);
92 document.body.appendChild(appview);
93 LOG('Attempting to connect to app with refused params.');
94 appview.connect(appToEmbed, {'foo': 'bar'}, function(success) {
97 LOG('UNEXPECTED CONNECTION.');
101 LOG('Failed to connect.');
102 embedder.test.succeed();
106 function testAppViewWithUndefinedDataShouldSucceed(appToEmbed) {
107 var appview = new AppView();
108 LOG('appToEmbed ' + appToEmbed);
109 document.body.appendChild(appview);
110 // Step 1: Attempt to connect to a non-existant app (abc123).
111 LOG('Attempting to connect to non-existant app.');
112 appview.connect('abc123', undefined, function(success) {
113 // Make sure we fail.
115 LOG('UNEXPECTED CONNECTION.');
116 embedder.test.fail();
119 LOG('failed to connect to non-existant app.');
120 LOG('attempting to connect to known app.');
121 // Step 2: Attempt to connect to an app we know exists.
122 appview.connect(appToEmbed, undefined, function(success) {
123 // Make sure we don't fail.
125 LOG('FAILED TO CONNECT.');
126 embedder.test.fail();
130 embedder.test.succeed();
135 embedder.test.testList = {
136 'testAppViewGoodDataShouldSucceed': testAppViewGoodDataShouldSucceed,
137 'testAppViewMediaRequest': testAppViewMediaRequest,
138 'testAppViewRefusedDataShouldFail': testAppViewRefusedDataShouldFail,
139 'testAppViewWithUndefinedDataShouldSucceed':
140 testAppViewWithUndefinedDataShouldSucceed
143 onload = function() {
144 chrome.test.sendMessage('LAUNCHED');