Chromium Code Reviews| Index: blimp/test/browser_tests/blimp_browser_test.cc |
| diff --git a/blimp/test/browser_tests/blimp_browser_test.cc b/blimp/test/browser_tests/blimp_browser_test.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c6354433c7d6e744df15db07cbdad09de678f1ca |
| --- /dev/null |
| +++ b/blimp/test/browser_tests/blimp_browser_test.cc |
| @@ -0,0 +1,113 @@ |
| +// Copyright 2016 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 "blimp/test/browser_tests/blimp_browser_test.h" |
| + |
| +#include <string> |
| + |
| +#include "base/base_switches.h" |
| +#include "base/command_line.h" |
| +#include "base/files/file_path.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/run_loop.h" |
| +#include "blimp/client/app/blimp_client_switches.h" |
| +#include "blimp/client/session/assignment_source.h" |
| +#include "blimp/engine/app/blimp_engine_config.h" |
| +#include "blimp/engine/app/switches.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/render_process_host.h" |
| +#include "content/public/common/url_constants.h" |
| +#include "net/base/ip_endpoint.h" |
| +#include "net/log/net_log.h" |
| +#include "net/socket/tcp_server_socket.h" |
| +#include "ui/gl/gl_switches.h" |
| + |
| +namespace blimp { |
| +namespace { |
| + |
| +const char* kTestDataFilePath = "blimp/engine/test/data"; |
|
Kevin M
2016/05/03 20:29:34
const char kTestDataFilePath[]
haibinlu
2016/05/03 20:51:59
Done.
|
| +const char* kClientTokenFilePath = "blimp/test/data/test_client_token"; |
|
Kevin M
2016/05/03 20:29:34
ditto
haibinlu
2016/05/03 20:51:59
Done.
|
| + |
| +uint16_t FindAvailableLocalPort() { |
| + net::NetLog::Source source; |
| + net::TCPServerSocket sock(NULL, source); |
| + DCHECK_EQ(sock.Listen(net::IPEndPoint(net::IPAddress::IPv4Localhost(), 0), 1), |
| + net::OK); |
| + net::IPEndPoint address; |
| + sock.GetLocalAddress(&address); |
| + return address.port(); |
| +} |
| + |
| +} // namespace |
| + |
| +BlimpBrowserTest::BlimpBrowserTest() { |
| + base::FilePath test_data(FILE_PATH_LITERAL(kTestDataFilePath)); |
| + CreateTestServer(test_data); |
| +} |
| + |
| +BlimpBrowserTest::~BlimpBrowserTest() {} |
| + |
| +void BlimpBrowserTest::SetUp() { |
| + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| + SetUpCommandLine(command_line); |
| + BrowserTestBase::SetUp(); |
| +} |
| + |
| +void BlimpBrowserTest::SetUpOnMainThread() {} |
| + |
| +void BlimpBrowserTest::TearDownOnMainThread() { |
| + content::BrowserThread::GetMessageLoopProxyForThread( |
| + content::BrowserThread::UI) |
| + ->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| +} |
| + |
| +void BlimpBrowserTest::SetUpCommandLine(base::CommandLine* command_line) { |
| + command_line->AppendSwitchASCII(::switches::kVModule, "blimp*=2"); |
| + command_line->AppendSwitchASCII(blimp::switches::kEnginePort, |
| + std::to_string(FindAvailableLocalPort())); |
| + |
| + // Engine switches |
| + blimp::engine::SetUpCommandLine(command_line); |
| + command_line->AppendSwitchASCII(blimp::engine::kClientTokenPath, |
| + kClientTokenFilePath); |
| + |
| + // Client switches |
| + // Client's AssignmentSource uses engine IP&port from command line and |
| + // defaults to TCP client. |
| + command_line->AppendSwitchASCII(blimp::switches::kEngineIP, "127.0.0.1"); |
| + command_line->AppendSwitchASCII(blimp::switches::kEngineTransport, "tcp"); |
| +} |
| + |
| +void BlimpBrowserTest::RunTestOnMainThreadLoop() { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + |
| + // Pump startup related events. |
| + base::MessageLoop::current()->RunUntilIdle(); |
| + |
| + SetUpOnMainThread(); |
| + RunTestOnMainThread(); |
| + TearDownOnMainThread(); |
| + |
| + for (content::RenderProcessHost::iterator i( |
| + content::RenderProcessHost::AllHostsIterator()); |
| + !i.IsAtEnd(); i.Advance()) { |
| + i.GetCurrentValue()->FastShutdownIfPossible(); |
| + } |
| +} |
| + |
| +void BlimpBrowserTest::RunUntilQuit() { |
| + base::MessageLoop::ScopedNestableTaskAllower nestable_allower( |
| + base::MessageLoop::current()); |
| + EXPECT_FALSE(run_loop_); |
| + run_loop_ = base::WrapUnique(new base::RunLoop()); |
| + run_loop_->Run(); |
| + run_loop_ = nullptr; |
| +} |
| + |
| +void BlimpBrowserTest::QuitRunLoop() { |
| + run_loop_->Quit(); |
| +} |
| + |
| +} // namespace blimp |