#include "content/test/content_browser_test.h"
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/shell/shell.h"
#include "content/shell/shell_browser_context.h"
#include "content/shell/shell_content_browser_client.h"
#include "content/shell/shell_content_renderer_client.h"
#include "content/shell/shell_main_delegate.h"
#include "content/shell/shell_switches.h"
#include "content/test/test_content_client.h"
#if defined(OS_MACOSX)
#include "base/mac/scoped_nsautorelease_pool.h"
#endif
namespace content {
IN_PROC_BROWSER_TEST_F(ContentBrowserTest, MANUAL_ShouldntRun) {
ASSERT_TRUE(false);
}
ContentBrowserTest::ContentBrowserTest() {
#if defined(OS_MACOSX)
FilePath content_shell_path;
CHECK(PathService::Get(base::FILE_EXE, &content_shell_path));
content_shell_path = content_shell_path.DirName();
content_shell_path = content_shell_path.Append(
FILE_PATH_LITERAL("Content Shell.app/Contents/MacOS/Content Shell"));
CHECK(PathService::Override(base::FILE_EXE, content_shell_path));
#endif
CreateTestServer("content/test/data");
}
ContentBrowserTest::~ContentBrowserTest() {
}
void ContentBrowserTest::SetUp() {
shell_main_delegate_.reset(new ShellMainDelegate);
shell_main_delegate_->PreSandboxStartup();
CommandLine* command_line = CommandLine::ForCurrentProcess();
command_line->AppendSwitch(switches::kContentBrowserTest);
SetUpCommandLine(command_line);
if (command_line->HasSwitch(switches::kSingleProcess)) {
RenderProcessHost::set_run_renderer_in_process(true);
single_process_renderer_client_.reset(new ShellContentRendererClient);
content::GetContentClient()->set_renderer_for_testing(
single_process_renderer_client_.get());
}
#if defined(OS_MACOSX)
FilePath subprocess_path;
PathService::Get(base::FILE_EXE, &subprocess_path);
subprocess_path = subprocess_path.DirName().DirName();
DCHECK_EQ(subprocess_path.BaseName().value(), "Contents");
subprocess_path = subprocess_path.Append(
"Frameworks/Content Shell Helper.app/Contents/MacOS/Content Shell Helper");
command_line->AppendSwitchPath(switches::kBrowserSubprocessPath,
subprocess_path);
#endif
#if !defined(OS_WIN) && !defined(OS_CHROMEOS)
command_line->AppendSwitch(switches::kDisableAcceleratedVideoDecode);
#endif
BrowserTestBase::SetUp();
}
void ContentBrowserTest::TearDown() {
BrowserTestBase::TearDown();
shell_main_delegate_.reset();
}
void ContentBrowserTest::RunTestOnMainThreadLoop() {
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) {
CHECK_EQ(Shell::windows().size(), 1u);
shell_ = Shell::windows()[0];
}
#if defined(OS_MACOSX)
base::mac::ScopedNSAutoreleasePool pool;
#endif
MessageLoopForUI::current()->RunAllPending();
#if defined(OS_MACOSX)
pool.Recycle();
#endif
SetUpOnMainThread();
RunTestOnMainThread();
#if defined(OS_MACOSX)
pool.Recycle();
#endif
for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
!i.IsAtEnd(); i.Advance()) {
i.GetCurrentValue()->FastShutdownIfPossible();
}
Shell::CloseAllWindows();
}
Shell* ContentBrowserTest::CreateBrowser() {
ShellContentBrowserClient* browser_client =
static_cast<ShellContentBrowserClient*>(GetContentClient()->browser());
return Shell::CreateNewWindow(
browser_client->browser_context(),
GURL(chrome::kAboutBlankURL),
NULL,
MSG_ROUTING_NONE,
NULL);
}
Shell* ContentBrowserTest::CreateOffTheRecordBrowser() {
ShellContentBrowserClient* browser_client =
static_cast<ShellContentBrowserClient*>(GetContentClient()->browser());
return Shell::CreateNewWindow(
browser_client->off_the_record_browser_context(),
GURL(chrome::kAboutBlankURL),
NULL,
MSG_ROUTING_NONE,
NULL);
}
}