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_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 | |
| 31 const char kTestDataFilePath[] = "blimp/engine/test/data"; | |
| 32 const char kClientTokenFilePath[] = "blimp/test/data/test_client_token"; | |
| 33 } // namespace | |
|
mmenke
2016/05/05 14:45:01
nit: should be consistent here - either a blank l
haibinlu
2016/05/05 18:06:30
Done.
| |
| 34 | |
| 35 BlimpBrowserTest::BlimpBrowserTest() { | |
| 36 base::FilePath test_data(FILE_PATH_LITERAL(kTestDataFilePath)); | |
| 37 CreateTestServer(test_data); | |
| 38 } | |
| 39 | |
| 40 BlimpBrowserTest::~BlimpBrowserTest() {} | |
| 41 | |
| 42 void BlimpBrowserTest::SetUp() { | |
| 43 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 44 SetUpCommandLine(command_line); | |
| 45 BrowserTestBase::SetUp(); | |
| 46 } | |
| 47 | |
| 48 engine::BlimpEngineSession* BlimpBrowserTest::GetEngineSession() { | |
| 49 return engine::BlimpContentMainDelegate::GetInstanceForTesting() | |
| 50 ->GetBlimpContentBrowserClient() | |
| 51 ->blimp_browser_main_parts() | |
| 52 ->GetBlimpEngineSession(); | |
| 53 } | |
| 54 | |
| 55 void BlimpBrowserTest::OnGetEnginePort(uint16_t port) { | |
| 56 DCHECK_GT(port, 0); | |
| 57 // Update the command line so that Client will use this port to connect. | |
| 58 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 59 blimp::switches::kEnginePort, std::to_string(port)); | |
|
mmenke
2016/05/05 14:45:01
Modifying the command line after we've started oth
haibinlu
2016/05/05 18:06:30
Thanks for catching another bug!
Changed to not
| |
| 60 QuitRunLoop(); | |
| 61 } | |
| 62 | |
| 63 void BlimpBrowserTest::SetUpOnMainThread() { | |
| 64 GetEngineSession()->GetEnginePortForTesting( | |
| 65 base::Bind(&BlimpBrowserTest::OnGetEnginePort, base::Unretained(this))); | |
| 66 RunUntilQuit(); | |
| 67 } | |
| 68 | |
| 69 void BlimpBrowserTest::TearDownOnMainThread() { | |
| 70 content::BrowserThread::GetMessageLoopProxyForThread( | |
| 71 content::BrowserThread::UI) | |
| 72 ->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | |
| 73 } | |
| 74 | |
| 75 void BlimpBrowserTest::SetUpCommandLine(base::CommandLine* command_line) { | |
| 76 command_line->AppendSwitchASCII(::switches::kVModule, "blimp*=2"); | |
| 77 | |
| 78 // Engine switches | |
| 79 blimp::engine::SetUpCommandLine(command_line); | |
| 80 // Use dynamically allocated port for browser test. | |
| 81 command_line->AppendSwitchASCII(blimp::switches::kEnginePort, "0"); | |
| 82 command_line->AppendSwitchASCII(blimp::engine::kClientTokenPath, | |
| 83 kClientTokenFilePath); | |
| 84 | |
| 85 // Client switches | |
| 86 // Client's AssignmentSource uses engine IP&port from command line and | |
| 87 // defaults to TCP client. | |
| 88 command_line->AppendSwitchASCII(blimp::switches::kEngineIP, "127.0.0.1"); | |
| 89 command_line->AppendSwitchASCII(blimp::switches::kEngineTransport, "tcp"); | |
| 90 } | |
| 91 | |
| 92 void BlimpBrowserTest::RunTestOnMainThreadLoop() { | |
| 93 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 94 | |
| 95 // Pump startup related events. | |
| 96 base::MessageLoop::current()->RunUntilIdle(); | |
| 97 | |
| 98 SetUpOnMainThread(); | |
| 99 RunTestOnMainThread(); | |
| 100 TearDownOnMainThread(); | |
| 101 | |
| 102 for (content::RenderProcessHost::iterator i( | |
| 103 content::RenderProcessHost::AllHostsIterator()); | |
| 104 !i.IsAtEnd(); i.Advance()) { | |
| 105 i.GetCurrentValue()->FastShutdownIfPossible(); | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 void BlimpBrowserTest::RunUntilQuit() { | |
| 110 base::MessageLoop::ScopedNestableTaskAllower nestable_allower( | |
| 111 base::MessageLoop::current()); | |
| 112 EXPECT_FALSE(run_loop_); | |
| 113 run_loop_ = base::WrapUnique(new base::RunLoop()); | |
| 114 run_loop_->Run(); | |
| 115 run_loop_ = nullptr; | |
| 116 } | |
| 117 | |
| 118 void BlimpBrowserTest::QuitRunLoop() { | |
| 119 run_loop_->Quit(); | |
| 120 } | |
| 121 | |
| 122 } // namespace blimp | |
| OLD | NEW |