OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <utility> | 6 #include <utility> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
11 #include "mojo/public/c/environment/logger.h" | 11 #include "mojo/public/c/environment/logger.h" |
12 #include "mojo/public/cpp/application/application_impl.h" | 12 #include "mojo/public/cpp/application/application_impl.h" |
13 #include "mojo/public/cpp/application/application_test_base.h" | 13 #include "mojo/public/cpp/application/application_test_base.h" |
| 14 #include "mojo/public/cpp/application/connection_context.h" |
14 #include "mojo/public/cpp/system/time.h" | 15 #include "mojo/public/cpp/system/time.h" |
15 #include "mojo/services/log/interfaces/entry.mojom.h" | 16 #include "mojo/services/log/interfaces/entry.mojom.h" |
16 #include "mojo/services/log/interfaces/log.mojom.h" | 17 #include "mojo/services/log/interfaces/log.mojom.h" |
17 #include "services/log/log_impl.h" | 18 #include "services/log/log_impl.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 log { | 22 namespace log { |
22 namespace { | 23 namespace { |
23 | 24 |
24 using base::MessageLoop; | 25 using base::MessageLoop; |
25 using LogImplTest = mojo::test::ApplicationTestBase; | 26 using LogImplTest = mojo::test::ApplicationTestBase; |
26 | 27 |
27 // We need to supply a ApplicationConnection to LogImpl::Create(). | 28 // We need to supply a ApplicationConnection to LogImpl::Create(). |
28 class TestApplicationConnection : public ApplicationConnection { | 29 class TestApplicationConnection : public ApplicationConnection { |
29 public: | 30 public: |
| 31 TestApplicationConnection() |
| 32 : connection_context_(ConnectionContext::Type::INCOMING, |
| 33 "mojo:log_impl_unittest", |
| 34 "mojo:log") {} |
| 35 |
| 36 const ConnectionContext& GetConnectionContext() const override { |
| 37 return connection_context_; |
| 38 } |
| 39 |
30 const std::string& GetConnectionURL() override { | 40 const std::string& GetConnectionURL() override { |
31 static std::string kConnectionURL = "mojo:log"; | 41 return connection_context_.connection_url; |
32 return kConnectionURL; | |
33 } | 42 } |
34 | 43 |
35 const std::string& GetRemoteApplicationURL() override { | 44 const std::string& GetRemoteApplicationURL() override { |
36 static std::string kRemoteApplicationURL = "mojo:log_impl_unittest"; | 45 return connection_context_.remote_url; |
37 return kRemoteApplicationURL; | |
38 } | 46 } |
39 | 47 |
40 void SetServiceConnectorForName(ServiceConnector* service_connector, | 48 void SetServiceConnectorForName(ServiceConnector* service_connector, |
41 const std::string& name) override {} | 49 const std::string& name) override {} |
| 50 |
| 51 private: |
| 52 const ConnectionContext connection_context_; |
42 }; | 53 }; |
43 | 54 |
44 // Tests the Log service implementation by calling its AddEntry and verifying | 55 // Tests the Log service implementation by calling its AddEntry and verifying |
45 // the log message that it "prints". | 56 // the log message that it "prints". |
46 TEST_F(LogImplTest, AddEntryOutput) { | 57 TEST_F(LogImplTest, AddEntryOutput) { |
47 std::vector<std::string> messages; | 58 std::vector<std::string> messages; |
48 | 59 |
49 LogPtr log; | 60 LogPtr log; |
50 TestApplicationConnection app_connection; | 61 TestApplicationConnection app_connection; |
51 LogImpl::Create( | 62 LogImpl::Create( |
(...skipping 30 matching lines...) Expand all Loading... |
82 "<mojo:log_impl_unittest> [INFO] file.ext:1: 1234567890", | 93 "<mojo:log_impl_unittest> [INFO] file.ext:1: 1234567890", |
83 "<mojo:log_impl_unittest> [INFO] 1234567890", | 94 "<mojo:log_impl_unittest> [INFO] 1234567890", |
84 "<mojo:log_impl_unittest> [INFO] <no message>", | 95 "<mojo:log_impl_unittest> [INFO] <no message>", |
85 }; | 96 }; |
86 EXPECT_EQ(kExpectedMessages, messages); | 97 EXPECT_EQ(kExpectedMessages, messages); |
87 } | 98 } |
88 | 99 |
89 } // namespace | 100 } // namespace |
90 } // namespace log | 101 } // namespace log |
91 } // namespace mojo | 102 } // namespace mojo |
OLD | NEW |