Commit 69e05600 authored by lukasza's avatar lukasza Committed by Commit bot

Tests of ctrl-click can't postMessage to opener - using custom text instead.

This CL fixes/refactors two layout tests that used to depend on ability
to find the opener via window.open, even in case of ctrl-click or
shift-click.  This dependency is incorrect and will be broken once
https://crbug.com/658386 is fixed.

The tests had to be refactored so that they don't depend on ability to
communicate back with the main test window.  After this CL the tests
report their results via testRunner.setCustomTextOutput (rather than
sending the results back to the main window using window.postMessage).

In the 2 tests here, the custom text dump is being set from a secondary
test window - the CL also needs to relax the condition that limited
propagation of LayoutTestRuntimeFlags to the main test window.  The
intent of the original condition should have covered both secondary
and main windows (i.e. the intent was to just check if the renderer
has received a LayoutTestRuntimeFlags).  It seems desirable overall
to also propagate LayoutTestRuntimeFlags changes originating from
secondary test windows.

BUG=658386

Review-Url: https://codereview.chromium.org/2689483007
Cr-Commit-Position: refs/heads/master@{#463400}
parent 1d0058ca
......@@ -602,8 +602,11 @@ void BlinkTestRunner::SetLocale(const std::string& locale) {
void BlinkTestRunner::OnLayoutTestRuntimeFlagsChanged(
const base::DictionaryValue& changed_values) {
// Ignore changes that happen before we got the initial, accumulated
// layout flag changes in ShellViewMsg_ReplicateTestConfiguration.
if (!is_main_window_)
// layout flag changes in either OnReplicateTestConfiguration or
// OnSetTestConfiguration.
test_runner::WebTestInterfaces* interfaces =
LayoutTestRenderThreadObserver::GetInstance()->test_interfaces();
if (!interfaces->TestIsRunning())
return;
RenderThread::Get()->Send(
......@@ -611,14 +614,16 @@ void BlinkTestRunner::OnLayoutTestRuntimeFlagsChanged(
}
void BlinkTestRunner::TestFinished() {
test_runner::WebTestInterfaces* interfaces =
LayoutTestRenderThreadObserver::GetInstance()->test_interfaces();
interfaces->SetTestIsRunning(false);
if (!is_main_window_ || !render_view()->GetMainRenderFrame()) {
RenderThread::Get()->Send(
new LayoutTestHostMsg_TestFinishedInSecondaryRenderer());
return;
}
test_runner::WebTestInterfaces* interfaces =
LayoutTestRenderThreadObserver::GetInstance()->test_interfaces();
interfaces->SetTestIsRunning(false);
if (interfaces->TestRunner()->ShouldDumpBackForwardList()) {
SyncNavigationStateVisitor visitor;
RenderView::ForEach(&visitor);
......
......@@ -79,6 +79,10 @@ void TestInterfaces::ResetAll() {
test_runner_->Reset();
}
bool TestInterfaces::TestIsRunning() {
return test_runner_->TestIsRunning();
}
void TestInterfaces::SetTestIsRunning(bool running) {
test_runner_->SetTestIsRunning(running);
}
......
......@@ -37,6 +37,7 @@ class TestInterfaces {
void BindTo(blink::WebFrame* frame);
void ResetTestHelperControllers();
void ResetAll();
bool TestIsRunning();
void SetTestIsRunning(bool running);
void ConfigureForTestWithURL(const blink::WebURL& test_url,
bool generate_pixels);
......
......@@ -39,6 +39,10 @@ void WebTestInterfaces::ResetAll() {
interfaces_->ResetAll();
}
bool WebTestInterfaces::TestIsRunning() {
return interfaces_->TestIsRunning();
}
void WebTestInterfaces::SetTestIsRunning(bool running) {
interfaces_->SetTestIsRunning(running);
}
......
......@@ -45,6 +45,7 @@ class TEST_RUNNER_EXPORT WebTestInterfaces {
void SetMainView(blink::WebView* web_view);
void SetDelegate(WebTestDelegate* delegate);
void ResetAll();
bool TestIsRunning();
void SetTestIsRunning(bool running);
void ConfigureForTestWithURL(const blink::WebURL& test_url,
bool generate_pixels);
......
PASS results["method"] is "POST"
PASS results["formValue"] is "b"
PASS successfullyParsed is true
TEST COMPLETE
method: "POST"
formValue: "b"
......@@ -6,23 +6,12 @@
</form>
</div>
<div id="console"></div>
<script src="/js-test-resources/js-test.js"></script>
<script>
var results;
function concludeTest(data)
{
results = data;
shouldBeEqualToString('results["method"]', 'POST');
shouldBeEqualToString('results["formValue"]', 'b');
document.getElementById('container').outerHTML = '';
finishJSTest();
}
if (window.testRunner) {
window.jsTestIsAsync = true;
testRunner.dumpAsText();
testRunner.setCanOpenWindows(true);
testRunner.setCloseRemainingWindowsWhenComplete(true);
testRunner.waitUntilDone();
window.onload = function() {
var submit = document.querySelector('input[type="submit"]');
......@@ -31,15 +20,5 @@ if (window.testRunner) {
eventSender.mouseDown(0);
eventSender.mouseUp(0, ['shiftKey']);
};
// Shift-clicking doesn't set window.opener, so we allow the new window
// to find the opener using the name being set below.
// TODO(lukasza): After fixing https://crbug.com/658386, the test will
// need to use another mechanism for communicating verification results
// (most likely OOPIF-replicated testRunner.setCustomTextOutput).
window.name = "mainTestWindow";
window.addEventListener('message', function(e) {
concludeTest(e.data);
});
}
</script>
<script>
mainTestWindow = window.open("", "mainTestWindow")
var data = {
'method': '<?=$_SERVER['REQUEST_METHOD'] ?>',
'formValue': '<?= $_POST['a'] ?>',
};
mainTestWindow.postMessage(data, '*');
testRunner.setCustomTextOutput(
'method: "<?=$_SERVER['REQUEST_METHOD'] ?>"\n' +
'formValue: "<?= $_POST['a'] ?>"');
testRunner.notifyDone();
</script>
history.length: 1
window.self == window.parent: true
window.location.href: http://127.0.0.1:8000/security/contentSecurityPolicy/resources/frame-src-vs-shift-click-target.html
......@@ -6,8 +6,6 @@
<p>This is a regression test for https://crbug.com/658701</p>
</div>
<div id="log"></div>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe id="iframe"
srcdoc="
&lt;p&gt;frame-src-vs-shift-click-FRAME.html:
......@@ -17,41 +15,11 @@
&lt;/p&gt;
"></iframe>
<script>
var test = async_test("Testing frame-src vs shift-click");
function concludeTest(data)
{
test.step(function() {
assert_equals(
data["window.location.href"],
'http://127.0.0.1:8000/security/contentSecurityPolicy/resources/frame-src-vs-shift-click-target.html',
"Test should be finished from frame-src-vs-shift-click-target.html");
assert_equals(
data["history.length"],
1,
"frame-src-vs-shift-click-target.html should be in a fresh window");
assert_true(
data["window.self == window.parent"],
"frame-src-vs-shift-click-target.html should be the main frame");
});
document.getElementById('container').outerHTML = '';
test.done();
}
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.setCanOpenWindows(true);
testRunner.setCloseRemainingWindowsWhenComplete(true);
// Shift-clicking doesn't set window.opener, so we allow the new window
// to find the opener using the name being set below.
// TODO(lukasza): After fixing https://crbug.com/658386, the test will
// need to use another mechanism for communicating verification results
// (most likely OOPIF-replicated testRunner.setCustomTextOutput).
window.name = "mainTestWindow";
window.addEventListener('message', function(e) {
concludeTest(e.data);
});
testRunner.waitUntilDone();
window.onload = function() {
var iframe = document.getElementById("iframe");
......
<p>frame-src-vs-shift-click-TARGET.html</p>
<script>
mainTestWindow = window.open("", "mainTestWindow")
var data = {
'history.length': history.length,
'window.self == window.parent': window.self == window.parent,
'window.location.href': window.location.href
};
mainTestWindow.postMessage(data, '*');
testRunner.setCustomTextOutput(
'history.length: ' + history.length + '\n' +
'window.self == window.parent: ' + (window.self == window.parent) + '\n' +
'window.location.href: ' + window.location.href + '\n');
testRunner.notifyDone();
</script>
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