Closed
Bug 462064
Opened 16 years ago
Closed 14 years ago
Download manager shows decimal digit for bytes when file below 100 bytes
Categories
(Toolkit :: Downloads API, defect)
Toolkit
Downloads API
Tracking
()
RESOLVED
FIXED
mozilla2.0b12
People
(Reporter: greenreaper, Assigned: linostar)
Details
(Whiteboard: [good first bug])
Attachments
(1 file, 2 obsolete files)
4.60 KB,
patch
|
sdwilsh
:
review+
mossop
:
approval2.0+
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1b2pre) Gecko/20081027 Minefield/3.1b2pre (.NET CLR 3.5.30729)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1b2pre) Gecko/20081027 Minefield/3.1b2pre (.NET CLR 3.5.30729)
If a file is very small, the Download Manager will show a decimal point - e.g. "14.0 bytes" (as opposed to, say, "345 bytes"). This is not correct, as there is no such thing as a point of a byte - it is indivisible (as far as the Download Manager is concerned, anyway).
Reproducible: Always
Steps to Reproduce:
1. Download a 14 byte file with the Download Manager enabled
Actual Results:
Download Manager shows "14.0 bytes"
Expected Results:
Download Manager shows "14 bytes"
Comment 1•16 years ago
|
||
14.5 would be 14 Bytes and 4 Bits :-)
Reporter | ||
Comment 2•16 years ago
|
||
If you get 14.5 bytes from an integer counter, there are bigger fish to fry . . .
Comment 3•16 years ago
|
||
confirmed here also, it shows 4.0 bytes for a 4 byte file (Firefox 3.0.5).
Comment 4•15 years ago
|
||
For someone who wants to fix this, the relevant code is (I think) here: http://mxr.mozilla.org/mozilla/source/toolkit/mozapps/downloads/src/DownloadUtils.jsm#382
I think you just need to add (unitIndex != 0) to line 395. I'd do it, but I don't have FF source builds set up to test it out. See also bug 516787 which creates a C++ version of this function for Thunderbird.
Updated•14 years ago
|
Whiteboard: [good first bug]
Comment 5•14 years ago
|
||
You’re right. It’s just a little change to DownloadUtils.jsm:
I’ve just added “&& (unitIndex != 0)“ and it works as you predicted.
Change:
http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/downloads/DownloadUtils.jsm#407
to
aBytes = aBytes.toFixed((aBytes > 0) && (aBytes < 100) && (unitIndex != 0) ? 1 : 0);
I am able to reproduce the bug on windows7 ff4b9.
But the question is, should this be considered a bug. For a file of size 1118 bytes, in windows7 it shows as 1.09KB and download manager of ff shows 1.1KB. Or should I also file a bug in windows7? :)
Comment 7•14 years ago
|
||
Windows 7 is correct.
Hard disk sizes use the notation 1 KB = 1000 bytes.
Software however uses multiples of 2, which is because the minimum space allocation possible on disk are usually 512 bytes (disk sectors), 4KB (clusters) therefore 1 KB = 1024 bytes, so 1118 bytes / 1024 = 1.09 KB.
This difference in units of measures is also why 1 TB drives actually have approximately 931 GB when formatted. Disk manufacturers say 1 TB = 1000 MB x 1000 x 1000 while software says 1 TB = 1024MB x 1024 x 1024.
If it shows 1.1 KB in Firefox I'd argue it's incorrect, because division by 1000 would just confuse people and it doesn't seem to be rounding up error (result is 1.091 so it couldn't be rounded to 1.1)
Comment 8•14 years ago
|
||
(In reply to comment #7)
> (result is 1.091 so it couldn't be rounded to 1.1)
It absolutely can be rounded from 1.091 to 1.1. Example: http://codepad.org/I7C0lr46
Comment 9•14 years ago
|
||
This bug is not about rounding, but about showing a decimal point for files smaller than 100 bytes.
This bug can be solved by the change Jim suggested in comment #4.
Furthermore I can not find a rounding bug. Firefox uses the factor 1024 and shows just one position after the decimal point. 1118byte is both 1.09 KB (with two positions after the decimal point) and 1.1 KB (with just one position after the decimal point)
Updated•14 years ago
|
OS: Windows Vista → All
Hardware: x86 → All
Version: unspecified → Trunk
Assignee | ||
Updated•14 years ago
|
Assignee: nobody → linux.anas
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Assignee | ||
Comment 10•14 years ago
|
||
The patch was tested on ff4b9 and had given the desired result (no decimal digit appears when the file size is in bytes).
Attachment #505042 -
Flags: review?
Assignee | ||
Updated•14 years ago
|
Attachment #505042 -
Flags: review? → review?(sdwilsh)
Comment 11•14 years ago
|
||
Comment on attachment 505042 [details] [diff] [review]
Patch including the change described in comment 5
Edward can do a first pass here.
Attachment #505042 -
Flags: review?(sdwilsh) → review?(edilee)
Comment 12•14 years ago
|
||
Comment on attachment 505042 [details] [diff] [review]
Patch including the change described in comment 5
You'll need to update the tests here:
http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js#101
Notice that it's explicitly checking for a decimal point for sub 100 bytes.
102 testConvertByteUnits(1, _("1.0"), "bytes");
103 testConvertByteUnits(42, _("42.0"), "bytes");
104 testConvertByteUnits(123, _("123"), "bytes");
Attachment #505042 -
Flags: review?(edilee) → review+
Comment 13•14 years ago
|
||
Also, would probably be good to update the comment for the extra logic.
Assignee | ||
Comment 14•14 years ago
|
||
Attachment #505042 -
Attachment is obsolete: true
Attachment #505384 -
Flags: review?(edilee)
Comment 15•14 years ago
|
||
Sent to try, see:
http://tbpl.mozilla.org/?tree=MozillaTry&rev=339b93d96e2a
There is still one failing test:
TEST-UNEXPECTED-FAIL | /home/cltbld/talos-slave/test/build/xpcshell/tests/toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js | 25 seconds remaining 22.1 of 22.1 MB (58 bytes/sec) == 25 seconds remaining 22.1 of 22.1 MB (58.0 bytes/sec)
Comment 16•14 years ago
|
||
Comment on attachment 505384 [details] [diff] [review]
patch v2 including the changes made to the tests
sdwilsh can do the second pass! ;) The style-master!
Turns out there's 6 instances of "58.0 bytes/sec" in that test, so those need to be fixed as well.
Attachment #505384 -
Flags: review?(edilee) → review?(sdwilsh)
Comment 17•14 years ago
|
||
Comment on attachment 505384 [details] [diff] [review]
patch v2 including the changes made to the tests
I'll be happy to do the review once the tests pass!
Attachment #505384 -
Flags: review?(sdwilsh)
Assignee | ||
Comment 18•14 years ago
|
||
Attachment #505384 -
Attachment is obsolete: true
Assignee | ||
Updated•14 years ago
|
Attachment #508390 -
Flags: review?(sdwilsh)
Comment 19•14 years ago
|
||
Comment on attachment 508390 [details] [diff] [review]
patch v3 (fixing all the concerned decimal points in the test)
r=sdwilsh
Attachment #508390 -
Flags: review?(sdwilsh) → review+
Assignee | ||
Updated•14 years ago
|
Attachment #508390 -
Flags: approval2.0?
Comment 20•14 years ago
|
||
Just sent this to the try server:
http://tbpl.mozilla.org/?tree=MozillaTry&rev=5ab3ae478c2d
Whiteboard: [good first bug] → [good first bug][needs approval][needs try]
Updated•14 years ago
|
Attachment #508390 -
Flags: approval2.0? → approval2.0+
Comment 21•14 years ago
|
||
Pushed:
http://hg.mozilla.org/mozilla-central/rev/025ec6dfef03
Thank you for this patch Anas :)
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Whiteboard: [good first bug][needs approval][needs try] → [good first bug]
Target Milestone: --- → mozilla2.0b12
You need to log in
before you can comment on or make changes to this bug.
Description
•