OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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. |
| 4 |
| 5 var util = {}; |
| 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 |
| 25 window.runTest = function(testName, appToEmbed) { |
| 26 if (!embedder.test.testList[testName]) { |
| 27 window.console.log('Incorrect testName: ' + testName); |
| 28 embedder.test.fail(); |
| 29 return; |
| 30 } |
| 31 |
| 32 // Run the test. |
| 33 embedder.test.testList[testName](appToEmbed); |
| 34 }; |
| 35 |
| 36 var LOG = function(msg) { |
| 37 window.console.log(msg); |
| 38 }; |
| 39 |
| 40 embedder.test = {}; |
| 41 embedder.test.succeed = function() { |
| 42 chrome.test.sendMessage('TEST_PASSED'); |
| 43 }; |
| 44 |
| 45 embedder.test.fail = function() { |
| 46 chrome.test.sendMessage('TEST_FAILED'); |
| 47 }; |
| 48 |
| 49 embedder.test.assertEq = function(a, b) { |
| 50 if (a != b) { |
| 51 console.log('assertion failed: ' + a + ' != ' + b); |
| 52 embedder.test.fail(); |
| 53 } |
| 54 }; |
| 55 |
| 56 embedder.test.assertTrue = function(condition) { |
| 57 if (!condition) { |
| 58 console.log('assertion failed: true != ' + condition); |
| 59 embedder.test.fail(); |
| 60 } |
| 61 }; |
| 62 |
| 63 embedder.test.assertFalse = function(condition) { |
| 64 if (condition) { |
| 65 console.log('assertion failed: false != ' + condition); |
| 66 embedder.test.fail(); |
| 67 } |
| 68 }; |
| 69 |
| 70 // Tests begin. |
| 71 function testAppViewBasic(appToEmbed) { |
| 72 var appview = new AppView(); |
| 73 LOG('appToEmbed ' + appToEmbed); |
| 74 // Step 1: Attempt to connect to a non-existant app. |
| 75 LOG('attempting to connect to non-existant app.'); |
| 76 appview.connect('abc123', function(success) { |
| 77 // Make sure we fail. |
| 78 if (success) { |
| 79 embedder.test.fail(); |
| 80 return; |
| 81 } |
| 82 LOG('failed to connect to non-existant app.'); |
| 83 LOG('attempting to connect to known app.'); |
| 84 // Step 2: Attempt to connect to an app we know exists. |
| 85 appview.connect(appToEmbed, function(success) { |
| 86 // Make sure we don't fail. |
| 87 if (!success) { |
| 88 embedder.test.fail(); |
| 89 return; |
| 90 } |
| 91 embedder.test.succeed(); |
| 92 }); |
| 93 }); |
| 94 document.body.appendChild(appview); |
| 95 }; |
| 96 |
| 97 embedder.test.testList = { |
| 98 'testAppViewBasic': testAppViewBasic |
| 99 }; |
| 100 |
| 101 onload = function() { |
| 102 chrome.test.getConfig(function(config) { |
| 103 embedder.setUp_(config); |
| 104 chrome.test.sendMessage('Launched'); |
| 105 }); |
| 106 }; |
OLD | NEW |