| OLD | NEW |
| 1 |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 2 // 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 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 4 // found in the LICENSE file. |
| 4 | 5 |
| 5 function createBackgroundTab(url, callback) { | 6 function createBackgroundTab(url, callback) { |
| 6 chrome.tabs.query({ active: true }, function(tabs) { | 7 chrome.tabs.query({ active: true }, function(tabs) { |
| 7 chrome.test.assertEq(1, tabs.length); | 8 chrome.test.assertEq(1, tabs.length); |
| 8 var originalActiveTab = tabs[0]; | 9 var originalActiveTab = tabs[0]; |
| 9 createTab(url, function(tab) { | 10 createTab(url, function(tab) { |
| 10 chrome.tabs.update(originalActiveTab.id, { active: true }, function() { | 11 chrome.tabs.update(originalActiveTab.id, { active: true }, function() { |
| 11 callback(tab); | 12 callback(tab); |
| 12 }); | 13 }); |
| 13 }) | 14 }) |
| 14 }); | 15 }); |
| 15 } | 16 } |
| 16 | 17 |
| 17 function assertCorrectTab(rootNode) { | 18 function assertCorrectTab(rootNode) { |
| 18 var title = rootNode.attributes.docTitle; | 19 var title = rootNode.attributes.docTitle; |
| 19 chrome.test.assertEq('Automation Tests', title); | 20 chrome.test.assertEq('Automation Tests', title); |
| 20 chrome.test.succeed(); | 21 chrome.test.succeed(); |
| 21 } | 22 } |
| 22 | 23 |
| 23 var allTests = [ | 24 var allTests = [ |
| 24 function testGetTabById() { | 25 function testGetTabById() { |
| 25 getUrlFromConfig(function(url) { | 26 getUrlFromConfig('index.html', function(url) { |
| 26 // Keep the NTP as the active tab so that we know we're requesting the | 27 // Keep the NTP as the active tab so that we know we're requesting the |
| 27 // tab by ID rather than just getting the active tab still. | 28 // tab by ID rather than just getting the active tab still. |
| 28 createBackgroundTab(url, function(tab) { | 29 createBackgroundTab(url, function(tab) { |
| 29 chrome.automation.getTree(tab.id, function(rootNode) { | 30 chrome.automation.getTree(tab.id, function(rootNode) { |
| 30 if (rootNode.attributes.docLoaded) { | 31 if (rootNode.attributes.docLoaded) { |
| 31 assertCorrectTab(rootNode); | 32 assertCorrectTab(rootNode); |
| 32 return; | 33 return; |
| 33 } | 34 } |
| 34 | 35 |
| 35 rootNode.addEventListener('loadComplete', function() { | 36 rootNode.addEventListener('loadComplete', function() { |
| 36 assertCorrectTab(rootNode); | 37 assertCorrectTab(rootNode); |
| 37 }); | 38 }); |
| 38 }) | 39 }) |
| 39 }); | 40 }); |
| 40 }); | 41 }); |
| 41 } | 42 } |
| 42 ]; | 43 ]; |
| 43 | 44 |
| 44 chrome.test.runTests(allTests); | 45 chrome.test.runTests(allTests); |
| OLD | NEW |