| 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_browser_main_parts.h" |
| 18 #include "blimp/engine/app/blimp_content_browser_client.h" |
| 19 #include "blimp/engine/app/blimp_content_main_delegate.h" |
| 20 #include "blimp/engine/app/blimp_engine_config.h" |
| 21 #include "blimp/engine/app/switches.h" |
| 22 #include "blimp/engine/session/blimp_engine_session.h" |
| 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/render_process_host.h" |
| 25 #include "content/public/common/url_constants.h" |
| 26 #include "ui/gl/gl_switches.h" |
| 27 |
| 28 namespace blimp { |
| 29 namespace { |
| 30 const char kTestDataFilePath[] = "blimp/engine/test/data"; |
| 31 const char kClientTokenFilePath[] = "blimp/test/data/test_client_token"; |
| 32 } // namespace |
| 33 |
| 34 BlimpBrowserTest::BlimpBrowserTest() { |
| 35 base::FilePath test_data(FILE_PATH_LITERAL(kTestDataFilePath)); |
| 36 CreateTestServer(test_data); |
| 37 } |
| 38 |
| 39 BlimpBrowserTest::~BlimpBrowserTest() {} |
| 40 |
| 41 void BlimpBrowserTest::SetUp() { |
| 42 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 43 SetUpCommandLine(command_line); |
| 44 BrowserTestBase::SetUp(); |
| 45 } |
| 46 |
| 47 engine::BlimpEngineSession* BlimpBrowserTest::GetEngineSession() { |
| 48 return engine::BlimpContentMainDelegate::GetInstanceForTesting() |
| 49 ->GetBlimpContentBrowserClient() |
| 50 ->blimp_browser_main_parts() |
| 51 ->GetBlimpEngineSession(); |
| 52 } |
| 53 |
| 54 void BlimpBrowserTest::OnGetEnginePort(uint16_t port) { |
| 55 DCHECK_GT(port, 0); |
| 56 // A test Client is started after BlimpBrowserTest::SetUpOnMainThread() |
| 57 engine_port_ = port; |
| 58 QuitRunLoop(); |
| 59 } |
| 60 |
| 61 client::Assignment BlimpBrowserTest::GetClientAssignment() { |
| 62 client::Assignment assignment; |
| 63 assignment.client_token = client::kDummyClientToken; |
| 64 assignment.engine_endpoint = |
| 65 net::IPEndPoint(net::IPAddress::IPv4Localhost(), engine_port_); |
| 66 assignment.transport_protocol = client::Assignment::TransportProtocol::TCP; |
| 67 return assignment; |
| 68 } |
| 69 |
| 70 void BlimpBrowserTest::SetUpOnMainThread() { |
| 71 GetEngineSession()->GetEnginePortForTesting( |
| 72 base::Bind(&BlimpBrowserTest::OnGetEnginePort, base::Unretained(this))); |
| 73 RunUntilQuit(); |
| 74 } |
| 75 |
| 76 void BlimpBrowserTest::TearDownOnMainThread() { |
| 77 content::BrowserThread::GetMessageLoopProxyForThread( |
| 78 content::BrowserThread::UI) |
| 79 ->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 80 } |
| 81 |
| 82 void BlimpBrowserTest::SetUpCommandLine(base::CommandLine* command_line) { |
| 83 command_line->AppendSwitchASCII(::switches::kVModule, "blimp*=2"); |
| 84 |
| 85 // Engine switches |
| 86 blimp::engine::SetUpCommandLine(command_line); |
| 87 // Use dynamically allocated port for browser test. |
| 88 command_line->AppendSwitchASCII(blimp::engine::kEnginePort, "0"); |
| 89 command_line->AppendSwitchASCII(blimp::engine::kClientTokenPath, |
| 90 kClientTokenFilePath); |
| 91 } |
| 92 |
| 93 void BlimpBrowserTest::RunTestOnMainThreadLoop() { |
| 94 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 95 |
| 96 // Pump startup related events. |
| 97 base::MessageLoop::current()->RunUntilIdle(); |
| 98 |
| 99 SetUpOnMainThread(); |
| 100 RunTestOnMainThread(); |
| 101 TearDownOnMainThread(); |
| 102 |
| 103 for (content::RenderProcessHost::iterator i( |
| 104 content::RenderProcessHost::AllHostsIterator()); |
| 105 !i.IsAtEnd(); i.Advance()) { |
| 106 i.GetCurrentValue()->FastShutdownIfPossible(); |
| 107 } |
| 108 } |
| 109 |
| 110 void BlimpBrowserTest::RunUntilQuit() { |
| 111 base::MessageLoop::ScopedNestableTaskAllower nestable_allower( |
| 112 base::MessageLoop::current()); |
| 113 EXPECT_FALSE(run_loop_); |
| 114 run_loop_ = base::WrapUnique(new base::RunLoop()); |
| 115 run_loop_->Run(); |
| 116 run_loop_ = nullptr; |
| 117 } |
| 118 |
| 119 void BlimpBrowserTest::QuitRunLoop() { |
| 120 run_loop_->Quit(); |
| 121 } |
| 122 |
| 123 } // namespace blimp |
| OLD | NEW |