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 | |
| 27 namespace blimp { | |
| 28 namespace { | |
| 29 const char kTestDataFilePath[] = "blimp/engine/test/data"; | |
| 30 const char kClientTokenFilePath[] = "blimp/test/data/test_client_token"; | |
| 31 } // namespace | |
| 32 | |
| 33 BlimpBrowserTest::BlimpBrowserTest() { | |
| 34 base::FilePath test_data(FILE_PATH_LITERAL(kTestDataFilePath)); | |
| 35 CreateTestServer(test_data); | |
|
Kevin M
2016/05/05 20:28:51
Just put FILE_PATH_LITERAL inline, no need to make
haibinlu
2016/05/05 22:41:36
Done.
| |
| 36 } | |
| 37 | |
| 38 BlimpBrowserTest::~BlimpBrowserTest() {} | |
| 39 | |
| 40 void BlimpBrowserTest::SetUp() { | |
| 41 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 42 SetUpCommandLine(command_line); | |
| 43 BrowserTestBase::SetUp(); | |
|
Kevin M
2016/05/05 20:28:51
Does this need to come after the BlimpBrowserTest
haibinlu
2016/05/05 22:41:36
No, it should be called after our command line is
| |
| 44 } | |
| 45 | |
| 46 engine::BlimpEngineSession* BlimpBrowserTest::GetEngineSession() { | |
| 47 return engine::BlimpContentMainDelegate::GetInstanceForTesting() | |
| 48 ->GetBlimpContentBrowserClient() | |
| 49 ->blimp_browser_main_parts() | |
| 50 ->GetBlimpEngineSession(); | |
| 51 } | |
| 52 | |
| 53 void BlimpBrowserTest::OnGetEnginePort(uint16_t port) { | |
| 54 DCHECK_GT(port, 0); | |
| 55 // A test Client is started after BlimpBrowserTest::SetUpOnMainThread() | |
|
Kevin M
2016/05/05 20:28:51
lowercase C, trailing period, newline before comme
haibinlu
2016/05/05 22:41:36
Done.
| |
| 56 engine_port_ = port; | |
| 57 QuitRunLoop(); | |
| 58 } | |
| 59 | |
| 60 client::Assignment BlimpBrowserTest::GetClientAssignment() { | |
|
Kevin M
2016/05/05 20:28:51
We just call them "assignments", so how about GetA
haibinlu
2016/05/05 22:41:36
Done.
| |
| 61 client::Assignment assignment; | |
| 62 assignment.client_token = client::kDummyClientToken; | |
| 63 assignment.engine_endpoint = | |
| 64 net::IPEndPoint(net::IPAddress::IPv4Localhost(), engine_port_); | |
| 65 assignment.transport_protocol = client::Assignment::TransportProtocol::TCP; | |
| 66 return assignment; | |
| 67 } | |
| 68 | |
| 69 void BlimpBrowserTest::SetUpOnMainThread() { | |
| 70 GetEngineSession()->GetEnginePortForTesting( | |
| 71 base::Bind(&BlimpBrowserTest::OnGetEnginePort, base::Unretained(this))); | |
| 72 RunUntilQuit(); | |
| 73 } | |
| 74 | |
| 75 void BlimpBrowserTest::TearDownOnMainThread() { | |
| 76 content::BrowserThread::GetMessageLoopProxyForThread( | |
| 77 content::BrowserThread::UI) | |
| 78 ->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | |
| 79 } | |
| 80 | |
| 81 void BlimpBrowserTest::SetUpCommandLine(base::CommandLine* command_line) { | |
| 82 command_line->AppendSwitchASCII(::switches::kVModule, "blimp*=2"); | |
|
Kevin M
2016/05/05 20:28:51
This will make the test output very noisy. We shou
haibinlu
2016/05/05 22:41:36
removed
| |
| 83 | |
| 84 // Engine switches | |
|
Kevin M
2016/05/05 20:28:51
trailing period
| |
| 85 blimp::engine::SetUpCommandLine(command_line); | |
| 86 // Use dynamically allocated port for browser test. | |
|
Kevin M
2016/05/05 20:28:51
Newline before comment
haibinlu
2016/05/05 22:41:36
Done.
| |
| 87 command_line->AppendSwitchASCII(blimp::engine::kEnginePort, "0"); | |
| 88 command_line->AppendSwitchASCII(blimp::engine::kClientTokenPath, | |
| 89 kClientTokenFilePath); | |
| 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() { | |
|
Kevin M
2016/05/05 20:28:51
This function is too trivial, we should just make
haibinlu
2016/05/05 22:41:36
IN_PROC_BROWSER_TEST_F(EngineBrowserTest, LoadUrl)
| |
| 119 run_loop_->Quit(); | |
| 120 } | |
| 121 | |
| 122 } // namespace blimp | |
| OLD | NEW |