| Index: mojo/services/html_viewer/html_viewer_apptest.cc
|
| diff --git a/mojo/services/html_viewer/html_viewer_apptest.cc b/mojo/services/html_viewer/html_viewer_apptest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..04c0a326cdba22fc5efcbb7e1dbcfeb3716f02d4
|
| --- /dev/null
|
| +++ b/mojo/services/html_viewer/html_viewer_apptest.cc
|
| @@ -0,0 +1,170 @@
|
| +// 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 "base/bind.h"
|
| +#include "base/run_loop.h"
|
| +#include "base/strings/stringprintf.h"
|
| +#include "mojo/public/cpp/application/application_impl.h"
|
| +#include "mojo/public/cpp/application/application_test_base.h"
|
| +#include "mojo/services/html_viewer/public/interfaces/html_viewer.mojom.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "third_party/mojo_services/src/accessibility/public/interfaces/accessibility.mojom.h"
|
| +#include "third_party/mojo_services/src/http_server/public/cpp/http_server_util.h"
|
| +#include "third_party/mojo_services/src/http_server/public/interfaces/http_server.mojom.h"
|
| +#include "third_party/mojo_services/src/http_server/public/interfaces/http_server_factory.mojom.h"
|
| +
|
| +//#include "base/command_line.h"
|
| +//#include "base/test/test_timeouts.h"
|
| +#include "net/test/spawned_test_server/spawned_test_server.h"
|
| +
|
| +namespace mojo {
|
| +
|
| +namespace {
|
| +
|
| +// A simple test server and handler that uses the mojo:http_server service.
|
| +class TestHttpServer : public http_server::HttpHandler {
|
| + public:
|
| + TestHttpServer(ApplicationImpl* application) : handler_binding_(this) {
|
| + // Construct a server from the factory with a local address.
|
| + http_server::HttpServerFactoryPtr http_server_factory;
|
| + application->ConnectToService("mojo:http_server", &http_server_factory);
|
| + NetAddressPtr local_address(NetAddress::New());
|
| + local_address->family = NET_ADDRESS_FAMILY_IPV4;
|
| + local_address->ipv4 = NetAddressIPv4::New();
|
| + local_address->ipv4->addr.resize(4);
|
| + local_address->ipv4->addr[0] = 127;
|
| + local_address->ipv4->addr[1] = 0;
|
| + local_address->ipv4->addr[2] = 0;
|
| + local_address->ipv4->addr[3] = 1;
|
| + local_address->ipv4->port = 0;
|
| + http_server_factory->CreateHttpServer(GetProxy(&http_server_).Pass(),
|
| + local_address.Pass());
|
| +
|
| + // Get the assigned port.
|
| + http_server_->GetPort([=](uint16_t p) { this->assigned_port_ = p; });
|
| + http_server_.WaitForIncomingMethodCall();
|
| +
|
| + // Set this object as the handler and wait for confirmation.
|
| + http_server::HttpHandlerPtr http_handler_ptr;
|
| + handler_binding_.Bind(GetProxy(&http_handler_ptr).Pass());
|
| + http_server_->SetHandler("/test", http_handler_ptr.Pass(),
|
| + [](bool result) { EXPECT_TRUE(result); });
|
| + http_server_.WaitForIncomingMethodCall();
|
| + }
|
| +
|
| + uint16_t assigned_port() const { return assigned_port_; }
|
| +
|
| + private:
|
| + // http_server::HttpHandler:
|
| + void HandleRequest(http_server::HttpRequestPtr request,
|
| + const Callback<void(http_server::HttpResponsePtr)>&
|
| + callback) override {
|
| + const char* kExampleHTML = "<!DOCTYPE html><html>Hello world!</html>";
|
| + callback.Run(http_server::CreateHttpResponse(200, kExampleHTML));
|
| + }
|
| +
|
| + http_server::HttpServerPtr http_server_;
|
| + Binding<http_server::HttpHandler> handler_binding_;
|
| + uint16_t assigned_port_ = 0u;
|
| +
|
| + MOJO_DISALLOW_COPY_AND_ASSIGN(TestHttpServer);
|
| +};
|
| +
|
| +void PrintAxTree(Array<AxNodePtr> ax_tree) {
|
| + printf("MSW GetTree size %zu\n", ax_tree.size());
|
| + for (size_t i = 0; i < ax_tree.size(); ++i) {
|
| + const AxNodePtr& ax_node = ax_tree[i];
|
| + printf("MSW tree[%zu] id=%d parent=%d sibling=%d ",
|
| + i, ax_node->id, ax_node->parent_id, ax_node->next_sibling_id);
|
| + if (!ax_node->text.is_null())
|
| + printf("text=[%s] ", ax_node->text->content.data());
|
| + if (!ax_node->link.is_null())
|
| + printf("link=[%s] ", ax_node->link->url.data());
|
| + printf("\n");
|
| + }
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +typedef test::ApplicationTestBase HTMLViewerTest;
|
| +
|
| +TEST_F(HTMLViewerTest, AxProviderTest) {
|
| + //TestHttpServer server(application_impl());
|
| + //uint16_t assigned_port = server.assigned_port();
|
| +
|
| + //base::CommandLine
|
| + //TestTimeouts::Initialize();
|
| + net::SpawnedTestServer server(net::SpawnedTestServer::TYPE_HTTP, net::SpawnedTestServer::kLocalhost,
|
| + base::FilePath(FILE_PATH_LITERAL("net/data/proxy_resolver_perftest")));
|
| + ASSERT_TRUE(server.Start());
|
| + printf("MSW port: %u", server.host_port_pair().port());
|
| + uint16_t assigned_port = server.host_port_pair().port();
|
| +
|
| + // TODO(msw): Test a url without a handler? http://127.0.0.1:%u/bad_url
|
| + // [ERROR:network_fetcher.cc(229)] Error (404: HTTP/1.1 404 Not Found):
|
| + // while fetching http://127.0.0.1:44419/bad_url
|
| +
|
| + ApplicationConnection* connection = application_impl()->ConnectToApplication(
|
| + base::StringPrintf("http://127.0.0.1:%u/test", assigned_port));
|
| + printf("MSW good url: %s\n", connection->GetConnectionURL().c_str());
|
| +
|
| + // Connect to the HTMLViewerTestAPI of the HTMLViewerApplication.
|
| + // {
|
| + // base::RunLoop run_loop;
|
| + // HTMLViewerTestAPIPtr html_viewer_test_api;
|
| + // connection->ConnectToService(&html_viewer_test_api);
|
| + // html_viewer_test_api->WaitForHTMLDocument(run_loop.QuitClosure());
|
| + // run_loop.Run();
|
| + // }
|
| +
|
| + // Connect to the AxProvider of the HTMLDocument.
|
| + AxProviderPtr ax_provider;
|
| + connection->ConnectToService(&ax_provider);
|
| + {
|
| + base::RunLoop run_loop;
|
| + ax_provider->GetTree(
|
| + [&run_loop](Array<AxNodePtr> tree) {
|
| + PrintAxTree(tree.Pass());
|
| + run_loop.Quit();
|
| + });
|
| + run_loop.Run();
|
| + }
|
| +
|
| + // TODO(msw): Connect to the ViewManagerClient service via HTMLDocument... ?
|
| + // TODO(msw): Embed the html_viewer for some visible UI? (in another test?)
|
| +}
|
| +
|
| +// TEST_F(HTMLViewerTest, HTMLDocumentTest) {
|
| +// TestHttpServer server(application_impl());
|
| +// ApplicationConnection* connection = application_impl()->ConnectToApplication(
|
| +// base::StringPrintf("http://127.0.0.1:%u/test", server.assigned_port()));
|
| +// printf("MSW good url: %s\n", connection->GetConnectionURL().c_str());
|
| +
|
| +// Connect to the HTMLViewerTestAPI of the HTMLViewerApplication.
|
| +// {
|
| +// base::RunLoop run_loop;
|
| +// HTMLViewerTestAPIPtr html_viewer_test_api;
|
| +// connection->ConnectToService(&html_viewer_test_api);
|
| +// html_viewer_test_api->WaitForHTMLDocument(run_loop.QuitClosure());
|
| +// run_loop.Run();
|
| +// }
|
| +
|
| +// // Connect to the AxProvider of the HTMLDocument.
|
| +// AxProviderPtr ax_provider;
|
| +// connection->ConnectToService(&ax_provider);
|
| +// {
|
| +// base::RunLoop run_loop;
|
| +// ax_provider->GetTree(
|
| +// [&run_loop](Array<AxNodePtr> tree) {
|
| +// PrintAxTree(tree.Pass());
|
| +// run_loop.Quit();
|
| +// });
|
| +// run_loop.Run();
|
| +// }
|
| +
|
| +// // TODO(msw): Connect to the ViewManagerClient service via HTMLDocument... ?
|
| +// // TODO(msw): Embed the html_viewer for some visible UI? (in another test?)
|
| +// }
|
| +
|
| +} // namespace mojo
|
|
|