Closed Bug 949944 Opened 11 years ago Closed 11 years ago

[B2G][Helix][Browser][Wallpaper] use new File([blob], filename) to return a blob with filename when picking

Categories

(Firefox OS Graveyard :: Gaia::Wallpaper, defect, P2)

defect

Tracking

(blocking-b2g:-)

RESOLVED FIXED
blocking-b2g -

People

(Reporter: johnhu, Assigned: johnhu)

References

Details

Attachments

(1 file, 9 obsolete files)

+++ This bug was initially created as a clone of Bug #920905 +++

When handling pick activity, we need to use new File([blob], filename) to return a blob with readable file name.
Assignee: nobody → johu
Depends on: 949945
Blocks: 920905
No longer depends on: 920905
No longer depends on: 949941
No longer blocks: 949943
No longer depends on: 949945
nominate it as 1.3? since its original bug is 1.3?.
blocking-b2g: --- → 1.3?
Hi Baku,

I found a strange error when picking from wallpaper with/without using new File([blob], filename). I had dumped the returned filename and error message:

E/GeckoConsole( 2602): Content JS LOG at app://wallpaper.gaiamobile.org/js/pick.js:68 in wallpaper_pickWallpaper/img.onload/<: src resources/320x480/FXOS_Illus_Blocks.png

E/GeckoConsole( 2552): [JavaScript Error: "NS_ERROR_FILE_UNRECOGNIZED_PATH: Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsILocalFile.initWithPath]" {file: "jar:file:///system/b2g/omni.ja!/components/FilePicker.js" line: 194}]
E/GeckoConsole( 2082): Content JS WARN at app://system.gaiamobile.org/js/activity_window.js:202 in onClose: unknown window type of activity caller.

BTW, I found wallpaper returns its file name with result.name. Does that mean I don't need to return it with new File() according to [1]?

[1] http://mxr.mozilla.org/mozilla-central/source/b2g/components/FilePicker.js#185
Flags: needinfo?(amarchesini)
BTW, I found another bug at [1]. We should use let file = new FileUtils.File(name);

[1] http://mxr.mozilla.org/mozilla-central/source/b2g/components/FilePicker.js#194
Attached patch possible patch (obsolete) — Splinter Review
Baku,

I did some tests and found the "new FileUtils.File()" needs absolute file path. So, I use pure JavaScript to take the file name out. Any suggestions?
This is an approach that works for B2G. So I guess it's fine. I want to have fabrice to review this patch.
Flags: needinfo?(amarchesini)
Attached patch bug-949944-fix.patch (obsolete) — Splinter Review
Fabrice,

Please review this patch, according to the suggestion of baku at comment 5. The main thought of this patch is to use javascript function to take the filename out instead of FileUtils.File().
Attachment #8347939 - Attachment is obsolete: true
Attachment #8348493 - Flags: review?(fabrice)
Comment on attachment 8348493 [details] [diff] [review]
bug-949944-fix.patch

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

::: b2g/components/FilePicker.js
@@ +190,5 @@
>      }
>  
>      // Let's try to remove the full path and take just the filename.
>      if (name) {
> +      name = name.substr(name.lastIndexOf('/') + 1);

this will not work on windows, which we support in desktop builds.
Attachment #8348493 - Flags: review?(fabrice) → review-
Attached patch bug-949944-fix-v2.patch (obsolete) — Splinter Review
Thank you for telling me this. I thought b2g folder is only for b2g project in the past. I think I am wrong about it. b2g folder may also be used in b2g-desktop and others.

This patch uses OS.Path.split to get the filename. Please review it, thanks.
Attachment #8348493 - Attachment is obsolete: true
Attachment #8349848 - Flags: review?(fabrice)
Blocks: 949945
Blocks: 949941
Comment on attachment 8349848 [details] [diff] [review]
bug-949944-fix-v2.patch

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

Can we get tests for that?
Attachment #8349848 - Flags: review?(fabrice) → review+
Comment on attachment 8349848 [details] [diff] [review]
bug-949944-fix-v2.patch

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

::: b2g/components/FilePicker.js
@@ +32,4 @@
>                         'audio/webm'];
>  
>  Cu.import('resource://gre/modules/XPCOMUtils.jsm');
> +Cu.import('resource://gre/modules/FileUtils.jsm');

