Do not announce robot account token before account ID is available
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / tabs / basics / crud2.js
blobe1ae02f7dcc81b883dc1100b1b78ba73e1205128
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.
5 var secondWindowId;
6 var thirdWindowId;
7 var testTabId;
9 function clickLink(id) {
10 var clickEvent = document.createEvent('MouseEvents');
11 clickEvent.initMouseEvent('click', true, true, window);
12 document.querySelector('#' + id).dispatchEvent(clickEvent);
15 chrome.test.runTests([
17 function setupTwoWindows() {
18 createWindow(["about:blank", "chrome://newtab/", pageUrl("a")], {},
19 pass(function(winId, tabIds) {
20 secondWindowId = winId;
21 testTabId = tabIds[2];
23 createWindow(["chrome://newtab/", pageUrl("b")], {},
24 pass(function(winId, tabIds) {
25 thirdWindowId = winId;
26 }));
27 }));
30 function getAllInWindow() {
31 chrome.tabs.getAllInWindow(secondWindowId,
32 pass(function(tabs) {
33 assertEq(3, tabs.length);
34 for (var i = 0; i < tabs.length; i++) {
35 assertEq(secondWindowId, tabs[i].windowId);
36 assertEq(i, tabs[i].index);
38 // The first tab should be active
39 assertEq((i == 0), tabs[i].active && tabs[i].selected);
41 assertEq("about:blank", tabs[0].url);
42 assertEq("chrome://newtab/", tabs[1].url);
43 assertEq(pageUrl("a"), tabs[2].url);
44 }));
46 chrome.tabs.getAllInWindow(thirdWindowId,
47 pass(function(tabs) {
48 assertEq(2, tabs.length);
49 for (var i = 0; i < tabs.length; i++) {
50 assertEq(thirdWindowId, tabs[i].windowId);
51 assertEq(i, tabs[i].index);
53 assertEq("chrome://newtab/", tabs[0].url);
54 assertEq(pageUrl("b"), tabs[1].url);
55 }));
58 function updateSelect() {
59 chrome.tabs.getAllInWindow(secondWindowId, pass(function(tabs) {
60 assertEq(true, tabs[0].active && tabs[0].selected);
61 assertEq(false, tabs[1].active || tabs[1].selected);
62 assertEq(false, tabs[2].active || tabs[2].selected);
64 // Select tab[1].
65 chrome.tabs.update(tabs[1].id, {active: true},
66 pass(function(tab1){
67 // Check update of tab[1].
68 chrome.test.assertEq(true, tab1.active);
69 chrome.tabs.getAllInWindow(secondWindowId, pass(function(tabs) {
70 assertEq(true, tabs[1].active && tabs[1].selected);
71 assertEq(false, tabs[2].active || tabs[2].selected);
72 // Select tab[2].
73 chrome.tabs.update(tabs[2].id,
74 {active: true},
75 pass(function(tab2){
76 // Check update of tab[2].
77 chrome.test.assertEq(true, tab2.active);
78 chrome.tabs.getAllInWindow(secondWindowId, pass(function(tabs) {
79 assertEq(false, tabs[1].active || tabs[1].selected);
80 assertEq(true, tabs[2].active && tabs[2].selected);
81 }));
82 }));
83 }));
84 }));
85 }));
88 function update() {
89 chrome.tabs.get(testTabId, pass(function(tab) {
90 assertEq(pageUrl("a"), tab.url);
91 // Update url.
92 chrome.tabs.update(testTabId, {"url": pageUrl("c")},
93 pass(function(tab){
94 chrome.test.assertEq(pageUrl("c"), tab.url);
95 // Check url.
96 chrome.tabs.get(testTabId, pass(function(tab) {
97 assertEq(pageUrl("c"), tab.url);
98 }));
99 }));
100 }));
103 function openerTabId() {
104 chrome.test.listenOnce(
105 chrome.tabs.onCreated,
106 function(tab) {
107 chrome.tabs.getCurrent(pass(function(thisTab) {
108 assertEq(thisTab.id, tab.openerTabId);
109 }));
111 // Pretend to click a link (openers aren't tracked when using tabs.create).
112 clickLink("test_link");
115 // The window on chrome.tabs.create is ignored if it doesn't accept tabs.
116 function testRedirectingToAnotherWindow() {
117 chrome.windows.create(
118 {url: 'about:blank', type: 'popup'},
119 pass(function(window) {
120 chrome.tabs.create(
121 {url: 'about:blank', windowId: window.id},
122 pass(function(tab) {
123 assertTrue(window.id != tab.windowId);
124 }));
125 }));
128 // Creation of a tab in an empty non-tabbed window should be allowed.
129 function testOpenWindowInEmptyPopup() {
130 chrome.windows.create(
131 {type: 'popup'},
132 pass(function(window) {
133 chrome.tabs.create(
134 {url: 'about:blank', windowId: window.id},
135 pass(function(tab) {
136 assertEq(window.id, tab.windowId);
137 }));
138 }));
141 // An empty popup window does not contain any tabs and the number of tabs
142 // before and after creation should be the same.
143 function testOpenEmptyPopup() {
144 chrome.tabs.query({}, pass(function(tabs) {
145 var tabsCountBefore = tabs.length;
146 chrome.windows.create({type: 'popup'}, pass(function(window) {
147 assertEq(window.tabs.length, 0);
148 chrome.tabs.query({}, pass(function(tabs) {
149 assertEq(tabsCountBefore, tabs.length);
150 }));
151 }));
152 }));
155 function testCreatePopupAndMoveTab() {
156 // An existing tab can be moved into a created empty popup.
157 chrome.tabs.create({url: 'about:blank'}, pass(function(tab) {
158 chrome.windows.create({type: 'popup', tabId: tab.id},
159 pass(function(window) {
160 assertEq(window.tabs.length, 1);
161 chrome.tabs.get(tab.id, pass(function(updatedTabInfo) {
162 assertEq(window.id, updatedTabInfo.windowId);
163 }));
164 }));
165 }));
167 // An existing tab cannot be moved into a created non-empty popup.
168 chrome.tabs.create({url: 'about:blank'}, pass(function(tab) {
169 chrome.windows.create({type: 'popup', url: 'about:blank', tabId: tab.id},
170 pass(function(window) {
171 assertEq(window.tabs.length, 1);
172 chrome.tabs.get(tab.id, pass(function(updatedTabInfo) {
173 assertEq(tab.windowId, updatedTabInfo.windowId);
174 assertTrue(window.id != updatedTabInfo.windowId);
175 }));
176 }));
177 }));