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

Side by Side Diff: mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc

Issue 317433004: Get view manager client lib unit test harness to run again. Does not get any individual tests worki… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 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 | Annotate | Revision Log
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 "mojo/services/public/cpp/view_manager/view_manager.h" 5 #include "mojo/services/public/cpp/view_manager/view_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "mojo/public/cpp/application/application.h"
10 #include "mojo/service_manager/service_manager.h"
9 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h" 11 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h"
10 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" 12 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h"
11 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" 13 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h"
12 #include "mojo/services/public/cpp/view_manager/util.h" 14 #include "mojo/services/public/cpp/view_manager/util.h"
13 #include "mojo/services/public/cpp/view_manager/view.h" 15 #include "mojo/services/public/cpp/view_manager/view.h"
14 #include "mojo/services/public/cpp/view_manager/view_observer.h" 16 #include "mojo/services/public/cpp/view_manager/view_observer.h"
15 #include "mojo/services/public/cpp/view_manager/view_tree_node_observer.h" 17 #include "mojo/services/public/cpp/view_manager/view_tree_node_observer.h"
16 #include "mojo/shell/shell_test_helper.h" 18 #include "mojo/shell/shell_test_helper.h"
17 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
18 20
19 namespace mojo { 21 namespace mojo {
20 namespace view_manager { 22 namespace view_manager {
21 namespace { 23 namespace {
22 24
25 const char kTestServiceURL[] = "mojo:test_url";
26
23 base::RunLoop* current_run_loop = NULL; 27 base::RunLoop* current_run_loop = NULL;
24 28
25 void DoRunLoop() { 29 void DoRunLoop() {
26 base::RunLoop run_loop; 30 base::RunLoop run_loop;
27 current_run_loop = &run_loop; 31 current_run_loop = &run_loop;
28 current_run_loop->Run(); 32 current_run_loop->Run();
29 current_run_loop = NULL; 33 current_run_loop = NULL;
30 } 34 }
31 35
32 void QuitRunLoop() { 36 void QuitRunLoop() {
33 current_run_loop->Quit(); 37 current_run_loop->Quit();
34 } 38 }
35 39
36 void QuitRunLoopOnChangesAcked() { 40 void QuitRunLoopOnChangesAcked() {
37 QuitRunLoop(); 41 QuitRunLoop();
38 } 42 }
39 43
40 void WaitForAllChangesToBeAcked(ViewManager* manager) { 44 void WaitForAllChangesToBeAcked(ViewManager* manager) {
41 ViewManagerPrivate(manager).synchronizer()->set_changes_acked_callback( 45 ViewManagerPrivate(manager).synchronizer()->set_changes_acked_callback(
42 base::Bind(&QuitRunLoopOnChangesAcked)); 46 base::Bind(&QuitRunLoopOnChangesAcked));
43 DoRunLoop(); 47 DoRunLoop();
44 ViewManagerPrivate(manager).synchronizer()->ClearChangesAckedCallback(); 48 ViewManagerPrivate(manager).synchronizer()->ClearChangesAckedCallback();
45 } 49 }
46 50
51 // Used with IViewManager::Connect(). Creates a TestViewManagerClientConnection,
52 // which creates and owns the ViewManagerProxy.
53 class ConnectServiceLoader : public ServiceLoader {
54 public:
55 explicit ConnectServiceLoader(base::Callback<void(ViewManager*)> callback)
56 : callback_(callback) {}
57 virtual ~ConnectServiceLoader() {}
58
59 // ServiceLoader:
60 virtual void LoadService(ServiceManager* manager,
61 const GURL& url,
62 ScopedMessagePipeHandle shell_handle) OVERRIDE {
63 scoped_ptr<Application> app(new Application(shell_handle.Pass()));
64 ViewManager::Create(app.get(), callback_);
65 apps_.push_back(app.release());
66 }
67 virtual void OnServiceError(ServiceManager* manager,
68 const GURL& url) OVERRIDE {
69 }
70
71 private:
72 ScopedVector<Application> apps_;
73 base::Callback<void(ViewManager*)> callback_;
74
75 DISALLOW_COPY_AND_ASSIGN(ConnectServiceLoader);
76 };
77
47 class ActiveViewChangedObserver : public ViewTreeNodeObserver { 78 class ActiveViewChangedObserver : public ViewTreeNodeObserver {
48 public: 79 public:
49 explicit ActiveViewChangedObserver(ViewTreeNode* node) 80 explicit ActiveViewChangedObserver(ViewTreeNode* node)
50 : node_(node) {} 81 : node_(node) {}
51 virtual ~ActiveViewChangedObserver() {} 82 virtual ~ActiveViewChangedObserver() {}
52 83
53 private: 84 private:
54 // Overridden from ViewTreeNodeObserver: 85 // Overridden from ViewTreeNodeObserver:
55 virtual void OnNodeActiveViewChange(ViewTreeNode* node, 86 virtual void OnNodeActiveViewChange(ViewTreeNode* node,
56 View* old_view, 87 View* old_view,
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 300 }
270 301
271 void DestroyViewManager1() { 302 void DestroyViewManager1() {
272 // view_manager_1_.reset(); 303 // view_manager_1_.reset();
273 } 304 }
274 305
275 private: 306 private:
276 // Overridden from testing::Test: 307 // Overridden from testing::Test:
277 virtual void SetUp() OVERRIDE { 308 virtual void SetUp() OVERRIDE {
278 test_helper_.Init(); 309 test_helper_.Init();
310 ConnectServiceLoader* loader =
311 new ConnectServiceLoader(
312 base::Bind(&ViewManagerTest::OnViewManagerLoaded,
313 base::Unretained(this)));
314 test_helper_.SetLoaderForURL(
315 scoped_ptr<ServiceLoader>(loader),
316 GURL(kTestServiceURL));
317
318 ConnectToService(test_helper_.service_provider(),
319 "mojo:mojo_view_manager",
320 &view_manager_init_);
321 ASSERT_TRUE(ViewManagerInitConnect(view_manager_init_.get(),
322 kTestServiceURL));
323 }
324
325 void ViewManagerInitConnectCallback(bool* result_cache,
326 bool result) {
327 *result_cache = result;
328 }
329
330 bool ViewManagerInitConnect(IViewManagerInit* view_manager_init,
331 const std::string& url) {
332 bool result = false;
333 view_manager_init->Connect(
334 url,
335 base::Bind(&ViewManagerTest::ViewManagerInitConnectCallback,
336 base::Unretained(this), &result));
337 init_loop_.Run();
338 return result;
339 }
340
341 void OnViewManagerLoaded(ViewManager* view_manager) {
342 init_loop_.Quit();
279 } 343 }
280 344
281 base::MessageLoop loop_; 345 base::MessageLoop loop_;
346 base::RunLoop init_loop_;
282 shell::ShellTestHelper test_helper_; 347 shell::ShellTestHelper test_helper_;
348 IViewManagerInitPtr view_manager_init_;
283 ViewManager* view_manager_1_; 349 ViewManager* view_manager_1_;
284 ViewManager* view_manager_2_; 350 ViewManager* view_manager_2_;
285 int commit_count_; 351 int commit_count_;
286 352
287 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); 353 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest);
288 }; 354 };
289 355
290 // Base class for helpers that quit the current runloop after a specific tree 356 // Base class for helpers that quit the current runloop after a specific tree
291 // change is observed by a view manager. 357 // change is observed by a view manager.
292 class TreeObserverBase : public ViewTreeNodeObserver { 358 class TreeObserverBase : public ViewTreeNodeObserver {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 return params.receiver == view_manager()->tree() && 395 return params.receiver == view_manager()->tree() &&
330 !params.old_parent && 396 !params.old_parent &&
331 params.new_parent == view_manager()->tree(); 397 params.new_parent == view_manager()->tree();
332 } 398 }
333 399
334 DISALLOW_COPY_AND_ASSIGN(HierarchyChanged_NodeCreatedObserver); 400 DISALLOW_COPY_AND_ASSIGN(HierarchyChanged_NodeCreatedObserver);
335 }; 401 };
336 402
337 // TODO(beng): reenable these once converted to new way of connecting. 403 // TODO(beng): reenable these once converted to new way of connecting.
338 404
405 TEST_F(ViewManagerTest, SetUp) {
406 }
407
339 TEST_F(ViewManagerTest, DISABLED_HierarchyChanged_NodeCreated) { 408 TEST_F(ViewManagerTest, DISABLED_HierarchyChanged_NodeCreated) {
340 HierarchyChanged_NodeCreatedObserver observer(view_manager_2()); 409 HierarchyChanged_NodeCreatedObserver observer(view_manager_2());
341 ViewTreeNode* node1 = ViewTreeNode::Create(view_manager_1()); 410 ViewTreeNode* node1 = ViewTreeNode::Create(view_manager_1());
342 view_manager_1()->tree()->AddChild(node1); 411 view_manager_1()->tree()->AddChild(node1);
343 DoRunLoop(); 412 DoRunLoop();
344 413
345 EXPECT_EQ(view_manager_2()->tree()->children().front()->id(), node1->id()); 414 EXPECT_EQ(view_manager_2()->tree()->children().front()->id(), node1->id());
346 } 415 }
347 416
348 // Quits the current runloop when the root is notified about a node moved from 417 // Quits the current runloop when the root is notified about a node moved from
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 // Node should not have been destroyed. 699 // Node should not have been destroyed.
631 EXPECT_TRUE(tracker2.is_valid()); 700 EXPECT_TRUE(tracker2.is_valid());
632 701
633 NodeTracker tracker1(node1); 702 NodeTracker tracker1(node1);
634 node1->Destroy(); 703 node1->Destroy();
635 EXPECT_FALSE(tracker1.is_valid()); 704 EXPECT_FALSE(tracker1.is_valid());
636 } 705 }
637 706
638 } // namespace view_manager 707 } // namespace view_manager
639 } // namespace mojo 708 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/public/cpp/view_manager/tests/DEPS ('k') | mojo/services/public/cpp/view_manager/view_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698