- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / tabs / basics / opener.js
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 firstTabId;
6 var secondTabId;
7 var thirdTabId;
8
9 chrome.test.runTests([
10   function init() {
11     chrome.tabs.create({index:1, active:false}, pass(function(tab) {
12       secondTabId = tab.id;
13       assertFalse(tab.active);
14       assertEq(1, tab.index);
15       chrome.tabs.query(
16           {windowId: chrome.windows.WINDOW_ID_CURRENT, index:0},
17           pass(function(tabs) {
18         assertEq(1, tabs.length);
19         assertEq(0, tabs[0].index);
20         firstTabId = tabs[0].id;
21       }));
22     }));
23   },
24
25   function createWithOpener() {
26     chrome.tabs.create(
27         {openerTabId: firstTabId, active: true},
28         pass(function(tab) {
29       assertEq(firstTabId, tab.openerTabId);
30       assertTrue(tab.active);
31       assertEq(2, tab.index);
32       thirdTabId = tab.id;
33     }));
34   },
35
36   function closeOpener() {
37     chrome.tabs.remove(thirdTabId, pass(function() {
38       chrome.tabs.get(firstTabId, pass(function(tab) {
39         assertTrue(tab.active);
40       }));
41     }));
42   },
43
44   function updateOpener() {
45     chrome.tabs.create({active: true}, pass(function(tab1) {
46       thirdTabId = tab1.id;
47       assertTrue(tab1.active);
48       assertFalse("openerTabId" in tab1);
49       chrome.tabs.update(
50           tab1.id, {openerTabId: firstTabId},
51           pass(function(tab2) {
52         assertEq(firstTabId, tab2.openerTabId);
53       }));
54     }));
55   },
56
57   function closeOpenerAgain() {
58     chrome.tabs.remove(thirdTabId, pass(function() {
59       chrome.tabs.get(firstTabId, pass(function(tab) {
60         assertTrue(tab.active);
61       }));
62     }));
63   }
64 ]);