Open Bug 1232631 Opened 9 years ago Updated 3 months ago

Write tests for network part of bug 1137681

Categories

(Core :: Networking: HTTP, defect, P5)

defect

Tracking

()

People

(Reporter: ntim, Unassigned)

References

Details

(Whiteboard: [lang=js][necko-would-take])

Attachments

(1 file, 5 obsolete files)

The docshell part of the patch already has a test, but not the network part.
Whiteboard: [necko-would-take]
Assignee: ntim.bugs → nobody
Status: ASSIGNED → NEW
Mentor: ntim.bugs
Keywords: good-first-bug
Whiteboard: [necko-would-take] → [lang=js]
Whiteboard: [lang=js] → [lang=js][necko-would-take]
How would I go about testing this?
(In reply to Parker from comment #1)
> How would I go about testing this?

Thanks for your interest!
What the test needs to test:
There's a flag on the docShell (window wrapper) that allows you to set the user agent globally for a tab. That flag is customUserAgent. You should test whether that flag applies to the network requests sent inside that tab.

To write the actual test:
- in netwerk/test/mochitests, create a new file called test_user_agent_docshell_override.html
- Paste in the contents of netwerk/test/mochitests/test_user_agent_updates_reset.html inside the file you created
- Add the test to netwerk/test/mochitests/mochitest.ini
- Then you should be able to modify the test to check if the docshell override works, for that task, you can use the following:

... to set the docShell override:
function setOverride(override)
  var Ci = Components.interfaces;
  var docShell = SpecialPowers.wrap(window).QueryInterface(Ci.nsIInterfaceRequestor)
                                 .getInterface(Ci.nsIWebNavigation)
                                 .QueryInterface(Ci.nsIDocShell);
  docShell.customUserAgent = override;
}

... to test if the override works:
isnot(getUA(location.origin), UA_OVERRIDE,
      "No override is set yet");

setOverride(UA_OVERRIDE);

is(getUA(location.origin), UA_OVERRIDE,
  "User-Agent should be");

