OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/test/platform_test_helper.h" | 5 #include "ui/views/test/platform_test_helper.h" |
6 | 6 |
7 #include "base/path_service.h" | 7 #include "base/command_line.h" |
8 #include "mojo/shell/public/cpp/application_test_base.h" | 8 #include "mojo/shell/background/background_shell.h" |
9 #include "mojo/shell/public/cpp/shell.h" | 9 #include "mojo/shell/public/cpp/application_impl.h" |
10 #include "ui/aura/env.h" | 10 #include "mojo/shell/public/cpp/shell_client.h" |
11 #include "ui/base/resource/resource_bundle.h" | |
12 #include "ui/base/ui_base_paths.h" | |
13 #include "ui/gl/test/gl_surface_test_support.h" | |
14 #include "ui/views/mus/window_manager_connection.h" | 11 #include "ui/views/mus/window_manager_connection.h" |
| 12 #include "url/gurl.h" |
15 | 13 |
16 namespace views { | 14 namespace views { |
17 namespace { | 15 namespace { |
18 | 16 |
| 17 class DefaultShellClient : public mojo::ShellClient { |
| 18 public: |
| 19 DefaultShellClient() {} |
| 20 ~DefaultShellClient() override {} |
| 21 |
| 22 private: |
| 23 DISALLOW_COPY_AND_ASSIGN(DefaultShellClient); |
| 24 }; |
| 25 |
19 class PlatformTestHelperMus : public PlatformTestHelper { | 26 class PlatformTestHelperMus : public PlatformTestHelper { |
20 public: | 27 public: |
21 PlatformTestHelperMus() { | 28 PlatformTestHelperMus() { |
22 gfx::GLSurfaceTestSupport::InitializeOneOff(); | 29 // Force the new edk. |
| 30 base::CommandLine::ForCurrentProcess()->AppendSwitch("use-new-edk"); |
23 | 31 |
24 // TODO(sky): We really shouldn't need to configure ResourceBundle. | 32 background_shell_.reset(new mojo::shell::BackgroundShell); |
25 ui::RegisterPathProvider(); | 33 background_shell_->Init(); |
26 base::FilePath ui_test_pak_path; | 34 shell_client_.reset(new DefaultShellClient); |
27 CHECK(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); | 35 app_.reset(new mojo::ApplicationImpl( |
28 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); | 36 shell_client_.get(), |
29 aura::Env::CreateInstance(true); | 37 background_shell_->CreateApplication(GURL("mojo://test-app")))); |
30 | 38 app_->WaitForInitialize(); |
31 mojo_test_helper_.reset(new mojo::test::TestHelper(nullptr)); | |
32 // ui/views/mus requires a WindowManager running, for now use the desktop | 39 // ui/views/mus requires a WindowManager running, for now use the desktop |
33 // one. | 40 // one. |
34 mojo_test_helper_->shell()->Connect("mojo:desktop_wm"); | 41 app_->Connect("mojo:desktop_wm"); |
35 WindowManagerConnection::Create(mojo_test_helper_->shell()); | 42 WindowManagerConnection::Create(app_.get()); |
36 } | 43 } |
37 | 44 |
38 ~PlatformTestHelperMus() override { | 45 ~PlatformTestHelperMus() override { |
39 mojo_test_helper_.reset(nullptr); | 46 WindowManagerConnection::Reset(); |
40 aura::Env::DeleteInstance(); | 47 // |app_| has a reference to us, destroy it while we are still valid. |
41 ui::ResourceBundle::CleanupSharedInstance(); | 48 app_.reset(); |
42 } | 49 } |
43 | 50 |
44 private: | 51 private: |
45 scoped_ptr<mojo::test::TestHelper> mojo_test_helper_; | 52 scoped_ptr<mojo::shell::BackgroundShell> background_shell_; |
| 53 scoped_ptr<mojo::ApplicationImpl> app_; |
| 54 scoped_ptr<DefaultShellClient> shell_client_; |
46 | 55 |
47 DISALLOW_COPY_AND_ASSIGN(PlatformTestHelperMus); | 56 DISALLOW_COPY_AND_ASSIGN(PlatformTestHelperMus); |
48 }; | 57 }; |
49 | 58 |
50 } // namespace | 59 } // namespace |
51 | 60 |
52 // static | 61 // static |
53 scoped_ptr<PlatformTestHelper> PlatformTestHelper::Create() { | 62 scoped_ptr<PlatformTestHelper> PlatformTestHelper::Create() { |
54 return make_scoped_ptr(new PlatformTestHelperMus); | 63 return make_scoped_ptr(new PlatformTestHelperMus); |
55 } | 64 } |
56 | 65 |
57 } // namespace views | 66 } // namespace views |
OLD | NEW |