test_ext_tabs_query.html (1468B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Tabs create Test</title> 6 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 7 <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script> 8 <script type="text/javascript" src="head.js"></script> 9 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 13 <script type="text/javascript"> 14 "use strict"; 15 16 add_task(async function test_query_index() { 17 const extension = ExtensionTestUtils.loadExtension({ 18 background: function() { 19 browser.tabs.onCreated.addListener(async function({index, windowId, id}) { 20 browser.test.assertThrows( 21 () => browser.tabs.query({index: -1}), 22 /-1 is too small \(must be at least 0\)/, 23 "tab indices must be non-negative"); 24 25 let tabs = await browser.tabs.query({index, windowId}); 26 browser.test.assertEq(tabs.length, 1, `Got one tab at index ${index}`); 27 browser.test.assertEq(tabs[0].id, id, "The tab is the right one"); 28 29 tabs = await browser.tabs.query({index: 1e5, windowId}); 30 browser.test.assertEq(tabs.length, 0, "There is no tab at this index"); 31 32 browser.test.notifyPass("tabs.query"); 33 }); 34 }, 35 }); 36 37 await extension.startup(); 38 const win = window.open("http://example.com"); 39 await extension.awaitFinish("tabs.query"); 40 win.close(); 41 await extension.unload(); 42 }); 43 </script> 44 45 </body> 46 </html>