You'll also need to run the test to see if it works, for that, do:
./mach mochitest netwerk/test/mochitests/test_user_agent_updates_reset.html
Make sure all the tests pass, if not, feel free to needinfo me.
Hey, the netwerk/test/mochitests/user_agent_update.sjs changed in February to 'postMessage' to parent page instead of writing only the UA in the response (rev https://hg.mozilla.org/mozilla-central/rev/11a7fbfbe2d1). So, test_user_agent_updates_reset.html gets the whole page as the "UA" (script tags and all) and fails the test.

There seem like two possible best fixes:

1- Simpler option, add another .sjs file that writes only the UA in the response and make the request to that. Just as user_agent_update.sjs did before rev 11a7fbfbe2d1.
2- Change test_user_agent_updates_reset.html (and the new docshell test) to use an embedded iFrame and handle the postMessage event.

I'm guessing #2, since the other tests moved that way for a reason, but what's the right path forward?
Flags: needinfo?(ntim.bugs)
(In reply to Steve Jarvis [:sajarvis] from comment #3)
> Hey, the netwerk/test/mochitests/user_agent_update.sjs changed in February
> to 'postMessage' to parent page instead of writing only the UA in the
> response (rev https://hg.mozilla.org/mozilla-central/rev/11a7fbfbe2d1). So,
> test_user_agent_updates_reset.html gets the whole page as the "UA" (script
> tags and all) and fails the test.
Thanks for looking into this bug.

I'm surprised test_user_agent_updates_reset.html fails, since it had never been disabled (which means any failure should have been caught by CI). It probably fails silently now.
Anyway, that test should have been updated as per bug 1148544 as well, because right now it tests nothing. 

> There seem like two possible best fixes:
> 
> 1- Simpler option, add another .sjs file that writes only the UA in the
> response and make the request to that. Just as user_agent_update.sjs did
> before rev 11a7fbfbe2d1.
> 2- Change test_user_agent_updates_reset.html (and the new docshell test) to
> use an embedded iFrame and handle the postMessage event.
> 
> I'm guessing #2, since the other tests moved that way for a reason, but
> what's the right path forward?
#2 is the way to go, but let's check with Dylan who has more background than I do on this change.
Flags: needinfo?(ntim.bugs) → needinfo?(droeh)
(In reply to Tim Nguyen :ntim (use needinfo?) from comment #4) 
> I'm surprised test_user_agent_updates_reset.html fails, since it had never
> been disabled (which means any failure should have been caught by CI). It
> probably fails silently now.
> Anyway, that test should have been updated as per bug 1148544 as well,
> because right now it tests nothing. 

Yeah I worded that poorly, test_user_agent_updates_reset.html only checks that the user agent set is *not* the override, and "<html><body><script..." is successfully != "DummyUserAgent". So the test doesn't technically fail, but it doesn't work as intended, and using it as a framework in the docshell test to measure equality does fail.

> #2 is the way to go, but let's check with Dylan who has more background than I do on this change.

Great, thanks!
Yes, I think #2 is the way to go. If I'm recalling correctly, the reason I had to make those changes to the test cases was that an XHR is a sub-resource request, and will inherit the cached UA override (unless a UA is explicity provided in the XHR) rather than getting a new one.
Flags: needinfo?(droeh)
is this still available for anyone to take ?
(In reply to pkssg2006 from comment #7)
> is this still available for anyone to take ?

Hey pkssg2006, yeah, I didn't do any further work on it, feel free to take over.
pkssg2006 have you made any progress on this one? I was considering taking a stab at it too.
Going by Steve's comments, I tried to come up with a revised test_user_agent_updates_reset file.I'm not sure of how to change the code below to suit the new function added:

isnot(getUA(location.origin), UA_OVERRIDE,
  "User-Agent is not reverted");

If this looks okay or after recommendations from you guys, I'll then modify the test_user_agent_docshell_override.html file to reflect what's in test_user_agent_updates_reset.
Flags: needinfo?(ntim.bugs)
Attachment #8856100 - Flags: review?(ntim.bugs)
Flags: needinfo?(ntim.bugs)
Attachment #8856100 - Flags: review?(ntim.bugs) → review?(droeh)
Comment on attachment 8856100 [details]
Sample test_user_agent_updates_reset.html file

I'm not sure I'm really the best person to review this. I made some small changes to the UA override tests to let some Android-specific changes pass, but I'm not particularly comfortable/familiar with the code.

Off the top of my head, smaug might be a better choice to review this.
Attachment #8856100 - Flags: review?(droeh)
(In reply to Leni Kadali from comment #10)
> Created attachment 8856100 [details]
> Sample test_user_agent_updates_reset.html file
> 
> Going by Steve's comments, I tried to come up with a revised
> test_user_agent_updates_reset file.I'm not sure of how to change the code
> below to suit the new function added:
> 
> isnot(getUA(location.origin), UA_OVERRIDE,
>   "User-Agent is not reverted");
> 
> If this looks okay or after recommendations from you guys, I'll then modify
> the test_user_agent_docshell_override.html file to reflect what's in
> test_user_agent_updates_reset.

Smaug, could you kindly take a look at this?
Flags: needinfo?(bugs)
Not sure what I'm supposed to look at. I'd expect some mochitest setting UA string to various values and testing it works when doing requests.
Flags: needinfo?(bugs)
(In reply to Leni Kadali from comment #10)
> Created attachment 8856100 [details]
> Sample test_user_agent_updates_reset.html file
> 
> Going by Steve's comments, I tried to come up with a revised
> test_user_agent_updates_reset file.I'm not sure of how to change the code
> below to suit the new function added:
> 
> isnot(getUA(location.origin), UA_OVERRIDE,
>   "User-Agent is not reverted");
> 
> If this looks okay or after recommendations from you guys, I'll then modify
> the test_user_agent_docshell_override.html file to reflect what's in
> test_user_agent_updates_reset.

Apologies, I should have quoted the right message. As per the attachment, I had created a sample test_user_agent_updates_reset.html file. However I was stuck at how to rewrite the function mentioned above since Dylan had made this change: https://hg.mozilla.org/mozilla-central/rev/11a7fbfbe2d1. So when I first made my needinfo request, I addressed it to Tim who is the mentor of the bug, who then passed it on to Dylan since he knew more about the change, who then suggested smaug as a better person to ask. As mentioned in IRC, he forgot to pass on the needinfo request as part of his comment. So I 'manually' passed it on but without the requisite detail. Hope it explains what you're to look at :)
Flags: needinfo?(bugs)
Better to ask Tim then.  I'm not familiar with bug 1137681 and I haven't seen any patch here to review, nor really a question to answer.
Sorry that I can't be too useful here.
Flags: needinfo?(bugs)
Removed the DOCTYPE declaration
Sample test_user_agent_updates_reset.html file
Going by Steve's comments, I tried to come up with a revised test_user_agent_updates_reset.html file.
Not sure of how to change the code below to suit the new function added:

isnot(getUA(location.origin), UA_OVERRIDE,
  "User-Agent is not reverted");

If this is okay, I'll then modify the test_user_agent_docshell_override.html file to reflect what's in test_user_agent_updates_reset.html
The patch looks empty to me. Are you sure you've generated it properly ?
Comment on attachment 8863118 [details]
Bug 1232631 - Write tests for network part of bug 1137681

https://reviewboard.mozilla.org/r/134946/#review137894

The diff doesn't show much for me, only a blank line removal.
Attachment #8863118 - Flags: review?(ntim.bugs)
Comment on attachment 8863118 [details]
Bug 1232631 - Write tests for network part of bug 1137681

https://reviewboard.mozilla.org/r/134946/#review137894

Yes. I know. I need you to review the entire file. See if it meets the requirements of the bug. I haven't managed to get help regarding the modification of the function

isnot(getUA(location.origin), UA_OVERRIDE,
   "User-Agent is not reverted");
   
 If there's anything else I need to add or do, let me know.
(In reply to Leni Kadali from comment #20)
> Comment on attachment 8863118 [details]
> Bug 1232631 - Write tests for network part of bug 1137681
> 
> https://reviewboard.mozilla.org/r/134946/#review137894
> 
> Yes. I know. I need you to review the entire file. See if it meets the
> requirements of the bug. I haven't managed to get help regarding the
> modification of the function
It's quite hard to review a modification without having a diff of the changes.
You can read the docs here: https://mozilla-version-control-tools.readthedocs.io/en/latest/hgmozilla/index.html
or request help from IRC: https://wiki.mozilla.org/IRC
Modified netwerk/test/mochitests/test_user_agent_updates_reset.html
in line with changes made here: https://hg.mozilla.org/mozilla-central/rev/11a7fbfbe2d1
Discussion here: https://bugzilla.mozilla.org/show_bug.cgi?id=1232631#c3

I would like assistance on how to modify the code below to reflect the changed function:

const UA_OVERRIDE = "DummyUserAgent";

info("User agent is " + navigator.userAgent);
isnot(navigator.userAgent, UA_OVERRIDE,
  "navigator.userAgent is not reverted");
isnot(getUA(location.origin), UA_OVERRIDE,
  "User-Agent is not reverted");

This is preliminary work to ensure that there's a good base for the docshell test.

MozReview-Commit-ID: EAFIcRcdZme
Attachment #8862449 - Attachment is obsolete: true
Write tests for network part of bug 1137681

Modified netwerk/test/mochitests/test_user_agent_updates_reset.html
in line with changes made here: https://hg.mozilla.org/mozilla-central/rev/11a7fbfbe2d1
Discussion here: https://bugzilla.mozilla.org/show_bug.cgi?id=1232631#c3

I would like assistance on how to modify the code below to reflect the changed function:

const UA_OVERRIDE = "DummyUserAgent";

info("User agent is " + navigator.userAgent);
isnot(navigator.userAgent, UA_OVERRIDE,
  "navigator.userAgent is not reverted");
isnot(getUA(location.origin), UA_OVERRIDE,
  "User-Agent is not reverted");

This is preliminary work to ensure that there's a good base for the docshell test.

For some reason, I was unable to properly export this to Bugzilla or submit it to MozReview. I didn't realize that the file I had submitted to MozReview was the older version of the file, so my apologies Tim :). I'm having growing pains as regards my abilities to successfully diff and submit patches. 

I'm needinfo-ing smaug so that he can review this, since the last time I submitted a file for review it was the wrong file. :P
Attachment #8856100 - Attachment is obsolete: true
Attachment #8863118 - Attachment is obsolete: true
Attachment #8863745 - Attachment is obsolete: true
Flags: needinfo?(bugs)
Attachment #8863756 - Flags: review?(ntim.bugs)
Tim reviewing the test should be fine, but that patch still isn't a patch. It is just a file, without changes to relevant moz.build or so.
If MozReview doesn't work, one can always upload patches to bugzilla as attachments and ask reviews.

The test doesn't wait for the message event to arrive, so depending on timing it may fail.
You want some SimpleTest.waitForExplicitFinish(); and SimpleTest.finish() use.
And nothing calls testUAIFrame, so the test doesn't do anything currently.
Flags: needinfo?(bugs)
Comment on attachment 8863756 [details] [diff] [review]
sample test_user_agent_updates_reset.html file

> I'm having growing pains as regards my abilities to successfully diff and submit patches. 

You can request help from the #developers channel on irc.mozilla.org if needed.

It's a bit hard to review a file by itself, without seeing the changes that were made.
Attachment #8863756 - Flags: review?(ntim.bugs)
Bulk change to priority: https://bugzilla.mozilla.org/show_bug.cgi?id=1399258
Priority: -- → P5
Keywords: good-first-bug
Mentor: ntim.bugs
Severity: normal → S3
Attachment #9385707 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: