Commit 5138b3b9 authored by tyoshino's avatar tyoshino Committed by Commit bot

Add clean up logic to navigator.credentials layout tests

navigator.credentials is backed by MockCredentialManagerClient when
running layout tests. If two tests are run in sequence on the same
content_shell, the earlier test's configuration affects the following
one. Actually, passwordcredential-fetch.html is consistently failing.

Fix this by adding clean up logic to user of the mock configuration
API.

R=mkwst@chromium.org
BUG=650561

Review-Url: https://codereview.chromium.org/2373503003
Cr-Commit-Position: refs/heads/master@{#421155}
parent a14a3854
......@@ -257,11 +257,12 @@ class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
void WaitForPolicyDelegate();
void WaitUntilDone();
void WaitUntilExternalURLLoad();
void AddMockCredentialManagerError(const std::string& error);
void AddMockCredentialManagerResponse(const std::string& id,
void SetMockCredentialManagerError(const std::string& error);
void SetMockCredentialManagerResponse(const std::string& id,
const std::string& name,
const std::string& avatar,
const std::string& password);
void ClearMockCredentialManagerResponse();
bool AnimationScheduled();
bool CallShouldCloseOnWebView();
bool DisableAutoResizeMode(int new_width, int new_height);
......@@ -336,10 +337,12 @@ gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder(
return gin::Wrappable<TestRunnerBindings>::GetObjectTemplateBuilder(isolate)
.SetMethod("abortModal", &TestRunnerBindings::NotImplemented)
.SetMethod("addDisallowedURL", &TestRunnerBindings::NotImplemented)
.SetMethod("addMockCredentialManagerError",
&TestRunnerBindings::AddMockCredentialManagerError)
.SetMethod("addMockCredentialManagerResponse",
&TestRunnerBindings::AddMockCredentialManagerResponse)
.SetMethod("setMockCredentialManagerError",
&TestRunnerBindings::SetMockCredentialManagerError)
.SetMethod("setMockCredentialManagerResponse",
&TestRunnerBindings::SetMockCredentialManagerResponse)
.SetMethod("clearMockCredentialManagerResponse",
&TestRunnerBindings::ClearMockCredentialManagerResponse)
.SetMethod("addMockSpeechRecognitionResult",
&TestRunnerBindings::AddMockSpeechRecognitionResult)
.SetMethod("addOriginAccessWhitelistEntry",
......@@ -1376,19 +1379,24 @@ void TestRunnerBindings::SetMockSpeechRecognitionError(
runner_->SetMockSpeechRecognitionError(error, message);
}
void TestRunnerBindings::AddMockCredentialManagerResponse(
void TestRunnerBindings::SetMockCredentialManagerResponse(
const std::string& id,
const std::string& name,
const std::string& avatar,
const std::string& password) {
if (runner_)
runner_->AddMockCredentialManagerResponse(id, name, avatar, password);
runner_->SetMockCredentialManagerResponse(id, name, avatar, password);
}
void TestRunnerBindings::AddMockCredentialManagerError(
void TestRunnerBindings::ClearMockCredentialManagerResponse() {
if (runner_)
runner_->ClearMockCredentialManagerResponse();
}
void TestRunnerBindings::SetMockCredentialManagerError(
const std::string& error) {
if (runner_)
runner_->AddMockCredentialManagerError(error);
runner_->SetMockCredentialManagerError(error);
}
void TestRunnerBindings::AddWebPageOverlay() {
......@@ -2699,7 +2707,7 @@ void TestRunner::SetMockSpeechRecognitionError(const std::string& error,
WebString::fromUTF8(message));
}
void TestRunner::AddMockCredentialManagerResponse(const std::string& id,
void TestRunner::SetMockCredentialManagerResponse(const std::string& id,
const std::string& name,
const std::string& avatar,
const std::string& password) {
......@@ -2708,7 +2716,11 @@ void TestRunner::AddMockCredentialManagerResponse(const std::string& id,
WebString::fromUTF8(name), WebURL(GURL(avatar))));
}
void TestRunner::AddMockCredentialManagerError(const std::string& error) {
void TestRunner::ClearMockCredentialManagerResponse() {
credential_manager_client_->SetResponse(nullptr);
}
void TestRunner::SetMockCredentialManagerError(const std::string& error) {
credential_manager_client_->SetError(error);
}
......
......@@ -542,11 +542,12 @@ class TestRunner : public WebTestRunner {
// Credential Manager mock functions
// TODO(mkwst): Support FederatedCredential.
void AddMockCredentialManagerResponse(const std::string& id,
void SetMockCredentialManagerResponse(const std::string& id,
const std::string& name,
const std::string& avatar,
const std::string& password);
void AddMockCredentialManagerError(const std::string& error);
void ClearMockCredentialManagerResponse();
void SetMockCredentialManagerError(const std::string& error);
// Takes care of notifying the delegate after a change to layout test runtime
// flags.
......
......@@ -3,6 +3,11 @@
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
add_completion_callback(() => {
if (window.testRunner)
window.testRunner.clearMockCredentialManagerResponse();
});
function create_iframe_test(origin) {
return function (t) {
window.addEventListener("load", _ => {
......@@ -26,4 +31,3 @@ function create_iframe_test(origin) {
async_test(create_iframe_test("http://127.0.0.1:8000"), "Same-origin IFrame throws.");
async_test(create_iframe_test("http://example.test:8000"), "Cross-origin IFrame throws.");
</script>
......@@ -13,8 +13,13 @@ function stubRejectionChecker(reason) {
assert_unreached("get(...) should not reject, but did: " + reason.name);
}
add_completion_callback(() => {
if (window.testRunner)
window.testRunner.clearMockCredentialManagerResponse();
});
(function() {
var t = async_test("Verify the basics of get().");
var t = async_test("navigator.credentials.get() (no argument) should throw.");
t.step(function () {
navigator.credentials.get().then(
t.unreached_func(),
......@@ -23,7 +28,7 @@ function stubRejectionChecker(reason) {
}());
(function() {
var t = async_test("Verify the basics of get({}).");
var t = async_test("navigator.credentials.get({}).");
t.step(function () {
navigator.credentials.get({}).then(
t.step_func(stubResolverUndefinedChecker.bind(t)),
......@@ -32,7 +37,7 @@ function stubRejectionChecker(reason) {
}());
(function() {
var t = async_test("Verify the basics of get().");
var t = async_test("navigator.credentials.get() with a valid options including FederatedCredentialRequestOptions.");
t.step(function () {
navigator.credentials.get({
federated: {
......@@ -45,7 +50,7 @@ function stubRejectionChecker(reason) {
}());
(function() {
var t = async_test("Verify the basics of get().");
var t = async_test("navigator.credentials.get() with a valid options including password and unmediated.");
t.step(function () {
navigator.credentials.get({
password: true,
......@@ -57,7 +62,7 @@ function stubRejectionChecker(reason) {
}());
(function() {
var t = async_test("Verify the basics of get().");
var t = async_test("navigator.credentials.get() with a valid options including federated and unmediated.");
t.step(function () {
navigator.credentials.get({
federated: {
......@@ -71,7 +76,7 @@ function stubRejectionChecker(reason) {
}());
(function() {
var t = async_test("Verify the basics of get().");
var t = async_test("navigator.credentials.get() with a valid options including federated, password and unmediated.");
t.step(function () {
navigator.credentials.get({
password: true,
......@@ -86,7 +91,7 @@ function stubRejectionChecker(reason) {
}());
(function() {
var t = async_test("Verify the basics of get().");
var t = async_test("navigator.credentials.get() with a valid options including unmediated.");
t.step(function () {
navigator.credentials.get({
unmediated: true
......@@ -97,7 +102,7 @@ function stubRejectionChecker(reason) {
}());
(function() {
var t = async_test("Verify the basics of get().");
var t = async_test("navigator.credentials.get() with an options including an unknown attribute.");
t.step(function () {
navigator.credentials.get({
notValid: 'yay!'
......@@ -133,12 +138,12 @@ function stubRejectionChecker(reason) {
var t = async_test("Verify that the mock returns the values we give it.");
t.step(function() {
if (window.testRunner)
testRunner.addMockCredentialManagerResponse(id, name, icon, password);
testRunner.setMockCredentialManagerResponse(id, name, icon, password);
navigator.credentials.get({
password: true
password: true
}).then(
t.step_func(stubResolverChecker.bind(t)),
t.step_func(stubRejectionChecker.bind(t)));
});
});
}());
</script>
......@@ -3,29 +3,26 @@
<script src="../resources/testharnessreport.js"></script>
<script src="/serviceworker/resources/interfaces.js"></script>
<script>
function stubResolverUndefinedChecker(c) {
assert_equals(c, undefined);
this.done();
}
function stubRejectionChecker(reason) {
assert_unreached("get() should not reject, but did: " + reason.name);
}
add_completion_callback(() => {
if (window.testRunner) {
// Clear the error value by passing an empty string.
testRunner.setMockCredentialManagerError("");
}
});
promise_test(function (t) {
if (window.testRunner)
testRunner.addMockCredentialManagerError("pending");
testRunner.setMockCredentialManagerError("pending");
return promise_rejects(t, "InvalidStateError", navigator.credentials.get({ password: true }));
});
promise_test(function (t) {
if (window.testRunner)
testRunner.addMockCredentialManagerError("disabled");
testRunner.setMockCredentialManagerError("disabled");
return promise_rejects(t, "InvalidStateError", navigator.credentials.get({ password: true }));
});
promise_test(function (t) {
if (window.testRunner)
testRunner.addMockCredentialManagerError("unknown");
testRunner.setMockCredentialManagerError("unknown");
return promise_rejects(t, "NotReadableError", navigator.credentials.get({ password: true }));
});
</script>
......@@ -6,6 +6,11 @@
<body>
<input type=hidden id=thing value=sekrit>
<script>
add_completion_callback(() => {
if (window.testRunner)
testRunner.clearMockCredentialManagerResponse();
});
var c = new PasswordCredential({
id: 'id',
password: 'pencil',
......@@ -340,7 +345,7 @@ promise_test(_ => {
var password = "pencil";
if (window.testRunner)
testRunner.addMockCredentialManagerResponse(id, name, icon, password);
testRunner.setMockCredentialManagerResponse(id, name, icon, password);
return navigator.credentials.get({ password: true })
.then(c => {
......@@ -360,11 +365,10 @@ promise_test(_ => {
var password = "pencil";
if (window.testRunner)
testRunner.addMockCredentialManagerResponse(id, name, icon, password);
testRunner.setMockCredentialManagerResponse(id, name, icon, password);
return navigator.credentials.get({ password: true })
.then(c => {
var fd = new FormData();
fd.append('csrf_token', 'sekrit');
c.additionalData = fd;
......@@ -386,7 +390,7 @@ promise_test(_ => {
var password = "pencil";
if (window.testRunner)
testRunner.addMockCredentialManagerResponse(id, name, icon, password);
testRunner.setMockCredentialManagerResponse(id, name, icon, password);
return navigator.credentials.get({ password: true })
.then(c => {
......
<!DOCTYPE html>
<script>
if (window.testRunner)
testRunner.addMockCredentialManagerResponse("id", "name", "", "password");
testRunner.setMockCredentialManagerResponse("id", "name", "", "password");
navigator.credentials.get({ 'password': true })
.then(c => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment