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.
7 embedder.baseGuestURL = '';
8 embedder.emptyGuestURL = '';
9 embedder.windowOpenGuestURL = '';
10 embedder.noReferrerGuestURL = '';
11 embedder.redirectGuestURL = '';
12 embedder.redirectGuestURLDest = '';
13 embedder.closeSocketURL = '';
16 embedder.setUp_ = function(config) {
17 if (!config || !config.testServer) {
20 embedder.baseGuestURL = 'http://localhost:' + config.testServer.port;
21 embedder.emptyGuestURL = embedder.baseGuestURL +
22 '/extensions/platform_apps/web_view/shim/empty_guest.html';
25 window.runTest = function(testName, appToEmbed) {
26 if (!embedder.test.testList[testName]) {
27 window.console.log('Incorrect testName: ' + testName);
33 embedder.test.testList[testName](appToEmbed);
36 var LOG = function(msg) {
37 window.console.log(msg);
41 embedder.test.succeed = function() {
42 chrome.test.sendMessage('TEST_PASSED');
45 embedder.test.fail = function() {
46 chrome.test.sendMessage('TEST_FAILED');
49 embedder.test.assertEq = function(a, b) {
51 console.log('assertion failed: ' + a + ' != ' + b);
56 embedder.test.assertTrue = function(condition) {
58 console.log('assertion failed: true != ' + condition);
63 embedder.test.assertFalse = function(condition) {
65 console.log('assertion failed: false != ' + condition);
71 function testAppViewWithUndefinedDataShouldSucceed(appToEmbed) {
72 var appview = new AppView();
73 LOG('appToEmbed ' + appToEmbed);
74 document.body.appendChild(appview);
75 // Step 1: Attempt to connect to a non-existant app.
76 LOG('attempting to connect to non-existant app.');
77 appview.connect('abc123', undefined, function(success) {
80 LOG('UNEXPECTED CONNECTION.');
84 LOG('failed to connect to non-existant app.');
85 LOG('attempting to connect to known app.');
86 // Step 2: Attempt to connect to an app we know exists.
87 appview.connect(appToEmbed, undefined, function(success) {
88 // Make sure we don't fail.
90 LOG('FAILED TO CONNECT.');
95 embedder.test.succeed();
100 function testAppViewRefusedDataShouldFail(appToEmbed) {
101 var appview = new AppView();
102 LOG('appToEmbed ' + appToEmbed);
103 document.body.appendChild(appview);
104 LOG('Attempting to connect to app with refused params.');
105 appview.connect(appToEmbed, { 'foo': 'bar' }, function(success) {
106 // Make sure we fail.
108 LOG('UNEXPECTED CONNECTION.');
109 embedder.test.fail();
112 LOG('FAILED TO CONNECT.');
113 embedder.test.succeed();
117 function testAppViewGoodDataShouldSucceed(appToEmbed) {
118 var appview = new AppView();
119 LOG('appToEmbed ' + appToEmbed);
120 document.body.appendChild(appview);
121 LOG('Attempting to connect to app with good params.');
122 // Step 2: Attempt to connect to an app with good params.
123 appview.connect(appToEmbed, { 'foo': 'bleep' }, function(success) {
124 // Make sure we don't fail.
126 LOG('FAILED TO CONNECT.');
127 embedder.test.fail();
131 embedder.test.succeed();
135 function testAppViewMultipleConnects(appToEmbed) {
136 var appview = new AppView();
137 LOG('appToEmbed ' + appToEmbed);
138 document.body.appendChild(appview);
140 var callback = function(success) {
142 LOG('FAILED TO CONNECT.');
143 embedder.test.fail();
147 LOG('CONNECTED. (' + connections + ' / 10)');
148 if (connections == 10) {
149 embedder.test.succeed();
153 appview.connect(appToEmbed, { 'foo': 'bleep' }, callback);
154 appview.connect(appToEmbed, { 'foo': 'bleep' }, callback);
155 appview.connect(appToEmbed, { 'foo': 'bleep' }, callback);
156 appview.connect(appToEmbed, { 'foo': 'bleep' }, callback);
157 appview.connect(appToEmbed, { 'foo': 'bleep' }, callback);
158 appview.connect(appToEmbed, { 'foo': 'bleep' }, callback);
159 appview.connect(appToEmbed, { 'foo': 'bleep' }, callback);
160 appview.connect(appToEmbed, { 'foo': 'bleep' }, callback);
161 appview.connect(appToEmbed, { 'foo': 'bleep' }, callback);
162 appview.connect(appToEmbed, { 'foo': 'bleep' }, callback);
165 function testAppViewEmbedSelfShouldFail(appToEmbed) {
166 var appview = new AppView();
167 var currentapp_id = chrome.runtime.id;
168 LOG('appToEmbed ' + currentapp_id);
169 document.body.appendChild(appview);
170 LOG('Attempting to embed self...(id=' + currentapp_id + ').');
171 appview.connect(currentapp_id, undefined, function(success) {
173 LOG('UNEXPECTED CONNECTION.');
174 embedder.test.fail();
177 LOG('EXPECTED REFUSAL.');
178 embedder.test.succeed();
182 embedder.test.testList = {
183 'testAppViewWithUndefinedDataShouldSucceed':
184 testAppViewWithUndefinedDataShouldSucceed,
185 'testAppViewRefusedDataShouldFail': testAppViewRefusedDataShouldFail,
186 'testAppViewGoodDataShouldSucceed': testAppViewGoodDataShouldSucceed,
187 'testAppViewMultipleConnects': testAppViewMultipleConnects,
188 'testAppViewEmbedSelfShouldFail': testAppViewEmbedSelfShouldFail
191 onload = function() {
192 chrome.test.getConfig(function(config) {
193 embedder.setUp_(config);
194 chrome.test.sendMessage('Launched');