summaryrefslogtreecommitdiffstats
path: root/mojo/shell/background/tests/background_shell_unittest.cc
blob: 19280ef9754c47d6e1feae037cd479adedda6f77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mojo/shell/background/background_shell.h"

#include "base/run_loop.h"
#include "mojo/shell/background/tests/test.mojom.h"
#include "mojo/shell/background/tests/test_application_catalog_store.h"
#include "mojo/shell/public/cpp/shell_client.h"
#include "mojo/shell/public/cpp/shell_connection.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

namespace mojo {
namespace shell {
namespace {

const char kTestUrl[] = "mojo:test-app";

class ShellClientImpl : public ShellClient {
 public:
  ShellClientImpl() {}
  ~ShellClientImpl() override {}

 private:
  DISALLOW_COPY_AND_ASSIGN(ShellClientImpl);
};

scoped_ptr<TestApplicationCatalogStore> BuildTestApplicationCatalogStore() {
  scoped_ptr<base::ListValue> apps(new base::ListValue);
  apps->Append(BuildPermissiveSerializedAppInfo(GURL(kTestUrl), "test"));
  return make_scoped_ptr(new TestApplicationCatalogStore(std::move(apps)));
}

}  // namespace

// Uses BackgroundShell to start the shell in the background and connects to
// background_shell_test_app, verifying we can send a message to the app.
// An ApplicationCatalogStore is supplied to avoid using a manifest.
// TODO(crbug.com/589784): This test is disabled, as it fails
// on the Android GN bot.
TEST(BackgroundShellTest, DISABLED_Basic) {
  base::MessageLoop message_loop;
  BackgroundShell background_shell;
  scoped_ptr<BackgroundShell::InitParams> init_params(
      new BackgroundShell::InitParams);
  scoped_ptr<TestApplicationCatalogStore> store_ptr =
      BuildTestApplicationCatalogStore();
  TestApplicationCatalogStore* store = store_ptr.get();
  init_params->app_catalog = std::move(store_ptr);
  background_shell.Init(std::move(init_params));
  ShellClientImpl shell_client;
  ShellConnection shell_connection(
      &shell_client, background_shell.CreateShellClientRequest(GURL(kTestUrl)));
  shell_connection.WaitForInitialize();
  mojom::TestServicePtr test_service;
  static_cast<Shell*>(&shell_connection)
      ->ConnectToInterface("mojo:background_shell_test_app", &test_service);
  base::RunLoop run_loop;
  bool got_result = false;
  test_service->Test([&run_loop, &got_result]() {
    got_result = true;
    run_loop.Quit();
  });
  run_loop.Run();
  EXPECT_TRUE(got_result);
  EXPECT_TRUE(store->get_store_called());
}

}  // namespace shell
}  // namespace mojo