blob: 2807bd698acf40e4937ed5b24e31a78e1d0a7ca5 [file] [log] [blame]
Sergey Kuznetsovae594402019-04-19 16:08:051// Copyright 2019 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 <string>
6
7#include "base/bind.h"
8#include "base/macros.h"
9#include "base/test/bind_test_util.h"
10#include "components/services/patch/public/interfaces/constants.mojom.h"
11#include "components/services/patch/public/interfaces/file_patcher.mojom.h"
12#include "components/services/unzip/public/interfaces/constants.mojom.h"
13#include "components/services/unzip/public/interfaces/unzipper.mojom.h"
Ken Rockoteff2b822019-06-20 22:56:5314#include "content/public/browser/system_connector.h"
Sergey Kuznetsovae594402019-04-19 16:08:0515#include "content/public/test/test_browser_thread_bundle.h"
16#include "content/public/test/test_utils.h"
17#include "services/service_manager/public/cpp/connector.h"
18#include "testing/gtest/include/gtest/gtest.h"
19
20namespace {
21
22class ServicesTest : public testing::Test {
23 public:
24 ServicesTest()
25 : thread_bundle_(content::TestBrowserThreadBundle::MainThreadType::IO) {}
26
Sergey Kuznetsovae594402019-04-19 16:08:0527 template <typename Interface>
28 bool CanAccessInterfaceFromBrowser(const std::string& service_name) {
29 mojo::InterfacePtr<Interface> interface;
30 connector()->BindInterface(service_name, mojo::MakeRequest(&interface));
31
32 // If the service is present, the interface will be connected and
33 // FlushForTesting will complete without an error on the interface.
34 // Conversely if there is a problem connecting to the interface, we will
35 // always hit the error handler before FlushForTesting returns.
36 bool encountered_error = false;
37 interface.set_connection_error_handler(
38 base::BindLambdaForTesting([&] { encountered_error = true; }));
39 interface.FlushForTesting();
40 return !encountered_error;
41 }
42
43 private:
44 service_manager::Connector* connector() {
Ken Rockoteff2b822019-06-20 22:56:5345 return content::GetSystemConnector();
Sergey Kuznetsovae594402019-04-19 16:08:0546 }
47
48 content::TestBrowserThreadBundle thread_bundle_;
49 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_;
50
51 DISALLOW_COPY_AND_ASSIGN(ServicesTest);
52};
53
54} // namespace
55
56TEST_F(ServicesTest, ConnectToUnzip) {
57 EXPECT_TRUE(CanAccessInterfaceFromBrowser<unzip::mojom::Unzipper>(
58 unzip::mojom::kServiceName));
59}
60
61TEST_F(ServicesTest, ConnectToFilePatch) {
62 EXPECT_TRUE(CanAccessInterfaceFromBrowser<patch::mojom::FilePatcher>(
63 patch::mojom::kServiceName));
64}