OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/services/html_viewer/ax_provider_impl.h" | 5 #include "mojo/services/html_viewer/ax_provider_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/metrics/stats_counters.h" | 9 #include "base/metrics/stats_counters.h" |
10 #include "gin/public/isolate_holder.h" | 10 #include "gin/public/isolate_holder.h" |
11 #include "mojo/services/html_viewer/blink_platform_impl.h" | 11 #include "mojo/services/html_viewer/blink_platform_impl.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "third_party/WebKit/public/platform/WebData.h" | 13 #include "third_party/WebKit/public/platform/WebData.h" |
14 #include "third_party/WebKit/public/platform/WebURL.h" | 14 #include "third_party/WebKit/public/platform/WebURL.h" |
15 #include "third_party/WebKit/public/web/WebFrameClient.h" | 15 #include "third_party/WebKit/public/web/WebFrameClient.h" |
16 #include "third_party/WebKit/public/web/WebKit.h" | 16 #include "third_party/WebKit/public/web/WebKit.h" |
17 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 17 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
18 #include "third_party/WebKit/public/web/WebView.h" | 18 #include "third_party/WebKit/public/web/WebView.h" |
19 #include "third_party/WebKit/public/web/WebViewClient.h" | 19 #include "third_party/WebKit/public/web/WebViewClient.h" |
20 #include "url/gurl.h" | 20 #include "url/gurl.h" |
21 | 21 |
22 using blink::WebData; | 22 using blink::WebData; |
23 using blink::WebLocalFrame; | 23 using blink::WebLocalFrame; |
24 using blink::WebFrameClient; | 24 using blink::WebFrameClient; |
25 using blink::WebURL; | 25 using blink::WebURL; |
26 using blink::WebView; | 26 using blink::WebView; |
27 using blink::WebViewClient; | 27 using blink::WebViewClient; |
28 | 28 |
29 namespace mojo { | 29 using mojo::Array; |
| 30 using mojo::AxNode; |
| 31 using mojo::AxNodePtr; |
30 | 32 |
31 namespace { | 33 namespace { |
32 | 34 |
33 class TestWebFrameClient : public WebFrameClient { | 35 class TestWebFrameClient : public WebFrameClient { |
34 public: | 36 public: |
35 virtual ~TestWebFrameClient() {} | 37 virtual ~TestWebFrameClient() {} |
36 virtual void didStopLoading() { base::MessageLoop::current()->Quit(); } | 38 virtual void didStopLoading() { base::MessageLoop::current()->Quit(); } |
37 }; | 39 }; |
38 | 40 |
39 class TestWebViewClient : public WebViewClient { | 41 class TestWebViewClient : public WebViewClient { |
40 public: | 42 public: |
41 virtual bool allowsBrokenNullLayerTreeView() const { return true; } | 43 virtual bool allowsBrokenNullLayerTreeView() const { return true; } |
42 virtual ~TestWebViewClient() {} | 44 virtual ~TestWebViewClient() {} |
43 }; | 45 }; |
44 | 46 |
45 class AxProviderImplTest : public testing::Test { | 47 class AxProviderImplTest : public testing::Test { |
46 public: | 48 public: |
47 AxProviderImplTest() { | 49 AxProviderImplTest() { |
48 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 50 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
49 gin::IsolateHolder::LoadV8Snapshot(); | 51 gin::IsolateHolder::LoadV8Snapshot(); |
50 #endif | 52 #endif |
51 blink::initialize(new BlinkPlatformImpl()); | 53 blink::initialize(new html_viewer::BlinkPlatformImpl()); |
52 } | 54 } |
53 | 55 |
54 virtual ~AxProviderImplTest() override { blink::shutdown(); } | 56 virtual ~AxProviderImplTest() override { blink::shutdown(); } |
55 | 57 |
56 private: | 58 private: |
57 base::MessageLoopForUI message_loop; | 59 base::MessageLoopForUI message_loop; |
58 }; | 60 }; |
59 | 61 |
60 struct NodeCatcher { | 62 struct NodeCatcher { |
61 void OnNodes(Array<AxNodePtr> nodes) { this->nodes = nodes.Pass(); } | 63 void OnNodes(Array<AxNodePtr> nodes) { this->nodes = nodes.Pass(); } |
62 Array<AxNodePtr> nodes; | 64 Array<AxNodePtr> nodes; |
63 }; | 65 }; |
64 | 66 |
65 AxNodePtr CreateNode(int id, | 67 AxNodePtr CreateNode(int id, |
66 int parent_id, | 68 int parent_id, |
67 int next_sibling_id, | 69 int next_sibling_id, |
68 const RectPtr& bounds, | 70 const mojo::RectPtr& bounds, |
69 const std::string& url, | 71 const std::string& url, |
70 const std::string& text) { | 72 const std::string& text) { |
71 AxNodePtr node(AxNode::New()); | 73 AxNodePtr node(AxNode::New()); |
72 node->id = id; | 74 node->id = id; |
73 node->parent_id = parent_id; | 75 node->parent_id = parent_id; |
74 node->next_sibling_id = next_sibling_id; | 76 node->next_sibling_id = next_sibling_id; |
75 node->bounds = bounds.Clone(); | 77 node->bounds = bounds.Clone(); |
76 | 78 |
77 if (!url.empty()) { | 79 if (!url.empty()) { |
78 node->link = AxLink::New(); | 80 node->link = mojo::AxLink::New(); |
79 node->link->url = url; | 81 node->link->url = url; |
80 } | 82 } |
81 if (!text.empty()) { | 83 if (!text.empty()) { |
82 node->text = AxText::New(); | 84 node->text = mojo::AxText::New(); |
83 node->text->content = text; | 85 node->text->content = text; |
84 } | 86 } |
85 return node.Pass(); | 87 return node.Pass(); |
86 } | 88 } |
87 | 89 |
88 } // namespace | 90 } // namespace |
89 | 91 |
90 TEST_F(AxProviderImplTest, Basic) { | 92 TEST_F(AxProviderImplTest, Basic) { |
91 TestWebViewClient web_view_client; | 93 TestWebViewClient web_view_client; |
92 TestWebFrameClient web_frame_client; | 94 TestWebFrameClient web_frame_client; |
93 WebView* view = WebView::create(&web_view_client); | 95 WebView* view = WebView::create(&web_view_client); |
94 view->setMainFrame(WebLocalFrame::create(&web_frame_client)); | 96 view->setMainFrame(WebLocalFrame::create(&web_frame_client)); |
95 view->mainFrame()->loadHTMLString( | 97 view->mainFrame()->loadHTMLString( |
96 WebData( | 98 WebData( |
97 "<html><body>foo<a " | 99 "<html><body>foo<a " |
98 "href='http://monkey.net'>bar</a>baz</body></html>"), | 100 "href='http://monkey.net'>bar</a>baz</body></html>"), |
99 WebURL(GURL("http://someplace.net"))); | 101 WebURL(GURL("http://someplace.net"))); |
100 base::MessageLoop::current()->Run(); | 102 base::MessageLoop::current()->Run(); |
101 | 103 |
102 AxProviderImpl ax_provider_impl(view); | 104 html_viewer::AxProviderImpl ax_provider_impl(view); |
103 NodeCatcher catcher; | 105 NodeCatcher catcher; |
104 ax_provider_impl.GetTree( | 106 ax_provider_impl.GetTree( |
105 base::Bind(&NodeCatcher::OnNodes, base::Unretained(&catcher))); | 107 base::Bind(&NodeCatcher::OnNodes, base::Unretained(&catcher))); |
106 | 108 |
107 std::map<uint32, AxNode*> lookup; | 109 std::map<uint32, AxNode*> lookup; |
108 for (size_t i = 0; i < catcher.nodes.size(); ++i) { | 110 for (size_t i = 0; i < catcher.nodes.size(); ++i) { |
109 auto& node = catcher.nodes[i]; | 111 auto& node = catcher.nodes[i]; |
110 lookup[node->id] = node.get(); | 112 lookup[node->id] = node.get(); |
111 } | 113 } |
112 | 114 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 "", | 170 "", |
169 "")); | 171 "")); |
170 } | 172 } |
171 } | 173 } |
172 | 174 |
173 // TODO(aa): Test bounds. | 175 // TODO(aa): Test bounds. |
174 // TODO(aa): Test sibling ordering of foo/bar/baz. | 176 // TODO(aa): Test sibling ordering of foo/bar/baz. |
175 | 177 |
176 view->close(); | 178 view->close(); |
177 } | 179 } |
178 | |
179 } // namespace mojo | |
OLD | NEW |