Closed Bug 462064 Opened 16 years ago Closed 13 years ago

Download manager shows decimal digit for bytes when file below 100 bytes

Categories

(Toolkit :: Downloads API, defect)

defect
Not set
trivial

Tracking

()

RESOLVED FIXED
mozilla2.0b12

People

(Reporter: greenreaper, Assigned: linostar)

Details

(Whiteboard: [good first bug])

Attachments

(1 file, 2 obsolete files)

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"
14.5 would be 14 Bytes and 4 Bits :-)
If you get 14.5 bytes from an integer counter, there are bigger fish to fry . . .
confirmed here also, it shows 4.0 bytes for a 4 byte file (Firefox 3.0.5).
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.
Whiteboard: [good first bug]
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? :)
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)
(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
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)
OS: Windows Vista → All
Hardware: x86 → All
Version: unspecified → Trunk
Assignee: nobody → linux.anas
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
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?
Attachment #505042 - Flags: review? → review?(sdwilsh)
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 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+
Also, would probably be good to update the comment for the extra logic.
Attachment #505042 - Attachment is obsolete: true
Attachment #505384 - Flags: review?(edilee)
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 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 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)
Attachment #508390 - Flags: review?(sdwilsh)
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+
Attachment #508390 - Flags: approval2.0?
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]
Attachment #508390 - Flags: approval2.0? → approval2.0+
Pushed:
http://hg.mozilla.org/mozilla-central/rev/025ec6dfef03

Thank you for this patch Anas :)
Status: ASSIGNED → RESOLVED
Closed: 13 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.

Attachment

General

Created:
Updated:
Size: