James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 1 | // 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 Lerman | 5d429aa | 2015-05-07 16:21:00 +0200 | [diff] [blame] | 5 | #include "shell/background_application_loader.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 6 | |
James Robinson | e5ae9e4 | 2015-01-26 17:53:08 -0800 | [diff] [blame] | 7 | #include "mojo/public/interfaces/application/application.mojom.h" |
Benjamin Lerman | 8b53762 | 2015-05-07 16:48:34 +0200 | [diff] [blame] | 8 | #include "shell/context.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 9 | #include "testing/gtest/include/gtest/gtest.h" |
| 10 | |
Viet-Trung Luu | 36faa4d | 2015-03-04 18:08:18 -0800 | [diff] [blame] | 11 | namespace shell { |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 12 | namespace { |
| 13 | |
| 14 | class DummyLoader : public ApplicationLoader { |
| 15 | public: |
| 16 | DummyLoader() : simulate_app_quit_(true) {} |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 17 | ~DummyLoader() override {} |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 18 | |
| 19 | // ApplicationLoader overrides: |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 20 | void Load( |
| 21 | const GURL& url, |
| 22 | mojo::InterfaceRequest<mojo::Application> application_request) override { |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 23 | if (simulate_app_quit_) |
| 24 | base::MessageLoop::current()->Quit(); |
| 25 | } |
| 26 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 27 | void DontSimulateAppQuit() { simulate_app_quit_ = false; } |
| 28 | |
| 29 | private: |
| 30 | bool simulate_app_quit_; |
| 31 | }; |
| 32 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 33 | // Tests that the loader can start and stop gracefully. |
Scott Violet | f0ef082 | 2014-12-18 08:55:12 -0800 | [diff] [blame] | 34 | TEST(BackgroundApplicationLoaderTest, StartStop) { |
Benjamin Lerman | 8b53762 | 2015-05-07 16:48:34 +0200 | [diff] [blame] | 35 | Context::EnsureEmbedderIsInitialized(); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 36 | scoped_ptr<ApplicationLoader> real_loader(new DummyLoader()); |
Scott Violet | f0ef082 | 2014-12-18 08:55:12 -0800 | [diff] [blame] | 37 | BackgroundApplicationLoader loader(real_loader.Pass(), "test", |
| 38 | base::MessageLoop::TYPE_DEFAULT); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | // Tests that the loader can load a service that is well behaved (quits |
| 42 | // itself). |
Scott Violet | f0ef082 | 2014-12-18 08:55:12 -0800 | [diff] [blame] | 43 | TEST(BackgroundApplicationLoaderTest, Load) { |
Benjamin Lerman | 8b53762 | 2015-05-07 16:48:34 +0200 | [diff] [blame] | 44 | Context::EnsureEmbedderIsInitialized(); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 45 | scoped_ptr<ApplicationLoader> real_loader(new DummyLoader()); |
Scott Violet | f0ef082 | 2014-12-18 08:55:12 -0800 | [diff] [blame] | 46 | BackgroundApplicationLoader loader(real_loader.Pass(), "test", |
| 47 | base::MessageLoop::TYPE_DEFAULT); |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 48 | mojo::ApplicationPtr application; |
| 49 | loader.Load(GURL(), mojo::GetProxy(&application)); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Viet-Trung Luu | 36faa4d | 2015-03-04 18:08:18 -0800 | [diff] [blame] | 52 | } // namespace |
| 53 | } // namespace shell |