Chromium Code Reviews| Index: blimp/engine/testing/app/blimp_browser_testing_main_parts.cc |
| diff --git a/blimp/engine/testing/app/blimp_browser_testing_main_parts.cc b/blimp/engine/testing/app/blimp_browser_testing_main_parts.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..da44e0dece8378493746524902c922367b6eafae |
| --- /dev/null |
| +++ b/blimp/engine/testing/app/blimp_browser_testing_main_parts.cc |
| @@ -0,0 +1,82 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "blimp/engine/testing/app/blimp_browser_testing_main_parts.h" |
| + |
| +#include <utility> |
| + |
| +#include "base/command_line.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "base/threading/thread_restrictions.h" |
| +#include "blimp/common/proto/blimp_message.pb.h" |
| +#include "blimp/engine/app/blimp_engine_config.h" |
| +#include "blimp/engine/app/settings_manager.h" |
| +#include "blimp/engine/common/blimp_browser_context.h" |
| +#include "blimp/engine/feature/geolocation/blimp_location_provider.h" |
| +#include "blimp/engine/session/blimp_engine_session.h" |
| +#include "blimp/engine/testing/app/blimp_url_rewriter.h" |
| +#include "blimp/engine/testing/session/blimp_engine_testing_session.h" |
| +#include "blimp/net/blimp_connection.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/browser_url_handler.h" |
| +#include "content/public/common/main_function_params.h" |
| +#include "net/base/net_module.h" |
| +#include "net/log/net_log.h" |
| +#include "net/test/embedded_test_server/embedded_test_server.h" |
| + |
| +namespace blimp { |
| +namespace engine { |
| + |
| +const base::FilePath::CharType kBlimpTestRoot[] = FILE_PATH_LITERAL(""); |
| + |
| +BlimpBrowserTestingMainParts::BlimpBrowserTestingMainParts( |
| + const content::MainFunctionParams& parameters) |
| + : BlimpBrowserMainParts(parameters){}; |
| + |
| +void BlimpBrowserTestingMainParts::PreEarlyInitialization() { |
| + // Fetch the engine config from the command line, and crash if invalid. Allow |
| + // IO operations even though this is not in the FILE thread as this is |
| + // necessary for Blimp startup and occurs before any user interaction. |
| + { |
|
Kevin M
2017/01/09 20:17:17
Remove unnecessary curly braces?
shenghuazhang
2017/01/10 23:20:49
Done.
|
| + const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| + base::ThreadRestrictions::ScopedAllowIO allow_io; |
| + engine_config_ = BlimpEngineConfig::Create(*cmd_line); |
| + CHECK(engine_config_); |
| + } |
| +} |
| + |
| +void BlimpBrowserTestingMainParts::PreMainMessageLoopRun() { |
| + 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
|
| + blimp::engine::test::g_ets_instance->ServeFilesFromSourceDirectory( |
| + base::FilePath(kBlimpTestRoot)); |
| + DCHECK(blimp::engine::test::g_ets_instance->Start()); |
| + |
| + content::BrowserURLHandler::GetInstance()->AddHandlerPair( |
| + &blimp::engine::test::HandleBlimpTestURL, |
| + content::BrowserURLHandler::null_handler()); |
| + |
| + 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.
|
| + |
| + std::unique_ptr<SettingsManager> settings_manager_; |
| + settings_manager_.reset(new SettingsManager); |
| + std::unique_ptr<BlimpBrowserContext> browser_context( |
| + new BlimpBrowserContext(false, net_log_.get())); |
| + |
| + std::unique_ptr<BlimpEngineSession> engine_session_; |
| + engine_session_.reset(new BlimpEngineTestingSession( |
| + std::move(browser_context), net_log_.get(), engine_config_.get(), |
| + settings_manager_.get())); |
| + engine_session_->Initialize(); |
| + BlimpBrowserMainParts::SetSettingsManagerForTesting( |
| + std::move(settings_manager_)); |
| + BlimpBrowserMainParts::SetEngineSessionForTesting(std::move(engine_session_)); |
| +} |
| + |
| +void BlimpBrowserTestingMainParts::PostMainMessageLoopRun() { |
| + BlimpBrowserMainParts::PostMainMessageLoopRun(); |
| + DCHECK(blimp::engine::test::g_ets_instance->ShutdownAndWaitUntilComplete()); |
| +} |
| + |
| +} // namespace engine |
| +} // namespace blimp |