Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: ui/views/mus/platform_test_helper_mus.cc

Issue 1972363002: mus: Add views_mus_interactive_ui_tests target (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: similarity Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h"
6 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
7 #include "base/run_loop.h" 8 #include "base/run_loop.h"
8 #include "services/shell/background/background_shell.h" 9 #include "services/shell/background/background_shell.h"
9 #include "services/shell/background/tests/test_catalog_store.h" 10 #include "services/shell/background/tests/test_catalog_store.h"
10 #include "services/shell/public/cpp/connector.h" 11 #include "services/shell/public/cpp/connector.h"
11 #include "services/shell/public/cpp/shell_client.h" 12 #include "services/shell/public/cpp/shell_client.h"
12 #include "services/shell/public/cpp/shell_connection.h" 13 #include "services/shell/public/cpp/shell_connection.h"
13 #include "ui/aura/env.h" 14 #include "ui/aura/env.h"
14 #include "ui/views/mus/window_manager_connection.h" 15 #include "ui/views/mus/window_manager_connection.h"
15 #include "ui/views/test/platform_test_helper.h" 16 #include "ui/views/test/platform_test_helper.h"
16 #include "ui/views/views_delegate.h" 17 #include "ui/views/views_delegate.h"
17 18
18 using shell::BackgroundShell; 19 using shell::BackgroundShell;
19 20
20 namespace views { 21 namespace views {
21 namespace { 22 namespace {
22 23
23 const char kTestName[] = "exe:views_mus_unittests";
24
25 class DefaultShellClient : public shell::ShellClient { 24 class DefaultShellClient : public shell::ShellClient {
26 public: 25 public:
27 DefaultShellClient() {} 26 DefaultShellClient() {}
28 ~DefaultShellClient() override {} 27 ~DefaultShellClient() override {}
29 28
30 private: 29 private:
31 DISALLOW_COPY_AND_ASSIGN(DefaultShellClient); 30 DISALLOW_COPY_AND_ASSIGN(DefaultShellClient);
32 }; 31 };
33 32
34 class PlatformTestHelperMus : public PlatformTestHelper { 33 class PlatformTestHelperMus : public PlatformTestHelper {
35 public: 34 public:
36 PlatformTestHelperMus() { 35 PlatformTestHelperMus() {
37 background_shell_.reset(new BackgroundShell); 36 background_shell_.reset(new BackgroundShell);
38 background_shell_->Init(nullptr); 37 background_shell_->Init(nullptr);
39 shell_client_.reset(new DefaultShellClient); 38 shell_client_.reset(new DefaultShellClient);
40 shell_connection_.reset(new shell::ShellConnection( 39 shell_connection_.reset(new shell::ShellConnection(
41 shell_client_.get(), 40 shell_client_.get(),
42 background_shell_->CreateShellClientRequest(kTestName))); 41 background_shell_->CreateShellClientRequest(GetTestName())));
43 42
44 // TODO(rockot): Remove this RunLoop. http://crbug.com/594852. 43 // TODO(rockot): Remove this RunLoop. http://crbug.com/594852.
45 base::RunLoop wait_loop; 44 base::RunLoop wait_loop;
46 shell_connection_->set_initialize_handler(wait_loop.QuitClosure()); 45 shell_connection_->set_initialize_handler(wait_loop.QuitClosure());
47 wait_loop.Run(); 46 wait_loop.Run();
48 47
49 // ui/views/mus requires a WindowManager running, for now use the desktop 48 // ui/views/mus requires a WindowManager running, for now use the desktop
50 // one. 49 // one.
51 shell::Connector* connector = shell_connection_->connector(); 50 shell::Connector* connector = shell_connection_->connector();
52 connector->Connect("mojo:desktop_wm"); 51 connector->Connect("mojo:desktop_wm");
53 WindowManagerConnection::Create(connector, shell_connection_->identity()); 52 WindowManagerConnection::Create(connector, shell_connection_->identity());
54 53
55 // On X we need to reset the ContextFactory before every NativeWidgetMus 54 // On X we need to reset the ContextFactory before every NativeWidgetMus
56 // is created. 55 // is created.
57 // TODO(sad): this is a hack, figure out a better solution. 56 // TODO(sad): this is a hack, figure out a better solution.
58 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( 57 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind(
59 &PlatformTestHelperMus::CreateNativeWidgetMus, base::Unretained(this), 58 &PlatformTestHelperMus::CreateNativeWidgetMus, base::Unretained(this),
60 std::map<std::string, std::vector<uint8_t>>())); 59 std::map<std::string, std::vector<uint8_t>>()));
61 } 60 }
62 61
63 ~PlatformTestHelperMus() override { 62 ~PlatformTestHelperMus() override {
64 WindowManagerConnection::Reset(); 63 WindowManagerConnection::Reset();
65 // |app_| has a reference to us, destroy it while we are still valid. 64 // |app_| has a reference to us, destroy it while we are still valid.
66 shell_connection_.reset(); 65 shell_connection_.reset();
67 } 66 }
68 67
69 bool IsMus() const override { return true; }
70
71 private: 68 private:
72 NativeWidget* CreateNativeWidgetMus( 69 NativeWidget* CreateNativeWidgetMus(
73 const std::map<std::string, std::vector<uint8_t>>& props, 70 const std::map<std::string, std::vector<uint8_t>>& props,
74 const Widget::InitParams& init_params, 71 const Widget::InitParams& init_params,
75 internal::NativeWidgetDelegate* delegate) { 72 internal::NativeWidgetDelegate* delegate) {
76 ui::ContextFactory* factory = aura::Env::GetInstance()->context_factory(); 73 ui::ContextFactory* factory = aura::Env::GetInstance()->context_factory();
77 aura::Env::GetInstance()->set_context_factory(nullptr); 74 aura::Env::GetInstance()->set_context_factory(nullptr);
78 NativeWidget* result = 75 NativeWidget* result =
79 WindowManagerConnection::Get()->CreateNativeWidgetMus( 76 WindowManagerConnection::Get()->CreateNativeWidgetMus(
80 props, init_params, delegate); 77 props, init_params, delegate);
81 aura::Env::GetInstance()->set_context_factory(factory); 78 aura::Env::GetInstance()->set_context_factory(factory);
82 return result; 79 return result;
83 } 80 }
84 81
82 // Returns the name of the test executable, e.g. "exe:views_mus_unittests".
83 std::string GetTestName() {
84 base::FilePath executable = base::CommandLine::ForCurrentProcess()
85 ->GetProgram()
86 .BaseName()
87 .RemoveExtension();
88 return std::string("exe:") + executable.MaybeAsASCII();
89 }
90
85 std::unique_ptr<BackgroundShell> background_shell_; 91 std::unique_ptr<BackgroundShell> background_shell_;
86 std::unique_ptr<shell::ShellConnection> shell_connection_; 92 std::unique_ptr<shell::ShellConnection> shell_connection_;
87 std::unique_ptr<DefaultShellClient> shell_client_; 93 std::unique_ptr<DefaultShellClient> shell_client_;
88 94
89 DISALLOW_COPY_AND_ASSIGN(PlatformTestHelperMus); 95 DISALLOW_COPY_AND_ASSIGN(PlatformTestHelperMus);
90 }; 96 };
91 97
92 } // namespace 98 } // namespace
93 99
94 // static 100 // static
95 std::unique_ptr<PlatformTestHelper> PlatformTestHelper::Create() { 101 std::unique_ptr<PlatformTestHelper> PlatformTestHelper::Create() {
96 return base::WrapUnique(new PlatformTestHelperMus); 102 return base::WrapUnique(new PlatformTestHelperMus);
97 } 103 }
98 104
105 // static
106 bool PlatformTestHelper::IsMus() {
107 return true;
108 }
109
99 } // namespace views 110 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698