blob: 7ee8890e188968a44831265a83bdd414cfa09eed [file] [log] [blame]
[email protected]578c81b2012-01-27 07:25:021// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]2b99f8c2011-10-11 19:42:242// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
skyecd78dba2017-02-15 21:16:435#include "ash/test/ash_test_suite.h"
[email protected]2b99f8c2011-10-11 19:42:246
sky25b49b282017-03-31 14:41:137#include "ash/test/ash_test_helper.h"
[email protected]57999812013-02-24 05:40:528#include "base/files/file_path.h"
msw40ddaa81f2016-02-10 00:26:169#include "base/i18n/rtl.h"
10#include "base/path_service.h"
[email protected]2b99f8c2011-10-11 19:42:2411#include "build/build_config.h"
[email protected]41168e22013-02-13 18:25:4312#include "testing/gtest/include/gtest/gtest.h"
[email protected]2b99f8c2011-10-11 19:42:2413#include "ui/base/resource/resource_bundle.h"
14#include "ui/base/ui_base_paths.h"
Sadrul Habib Chowdhuryeeb5a942017-11-28 21:17:2315#include "ui/base/ui_base_switches.h"
Mitsuru Oshimaf5025cc72021-10-07 10:28:1816#include "ui/display/display_switches.h"
Scott Violet40bc90f2018-08-07 16:32:1417#include "ui/gl/gl_switches.h"
sadrulba162cd2015-07-20 22:34:2618#include "ui/gl/test/gl_surface_test_support.h"
Avery Musbach8e3efe12021-11-16 23:52:0619#include "ui/lottie/resource.h"
[email protected]72f08de2011-12-09 16:19:0320
[email protected]55f593352011-12-24 05:42:4621namespace ash {
[email protected]6377a002011-11-10 20:26:4722
skyecd78dba2017-02-15 21:16:4323AshTestSuite::AshTestSuite(int argc, char** argv) : TestSuite(argc, argv) {}
thakis94b36052015-04-30 20:07:4824
Chris Watkinsc24daf62017-11-28 03:43:0925AshTestSuite::~AshTestSuite() = default;
[email protected]2b99f8c2011-10-11 19:42:2426
skyecd78dba2017-02-15 21:16:4327void AshTestSuite::Initialize() {
[email protected]2b99f8c2011-10-11 19:42:2428 base::TestSuite::Initialize();
Scott Violet40bc90f2018-08-07 16:32:1429
30 // Force software-gl. This is necessary for tests that trigger launching ash
31 // in its own process
32 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
33 cmd_line->AppendSwitch(switches::kOverrideUseSoftwareGLForTests);
Mitsuru Oshimaf5025cc72021-10-07 10:28:1834 cmd_line->AppendSwitch(switches::kRejectSquareDisplay);
Scott Violet40bc90f2018-08-07 16:32:1435
kylechar7a463842016-05-26 14:46:1236 gl::GLSurfaceTestSupport::InitializeOneOff();
[email protected]2b99f8c2011-10-11 19:42:2437
[email protected]2b99f8c2011-10-11 19:42:2438 ui::RegisterPathProvider();
39
msw40ddaa81f2016-02-10 00:26:1640 // Force unittests to run using en-US so if we test against string output,
41 // it'll pass regardless of the system language.
42 base::i18n::SetICUDefaultLocale("en_US");
43
Avery Musbach8e3efe12021-11-16 23:52:0644 ui::ResourceBundle::SetParseLottieAsStillImage(
45 &lottie::ParseLottieAsStillImage);
46
Mitsuru Oshima20a852f2021-12-02 20:44:3147 LoadTestResources();
48
49 base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_);
50 env_ = aura::Env::CreateInstance();
51}
52
53void AshTestSuite::LoadTestResources() {
mswd04d3ef32016-07-18 23:43:0854 // Load ash test resources and en-US strings; not 'common' (Chrome) resources.
msw40ddaa81f2016-02-10 00:26:1655 base::FilePath path;
Mason Bendixend798600c2021-11-23 19:50:4256 base::PathService::Get(base::DIR_ASSETS, &path);
msw40ddaa81f2016-02-10 00:26:1657 base::FilePath ash_test_strings =
58 path.Append(FILE_PATH_LITERAL("ash_test_strings.pak"));
msw40ddaa81f2016-02-10 00:26:1659 ui::ResourceBundle::InitSharedInstanceWithPakPath(ash_test_strings);
skyabc167a2016-09-07 00:57:4560
Mitsuru Oshima20a852f2021-12-02 20:44:3161 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
62 path.AppendASCII("ash_test_resources_unscaled.pak"),
63 ui::kScaleFactorNone);
64
Mitsuru Oshima15732bc92021-08-16 22:59:3165 if (ui::ResourceBundle::IsScaleFactorSupported(ui::k100Percent)) {
skyabc167a2016-09-07 00:57:4566 base::FilePath ash_test_resources_100 =
Scott Violete9d8df7542018-12-18 16:19:0367 path.AppendASCII("ash_test_resources_100_percent.pak");
skyabc167a2016-09-07 00:57:4568 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
Mitsuru Oshima15732bc92021-08-16 22:59:3169 ash_test_resources_100, ui::k100Percent);
skyabc167a2016-09-07 00:57:4570 }
Mitsuru Oshima15732bc92021-08-16 22:59:3171 if (ui::ResourceBundle::IsScaleFactorSupported(ui::k200Percent)) {
skyabc167a2016-09-07 00:57:4572 base::FilePath ash_test_resources_200 =
73 path.Append(FILE_PATH_LITERAL("ash_test_resources_200_percent.pak"));
74 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
Mitsuru Oshima15732bc92021-08-16 22:59:3175 ash_test_resources_200, ui::k200Percent);
skyabc167a2016-09-07 00:57:4576 }
[email protected]2b99f8c2011-10-11 19:42:2477}
78
skyecd78dba2017-02-15 21:16:4379void AshTestSuite::Shutdown() {
sadrul578205fa2016-04-11 22:43:5680 env_.reset();
[email protected]2b99f8c2011-10-11 19:42:2481 ui::ResourceBundle::CleanupSharedInstance();
[email protected]2b99f8c2011-10-11 19:42:2482 base::TestSuite::Shutdown();
83}
[email protected]6377a002011-11-10 20:26:4784
[email protected]55f593352011-12-24 05:42:4685} // namespace ash