Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: mojo/service_manager/background_shell_service_loader_unittest.cc

Issue 437493002: mojo: allow BackgroundServiceLoader-loaded apps to Quit themselves. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
5 #include "mojo/service_manager/background_shell_service_loader.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace mojo {
10
11 namespace {
12
13 class DummyLoader : public ServiceLoader {
14 public:
15 DummyLoader() : simulate_app_quit_(true) {}
16 virtual ~DummyLoader() {}
17
18 // ServiceLoader overrides:
19 virtual void LoadService(ServiceManager* manager,
20 const GURL& url,
21 ScopedMessagePipeHandle shell_handle) OVERRIDE {
22 if (simulate_app_quit_)
23 base::MessageLoop::current()->Quit();
24 }
25
26 virtual void OnServiceError(ServiceManager* manager,
27 const GURL& url) OVERRIDE {
28 }
29
30 void DontSimulateAppQuit() { simulate_app_quit_ = false; }
31
32 private:
33 bool simulate_app_quit_;
34 };
35
36 } // namespace
37
38 // Tests that the loader can start and stop gracefully.
39 TEST(BackgroundShellServiceLoaderTest, StartStop) {
40 scoped_ptr<ServiceLoader> real_loader(new DummyLoader());
41 BackgroundShellServiceLoader loader(real_loader.Pass(), "test",
42 base::MessageLoop::TYPE_DEFAULT);
43 }
44
45 // Tests that the loader can load a service that is well behaved (quits
46 // itself).
47 TEST(BackgroundShellServiceLoaderTest, Load) {
48 scoped_ptr<ServiceLoader> real_loader(new DummyLoader());
49 BackgroundShellServiceLoader loader(real_loader.Pass(), "test",
50 base::MessageLoop::TYPE_DEFAULT);
51 MessagePipe dummy;
52 loader.LoadService(NULL, GURL(), dummy.handle0.Pass());
53 }
54
55 // Test that an app that doesn't quit itself can still be handled.
56 // TODO(tim): Remove this.
57 TEST(BackgroundShellServiceLoaderTest, LoadMisbehavedService) {
58 scoped_ptr<DummyLoader> real_loader(new DummyLoader());
59 real_loader->DontSimulateAppQuit();
60 BackgroundShellServiceLoader loader(
61 real_loader.PassAs<ServiceLoader>(), "test",
62 base::MessageLoop::TYPE_DEFAULT);
63 // Because this app is mis-behaved (doesn't quit itself), we need to
64 // explicitly kill the thread.
65 loader.set_quit_on_shutdown();
66 MessagePipe dummy;
67 loader.LoadService(NULL, GURL(), dummy.handle0.Pass());
68 }
69
70 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/service_manager/background_shell_service_loader.cc ('k') | mojo/service_manager/service_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698