| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 var inAppUrl = 'nav-target.html'; | |
| 5 | 4 |
| 6 function runTests(remoteUrl) { | 5 chrome.test.getConfig(function(config) { |
| 6 var IN_APP_URL = 'nav-target.html'; |
| 7 var REMOTE_URL = 'http://localhost:' + config.testServer.port |
| 8 '/files/extensions/platform_apps/navigation/nav-target.html'; |
| 9 |
| 7 var testForm = document.getElementById('test-form'); | 10 var testForm = document.getElementById('test-form'); |
| 8 var testLink = document.getElementById('test-link'); | 11 var testLink = document.getElementById('test-link'); |
| 9 | 12 |
| 10 function clickTestLink() { | 13 function clickTestLink() { |
| 11 var clickEvent = document.createEvent('MouseEvents'); | 14 var clickEvent = document.createEvent('MouseEvents'); |
| 12 clickEvent.initMouseEvent('click', true, true, window, | 15 clickEvent.initMouseEvent('click', true, true, window, |
| 13 0, 0, 0, 0, 0, false, false, | 16 0, 0, 0, 0, 0, false, false, |
| 14 false, false, 0, null); | 17 false, false, 0, null); |
| 15 | 18 |
| 16 return testLink.dispatchEvent(clickEvent); | 19 return testLink.dispatchEvent(clickEvent); |
| 17 } | 20 } |
| 18 | 21 |
| 19 var tests = [ | 22 var tests = [ |
| 20 // Location functions to in-app URLs. | 23 // Location functions to in-app URLs. |
| 21 function() { window.location = inAppUrl }, | 24 function() { window.location = IN_APP_URL }, |
| 22 function() { window.location.href = inAppUrl; }, | 25 function() { window.location.href = IN_APP_URL; }, |
| 23 function() { window.location.replace(inAppUrl); }, | 26 function() { window.location.replace(IN_APP_URL); }, |
| 24 function() { window.location.assign(inAppUrl); }, | 27 function() { window.location.assign(IN_APP_URL); }, |
| 25 | 28 |
| 26 // Location function to remote URLs (not testing all ways of navigating to | 29 // Location function to remote URLs (not testing all ways of navigating to |
| 27 // it, since that was covered by the previous set) | 30 // it, since that was covered by the previous set) |
| 28 function() { window.location = remoteUrl; }, | 31 function() { window.location = REMOTE_URL; }, |
| 29 | 32 |
| 30 // Form submission (GET, POST, in-app, and remote) | 33 // Form submission (GET, POST, in-app, and remote) |
| 31 function() { | 34 function() { |
| 32 testForm.method = 'GET'; | 35 testForm.method = 'GET'; |
| 33 testForm.action = inAppUrl; | 36 testForm.action = IN_APP_URL; |
| 34 testForm.submit(); | 37 testForm.submit(); |
| 35 }, | 38 }, |
| 36 function() { | 39 function() { |
| 37 testForm.method = 'POST'; | 40 testForm.method = 'POST'; |
| 38 testForm.action = inAppUrl; | 41 testForm.action = IN_APP_URL; |
| 39 testForm.submit(); | 42 testForm.submit(); |
| 40 }, | 43 }, |
| 41 function() { | 44 function() { |
| 42 testForm.method = 'GET'; | 45 testForm.method = 'GET'; |
| 43 testForm.action = remoteUrl; | 46 testForm.action = REMOTE_URL; |
| 44 testForm.submit(); | 47 testForm.submit(); |
| 45 }, | 48 }, |
| 46 function() { | 49 function() { |
| 47 testForm.method = 'POST'; | 50 testForm.method = 'POST'; |
| 48 testForm.action = remoteUrl; | 51 testForm.action = REMOTE_URL; |
| 49 testForm.submit(); | 52 testForm.submit(); |
| 50 }, | 53 }, |
| 51 | 54 |
| 52 // Clicks on links (in-app and remote). | 55 // Clicks on links (in-app and remote). |
| 53 function() { testLink.href = inAppUrl; clickTestLink(); }, | 56 function() { testLink.href = IN_APP_URL; clickTestLink(); }, |
| 54 function() { testLink.href = remoteUrl; clickTestLink(); }, | 57 function() { testLink.href = REMOTE_URL; clickTestLink(); }, |
| 55 | 58 |
| 56 // If we manage to execute this test case, then we haven't navigated away. | 59 // If we manage to execute this test case, then we haven't navigated away. |
| 57 function() { window.domAutomationController.send(true); } | 60 function() { chrome.test.notifyPass(); } |
| 58 ]; | 61 ]; |
| 59 | 62 |
| 60 var testIndex = 0; | 63 var testIndex = 0; |
| 61 | 64 |
| 62 function runTest() { | 65 function runTest() { |
| 63 var test = tests[testIndex++]; | 66 var test = tests[testIndex++]; |
| 64 | 67 |
| 65 console.log('Testing ' + (testIndex - 1) + ': ' + test); | 68 console.log('Testing ' + (testIndex - 1) + ': ' + test); |
| 66 test(); | 69 test(); |
| 67 | 70 |
| 68 if (testIndex < tests.length) { | 71 if (testIndex < tests.length) { |
| 69 // Don't run the next test immediately, since navigation happens | 72 // Don't run the next test immediately, since navigation happens |
| 70 // asynchronously, and if we do end up navigating, we don't want to still | 73 // asynchronously, and if we do end up navigating, we don't want to still |
| 71 // execute the final test case (which signals success). | 74 // execute the final test case (which signals success). |
| 72 window.setTimeout(runTest, 100); | 75 window.setTimeout(runTest, 100); |
| 73 } | 76 } |
| 74 } | 77 } |
| 75 | 78 |
| 76 runTest(); | 79 runTest(); |
| 77 } | 80 }); |
| OLD | NEW |