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

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

Powered by Google App Engine
This is Rietveld 408576698