Bug 1446913 - test TabOpen/TabMove event sequence during content click, r=kmag a=RyanVM
authorShane Caraveo <scaraveo@mozilla.com>
Mon, 26 Mar 2018 12:11:10 -0500
changeset 462951 067a4f15341f5e92a373051e0502851e41ffc83d
parent 462950 d0a166d249fbcd024fba7e0b2b3a8bbea35709f3
child 462952 2a46fc9aa444c236b05dd3f6113293e9ad16ca0b
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag, RyanVM
bugs1446913
milestone60.0
Bug 1446913 - test TabOpen/TabMove event sequence during content click, r=kmag a=RyanVM
browser/components/extensions/test/browser/browser_ext_tabs_events.js
browser/components/extensions/test/browser/file_dummy.html
--- a/browser/components/extensions/test/browser/browser_ext_tabs_events.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_events.js
@@ -298,8 +298,60 @@ add_task(async function testTabRemovalEv
 
     background,
   });
 
   await extension.startup();
   await extension.awaitFinish("tabs-events");
   await extension.unload();
 });
+
+add_task(async function testTabCreateRelated() {
+  await SpecialPowers.pushPrefEnv({set: [
+    ["browser.tabs.opentabfor.middleclick", true],
+    ["browser.tabs.insertRelatedAfterCurrent", true],
+  ]});
+
+  async function background() {
+    let created;
+    browser.tabs.onCreated.addListener(tab => {
+      browser.test.log(`tabs.onCreated, index=${tab.index}`);
+      browser.test.assertEq(1, tab.index, "expecting tab index of 1");
+      created = tab.id;
+    });
+    browser.tabs.onMoved.addListener((id, info) => {
+      browser.test.log(`tabs.onMoved, from ${info.fromIndex} to ${info.toIndex}`);
+      browser.test.fail("tabMoved was received");
+    });
+    browser.tabs.onRemoved.addListener((tabId, info) => {
+      browser.test.assertEq(created, tabId, "removed id same as created");
+      browser.test.sendMessage("tabRemoved");
+    });
+  }
+
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      "permissions": ["tabs"],
+    },
+
+    background,
+  });
+
+  // Create a *opener* tab page which has a link to "example.com".
+  let pageURL = "http://example.com/browser/browser/components/extensions/test/browser/file_dummy.html";
+  let openerTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, pageURL);
+  gBrowser.moveTabTo(openerTab, 0);
+
+  await extension.startup();
+
+  let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, "http://example.com/#linkclick", true);
+  await BrowserTestUtils.synthesizeMouseAtCenter("#link_to_example_com",
+                                                 {button: 1}, gBrowser.selectedBrowser);
+  let openTab = await newTabPromise;
+  is(openTab.linkedBrowser.currentURI.spec, "http://example.com/#linkclick",
+     "Middle click should open site to correct url.");
+  BrowserTestUtils.removeTab(openTab);
+
+  await extension.awaitMessage("tabRemoved");
+  await extension.unload();
+
+  BrowserTestUtils.removeTab(openerTab);
+});
--- a/browser/components/extensions/test/browser/file_dummy.html
+++ b/browser/components/extensions/test/browser/file_dummy.html
@@ -1,9 +1,10 @@
 <html>
 <head>
 <title>Dummy test page</title>
 <meta http-equiv="Content-Type" content="text/html;charset=utf-8"></meta>
 </head>
 <body>
 <p>Dummy test page</p>
+<a id="link_to_example_com" href="http://example.com/#linkclick">link</a>
 </body>
 </html>