OLD | NEW |
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 #import "ios/web/webui/mojo_facade.h" | 5 #import "ios/web/webui/mojo_facade.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #import "base/mac/scoped_nsobject.h" | 9 #import "base/mac/scoped_nsobject.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 // Deserializes the given |json| to an object. | 37 // Deserializes the given |json| to an object. |
38 id GetObject(const std::string& json) { | 38 id GetObject(const std::string& json) { |
39 NSData* json_as_data = | 39 NSData* json_as_data = |
40 [base::SysUTF8ToNSString(json) dataUsingEncoding:NSUTF8StringEncoding]; | 40 [base::SysUTF8ToNSString(json) dataUsingEncoding:NSUTF8StringEncoding]; |
41 return [NSJSONSerialization JSONObjectWithData:json_as_data | 41 return [NSJSONSerialization JSONObjectWithData:json_as_data |
42 options:0 | 42 options:0 |
43 error:nil]; | 43 error:nil]; |
44 } | 44 } |
45 | 45 |
46 // Test mojo handler factory. | 46 // Test mojo handler factory. |
47 class TestUIHandlerFactory : public shell::InterfaceFactory<TestUIHandlerMojo> { | 47 class TestUIHandlerFactory |
| 48 : public service_manager::InterfaceFactory<TestUIHandlerMojo> { |
48 public: | 49 public: |
49 ~TestUIHandlerFactory() override {} | 50 ~TestUIHandlerFactory() override {} |
50 | 51 |
51 private: | 52 private: |
52 // shell::InterfaceFactory overrides. | 53 // service_manager::InterfaceFactory overrides. |
53 void Create(const shell::Identity& remote_identity, | 54 void Create(const service_manager::Identity& remote_identity, |
54 mojo::InterfaceRequest<TestUIHandlerMojo> request) override {} | 55 mojo::InterfaceRequest<TestUIHandlerMojo> request) override {} |
55 }; | 56 }; |
56 | 57 |
57 } // namespace | 58 } // namespace |
58 | 59 |
59 // A test fixture to test MojoFacade class. | 60 // A test fixture to test MojoFacade class. |
60 class MojoFacadeTest : public WebTest { | 61 class MojoFacadeTest : public WebTest { |
61 protected: | 62 protected: |
62 MojoFacadeTest() { | 63 MojoFacadeTest() { |
63 interface_registry_.reset(new shell::InterfaceRegistry); | 64 interface_registry_.reset(new service_manager::InterfaceRegistry); |
64 interface_registry_->AddInterface(&ui_handler_factory_); | 65 interface_registry_->AddInterface(&ui_handler_factory_); |
65 evaluator_.reset([[OCMockObject | 66 evaluator_.reset([[OCMockObject |
66 mockForProtocol:@protocol(CRWJSInjectionEvaluator)] retain]); | 67 mockForProtocol:@protocol(CRWJSInjectionEvaluator)] retain]); |
67 facade_.reset(new MojoFacade( | 68 facade_.reset(new MojoFacade( |
68 interface_registry_.get(), | 69 interface_registry_.get(), |
69 static_cast<id<CRWJSInjectionEvaluator>>(evaluator_.get()))); | 70 static_cast<id<CRWJSInjectionEvaluator>>(evaluator_.get()))); |
70 } | 71 } |
71 | 72 |
72 OCMockObject* evaluator() { return evaluator_.get(); } | 73 OCMockObject* evaluator() { return evaluator_.get(); } |
73 MojoFacade* facade() { return facade_.get(); } | 74 MojoFacade* facade() { return facade_.get(); } |
74 | 75 |
75 private: | 76 private: |
76 TestUIHandlerFactory ui_handler_factory_; | 77 TestUIHandlerFactory ui_handler_factory_; |
77 std::unique_ptr<shell::InterfaceRegistry> interface_registry_; | 78 std::unique_ptr<service_manager::InterfaceRegistry> interface_registry_; |
78 base::scoped_nsobject<OCMockObject> evaluator_; | 79 base::scoped_nsobject<OCMockObject> evaluator_; |
79 std::unique_ptr<MojoFacade> facade_; | 80 std::unique_ptr<MojoFacade> facade_; |
80 }; | 81 }; |
81 | 82 |
82 // Tests connecting to existing interface and closing the handle. | 83 // Tests connecting to existing interface and closing the handle. |
83 TEST_F(MojoFacadeTest, GetInterfaceAndCloseHandle) { | 84 TEST_F(MojoFacadeTest, GetInterfaceAndCloseHandle) { |
84 // Bind to the interface. | 85 // Bind to the interface. |
85 NSDictionary* connect = @{ | 86 NSDictionary* connect = @{ |
86 @"name" : @"interface_provider.getInterface", | 87 @"name" : @"interface_provider.getInterface", |
87 @"args" : @{ | 88 @"args" : @{ |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 NSDictionary* message = GetObject(facade()->HandleMojoMessage(GetJson(read))); | 270 NSDictionary* message = GetObject(facade()->HandleMojoMessage(GetJson(read))); |
270 EXPECT_TRUE([message isKindOfClass:[NSDictionary class]]); | 271 EXPECT_TRUE([message isKindOfClass:[NSDictionary class]]); |
271 EXPECT_TRUE(message); | 272 EXPECT_TRUE(message); |
272 NSArray* expected_message = @[ @9, @2, @216 ]; // 2008 does not fit 8-bit. | 273 NSArray* expected_message = @[ @9, @2, @216 ]; // 2008 does not fit 8-bit. |
273 EXPECT_NSEQ(expected_message, message[@"buffer"]); | 274 EXPECT_NSEQ(expected_message, message[@"buffer"]); |
274 EXPECT_FALSE([message[@"handles"] count]); | 275 EXPECT_FALSE([message[@"handles"] count]); |
275 EXPECT_EQ(MOJO_RESULT_OK, [message[@"result"] unsignedIntValue]); | 276 EXPECT_EQ(MOJO_RESULT_OK, [message[@"result"] unsignedIntValue]); |
276 } | 277 } |
277 | 278 |
278 } // namespace web | 279 } // namespace web |
OLD | NEW |