Skip to content

Commit

Permalink
Bug 1410749 - Start tab ID numbering from #1. r=geckoview-reviewers,e…
Browse files Browse the repository at this point in the history
…sawin

It's easier this way than fixing who knows how many Webextension APIs that have
learned from Desktop that there is no tab #0 and that therefore refuse to work
in our first tab.

We'll also make a similar change to GeckoView's stub implementation of the tab
API because that affects Custom Tabs and PWAs in Fennec for now.

The tests for tab ID 0 are therefore no longer required - they were added in a
previous attempt to fix the Webextension APIs themselves, which was ultimately
never carried through to completion, though.

Differential Revision: https://phabricator.services.mozilla.com/D26431

UltraBlame original commit: 5519079b4dc05033c01baec3e80ff673c3a44f11
  • Loading branch information
marco-c committed Oct 4, 2019
1 parent 29fa396 commit 142afe0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 58 deletions.
4 changes: 3 additions & 1 deletion mobile/android/base/java/org/mozilla/gecko/Tabs.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ public class Tabs implements BundleEventListener {

public static final int NEW_LAST_INDEX = -1;

private static final AtomicInteger sTabId = new AtomicInteger(0);


private static final AtomicInteger sTabId = new AtomicInteger(1);
private volatile boolean mInitialTabsAdded;

private Context mAppContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@
return tab;
}

// Test on tabId 0
// Test that the default title is returned before the title is set for the tab.
let tabTitle = await browser.browserAction.getTitle({tabId: 0});
browser.test.assertEq("Browser Action", tabTitle,
"Expected the default title to be returned for tabId 0");

// Set the title for the new tab and test that getTitle returns the correct title.
await browser.browserAction.setTitle({tabId: 0, title: "tab 0"});
tabTitle = await browser.browserAction.getTitle({tabId: 0});
browser.test.assertEq("tab 0", tabTitle,
"Expected the new tab title to be returned for tabId 0");

// Create and test 3 new tabs.
let tab1 = await createAndTestNewTab("tab 1", "about:blank");
let tab2 = await createAndTestNewTab("tab 2", "about:blank");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,50 +237,6 @@
await extension.unload();
});


add_task(async function tabsSendAndReceiveMessageTabId0() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": ["tabs", "<all_urls>"],
},

async background() {
function contentScriptCode() {
browser.runtime.onMessage.addListener(msg => {
browser.test.assertEq(msg, "message to tabId 0",
"Got the expected message from the background page");

return Promise.resolve("reply to background page");
});
browser.runtime.sendMessage("message from tabId 0");
}

await browser.runtime.onMessage.addListener(async (msg, sender) => {
browser.test.assertEq("message from tabId 0", msg,
"Got the expected message from a content script");
browser.test.assertTrue(sender.tab,
"Got a sender.tab object as expected");
browser.test.assertEq(0, sender.tab.id,
"Got a sender.tab object with tab.id == 0");

const reply = await browser.tabs.sendMessage(0, "message to tabId 0");

browser.test.assertEq("reply to background page", reply);

browser.test.notifyPass("tabs.messaging.tab0");
});

await browser.tabs.executeScript(0, {code: `new ${contentScriptCode}`});
},
});

await extension.startup();

await extension.awaitFinish("tabs.messaging.tab0");

await extension.unload();
});

</script>

</body>
Expand Down
5 changes: 4 additions & 1 deletion mobile/android/modules/geckoview/GeckoViewTab.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ class Tab {

class GeckoViewTab extends GeckoViewModule {
onInit() {
const tab = new Tab(0, this.browser);



const tab = new Tab(10001, this.browser);

this.window.gBrowser = this.window.BrowserApp = {
selectedBrowser: this.browser,
Expand Down

0 comments on commit 142afe0

Please sign in to comment.