- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / tabs / basics / crud.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 firstWindowId;
6
7 chrome.test.runTests([
8   function getSelected() {
9     chrome.tabs.getSelected(null, pass(function(tab) {
10       assertEq(location.href, tab.url);
11       assertEq(location.href, tab.title);
12       firstWindowId = tab.windowId;
13     }));
14   },
15
16   function create() {
17     chrome.tabs.create({"windowId" : firstWindowId, "active" : false},
18                        pass(function(tab){
19       assertEq(1, tab.index);
20       assertEq(firstWindowId, tab.windowId);
21       assertEq(false, tab.selected);
22       assertEq("chrome://newtab/", tab.url);
23       assertEq(false, tab.pinned);
24     }));
25   },
26
27   function createInCurrent() {
28     chrome.tabs.create({'windowId': chrome.windows.WINDOW_ID_CURRENT},
29                        pass(function(tab) {
30       chrome.windows.getCurrent(pass(function(win) {
31         assertEq(win.id, tab.windowId);
32       }));
33     }));
34   },
35
36   function createInOtherWindow() {
37     chrome.windows.create({}, pass(function(win) {
38       // Create a tab in the older window.
39       chrome.tabs.create({"windowId" : firstWindowId, "active" : false},
40                          pass(function(tab) {
41         assertEq(firstWindowId, tab.windowId);
42       }));
43       // Create a tab in this new window.
44       chrome.tabs.create({"windowId" : win.id}, pass(function(tab) {
45         assertEq(win.id, tab.windowId);
46       }));
47     }));
48   },
49
50   function createAtIndex() {
51     chrome.tabs.create({"windowId" : firstWindowId, "index" : 1},
52                        pass(function(tab) {
53       assertEq(1, tab.index);
54     }));
55   },
56
57   function createSelected() {
58     chrome.tabs.create({"windowId" : firstWindowId, "active" : true},
59                        pass(function(tab) {
60       assertTrue(tab.active && tab.selected);
61       chrome.tabs.getSelected(firstWindowId, pass(function(selectedTab) {
62         assertEq(tab.id, selectedTab.id);
63       }));
64     }));
65   },
66
67   function createWindowWithDefaultTab() {
68     var verify_default = function() {
69       return pass(function(win) {
70         assertEq(1, win.tabs.length);
71         assertEq("chrome://newtab/", win.tabs[0].url);
72       });
73     };
74
75     // Make sure the window always has the NTP when no URL is supplied.
76     chrome.windows.create({}, verify_default());
77     chrome.windows.create({url:[]}, verify_default());
78   },
79
80   function createWindowWithExistingTab() {
81     // Create a tab in the old window
82     chrome.tabs.create({"windowId" : firstWindowId, "url": pageUrl('a'),
83                         "active" : false},
84                        pass(function(tab) {
85       assertEq(firstWindowId, tab.windowId);
86       assertEq(pageUrl('a'), tab.url);
87
88       // Create a new window with this tab
89       chrome.windows.create({"tabId": tab.id}, pass(function(win) {
90         assertEq(1, win.tabs.length);
91         assertEq(tab.id, win.tabs[0].id);
92         assertEq(win.id, win.tabs[0].windowId);
93         assertEq(pageUrl('a'), win.tabs[0].url);
94       }));
95     }));
96   },
97
98   function getAllInWindowNullArg() {
99     chrome.tabs.getAllInWindow(null, pass(function(tabs) {
100       assertEq(6, tabs.length);
101       assertEq(firstWindowId, tabs[0].windowId);
102     }));
103   },
104
105   function detectLanguage() {
106     chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
107       chrome.tabs.detectLanguage(tabs[0].id, pass(function(lang) {
108         assertEq("und", lang);
109       }));
110     }));
111   },
112
113   function windowCreate() {
114     chrome.windows.create({type: "popup"}, pass(function(window) {
115       assertEq("popup", window.type);
116       assertTrue(!window.incognito);
117     }));
118     chrome.windows.create({incognito: true}, pass(function(window) {
119       // This extension is not incognito-enabled, so it shouldn't be able to
120       // see the incognito window.
121       assertEq(null, window);
122     }));
123   },
124
125   function getCurrentWindow() {
126     var errorMsg = "No window with id: -1.";
127     chrome.windows.get(chrome.windows.WINDOW_ID_NONE, fail(errorMsg));
128     chrome.windows.get(chrome.windows.WINDOW_ID_CURRENT, pass(function(win1) {
129       chrome.windows.getCurrent(pass(function(win2) {
130         assertEq(win1.id, win2.id);
131       }));
132     }));
133   }
134
135   /* Disabled -- see http://bugs.chromium.org/58229.
136   function windowSetFocused() {
137     chrome.windows.getCurrent(function(oldWin) {
138       chrome.windows.create({}, function(newWin) {
139         assertTrue(newWin.focused);
140         chrome.windows.update(oldWin.id, {focused:true});
141         chrome.windows.get(oldWin.id, pass(function(oldWin2) {
142           assertTrue(oldWin2.focused);
143         }));
144       });
145     });
146   },
147   */
148 ]);