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

Side by Side Diff: mojo/services/html_viewer/html_viewer_apptest.cc

Issue 1049013004: Add some simple HTMLViewer apptests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use net::SpawnedTestServer instead of mojo:http_server. Created 5 years, 8 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
OLDNEW
(Empty)
1 // Copyright 2015 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 "base/bind.h"
6 #include "base/run_loop.h"
7 #include "base/strings/stringprintf.h"
8 #include "mojo/public/cpp/application/application_impl.h"
9 #include "mojo/public/cpp/application/application_test_base.h"
10 #include "mojo/services/html_viewer/public/interfaces/html_viewer.mojom.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/mojo_services/src/accessibility/public/interfaces/accessib ility.mojom.h"
13 #include "third_party/mojo_services/src/http_server/public/cpp/http_server_util. h"
14 #include "third_party/mojo_services/src/http_server/public/interfaces/http_serve r.mojom.h"
15 #include "third_party/mojo_services/src/http_server/public/interfaces/http_serve r_factory.mojom.h"
16
17 //#include "base/command_line.h"
18 //#include "base/test/test_timeouts.h"
19 #include "net/test/spawned_test_server/spawned_test_server.h"
20
21 namespace mojo {
22
23 namespace {
24
25 // A simple test server and handler that uses the mojo:http_server service.
26 class TestHttpServer : public http_server::HttpHandler {
27 public:
28 TestHttpServer(ApplicationImpl* application) : handler_binding_(this) {
29 // Construct a server from the factory with a local address.
30 http_server::HttpServerFactoryPtr http_server_factory;
31 application->ConnectToService("mojo:http_server", &http_server_factory);
32 NetAddressPtr local_address(NetAddress::New());
33 local_address->family = NET_ADDRESS_FAMILY_IPV4;
34 local_address->ipv4 = NetAddressIPv4::New();
35 local_address->ipv4->addr.resize(4);
36 local_address->ipv4->addr[0] = 127;
37 local_address->ipv4->addr[1] = 0;
38 local_address->ipv4->addr[2] = 0;
39 local_address->ipv4->addr[3] = 1;
40 local_address->ipv4->port = 0;
41 http_server_factory->CreateHttpServer(GetProxy(&http_server_).Pass(),
42 local_address.Pass());
43
44 // Get the assigned port.
45 http_server_->GetPort([=](uint16_t p) { this->assigned_port_ = p; });
46 http_server_.WaitForIncomingMethodCall();
47
48 // Set this object as the handler and wait for confirmation.
49 http_server::HttpHandlerPtr http_handler_ptr;
50 handler_binding_.Bind(GetProxy(&http_handler_ptr).Pass());
51 http_server_->SetHandler("/test", http_handler_ptr.Pass(),
52 [](bool result) { EXPECT_TRUE(result); });
53 http_server_.WaitForIncomingMethodCall();
54 }
55
56 uint16_t assigned_port() const { return assigned_port_; }
57
58 private:
59 // http_server::HttpHandler:
60 void HandleRequest(http_server::HttpRequestPtr request,
61 const Callback<void(http_server::HttpResponsePtr)>&
62 callback) override {
63 const char* kExampleHTML = "<!DOCTYPE html><html>Hello world!</html>";
64 callback.Run(http_server::CreateHttpResponse(200, kExampleHTML));
65 }
66
67 http_server::HttpServerPtr http_server_;
68 Binding<http_server::HttpHandler> handler_binding_;
69 uint16_t assigned_port_ = 0u;
70
71 MOJO_DISALLOW_COPY_AND_ASSIGN(TestHttpServer);
72 };
73
74 void PrintAxTree(Array<AxNodePtr> ax_tree) {
75 printf("MSW GetTree size %zu\n", ax_tree.size());
76 for (size_t i = 0; i < ax_tree.size(); ++i) {
77 const AxNodePtr& ax_node = ax_tree[i];
78 printf("MSW tree[%zu] id=%d parent=%d sibling=%d ",
79 i, ax_node->id, ax_node->parent_id, ax_node->next_sibling_id);
80 if (!ax_node->text.is_null())
81 printf("text=[%s] ", ax_node->text->content.data());
82 if (!ax_node->link.is_null())
83 printf("link=[%s] ", ax_node->link->url.data());
84 printf("\n");
85 }
86 }
87
88 } // namespace
89
90 typedef test::ApplicationTestBase HTMLViewerTest;
91
92 TEST_F(HTMLViewerTest, AxProviderTest) {
93 //TestHttpServer server(application_impl());
94 //uint16_t assigned_port = server.assigned_port();
95
96 //base::CommandLine
97 //TestTimeouts::Initialize();
98 net::SpawnedTestServer server(net::SpawnedTestServer::TYPE_HTTP, net::SpawnedT estServer::kLocalhost,
99 base::FilePath(FILE_PATH_LITERAL("net/data/proxy_resolver_perf test")));
100 ASSERT_TRUE(server.Start());
101 printf("MSW port: %u", server.host_port_pair().port());
102 uint16_t assigned_port = server.host_port_pair().port();
103
104 // TODO(msw): Test a url without a handler? http://127.0.0.1:%u/bad_url
105 // [ERROR:network_fetcher.cc(229)] Error (404: HTTP/1.1 404 Not Found):
106 // while fetching http://127.0.0.1:44419/bad_url
107
108 ApplicationConnection* connection = application_impl()->ConnectToApplication(
109 base::StringPrintf("http://127.0.0.1:%u/test", assigned_port));
110 printf("MSW good url: %s\n", connection->GetConnectionURL().c_str());
111
112 // Connect to the HTMLViewerTestAPI of the HTMLViewerApplication.
113 // {
114 // base::RunLoop run_loop;
115 // HTMLViewerTestAPIPtr html_viewer_test_api;
116 // connection->ConnectToService(&html_viewer_test_api);
117 // html_viewer_test_api->WaitForHTMLDocument(run_loop.QuitClosure());
118 // run_loop.Run();
119 // }
120
121 // Connect to the AxProvider of the HTMLDocument.
122 AxProviderPtr ax_provider;
123 connection->ConnectToService(&ax_provider);
124 {
125 base::RunLoop run_loop;
126 ax_provider->GetTree(
127 [&run_loop](Array<AxNodePtr> tree) {
128 PrintAxTree(tree.Pass());
129 run_loop.Quit();
130 });
131 run_loop.Run();
132 }
133
134 // TODO(msw): Connect to the ViewManagerClient service via HTMLDocument... ?
135 // TODO(msw): Embed the html_viewer for some visible UI? (in another test?)
136 }
137
138 // TEST_F(HTMLViewerTest, HTMLDocumentTest) {
139 // TestHttpServer server(application_impl());
140 // ApplicationConnection* connection = application_impl()->ConnectToApplicatio n(
141 // base::StringPrintf("http://127.0.0.1:%u/test", server.assigned_port())) ;
142 // printf("MSW good url: %s\n", connection->GetConnectionURL().c_str());
143
144 // Connect to the HTMLViewerTestAPI of the HTMLViewerApplication.
145 // {
146 // base::RunLoop run_loop;
147 // HTMLViewerTestAPIPtr html_viewer_test_api;
148 // connection->ConnectToService(&html_viewer_test_api);
149 // html_viewer_test_api->WaitForHTMLDocument(run_loop.QuitClosure());
150 // run_loop.Run();
151 // }
152
153 // // Connect to the AxProvider of the HTMLDocument.
154 // AxProviderPtr ax_provider;
155 // connection->ConnectToService(&ax_provider);
156 // {
157 // base::RunLoop run_loop;
158 // ax_provider->GetTree(
159 // [&run_loop](Array<AxNodePtr> tree) {
160 // PrintAxTree(tree.Pass());
161 // run_loop.Quit();
162 // });
163 // run_loop.Run();
164 // }
165
166 // // TODO(msw): Connect to the ViewManagerClient service via HTMLDocument... ?
167 // // TODO(msw): Embed the html_viewer for some visible UI? (in another test?)
168 // }
169
170 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/html_viewer/html_viewer.cc ('k') | mojo/services/html_viewer/public/interfaces/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698