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

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

Issue 1099303002: Move html_viewer from mojo/services to components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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 "base/test/test_timeouts.h"
9 #include "mojo/application/application_test_base_chromium.h"
10 #include "mojo/public/cpp/application/application_impl.h"
11 #include "net/test/spawned_test_server/spawned_test_server.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/mojo_services/src/accessibility/public/interfaces/accessib ility.mojom.h"
14
15 namespace mojo {
16
17 namespace {
18
19 base::RunLoop* current_run_loop = nullptr;
20
21 void TimeoutRunLoop(const base::Closure& timeout_task, bool* timeout) {
22 CHECK(current_run_loop);
23 *timeout = true;
24 timeout_task.Run();
25 }
26
27 bool DoRunLoopWithTimeout() {
28 if (current_run_loop != nullptr)
29 return false;
30
31 bool timeout = false;
32 base::RunLoop run_loop;
33 base::MessageLoop::current()->PostDelayedTask(
34 FROM_HERE, base::Bind(&TimeoutRunLoop, run_loop.QuitClosure(), &timeout),
35 TestTimeouts::action_timeout());
36
37 current_run_loop = &run_loop;
38 current_run_loop->Run();
39 current_run_loop = nullptr;
40 return !timeout;
41 }
42
43 void QuitRunLoop() {
44 current_run_loop->Quit();
45 current_run_loop = nullptr;
46 }
47
48 // Returns true if the tree contains a text node with contents matching |text|.
49 bool AxTreeContainsText(const Array<AxNodePtr>& tree, const String& text) {
50 for (size_t i = 0; i < tree.size(); ++i) {
51 if (!tree[i]->text.is_null() && tree[i]->text->content == text)
52 return true;
53 }
54 return false;
55 }
56
57 } // namespace
58
59 typedef test::ApplicationTestBase AXProviderTest;
60
61 TEST_F(AXProviderTest, HelloWorld) {
62 // Start a test server for net/data/test.html access.
63 net::SpawnedTestServer server(
64 net::SpawnedTestServer::TYPE_HTTP, net::SpawnedTestServer::kLocalhost,
65 base::FilePath(FILE_PATH_LITERAL("net/data")));
66 ASSERT_TRUE(server.Start());
67
68 // Connect to the URL through the mojo:html_viewer content handler.
69 const uint16_t assigned_port = server.host_port_pair().port();
70 ApplicationConnection* connection = application_impl()->ConnectToApplication(
71 base::StringPrintf("http://127.0.0.1:%u/files/test.html", assigned_port));
72
73 // Connect to the AxProvider of the HTML document and get the AxTree.
74 AxProviderPtr ax_provider;
75 connection->ConnectToService(&ax_provider);
76 Array<AxNodePtr> ax_tree;
77 ax_provider->GetTree([&ax_tree](Array<AxNodePtr> tree) {
78 ax_tree = tree.Pass();
79 QuitRunLoop();
80 });
81 ASSERT_TRUE(DoRunLoopWithTimeout());
82
83 EXPECT_TRUE(AxTreeContainsText(ax_tree, "Hello "));
84 EXPECT_TRUE(AxTreeContainsText(ax_tree, "World!"));
85 EXPECT_FALSE(AxTreeContainsText(ax_tree, "foo"));
86 }
87
88 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698