blob: b9af70cb0c4227e2b82792893befbeba0cd2ee62 [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001// Copyright 2014 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
Benjamin Lerman5d429aa2015-05-07 16:21:00 +02005#include "shell/background_application_loader.h"
James Robinson646469d2014-10-03 15:33:28 -07006
James Robinsone5ae9e42015-01-26 17:53:08 -08007#include "mojo/public/interfaces/application/application.mojom.h"
Benjamin Lerman8b537622015-05-07 16:48:34 +02008#include "shell/context.h"
James Robinson646469d2014-10-03 15:33:28 -07009#include "testing/gtest/include/gtest/gtest.h"
10
Viet-Trung Luu36faa4d2015-03-04 18:08:18 -080011namespace shell {
James Robinson646469d2014-10-03 15:33:28 -070012namespace {
13
14class DummyLoader : public ApplicationLoader {
15 public:
16 DummyLoader() : simulate_app_quit_(true) {}
James Robinsone1b30cf2014-10-21 12:25:40 -070017 ~DummyLoader() override {}
James Robinson646469d2014-10-03 15:33:28 -070018
19 // ApplicationLoader overrides:
Viet-Trung Luubd07e3a2015-04-09 12:43:29 -070020 void Load(
21 const GURL& url,
22 mojo::InterfaceRequest<mojo::Application> application_request) override {
James Robinson646469d2014-10-03 15:33:28 -070023 if (simulate_app_quit_)
24 base::MessageLoop::current()->Quit();
25 }
26
James Robinson646469d2014-10-03 15:33:28 -070027 void DontSimulateAppQuit() { simulate_app_quit_ = false; }
28
29 private:
30 bool simulate_app_quit_;
31};
32
James Robinson646469d2014-10-03 15:33:28 -070033// Tests that the loader can start and stop gracefully.
Scott Violetf0ef0822014-12-18 08:55:12 -080034TEST(BackgroundApplicationLoaderTest, StartStop) {
Benjamin Lerman8b537622015-05-07 16:48:34 +020035 Context::EnsureEmbedderIsInitialized();
James Robinson646469d2014-10-03 15:33:28 -070036 scoped_ptr<ApplicationLoader> real_loader(new DummyLoader());
Scott Violetf0ef0822014-12-18 08:55:12 -080037 BackgroundApplicationLoader loader(real_loader.Pass(), "test",
38 base::MessageLoop::TYPE_DEFAULT);
James Robinson646469d2014-10-03 15:33:28 -070039}
40
41// Tests that the loader can load a service that is well behaved (quits
42// itself).
Scott Violetf0ef0822014-12-18 08:55:12 -080043TEST(BackgroundApplicationLoaderTest, Load) {
Benjamin Lerman8b537622015-05-07 16:48:34 +020044 Context::EnsureEmbedderIsInitialized();
James Robinson646469d2014-10-03 15:33:28 -070045 scoped_ptr<ApplicationLoader> real_loader(new DummyLoader());
Scott Violetf0ef0822014-12-18 08:55:12 -080046 BackgroundApplicationLoader loader(real_loader.Pass(), "test",
47 base::MessageLoop::TYPE_DEFAULT);
Viet-Trung Luubd07e3a2015-04-09 12:43:29 -070048 mojo::ApplicationPtr application;
49 loader.Load(GURL(), mojo::GetProxy(&application));
James Robinson646469d2014-10-03 15:33:28 -070050}
51
Viet-Trung Luu36faa4d2015-03-04 18:08:18 -080052} // namespace
53} // namespace shell