Commit 9eaedfd9 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Split AshTestHelper setup and put some pieces in the constructor.

This is yet more precursor work for making AshTestHelper an
AuraTestHelper subclass.  It moves into the constructor things that
are more "general-purpose" and don't rely on any state that might be
customized after construction (e.g. reading the ViewsDelegate), and
leaves SetUp() focused more on the ash-specific shell/windowing stuff.

This changes the parameters passed to the constructor vs. setup, since
ultimately some will be relevant to the Aura side and some won't.  For
now, this requires storing the |context_factory_| on the object to
pass it from the constructor to setup, but that will go away later.

This also adds a no-args SetUp() function, which just calls the main
SetUp() function.  This is a precursor to making SetUp() and TearDown()
be virtual method overrides.

A few other trivial changes:
* Explicitly resets |session_controller_client_| during TearDown(),
  since I forgot that previously.  (Should have no effect)
* Puts GetLocalStatePrefService() into the same order in the .cc file
  as the .h file.

Should be no functional effects.

Bug: none
Change-Id: Ida64c3fc0779f3bb38a032cf8d3f490104fe88ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2124934
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754707}
parent a257b4e6
......@@ -83,18 +83,16 @@ void ShellBrowserMainParts::ToolkitInitialized() {
void ShellBrowserMainParts::PreMainMessageLoopRun() {
browser_context_.reset(new content::ShellBrowserContext(false));
AshTestHelper::InitParams init_params;
init_params.delegate = std::make_unique<ShellDelegateImpl>();
init_params.context_factory = content::GetContextFactory();
if (!parameters_.ui_task)
new_window_delegate_ = std::make_unique<ShellNewWindowDelegate>();
// TODO(oshima): Separate the class for ash_shell to reduce the test binary
// size.
if (parameters_.ui_task) {
init_params.config_type = AshTestHelper::kPerfTest;
} else {
new_window_delegate_ = std::make_unique<ShellNewWindowDelegate>();
init_params.config_type = AshTestHelper::kShell;
}
ash_test_helper_ = std::make_unique<AshTestHelper>();
ash_test_helper_ = std::make_unique<AshTestHelper>(
parameters_.ui_task ? AshTestHelper::kPerfTest : AshTestHelper::kShell,
content::GetContextFactory());
AshTestHelper::InitParams init_params;
init_params.delegate = std::make_unique<ShellDelegateImpl>();
ash_test_helper_->SetUp(std::move(init_params));
window_watcher_ = std::make_unique<WindowWatcher>();
......
This diff is collapsed.
......@@ -61,12 +61,6 @@ class TestPhotoController;
// root window and an ash::Shell instance with a test delegate.
class AshTestHelper {
public:
// Instantiates/destroys an AshTestHelper. This can happen in a
// single-threaded phase without a backing task environment. As such, the vast
// majority of initialization/tear down will be done in SetUp()/TearDown().
AshTestHelper();
~AshTestHelper();
enum ConfigType {
// The configuration for shell executable.
kShell,
......@@ -87,23 +81,31 @@ class AshTestHelper {
bool start_session = true;
// If this is not set, a TestShellDelegate will be used automatically.
std::unique_ptr<ShellDelegate> delegate;
ui::ContextFactory* context_factory = nullptr;
PrefService* local_state = nullptr;
ConfigType config_type = kUnitTest;
};
// Creates the ash::Shell and performs associated initialization according
// to |init_params|.
void SetUp(InitParams init_params = InitParams());
// Instantiates/destroys an AshTestHelper. This can happen in a
// single-threaded phase without a backing task environment or ViewsDelegate,
// and must not create those lest the caller wish to do so.
explicit AshTestHelper(ConfigType config_type = kUnitTest,
ui::ContextFactory* context_factory = nullptr);
~AshTestHelper();
// Calls through to SetUp() below, see comments there.
void SetUp();
// Destroys the ash::Shell and performs associated cleanup.
// Tears down everything but the Screen instance, which some tests access
// after this point.
void TearDown();
// Returns a root Window. Usually this is the active root Window, but that
// method can return NULL sometimes, and in those cases, we fall back on the
// primary root Window.
aura::Window* GetContext();
// Creates the ash::Shell and performs associated initialization according
// to |init_params|. When this function returns it guarantees a task
// environment and ViewsDelegate will exist, the shell will be started, and a
// window will be showing.
void SetUp(InitParams init_params);
PrefService* GetLocalStatePrefService();
display::Display GetSecondaryDisplay() const;
......@@ -138,6 +140,8 @@ class AshTestHelper {
void reset_commandline() { command_line_.reset(); }
private:
ConfigType config_type_;
ui::ContextFactory* context_factory_;
std::unique_ptr<::wm::WMState> wm_state_;
std::unique_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_;
std::unique_ptr<ui::TestContextFactories> context_factories_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment