| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "shell/android/background_application_loader.h" | 5 #include "shell/android/background_application_loader.h" |
| 6 | 6 |
| 7 #include "mojo/public/interfaces/application/application.mojom.h" | 7 #include "mojo/public/interfaces/application/application.mojom.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace mojo { | 10 namespace mojo { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 class DummyLoader : public ApplicationLoader { | 14 class DummyLoader : public ApplicationLoader { |
| 15 public: | 15 public: |
| 16 DummyLoader() : simulate_app_quit_(true) {} | 16 DummyLoader() : simulate_app_quit_(true) {} |
| 17 ~DummyLoader() override {} | 17 ~DummyLoader() override {} |
| 18 | 18 |
| 19 // ApplicationLoader overrides: | 19 // ApplicationLoader overrides: |
| 20 void Load(ApplicationManager* manager, | 20 void Load(const GURL& url, |
| 21 const GURL& url, | 21 InterfaceRequest<Application> application_request) override { |
| 22 InterfaceRequest<Application> application_request, | |
| 23 LoadCallback callback) override { | |
| 24 if (simulate_app_quit_) | 22 if (simulate_app_quit_) |
| 25 base::MessageLoop::current()->Quit(); | 23 base::MessageLoop::current()->Quit(); |
| 26 } | 24 } |
| 27 | 25 |
| 28 void OnApplicationError(ApplicationManager* manager, | 26 void OnApplicationError(ApplicationManager* manager, |
| 29 const GURL& url) override {} | 27 const GURL& url) override {} |
| 30 | 28 |
| 31 void DontSimulateAppQuit() { simulate_app_quit_ = false; } | 29 void DontSimulateAppQuit() { simulate_app_quit_ = false; } |
| 32 | 30 |
| 33 private: | 31 private: |
| 34 bool simulate_app_quit_; | 32 bool simulate_app_quit_; |
| 35 }; | 33 }; |
| 36 | 34 |
| 37 } // namespace | 35 } // namespace |
| 38 | 36 |
| 39 // Tests that the loader can start and stop gracefully. | 37 // Tests that the loader can start and stop gracefully. |
| 40 TEST(BackgroundApplicationLoaderTest, StartStop) { | 38 TEST(BackgroundApplicationLoaderTest, StartStop) { |
| 41 scoped_ptr<ApplicationLoader> real_loader(new DummyLoader()); | 39 scoped_ptr<ApplicationLoader> real_loader(new DummyLoader()); |
| 42 BackgroundApplicationLoader loader(real_loader.Pass(), "test", | 40 BackgroundApplicationLoader loader(real_loader.Pass(), "test", |
| 43 base::MessageLoop::TYPE_DEFAULT); | 41 base::MessageLoop::TYPE_DEFAULT); |
| 44 } | 42 } |
| 45 | 43 |
| 46 // Tests that the loader can load a service that is well behaved (quits | 44 // Tests that the loader can load a service that is well behaved (quits |
| 47 // itself). | 45 // itself). |
| 48 TEST(BackgroundApplicationLoaderTest, Load) { | 46 TEST(BackgroundApplicationLoaderTest, Load) { |
| 49 scoped_ptr<ApplicationLoader> real_loader(new DummyLoader()); | 47 scoped_ptr<ApplicationLoader> real_loader(new DummyLoader()); |
| 50 BackgroundApplicationLoader loader(real_loader.Pass(), "test", | 48 BackgroundApplicationLoader loader(real_loader.Pass(), "test", |
| 51 base::MessageLoop::TYPE_DEFAULT); | 49 base::MessageLoop::TYPE_DEFAULT); |
| 52 ApplicationPtr application; | 50 ApplicationPtr application; |
| 53 loader.Load(NULL, GURL(), GetProxy(&application), | 51 loader.Load(GURL(), GetProxy(&application)); |
| 54 ApplicationLoader::SimpleLoadCallback()); | |
| 55 } | 52 } |
| 56 | 53 |
| 57 } // namespace mojo | 54 } // namespace mojo |
| OLD | NEW |