This source file includes following definitions.
- PrepareToDuplicateHosts
- SetUpCommandLine
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/command_line.h"
#include "base/containers/hash_tables.h"
#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
#include "content/browser/dom_storage/session_storage_namespace_impl.h"
#include "content/browser/frame_host/navigator.h"
#include "content/browser/renderer_host/render_view_host_factory.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/view_messages.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
namespace content {
namespace {
RenderViewHostImpl* PrepareToDuplicateHosts(Shell* shell,
int* target_routing_id) {
GURL foo("http://foo.com/files/simple_page.html");
NavigateToURL(shell, foo);
ShellAddedObserver shell2_observer;
EXPECT_TRUE(ExecuteScript(
shell->web_contents(), "window.open(document.URL + '#2');"));
Shell* shell2 = shell2_observer.GetShell();
EXPECT_EQ(shell->web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
shell2->web_contents()->GetRenderViewHost()->GetProcess()->GetID());
*target_routing_id =
shell2->web_contents()->GetRenderViewHost()->GetRoutingID();
EXPECT_NE(*target_routing_id,
shell->web_contents()->GetRenderViewHost()->GetRoutingID());
GURL extension_url("https://bar.com/files/simple_page.html");
WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell->web_contents());
wc->GetFrameTree()->root()->navigator()->RequestOpenURL(
wc->GetFrameTree()->root()->current_frame_host(), extension_url,
Referrer(), CURRENT_TAB,
false, true);
RenderViewHostImpl* pending_rvh =
wc->GetRenderManagerForTesting()->pending_render_view_host();
EXPECT_TRUE(pending_rvh != NULL);
EXPECT_NE(shell->web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
pending_rvh->GetProcess()->GetID());
return pending_rvh;
}
}
class SecurityExploitBrowserTest : public ContentBrowserTest {
public:
SecurityExploitBrowserTest() {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ASSERT_TRUE(test_server()->Start());
command_line->AppendSwitchASCII(
switches::kHostResolverRules,
"MAP * " + test_server()->host_port_pair().ToString() +
",EXCLUDE localhost");
}
};
IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, SetWebUIProperty) {
GURL foo("http://foo.com/files/simple_page.html");
NavigateToURL(shell(), foo);
EXPECT_EQ(0,
shell()->web_contents()->GetRenderViewHost()->GetEnabledBindings());
content::RenderProcessHostWatcher terminated(
shell()->web_contents(),
content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
shell()->web_contents()->GetRenderViewHost()->SetWebUIProperty(
"toolkit", "views");
terminated.Wait();
}
IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest,
AttemptDuplicateRenderViewHost) {
int duplicate_routing_id = MSG_ROUTING_NONE;
RenderViewHostImpl* pending_rvh =
PrepareToDuplicateHosts(shell(), &duplicate_routing_id);
EXPECT_NE(MSG_ROUTING_NONE, duplicate_routing_id);
ViewHostMsg_CreateWindow_Params params;
DOMStorageContextWrapper* dom_storage_context =
static_cast<DOMStorageContextWrapper*>(
BrowserContext::GetStoragePartition(
shell()->web_contents()->GetBrowserContext(),
pending_rvh->GetSiteInstance())->GetDOMStorageContext());
scoped_refptr<SessionStorageNamespaceImpl> session_storage(
new SessionStorageNamespaceImpl(dom_storage_context));
int main_frame_routing_id = duplicate_routing_id + 1;
pending_rvh->CreateNewWindow(
duplicate_routing_id, main_frame_routing_id, params, session_storage);
}
IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest,
AttemptDuplicateRenderWidgetHost) {
int duplicate_routing_id = MSG_ROUTING_NONE;
RenderViewHostImpl* pending_rvh =
PrepareToDuplicateHosts(shell(), &duplicate_routing_id);
EXPECT_NE(MSG_ROUTING_NONE, duplicate_routing_id);
pending_rvh->CreateNewWidget(duplicate_routing_id, blink::WebPopupTypeSelect);
}
}