Write a test for bug 867649: Test that SMS app acquires CPU wake lock after receiving system message and then releases it after displaying a notification to the user

RESOLVED FIXED

Status

RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: justin.lebar+bug, Assigned: julienw)

Tracking

unspecified
Dependency tree / graph

Firefox Tracking Flags

(b2g18 fixed)

Details

(Whiteboard: u=fx-os-user c=scravag-sprint p=1)

Attachments

(1 attachment, 2 obsolete attachments)

See bug 867649 comment 3: Julien volunteered to write a unit test for this bug.
(Reporter)

Updated

6 years ago
Assignee: nobody → felash
(Assignee)

Comment 1

6 years ago
Bug 840075 will likely modify activity_handler.js to make it more easily testable, so I'll wait for this bug.
Depends on: 840075
(Assignee)

Comment 2

6 years ago
Created attachment 750581 [details] [diff] [review]
WIP patch v1
(Assignee)

Updated

6 years ago
Blocks: 874441
Whiteboard: u=fx-os-user c=scravag-sprint-may-20-31 p=1
Whiteboard: u=fx-os-user c=scravag-sprint-may-20-31 p=1 → u=fx-os-user c=scravag-sprint p=1
(Assignee)

Updated

6 years ago
Blocks: 876350
(Assignee)

Comment 3

6 years ago
Created attachment 754812 [details] [diff] [review]
patch v1

* Moved the wake lock and notification helper mocks to /shared
* added lots of mocks, some very basic
* added tests for the actibity handler
---
 apps/sms/test/unit/activity_handler_test.js        |  125 ++++++++++++++++++--
 apps/sms/test/unit/mock_black_list.js              |   13 ++
 apps/sms/test/unit/mock_contacts.js                |   35 ++++++
 apps/sms/test/unit/mock_messages.js                |   53 +++++++++
 apps/sms/test/unit/mock_navigator_moz_apps.js      |   31 +++++
 .../unit/mock_navigator_moz_set_message_handler.js |   35 ++++++
 apps/sms/test/unit/mock_threads.js                 |    9 ++
 apps/system/test/unit/app_install_manager_test.js  |    2 +-
 apps/system/test/unit/mock_navigator_wake_lock.js  |   41 -------
 apps/system/test/unit/mock_notification_helper.js  |   22 ----
 apps/system/test/unit/update_manager_test.js       |    2 +-
 shared/test/unit/mocks/mock_navigator_wake_lock.js |   41 +++++++
 shared/test/unit/mocks/mock_notification_helper.js |   32 +++++
 13 files changed, 369 insertions(+), 72 deletions(-)
 create mode 100644 apps/sms/test/unit/mock_black_list.js
 create mode 100644 apps/sms/test/unit/mock_contacts.js
 create mode 100644 apps/sms/test/unit/mock_messages.js
 create mode 100644 apps/sms/test/unit/mock_navigator_moz_apps.js
 create mode 100644 apps/sms/test/unit/mock_navigator_moz_set_message_handler.js
 create mode 100644 apps/sms/test/unit/mock_threads.js
 delete mode 100644 apps/system/test/unit/mock_navigator_wake_lock.js
 delete mode 100644 apps/system/test/unit/mock_notification_helper.js
 create mode 100644 shared/test/unit/mocks/mock_navigator_wake_lock.js
 create mode 100644 shared/test/unit/mocks/mock_notification_helper.js

see also PR https://github.com/mozilla-b2g/gaia/pull/10040

I tried to use sinon.js to do some mocks (especially the contacts mock) but they are too specific here.
Attachment #750581 - Attachment is obsolete: true
Attachment #754812 - Flags: review?(gnarf37)
Comment on attachment 754812 [details] [diff] [review]
patch v1

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

Couple of random comments, none of it blocking though.  Also, I assume you can tell me why we are removing mocks from apps/system?  So long as the whole suite still passes: r=me

::: apps/sms/test/unit/activity_handler_test.js
@@ +42,5 @@
> +    realWakeLock = navigator.requestWakeLock;
> +    navigator.requestWakeLock = MockNavigatorWakeLock.requestWakeLock;
> +
> +    realMozApps = navigator.mozApps;
> +    navigator.mozApps = MockNavigatormozApps;

Seeing us add three of these in one test, might it be time to make MocksHelper able to do navigator. namespace replaces as well?

