OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var util = {}; | 5 var util = {}; |
6 var embedder = {}; | 6 var embedder = {}; |
7 embedder.baseGuestURL = ''; | |
8 embedder.emptyGuestURL = ''; | |
9 embedder.windowOpenGuestURL = ''; | |
10 embedder.noReferrerGuestURL = ''; | |
11 embedder.redirectGuestURL = ''; | |
12 embedder.redirectGuestURLDest = ''; | |
13 embedder.closeSocketURL = ''; | |
14 embedder.tests = {}; | |
15 | |
16 embedder.setUp_ = function(config) { | |
17 if (!config || !config.testServer) { | |
18 return; | |
19 } | |
20 embedder.baseGuestURL = 'http://localhost:' + config.testServer.port; | |
21 embedder.emptyGuestURL = embedder.baseGuestURL + | |
22 '/extensions/platform_apps/web_view/shim/empty_guest.html'; | |
23 }; | |
24 | 7 |
25 window.runTest = function(testName, appToEmbed) { | 8 window.runTest = function(testName, appToEmbed) { |
26 if (!embedder.test.testList[testName]) { | 9 if (!embedder.test.testList[testName]) { |
27 window.console.log('Incorrect testName: ' + testName); | 10 window.console.log('Incorrect testName: ' + testName); |
28 embedder.test.fail(); | 11 embedder.test.fail(); |
29 return; | 12 return; |
30 } | 13 } |
31 | 14 |
32 // Run the test. | 15 // Run the test. |
33 embedder.test.testList[testName](appToEmbed); | 16 embedder.test.testList[testName](appToEmbed); |
34 }; | 17 }; |
35 | 18 |
36 var LOG = function(msg) { | 19 var LOG = function(msg) { |
37 window.console.log(msg); | 20 window.console.log(msg); |
38 }; | 21 }; |
39 | 22 |
40 embedder.test = {}; | 23 embedder.test = {}; |
41 embedder.test.succeed = function() { | 24 embedder.test.succeed = function() { |
42 chrome.test.sendMessage('TEST_PASSED'); | 25 chrome.test.sendMessage('TEST_PASSED'); |
43 }; | 26 }; |
44 | 27 |
45 embedder.test.fail = function() { | 28 embedder.test.fail = function() { |
46 chrome.test.sendMessage('TEST_FAILED'); | 29 chrome.test.sendMessage('TEST_FAILED'); |
47 }; | 30 }; |
48 | 31 |
49 embedder.test.assertEq = function(a, b) { | 32 embedder.test.assertEq = function(a, b) { |
50 if (a != b) { | 33 if (a != b) { |
51 console.log('assertion failed: ' + a + ' != ' + b); | 34 console.log('Assertion failed: ' + a + ' != ' + b); |
52 embedder.test.fail(); | 35 embedder.test.fail(); |
53 } | 36 } |
54 }; | 37 }; |
55 | 38 |
56 embedder.test.assertTrue = function(condition) { | 39 embedder.test.assertTrue = function(condition) { |
57 if (!condition) { | 40 if (!condition) { |
58 console.log('assertion failed: true != ' + condition); | 41 console.log('Assertion failed: true != ' + condition); |
59 embedder.test.fail(); | 42 embedder.test.fail(); |
60 } | 43 } |
61 }; | 44 }; |
62 | 45 |
63 embedder.test.assertFalse = function(condition) { | 46 embedder.test.assertFalse = function(condition) { |
64 if (condition) { | 47 if (condition) { |
65 console.log('assertion failed: false != ' + condition); | 48 console.log('Assertion failed: false != ' + condition); |
66 embedder.test.fail(); | 49 embedder.test.fail(); |
67 } | 50 } |
68 }; | 51 }; |
69 | 52 |
70 // Tests begin. | 53 // Tests begin. |
71 function testAppViewWithUndefinedDataShouldSucceed(appToEmbed) { | 54 function testAppViewGoodDataShouldSucceed(appToEmbed) { |
72 var appview = new AppView(); | 55 var appview = new AppView(); |
73 LOG('appToEmbed ' + appToEmbed); | 56 LOG('appToEmbed ' + appToEmbed); |
74 document.body.appendChild(appview); | 57 document.body.appendChild(appview); |
75 // Step 1: Attempt to connect to a non-existant app. | 58 LOG('Attempting to connect to app with good params.'); |
76 LOG('attempting to connect to non-existant app.'); | 59 // Step 2: Attempt to connect to an app with good params. |
77 appview.connect('abc123', undefined, function(success) { | 60 appview.connect(appToEmbed, {'foo': 'bleep'}, function(success) { |
78 // Make sure we fail. | 61 // Make sure we don't fail. |
79 if (success) { | 62 if (!success) { |
80 LOG('UNEXPECTED CONNECTION.'); | 63 LOG('FAILED TO CONNECT.'); |
81 embedder.test.fail(); | 64 embedder.test.fail(); |
82 return; | 65 return; |
83 } | 66 } |
84 LOG('failed to connect to non-existant app.'); | 67 LOG('Connected.'); |
85 LOG('attempting to connect to known app.'); | 68 embedder.test.succeed(); |
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. | |
89 if (!success) { | |
90 LOG('FAILED TO CONNECT.'); | |
91 embedder.test.fail(); | |
92 return; | |
93 } | |
94 LOG('CONNECTED.'); | |
95 embedder.test.succeed(); | |
96 }); | |
97 }); | 69 }); |
98 }; | 70 }; |
99 | 71 |
100 function testAppViewRefusedDataShouldFail(appToEmbed) { | 72 function testAppViewRefusedDataShouldFail(appToEmbed) { |
101 var appview = new AppView(); | 73 var appview = new AppView(); |
102 LOG('appToEmbed ' + appToEmbed); | 74 LOG('appToEmbed ' + appToEmbed); |
103 document.body.appendChild(appview); | 75 document.body.appendChild(appview); |
104 LOG('Attempting to connect to app with refused params.'); | 76 LOG('Attempting to connect to app with refused params.'); |
105 appview.connect(appToEmbed, { 'foo': 'bar' }, function(success) { | 77 appview.connect(appToEmbed, {'foo': 'bar'}, function(success) { |
106 // Make sure we fail. | 78 // Make sure we fail. |
107 if (success) { | 79 if (success) { |
108 LOG('UNEXPECTED CONNECTION.'); | 80 LOG('UNEXPECTED CONNECTION.'); |
109 embedder.test.fail(); | 81 embedder.test.fail(); |
110 return; | 82 return; |
111 } | 83 } |
112 LOG('FAILED TO CONNECT.'); | 84 LOG('Failed to connect.'); |
113 embedder.test.succeed(); | 85 embedder.test.succeed(); |
114 }); | 86 }); |
115 }; | 87 }; |
116 | 88 |
117 function testAppViewGoodDataShouldSucceed(appToEmbed) { | 89 function testAppViewWithUndefinedDataShouldSucceed(appToEmbed) { |
118 var appview = new AppView(); | 90 var appview = new AppView(); |
119 LOG('appToEmbed ' + appToEmbed); | 91 LOG('appToEmbed ' + appToEmbed); |
120 document.body.appendChild(appview); | 92 document.body.appendChild(appview); |
121 LOG('Attempting to connect to app with good params.'); | 93 // Step 1: Attempt to connect to a non-existant app (abc123). |
122 // Step 2: Attempt to connect to an app with good params. | 94 LOG('Attempting to connect to non-existant app.'); |
123 appview.connect(appToEmbed, { 'foo': 'bleep' }, function(success) { | 95 appview.connect('abc123', undefined, function(success) { |
124 // Make sure we don't fail. | 96 // Make sure we fail. |
125 if (!success) { | 97 if (success) { |
126 LOG('FAILED TO CONNECT.'); | 98 LOG('UNEXPECTED CONNECTION.'); |
127 embedder.test.fail(); | 99 embedder.test.fail(); |
128 return; | 100 return; |
129 } | 101 } |
130 LOG('CONNECTED.'); | 102 LOG('failed to connect to non-existant app.'); |
131 embedder.test.succeed(); | 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. |
| 107 if (!success) { |
| 108 LOG('FAILED TO CONNECT.'); |
| 109 embedder.test.fail(); |
| 110 return; |
| 111 } |
| 112 LOG('Connected.'); |
| 113 embedder.test.succeed(); |
| 114 }); |
132 }); | 115 }); |
133 }; | 116 }; |
134 | 117 |
135 embedder.test.testList = { | 118 embedder.test.testList = { |
| 119 'testAppViewGoodDataShouldSucceed': testAppViewGoodDataShouldSucceed, |
| 120 'testAppViewRefusedDataShouldFail': testAppViewRefusedDataShouldFail, |
136 'testAppViewWithUndefinedDataShouldSucceed': | 121 'testAppViewWithUndefinedDataShouldSucceed': |
137 testAppViewWithUndefinedDataShouldSucceed, | 122 testAppViewWithUndefinedDataShouldSucceed |
138 'testAppViewRefusedDataShouldFail': testAppViewRefusedDataShouldFail, | |
139 'testAppViewGoodDataShouldSucceed': testAppViewGoodDataShouldSucceed | |
140 }; | 123 }; |
141 | 124 |
142 onload = function() { | 125 onload = function() { |
143 chrome.test.getConfig(function(config) { | 126 chrome.test.sendMessage('LAUNCHED'); |
144 embedder.setUp_(config); | |
145 chrome.test.sendMessage('Launched'); | |
146 }); | |
147 }; | 127 }; |
OLD | NEW |