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

Side by Side Diff: sky/tools/tester/tester.cc

Issue 702603005: Add a sketch of a test_perf script (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« sky/tools/test_perf ('K') | « sky/tools/tester/test_harness.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <iostream>
6 #include "base/bind.h"
7 #include "base/memory/weak_ptr.h"
5 #include "mojo/application/application_runner_chromium.h" 8 #include "mojo/application/application_runner_chromium.h"
6 #include "mojo/public/c/system/main.h" 9 #include "mojo/public/c/system/main.h"
7 #include "mojo/public/cpp/application/application_delegate.h" 10 #include "mojo/public/cpp/application/application_delegate.h"
8 #include "mojo/public/cpp/application/application_impl.h" 11 #include "mojo/public/cpp/application/application_impl.h"
9 #include "mojo/public/cpp/application/connect.h" 12 #include "mojo/public/cpp/application/connect.h"
10 #include "mojo/public/cpp/application/service_provider_impl.h" 13 #include "mojo/public/cpp/application/service_provider_impl.h"
11 #include "mojo/services/public/cpp/view_manager/view_manager.h" 14 #include "mojo/services/public/cpp/view_manager/view_manager.h"
12 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 15 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
13 #include "mojo/services/public/cpp/view_manager/view_observer.h" 16 #include "mojo/services/public/cpp/view_manager/view_observer.h"
14 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" 17 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
15 #include "mojo/services/window_manager/window_manager_app.h" 18 #include "mojo/services/window_manager/window_manager_app.h"
16 #include "mojo/services/window_manager/window_manager_delegate.h" 19 #include "mojo/services/window_manager/window_manager_delegate.h"
17 #include "sky/tools/tester/test_harness.h" 20 #include "sky/tools/tester/test_runner.h"
18 21
19 namespace sky { 22 namespace sky {
20 namespace tester { 23 namespace tester {
24 namespace {
25
26 std::string WaitForURL() {
27 std::string url;
28 std::cin >> url;
29 return url;
30 }
31
32 } // namespace
21 33
22 class SkyTester : public mojo::ApplicationDelegate, 34 class SkyTester : public mojo::ApplicationDelegate,
23 public mojo::ViewManagerDelegate, 35 public mojo::ViewManagerDelegate,
24 public mojo::WindowManagerDelegate, 36 public mojo::WindowManagerDelegate,
25 public mojo::ViewObserver { 37 public mojo::ViewObserver,
38 public TestRunnerClient {
26 public: 39 public:
27 SkyTester() 40 SkyTester()
28 : window_manager_app_(new mojo::WindowManagerApp(this, this)), 41 : window_manager_app_(new mojo::WindowManagerApp(this, this)),
29 view_manager_(NULL), 42 view_manager_(NULL),
30 root_(NULL), 43 root_(NULL),
31 content_(NULL) {} 44 content_(NULL),
45 weak_ptr_factory_(this) {}
32 virtual ~SkyTester() {} 46 virtual ~SkyTester() {}
33 47
34 private: 48 private:
35 // Overridden from mojo::ApplicationDelegate: 49 // Overridden from mojo::ApplicationDelegate:
36 virtual void Initialize(mojo::ApplicationImpl* impl) override { 50 virtual void Initialize(mojo::ApplicationImpl* impl) override {
37 window_manager_app_->Initialize(impl); 51 window_manager_app_->Initialize(impl);
52
53 if (impl->args().size() >= 2)
54 url_from_args_ = impl->args()[1];
38 } 55 }
39 virtual bool ConfigureIncomingConnection( 56 virtual bool ConfigureIncomingConnection(
40 mojo::ApplicationConnection* connection) override { 57 mojo::ApplicationConnection* connection) override {
41 window_manager_app_->ConfigureIncomingConnection(connection); 58 window_manager_app_->ConfigureIncomingConnection(connection);
42 return true; 59 return true;
43 } 60 }
44 61
45 // Overridden from mojo::ViewManagerDelegate: 62 // Overridden from mojo::ViewManagerDelegate:
46 virtual void OnEmbed( 63 virtual void OnEmbed(
47 mojo::ViewManager* view_manager, 64 mojo::ViewManager* view_manager,
48 mojo::View* root, 65 mojo::View* root,
49 mojo::ServiceProviderImpl* exported_services, 66 mojo::ServiceProviderImpl* exported_services,
50 scoped_ptr<mojo::ServiceProvider> remote_service_provider) override { 67 scoped_ptr<mojo::ServiceProvider> remote_service_provider) override {
51 view_manager_ = view_manager; 68 view_manager_ = view_manager;
52 root_ = root; 69 root_ = root;
53 root_->AddObserver(this); 70 root_->AddObserver(this);
54 71
55 content_ = mojo::View::Create(view_manager_); 72 content_ = mojo::View::Create(view_manager_);
56 content_->SetBounds(root_->bounds()); 73 content_->SetBounds(root_->bounds());
57 root_->AddChild(content_); 74 root_->AddChild(content_);
58 75
59 test_harness_.reset(new TestHarness(content_)); 76 std::cout << "#READY\n";
60 test_harness_->ScheduleRun(); 77 std::cout.flush();
78 ScheduleRun();
61 } 79 }
62 80
63 // Overridden from WindowManagerDelegate: 81 // Overridden from WindowManagerDelegate:
64 virtual void Embed( 82 virtual void Embed(
65 const mojo::String& url, 83 const mojo::String& url,
66 mojo::InterfaceRequest<mojo::ServiceProvider> service_provider) override { 84 mojo::InterfaceRequest<mojo::ServiceProvider> service_provider) override {
67 } 85 }
68 86
69 virtual void OnViewManagerDisconnected( 87 virtual void OnViewManagerDisconnected(
70 mojo::ViewManager* view_manager) override { 88 mojo::ViewManager* view_manager) override {
71 view_manager_ = NULL; 89 view_manager_ = NULL;
72 root_ = NULL; 90 root_ = NULL;
73 } 91 }
74 92
75 virtual void OnViewDestroyed(mojo::View* view) override { 93 virtual void OnViewDestroyed(mojo::View* view) override {
76 view->RemoveObserver(this); 94 view->RemoveObserver(this);
77 } 95 }
78 96
79 virtual void OnViewBoundsChanged(mojo::View* view, 97 virtual void OnViewBoundsChanged(mojo::View* view,
80 const mojo::Rect& old_bounds, 98 const mojo::Rect& old_bounds,
81 const mojo::Rect& new_bounds) override { 99 const mojo::Rect& new_bounds) override {
82 content_->SetBounds(new_bounds); 100 content_->SetBounds(new_bounds);
83 } 101 }
84 102
103 void ScheduleRun() {
104 base::MessageLoop::current()->PostTask(FROM_HERE,
105 base::Bind(&SkyTester::Run, weak_ptr_factory_.GetWeakPtr()));
106 }
107
108 void Run() {
109 DCHECK(!test_runner_);
110 std::string url = url_from_args_.length() ? url_from_args_ : WaitForURL();
111 test_runner_.reset(new TestRunner(this, content_, url));
112 }
113
114 void OnTestComplete() override {
115 test_runner_.reset();
116 if (url_from_args_.length())
117 exit(0);
118 ScheduleRun();
119 }
120
85 scoped_ptr<mojo::WindowManagerApp> window_manager_app_; 121 scoped_ptr<mojo::WindowManagerApp> window_manager_app_;
86 122
123 std::string url_from_args_;
124
87 mojo::ViewManager* view_manager_; 125 mojo::ViewManager* view_manager_;
88 mojo::View* root_; 126 mojo::View* root_;
89 mojo::View* content_; 127 mojo::View* content_;
90 scoped_ptr<TestHarness> test_harness_; 128
129 scoped_ptr<TestRunner> test_runner_;
130
131 base::WeakPtrFactory<SkyTester> weak_ptr_factory_;
91 132
92 DISALLOW_COPY_AND_ASSIGN(SkyTester); 133 DISALLOW_COPY_AND_ASSIGN(SkyTester);
93 }; 134 };
94 135
95 } // namespace tester 136 } // namespace tester
96 } // namespace examples 137 } // namespace examples
97 138
98 MojoResult MojoMain(MojoHandle shell_handle) { 139 MojoResult MojoMain(MojoHandle shell_handle) {
99 mojo::ApplicationRunnerChromium runner(new sky::tester::SkyTester); 140 mojo::ApplicationRunnerChromium runner(new sky::tester::SkyTester);
100 return runner.Run(shell_handle); 141 return runner.Run(shell_handle);
101 } 142 }
OLDNEW
« sky/tools/test_perf ('K') | « sky/tools/tester/test_harness.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698