Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: chrome/test/data/extensions/api_test/tabs/test.js

Issue 203042: windows.create({url:}) now supports relative paths. tabs.update()/tabs.move() now return Tab. (Closed)
Patch Set: forgot page Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/data/extensions/api_test/tabs/relative.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // tabs api test 1 // tabs api test
2 // browser_tests.exe --gtest_filter=ExtensionApiTest.Tabs 2 // browser_tests.exe --gtest_filter=ExtensionApiTest.Tabs
3 3
4 // We have a bunch of places where we need to remember some state from one 4 // We have a bunch of places where we need to remember some state from one
5 // test (or setup code) to subsequent tests. 5 // test (or setup code) to subsequent tests.
6 var firstWindowId = null; 6 var firstWindowId = null;
7 var secondWindowId = null; 7 var secondWindowId = null;
8 var firstTabIndex = null; 8 var firstTabIndex = null;
9 var testTabId = null; 9 var testTabId = null;
10 10
11 var moveWindow1 = null; 11 var moveWindow1 = null;
12 var moveWindow2 = null; 12 var moveWindow2 = null;
13 var moveTabIds = {}; 13 var moveTabIds = {};
14 14
15 var pass = chrome.test.callbackPass; 15 var pass = chrome.test.callbackPass;
16 var assertEq = chrome.test.assertEq; 16 var assertEq = chrome.test.assertEq;
17 var assertTrue = chrome.test.assertTrue; 17 var assertTrue = chrome.test.assertTrue;
18 18
19 // Called by relative.html during onload.
20 function relativePageLoaded() {
21 chrome.test.succeed();
22 }
23
19 chrome.test.runTests([ 24 chrome.test.runTests([
20 function getSelected() { 25 function getSelected() {
21 chrome.tabs.getSelected(null, pass(function(tab) { 26 chrome.tabs.getSelected(null, pass(function(tab) {
22 assertEq("about:blank", tab.url); 27 assertEq("about:blank", tab.url);
23 assertEq("about:blank", tab.title); 28 assertEq("about:blank", tab.title);
24 firstWindowId = tab.windowId; 29 firstWindowId = tab.windowId;
25 firstTabIndex = tab.index; 30 firstTabIndex = tab.index;
26 })); 31 }));
27 }, 32 },
28 33
(...skipping 21 matching lines...) Expand all
50 chrome.windows.create({}, pass(function(win) { 55 chrome.windows.create({}, pass(function(win) {
51 assertTrue(win.id > 0); 56 assertTrue(win.id > 0);
52 secondWindowId = win.id; 57 secondWindowId = win.id;
53 // Create first window. 58 // Create first window.
54 chrome.tabs.create({"windowId" : firstWindowId, "url" : "chrome://a"}, 59 chrome.tabs.create({"windowId" : firstWindowId, "url" : "chrome://a"},
55 pass(function() { 60 pass(function() {
56 // Create second window. 61 // Create second window.
57 chrome.tabs.create({"windowId" : secondWindowId, "url" : "chrome://b"}, 62 chrome.tabs.create({"windowId" : secondWindowId, "url" : "chrome://b"},
58 pass()); 63 pass());
59 })); 64 }));
60 })); 65 }));
61 }, 66 },
62 67
63 function getAllFirstWindow() { 68 function getAllFirstWindow() {
64 // TODO(asargent) Add test for passing null for windowId - this should 69 // TODO(asargent) Add test for passing null for windowId - this should
65 // default to the "current" window. 70 // default to the "current" window.
66 chrome.tabs.getAllInWindow(firstWindowId, 71 chrome.tabs.getAllInWindow(firstWindowId,
67 pass(function(tabs) { 72 pass(function(tabs) {
68 assertEq(3, tabs.length); 73 assertEq(3, tabs.length);
69 for (var i = 0; i < tabs.length; i++) { 74 for (var i = 0; i < tabs.length; i++) {
70 assertEq(firstWindowId, tabs[i].windowId); 75 assertEq(firstWindowId, tabs[i].windowId);
(...skipping 19 matching lines...) Expand all
90 } 95 }
91 assertEq("chrome://newtab/", tabs[0].url); 96 assertEq("chrome://newtab/", tabs[0].url);
92 assertEq("chrome://b/", tabs[1].url); 97 assertEq("chrome://b/", tabs[1].url);
93 })); 98 }));
94 }, 99 },
95 100
96 function updateUrl() { 101 function updateUrl() {
97 chrome.tabs.get(testTabId, pass(function(tab) { 102 chrome.tabs.get(testTabId, pass(function(tab) {
98 assertEq("chrome://a/", tab.url); 103 assertEq("chrome://a/", tab.url);
99 // Update url. 104 // Update url.
100 chrome.tabs.update(testTabId, {"url": "chrome://c"}, 105 chrome.tabs.update(testTabId, {"url": "chrome://c/"},
101 pass(function(){ 106 pass(function(tab){
107 chrome.test.assertEq("chrome://c/", tab.url);
102 // Check url. 108 // Check url.
103 chrome.tabs.get(testTabId, pass(function(tab) { 109 chrome.tabs.get(testTabId, pass(function(tab) {
104 assertEq("chrome://c/", tab.url); 110 assertEq("chrome://c/", tab.url);
105 })); 111 }));
106 })); 112 }));
107 })); 113 }));
108 }, 114 },
109 115
110 function updateSelect() { 116 function updateSelect() {
111 chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) { 117 chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
112 assertEq(false, tabs[1].selected); 118 assertEq(false, tabs[1].selected);
113 assertEq(true, tabs[2].selected); 119 assertEq(true, tabs[2].selected);
114 // Select tab[1]. 120 // Select tab[1].
115 chrome.tabs.update(tabs[1].id, {selected: true}, 121 chrome.tabs.update(tabs[1].id, {selected: true},
116 pass(function(){ 122 pass(function(tab1){
117 // Check update of tab[1]. 123 // Check update of tab[1].
124 chrome.test.assertEq(true, tab1.selected);
118 chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) { 125 chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
119 assertEq(true, tabs[1].selected); 126 assertEq(true, tabs[1].selected);
120 assertEq(false, tabs[2].selected); 127 assertEq(false, tabs[2].selected);
121 // Select tab[2]. 128 // Select tab[2].
122 chrome.tabs.update(tabs[2].id, {selected: true}, 129 chrome.tabs.update(tabs[2].id, {selected: true},
123 pass(function(){ 130 pass(function(tab2){
124 // Check update of tab[2]. 131 // Check update of tab[2].
132 chrome.test.assertEq(true, tab2.selected);
125 chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) { 133 chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
126 assertEq(false, tabs[1].selected); 134 assertEq(false, tabs[1].selected);
127 assertEq(true, tabs[2].selected); 135 assertEq(true, tabs[2].selected);
128 })); 136 }));
129 })); 137 }));
130 })); 138 }));
131 })); 139 }));
132 })); 140 }));
133 }, 141 },
134 142
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // 184 //
177 // Before: 185 // Before:
178 // Window1: (newtab),a,b,c,d,e 186 // Window1: (newtab),a,b,c,d,e
179 // Window2: (newtab) 187 // Window2: (newtab)
180 // 188 //
181 // After: 189 // After:
182 // Window1: (newtab),a,e,c 190 // Window1: (newtab),a,e,c
183 // Window2: b,(newtab),d 191 // Window2: b,(newtab),d
184 function moveTabs() { 192 function moveTabs() {
185 chrome.tabs.move(moveTabIds['b'], {"windowId": moveWindow2, "index": 0}, 193 chrome.tabs.move(moveTabIds['b'], {"windowId": moveWindow2, "index": 0},
186 pass(function() { 194 pass(function(tabB) {
195 chrome.test.assertEq(0, tabB.index);
187 chrome.tabs.move(moveTabIds['e'], {"index": 2}, 196 chrome.tabs.move(moveTabIds['e'], {"index": 2},
188 pass(function() { 197 pass(function(tabE) {
198 chrome.test.assertEq(2, tabE.index);
189 chrome.tabs.move(moveTabIds['d'], {"windowId": moveWindow2, 199 chrome.tabs.move(moveTabIds['d'], {"windowId": moveWindow2,
190 "index": 2}, pass(function() {})); 200 "index": 2}, pass(function(tabD) {
201 chrome.test.assertEq(2, tabD.index);
202 }));
191 })); 203 }));
192 })); 204 }));
193 }, 205 },
194 206
195 // Check that the tab/window state is what we expect after doing moves. 207 // Check that the tab/window state is what we expect after doing moves.
196 function moveTabsCheck() { 208 function moveTabsCheck() {
197 chrome.tabs.getAllInWindow(moveWindow1, pass(function(tabs) { 209 chrome.tabs.getAllInWindow(moveWindow1, pass(function(tabs) {
198 assertEq(4, tabs.length); 210 assertEq(4, tabs.length);
199 assertEq("chrome://newtab/", tabs[0].url); 211 assertEq("chrome://newtab/", tabs[0].url);
200 assertEq("chrome://a/", tabs[1].url); 212 assertEq("chrome://a/", tabs[1].url);
201 assertEq("chrome://e/", tabs[2].url); 213 assertEq("chrome://e/", tabs[2].url);
202 assertEq("chrome://c/", tabs[3].url); 214 assertEq("chrome://c/", tabs[3].url);
203 215
204 chrome.tabs.getAllInWindow(moveWindow2, pass(function(tabs) { 216 chrome.tabs.getAllInWindow(moveWindow2, pass(function(tabs) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 chrome.tabs.update(moveTabIds['c'], {"selected": true}, 314 chrome.tabs.update(moveTabIds['c'], {"selected": true},
303 pass()); 315 pass());
304 }, 316 },
305 317
306 function onRemoved() { 318 function onRemoved() {
307 chrome.test.listenOnce(chrome.tabs.onRemoved, function(tabid) { 319 chrome.test.listenOnce(chrome.tabs.onRemoved, function(tabid) {
308 assertEq(moveTabIds['c'], tabid); 320 assertEq(moveTabIds['c'], tabid);
309 }); 321 });
310 322
311 chrome.tabs.remove(moveTabIds['c'], pass()); 323 chrome.tabs.remove(moveTabIds['c'], pass());
324 },
325
326 function setupRelativeUrlTests() {
327 chrome.windows.create({}, pass(function(win) {
328 assertTrue(win.id > 0);
329 firstWindowId = win.id;
330
331 chrome.windows.getAll({}, pass(function(windows) {
332 for (var i = 0; i < windows.length; i++) {
333 if (windows[i].id != firstWindowId) {
334 chrome.windows.remove(windows[i].id, pass());
335 }
336 }
337 }));
338 }));
339 },
340
341 // The subsequent three tests all load relative.html, which calls
342 // this page's relativePageLoad(), which ends the test.
343 function relativeUrlTabsCreate() {
344 chrome.tabs.create({windowId: firstWindowId, url: 'relative.html'},
345 pass(function(tab){
346 testTabId = tab.id;
347 }
348 ));
349 },
350
351 function relativeUrlTabsUpdate() {
352 chrome.tabs.update(testTabId, {url: "chrome://a/"}, function(tab) {
353 chrome.test.assertEq("chrome://a/", tab.url);
354 chrome.tabs.update(tab.id, {url: "relative.html"}, function(tab) {
355 });
356 });
357 },
358
359 function relativeUrlWindowsCreate() {
360 chrome.windows.create({url: "relative.html"});
312 } 361 }
313 362
314 // TODO(asargent) We still need to add tests for the following: 363 // TODO(asargent) We still need to add tests for the following:
315 // Methods: 364 // Methods:
316 // -chrome.tabs.connect 365 // -chrome.tabs.connect
317 // Events: 366 // Events:
318 // -chrome.tabs.onAttached 367 // -chrome.tabs.onAttached
319 // -chrome.tabs.onDetched 368 // -chrome.tabs.onDetched
320 // 369 //
321 // Also, it would be an improvement to check the captureVisibleTab results 370 // Also, it would be an improvement to check the captureVisibleTab results
322 // against a known-good result. 371 // against a known-good result.
323 ]); 372 ]);
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/tabs/relative.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698