Commit b8f5ecbe authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

chromeos: makes it possible for unittests to honor --mus

This makes it so aura::Env is configured for mus if --mus is specified
on the command line.

BUG=776514
TEST=test only change

Change-Id: Iaeb80b571e274f5bae9af7688d6b55b79e43b3d2
Reviewed-on: https://chromium-review.googlesource.com/823568Reviewed-by: default avatarElliot Glaysher <erg@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523824}
parent 3cd93982
......@@ -63,6 +63,9 @@ class AshTestHelper {
explicit AshTestHelper(AshTestEnvironment* ash_test_environment);
~AshTestHelper();
// This is intended to be called from TestSuites, not individual configs.
static void set_config(Config config) { config_ = config; }
// Returns the configuration that tests are run in. See ash::Config enum for
// details.
static Config config() { return config_; }
......
......@@ -4190,6 +4190,13 @@ static_library("test_support_unit") {
"//chrome/install_static/test:test_support",
]
}
if (is_chromeos) {
deps = [
"//ash:test_support_with_content",
"//ash/public/cpp",
]
}
}
if (is_win) {
......
......@@ -30,7 +30,11 @@
#include "ui/gl/test/gl_surface_test_support.h"
#if defined(OS_CHROMEOS)
#include "ash/public/cpp/config.h"
#include "ash/test/ash_test_helper.h"
#include "chromeos/chromeos_paths.h"
#include "ui/aura/env.h"
#include "ui/aura/test/aura_test_context_factory.h"
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
......@@ -107,6 +111,16 @@ void ChromeUnitTestSuite::Initialize() {
base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_);
ProfileShortcutManager::DisableForUnitTests();
#if defined(OS_CHROMEOS)
aura::Env* env = aura::Env::GetInstance();
if (env->mode() == aura::Env::Mode::MUS) {
ash::AshTestHelper::set_config(ash::Config::MUS);
context_factory_ = std::make_unique<aura::test::AuraTestContextFactory>();
env->set_context_factory(context_factory_.get());
env->set_context_factory_private(nullptr);
}
#endif
}
void ChromeUnitTestSuite::Shutdown() {
......
......@@ -5,12 +5,20 @@
#ifndef CHROME_TEST_BASE_CHROME_UNIT_TEST_SUITE_H_
#define CHROME_TEST_BASE_CHROME_UNIT_TEST_SUITE_H_
#include <memory>
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/test/test_discardable_memory_allocator.h"
#include "chrome/test/base/chrome_test_suite.h"
#if defined(OS_CHROMEOS)
namespace ui {
class ContextFactory;
}
#endif
// Test suite for unit tests. Creates additional stub services that are not
// needed for browser tests (e.g. a TestingBrowserProcess).
class ChromeUnitTestSuite : public ChromeTestSuite {
......@@ -31,6 +39,12 @@ class ChromeUnitTestSuite : public ChromeTestSuite {
private:
base::TestDiscardableMemoryAllocator discardable_memory_allocator_;
#if defined(OS_CHROMEOS)
// Only used when running in mus/mash, and is set as the context_factory
// on aura::Env.
std::unique_ptr<ui::ContextFactory> context_factory_;
#endif
DISALLOW_COPY_AND_ASSIGN(ChromeUnitTestSuite);
};
......
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