Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "blimp/test/browser_tests/blimp_browser_test.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/base_switches.h" | |
| 10 #include "base/command_line.h" | |
| 11 #include "base/files/file_path.h" | |
| 12 #include "base/memory/ptr_util.h" | |
| 13 #include "base/message_loop/message_loop.h" | |
| 14 #include "base/run_loop.h" | |
| 15 #include "blimp/client/app/blimp_client_switches.h" | |
| 16 #include "blimp/client/session/assignment_source.h" | |
| 17 #include "blimp/engine/app/blimp_engine_config.h" | |
| 18 #include "blimp/engine/app/switches.h" | |
| 19 #include "content/public/browser/browser_thread.h" | |
| 20 #include "content/public/browser/render_process_host.h" | |
| 21 #include "content/public/common/url_constants.h" | |
| 22 #include "net/base/ip_endpoint.h" | |
| 23 #include "net/log/net_log.h" | |
| 24 #include "net/socket/tcp_server_socket.h" | |
| 25 #include "ui/gl/gl_switches.h" | |
| 26 | |
| 27 namespace blimp { | |
| 28 namespace { | |
| 29 | |
| 30 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.
| |
| 31 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.
| |
| 32 | |
| 33 uint16_t FindAvailableLocalPort() { | |
| 34 net::NetLog::Source source; | |
| 35 net::TCPServerSocket sock(NULL, source); | |
| 36 DCHECK_EQ(sock.Listen(net::IPEndPoint(net::IPAddress::IPv4Localhost(), 0), 1), | |
| 37 net::OK); | |
| 38 net::IPEndPoint address; | |
| 39 sock.GetLocalAddress(&address); | |
| 40 return address.port(); | |
| 41 } | |
| 42 | |
| 43 } // namespace | |
| 44 | |
| 45 BlimpBrowserTest::BlimpBrowserTest() { | |
| 46 base::FilePath test_data(FILE_PATH_LITERAL(kTestDataFilePath)); | |
| 47 CreateTestServer(test_data); | |
| 48 } | |
| 49 | |
| 50 BlimpBrowserTest::~BlimpBrowserTest() {} | |
| 51 | |
| 52 void BlimpBrowserTest::SetUp() { | |
| 53 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 54 SetUpCommandLine(command_line); | |
| 55 BrowserTestBase::SetUp(); | |
| 56 } | |
| 57 | |
| 58 void BlimpBrowserTest::SetUpOnMainThread() {} | |
| 59 | |
| 60 void BlimpBrowserTest::TearDownOnMainThread() { | |
| 61 content::BrowserThread::GetMessageLoopProxyForThread( | |
| 62 content::BrowserThread::UI) | |
| 63 ->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | |
| 64 } | |
| 65 | |
| 66 void BlimpBrowserTest::SetUpCommandLine(base::CommandLine* command_line) { | |
| 67 command_line->AppendSwitchASCII(::switches::kVModule, "blimp*=2"); | |
| 68 command_line->AppendSwitchASCII(blimp::switches::kEnginePort, | |
| 69 std::to_string(FindAvailableLocalPort())); | |
| 70 | |
| 71 // Engine switches | |
| 72 blimp::engine::SetUpCommandLine(command_line); | |
| 73 command_line->AppendSwitchASCII(blimp::engine::kClientTokenPath, | |
| 74 kClientTokenFilePath); | |
| 75 | |
| 76 // Client switches | |
| 77 // Client's AssignmentSource uses engine IP&port from command line and | |
| 78 // defaults to TCP client. | |
| 79 command_line->AppendSwitchASCII(blimp::switches::kEngineIP, "127.0.0.1"); | |
| 80 command_line->AppendSwitchASCII(blimp::switches::kEngineTransport, "tcp"); | |
| 81 } | |
| 82 | |
| 83 void BlimpBrowserTest::RunTestOnMainThreadLoop() { | |
| 84 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 85 | |
| 86 // Pump startup related events. | |
| 87 base::MessageLoop::current()->RunUntilIdle(); | |
| 88 | |
| 89 SetUpOnMainThread(); | |
| 90 RunTestOnMainThread(); | |
| 91 TearDownOnMainThread(); | |
| 92 | |
| 93 for (content::RenderProcessHost::iterator i( | |
| 94 content::RenderProcessHost::AllHostsIterator()); | |
| 95 !i.IsAtEnd(); i.Advance()) { | |
| 96 i.GetCurrentValue()->FastShutdownIfPossible(); | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 void BlimpBrowserTest::RunUntilQuit() { | |
| 101 base::MessageLoop::ScopedNestableTaskAllower nestable_allower( | |
| 102 base::MessageLoop::current()); | |
| 103 EXPECT_FALSE(run_loop_); | |
| 104 run_loop_ = base::WrapUnique(new base::RunLoop()); | |
| 105 run_loop_->Run(); | |
| 106 run_loop_ = nullptr; | |
| 107 } | |
| 108 | |
| 109 void BlimpBrowserTest::QuitRunLoop() { | |
| 110 run_loop_->Quit(); | |
| 111 } | |
| 112 | |
| 113 } // namespace blimp | |
| OLD | NEW |