Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Unified Diff: LayoutTests/fast/forms/form-request-autocomplete.html

Issue 228783007: rAc: make requestAutocomplete() return a promise. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: merge Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | LayoutTests/fast/forms/form-request-autocomplete-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/fast/forms/form-request-autocomplete.html
diff --git a/LayoutTests/fast/forms/form-request-autocomplete.html b/LayoutTests/fast/forms/form-request-autocomplete.html
index 7c3b99a9b245e3a96c71765cf3a804f081602114..9039dfbdf44fb8a9e4f6786103b2a5ef62b5b595 100644
--- a/LayoutTests/fast/forms/form-request-autocomplete.html
+++ b/LayoutTests/fast/forms/form-request-autocomplete.html
@@ -6,65 +6,71 @@
jsTestIsAsync = true;
var numErrors = 0;
-var numErrorsExpected = 4;
+var numErrorsExpected = 5;
var eventsBubbleToBody = false;
var eventsBubbleToDocument = false;
var eventsBubbleToWindow = false;
+var eventReason = '';
+var promiseFired = false;
+
+function debugMsg(msg)
+{
+ debug('DEBUG ' + msg);
+}
function runTests()
{
checkDynamicAttributes();
- checkNonUserGesture();
checkParsedAttributes();
checkEventsBubble();
+ checkPromiseRejects();
+ checkNonUserGesture();
+ debugMsg('finished runs tests, waiting for results');
+}
+
+function debugStart()
+{
+ debugMsg(arguments.callee.caller.name + ' running');
}
function checkForEnumerableProperties(form)
{
- var enumerable = {};
- for (var field in form)
- enumerable[field] = true;
- if (!enumerable.onautocomplete)
+ if (!('onautocomplete' in form))
testFailed('failed to enumerate HTMLFormElement.onautocomplete');
- if (!enumerable.onautocompleteerror)
+
+ if (!('onautocompleteerror' in form))
testFailed('failed to enumerate HTMLFormElement.onautocompleteerror');
+
testPassed('found enumerable properties on HTMLFormElement');
}
function checkDynamicAttributes()
{
+ debugStart();
+
var form = document.createElement('form');
checkForEnumerableProperties(form);
-
- form.autocomplete = 'off';
form.addEventListener('autocompleteerror', errorWithReason('disabled'));
+ form.autocomplete = 'off';
form.requestAutocomplete();
}
-function checkNonUserGesture()
-{
- var form = document.createElement('form');
- checkForEnumerableProperties(form);
- form.onautocompleteerror = errorWithReason('disabled');
-
- setTimeout(function()
- {
- form.requestAutocomplete();
- }, 0);
-}
-
function checkParsedAttributes()
{
+ debugStart();
+
var form = document.forms[0];
+ checkForEnumerableProperties(form);
if (!form || !form.onautocompleteerror || form.autocomplete != 'off')
testFailed('failed to pick up parsed DOM attributes correctly');
- checkForEnumerableProperties(form);
form.requestAutocomplete();
}
function checkEventsBubble()
{
+ debugStart();
+
var form = document.createElement('form');
form.autocomplete = 'off';
@@ -92,9 +98,44 @@ function checkEventsBubble()
form.requestAutocomplete();
}
+function checkPromiseRejects()
+{
+ debugStart();
+
+ var form = document.createElement('form');
+ form.autocomplete = 'off';
+
+ form.onautocompleteerror = function(e) {
+ eventReason = e.reason;
+ };
+
+ var promise = form.requestAutocomplete();
+ if (promise instanceof Promise)
+ testPassed('requestAutocomplete() returns a Promise');
+ else
+ testFailed('expected requestAutocomplete() to return a Promise');
+
+ promise.catch(objectWithReason('disabled'));
+}
+
+function checkNonUserGesture()
+{
+ debugStart();
+
+ var form = document.createElement('form');
+ form.onautocompleteerror = errorWithReason('disabled');
+
+ setTimeout(function() {
+ form.requestAutocomplete();
+ });
+}
+
function errorWithReason(reason)
{
+ var from = arguments.callee.caller.name;
return function(event) {
+ debugMsg('handling error from ' + from);
+
if (event instanceof AutocompleteErrorEvent)
testPassed('event is an AutocompleteErrorEvent');
else
@@ -109,20 +150,52 @@ function errorWithReason(reason)
};
}
+function objectWithReason(reason)
+{
+ return function(result) {
+ if (promiseFired) {
+ testFailed('Promise.catch() fired too many times');
+ return;
+ }
+ promiseFired = true;
+
+ if (!eventReason)
+ testFailed('events should dispatch before Promises are resolved');
+
+ if (!(result instanceof Error))
+ testFailed('expected Promise argument to be an result');
+
+ if (!('reason' in result))
+ testFailed('Promise result has no "reason" key');
+
+ if (result.reason != eventReason)
+ testFailed('wrong reason, expected: ' + promiseResult.expectedReason + ', got: ' + promiseResult.actualReason);
+
+ onError();
+ };
+}
+
function onError()
{
numErrors += 1;
- if (numErrors > numErrorsExpected) {
- testFailed('too many error events');
- } else if (numErrors == numErrorsExpected) {
+ if (numErrors == numErrorsExpected) {
if (!eventsBubbleToBody)
testFailed('no events bubbled to body');
+
if (!eventsBubbleToDocument)
testFailed('no events bubbled to document');
+
if (!eventsBubbleToWindow)
testFailed('no events bubbled to window');
+
if (eventsBubbleToBody && eventsBubbleToDocument && eventsBubbleToWindow)
testPassed('events bubbled as expected');
+
+ if (promiseFired)
+ testPassed('Promise.catch() fired');
+ else
+ testFailed('Promise.catch() never fired');
+
testPassed('got expected number of error events (' + numErrorsExpected + ')');
finishJSTest();
}
« no previous file with comments | « no previous file | LayoutTests/fast/forms/form-request-autocomplete-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698