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/engine/testing/app/blimp_browser_testing_main_parts.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/command_line.h" | |
| 10 #include "base/memory/ptr_util.h" | |
| 11 #include "base/threading/thread_restrictions.h" | |
| 12 #include "blimp/common/proto/blimp_message.pb.h" | |
| 13 #include "blimp/engine/app/blimp_engine_config.h" | |
| 14 #include "blimp/engine/app/settings_manager.h" | |
| 15 #include "blimp/engine/common/blimp_browser_context.h" | |
| 16 #include "blimp/engine/feature/geolocation/blimp_location_provider.h" | |
| 17 #include "blimp/engine/session/blimp_engine_session.h" | |
| 18 #include "blimp/engine/testing/app/blimp_url_rewriter.h" | |
| 19 #include "blimp/engine/testing/session/blimp_engine_testing_session.h" | |
| 20 #include "blimp/net/blimp_connection.h" | |
| 21 #include "content/public/browser/browser_thread.h" | |
| 22 #include "content/public/browser/browser_url_handler.h" | |
| 23 #include "content/public/common/main_function_params.h" | |
| 24 #include "net/base/net_module.h" | |
| 25 #include "net/log/net_log.h" | |
| 26 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 27 | |
| 28 namespace blimp { | |
| 29 namespace engine { | |
| 30 | |
| 31 const base::FilePath::CharType kBlimpTestRoot[] = FILE_PATH_LITERAL(""); | |
| 32 | |
| 33 BlimpBrowserTestingMainParts::BlimpBrowserTestingMainParts( | |
| 34 const content::MainFunctionParams& parameters) | |
| 35 : BlimpBrowserMainParts(parameters){}; | |
| 36 | |
| 37 void BlimpBrowserTestingMainParts::PreEarlyInitialization() { | |
| 38 // Fetch the engine config from the command line, and crash if invalid. Allow | |
| 39 // IO operations even though this is not in the FILE thread as this is | |
| 40 // necessary for Blimp startup and occurs before any user interaction. | |
| 41 { | |
|
Kevin M
2017/01/09 20:17:17
Remove unnecessary curly braces?
shenghuazhang
2017/01/10 23:20:49
Done.
| |
| 42 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | |
| 43 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 44 engine_config_ = BlimpEngineConfig::Create(*cmd_line); | |
| 45 CHECK(engine_config_); | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 void BlimpBrowserTestingMainParts::PreMainMessageLoopRun() { | |
| 50 blimp::engine::test::g_ets_instance.reset(new net::EmbeddedTestServer()); | |
|
Kevin M
2017/01/09 20:17:17
Why is this a global singleton? Can we bind an ins
shenghuazhang
2017/01/10 23:20:49
The embedded_test_server instance is called by the
Kevin M
2017/01/11 00:28:14
Got it. I wonder why this a free function, and not
| |
| 51 blimp::engine::test::g_ets_instance->ServeFilesFromSourceDirectory( | |
| 52 base::FilePath(kBlimpTestRoot)); | |
| 53 DCHECK(blimp::engine::test::g_ets_instance->Start()); | |
| 54 | |
| 55 content::BrowserURLHandler::GetInstance()->AddHandlerPair( | |
| 56 &blimp::engine::test::HandleBlimpTestURL, | |
| 57 content::BrowserURLHandler::null_handler()); | |
| 58 | |
| 59 net_log_.reset(new net::NetLog()); | |
|
Kevin M
2017/01/09 20:17:17
nit: use base::MakeUnique<X>() instead of "new X"
shenghuazhang
2017/01/10 23:20:49
Done.
| |
| 60 | |
| 61 std::unique_ptr<SettingsManager> settings_manager_; | |
| 62 settings_manager_.reset(new SettingsManager); | |
| 63 std::unique_ptr<BlimpBrowserContext> browser_context( | |
| 64 new BlimpBrowserContext(false, net_log_.get())); | |
| 65 | |
| 66 std::unique_ptr<BlimpEngineSession> engine_session_; | |
| 67 engine_session_.reset(new BlimpEngineTestingSession( | |
| 68 std::move(browser_context), net_log_.get(), engine_config_.get(), | |
| 69 settings_manager_.get())); | |
| 70 engine_session_->Initialize(); | |
| 71 BlimpBrowserMainParts::SetSettingsManagerForTesting( | |
| 72 std::move(settings_manager_)); | |
| 73 BlimpBrowserMainParts::SetEngineSessionForTesting(std::move(engine_session_)); | |
| 74 } | |
| 75 | |
| 76 void BlimpBrowserTestingMainParts::PostMainMessageLoopRun() { | |
| 77 BlimpBrowserMainParts::PostMainMessageLoopRun(); | |
| 78 DCHECK(blimp::engine::test::g_ets_instance->ShutdownAndWaitUntilComplete()); | |
| 79 } | |
| 80 | |
| 81 } // namespace engine | |
| 82 } // namespace blimp | |
| OLD | NEW |