diff options
author | sky <sky@chromium.org> | 2016-02-24 14:24:02 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-24 22:25:34 +0000 |
commit | 758df73af1b6dc37555ce3b8a7c89b39da3f5a03 (patch) | |
tree | 36b9779cf8378b239156101c32c3f43da0f24b84 /mojo/shell/background/tests | |
parent | 43c8de64e250e814ea15c4240d5d4273a8272535 (diff) | |
download | chromium_src-758df73af1b6dc37555ce3b8a7c89b39da3f5a03.zip chromium_src-758df73af1b6dc37555ce3b8a7c89b39da3f5a03.tar.gz chromium_src-758df73af1b6dc37555ce3b8a7c89b39da3f5a03.tar.bz2 |
Makes PackageManager take the ApplicationCatalogStore in constructor
And plumbs through the appropriate places.
Also adds a test of all this via backroundshell.
And lastly I converted PackageManager to be in terms of GURLs. This way mojo:foo, mojo://foo and mojo://foo/ are all treated the same.
BUG=577274
TEST=covered by tests
R=ben@chromium.org
Review URL: https://codereview.chromium.org/1733463002
Cr-Commit-Position: refs/heads/master@{#377410}
Diffstat (limited to 'mojo/shell/background/tests')
-rw-r--r-- | mojo/shell/background/tests/BUILD.gn | 64 | ||||
-rw-r--r-- | mojo/shell/background/tests/background_shell_unittest.cc | 70 | ||||
-rw-r--r-- | mojo/shell/background/tests/test.mojom | 9 | ||||
-rw-r--r-- | mojo/shell/background/tests/test_application_catalog_store.cc | 46 | ||||
-rw-r--r-- | mojo/shell/background/tests/test_application_catalog_store.h | 49 | ||||
-rw-r--r-- | mojo/shell/background/tests/test_service.cc | 53 |
6 files changed, 291 insertions, 0 deletions
diff --git a/mojo/shell/background/tests/BUILD.gn b/mojo/shell/background/tests/BUILD.gn new file mode 100644 index 0000000..b6037522 --- /dev/null +++ b/mojo/shell/background/tests/BUILD.gn @@ -0,0 +1,64 @@ +# Copyright 2016 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. + +import("//mojo/public/mojo_application.gni") +import("//mojo/public/mojo_application_manifest.gni") +import("//mojo/public/tools/bindings/mojom.gni") +import("//testing/test.gni") + +source_set("test_support") { + sources = [ + "test_application_catalog_store.cc", + "test_application_catalog_store.h", + ] + + deps = [ + "//base", + "//mojo/services/package_manager:lib", + "//url", + ] +} + +source_set("unittests") { + testonly = true + sources = [ + "background_shell_unittest.cc", + ] + + deps = [ + ":test_app_bindings", + ":test_support", + "//base", + "//mojo/shell/background:lib", + "//mojo/shell/background:main", + "//mojo/shell/public/cpp:sources", + "//testing/gtest", + "//url", + ] + + data_deps = [ + ":test_app", + ] +} + +mojom("test_app_bindings") { + sources = [ + "test.mojom", + ] +} + +mojo_native_application("test_app") { + output_name = "background_shell_test_app" + + sources = [ + "test_service.cc", + ] + + deps = [ + ":test_app_bindings", + "//base", + "//mojo/shell/public/cpp:sources", + "//mojo/shell/public/interfaces", + ] +} diff --git a/mojo/shell/background/tests/background_shell_unittest.cc b/mojo/shell/background/tests/background_shell_unittest.cc new file mode 100644 index 0000000..04ec802 --- /dev/null +++ b/mojo/shell/background/tests/background_shell_unittest.cc @@ -0,0 +1,70 @@ +// Copyright 2016 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/background/background_shell.h" + +#include "base/run_loop.h" +#include "mojo/shell/background/tests/test.mojom.h" +#include "mojo/shell/background/tests/test_application_catalog_store.h" +#include "mojo/shell/public/cpp/shell_client.h" +#include "mojo/shell/public/cpp/shell_connection.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "url/gurl.h" + +namespace mojo { +namespace shell { +namespace { + +const char kTestUrl[] = "mojo:test-app"; + +class ShellClientImpl : public ShellClient { + public: + ShellClientImpl() {} + ~ShellClientImpl() override {} + + private: + DISALLOW_COPY_AND_ASSIGN(ShellClientImpl); +}; + +scoped_ptr<TestApplicationCatalogStore> BuildTestApplicationCatalogStore() { + scoped_ptr<base::ListValue> apps(new base::ListValue); + apps->Append(BuildPermissiveSerializedAppInfo(GURL(kTestUrl), "test")); + return make_scoped_ptr(new TestApplicationCatalogStore(std::move(apps))); +} + +} // namespace + +// Uses BackgroundShell to start the shell in the background and connects to +// background_shell_test_app, verifying we can send a message to the app. +// An ApplicationCatalogStore is supplied to avoid using a manifest. +TEST(BackgroundShellTest, Basic) { + base::MessageLoop message_loop; + BackgroundShell background_shell; + scoped_ptr<BackgroundShell::InitParams> init_params( + new BackgroundShell::InitParams); + scoped_ptr<TestApplicationCatalogStore> store_ptr = + BuildTestApplicationCatalogStore(); + TestApplicationCatalogStore* store = store_ptr.get(); + init_params->app_catalog = std::move(store_ptr); + background_shell.Init(std::move(init_params)); + ShellClientImpl shell_client; + ShellConnection shell_connection( + &shell_client, background_shell.CreateShellClientRequest(GURL(kTestUrl))); + shell_connection.WaitForInitialize(); + mojom::TestServicePtr test_service; + static_cast<Shell*>(&shell_connection) + ->ConnectToInterface("mojo:background_shell_test_app", &test_service); + base::RunLoop run_loop; + bool got_result = false; + test_service->Test([&run_loop, &got_result]() { + got_result = true; + run_loop.Quit(); + }); + run_loop.Run(); + EXPECT_TRUE(got_result); + EXPECT_TRUE(store->get_store_called()); +} + +} // namespace shell +} // namespace mojo diff --git a/mojo/shell/background/tests/test.mojom b/mojo/shell/background/tests/test.mojom new file mode 100644 index 0000000..a021d70 --- /dev/null +++ b/mojo/shell/background/tests/test.mojom @@ -0,0 +1,9 @@ +// Copyright 2016 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. + +module mojo.shell.mojom; + +interface TestService { + Test() => (); +}; diff --git a/mojo/shell/background/tests/test_application_catalog_store.cc b/mojo/shell/background/tests/test_application_catalog_store.cc new file mode 100644 index 0000000..7c0a2c9 --- /dev/null +++ b/mojo/shell/background/tests/test_application_catalog_store.cc @@ -0,0 +1,46 @@ +// Copyright 2016 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/background/tests/test_application_catalog_store.h" + +#include "url/gurl.h" + +using package_manager::ApplicationCatalogStore; + +namespace mojo { +namespace shell { + +TestApplicationCatalogStore::TestApplicationCatalogStore( + scoped_ptr<base::ListValue> store) + : store_(std::move(store)) {} + +TestApplicationCatalogStore::~TestApplicationCatalogStore() {} + +const base::ListValue* TestApplicationCatalogStore::GetStore() { + get_store_called_ = true; + return store_.get(); +} + +void TestApplicationCatalogStore::UpdateStore( + scoped_ptr<base::ListValue> store) {} + +scoped_ptr<base::DictionaryValue> BuildPermissiveSerializedAppInfo( + const GURL& url, + const std::string& name) { + scoped_ptr<base::DictionaryValue> app(new base::DictionaryValue); + app->SetString(ApplicationCatalogStore::kUrlKey, url.spec()); + app->SetString(ApplicationCatalogStore::kNameKey, name); + + scoped_ptr<base::DictionaryValue> capabilities(new base::DictionaryValue); + scoped_ptr<base::ListValue> interfaces(new base::ListValue); + interfaces->AppendString("*"); + capabilities->Set("*", std::move(interfaces)); + + app->Set(ApplicationCatalogStore::kCapabilitiesKey, std::move(capabilities)); + + return app; +} + +} // namespace shell +} // namespace mojo diff --git a/mojo/shell/background/tests/test_application_catalog_store.h b/mojo/shell/background/tests/test_application_catalog_store.h new file mode 100644 index 0000000..691df28 --- /dev/null +++ b/mojo/shell/background/tests/test_application_catalog_store.h @@ -0,0 +1,49 @@ +// Copyright 2016 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. + +#ifndef MOJO_SHELL_BACKGROUND_TESTS_TEST_APPLICATION_CATALOG_STORE_H_ +#define MOJO_SHELL_BACKGROUND_TESTS_TEST_APPLICATION_CATALOG_STORE_H_ + +#include <string> + +#include "base/memory/scoped_ptr.h" +#include "base/values.h" +#include "mojo/services/package_manager/package_manager.h" + +class GURL; + +namespace mojo { +namespace shell { + +// ApplicationCatalogStore implementation that takes the ListValue to return +// as store. +class TestApplicationCatalogStore + : public package_manager::ApplicationCatalogStore { + public: + explicit TestApplicationCatalogStore(scoped_ptr<base::ListValue> store); + ~TestApplicationCatalogStore() override; + + bool get_store_called() const { return get_store_called_; } + + // ApplicationCatalogStore: + const base::ListValue* GetStore() override; + void UpdateStore(scoped_ptr<base::ListValue> store) override; + + private: + bool get_store_called_ = false; + scoped_ptr<base::ListValue> store_; + + DISALLOW_COPY_AND_ASSIGN(TestApplicationCatalogStore); +}; + +// Returns a dictionary for an app with the specified url, name and a +// permissive filter. +scoped_ptr<base::DictionaryValue> BuildPermissiveSerializedAppInfo( + const GURL& url, + const std::string& name); + +} // namespace shell +} // namespace mojo + +#endif // MOJO_SHELL_BACKGROUND_TESTS_TEST_APPLICATION_CATALOG_STORE_H_ diff --git a/mojo/shell/background/tests/test_service.cc b/mojo/shell/background/tests/test_service.cc new file mode 100644 index 0000000..3c9dbbd --- /dev/null +++ b/mojo/shell/background/tests/test_service.cc @@ -0,0 +1,53 @@ +// Copyright 2016 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/public/c/system/main.h" +#include "mojo/public/cpp/bindings/weak_binding_set.h" +#include "mojo/shell/background/tests/test.mojom.h" +#include "mojo/shell/public/cpp/application_runner.h" +#include "mojo/shell/public/cpp/connection.h" +#include "mojo/shell/public/cpp/shell_client.h" + +namespace mojo { +namespace shell { + +class TestClient : public ShellClient, + public InterfaceFactory<mojom::TestService>, + public mojom::TestService { + public: + TestClient() {} + ~TestClient() override {} + + private: + // ShellClient: + void Initialize(Shell* shell, + const std::string& url, + uint32_t id, + uint32_t user_id) override {} + bool AcceptConnection(Connection* connection) override { + connection->AddInterface(this); + return true; + } + + // InterfaceFactory<mojom::TestService>: + void Create(Connection* connection, + InterfaceRequest<mojom::TestService> request) override { + bindings_.AddBinding(this, std::move(request)); + } + + // mojom::TestService + void Test(const TestCallback& callback) override { callback.Run(); } + + WeakBindingSet<mojom::TestService> bindings_; + + DISALLOW_COPY_AND_ASSIGN(TestClient); +}; + +} // namespace shell +} // namespace mojo + +MojoResult MojoMain(MojoHandle shell_handle) { + mojo::ApplicationRunner runner(new mojo::shell::TestClient); + return runner.Run(shell_handle); +} |