Closed Bug 987185 Opened 10 years ago Closed 10 years ago

Add test for the functionality of the Sync button when user is signed into an account

Categories

(Firefox :: Sync, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
Firefox 35

People

(Reporter: mihaelav, Assigned: mihaelav)

References

(Blocks 1 open bug)

Details

(Whiteboard: [tps][Australis:P-])

Attachments

(1 file, 3 obsolete files)

This is a follow-up bug for the Sync button functionality in Australis - bug #967000 comment #21:
"For this, too, can you file a followup bug to test that it starts a sync process if you're signed in?"
I think this is TPS dependent. Henrik, can you please help with some tracking/blocking bugs for this? Thank you!
This is definitely a TPS related test. Also it might have to rely on Mozmill. As of now we do not have Mozmill tests active, and also have to update mozmill to 2.0.6. But all that should not stop us to get a test implemented.

Mihaela, do you want to work on that test?
Whiteboard: [tps]
I don't know what TPS is, but I presume that this can just be a browser mochitest with some mocking of the signed in state...
If a mockup for sync is fine for you, you wont need tps (https://developer.mozilla.org/en-US/docs/TPS), which is for testing against the real sync server.
(In reply to Henrik Skupin (:whimboo) from comment #2)
> Mihaela, do you want to work on that test?
I was thinking that maybe we can use this in this week's automation training days. If nobody else jumps for it, I can work on it later.
I don't think we will find someone with such an experience to work on that during the training day. So it would be good if you can get started. I'm happy to help with sync and fxaccount related questions.
Whiteboard: [tps] → [tps][Australis:P-]
QA Contact: mihaela.velimiroviciu
Attached patch v1 (obsolete) — Splinter Review
I couldn't fake the account to be signed in so that clicking the Sync button to start a sync, but I managed to set up the account and pressing the Sync button starts the login with the configured account, which IMO also validates the functionality of the button.
Attachment #8432502 - Flags: review?(gijskruitbosch+bugs)
Comment on attachment 8432502 [details] [diff] [review]
v1

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

This looks reasonable to me, but for the nits below. I'm flagging Mark for review because this is sync stuff and I am not an expert. Can you also do a try push of this patch? Thanks!

::: browser/components/customizableui/test/browser_987185_sync.js
@@ +7,5 @@
> +let tmp = {};
> +
> +Components.utils.import("resource://gre/modules/Promise.jsm", tmp);
> +Components.utils.import("resource://gre/modules/Services.jsm", tmp);
> +Components.utils.import("resource://gre/modules/FxAccounts.jsm", tmp);

I expect none of these imports are necessary. :-)

@@ +17,5 @@
> +
> +  let account = new FxAccounts({onlySetInternal: true})
> +  let credentials = {
> +    email: "test_sync_button_987185@example.com",
> +    uid: "1234@lcip.org",

lcip.org ? :-)

Might as well use example.org/.com if it doesn't matter.

@@ +55,5 @@
> +  // reset the panel UI to the default state
> +  yield resetCustomization();
> +  ok(CustomizableUI.inDefaultState, "The panel UI is in default state again.");
> +
> +  if(isPanelUIOpen()) {

Nit: space after 'if'
Attachment #8432502 - Flags: review?(mhammond)
Attachment #8432502 - Flags: review?(gijskruitbosch+bugs)
Attachment #8432502 - Flags: feedback+
Attached patch v1.1 (obsolete) — Splinter Review
Updated patch.

remote:   https://tbpl.mozilla.org/?tree=Try&rev=9ad448e09ec5
Attachment #8432502 - Attachment is obsolete: true
Attachment #8432502 - Flags: review?(mhammond)
Attachment #8432539 - Flags: review?(mhammond)
Comment on attachment 8432539 [details] [diff] [review]
v1.1

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

As you probably noticed, the try run was orange on some platforms.  Without arranging for the sync logs to appear in the test output, it's hard to guess why, but the most likely option is that without mocking more of the FxA stuff, we might be failing to initialize correctly, so no attempt to login will happen.  This initialization is async.  I suspect this test will also cause us to hit the real network to try and authenticate the stub user you setup (which might not be a real problem)

Also, the platforms that pass still log:

09:05:51     INFO -  * Call to xpconnect wrapped JSObject produced this error:  *
09:05:51     INFO -  [Exception... "Unexpected error"  nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)"  location: "JS frame :: chrome://browser/content/browser.js :: SUI_onActivityStart/< :: line 9294"  data: 

Sadly getting logs will require some cargo-culting - probably making the logs 'FirefoxAccounts', 'Sync.BrowserIDManager' and 'Sync.SyncScheduler' have a level of TRACE and creating a new log DumpAppender and attaching it to them - the resulting dump() calls should end up in the log.

On a more general note, I don't actually see a whole lot of value in this test trying to go quite this far.  The button calls gSyncUI.handleToolbarButton() and we want to ensure that calls Weave.Service.errorHandler.syncAndReportErrors().  The latter function already has test coverage, so it's probably not necessary to check a sync actually starts, simply that the function is called (or maybe that service.sync() is called, which is what syncAndReportErrors() calls).  So I wonder if the test can mock-out gSyncUI.needsSetup() to always return false, then mock-out either errorHandler.syncAndReportErrors or service.sync just to verify the call is made, and if so, assume the sync xpcshell tests cover the fact that these functions actually work as intended.  This might help keep sync and FxA totally out of the test path which sounds like a win.

::: browser/components/customizableui/test/browser_987185_sync.js
@@ +27,5 @@
> +  yield account.setSignedInUser(credentials);
> +
> +  Weave.Svc.Obs.add("weave:service:login:start", function onSyncStart() {
> +    Weave.Svc.Obs.remove("weave:service:login:start", onSyncStart);
> +    loginStarted = true;

instead of a flag and a waitForCondition, an alternative would be to create a deferred and resolve it in the observer.  The waitForCondition would then be replaced with a yield for the promise.
Attachment #8432539 - Flags: review?(mhammond) → review-
Attached patch v2 (obsolete) — Splinter Review
I mocked the syncAndReportErrors function and faked the conditions for needsSetup to return false.

Try run: https://treeherder.mozilla.org/ui/#/jobs?repo=try&revision=e987a461b109
Assignee: nobody → mihaela.velimiroviciu
Attachment #8432539 - Attachment is obsolete: true
Attachment #8498886 - Flags: review?(mhammond)
Comment on attachment 8498886 [details] [diff] [review]
v2

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

This looks fine to me - thanks!  r=me with the requested changes.

::: browser/components/customizableui/test/browser_987185_syncButton.js
@@ +13,5 @@
> +let service = syncService.Service;
> +let signedInUser;
> +let syncWasCalled = false;
> +
> +add_task(function() {

generator functions should be declared as "function* ()" these days (both here and for asyncCleanup) - and this function should have a name as IIRC, the name is used in some test logs.

@@ +49,5 @@
> +});
> +
> +function mockFunctions() {
> +  // alter properties to make gSyncUI._needsSetup() always return false
> +  Weave.Status._authManager._signedInUser = false;

Can we do the same mock for _needsSetup - I'd think something like gSyncUI._needsSetup = function() false; (along with saving and restoring like for syncAndREportErrors) would do it and be a little cleaner and more obvious.
Attachment #8498886 - Flags: review?(mhammond) → review+
Attached patch v2.1Splinter Review
Attachment #8498886 - Attachment is obsolete: true
Attachment #8499408 - Flags: review+
https://hg.mozilla.org/integration/fx-team/rev/23a0a5f3c0ad
Flags: in-testsuite+
Keywords: checkin-needed
Whiteboard: [tps][Australis:P-] → [tps][Australis:P-][fixed-in-fx-team]
https://hg.mozilla.org/mozilla-central/rev/23a0a5f3c0ad
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Whiteboard: [tps][Australis:P-][fixed-in-fx-team] → [tps][Australis:P-]
Target Milestone: --- → Firefox 35
You need to log in before you can comment on or make changes to this bug.