Closed Bug 707786 Opened 13 years ago Closed 12 years ago

Use Services.prefs instead of preferences-service / gPrefService, in SeaMonkey tests

Categories

(SeaMonkey :: Testing Infrastructure, defect)

defect
Not set
trivial

Tracking

(seamonkey2.10 verified)

VERIFIED FIXED
seamonkey2.10
Tracking Status
seamonkey2.10 --- verified

People

(Reporter: sgautherie, Assigned: ewong)

References

Details

Attachments

(3 files, 9 obsolete files)

29.41 KB, patch
neil
: review+
sgautherie
: feedback+
Details | Diff | Splinter Review
11.47 KB, patch
ewong
: review+
ewong
: feedback+
Details | Diff | Splinter Review
712 bytes, patch
neil
: review+
sgautherie
: feedback+
Details | Diff | Splinter Review
Blocks: 664838
Assignee: nobody → ewong
Status: NEW → ASSIGNED
Comment on attachment 584560 [details] [diff] [review]
Use Services.prefs instead of preferences-service / gPrefService in SeaMonkey (v1)

> function test()
> {
>+  Components.utils.import("resource://gre/modules/Services.jsm");
Importing Services inside a function is not useful.

>+      this.prefs = Services.prefs;
You're supposed to replace this.prefs with Services.prefs, not assign it...
Comment on attachment 584560 [details] [diff] [review] [diff] [details] [review]
Use Services.prefs instead of preferences-service / gPrefService in SeaMonkey (v1)

>> function test()
>> {
>>+  Components.utils.import("resource://gre/modules/Services.jsm");
>Importing Services inside a function is not useful.

fixed

>>+      this.prefs = Services.prefs;
>You're supposed to replace this.prefs with Services.prefs, not assign it...

fixed
Attachment #584560 - Attachment is obsolete: true
Attachment #584671 - Flags: review?(neil)
Comment on attachment 584671 [details] [diff] [review]
Use Services.prefs instead of preferences-service / gPrefService, in SeaMonkey (v2)

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

See
http://mxr.mozilla.org/mozilla-central/source/toolkit/content/Services.jsm

::: suite/common/downloads/tests/chrome/test_ui_stays_open_on_alert_clickback.xul
@@ +70,4 @@
>  
>    // Close the UI if necessary
>    var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
>                       .getService(Components.interfaces.nsIWindowMediator);

Not strictly this bug, but, while there, would you care to update the other services in the (test) files you touch?

::: suite/common/places/tests/unit/test_browserGlue_smartBookmarks.js
@@ +41,5 @@
>   * by the user or by other components.
>   */
>  
>  Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
> +Components.utils.import("resource://gre/modules/Services.jsm");

Fwiw,
Neil, do we want both imports?
Edmund, do we need either? (I'm guessing 'yes' in xpcshell, I'm 'not sure' in (all/some) mochitest...)
> Not strictly this bug, but, while there, would you care to update the other services in
> the (test) files you touch?
Out of scope in this bug.
Comment on attachment 584671 [details] [diff] [review]
Use Services.prefs instead of preferences-service / gPrefService, in SeaMonkey (v2)

>   <![CDATA[
>+Components.utils.import("resource://gre/modules/Services.jsm");
> 
> function test()
> {
>+
Nit: spare blank line here. (Might move it to after CDATA, see below.)

>  * ***** END LICENSE BLOCK ***** */
>+Components.utils.import("resource://gre/modules/Services.jsm");
Although not so bad in some other places, it looks particularly bad here to have the import statements jammed up against something else. I think it would look neatest to ensure there is a blank line both above and below the import(s) in each file.

> // Get pref service
> try {
>-  var pref =  Cc["@mozilla.org/preferences-service;1"].
>-              getService(Ci.nsIPrefBranch);
>+  var pref =  Services.prefs;
> } catch(ex) {
>   do_throw("Could not get Preferences service\n");
> }
Just replace pref with Services.prefs (sorry if I missed this last time).

> Components.utils.import("resource:///modules/Sanitizer.jsm");
>+Components.utils.import("resource://gre/modules/Services.jsm");
> ok(typeof Sanitizer != "undefined", "Sanitizer module imported")
The import of Sanitizer.jsm is actually a test, so you should import Services.jsm before it.
(In reply to Serge Gautherie from comment #4)
> (From update of attachment 584671 [details] [diff] [review])
> ::: suite/common/places/tests/unit/test_browserGlue_smartBookmarks.js
> @@ +41,5 @@
> >   * by the user or by other components.
> >   */
> >  
> >  Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
> > +Components.utils.import("resource://gre/modules/Services.jsm");
> do we want both imports?
If you can prove that XPCOMUtils isn't necessary then file a bug to remove it.
(In reply to neil@parkwaycc.co.uk from comment #7)
> (In reply to Serge Gautherie from comment #4)
> > >  Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
> > > +Components.utils.import("resource://gre/modules/Services.jsm");
> > do we want both imports?
> If you can prove that XPCOMUtils isn't necessary then file a bug to remove
> it.

My question assumed that Services.jsm importing XPCOMUtils.jsm would subsume doing it explicitely:
http://mxr.mozilla.org/mozilla-central/source/toolkit/content/Services.jsm
43 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

I'll check that if it is not already done in this bug.
> My question assumed that Services.jsm importing XPCOMUtils.jsm would subsume doing it
> explicitely:
Services.jsm is a JS Module. It doesn't export XPCOMUtils so XPCOMUtils is not available to callers of Services.
(In reply to Philip Chee from comment #9)
> Services.jsm is a JS Module. It doesn't export XPCOMUtils so XPCOMUtils is
> not available to callers of Services.

I stand corrected.

Nonetheless, I tested test_browserGlue_smartBookmarks.js and it passes even without importing XPCOMUtils.jsm.
Iiuc, XPCOMUtils.jsm is already imported by head_common.js through head_bookmarks.js.
And head_bookmarks.js even already imports Services.jsm (for its own use).

Then, I doubt even more that Services.jsm imports need to be "re-added" to most/all of these tests: it looks like old getService() can simply be removed.
Ping for update/rewiew.
Attachment #584671 - Attachment is obsolete: true
Attachment #584671 - Flags: review?(neil)
Attachment #600603 - Flags: review?(neil)
Comment on attachment 600603 [details] [diff] [review]
Use Services.prefs instead of preferences-service / gPrefService, in SeaMonkey (v3)

patch has been bitrotted.
Attachment #600603 - Flags: review?(neil)
Attachment #600603 - Attachment is obsolete: true
Attachment #600608 - Flags: review?(neil)
Comment on attachment 600608 [details] [diff] [review]
Use Services.prefs instead of preferences-service / gPrefService, in SeaMonkey (v4)

What about my previous comments about not needing some of the imports?
Comment on attachment 600608 [details] [diff] [review]
Use Services.prefs instead of preferences-service / gPrefService, in SeaMonkey (v4)

> let tempScope = {};
>+Components.utils.import("resource://gre/modules/Services.jsm");
I don't remember that line being there before but now it's there you should import Services before it. r=me with that fixed.

Serge could be right about Services already being imported in some of the tests but he should identify which ones (e.g. "all the Places tests") so you know which ones you can remove the imports from again. (That change doesn't need my review but you may want to request feedback from him to double-check.)
Attachment #600608 - Flags: review?(neil) → review+
(In reply to neil@parkwaycc.co.uk from comment #16)
> Comment on attachment 600608 [details] [diff] [review]
> Use Services.prefs instead of preferences-service / gPrefService, in
> SeaMonkey (v4)
> 
> > let tempScope = {};
> >+Components.utils.import("resource://gre/modules/Services.jsm");
> I don't remember that line being there before but now it's there you should
> import Services before it. r=me with that fixed.

That line's new (not part of my patch).  That line (amongst others) bitrotted
me.
Attachment #600608 - Flags: feedback?(sgautherie.bz)
Attachment #600608 - Attachment is obsolete: true
Attachment #600608 - Flags: feedback?(sgautherie.bz)
Attachment #600838 - Flags: review+
Attachment #600838 - Flags: feedback?(sgautherie.bz)
Comment on attachment 600838 [details] [diff] [review]
Use Services.prefs instead of preferences-service / gPrefService, in SeaMonkey (v5)

(In reply to neil@parkwaycc.co.uk from comment #16)

> > let tempScope = {};
> >+Components.utils.import("resource://gre/modules/Services.jsm");
> I don't remember that line being there before but now it's there you should

I added it in bug 725529.

> import Services before it. r=me with that fixed.

That's wrong: either (re-)importing Services.jsm in browser-chrome tests is not needed or it should be done through tempScope too. (See that bug.)

> Serge could be right about Services already being imported in some of the
> tests but he should identify which ones (e.g. "all the Places tests") so you
> know which ones you can remove the imports from again.

I already started to do this in my previous comments.
Wrt to the other cases, it's ease to comment the added import out then check whether/why the test passes.
Attachment #600838 - Flags: review+
Attachment #600838 - Flags: feedback?(sgautherie.bz)
Attachment #600838 - Flags: feedback-
It seems as if none of the tests require the import statement, so I removed the import statement from all tests.
Attachment #600838 - Attachment is obsolete: true
Attachment #603597 - Flags: review?(neil)
Comment on attachment 603597 [details] [diff] [review]
Use Services.prefs instead of preferences-service / gPrefService, in SeaMonkey (v6)

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

::: suite/modules/test/browser_sanitizer.js
@@ +302,2 @@
>  
> +  var poppref = Services.prefs.getBranch("privacy.sanitize.");

Nit: while here, you could just get rid of poppref by inlining "privacy.sanitize." where it is used (twice).
Attachment #603597 - Flags: review?(neil) → feedback+
Fixed nit from comment #21.
Attachment #603597 - Attachment is obsolete: true
Attachment #603938 - Flags: review?(neil)
Comment on attachment 603938 [details] [diff] [review]
Use Services.prefs instead of preferences-service / gPrefService, in SeaMonkey (v7)

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

(I don't think Neil needs/wants to review this again.)

::: suite/modules/test/browser_sanitizer.js
@@ +302,3 @@
>  
> +  Services.prefs.getBranch("privacy.sanitize.")
> +                .setBoolPref("promptOnSanitize", false);

Doesn't "privacy.sanitize.promptOnSanitize" just work? (both places)
Attachment #603938 - Flags: review?(neil)
Misunderstood 'inlining'  Fixed.
Attachment #603938 - Attachment is obsolete: true
Attachment #603958 - Flags: review?(neil)
Wrong patch added.  Fixed.
Attachment #603958 - Attachment is obsolete: true
Attachment #603958 - Flags: review?(neil)
Attachment #603959 - Flags: review?(neil)
Comment on attachment 603959 [details] [diff] [review]
Use Services.prefs instead of preferences-service / gPrefService, in SeaMonkey (v8)

Fair enough, assuming it all works...
Attachment #603959 - Flags: review?(neil) → review+
Attachment #603959 - Flags: feedback+
Pushed to comm-central:
http://hg.mozilla.org/comm-central/rev/714c2c71f323
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Not fully fixed yet:

Tests:
http://mxr.mozilla.org/comm-central/search?string=preferences-service&case=1&find=%2Fsuite%2F.*%2Ftest
"Found 2 matching lines in 2 files"


Shall we fix application code too while here? Or in a separate bug?
http://mxr.mozilla.org/comm-central/search?string=gPrefService&case=1&find=%2Fsuite%2F
"Found 10 matching lines in 3 files"
http://mxr.mozilla.org/comm-central/search?string=preferences-service&case=1&find=%2Fsuite%2F
"Found 77 matching lines in 44 files"
Status: RESOLVED → REOPENED
Flags: in-testsuite+
Resolution: FIXED → ---
Target Milestone: --- → seamonkey2.10
Fixed outstanding occurrences.
Attachment #604743 - Flags: review?(neil)
Attachment #604743 - Flags: feedback?(sgautherie.bz)
Attachment #604743 - Flags: review?(neil) → review+
Comment on attachment 604743 [details] [diff] [review]
Use Services.prefs instead of preferences-service / gPrefService in SeaMonkey p2 (v1)

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

::: suite/common/places/tests/unit/test_384370.js
@@ -59,5 @@
>  
>    // get places import/export service
>    var importer = Cc["@mozilla.org/browser/places/import-export-service;1"].getService(Ci.nsIPlacesImportExportService);
>  
> -  // avoid creating the places smart folder during tests

Nit: Leave this comment in, or fix it if it's wrong.
Attachment #604743 - Flags: feedback?(sgautherie.bz) → feedback+
Pushed to comm-central:
http://hg.mozilla.org/comm-central/rev/f3dd079d3da9
Status: REOPENED → RESOLVED
Closed: 12 years ago12 years ago
Resolution: --- → FIXED
V.Fixed, per MXR search.
Status: RESOLVED → VERIFIED
Summary: Use Services.prefs instead of preferences-service / gPrefService, in SeaMonkey → Use Services.prefs instead of preferences-service / gPrefService, in SeaMonkey tests
Whiteboard: [good first bug]
Blocks: 735333
(In reply to Serge Gautherie (:sgautherie) from comment #28)
> Shall we fix application code too while here? Or in a separate bug?

I filed bug 735333.
One of the test fails: (apparently on Linux and Windows, not OSX 10.6)
{
13144 ERROR TEST-UNEXPECTED-FAIL | chrome://mochitests/content/chrome/suite/common/downloads/tests/test_ui_stays_open_on_alert_clickback.xul | an unexpected uncaught JS exception reported through window.onerror - Services is not defined at chrome://mochitests/content/chrome/suite/common/downloads/tests/test_ui_stays_open_on_alert_clickback.xul:66
}
Status: VERIFIED → REOPENED
Resolution: FIXED → ---
Comment on attachment 607539 [details] [diff] [review]
Use Services.prefs instead of preferences-service / gPrefService in SeaMonkey p3 (v1)
[Checked in: Comment 39 & 44]

Verified patch allows test to pass.
Attachment #607539 - Flags: review?(neil) → review+
Comment on attachment 607539 [details] [diff] [review]
Use Services.prefs instead of preferences-service / gPrefService in SeaMonkey p3 (v1)
[Checked in: Comment 39 & 44]

That's most likely it :->
Attachment #607539 - Flags: feedback?(sgautherie.bz) → feedback+
Pushed p3 to comm-central:
http://hg.mozilla.org/comm-central/rev/2326f20b3bc6
Status: REOPENED → RESOLVED
Closed: 12 years ago12 years ago
Resolution: --- → FIXED
http://tinderbox.mozilla.org/showlog.cgi?log=SeaMonkey/1332499182.1332503873.20181.gz
Linux comm-central-trunk debug test mochitest-other on 2012/03/23 03:39:42

V.Fixed
Status: RESOLVED → VERIFIED
Comment on attachment 607539 [details] [diff] [review]
Use Services.prefs instead of preferences-service / gPrefService in SeaMonkey p3 (v1)
[Checked in: Comment 39 & 44]

[Approval Request Comment]
Regression happened in SM 2.10 initially.
No risk, test only.
Attachment #607539 - Flags: approval-comm-aurora?
Comment on attachment 607539 [details] [diff] [review]
Use Services.prefs instead of preferences-service / gPrefService in SeaMonkey p3 (v1)
[Checked in: Comment 39 & 44]

Missed Aurora-2.10.
Attachment #607539 - Flags: approval-comm-aurora? → approval-comm-beta?
Comment on attachment 607539 [details] [diff] [review]
Use Services.prefs instead of preferences-service / gPrefService in SeaMonkey p3 (v1)
[Checked in: Comment 39 & 44]

a=test-only
Attachment #607539 - Flags: approval-comm-beta? → approval-comm-beta+
http://tinderbox.mozilla.org/showlog.cgi?log=SeaMonkey-Beta/1337595251.1337600055.1708.gz
WINNT 5.2 comm-beta debug test mochitest-other on 2012/05/21 03:14:11

seamonkey2.10: verified.
Attachment #607539 - Attachment description: Use Services.prefs instead of preferences-service / gPrefService in SeaMonkey p3 (v1) → Use Services.prefs instead of preferences-service / gPrefService in SeaMonkey p3 (v1) [Checked in: Comment 39 & 44]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: