Commit 71e49a0b authored by dimich@chromium.org's avatar dimich@chromium.org

Add a browsertest for magic iframe.

The test verifies that in-progress XHR is still loading after transfer.
BUG=55200


Review URL: http://codereview.chromium.org/7550021

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95676 0039d316-1c4b-4281-b951-d872f2087c98
parent d22bd660
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/memory/ref_counted.h"
#include "base/scoped_temp_dir.h"
#include "base/test/thread_test_helper.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/common/content_switches.h"
class MagicIframeBrowserTest : public InProcessBrowserTest {
public:
MagicIframeBrowserTest() {
EnableDOMAutomation();
}
GURL GetTestURL(const std::string& path);
};
GURL MagicIframeBrowserTest::GetTestURL(const std::string& path) {
std::string url_path = "files/magic_iframe/";
url_path.append(path);
return test_server()->GetURL(url_path);
}
// Verifies that reparenting of iframe between different pages works as
// expected, including smooth transfer of resources that are still being loaded.
// The test failure manifests as the ongoing XHR request is not finishing
// (silently aborted) when the test iframe is transferred between pages (and
// the original page closes). This causes the final navigation to not complete
// and test terminated due to a timeout.
// Currently disabled (http://crbug.com/55200, work in progress).
IN_PROC_BROWSER_TEST_F(MagicIframeBrowserTest,
DISABLED_TransferIframeCloseWindow) {
ASSERT_TRUE(test_server()->Start());
GURL url(GetTestURL("iframe-reparenting-close-window.html"));
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 3);
std::string result;
ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
browser()->GetSelectedTabContents()->render_view_host(), L"",
L"window.domAutomationController.send(getLog())", &result));
ASSERT_NE(result.find("DONE"), std::string::npos) << result;
}
......@@ -2562,6 +2562,7 @@
'browser/history/history_browsertest.cc',
'browser/idbbindingutilities_browsertest.cc',
'browser/importer/toolbar_importer_utils_browsertest.cc',
'browser/magic_iframe_browsertest.cc',
'browser/net/cookie_policy_browsertest.cc',
'browser/net/ftp_browsertest.cc',
'browser/plugin_data_remover_browsertest.cc',
......
<html>
<script>
// Called from Iframe when it is loaded and initialized.
window.transferIframeAndCloseWindow = function() {
var backgroundWin = window.opener;
backgroundWin.log("Transferring Iframe now.");
var xhrFrame = document.getElementById("iframe");
backgroundWin.document.adoptNode(xhrFrame);
backgroundWin.document.body.appendChild(xhrFrame);
window.close(); // This is what caused the XHR load to silently abort.
}
</script>
<body>
<iframe id="iframe" src="iframe-reparenting-close-window-iframe.html">
</iframe>
</body>
</html>
\ No newline at end of file
<html>
<head>
<script>
var logWin = window.parent.opener;
logWin.log('Iframe is being loaded.');
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
logWin.log('xhr onreadystatechange state:' + xhr.readyState);
if (xhr.readyState == 4) {
var text = xhr.responseText;
// Report that the test is finished.
logWin.finish();
}
}
xhr.onerror = function() {
logWin.log('xhr onerror:' + xhr.readyState);
}
// Timeout explanation:
// To reproduce the issue, I need the XHR to start but not finish until the
// iframe transfer is complete. If I just navigate to some file, the load
// actually happens before the iframe is transferred and all the
// onreadystatechange notifications are already queued and just fire in the new
// page.
// The bug, however, deals with XHR being still in progress in the browser
// process, so when it is done and comes back with the routing_id of the closed
// window, it has no way of finding the original iframe and firing
// onreadystatechange. Because of this timeout the test can occasionally produce
// false positive (if the reparenting takes longer then 1 second for example),
// however this is very unlikely, and it won't make test flakey
// (which is usually a false negative).
xhr.open('GET', '/slow?1', true);
xhr.send();
window.parent.transferIframeAndCloseWindow();
</script>
</head>
<body>
</body>
</html>
\ No newline at end of file
<html>
<script>
window.log = function(message)
{
document.getElementById("log").innerText += message + "\n";
}
window.getLog = function()
{
return document.getElementById("log").innerText;
}
window.finish = function()
{
log("DONE");
// This navigation terminates the wait condition in the test code.
window.location.href = window.location.href + "#done";
}
function start()
{
window.childWindow = window.open("iframe-reparenting-close-window-child.html",
"_blank");
window.childWindow.addEventListener("load", "log('Child window loaded.')",
false);
}
</script>
<body onload="start()">
<pre id="log"></pre>
</body>
</html>
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