Closed Bug 1130287 Opened 7 years ago Closed 7 years ago

Expose isB2G in SpecialPowers

Categories

(Firefox OS Graveyard :: Runtime, defect)

x86_64
Linux
defect
Not set
normal

Tracking

(firefox38 fixed)

RESOLVED FIXED
2.2 S6 (20feb)
Tracking Status
firefox38 --- fixed

People

(Reporter: gerard-majax, Assigned: gerard-majax)

References

Details

(Whiteboard: [systemsfe])

Attachments

(1 file, 3 obsolete files)

On B2G Desktop/Mulet, the user agent string is:
> Mozilla/5.0 (rv:38.0) Gecko/20100101 Firefox/38.0

On Firefox OS Simulator (FXOS_SIMULATOR flag), we have:
> Mozilla/5.0 (X11; Mobile; rv:38.0) Gecko/20100101 Firefox/38.0

Having B2G Destop, Mulet, and Firefox OS Simulator having the same user agent string makes sense and would help fixing some mochitests.
I disagree. There's no reason b2g desktop should pretend to be Mobile when it's not running as FXOS_SIMULATOR. I don't care too much about Mulet.
From http://ftp.mozilla.org/pub/mozilla.org/b2g/try-builds/alissy@mozilla.com-b92db483929d/try-linux64_gecko/try_ubuntu64_vm-b2gdt_test-mochitest-oop-1-bm115-tests1-linux64-build1030.txt.gz :
> 03:16:49     INFO -  8425 INFO TEST-START | dom/workers/test/test_navigator.html
> 03:16:49     INFO -  UserAgent :: Mozilla/5.0 (Mobile; rv:38.0) Gecko/20100101 Firefox/38.0
> 03:16:49     INFO -  UserAgent :: Mozilla/5.0 (Mobile; rv:38.0) Gecko/20100101 Firefox/38.0 => isDesktop: false
> 03:16:49     INFO -  UserAgent :: Mozilla/5.0 (Mobile; rv:38.0) Gecko/20100101 Firefox/38.0 => isB2G: true
> 03:16:49     INFO -  8426 INFO TEST-OK | dom/workers/test/test_navigator.html | took 219ms

So B2G Desktop Linux shows the "Mobile" substring.
And that's because ... http://ftp.mozilla.org/pub/mozilla.org/b2g/try-builds/alissy@mozilla.com-b92db483929d/try-linux64_gecko/try-linux64_gecko-bm75-try1-build4736.txt.gz :

> # Build simulator xpi and phone tweaks for b2g-desktop
> FXOS_SIMULATOR=1
Current uses:

Introduction FXOS_SIMULATOR=1 : f0f375c4 2014-04-08 08:23:00 +0200
==================================================================

 - dom/base/test/test_getFeature_with_perm.html:    var isB2G = !isAndroid && /Mobile|Tablet/.test(navigator.userAgent);
   => 843ce0bc 2014-04-15 14:30:22 +0800

 - dom/base/test/test_hasFeature.html:    var isB2g = isMulet || (!isAndroid && /Mobile|Tablet/.test(navigator.userAgent));
   => 62da4d35 2014-07-24 16:57:02 -0300

 - dom/browser-element/mochitest/browserElement_GetScreenshot.js:        var isB2G = (navigator.platform === '');
   => 2f91ae99 2014-01-13 08:55:15 -0500

 - dom/canvas/test/test_drawWindow.html:    var isB2G = /Mobile|Tablet/.test(navigator.userAgent) &&
   => 9fcd6a5b 2014-04-14 11:12:00 -0700

 - dom/tests/mochitest/general/test_donottrack.html:  var isB2G = !isAndroid && /Mobile|Tablet/.test(navigator.userAgent);
   => d2190515 2014-05-26 22:10:39 +0100

 - dom/tests/mochitest/general/test_interfaces.html:  var isB2G = !isDesktop && !navigator.userAgent.contains("Android");
   => 793b2837e 2013-09-01 02:50:18 +0900

 - dom/workers/test/navigator_worker.js:var isB2G = !isDesktop && !navigator.userAgent.contains("Android");
   => dd4520e3 2014-02-24 21:57:42 +0800

 - dom/workers/test/test_worker_interfaces.js:  var isB2G = !isDesktop && !userAgent.contains("Android");
   => 3017d285 2014-07-31 21:54:44 -0400
