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.
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;
17 chrome.tabs.create({"windowId" : firstWindowId, "active" : false},
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);
27 function createInCurrent() {
28 chrome.tabs.create({'windowId': chrome.windows.WINDOW_ID_CURRENT},
30 chrome.windows.getCurrent(pass(function(win) {
31 assertEq(win.id, tab.windowId);
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},
41 assertEq(firstWindowId, tab.windowId);
43 // Create a tab in this new window.
44 chrome.tabs.create({"windowId" : win.id}, pass(function(tab) {
45 assertEq(win.id, tab.windowId);
50 function createAtIndex() {
51 chrome.tabs.create({"windowId" : firstWindowId, "index" : 1},
53 assertEq(1, tab.index);
57 function createSelected() {
58 chrome.tabs.create({"windowId" : firstWindowId, "active" : true},
60 assertTrue(tab.active && tab.selected);
61 chrome.tabs.getSelected(firstWindowId, pass(function(selectedTab) {
62 assertEq(tab.id, selectedTab.id);
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);
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());
80 function createWindowWithExistingTab() {
81 // Create a tab in the old window
82 chrome.tabs.create({"windowId" : firstWindowId, "url": pageUrl('a'),
85 assertEq(firstWindowId, tab.windowId);
86 assertEq(pageUrl('a'), tab.url);
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);
98 function getAllInWindowNullArg() {
99 chrome.tabs.getAllInWindow(null, pass(function(tabs) {
100 assertEq(6, tabs.length);
101 assertEq(firstWindowId, tabs[0].windowId);
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);
113 function windowCreate() {
114 chrome.windows.create({type: "popup"}, pass(function(window) {
115 assertEq("popup", window.type);
116 assertTrue(!window.incognito);
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);
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);
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);