OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
10 #include "components/mus/public/cpp/tests/view_manager_test_base.h" | 10 #include "components/mus/public/cpp/tests/view_manager_test_base.h" |
11 #include "components/mus/public/cpp/view.h" | 11 #include "components/mus/public/cpp/view.h" |
12 #include "components/mus/public/cpp/view_tree_connection.h" | 12 #include "components/mus/public/cpp/view_tree_connection.h" |
13 #include "components/web_view/public/interfaces/frame_tree.mojom.h" | 13 #include "components/web_view/public/interfaces/frame.mojom.h" |
14 #include "mojo/application/public/cpp/application_impl.h" | 14 #include "mojo/application/public/cpp/application_impl.h" |
15 #include "mojo/application/public/cpp/application_test_base.h" | 15 #include "mojo/application/public/cpp/application_test_base.h" |
16 #include "net/test/spawned_test_server/spawned_test_server.h" | 16 #include "net/test/spawned_test_server/spawned_test_server.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "third_party/mojo_services/src/accessibility/public/interfaces/accessib
ility.mojom.h" | 18 #include "third_party/mojo_services/src/accessibility/public/interfaces/accessib
ility.mojom.h" |
19 | 19 |
20 namespace mojo { | 20 namespace mojo { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Returns true if the tree contains a text node with contents matching |text|. | 24 // Returns true if the tree contains a text node with contents matching |text|. |
25 bool AxTreeContainsText(const Array<AxNodePtr>& tree, const String& text) { | 25 bool AxTreeContainsText(const Array<AxNodePtr>& tree, const String& text) { |
26 for (size_t i = 0; i < tree.size(); ++i) { | 26 for (size_t i = 0; i < tree.size(); ++i) { |
27 if (!tree[i]->text.is_null() && tree[i]->text->content == text) | 27 if (!tree[i]->text.is_null() && tree[i]->text->content == text) |
28 return true; | 28 return true; |
29 } | 29 } |
30 return false; | 30 return false; |
31 } | 31 } |
32 | 32 |
33 class TestFrameTreeServer : public web_view::FrameTreeServer { | 33 class TestFrame : public web_view::mojom::Frame { |
34 public: | 34 public: |
35 TestFrameTreeServer() {} | 35 TestFrame() {} |
36 ~TestFrameTreeServer() override {} | 36 ~TestFrame() override {} |
37 | 37 |
38 // web_view::FrameTreeServer: | 38 // web_view::mojom::Frame: |
39 void PostMessageEventToFrame(uint32_t target_frame_id, | 39 void PostMessageEventToFrame( |
40 web_view::HTMLMessageEventPtr event) override {} | 40 uint32_t target_frame_id, |
| 41 web_view::mojom::HTMLMessageEventPtr event) override {} |
41 void LoadingStateChanged(bool loading, double progress) override {} | 42 void LoadingStateChanged(bool loading, double progress) override {} |
42 void TitleChanged(const mojo::String& title) override {} | 43 void TitleChanged(const mojo::String& title) override {} |
43 void DidCommitProvisionalLoad() override {} | 44 void DidCommitProvisionalLoad() override {} |
44 void SetClientProperty(const mojo::String& name, | 45 void SetClientProperty(const mojo::String& name, |
45 mojo::Array<uint8_t> value) override {} | 46 mojo::Array<uint8_t> value) override {} |
46 void OnCreatedFrame( | 47 void OnCreatedFrame( |
47 mojo::InterfaceRequest<web_view::FrameTreeServer> server_request, | 48 mojo::InterfaceRequest<web_view::mojom::Frame> frame_request, |
48 web_view::FrameTreeClientPtr client, | 49 web_view::mojom::FrameClientPtr client, |
49 uint32_t frame_id, | 50 uint32_t frame_id, |
50 mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties) | 51 mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties) |
51 override {} | 52 override {} |
52 void RequestNavigate(web_view::NavigationTargetType target_type, | 53 void RequestNavigate(web_view::mojom::NavigationTargetType target_type, |
53 uint32_t target_frame_id, | 54 uint32_t target_frame_id, |
54 mojo::URLRequestPtr request) override {} | 55 mojo::URLRequestPtr request) override {} |
55 void DidNavigateLocally(const mojo::String& url) override {} | 56 void DidNavigateLocally(const mojo::String& url) override {} |
56 void DispatchLoadEventToParent() override {} | 57 void DispatchLoadEventToParent() override {} |
57 | 58 |
58 private: | 59 private: |
59 DISALLOW_COPY_AND_ASSIGN(TestFrameTreeServer); | 60 DISALLOW_COPY_AND_ASSIGN(TestFrame); |
60 }; | 61 }; |
61 | 62 |
62 } // namespace | 63 } // namespace |
63 | 64 |
64 using AXProviderTest = mus::ViewManagerTestBase; | 65 using AXProviderTest = mus::ViewManagerTestBase; |
65 | 66 |
66 TEST_F(AXProviderTest, HelloWorld) { | 67 TEST_F(AXProviderTest, HelloWorld) { |
67 // Start a test server for net/data/test.html access. | 68 // Start a test server for net/data/test.html access. |
68 net::SpawnedTestServer server( | 69 net::SpawnedTestServer server( |
69 net::SpawnedTestServer::TYPE_HTTP, net::SpawnedTestServer::kLocalhost, | 70 net::SpawnedTestServer::TYPE_HTTP, net::SpawnedTestServer::kLocalhost, |
70 base::FilePath(FILE_PATH_LITERAL("net/data"))); | 71 base::FilePath(FILE_PATH_LITERAL("net/data"))); |
71 ASSERT_TRUE(server.Start()); | 72 ASSERT_TRUE(server.Start()); |
72 | 73 |
73 // Connect to the URL through the mojo:html_viewer content handler. | 74 // Connect to the URL through the mojo:html_viewer content handler. |
74 const uint16_t assigned_port = server.host_port_pair().port(); | 75 const uint16_t assigned_port = server.host_port_pair().port(); |
75 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 76 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
76 request->url = mojo::String::From( | 77 request->url = mojo::String::From( |
77 base::StringPrintf("http://127.0.0.1:%u/files/test.html", assigned_port)); | 78 base::StringPrintf("http://127.0.0.1:%u/files/test.html", assigned_port)); |
78 scoped_ptr<ApplicationConnection> connection = | 79 scoped_ptr<ApplicationConnection> connection = |
79 application_impl()->ConnectToApplication(request.Pass()); | 80 application_impl()->ConnectToApplication(request.Pass()); |
80 | 81 |
81 // Embed the html_viewer in a View. | 82 // Embed the html_viewer in a View. |
82 ViewTreeClientPtr tree_client; | 83 ViewTreeClientPtr tree_client; |
83 connection->ConnectToService(&tree_client); | 84 connection->ConnectToService(&tree_client); |
84 mus::View* embed_view = window_manager()->CreateView(); | 85 mus::View* embed_view = window_manager()->CreateView(); |
85 embed_view->Embed(tree_client.Pass()); | 86 embed_view->Embed(tree_client.Pass()); |
86 | 87 |
87 TestFrameTreeServer frame_tree_server; | 88 TestFrame frame; |
88 web_view::FrameTreeServerPtr frame_tree_server_ptr; | 89 web_view::mojom::FramePtr frame_ptr; |
89 mojo::Binding<web_view::FrameTreeServer> frame_tree_server_binding( | 90 mojo::Binding<web_view::mojom::Frame> frame_binding(&frame); |
90 &frame_tree_server); | 91 frame_binding.Bind(GetProxy(&frame_ptr).Pass()); |
91 frame_tree_server_binding.Bind(GetProxy(&frame_tree_server_ptr).Pass()); | |
92 | 92 |
93 mojo::Array<web_view::FrameDataPtr> array(1u); | 93 mojo::Array<web_view::mojom::FrameDataPtr> array(1u); |
94 array[0] = web_view::FrameData::New().Pass(); | 94 array[0] = web_view::mojom::FrameData::New().Pass(); |
95 array[0]->frame_id = embed_view->id(); | 95 array[0]->frame_id = embed_view->id(); |
96 array[0]->parent_id = 0u; | 96 array[0]->parent_id = 0u; |
97 | 97 |
98 web_view::FrameTreeClientPtr frame_tree_client; | 98 web_view::mojom::FrameClientPtr frame_client; |
99 connection->ConnectToService(&frame_tree_client); | 99 connection->ConnectToService(&frame_client); |
100 frame_tree_client->OnConnect( | 100 frame_client->OnConnect(frame_ptr.Pass(), 1u, embed_view->id(), |
101 frame_tree_server_ptr.Pass(), 1u, embed_view->id(), | 101 web_view::mojom::VIEW_CONNECT_TYPE_USE_NEW, |
102 web_view::VIEW_CONNECT_TYPE_USE_NEW, array.Pass(), base::Closure()); | 102 array.Pass(), base::Closure()); |
103 | 103 |
104 // Connect to the AxProvider of the HTML document and get the AxTree. | 104 // Connect to the AxProvider of the HTML document and get the AxTree. |
105 AxProviderPtr ax_provider; | 105 AxProviderPtr ax_provider; |
106 connection->ConnectToService(&ax_provider); | 106 connection->ConnectToService(&ax_provider); |
107 Array<AxNodePtr> ax_tree; | 107 Array<AxNodePtr> ax_tree; |
108 ax_provider->GetTree([&ax_tree](Array<AxNodePtr> tree) { | 108 ax_provider->GetTree([&ax_tree](Array<AxNodePtr> tree) { |
109 ax_tree = tree.Pass(); | 109 ax_tree = tree.Pass(); |
110 EXPECT_TRUE(QuitRunLoop()); | 110 EXPECT_TRUE(QuitRunLoop()); |
111 }); | 111 }); |
112 ASSERT_TRUE(DoRunLoopWithTimeout()); | 112 ASSERT_TRUE(DoRunLoopWithTimeout()); |
113 | 113 |
114 EXPECT_TRUE(AxTreeContainsText(ax_tree, "Hello ")); | 114 EXPECT_TRUE(AxTreeContainsText(ax_tree, "Hello ")); |
115 EXPECT_TRUE(AxTreeContainsText(ax_tree, "World!")); | 115 EXPECT_TRUE(AxTreeContainsText(ax_tree, "World!")); |
116 EXPECT_FALSE(AxTreeContainsText(ax_tree, "foo")); | 116 EXPECT_FALSE(AxTreeContainsText(ax_tree, "foo")); |
117 } | 117 } |
118 | 118 |
119 } // namespace mojo | 119 } // namespace mojo |
OLD | NEW |