New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to WPT-test file uploads and fetches, fixes #12322 #12344
Merged
+168
−71
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
| @@ -21,6 +21,7 @@ use std::sync::{Arc, RwLock}; | ||
| #[cfg(any(target_os = "macos", target_os = "linux"))] | ||
| use tinyfiledialogs; | ||
| use url::Url; | ||
| use util::prefs::PREFS; | ||
| use util::thread::spawn_named; | ||
| use uuid::Uuid; | ||
|
|
||
| @@ -128,14 +129,14 @@ impl<UI: 'static + UIProvider> FileManager<UI> { | ||
| loop { | ||
| let store = self.store.clone(); | ||
| match self.receiver.recv().unwrap() { | ||
| FileManagerThreadMsg::SelectFile(filter, sender, origin) => { | ||
| FileManagerThreadMsg::SelectFile(filter, sender, origin, opt_test_path) => { | ||
| spawn_named("select file".to_owned(), move || { | ||
| store.select_file(filter, sender, origin); | ||
| store.select_file(filter, sender, origin, opt_test_path); | ||
| }); | ||
| } | ||
| FileManagerThreadMsg::SelectFiles(filter, sender, origin) => { | ||
| FileManagerThreadMsg::SelectFiles(filter, sender, origin, opt_test_paths) => { | ||
| spawn_named("select files".to_owned(), move || { | ||
| store.select_files(filter, sender, origin); | ||
| store.select_files(filter, sender, origin, opt_test_paths); | ||
| }) | ||
| } | ||
| FileManagerThreadMsg::ReadFile(sender, id, origin) => { | ||
| @@ -309,8 +310,17 @@ impl <UI: 'static + UIProvider> FileManagerStore<UI> { | ||
|
|
||
| fn select_file(&self, patterns: Vec<FilterPattern>, | ||
| sender: IpcSender<FileManagerResult<SelectedFile>>, | ||
| origin: FileOrigin) { | ||
| match self.ui.open_file_dialog("", patterns) { | ||
| origin: FileOrigin, opt_test_path: Option<String>) { | ||
| // Check if the select_files preference is enabled | ||
| // to ensure process-level security against compromised script; | ||
| // Then try applying opt_test_path directly for testing convenience | ||
| let opt_s = if select_files_pref_enabled() { | ||
| opt_test_path | ||
| } else { | ||
| self.ui.open_file_dialog("", patterns) | ||
| }; | ||
Manishearth
Member
|
||
|
|
||
| match opt_s { | ||
| Some(s) => { | ||
| let selected_path = Path::new(&s); | ||
|
|
||
| @@ -328,8 +338,17 @@ impl <UI: 'static + UIProvider> FileManagerStore<UI> { | ||
|
|
||
| fn select_files(&self, patterns: Vec<FilterPattern>, | ||
| sender: IpcSender<FileManagerResult<Vec<SelectedFile>>>, | ||
| origin: FileOrigin) { | ||
| match self.ui.open_file_dialog_multi("", patterns) { | ||
| origin: FileOrigin, opt_test_paths: Option<Vec<String>>) { | ||
| // Check if the select_files preference is enabled | ||
| // to ensure process-level security against compromised script; | ||
| // Then try applying opt_test_paths directly for testing convenience | ||
| let opt_v = if select_files_pref_enabled() { | ||
| opt_test_paths | ||
| } else { | ||
| self.ui.open_file_dialog_multi("", patterns) | ||
| }; | ||
|
|
||
| match opt_v { | ||
| Some(v) => { | ||
| let mut selected_paths = vec![]; | ||
|
|
||
| @@ -481,3 +500,9 @@ impl <UI: 'static + UIProvider> FileManagerStore<UI> { | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| fn select_files_pref_enabled() -> bool { | ||
| PREFS.get("dom.testing.htmlinputelement.select_files.enabled") | ||
| .as_boolean().unwrap_or(false) | ||
| } | ||
| @@ -0,0 +1,3 @@ | ||
| [file_upload.html] | ||
| type: testharness | ||
| prefs: [dom.testing.htmlinputelement.select_files.enabled:true] |
| @@ -0,0 +1,31 @@ | ||
| <!doctype html> | ||
| <meta charset="utf-8"> | ||
| <title>Test of uploading a file through input element</title> | ||
| <script src="/resources/testharness.js"></script> | ||
| <script src="/resources/testharnessreport.js"></script> | ||
|
|
||
| <body><input id="file-input" type="file"></body> | ||
|
|
||
| <script> | ||
|
|
||
| async_test(function() { | ||
| var e = document.getElementById("file-input"); | ||
|
|
||
| assert_true(e.selectFiles != undefined, "selectFiles is not defined") | ||
|
|
||
| e.selectFiles(["./tests/wpt/mozilla/tests/mozilla/test.txt"]); | ||
|
|
||
| assert_true(e.files.length > 0, "test.txt is not selected"); | ||
|
|
||
| var reader = new FileReader; | ||
|
|
||
| reader.onloadend = this.step_func(function(evt) { | ||
| assert_equals(evt.target.result, "hello, servo\n"); | ||
|
|
||
| this.done(); | ||
| }); | ||
|
|
||
| reader.readAsText(e.files[0]); | ||
|
|
||
| }, "Select a file"); | ||
| </script> |
| @@ -0,0 +1 @@ | ||
| hello, servo |
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
@Manishearth Looks good?