Upstream version 8.37.180.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / automation / tests / tabs / common.js
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.
4
5 var assertEq = chrome.test.assertEq;
6 var assertFalse = chrome.test.assertFalse;
7 var assertTrue = chrome.test.assertTrue;
8
9 var EventType = chrome.automation.EventType;
10 var RoleType = chrome.automation.RoleType;
11 var StateType = chrome.automation.StateType;
12
13 var rootNode = null;
14
15 function createTab(url, callback) {
16   chrome.tabs.create({"url": url}, function(tab) {
17     callback(tab);
18   });
19 }
20
21 function setUpAndRunTests(allTests) {
22   getUrlFromConfig(function(url) {
23     createTab(url, function(unused_tab) {
24       chrome.automation.getTree(function (returnedRootNode) {
25         rootNode = returnedRootNode;
26         rootNode.addEventListener('loadComplete', function() {
27           chrome.test.runTests(allTests);
28         });
29       });
30     });
31   });
32 }
33
34 function getUrlFromConfig(callback) {
35   chrome.test.getConfig(function(config) {
36     assertTrue('testServer' in config, 'Expected testServer in config');
37     var url = 'http://a.com:PORT/index.html'
38         .replace(/PORT/, config.testServer.port);
39     callback(url)
40   });
41 }