[email protected] | 578c81b | 2012-01-27 07:25:02 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 2b99f8c | 2011-10-11 19:42:24 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
sky | ecd78dba | 2017-02-15 21:16:43 | [diff] [blame] | 5 | #include "ash/test/ash_test_suite.h" |
[email protected] | 2b99f8c | 2011-10-11 19:42:24 | [diff] [blame] | 6 | |
sky | 25b49b28 | 2017-03-31 14:41:13 | [diff] [blame] | 7 | #include "ash/test/ash_test_helper.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 8 | #include "base/files/file_path.h" |
msw | 40ddaa81f | 2016-02-10 00:26:16 | [diff] [blame] | 9 | #include "base/i18n/rtl.h" |
10 | #include "base/path_service.h" | ||||
[email protected] | 2b99f8c | 2011-10-11 19:42:24 | [diff] [blame] | 11 | #include "build/build_config.h" |
[email protected] | 41168e2 | 2013-02-13 18:25:43 | [diff] [blame] | 12 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 2b99f8c | 2011-10-11 19:42:24 | [diff] [blame] | 13 | #include "ui/base/resource/resource_bundle.h" |
14 | #include "ui/base/ui_base_paths.h" | ||||
Sadrul Habib Chowdhury | eeb5a94 | 2017-11-28 21:17:23 | [diff] [blame] | 15 | #include "ui/base/ui_base_switches.h" |
Mitsuru Oshima | f5025cc7 | 2021-10-07 10:28:18 | [diff] [blame] | 16 | #include "ui/display/display_switches.h" |
Scott Violet | 40bc90f | 2018-08-07 16:32:14 | [diff] [blame] | 17 | #include "ui/gl/gl_switches.h" |
sadrul | ba162cd | 2015-07-20 22:34:26 | [diff] [blame] | 18 | #include "ui/gl/test/gl_surface_test_support.h" |
Avery Musbach | 8e3efe1 | 2021-11-16 23:52:06 | [diff] [blame] | 19 | #include "ui/lottie/resource.h" |
[email protected] | 72f08de | 2011-12-09 16:19:03 | [diff] [blame] | 20 | |
[email protected] | 55f59335 | 2011-12-24 05:42:46 | [diff] [blame] | 21 | namespace ash { |
[email protected] | 6377a00 | 2011-11-10 20:26:47 | [diff] [blame] | 22 | |
sky | ecd78dba | 2017-02-15 21:16:43 | [diff] [blame] | 23 | AshTestSuite::AshTestSuite(int argc, char** argv) : TestSuite(argc, argv) {} |
thakis | 94b3605 | 2015-04-30 20:07:48 | [diff] [blame] | 24 | |
Chris Watkins | c24daf6 | 2017-11-28 03:43:09 | [diff] [blame] | 25 | AshTestSuite::~AshTestSuite() = default; |
[email protected] | 2b99f8c | 2011-10-11 19:42:24 | [diff] [blame] | 26 | |
sky | ecd78dba | 2017-02-15 21:16:43 | [diff] [blame] | 27 | void AshTestSuite::Initialize() { |
[email protected] | 2b99f8c | 2011-10-11 19:42:24 | [diff] [blame] | 28 | base::TestSuite::Initialize(); |
Scott Violet | 40bc90f | 2018-08-07 16:32:14 | [diff] [blame] | 29 | |
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 Oshima | f5025cc7 | 2021-10-07 10:28:18 | [diff] [blame] | 34 | cmd_line->AppendSwitch(switches::kRejectSquareDisplay); |
Scott Violet | 40bc90f | 2018-08-07 16:32:14 | [diff] [blame] | 35 | |
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 36 | gl::GLSurfaceTestSupport::InitializeOneOff(); |
[email protected] | 2b99f8c | 2011-10-11 19:42:24 | [diff] [blame] | 37 | |
[email protected] | 2b99f8c | 2011-10-11 19:42:24 | [diff] [blame] | 38 | ui::RegisterPathProvider(); |
39 | |||||
msw | 40ddaa81f | 2016-02-10 00:26:16 | [diff] [blame] | 40 | // 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 Musbach | 8e3efe1 | 2021-11-16 23:52:06 | [diff] [blame] | 44 | ui::ResourceBundle::SetParseLottieAsStillImage( |
45 | &lottie::ParseLottieAsStillImage); | ||||
46 | |||||
Mitsuru Oshima | 20a852f | 2021-12-02 20:44:31 | [diff] [blame] | 47 | LoadTestResources(); |
48 | |||||
49 | base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_); | ||||
50 | env_ = aura::Env::CreateInstance(); | ||||
51 | } | ||||
52 | |||||
53 | void AshTestSuite::LoadTestResources() { | ||||
msw | d04d3ef3 | 2016-07-18 23:43:08 | [diff] [blame] | 54 | // Load ash test resources and en-US strings; not 'common' (Chrome) resources. |
msw | 40ddaa81f | 2016-02-10 00:26:16 | [diff] [blame] | 55 | base::FilePath path; |
Mason Bendixen | d798600c | 2021-11-23 19:50:42 | [diff] [blame] | 56 | base::PathService::Get(base::DIR_ASSETS, &path); |
msw | 40ddaa81f | 2016-02-10 00:26:16 | [diff] [blame] | 57 | base::FilePath ash_test_strings = |
58 | path.Append(FILE_PATH_LITERAL("ash_test_strings.pak")); | ||||
msw | 40ddaa81f | 2016-02-10 00:26:16 | [diff] [blame] | 59 | ui::ResourceBundle::InitSharedInstanceWithPakPath(ash_test_strings); |
sky | abc167a | 2016-09-07 00:57:45 | [diff] [blame] | 60 | |
Mitsuru Oshima | 20a852f | 2021-12-02 20:44:31 | [diff] [blame] | 61 | ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( |
62 | path.AppendASCII("ash_test_resources_unscaled.pak"), | ||||
63 | ui::kScaleFactorNone); | ||||
64 | |||||
Mitsuru Oshima | 15732bc9 | 2021-08-16 22:59:31 | [diff] [blame] | 65 | if (ui::ResourceBundle::IsScaleFactorSupported(ui::k100Percent)) { |
sky | abc167a | 2016-09-07 00:57:45 | [diff] [blame] | 66 | base::FilePath ash_test_resources_100 = |
Scott Violet | e9d8df754 | 2018-12-18 16:19:03 | [diff] [blame] | 67 | path.AppendASCII("ash_test_resources_100_percent.pak"); |
sky | abc167a | 2016-09-07 00:57:45 | [diff] [blame] | 68 | ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( |
Mitsuru Oshima | 15732bc9 | 2021-08-16 22:59:31 | [diff] [blame] | 69 | ash_test_resources_100, ui::k100Percent); |
sky | abc167a | 2016-09-07 00:57:45 | [diff] [blame] | 70 | } |
Mitsuru Oshima | 15732bc9 | 2021-08-16 22:59:31 | [diff] [blame] | 71 | if (ui::ResourceBundle::IsScaleFactorSupported(ui::k200Percent)) { |
sky | abc167a | 2016-09-07 00:57:45 | [diff] [blame] | 72 | base::FilePath ash_test_resources_200 = |
73 | path.Append(FILE_PATH_LITERAL("ash_test_resources_200_percent.pak")); | ||||
74 | ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( | ||||
Mitsuru Oshima | 15732bc9 | 2021-08-16 22:59:31 | [diff] [blame] | 75 | ash_test_resources_200, ui::k200Percent); |
sky | abc167a | 2016-09-07 00:57:45 | [diff] [blame] | 76 | } |
[email protected] | 2b99f8c | 2011-10-11 19:42:24 | [diff] [blame] | 77 | } |
78 | |||||
sky | ecd78dba | 2017-02-15 21:16:43 | [diff] [blame] | 79 | void AshTestSuite::Shutdown() { |
sadrul | 578205fa | 2016-04-11 22:43:56 | [diff] [blame] | 80 | env_.reset(); |
[email protected] | 2b99f8c | 2011-10-11 19:42:24 | [diff] [blame] | 81 | ui::ResourceBundle::CleanupSharedInstance(); |
[email protected] | 2b99f8c | 2011-10-11 19:42:24 | [diff] [blame] | 82 | base::TestSuite::Shutdown(); |
83 | } | ||||
[email protected] | 6377a00 | 2011-11-10 20:26:47 | [diff] [blame] | 84 | |
[email protected] | 55f59335 | 2011-12-24 05:42:46 | [diff] [blame] | 85 | } // namespace ash |