OLD | NEW |
| (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 <stddef.h> | |
6 #include <stdint.h> | |
7 #include <utility> | |
8 | |
9 #include "base/bind.h" | |
10 #include "base/command_line.h" | |
11 #include "base/macros.h" | |
12 #include "base/run_loop.h" | |
13 #include "base/strings/stringprintf.h" | |
14 #include "base/test/test_timeouts.h" | |
15 #include "base/time/time.h" | |
16 #include "components/mus/public/cpp/tests/window_server_test_base.h" | |
17 #include "components/mus/public/cpp/window.h" | |
18 #include "components/mus/public/cpp/window_tree_connection.h" | |
19 #include "components/web_view/public/interfaces/frame.mojom.h" | |
20 #include "mojo/converters/network/network_type_converters.h" | |
21 #include "mojo/services/accessibility/public/interfaces/accessibility.mojom.h" | |
22 #include "mojo/shell/public/cpp/application_test_base.h" | |
23 #include "net/test/embedded_test_server/embedded_test_server.h" | |
24 #include "testing/gtest/include/gtest/gtest.h" | |
25 | |
26 namespace mojo { | |
27 | |
28 namespace { | |
29 | |
30 // Returns true if the tree contains a text node with contents matching |text|. | |
31 bool AxTreeContainsText(const Array<AxNodePtr>& tree, const String& text) { | |
32 for (size_t i = 0; i < tree.size(); ++i) { | |
33 if (!tree[i]->text.is_null() && tree[i]->text->content == text) | |
34 return true; | |
35 } | |
36 return false; | |
37 } | |
38 | |
39 class TestFrame : public web_view::mojom::Frame { | |
40 public: | |
41 TestFrame() {} | |
42 ~TestFrame() override {} | |
43 | |
44 // web_view::mojom::Frame: | |
45 void PostMessageEventToFrame( | |
46 uint32_t target_frame_id, | |
47 web_view::mojom::HTMLMessageEventPtr event) override {} | |
48 void LoadingStateChanged(bool loading, double progress) override {} | |
49 void TitleChanged(const mojo::String& title) override {} | |
50 void DidCommitProvisionalLoad() override {} | |
51 void SetClientProperty(const mojo::String& name, | |
52 mojo::Array<uint8_t> value) override {} | |
53 void OnCreatedFrame( | |
54 mojo::InterfaceRequest<web_view::mojom::Frame> frame_request, | |
55 web_view::mojom::FrameClientPtr client, | |
56 uint32_t frame_id, | |
57 mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties) | |
58 override {} | |
59 void RequestNavigate(web_view::mojom::NavigationTargetType target_type, | |
60 uint32_t target_frame_id, | |
61 mojo::URLRequestPtr request) override {} | |
62 void DidNavigateLocally(const mojo::String& url) override {} | |
63 void DispatchLoadEventToParent() override {} | |
64 void OnFindInFrameCountUpdated(int32_t request_id, | |
65 int32_t count, | |
66 bool final_update) override {} | |
67 void OnFindInPageSelectionUpdated(int32_t request_id, | |
68 int32_t active_match_ordinal) override {} | |
69 | |
70 private: | |
71 DISALLOW_COPY_AND_ASSIGN(TestFrame); | |
72 }; | |
73 | |
74 } // namespace | |
75 | |
76 using AXProviderTest = mus::WindowServerTestBase; | |
77 | |
78 TEST_F(AXProviderTest, HelloWorld) { | |
79 // Start a test server for net/data/test.html access. | |
80 net::EmbeddedTestServer server; | |
81 server.ServeFilesFromSourceDirectory("net/data"); | |
82 ASSERT_TRUE(server.Start()); | |
83 | |
84 // Connect to the URL through the mojo:html_viewer content handler. | |
85 scoped_ptr<Connection> connection = | |
86 shell()->Connect(server.GetURL("/test.html").spec()); | |
87 | |
88 // Embed the html_viewer in a Window. | |
89 mus::mojom::WindowTreeClientPtr tree_client; | |
90 connection->ConnectToService(&tree_client); | |
91 mus::Window* embed_window = window_manager()->NewWindow(); | |
92 embed_window->Embed(std::move(tree_client)); | |
93 | |
94 TestFrame frame; | |
95 web_view::mojom::FramePtr frame_ptr; | |
96 mojo::Binding<web_view::mojom::Frame> frame_binding(&frame); | |
97 frame_binding.Bind(GetProxy(&frame_ptr)); | |
98 | |
99 mojo::Array<web_view::mojom::FrameDataPtr> array(1u); | |
100 array[0] = web_view::mojom::FrameData::New(); | |
101 array[0]->frame_id = embed_window->id(); | |
102 array[0]->parent_id = 0u; | |
103 | |
104 web_view::mojom::FrameClientPtr frame_client; | |
105 connection->ConnectToService(&frame_client); | |
106 frame_client->OnConnect( | |
107 std::move(frame_ptr), 1u, embed_window->id(), | |
108 web_view::mojom::WindowConnectType::USE_NEW, std::move(array), | |
109 base::TimeTicks::Now().ToInternalValue(), base::Closure()); | |
110 | |
111 // Connect to the AxProvider of the HTML document and get the AxTree. | |
112 AxProviderPtr ax_provider; | |
113 connection->ConnectToService(&ax_provider); | |
114 Array<AxNodePtr> ax_tree; | |
115 ax_provider->GetTree([&ax_tree](Array<AxNodePtr> tree) { | |
116 ax_tree = std::move(tree); | |
117 EXPECT_TRUE(QuitRunLoop()); | |
118 }); | |
119 ASSERT_TRUE(DoRunLoopWithTimeout()); | |
120 | |
121 EXPECT_TRUE(AxTreeContainsText(ax_tree, "Hello ")); | |
122 EXPECT_TRUE(AxTreeContainsText(ax_tree, "World!")); | |
123 EXPECT_FALSE(AxTreeContainsText(ax_tree, "foo")); | |
124 } | |
125 | |
126 } // namespace mojo | |
OLD | NEW |