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

Side by Side Diff: ios/web/webui/mojo_facade_unittest.mm

Issue 2847743003: Eliminate InterfaceRegistry (Closed)
Patch Set: . Created 3 years, 7 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
OLDNEW
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"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #import "base/test/ios/wait_util.h" 12 #import "base/test/ios/wait_util.h"
13 #include "ios/web/public/test/web_test.h" 13 #include "ios/web/public/test/web_test.h"
14 #import "ios/web/public/web_state/js/crw_js_injection_evaluator.h" 14 #import "ios/web/public/web_state/js/crw_js_injection_evaluator.h"
15 #include "ios/web/test/mojo_test.mojom.h" 15 #include "ios/web/test/mojo_test.mojom.h"
16 #include "ios/web/web_state/web_state_impl.h"
16 #include "mojo/public/cpp/bindings/binding_set.h" 17 #include "mojo/public/cpp/bindings/binding_set.h"
17 #include "services/service_manager/public/cpp/identity.h" 18 #include "services/service_manager/public/cpp/identity.h"
18 #include "services/service_manager/public/cpp/interface_factory.h" 19 #include "services/service_manager/public/cpp/interface_factory.h"
19 #include "services/service_manager/public/cpp/interface_registry.h"
20 #import "testing/gtest_mac.h" 20 #import "testing/gtest_mac.h"
21 #import "third_party/ocmock/OCMock/OCMock.h" 21 #import "third_party/ocmock/OCMock/OCMock.h"
22 22
23 namespace web { 23 namespace web {
24 24
25 namespace { 25 namespace {
26 26
27 // Serializes the given |object| to JSON string. 27 // Serializes the given |object| to JSON string.
28 std::string GetJson(id object) { 28 std::string GetJson(id object) {
29 NSData* json_as_data = 29 NSData* json_as_data =
(...skipping 24 matching lines...) Expand all
54 void Create(const service_manager::Identity& remote_identity, 54 void Create(const service_manager::Identity& remote_identity,
55 mojo::InterfaceRequest<TestUIHandlerMojo> request) override {} 55 mojo::InterfaceRequest<TestUIHandlerMojo> request) override {}
56 }; 56 };
57 57
58 } // namespace 58 } // namespace
59 59
60 // A test fixture to test MojoFacade class. 60 // A test fixture to test MojoFacade class.
61 class MojoFacadeTest : public WebTest { 61 class MojoFacadeTest : public WebTest {
62 protected: 62 protected:
63 MojoFacadeTest() { 63 MojoFacadeTest() {
64 interface_registry_.reset( 64 interface_provider_ = base::MakeUnique<WebStateInterfaceProvider>();
65 new service_manager::InterfaceRegistry(std::string())); 65 interface_provider_->registry()->AddInterface(&ui_handler_factory_);
66 interface_registry_->AddInterface(&ui_handler_factory_);
67 evaluator_.reset([[OCMockObject 66 evaluator_.reset([[OCMockObject
68 mockForProtocol:@protocol(CRWJSInjectionEvaluator)] retain]); 67 mockForProtocol:@protocol(CRWJSInjectionEvaluator)] retain]);
69 facade_.reset(new MojoFacade( 68 facade_.reset(new MojoFacade(
70 interface_registry_.get(), 69 interface_provider_.get(),
71 static_cast<id<CRWJSInjectionEvaluator>>(evaluator_.get()))); 70 static_cast<id<CRWJSInjectionEvaluator>>(evaluator_.get())));
72 } 71 }
73 72
74 OCMockObject* evaluator() { return evaluator_.get(); } 73 OCMockObject* evaluator() { return evaluator_.get(); }
75 MojoFacade* facade() { return facade_.get(); } 74 MojoFacade* facade() { return facade_.get(); }
76 75
77 private: 76 private:
78 TestUIHandlerFactory ui_handler_factory_; 77 TestUIHandlerFactory ui_handler_factory_;
79 std::unique_ptr<service_manager::InterfaceRegistry> interface_registry_; 78 std::unique_ptr<WebStateInterfaceProvider> interface_provider_;
80 base::scoped_nsobject<OCMockObject> evaluator_; 79 base::scoped_nsobject<OCMockObject> evaluator_;
81 std::unique_ptr<MojoFacade> facade_; 80 std::unique_ptr<MojoFacade> facade_;
82 }; 81 };
83 82
84 // Tests connecting to existing interface and closing the handle. 83 // Tests connecting to existing interface and closing the handle.
85 TEST_F(MojoFacadeTest, GetInterfaceAndCloseHandle) { 84 TEST_F(MojoFacadeTest, GetInterfaceAndCloseHandle) {
86 // Bind to the interface. 85 // Bind to the interface.
87 NSDictionary* connect = @{ 86 NSDictionary* connect = @{
88 @"name" : @"interface_provider.getInterface", 87 @"name" : @"interface_provider.getInterface",
89 @"args" : @{ 88 @"args" : @{
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 NSDictionary* message = GetObject(facade()->HandleMojoMessage(GetJson(read))); 282 NSDictionary* message = GetObject(facade()->HandleMojoMessage(GetJson(read)));
284 EXPECT_TRUE([message isKindOfClass:[NSDictionary class]]); 283 EXPECT_TRUE([message isKindOfClass:[NSDictionary class]]);
285 EXPECT_TRUE(message); 284 EXPECT_TRUE(message);
286 NSArray* expected_message = @[ @9, @2, @216 ]; // 2008 does not fit 8-bit. 285 NSArray* expected_message = @[ @9, @2, @216 ]; // 2008 does not fit 8-bit.
287 EXPECT_NSEQ(expected_message, message[@"buffer"]); 286 EXPECT_NSEQ(expected_message, message[@"buffer"]);
288 EXPECT_FALSE([message[@"handles"] count]); 287 EXPECT_FALSE([message[@"handles"] count]);
289 EXPECT_EQ(MOJO_RESULT_OK, [message[@"result"] unsignedIntValue]); 288 EXPECT_EQ(MOJO_RESULT_OK, [message[@"result"] unsignedIntValue]);
290 } 289 }
291 290
292 } // namespace web 291 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698