| OLD | NEW |
| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "mojo/public/cpp/bindings/allocation_scope.h" | 13 #include "mojo/public/cpp/bindings/allocation_scope.h" |
| 14 #include "mojo/public/cpp/environment/environment.h" | 14 #include "mojo/public/cpp/environment/environment.h" |
| 15 #include "mojo/services/public/cpp/view_manager/util.h" |
| 15 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" | 16 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" |
| 16 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" | 17 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
| 17 #include "mojo/shell/shell_test_helper.h" | 18 #include "mojo/shell/shell_test_helper.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 namespace mojo { | 21 namespace mojo { |
| 21 namespace services { | 22 namespace services { |
| 22 namespace view_manager { | 23 namespace view_manager { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 base::RunLoop* current_run_loop = NULL; | 27 base::RunLoop* current_run_loop = NULL; |
| 27 | 28 |
| 28 uint16_t FirstIdFromTransportId(uint32_t id) { | |
| 29 return static_cast<uint16_t>((id >> 16) & 0xFFFF); | |
| 30 } | |
| 31 | |
| 32 uint16_t SecondIdFromTransportId(uint32_t id) { | |
| 33 return static_cast<uint16_t>(id & 0xFFFF); | |
| 34 } | |
| 35 | |
| 36 // Sets |current_run_loop| and runs it. It is expected that someone else quits | 29 // Sets |current_run_loop| and runs it. It is expected that someone else quits |
| 37 // the loop. | 30 // the loop. |
| 38 void DoRunLoop() { | 31 void DoRunLoop() { |
| 39 base::RunLoop run_loop; | 32 base::RunLoop run_loop; |
| 40 current_run_loop = &run_loop; | 33 current_run_loop = &run_loop; |
| 41 current_run_loop->Run(); | 34 current_run_loop->Run(); |
| 42 current_run_loop = NULL; | 35 current_run_loop = NULL; |
| 43 } | 36 } |
| 44 | 37 |
| 45 // Converts |id| into a string. | 38 // Converts |id| into a string. |
| 46 std::string NodeIdToString(TransportNodeId id) { | 39 std::string NodeIdToString(TransportNodeId id) { |
| 47 return (id == 0) ? "null" : | 40 return (id == 0) ? "null" : |
| 48 base::StringPrintf("%d,%d", FirstIdFromTransportId(id), | 41 base::StringPrintf("%d,%d", HiWord(id), LoWord(id)); |
| 49 SecondIdFromTransportId(id)); | |
| 50 } | 42 } |
| 51 | 43 |
| 52 // Boolean callback. Sets |result_cache| to the value of |result| and quits | 44 // Boolean callback. Sets |result_cache| to the value of |result| and quits |
| 53 // the run loop. | 45 // the run loop. |
| 54 void BooleanCallback(bool* result_cache, bool result) { | 46 void BooleanCallback(bool* result_cache, bool result) { |
| 55 *result_cache = result; | 47 *result_cache = result; |
| 56 current_run_loop->Quit(); | 48 current_run_loop->Quit(); |
| 57 } | 49 } |
| 58 | 50 |
| 59 struct TestNode { | 51 struct TestNode { |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes); | 621 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes); |
| 630 ASSERT_EQ(2u, nodes.size()); | 622 ASSERT_EQ(2u, nodes.size()); |
| 631 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); | 623 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); |
| 632 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); | 624 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); |
| 633 } | 625 } |
| 634 } | 626 } |
| 635 | 627 |
| 636 } // namespace view_manager | 628 } // namespace view_manager |
| 637 } // namespace services | 629 } // namespace services |
| 638 } // namespace mojo | 630 } // namespace mojo |
| OLD | NEW |