| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "blimp/test/browser_tests/blimp_browser_test.h" | 5 #include "blimp/test/browser_tests/blimp_browser_test.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "blimp/client/app/blimp_client_switches.h" | 16 #include "blimp/client/app/blimp_client_switches.h" |
| 17 #include "blimp/client/session/assignment_source.h" | 17 #include "blimp/client/session/assignment_source.h" |
| 18 #include "blimp/common/get_client_token.h" |
| 19 #include "blimp/common/switches.h" |
| 18 #include "blimp/engine/app/blimp_browser_main_parts.h" | 20 #include "blimp/engine/app/blimp_browser_main_parts.h" |
| 19 #include "blimp/engine/app/blimp_content_browser_client.h" | 21 #include "blimp/engine/app/blimp_content_browser_client.h" |
| 20 #include "blimp/engine/app/blimp_engine_config.h" | 22 #include "blimp/engine/app/blimp_engine_config.h" |
| 21 #include "blimp/engine/app/switches.h" | 23 #include "blimp/engine/app/switches.h" |
| 22 #include "blimp/engine/app/test_content_main_delegate.h" | 24 #include "blimp/engine/app/test_content_main_delegate.h" |
| 23 #include "blimp/engine/session/blimp_engine_session.h" | 25 #include "blimp/engine/session/blimp_engine_session.h" |
| 24 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/render_process_host.h" | 27 #include "content/public/browser/render_process_host.h" |
| 26 #include "content/public/common/url_constants.h" | 28 #include "content/public/common/url_constants.h" |
| 27 | 29 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 53 void BlimpBrowserTest::OnGetEnginePort(uint16_t port) { | 55 void BlimpBrowserTest::OnGetEnginePort(uint16_t port) { |
| 54 DCHECK_GT(port, 0); | 56 DCHECK_GT(port, 0); |
| 55 | 57 |
| 56 // A test client is started after BlimpBrowserTest::SetUpOnMainThread(). | 58 // A test client is started after BlimpBrowserTest::SetUpOnMainThread(). |
| 57 engine_port_ = port; | 59 engine_port_ = port; |
| 58 QuitRunLoop(); | 60 QuitRunLoop(); |
| 59 } | 61 } |
| 60 | 62 |
| 61 client::Assignment BlimpBrowserTest::GetAssignment() { | 63 client::Assignment BlimpBrowserTest::GetAssignment() { |
| 62 client::Assignment assignment; | 64 client::Assignment assignment; |
| 63 assignment.client_token = client::kDummyClientToken; | 65 assignment.client_token = GetClientToken( |
| 66 *base::CommandLine::ForCurrentProcess()); |
| 64 assignment.engine_endpoint = | 67 assignment.engine_endpoint = |
| 65 net::IPEndPoint(net::IPAddress::IPv4Localhost(), engine_port_); | 68 net::IPEndPoint(net::IPAddress::IPv4Localhost(), engine_port_); |
| 66 assignment.transport_protocol = client::Assignment::TransportProtocol::TCP; | 69 assignment.transport_protocol = client::Assignment::TransportProtocol::TCP; |
| 67 return assignment; | 70 return assignment; |
| 68 } | 71 } |
| 69 | 72 |
| 70 void BlimpBrowserTest::SetUpOnMainThread() { | 73 void BlimpBrowserTest::SetUpOnMainThread() { |
| 71 GetEngineSession()->GetEnginePortForTesting( | 74 GetEngineSession()->GetEnginePortForTesting( |
| 72 base::Bind(&BlimpBrowserTest::OnGetEnginePort, base::Unretained(this))); | 75 base::Bind(&BlimpBrowserTest::OnGetEnginePort, base::Unretained(this))); |
| 73 RunUntilQuit(); | 76 RunUntilQuit(); |
| 74 } | 77 } |
| 75 | 78 |
| 76 void BlimpBrowserTest::TearDownOnMainThread() { | 79 void BlimpBrowserTest::TearDownOnMainThread() { |
| 77 content::BrowserThread::GetMessageLoopProxyForThread( | 80 content::BrowserThread::GetMessageLoopProxyForThread( |
| 78 content::BrowserThread::UI) | 81 content::BrowserThread::UI) |
| 79 ->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 82 ->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 80 } | 83 } |
| 81 | 84 |
| 82 void BlimpBrowserTest::SetUpCommandLine(base::CommandLine* command_line) { | 85 void BlimpBrowserTest::SetUpCommandLine(base::CommandLine* command_line) { |
| 83 // Engine switches. | 86 // Engine switches. |
| 84 blimp::engine::SetCommandLineDefaults(command_line); | 87 blimp::engine::SetCommandLineDefaults(command_line); |
| 85 | 88 |
| 86 // Use dynamically allocated port for browser test. | 89 // Use dynamically allocated port for browser test. |
| 87 command_line->AppendSwitchASCII(blimp::engine::kEnginePort, "0"); | 90 command_line->AppendSwitchASCII(blimp::engine::kEnginePort, "0"); |
| 88 base::FilePath src_root; | 91 base::FilePath src_root; |
| 89 PathService::Get(base::DIR_SOURCE_ROOT, &src_root); | 92 PathService::Get(base::DIR_SOURCE_ROOT, &src_root); |
| 90 command_line->AppendSwitchASCII( | 93 command_line->AppendSwitchASCII(kClientTokenPath, |
| 91 blimp::engine::kClientTokenPath, | |
| 92 src_root.Append(kClientTokenFilePath).value()); | 94 src_root.Append(kClientTokenFilePath).value()); |
| 93 } | 95 } |
| 94 | 96 |
| 95 void BlimpBrowserTest::RunTestOnMainThreadLoop() { | 97 void BlimpBrowserTest::RunTestOnMainThreadLoop() { |
| 96 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 98 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 97 | 99 |
| 98 // Pump startup related events. | 100 // Pump startup related events. |
| 99 base::MessageLoop::current()->RunUntilIdle(); | 101 base::MessageLoop::current()->RunUntilIdle(); |
| 100 | 102 |
| 101 SetUpOnMainThread(); | 103 SetUpOnMainThread(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 116 run_loop_ = base::WrapUnique(new base::RunLoop()); | 118 run_loop_ = base::WrapUnique(new base::RunLoop()); |
| 117 run_loop_->Run(); | 119 run_loop_->Run(); |
| 118 run_loop_ = nullptr; | 120 run_loop_ = nullptr; |
| 119 } | 121 } |
| 120 | 122 |
| 121 void BlimpBrowserTest::QuitRunLoop() { | 123 void BlimpBrowserTest::QuitRunLoop() { |
| 122 run_loop_->Quit(); | 124 run_loop_->Quit(); |
| 123 } | 125 } |
| 124 | 126 |
| 125 } // namespace blimp | 127 } // namespace blimp |
| OLD | NEW |