Commit f1e370b9 authored by Andrey Kosyakov's avatar Andrey Kosyakov Committed by Commit Bot

Rewrite several devtools_protocol_browsertest tests as inspector-protocol layout tests

Bug: 721408
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_mojo
Change-Id: Ifd9be7ae953b43bdeca09ec7f2c8dfa51dcbe7d1
Reviewed-on: https://chromium-review.googlesource.com/1042857
Commit-Queue: Andrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555924}
parent c7fadd21
...@@ -1560,206 +1560,6 @@ IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, BrowserGetTargets) { ...@@ -1560,206 +1560,6 @@ IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, BrowserGetTargets) {
EXPECT_EQ("about:blank", url); EXPECT_EQ("about:blank", url);
} }
namespace {
class NavigationFinishedObserver : public content::WebContentsObserver {
public:
explicit NavigationFinishedObserver(WebContents* web_contents)
: WebContentsObserver(web_contents),
num_finished_(0),
num_to_wait_for_(0) {}
~NavigationFinishedObserver() override {}
void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override {
if (navigation_handle->WasServerRedirect())
return;
num_finished_++;
if (num_finished_ >= num_to_wait_for_ && num_to_wait_for_ != 0) {
base::RunLoop::QuitCurrentDeprecated();
}
}
void WaitForNavigationsToFinish(int num_to_wait_for) {
if (num_finished_ < num_to_wait_for) {
num_to_wait_for_ = num_to_wait_for;
RunMessageLoop();
}
num_to_wait_for_ = 0;
}
private:
int num_finished_;
int num_to_wait_for_;
};
class LoadFinishedObserver : public content::WebContentsObserver {
public:
explicit LoadFinishedObserver(WebContents* web_contents)
: WebContentsObserver(web_contents), num_finished_(0) {}
~LoadFinishedObserver() override {}
void DidStopLoading() override {
num_finished_++;
if (run_loop_.running())
run_loop_.Quit();
}
void WaitForLoadToFinish() {
if (num_finished_ == 0)
run_loop_.Run();
}
private:
int num_finished_;
base::RunLoop run_loop_;
};
} // namespace
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, PageStopLoading) {
ASSERT_TRUE(embedded_test_server()->Start());
// Navigate to about:blank first so we can make sure there is a target page we
// can attach to, and have Network.setRequestInterception complete
// before we start the navigations we're interested in.
NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
Attach();
std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue());
std::unique_ptr<base::ListValue> patterns(new base::ListValue());
patterns->Append(std::make_unique<base::DictionaryValue>());
params->Set("patterns", std::move(patterns));
SendCommand("Network.setRequestInterception", std::move(params), true);
LoadFinishedObserver load_finished_observer(shell()->web_contents());
// The page will try to navigate twice, however since
// Network.setRequestInterception is true,
// it'll wait for confirmation before committing to the navigation.
GURL test_url = embedded_test_server()->GetURL(
"/devtools/control_navigations/meta_tag.html");
shell()->LoadURL(test_url);
// Stop all navigations.
SendCommand("Page.stopLoading", nullptr);
// Wait for the initial navigation to finish.
load_finished_observer.WaitForLoadToFinish();
}
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, ControlNavigationsMainFrame) {
ASSERT_TRUE(embedded_test_server()->Start());
// Navigate to about:blank first so we can make sure there is a target page we
// can attach to, and have Network.setRequestInterception complete
// before we start the navigations we're interested in.
NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
Attach();
std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue());
std::unique_ptr<base::ListValue> patterns(new base::ListValue());
patterns->Append(std::make_unique<base::DictionaryValue>());
params->Set("patterns", std::move(patterns));
SendCommand("Network.setRequestInterception", std::move(params), true);
NavigationFinishedObserver navigation_finished_observer(
shell()->web_contents());
GURL test_url = embedded_test_server()->GetURL(
"/devtools/control_navigations/meta_tag.html");
shell()->LoadURL(test_url);
std::vector<ExpectedNavigation> expected_navigations = {
{"http://127.0.0.1/devtools/control_navigations/meta_tag.html",
false /* expected_is_redirect */, false /* abort */},
{"http://127.0.0.1/devtools/navigation.html",
false /* expected_is_redirect */, true /* abort */}};
ProcessNavigationsAnyOrder(std::move(expected_navigations));
// Wait for the initial navigation and the cancelled meta refresh navigation
// to finish.
navigation_finished_observer.WaitForNavigationsToFinish(2);
// Check main frame has the expected url.
EXPECT_EQ(
"http://127.0.0.1/devtools/control_navigations/meta_tag.html",
RemovePort(
shell()->web_contents()->GetMainFrame()->GetLastCommittedURL()));
}
class IsolatedDevToolsProtocolTest : public DevToolsProtocolTest {
public:
~IsolatedDevToolsProtocolTest() override {}
void SetUpCommandLine(base::CommandLine* command_line) override {
IsolateAllSitesForTesting(command_line);
}
};
IN_PROC_BROWSER_TEST_F(IsolatedDevToolsProtocolTest,
ControlNavigationsChildFrames) {
content::SetupCrossSiteRedirector(embedded_test_server());
ASSERT_TRUE(embedded_test_server()->Start());
// Navigate to about:blank first so we can make sure there is a target page we
// can attach to, and have Network.setRequestInterception complete
// before we start the navigations we're interested in.
NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
Attach();
std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue());
std::unique_ptr<base::ListValue> patterns(new base::ListValue());
patterns->Append(std::make_unique<base::DictionaryValue>());
params->Set("patterns", std::move(patterns));
SendCommand("Network.setRequestInterception", std::move(params), true);
NavigationFinishedObserver navigation_finished_observer(
shell()->web_contents());
GURL test_url = embedded_test_server()->GetURL(
"/devtools/control_navigations/iframe_navigation.html");
shell()->LoadURL(test_url);
// Allow main frame navigation, and all iframe navigations to http://a.com
// Allow initial iframe navigation to http://b.com but dissallow it to
// navigate to /devtools/navigation.html.
std::vector<ExpectedNavigation> expected_navigations = {
{"http://127.0.0.1/devtools/control_navigations/"
"iframe_navigation.html",
false /* expected_is_redirect */, false /* abort */},
{"http://127.0.0.1/cross-site/a.com/devtools/control_navigations/"
"meta_tag.html",
false /* expected_is_redirect */, false /* abort */},
{"http://127.0.0.1/cross-site/b.com/devtools/control_navigations/"
"meta_tag.html",
false /* expected_is_redirect */, false /* abort */},
{"http://a.com/devtools/control_navigations/meta_tag.html",
true /* expected_is_redirect */, false /* abort */},
{"http://b.com/devtools/control_navigations/meta_tag.html",
true /* expected_is_redirect */, false /* abort */},
{"http://a.com/devtools/navigation.html",
false /* expected_is_redirect */, false /* abort */},
{"http://b.com/devtools/navigation.html",
false /* expected_is_redirect */, true /* abort */}};
ProcessNavigationsAnyOrder(std::move(expected_navigations));
// Wait for each frame's navigation to finish, ignoring redirects.
navigation_finished_observer.WaitForNavigationsToFinish(3);
// Make sure each frame has the expected url.
EXPECT_THAT(
GetAllFrameUrls(),
ElementsAre("http://127.0.0.1/devtools/control_navigations/"
"iframe_navigation.html",
"http://a.com/devtools/navigation.html",
"http://b.com/devtools/control_navigations/meta_tag.html"));
}
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, VirtualTimeTest) { IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, VirtualTimeTest) {
NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
Attach(); Attach();
......
<html>
<body>
Dummy page.
<iframe src="/cross-site/a.com/devtools/control_navigations/meta_tag.html"></iframe>
<iframe src="/cross-site/b.com/devtools/control_navigations/meta_tag.html"></iframe>
</body>
</html>
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
-NavigationHandleImplBrowserTest.RedirectToRendererDebugUrl -NavigationHandleImplBrowserTest.RedirectToRendererDebugUrl
-AsyncResourceHandlerBrowserTest/AsyncResourceHandlerBrowserTest.UploadProgress* -AsyncResourceHandlerBrowserTest/AsyncResourceHandlerBrowserTest.UploadProgress*
-IsolatedDevToolsProtocolTest.ControlNavigationsChildFrames
-NavigationHandleImplBrowserTest.ErrorCodeOnRedirect -NavigationHandleImplBrowserTest.ErrorCodeOnRedirect
-WebContentsImplBrowserTest.DownloadImage_Deny_FileImage -WebContentsImplBrowserTest.DownloadImage_Deny_FileImage
......
Tests that top-frame navigations are correctly blocked when intercepted.
intercepted: http://127.0.0.1:8000/inspector-protocol/resources/meta-tag.html, continuing
intercepted: http://127.0.0.1:8000/inspector-protocol/resources/test-page.html, cancelling
location.href = http://127.0.0.1:8000/inspector-protocol/resources/meta-tag.html
Tests that navigations in cross-origin subframes are correctly blocked when intercepted.
Interceptions:
[
[0] : http://127.0.0.1:8000/inspector-protocol/resources/iframe-navigation.html
[1] : http://devtools.oopif-a.test:8000/inspector-protocol/resources/meta-tag.html
[2] : http://devtools.oopif-a.test:8000/inspector-protocol/resources/test-page.html
[3] : http://devtools.oopif-b.test:8000/inspector-protocol/resources/meta-tag.html
[4] : http://devtools.oopif-b.test:8000/inspector-protocol/resources/test-page.html: Aborted
]
Frames in page:
[
[0] : http://127.0.0.1:8000/inspector-protocol/resources/iframe-navigation.html
[1] : http://devtools.oopif-a.test:8000/inspector-protocol/resources/test-page.html
[2] : http://devtools.oopif-b.test:8000/inspector-protocol/resources/meta-tag.html
]
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(
`Tests that navigations in cross-origin subframes are correctly blocked when intercepted.`);
await session.protocol.Network.clearBrowserCache();
await session.protocol.Network.setCacheDisabled({cacheDisabled: true});
await dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: true});
let interceptionLog = [];
function onRequestIntercepted(dp, e) {
const response = {interceptionId: e.params.interceptionId};
if (e.params.request.url === 'http://devtools.oopif-b.test:8000/inspector-protocol/resources/test-page.html')
response.errorReason = 'Aborted';
interceptionLog.push(e.params.request.url + (response.errorReason ? `: ${response.errorReason}` : ''));
dp.Network.continueInterceptedRequest(response);
}
let loadCount = 5;
let loadCallback;
const loadPromise = new Promise(fulfill => loadCallback = fulfill);
const allTargets = [];
function initalizeTarget(dp) {
allTargets.push(dp);
dp.Network.setRequestInterception({patterns: [{}]});
dp.Network.onRequestIntercepted(onRequestIntercepted.bind(this, dp));
dp.Network.enable();
dp.Page.enable();
dp.Page.onFrameStoppedLoading(e => {
if (!--loadCount)
loadCallback();
});
dp.Runtime.runIfWaitingForDebugger();
}
initalizeTarget(dp);
dp.Target.onAttachedToTarget(e => {
const targetProtocol = session.createChild(e.params.sessionId).protocol;
initalizeTarget(targetProtocol);
});
dp.Page.navigate({url: 'http://127.0.0.1:8000/inspector-protocol/resources/iframe-navigation.html'});
let urls = [];
function getURLsRecursively(frameTree) {
urls.push(frameTree.frame.url);
(frameTree.childFrames || []).forEach(getURLsRecursively);
}
await loadPromise;
let trees = await Promise.all(allTargets.map(target => target.Page.getFrameTree()));
trees.map(result => result.result.frameTree).forEach(getURLsRecursively);
testRunner.log('Interceptions:');
testRunner.log(interceptionLog.sort());
testRunner.log('Frames in page:');
testRunner.log(urls.sort());
testRunner.completeTest();
})
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(
`Tests that top-frame navigations are correctly blocked when intercepted.`);
await session.protocol.Network.clearBrowserCache();
await session.protocol.Network.setCacheDisabled({cacheDisabled: true});
await session.protocol.Network.enable();
await session.protocol.Runtime.enable();
await dp.Network.setRequestInterception({patterns: [{}]});
dp.Page.navigate({url: 'http://127.0.0.1:8000/inspector-protocol/resources/meta-tag.html'});
const frame1 = (await dp.Network.onceRequestIntercepted()).params;
testRunner.log(`intercepted: ${frame1.request.url}, continuing`);
dp.Network.continueInterceptedRequest({interceptionId: frame1.interceptionId});
const frame2 = (await dp.Network.onceRequestIntercepted()).params;
testRunner.log(`intercepted: ${frame2.request.url}, cancelling`);
dp.Network.continueInterceptedRequest({interceptionId: frame2.interceptionId, errorReason: 'Aborted'});
const location = await session.evaluate('location.href');
testRunner.log(`location.href = ${location}`);
testRunner.completeTest();
})
Tests that Page.stopLoading cancels navigation
navigation finished
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(
'Tests that Page.stopLoading cancels navigation');
await dp.Page.enable();
await dp.Runtime.enable();
await dp.Network.enable();
await dp.Network.setRequestInterception({patterns: [{}]});
const navigatePromise = dp.Page.navigate({url: testRunner.url('../resources/inspector-protocol-page.html')});
dp.Page.stopLoading();
await navigatePromise;
testRunner.log('navigation finished');
testRunner.completeTest();
})
\ No newline at end of file
<html>
<body>
Dummy page.
<iframe src="http://devtools.oopif-a.test:8000/inspector-protocol/resources/meta-tag.html"></iframe>
<iframe src="http://devtools.oopif-b.test:8000/inspector-protocol/resources/meta-tag.html"></iframe>
</body>
</html>
<html> <html>
<head> <head>
<meta http-equiv="refresh" content="0; url=/devtools/navigation.html"> <meta http-equiv="refresh" content="0; url=/inspector-protocol/resources/test-page.html">
</head> </head>
<body> <body>
Dummy page, can't stay for long! Dummy page, can't stay for long!
......
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