Change in dart/sdk[master]: expose onUploadProgress on HttpRequest dart:html

13 views
Skip to first unread message

Copybara Prod (Gerrit)

unread,
May 25, 2021, 9:57:54 AM5/25/21
to rev...@dartlang.org

Copybara Prod has uploaded this change for review.

View Change

expose onUploadProgress on HttpRequest dart:html

Context:
I am using HttpRequest in `dart:html` to upload file.
All is ok when I use HttpRequest with `onProgress` on Flutter `2.0.5` but when I upgraded Flutter `2.2.0`, the `onProgress` is not called then I read the document and know the way use [xhr.upload.onprogress](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/upload) to get the upload progress and it works.

Closes https://github.com/dart-lang/sdk/pull/46132
https://github.com/dart-lang/sdk/pull/46132

GitOrigin-RevId: 9d5fa97b14c26cea3a085317d1062d0c87cb5c5f
Change-Id: I15e45efc059a02670f57e5f7e31d580da85897d1
---
M sdk/lib/html/dart2js/html_dart2js.dart
M tests/lib/html/xhr_test.dart
M tests/lib_2/html/xhr_test.dart
3 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
index 6ade06e..5f5c9e9 100644
--- a/sdk/lib/html/dart2js/html_dart2js.dart
+++ b/sdk/lib/html/dart2js/html_dart2js.dart
@@ -18134,14 +18134,17 @@
*
* See also: [authorization headers](http://en.wikipedia.org/wiki/Basic_access_authentication).
*/
- static Future<HttpRequest> request(String url,
- {String? method,
- bool? withCredentials,
- String? responseType,
- String? mimeType,
- Map<String, String>? requestHeaders,
- sendData,
- void onProgress(ProgressEvent e)?}) {
+ static Future<HttpRequest> request(
+ String url, {
+ String? method,
+ bool? withCredentials,
+ String? responseType,
+ String? mimeType,
+ Map<String, String>? requestHeaders,
+ sendData,
+ void onProgress(ProgressEvent e)?,
+ void onUploadProgress(ProgressEvent e)?,
+ }) {
var completer = new Completer<HttpRequest>();

var xhr = new HttpRequest();
@@ -18172,6 +18175,10 @@
xhr.onProgress.listen(onProgress);
}

+ if (onUploadProgress != null) {
+ xhr.upload.onProgress.listen(onUploadProgress);
+ }
+
xhr.onLoad.listen((e) {
var status = xhr.status!;
var accepted = status >= 200 && status < 300;
diff --git a/tests/lib/html/xhr_test.dart b/tests/lib/html/xhr_test.dart
index bffd1cf..16c03be 100644
--- a/tests/lib/html/xhr_test.dart
+++ b/tests/lib/html/xhr_test.dart
@@ -99,6 +99,16 @@
validate200Response(xhr);
}

+Future testRequestOnUploadProgress() async {
+ var progressCalled = false;
+ var xhr = await HttpRequest.request(url, onUploadProgress: (_) {
+ progressCalled = true;
+ });
+ expect(xhr.readyState, HttpRequest.DONE);
+ expect(progressCalled, HttpRequest.supportsProgressEvent);
+ validate200Response(xhr);
+}
+
Future testRequestWithCredentialsNoFile() async {
try {
await HttpRequest.request('NonExistingFile', withCredentials: true);
diff --git a/tests/lib_2/html/xhr_test.dart b/tests/lib_2/html/xhr_test.dart
index 84fc4a6..d76a54b 100644
--- a/tests/lib_2/html/xhr_test.dart
+++ b/tests/lib_2/html/xhr_test.dart
@@ -101,6 +101,16 @@
validate200Response(xhr);
}

+Future testRequestOnUploadProgress() async {
+ var progressCalled = false;
+ var xhr = await HttpRequest.request(url, onUploadProgress: (_) {
+ progressCalled = true;
+ });
+ expect(xhr.readyState, HttpRequest.DONE);
+ expect(progressCalled, HttpRequest.supportsProgressEvent);
+ validate200Response(xhr);
+}
+
Future testRequestWithCredentialsNoFile() async {
try {
await HttpRequest.request('NonExistingFile', withCredentials: true);

To view, visit change 201280. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: sdk
Gerrit-Branch: master
Gerrit-Change-Id: I15e45efc059a02670f57e5f7e31d580da85897d1
Gerrit-Change-Number: 201280
Gerrit-PatchSet: 1
Gerrit-Owner: Copybara Prod <copybara-wor...@google.com>
Gerrit-MessageType: newchange

Copybara Prod (Gerrit)

unread,
Jun 3, 2021, 4:15:52 PM6/3/21
to rev...@dartlang.org

Copybara Prod uploaded patch set #2 to this change.

View Change

expose onUploadProgress on HttpRequest dart:html

Context:
I am using HttpRequest in `dart:html` to upload file.
All is ok when I use HttpRequest with `onProgress` on Flutter `2.0.5` but when I upgraded Flutter `2.2.0`, the `onProgress` is not called then I read the document and know the way use [xhr.upload.onprogress](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/upload) to get the upload progress and it works.

Closes https://github.com/dart-lang/sdk/pull/46132
https://github.com/dart-lang/sdk/pull/46132

GitOrigin-RevId: 4512b166733aae2e00cf6257af282b8c6e70f2e3

Change-Id: I15e45efc059a02670f57e5f7e31d580da85897d1
---
M sdk/lib/html/dart2js/html_dart2js.dart
M tests/lib/html/xhr_test.dart
M tests/lib_2/html/xhr_test.dart
3 files changed, 35 insertions(+), 8 deletions(-)

To view, visit change 201280. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: sdk
Gerrit-Branch: master
Gerrit-Change-Id: I15e45efc059a02670f57e5f7e31d580da85897d1
Gerrit-Change-Number: 201280
Gerrit-PatchSet: 2
Gerrit-Owner: Copybara Prod <copybara-wor...@google.com>
Gerrit-MessageType: newpatchset

Michael Thomsen (Gerrit)

unread,
Aug 3, 2021, 10:06:01 AM8/3/21
to Srujan Gaddam, rev...@dartlang.org, Copybara Prod

Attention is currently required from: Srujan Gaddam.

Michael Thomsen would like Srujan Gaddam to review this change authored by Copybara Prod.

View Change

expose onUploadProgress on HttpRequest dart:html

Context:
I am using HttpRequest in `dart:html` to upload file.
All is ok when I use HttpRequest with `onProgress` on Flutter `2.0.5` but when I upgraded Flutter `2.2.0`, the `onProgress` is not called then I read the document and know the way use [xhr.upload.onprogress](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/upload) to get the upload progress and it works.

Closes https://github.com/dart-lang/sdk/pull/46132
https://github.com/dart-lang/sdk/pull/46132

GitOrigin-RevId: 4512b166733aae2e00cf6257af282b8c6e70f2e3
Change-Id: I15e45efc059a02670f57e5f7e31d580da85897d1
---
M sdk/lib/html/dart2js/html_dart2js.dart
M tests/lib/html/xhr_test.dart
M tests/lib_2/html/xhr_test.dart
3 files changed, 35 insertions(+), 8 deletions(-)

To view, visit change 201280. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: sdk
Gerrit-Branch: master
Gerrit-Change-Id: I15e45efc059a02670f57e5f7e31d580da85897d1
Gerrit-Change-Number: 201280
Gerrit-PatchSet: 2
Gerrit-Owner: Copybara Prod <copybara-wor...@google.com>
Gerrit-Reviewer: Srujan Gaddam <sru...@google.com>
Gerrit-CC: Michael Thomsen <m...@google.com>
Gerrit-Attention: Srujan Gaddam <sru...@google.com>
Gerrit-MessageType: newchange

Srujan Gaddam (Gerrit)

unread,
Aug 3, 2021, 2:58:03 PM8/3/21
to Copybara Prod, rev...@dartlang.org, Michael Thomsen

View Change

1 comment:

  • Patchset:

    • Patch Set #2:

      I believe that this still requires some changes to the template files that are being worked on, so will review when ready.

To view, visit change 201280. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: sdk
Gerrit-Branch: master
Gerrit-Change-Id: I15e45efc059a02670f57e5f7e31d580da85897d1
Gerrit-Change-Number: 201280
Gerrit-PatchSet: 2
Gerrit-Owner: Copybara Prod <copybara-wor...@google.com>
Gerrit-Reviewer: Srujan Gaddam <sru...@google.com>
Gerrit-CC: Michael Thomsen <m...@google.com>
Gerrit-Comment-Date: Tue, 03 Aug 2021 18:57:59 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Reply all
Reply to author
Forward
0 new messages