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

Side by Side Diff: services/resource_coordinator/resource_coordinator_service_unittest.cc

Issue 2798713002: Global Resource Coordinator: Basic service internals (Closed)
Patch Set: Review fixes Created 3 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <memory>
6
7 #include "base/macros.h"
8 #include "base/run_loop.h"
9 #include "mojo/public/cpp/bindings/binding.h"
10 #include "services/resource_coordinator/public/interfaces/coordination_unit_prov ider.mojom.h"
11 #include "services/resource_coordinator/public/interfaces/service_constants.mojo m.h"
12 #include "services/service_manager/public/cpp/service.h"
13 #include "services/service_manager/public/cpp/service_test.h"
14
15 namespace resource_coordinator {
16
17 class ResourceCoordinatorTest : public service_manager::test::ServiceTest,
18 public mojom::PolicyCallback {
19 public:
20 ResourceCoordinatorTest()
21 : service_manager::test::ServiceTest("resource_coordinator_unittests"),
22 binding_(this) {}
23 ~ResourceCoordinatorTest() override {}
24
25 protected:
26 void SetUp() override {
27 service_manager::test::ServiceTest::SetUp();
28 resource_coordinator_connection_ =
29 connector()->Connect(mojom::kServiceName);
30 }
31
32 mojom::PolicyCallbackPtr GetPolicyCallback() {
33 return binding_.CreateInterfacePtrAndBind();
34 }
35
36 void QuitOnPolicyCallback(base::RunLoop* loop) { loop_ = loop; }
37
38 private:
39 // mojom::PolicyCallback:
40 void SetPolicy(resource_coordinator::mojom::PolicyPtr policy) override {
41 loop_->Quit();
42 }
43
44 mojo::Binding<mojom::PolicyCallback> binding_;
45 base::RunLoop* loop_ = nullptr;
46 std::unique_ptr<service_manager::Connection> resource_coordinator_connection_;
47
48 DISALLOW_COPY_AND_ASSIGN(ResourceCoordinatorTest);
49 };
50
51 TEST_F(ResourceCoordinatorTest, ResourceCoordinatorInstantiate) {
52 mojom::CoordinationUnitProviderPtr provider;
53 connector()->BindInterface(mojom::kServiceName, mojo::MakeRequest(&provider));
54
55 CoordinationUnitID new_id(CoordinationUnitType::WEBCONTENTS, "test_id");
56 mojom::CoordinationUnitPtr coordination_unit;
57 provider->CreateCoordinationUnit(mojo::MakeRequest(&coordination_unit),
58 new_id);
59
60 coordination_unit->SetPolicyCallback(GetPolicyCallback());
61
62 base::RunLoop loop;
63 QuitOnPolicyCallback(&loop);
64 loop.Run();
65 }
66
67 } // namespace resource_coordinator
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698