Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: blimp/engine/browser_tests/blimp_browser_test.cc

Issue 2462183002: GRPC Stream implementation of HeliumStream
Patch Set: Fixed a few minor comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/engine/browser_tests/blimp_browser_test.h" 5 #include "blimp/engine/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/core/session/assignment_source.h" 16 #include "blimp/client/core/session/assignment_source.h"
17 #include "blimp/client/core/switches/blimp_client_switches.h" 17 #include "blimp/client/core/switches/blimp_client_switches.h"
18 #include "blimp/common/assignment_options.h"
18 #include "blimp/common/switches.h" 19 #include "blimp/common/switches.h"
19 #include "blimp/engine/app/blimp_browser_main_parts.h" 20 #include "blimp/engine/app/blimp_browser_main_parts.h"
20 #include "blimp/engine/app/blimp_content_browser_client.h" 21 #include "blimp/engine/app/blimp_content_browser_client.h"
21 #include "blimp/engine/app/blimp_engine_config.h" 22 #include "blimp/engine/app/blimp_engine_config.h"
22 #include "blimp/engine/app/switches.h" 23 #include "blimp/engine/app/switches.h"
23 #include "blimp/engine/app/test_content_main_delegate.h" 24 #include "blimp/engine/app/test_content_main_delegate.h"
24 #include "blimp/engine/session/blimp_engine_session.h" 25 #include "blimp/engine/session/blimp_engine_session.h"
25 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/render_process_host.h" 27 #include "content/public/browser/render_process_host.h"
27 #include "content/public/common/url_constants.h" 28 #include "content/public/common/url_constants.h"
28 #include "content/public/test/test_utils.h" 29 #include "content/public/test/test_utils.h"
29 30
30 namespace blimp { 31 namespace blimp {
31 namespace { 32 namespace {
32 const char kTestDataFilePath[] = "blimp/test/data"; 33 const char kTestDataFilePath[] = "blimp/test/data";
33 const char kClientAuthTokenFilePath[] = "blimp/test/data/test_client_token"; 34 const char kClientAuthTokenFilePath[] = "blimp/test/data/test_client_token";
34 const char kClientAuthToken[] = "MyVoiceIsMyPassport"; 35 const char kClientAuthToken[] = "MyVoiceIsMyPassport";
35 } // namespace 36 } // namespace
36 37
37 BlimpBrowserTest::BlimpBrowserTest() 38 BlimpBrowserTest::BlimpBrowserTest()
38 : engine_port_(0), 39 : completion_event_(base::WaitableEvent::ResetPolicy::MANUAL,
39 completion_event_(base::WaitableEvent::ResetPolicy::MANUAL,
40 base::WaitableEvent::InitialState::NOT_SIGNALED) { 40 base::WaitableEvent::InitialState::NOT_SIGNALED) {
41 CreateTestServer(base::FilePath(FILE_PATH_LITERAL(kTestDataFilePath))); 41 CreateTestServer(base::FilePath(FILE_PATH_LITERAL(kTestDataFilePath)));
42 } 42 }
43 43
44 BlimpBrowserTest::~BlimpBrowserTest() {} 44 BlimpBrowserTest::~BlimpBrowserTest() {}
45 45
46 extern bool UsesGrpc();
47
48 // Lets the same set of browser_tests run with different protocols.
49 client::Assignment::TransportProtocol GetAssignmentProtocol() {
50 if (UsesGrpc()) {
51 return client::Assignment::TransportProtocol::GRPC;
52 } else {
53 return client::Assignment::TransportProtocol::TCP;
54 }
55 }
56
46 void BlimpBrowserTest::RunUntilCompletion() { 57 void BlimpBrowserTest::RunUntilCompletion() {
47 while (!completion_event_.IsSignaled()) { 58 while (!completion_event_.IsSignaled()) {
48 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); 59 content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
49 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); 60 content::RunAllPendingInMessageLoop(content::BrowserThread::UI);
50 } 61 }
51 completion_event_.Reset(); 62 completion_event_.Reset();
52 } 63 }
53 64
54 void BlimpBrowserTest::AllowUIWaits() { 65 void BlimpBrowserTest::AllowUIWaits() {
55 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 66 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(...skipping 14 matching lines...) Expand all
70 engine::BlimpEngineSession* BlimpBrowserTest::GetEngineSession() { 81 engine::BlimpEngineSession* BlimpBrowserTest::GetEngineSession() {
71 return engine::TestContentMainDelegate::GetInstance() 82 return engine::TestContentMainDelegate::GetInstance()
72 ->browser_client() 83 ->browser_client()
73 ->blimp_browser_main_parts() 84 ->blimp_browser_main_parts()
74 ->GetBlimpEngineSession(); 85 ->GetBlimpEngineSession();
75 } 86 }
76 87
77 client::Assignment BlimpBrowserTest::GetAssignment() { 88 client::Assignment BlimpBrowserTest::GetAssignment() {
78 client::Assignment assignment; 89 client::Assignment assignment;
79 assignment.client_auth_token = kClientAuthToken; 90 assignment.client_auth_token = kClientAuthToken;
80 assignment.engine_endpoint = 91 assignment.assignment_options = assignment_options_;
81 net::IPEndPoint(net::IPAddress::IPv4Localhost(), engine_port_); 92 assignment.transport_protocol = GetAssignmentProtocol();
82 assignment.transport_protocol = client::Assignment::TransportProtocol::TCP;
83 return assignment; 93 return assignment;
84 } 94 }
85 95
86 void BlimpBrowserTest::SetUpCommandLine(base::CommandLine* command_line) { 96 void BlimpBrowserTest::SetUpCommandLine(base::CommandLine* command_line) {
87 // Engine switches. 97 // Engine switches.
88 blimp::engine::SetCommandLineDefaults(command_line); 98 blimp::engine::SetCommandLineDefaults(command_line);
89 99
90 // Pass through the engine port if it is passed to the test. 100 // Pass through the engine port if it is passed to the test.
91 // Otherwise, use a dynamic port. 101 // Otherwise, use a dynamic port.
92 if (!command_line->HasSwitch(blimp::engine::kEnginePort)) { 102 if (!command_line->HasSwitch(blimp::engine::kEnginePort)) {
93 command_line->AppendSwitchASCII(blimp::engine::kEnginePort, "0"); 103 command_line->AppendSwitchASCII(blimp::engine::kEnginePort, "0");
94 } 104 }
95 105
96 // TODO(perumaal): Switch to gRPC when it's ready. See crbug.com/659279. 106 switch (GetAssignmentProtocol()) {
107 case client::Assignment::TransportProtocol::TCP:
108 command_line->AppendSwitchASCII(blimp::engine::kEngineTransport,
109 blimp::engine::kTcpTransport);
110 break;
111 case client::Assignment::TransportProtocol::GRPC:
112 command_line->AppendSwitchASCII(blimp::engine::kEngineTransport,
113 blimp::engine::kGrpcTransport);
114 break;
115 default:
116 LOG(FATAL) << "Unknown transport type: "
117 << static_cast<int>(GetAssignmentProtocol());
118 }
97 119
98 base::FilePath src_root; 120 base::FilePath src_root;
99 PathService::Get(base::DIR_SOURCE_ROOT, &src_root); 121 PathService::Get(base::DIR_SOURCE_ROOT, &src_root);
100 command_line->AppendSwitchASCII( 122 command_line->AppendSwitchASCII(
101 kClientAuthTokenPath, src_root.Append(kClientAuthTokenFilePath).value()); 123 kClientAuthTokenPath, src_root.Append(kClientAuthTokenFilePath).value());
102 } 124 }
103 125
104 void BlimpBrowserTest::SetUpOnMainThread() { 126 void BlimpBrowserTest::SetUpOnMainThread() {
105 // Get the connection's port number across the IO/UI thread boundary. 127 // Get the connection's port number across the IO/UI thread boundary.
106 GetEngineSession()->GetEnginePortForTesting(base::Bind( 128 GetEngineSession()->GetAssignmentOptions(base::Bind(
107 &BlimpBrowserTest::OnGetEnginePortCompletion, base::Unretained(this))); 129 &BlimpBrowserTest::OnGetEngineSetupCompletion, base::Unretained(this)));
108 130
109 RunUntilCompletion(); 131 RunUntilCompletion();
110 } 132 }
111 133
112 void BlimpBrowserTest::TearDownOnMainThread() { 134 void BlimpBrowserTest::TearDownOnMainThread() {
113 allow_ui_waits_.reset(); 135 allow_ui_waits_.reset();
114 base::MessageLoop::current()->QuitWhenIdle(); 136 base::MessageLoop::current()->QuitWhenIdle();
115 } 137 }
116 138
117 void BlimpBrowserTest::RunTestOnMainThreadLoop() { 139 void BlimpBrowserTest::RunTestOnMainThreadLoop() {
118 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 140 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
119 141
120 SetUpOnMainThread(); 142 SetUpOnMainThread();
121 RunTestOnMainThread(); 143 RunTestOnMainThread();
122 TearDownOnMainThread(); 144 TearDownOnMainThread();
123 145
124 for (content::RenderProcessHost::iterator i( 146 for (content::RenderProcessHost::iterator i(
125 content::RenderProcessHost::AllHostsIterator()); 147 content::RenderProcessHost::AllHostsIterator());
126 !i.IsAtEnd(); i.Advance()) { 148 !i.IsAtEnd(); i.Advance()) {
127 i.GetCurrentValue()->FastShutdownIfPossible(); 149 i.GetCurrentValue()->FastShutdownIfPossible();
128 } 150 }
129 } 151 }
130 152
131 void BlimpBrowserTest::OnGetEnginePortCompletion(uint16_t port) { 153 void BlimpBrowserTest::OnGetEngineSetupCompletion(
132 engine_port_ = port; 154 AssignmentOptions assignment_options) {
155 assignment_options_ = assignment_options;
133 SignalCompletion(); 156 SignalCompletion();
134 } 157 }
135 158
136 } // namespace blimp 159 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698