Closed Bug 1234308 Opened 9 years ago Closed 8 years ago

tabs.onCreated callback should receive a bare tab object as its argument

Categories

(WebExtensions :: Untriaged, defect, P4)

44 Branch
x86_64
Linux
defect

Tracking

(firefox47 fixed)

RESOLVED FIXED
mozilla47
Tracking Status
firefox47 --- fixed

People

(Reporter: general, Assigned: mattw, Mentored)

Details

(Whiteboard: [tabs][good first bug] triaged)

Attachments

(2 files, 4 obsolete files)

User Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0
Build ID: 20151210112434

Steps to reproduce:

chrome.tabs.onCreated.addListener(function onCreated(tab) {
  console.log(tab); // { tab: { tab: ... } }
});


Actual results:

The tab paremeter is an nested object


Expected results:

The tab paremeter should be a plain object

Firefox dev-edition 45.0a2 (2015-12-21)
Linux x64
OS: Unspecified → Linux
Hardware: Unspecified → x86_64
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: blocking-webextensions+
Summary: chrome.tabs.onCreated callback parameter is nested object → tabs.onCreated callback should receive a bare tab object as its argument
Mentor: kmaglione+bmo
Whiteboard: [tabs][good first bug]
Assignee: nobody → mwein
Attachment #8712803 - Flags: review?(kmaglione+bmo)
Comment on attachment 8712803 [details] [diff] [review]
Fixes the tabs.onCreated callback to receive a bare tabs object

Review of attachment 8712803 [details] [diff] [review]:
-----------------------------------------------------------------

This is very close. We just need to be a little stricter.

::: browser/components/extensions/test/browser/browser_ext_tabs_create.js
@@ +123,5 @@
>                browser.tabs.onUpdated.addListener(onUpdated);
>              });
>  
> +            browser.tabs.onCreated.addListener(tab => {
> +              browser.test.assertTrue("id" in tab, `Expected tabs.onCreated callback to receive tab object`);

We need to test that this is actually called. The easiest way would be to add a |createdPromise| to match the |updatedPromise| above.
Attachment #8712803 - Flags: review?(kmaglione+bmo)
Attachment #8712803 - Attachment is obsolete: true
Attachment #8712886 - Flags: review?(kmaglione+bmo)
Comment on attachment 8712886 [details] [diff] [review]
Fixes the tabs.onCreated callback to receive a bare tabs object (patch v2)

Review of attachment 8712886 [details] [diff] [review]:
-----------------------------------------------------------------

::: browser/components/extensions/test/browser/browser_ext_tabs_create.js
@@ +132,3 @@
>              });
>  
> +            promiseTabs.create(test.create).then(createdPromise).then(tab => {

The argument to .then() should be a function, not a promise, so this should look something like the other handlers:

  promiseTabs.create(test.create).then(() => {
    return createdPromise;
  }).then(tab => {

It would be better to use the tab returned by .create(), though, so something like this would work:

  Promise.all([
    promiseTabs.create(test.create),
    createdPromise,
  }).then(([tab]) => {

The Promise.all returns a new promise which resolves when all of the promises in the array you pass it resolves. The ([tab]) in the callback destructures the array of results that that promise returns, and gives you the tab returned by promiseTabs.create.
Attachment #8712886 - Flags: review?(kmaglione+bmo)
I also have createdPromise resolve with a tab, so I think the array passed into the .then() call will be [tab, tab].  If that's true then the destructuring would seem a bit confusing.  Should I go ahead and make createdPromise resolve with nothing to ensure that .then() gets the tab returned by promiseTabs.create?
You should probably change it to resolve with nothing, yes, but it doesn't really matter. You'll still get a two-element array as the result, and the first element will still be the tab from .create().

I wouldn't worry too much about it being confusing. Our code does this all over the place.
Attachment #8712886 - Attachment is obsolete: true
Attachment #8712940 - Flags: review?(kmaglione+bmo)
Sounds good.
Attachment #8712948 - Flags: review?(kmaglione+bmo)
Comment on attachment 8712948 [details] [diff] [review]
Fix tabs.onCreated callback to receive bare tabs object ()

Review of attachment 8712948 [details] [diff] [review]:
-----------------------------------------------------------------

https://treeherder.mozilla.org/#/jobs?repo=try&revision=1625b9c71bd4

::: browser/components/extensions/test/browser/browser_ext_tabs_create.js
@@ +126,5 @@
> +            let createdPromise = new Promise(resolve => {
> +              let onCreated = tab => {
> +                browser.test.assertTrue("id" in tab, `Expected tabs.onCreated callback to receive tab object`);
> +                resolve();
> +              }

You're missing a semicolon.
Attachment #8712948 - Flags: review?(kmaglione+bmo) → review+
Comment on attachment 8712956 [details] [diff] [review]
Fix tabs.onCreated callback to receive bare tabs object ()

In the future, you can just set r+ when you update a patch that already has r+
Attachment #8712956 - Flags: review?(kmaglione+bmo) → review+
Attachment #8712948 - Attachment is obsolete: true
Attachment #8712940 - Attachment is obsolete: true
Attachment #8712940 - Flags: review?(kmaglione+bmo)
Okay cool, will do.
Priority: -- → P4
Whiteboard: [tabs][good first bug] → [tabs][good first bug] triaged
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/1b4278d9c84c
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla47
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: