diff options
-rw-r--r-- | BUILD.gn | 1 | ||||
-rw-r--r-- | components/resource_provider/BUILD.gn | 46 | ||||
-rw-r--r-- | components/resource_provider/apptest_manifest.json | 5 | ||||
-rw-r--r-- | components/resource_provider/resource_provider_apptest.cc | 95 | ||||
-rw-r--r-- | components/resource_provider/resource_provider_test_app.cc | 126 | ||||
-rw-r--r-- | components/resource_provider/resource_provider_unittest.cc | 41 | ||||
-rw-r--r-- | components/resource_provider/test.mojom | 13 | ||||
-rw-r--r-- | components/resource_provider/test_manifest.json | 5 | ||||
-rw-r--r-- | components/resource_provider/unittests_manifest.json | 5 | ||||
-rw-r--r-- | mojo/tools/data/apptests | 4 |
10 files changed, 223 insertions, 118 deletions
@@ -588,7 +588,6 @@ group("mojo_apptests") { if (is_win || is_linux) { deps += [ - "//components/resource_provider:apptests", "//components/resource_provider:resource_provider_unittests", "//mash/wm:tests", "//media/mojo/services:tests", diff --git a/components/resource_provider/BUILD.gn b/components/resource_provider/BUILD.gn index 5133229..ce66701 100644 --- a/components/resource_provider/BUILD.gn +++ b/components/resource_provider/BUILD.gn @@ -4,6 +4,7 @@ import("//mojo/public/mojo_application.gni") import("//mojo/public/mojo_application_manifest.gni") +import("//mojo/public/tools/bindings/mojom.gni") import("//testing/test.gni") if (is_android) { @@ -112,26 +113,33 @@ source_set("lib") { test("resource_provider_unittests") { sources = [ "file_utils_unittest.cc", + "resource_provider_unittest.cc", ] deps = [ ":lib", + ":test_interfaces", "//base", - "//base/test:test_config", "//components/resource_provider/public/interfaces", - "//mojo/edk/test:run_all_unittests", - "//mojo/platform_handle:for_shared_library", + "//mojo/shell/background:main", + "//mojo/shell/public/cpp:shell_test_support", + "//mojo/shell/public/cpp/test:run_all_shelltests", "//testing/gtest", "//url", ] + + data_deps = [ + ":test_app", + ":unittests_manifest", + ] } -mojo_native_application("apptests") { - output_name = "resource_provider_apptests" +mojo_native_application("test_app") { + output_name = "resource_provider_test_app" testonly = true sources = [ - "resource_provider_apptest.cc", + "resource_provider_test_app.cc", ] resources = [ @@ -140,21 +148,33 @@ mojo_native_application("apptests") { ] deps = [ + ":test_interfaces", "//base", - "//base/test:test_config", "//components/resource_provider/public/cpp", "//components/resource_provider/public/interfaces", - "//mojo/common", - "//mojo/shell/public/cpp:test_support", + "//mojo/shell/public/cpp", + "//mojo/shell/public/interfaces", ] data_deps = [ - ":apptest_manifest", ":resource_provider", + ":test_manifest", ] } -mojo_application_manifest("apptest_manifest") { - application_name = "resource_provider_apptests" - source = "apptest_manifest.json" +mojo_application_manifest("test_manifest") { + application_name = "resource_provider_test_app" + source = "test_manifest.json" +} + +mojo_application_manifest("unittests_manifest") { + type = "exe" + application_name = "resource_provider_unittests" + source = "unittests_manifest.json" +} + +mojom("test_interfaces") { + sources = [ + "test.mojom", + ] } diff --git a/components/resource_provider/apptest_manifest.json b/components/resource_provider/apptest_manifest.json deleted file mode 100644 index 6bbc800..0000000 --- a/components/resource_provider/apptest_manifest.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "mojo:resource_provider_apptests", - "display_name": "Resource Provider Apptests", - "capabilities": { "*": [ "*" ] } -} diff --git a/components/resource_provider/resource_provider_apptest.cc b/components/resource_provider/resource_provider_apptest.cc deleted file mode 100644 index a4c84ad..0000000 --- a/components/resource_provider/resource_provider_apptest.cc +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2015 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 <stddef.h> -#include <stdint.h> - -#include "base/containers/scoped_ptr_hash_map.h" -#include "base/files/file.h" -#include "base/macros.h" -#include "base/run_loop.h" -#include "components/resource_provider/public/cpp/resource_loader.h" -#include "components/resource_provider/public/interfaces/resource_provider.mojom.h" -#include "mojo/common/common_type_converters.h" -#include "mojo/platform_handle/platform_handle_functions.h" -#include "mojo/public/cpp/bindings/array.h" -#include "mojo/shell/public/cpp/application_test_base.h" - -namespace resource_provider { -namespace { - -std::string ReadFile(base::File* file) { - const size_t kBufferSize = 1 << 16; - scoped_ptr<char[]> buffer(new char[kBufferSize]); - const int read = file->ReadAtCurrentPos(buffer.get(), kBufferSize); - if (read == -1) - return std::string(); - return std::string(buffer.get(), read); -} - -std::set<std::string> SetWithString(const std::string& contents) { - std::set<std::string> result; - result.insert(contents); - return result; -} - -std::set<std::string> SetWithStrings(const std::string& contents1, - const std::string& contents2) { - std::set<std::string> result; - result.insert(contents1); - result.insert(contents2); - return result; -} - -class ResourceProviderApplicationTest : public mojo::test::ApplicationTestBase { - public: - ResourceProviderApplicationTest() {} - ~ResourceProviderApplicationTest() override {} - - protected: - using ResourceContentsMap = std::map<std::string, std::string>; - - // Queries ResourceProvider for the specified resources, blocking until the - // resources are returned. The return map maps from the path to the contents - // of the file at the specified path. - ResourceContentsMap GetResources(const std::set<std::string>& paths) { - ResourceLoader loader(connector(), paths); - loader.BlockUntilLoaded(); - - // Load the contents of each of the handles. - ResourceContentsMap results; - for (auto& path : paths) { - base::File file(loader.ReleaseFile(path)); - results[path] = ReadFile(&file); - } - return results; - } - - // ApplicationTestBase: - void SetUp() override { - ApplicationTestBase::SetUp(); - } - - private: - DISALLOW_COPY_AND_ASSIGN(ResourceProviderApplicationTest); -}; - -TEST_F(ResourceProviderApplicationTest, FetchOneResource) { - ResourceContentsMap results(GetResources(SetWithString("sample"))); - ASSERT_TRUE(results.count("sample") > 0u); - EXPECT_EQ("test data\n", results["sample"]); -} - -TEST_F(ResourceProviderApplicationTest, FetchTwoResources) { - ResourceContentsMap results( - GetResources(SetWithStrings("sample", "dir/sample2"))); - ASSERT_TRUE(results.count("sample") > 0u); - EXPECT_EQ("test data\n", results["sample"]); - - ASSERT_TRUE(results.count("dir/sample2") > 0u); - EXPECT_EQ("xxyy\n", results["dir/sample2"]); -} - -} // namespace -} // namespace resource_provider diff --git a/components/resource_provider/resource_provider_test_app.cc b/components/resource_provider/resource_provider_test_app.cc new file mode 100644 index 0000000..ab0147f --- /dev/null +++ b/components/resource_provider/resource_provider_test_app.cc @@ -0,0 +1,126 @@ +// 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 <stddef.h> +#include <stdint.h> + +#include "base/files/file.h" +#include "base/macros.h" +#include "base/run_loop.h" +#include "components/resource_provider/public/cpp/resource_loader.h" +#include "components/resource_provider/public/interfaces/resource_provider.mojom.h" +#include "components/resource_provider/test.mojom.h" +#include "mojo/platform_handle/platform_handle_functions.h" +#include "mojo/public/c/system/main.h" +#include "mojo/public/cpp/bindings/array.h" +#include "mojo/public/cpp/bindings/binding_set.h" +#include "mojo/shell/public/cpp/application_runner.h" +#include "mojo/shell/public/cpp/shell_client.h" + +namespace resource_provider { +namespace test { + +std::string ReadFile(base::File* file) { + const size_t kBufferSize = 1 << 16; + scoped_ptr<char[]> buffer(new char[kBufferSize]); + const int read = file->ReadAtCurrentPos(buffer.get(), kBufferSize); + if (read == -1) + return std::string(); + return std::string(buffer.get(), read); +} + +std::set<std::string> SetWithString(const std::string& contents) { + std::set<std::string> result; + result.insert(contents); + return result; +} + +std::set<std::string> SetWithStrings(const std::string& contents1, + const std::string& contents2) { + std::set<std::string> result; + result.insert(contents1); + result.insert(contents2); + return result; +} + +class Test : public mojom::Test { + public: + explicit Test(mojo::Connector* connector) : connector_(connector) {} + ~Test() override {} + + // mojom::Test: + void GetResource1(const GetResource1Callback& callback) override { + printf("GetResource1\n"); + ResourceContentsMap results(GetResources(SetWithString("sample"))); + printf("GetResource1 result %s\n", results["sample"].c_str()); + callback.Run(results["sample"]); + } + void GetBothResources(const GetBothResourcesCallback& callback) override { + ResourceContentsMap results( + GetResources(SetWithStrings("sample", "dir/sample2"))); + callback.Run(results["sample"], results["dir/sample2"]); + } + + private: + using ResourceContentsMap = std::map<std::string, std::string>; + + ResourceContentsMap GetResources(const std::set<std::string>& paths) { + ResourceLoader loader(connector_, paths); + loader.BlockUntilLoaded(); + + // Load the contents of each of the handles. + ResourceContentsMap results; + for (auto& path : paths) { + base::File file(loader.ReleaseFile(path)); + results[path] = ReadFile(&file); + } + return results; + } + + mojo::Connector* connector_; + + DISALLOW_COPY_AND_ASSIGN(Test); +}; + +class TestApp : public mojo::ShellClient, + public mojo::InterfaceFactory<mojom::Test> { + public: + TestApp() {} + ~TestApp() override {} + + // mojo::ShellClient: + void Initialize(mojo::Connector* connector, + const mojo::Identity& identity, + uint32_t id) override { + test_.reset(new Test(connector)); + } + bool AcceptConnection(mojo::Connection* connection) override { + connection->AddInterface<mojom::Test>(this); + return true; + } + void ShellConnectionLost() override { + base::MessageLoop::current()->QuitWhenIdle(); + } + + // InterfaceFactory<mojom::Test>: + void Create(mojo::Connection* connection, + mojom::TestRequest request) override { + printf("test app create\n"); + bindings_.AddBinding(test_.get(), std::move(request)); + } + + private: + scoped_ptr<Test> test_; + mojo::BindingSet<test::mojom::Test> bindings_; + + DISALLOW_COPY_AND_ASSIGN(TestApp); +}; + +} // namespace test +} // namespace resource_provider + +MojoResult MojoMain(MojoHandle shell_handle) { + return mojo::ApplicationRunner(new resource_provider::test::TestApp) + .Run(shell_handle); +} diff --git a/components/resource_provider/resource_provider_unittest.cc b/components/resource_provider/resource_provider_unittest.cc new file mode 100644 index 0000000..a24bf97 --- /dev/null +++ b/components/resource_provider/resource_provider_unittest.cc @@ -0,0 +1,41 @@ +// 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 "base/macros.h" +#include "components/resource_provider/test.mojom.h" +#include "mojo/public/cpp/bindings/string.h" +#include "mojo/shell/public/cpp/shell_test.h" + +namespace resource_provider { +namespace test { + +class ResourceProviderTest : public mojo::test::ShellTest { + public: + ResourceProviderTest() + : mojo::test::ShellTest("exe:resource_provider_unittests") {} + ~ResourceProviderTest() override {} + + private: + DISALLOW_COPY_AND_ASSIGN(ResourceProviderTest); +}; + +TEST_F(ResourceProviderTest, FetchOneResource) { + mojom::TestPtr test_app; + mojo::String resource1; + connector()->ConnectToInterface("mojo:resource_provider_test_app", &test_app); + ASSERT_TRUE(test_app->GetResource1(&resource1)); + EXPECT_EQ("test data\n", resource1); +} + +TEST_F(ResourceProviderTest, FetchTwoResources) { + mojom::TestPtr test_app; + mojo::String resource1, resource2; + connector()->ConnectToInterface("mojo:resource_provider_test_app", &test_app); + ASSERT_TRUE(test_app->GetBothResources(&resource1, &resource2)); + EXPECT_EQ("test data\n", resource1); + EXPECT_EQ("xxyy\n", resource2); +} + +} // namespace test +} // namespace resource_provider diff --git a/components/resource_provider/test.mojom b/components/resource_provider/test.mojom new file mode 100644 index 0000000..cfc1b3d --- /dev/null +++ b/components/resource_provider/test.mojom @@ -0,0 +1,13 @@ +// 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 resource_provider.test.mojom; + +interface Test { + [Sync] + GetResource1() => (string resource); + + [Sync] + GetBothResources() => (string resource1, string resource2); +}; diff --git a/components/resource_provider/test_manifest.json b/components/resource_provider/test_manifest.json new file mode 100644 index 0000000..0648b16 --- /dev/null +++ b/components/resource_provider/test_manifest.json @@ -0,0 +1,5 @@ +{ + "name": "mojo:resource_provider_test_app", + "display_name": "Resource Provider Test App", + "capabilities": { "*": [ "*" ] } +} diff --git a/components/resource_provider/unittests_manifest.json b/components/resource_provider/unittests_manifest.json new file mode 100644 index 0000000..30b91bf --- /dev/null +++ b/components/resource_provider/unittests_manifest.json @@ -0,0 +1,5 @@ +{ + "name": "exe:resource_provider_unittests", + "display_name": "Resource Provider Unittests", + "capabilities": { "*": [ "*" ] } +} diff --git a/mojo/tools/data/apptests b/mojo/tools/data/apptests index d28fb98..a3a4940 100644 --- a/mojo/tools/data/apptests +++ b/mojo/tools/data/apptests @@ -24,10 +24,6 @@ # WARNING: If you add a test make sure the gn target mojo_apptests depends upon # it. tests = [ - { - 'test': 'mojo:resource_provider_apptests', - 'type': 'gtest_isolated', - }, # TODO(msw|jam): Fix and enable the runner_apptests: http://crbug.com/479316 #{ # 'test': 'mojo:runner_apptests', |