@@ +80,5 @@
>  
>      setup(function() {
>        this.prevHash = window.location.hash;
> +
> +      shareActivity = {

Why use a var instead of this. ?

@@ +135,5 @@
> +    });
> +
> +    suite('after getSelf', function() {
> +      setup(function(done) {
> +        setTimeout(function() { done(); });

Could the response to getSelf be stubbed and then just called here instead of going async with the setup?

::: apps/sms/test/unit/mock_messages.js
@@ +30,5 @@
> +      id: 1,
> +      threadId: 1,
> +      sender: 'sender',
> +      receivers: ['receiver'],
> +      body: 'body',

mms don't have a body

@@ +37,5 @@
> +      timestamp: Date.now(),
> +      read: true,
> +      subject: '',
> +      smil: null,
> +      attachments: [],

[new Blob(['body'], {type: 'text/plain'})]

::: apps/sms/test/unit/mock_navigator_moz_apps.js
@@ +3,5 @@
> +var MockNavigatormozApps = {
> +  getSelf: function mnma_getSelf() {
> +    var request = {};
> +
> +    setTimeout(function nextTick() {

Could we make this a method we can call from the test setup rather than force an async here?
Attachment #754812 - Flags: review?(gnarf37) → review+
(Assignee)

Comment 5

6 years ago
(In reply to Corey Frang [:gnarf] [:gnarf37] from comment #4)
> Comment on attachment 754812 [details] [diff] [review]
> patch v1
> 
> Review of attachment 754812 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> Couple of random comments, none of it blocking though.  Also, I assume you
> can tell me why we are removing mocks from apps/system?  So long as the
> whole suite still passes: r=me

not removing, moving to /shared ;)

> ::: apps/sms/test/unit/activity_handler_test.js
> @@ +42,5 @@
> > +    realWakeLock = navigator.requestWakeLock;
> > +    navigator.requestWakeLock = MockNavigatorWakeLock.requestWakeLock;
> > +
> > +    realMozApps = navigator.mozApps;
> > +    navigator.mozApps = MockNavigatormozApps;
> 
> Seeing us add three of these in one test, might it be time to make
> MocksHelper able to do navigator. namespace replaces as well?

I already tried this numerous time but I can't find a nice enough API. So for now I'm not doing it.

> 
> @@ +80,5 @@
> >  
> >      setup(function() {
> >        this.prevHash = window.location.hash;
> > +
> > +      shareActivity = {
> 
> Why use a var instead of this. ?

Just a matter of habit, that's how I do for other tests, and I feel like this can lead to less unknown side-effects. I didn't want to change what was existing though.

I can change this if you want though. You're the reviewer, you're the master ;)

> 
> @@ +135,5 @@
> > +    });
> > +
> > +    suite('after getSelf', function() {
> > +      setup(function(done) {
> > +        setTimeout(function() { done(); });
> 
> Could the response to getSelf be stubbed and then just called here instead
> of going async with the setup?

> ::: apps/sms/test/unit/mock_navigator_moz_apps.js
> @@ +3,5 @@
> > +var MockNavigatormozApps = {
> > +  getSelf: function mnma_getSelf() {
> > +    var request = {};
> > +
> > +    setTimeout(function nextTick() {
> 
> Could we make this a method we can call from the test setup rather than
> force an async here?

Yep, I can try this. You're right that calling a method or calling setTimeout from the test feels quite the same, and we would have the benefit of a more readable test.

Thanks !
(In reply to Julien Wajsberg [:julienw] from comment #5)
> > Why use a var instead of this. ?
> 
> Just a matter of habit, that's how I do for other tests, and I feel like
> this can lead to less unknown side-effects. I didn't want to change what was
> existing though.
> 
> I can change this if you want though. You're the reviewer, you're the master
> ;)

I'm not sure either is better, but we should make up our minds (soon) and use one.  I think using the `this.` scope is more protected, each test is it's own namespace that way, you can't have a leaky `var`.

Do whichever, both work.
(Assignee)

Comment 7

6 years ago
Created attachment 755271 [details] [diff] [review]
patch v2

carrying r=gnarf

The mozApps mock feels really better now, therefore I promoted it to /shared, along with the setMessageHandler mock.

Pushed to the PR https://github.com/mozilla-b2g/gaia/pull/10040, waiting for travis.
Attachment #754812 - Attachment is obsolete: true
Attachment #755271 - Flags: review+
(Assignee)

Comment 8

6 years ago
unrelated failures on Travis.

master: 933fe64315ff7445aa619b16bf08832f9b5faaf0
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
(Assignee)

Comment 9

6 years ago
a=npotb
v1-train: b09378e2ec19aabaff18bf9582b7230f6a28c49c
status-b2g18: --- → fixed
(Assignee)

Comment 10

6 years ago
(In reply to Corey Frang [:gnarf] [:gnarf37] from comment #6)
> I'm not sure either is better, but we should make up our minds (soon) and
> use one.  I think using the `this.` scope is more protected, each test is
> it's own namespace that way, you can't have a leaky `var`.
> 
> Do whichever, both work.

I read mocha's code and it looks like the context is shared between all suites/tests.

If the this context is only shared to the current suite/test, then I'd be ok with using it, but I'd like that we investigate more before that.
Blocks: 876003
You need to log in before you can comment on or make changes to this bug.