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 testAppViewRefusedDataShouldFail(appToEmbed) {
73 var appview = new AppView();
74 LOG('appToEmbed ' + appToEmbed);
75 document.body.appendChild(appview);
76 LOG('Attempting to connect to app with refused params.');
77 appview.connect(appToEmbed, {'foo': 'bar'}, function(success) {
80 LOG('UNEXPECTED CONNECTION.');
84 LOG('Failed to connect.');
85 embedder.test.succeed();
89 function testAppViewWithUndefinedDataShouldSucceed(appToEmbed) {
90 var appview = new AppView();
91 LOG('appToEmbed ' + appToEmbed);
92 document.body.appendChild(appview);
93 // Step 1: Attempt to connect to a non-existant app (abc123).
94 LOG('Attempting to connect to non-existant app.');
95 appview.connect('abc123', undefined, function(success) {
98 LOG('UNEXPECTED CONNECTION.');
102 LOG('failed to connect to non-existant app.');
103 LOG('attempting to connect to known app.');
104 // Step 2: Attempt to connect to an app we know exists.
105 appview.connect(appToEmbed, undefined, function(success) {
106 // Make sure we don't fail.
108 LOG('FAILED TO CONNECT.');
109 embedder.test.fail();
113 embedder.test.succeed();
118 embedder.test.testList = {
119 'testAppViewGoodDataShouldSucceed': testAppViewGoodDataShouldSucceed,
120 'testAppViewRefusedDataShouldFail': testAppViewRefusedDataShouldFail,
121 'testAppViewWithUndefinedDataShouldSucceed':
122 testAppViewWithUndefinedDataShouldSucceed
125 onload = function() {
126 chrome.test.sendMessage('LAUNCHED');