Do we need this line?
(In reply to Andrea Marchesini (:baku) from comment #10)
> > +Cu.import('resource://gre/modules/FileUtils.jsm');
> 
> Do we need this line?

No, we don't need this line. I will remove it.
Component: Gaia → Gaia::Wallpaper
Ok, I will try to write tests for this patch....
Attached patch bug-949944-v3.patch (obsolete) — Splinter Review
Remove the useless import, as per comment 10, and move the r+ here.
Attachment #8349848 - Attachment is obsolete: true
Attachment #8350463 - Flags: review+
Attached patch bug-949944-v4.patch (obsolete) — Splinter Review
Fabrice,

I had merged the tests into the patch. Please review it again.

And Shih-Chiang Chien told me that this test needs to run at OOP environment to have correct result. So, I only put tests into b2g and b2g-debug.

Thanks.
Attachment #8351352 - Flags: review?(fabrice)
Attached patch bug-949944-v4.1.patch (obsolete) — Splinter Review
Found additional spaces at v4.
Attachment #8350463 - Attachment is obsolete: true
Attachment #8351352 - Attachment is obsolete: true
Attachment #8351352 - Flags: review?(fabrice)
Comment on attachment 8351354 [details] [diff] [review]
bug-949944-v4.1.patch


Fabrice,

I had merged the tests into the patch. Please review it again.

And Shih-Chiang Chien told me that this test needs to run at OOP environment to have correct result. So, I only put tests into b2g and b2g-debug.

Thanks
Attachment #8351354 - Flags: review?(fabrice)
Attached patch bug-949944-v5.patch (obsolete) — Splinter Review
Attachment #8351354 - Attachment is obsolete: true
Attachment #8351354 - Flags: review?(fabrice)
Comment on attachment 8351355 [details] [diff] [review]
bug-949944-v5.patch


Fabrice,

I had merged the tests into the patch. Please review it again.

And Shih-Chiang Chien told me that this test needs to run at OOP environment to have correct result. So, I only put tests into b2g and b2g-debug.

Thanks
Attachment #8351355 - Flags: review?(fabrice)
Comment on attachment 8351355 [details] [diff] [review]
bug-949944-v5.patch

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

That looks good, thanks! Can you check the windows path before landing?

::: b2g/components/test/mochitest/filepicker_path_handler_chrome.js
@@ +8,5 @@
> +const Ci = Components.interfaces;
> +
> +// use ppmm to handle file-picker message.
> +let ppmm = Cc['@mozilla.org/parentprocessmessagemanager;1']
> +           .getService(Ci.nsIMessageListenerManager);

nit: align .getService() with ['..']

::: b2g/components/test/mochitest/test_filepicker_path.html
@@ +17,5 @@
> +
> +var testCases = [
> +  // case 1: returns blob with name
> +  { pickedResult: { success: true,
> +                  result: {

nit: indentation is wrong (align 'success' and 'result')

@@ +65,5 @@
> +                            name: 'test5.txt'
> +                          }
> +                },
> +    fileName: 'test5.txt'},
> +  // case 6: returns file without name. This case may be failed because we

nit: This case may fail

@@ +120,5 @@
> +    var name = activeTestCase.pickedResult.result.name;
> +    name = name.replace('/', '\\');
> +    if (name.startWidth('\\')) {
> +      name = 'C:' + name;
> +    }

hm, this windows specific part is a bit ugly. Can you check if other tests do something else in these situations?
Attachment #8351355 - Flags: review?(fabrice) → feedback+
Thanks for your reviews, Fabrice.

As to the windows specific part, that's for building the expected result. I had found another one using the same syntax[1], so I use the same way. I don't know if there any other better way. If you know it, please tell me and I will update the patch of it.

I am not sure about one thing: with this patch, the mochitests under b2g/components folder is only enabled in b2g and b2g-debug. So, those tests are not run at b2g-desktop and the windows parts are useless, aren't they?? If yes, I will remove those ugly codes.

Thanks.

[1] http://dxr.mozilla.org/mozilla-central/source/toolkit/content/tests/browser/browser_input_file_tooltips.js#22
Flags: needinfo?(fabrice)
Ok. Your tests will run on b2g-desktop, so keep the windows part. b2g/b2g-debug just means "opt build"/"debug build", but they will run on desktop.
Flags: needinfo?(fabrice)
Attachment #8351355 - Flags: feedback+ → review+
Attached patch bug-949944-v6.patch (obsolete) — Splinter Review
This patch only fixes the nits mentioned in comment 19. Move r+ to this one.
Attachment #8351355 - Attachment is obsolete: true
Attachment #8356931 - Flags: review+
Attached patch bug-949944-v7.patch (obsolete) — Splinter Review
conflict found while testing in the try server. this is the rebased version.
Attachment #8356931 - Attachment is obsolete: true
Attachment #8357604 - Flags: review+
Attachment #8357604 - Attachment is obsolete: true
Attachment #8357606 - Flags: review+
This doesn't seem like something we'd hold 1.3 for but please request aurora uplift approval when ready.
blocking-b2g: 1.3? → -
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: