summaryrefslogtreecommitdiffstats
path: root/mojo/shell/standalone/android/background_application_loader_unittest.cc
blob: fcea7571f4407788b990688a1e1c5de84c625ee3 (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
// Copyright 2014 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/standalone/android/background_application_loader.h"

#include "mojo/shell/public/interfaces/shell_client.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace mojo {
namespace shell {
namespace {

class DummyLoader : public ApplicationLoader {
 public:
  DummyLoader() : simulate_app_quit_(true) {}
  ~DummyLoader() override {}

  // ApplicationLoader overrides:
  void Load(const GURL& url,
            InterfaceRequest<mojom::ShellClient> request) override {
    if (simulate_app_quit_)
      base::MessageLoop::current()->QuitWhenIdle();
  }

  void DontSimulateAppQuit() { simulate_app_quit_ = false; }

 private:
  bool simulate_app_quit_;
};

// Tests that the loader can start and stop gracefully.
TEST(BackgroundApplicationLoaderTest, StartStop) {
  scoped_ptr<ApplicationLoader> real_loader(new DummyLoader());
  BackgroundApplicationLoader loader(std::move(real_loader), "test",
                                     base::MessageLoop::TYPE_DEFAULT);
}

// Tests that the loader can load a service that is well behaved (quits
// itself).
TEST(BackgroundApplicationLoaderTest, Load) {
  scoped_ptr<ApplicationLoader> real_loader(new DummyLoader());
  BackgroundApplicationLoader loader(std::move(real_loader), "test",
                                     base::MessageLoop::TYPE_DEFAULT);
  ApplicationPtr application;
  loader.Load(GURL(), GetProxy(&application));
}

}  // namespace
}  // namespace shell
}  // namespace mojo