(In reply to Alexandre LISSY :gerard-majax from comment #3)
> And that's because ...
> http://ftp.mozilla.org/pub/mozilla.org/b2g/try-builds/alissy@mozilla.com-
> b92db483929d/try-linux64_gecko/try-linux64_gecko-bm75-try1-build4736.txt.gz :
> 
> > # Build simulator xpi and phone tweaks for b2g-desktop
> > FXOS_SIMULATOR=1

When removed, it fails also on B2G Desktop: https://treeherder.mozilla.org/#/jobs?repo=try&revision=877652fc8efa&exclusion_state=all
Summary: Expose "Mobile" in User Agent String for B2G Desktop/Mulet → Fix mochitests for proper B2G detection
Whiteboard: [systemsfe]
Depends on: 1115935
Attachment #8560867 - Flags: review?(jonas)
Comment on attachment 8560867 [details] [diff] [review]
Expose isB2G in SpecialPowers r=sicking

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

::: testing/specialpowers/content/specialpowersAPI.js
@@ +1508,5 @@
> +      } catch (ex) { };
> +    }
> +
> +    return this._isB2G;
> +  },

Simpler option: make specialpowersAPI.js a preprocessed file, and just do:

get isB2G() {
#ifdef MOZ_B2G
  return true;
#else
  return false;
#endif
}
Comment on attachment 8560867 [details] [diff] [review]
Expose isB2G in SpecialPowers r=sicking

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

r=me with this or Fabrice's solution.
Attachment #8560867 - Flags: review?(jonas) → review+
Some mochitests needs to behave differently when ran on B2G Desktop.
Currently, this is implemented using user agent string detection,
mostly relying on "Mobile" being present and "Android" being absent.
This is only true on B2G Desktop when ran on Try because the mozconfig
defined FXOS_SIMULATOR and that, per bug 1115935, this substring is only
added in this case, but not if just MOZ_B2G is defined. A better
approach is to expose 'isB2G' in SpecialPowers for this kind of
detection.
Comment on attachment 8560984 [details] [diff] [review]
Expose isB2G in SpecialPowers r=sicking

Carrying r+ from :sicking, implemented as suggested by :fabrice
Attachment #8560984 - Flags: review+
Attachment #8560867 - Attachment is obsolete: true
Summary: Fix mochitests for proper B2G detection → Expose isB2G in SpecialPowers
Some mochitests needs to behave differently when ran on B2G Desktop.
Currently, this is implemented using user agent string detection,
mostly relying on "Mobile" being present and "Android" being absent.
This is only true on B2G Desktop when ran on Try because the mozconfig
defined FXOS_SIMULATOR and that, per bug 1115935, this substring is only
added in this case, but not if just MOZ_B2G is defined. A better
approach is to expose 'isB2G' in SpecialPowers for this kind of
detection.
Attachment #8560984 - Attachment is obsolete: true
Comment on attachment 8561024 [details] [diff] [review]
Expose isB2G in SpecialPowers r=sicking

Carrying r+, making specialpowersAPI.js a preprocessed file on more cases.
Attachment #8561024 - Flags: review+
Comment on attachment 8561024 [details] [diff] [review]
Expose isB2G in SpecialPowers r=sicking

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

::: testing/specialpowers/content/specialpowersAPI.js
@@ +4,5 @@
>  /* This code is loaded in every child process that is started by mochitest in
>   * order to be used as a replacement for UniversalXPConnect
>   */
>  
> +#filter substitution

Are you sure you need that?
According to the doc, you're right it's not needed. Thanks for spotting it
Attachment #8561024 - Attachment is obsolete: true
Some mochitests needs to behave differently when ran on B2G Desktop.
Currently, this is implemented using user agent string detection,
mostly relying on "Mobile" being present and "Android" being absent.
This is only true on B2G Desktop when ran on Try because the mozconfig
defined FXOS_SIMULATOR and that, per bug 1115935, this substring is only
added in this case, but not if just MOZ_B2G is defined. A better
approach is to expose 'isB2G' in SpecialPowers for this kind of
detection.
Attachment #8561063 - Flags: review+
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/8fff8db4305b
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → 2.2 S6 (20feb)
You need to log in before you can comment on or make changes to this bug.