OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/scoped_ptr.h" | 5 #include "base/scoped_ptr.h" |
6 #include "base/string16.h" | 6 #include "base/string16.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "webkit/glue/webaccessibility.h" | 10 #include "webkit/glue/webaccessibility.h" |
11 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" |
12 | 12 |
13 TEST(RenderMessagesUnittest, WebAccessibility) { | 13 TEST(RenderMessagesUnittest, WebAccessibility) { |
14 // Test a simple case. | 14 // Test a simple case. |
15 webkit_glue::WebAccessibility input; | 15 webkit_glue::WebAccessibility input; |
16 input.id = 123; | 16 input.id = 123; |
17 input.name = ASCIIToUTF16("name"); | 17 input.name = ASCIIToUTF16("name"); |
18 input.value = ASCIIToUTF16("value"); | 18 input.value = ASCIIToUTF16("value"); |
19 string16 help = ASCIIToUTF16("help"); | 19 string16 help = ASCIIToUTF16("help"); |
20 input.attributes[webkit_glue::WebAccessibility::ATTR_HELP] = help; | 20 input.attributes[webkit_glue::WebAccessibility::ATTR_HELP] = help; |
21 input.role = webkit_glue::WebAccessibility::ROLE_CHECKBOX; | 21 input.role = webkit_glue::WebAccessibility::ROLE_CHECKBOX; |
22 input.state = | 22 input.state = |
23 (1 << webkit_glue::WebAccessibility::STATE_CHECKED) | | 23 (1 << webkit_glue::WebAccessibility::STATE_CHECKED) | |
24 (1 << webkit_glue::WebAccessibility::STATE_FOCUSED); | 24 (1 << webkit_glue::WebAccessibility::STATE_FOCUSED); |
25 input.location = WebKit::WebRect(11, 22, 333, 444); | 25 input.location = WebKit::WebRect(11, 22, 333, 444); |
26 input.html_attributes.push_back( | |
27 std::pair<string16, string16>(ASCIIToUTF16("id"), ASCIIToUTF16("a"))); | |
28 input.html_attributes.push_back( | |
29 std::pair<string16, string16>(ASCIIToUTF16("class"), ASCIIToUTF16("b"))); | |
30 | 26 |
31 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 27 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
32 IPC::WriteParam(&msg, input); | 28 IPC::WriteParam(&msg, input); |
33 | 29 |
34 webkit_glue::WebAccessibility output; | 30 webkit_glue::WebAccessibility output; |
35 void* iter = NULL; | 31 void* iter = NULL; |
36 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); | 32 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); |
37 EXPECT_EQ(input.id, output.id); | 33 EXPECT_EQ(input.id, output.id); |
38 EXPECT_EQ(input.name, output.name); | 34 EXPECT_EQ(input.name, output.name); |
39 EXPECT_EQ(input.value, output.value); | 35 EXPECT_EQ(input.value, output.value); |
40 EXPECT_EQ(static_cast<size_t>(1), input.attributes.size()); | 36 EXPECT_EQ(static_cast<size_t>(1), input.attributes.size()); |
41 EXPECT_EQ(help, input.attributes[webkit_glue::WebAccessibility::ATTR_HELP]); | 37 EXPECT_EQ(help, input.attributes[webkit_glue::WebAccessibility::ATTR_HELP]); |
42 EXPECT_EQ(input.role, output.role); | 38 EXPECT_EQ(input.role, output.role); |
43 EXPECT_EQ(input.state, output.state); | 39 EXPECT_EQ(input.state, output.state); |
44 EXPECT_EQ(input.location, output.location); | 40 EXPECT_EQ(input.location, output.location); |
45 EXPECT_EQ(input.children.size(), output.children.size()); | 41 EXPECT_EQ(input.children.size(), output.children.size()); |
46 EXPECT_EQ(input.html_attributes.size(), output.html_attributes.size()); | |
47 EXPECT_EQ(input.html_attributes[0].first, | |
48 output.html_attributes[0].first); | |
49 EXPECT_EQ(input.html_attributes[0].second, | |
50 output.html_attributes[0].second); | |
51 EXPECT_EQ(input.html_attributes[1].first, | |
52 output.html_attributes[1].first); | |
53 EXPECT_EQ(input.html_attributes[1].second, | |
54 output.html_attributes[1].second); | |
55 | 42 |
56 // Test a corrupt case. | 43 // Test a corrupt case. |
57 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 44 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
58 bad_msg.WriteInt(99); | 45 bad_msg.WriteInt(99); |
59 iter = NULL; | 46 iter = NULL; |
60 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); | 47 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); |
61 | 48 |
62 // Test a recursive case. | 49 // Test a recursive case. |
63 webkit_glue::WebAccessibility outer; | 50 webkit_glue::WebAccessibility outer; |
64 outer.id = 1000; | 51 outer.id = 1000; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 EXPECT_EQ(inner1.name, output.children[0].name); | 85 EXPECT_EQ(inner1.name, output.children[0].name); |
99 EXPECT_EQ(inner1.role, output.children[0].role); | 86 EXPECT_EQ(inner1.role, output.children[0].role); |
100 EXPECT_EQ(inner1.state, output.children[0].state); | 87 EXPECT_EQ(inner1.state, output.children[0].state); |
101 EXPECT_EQ(inner1.location, output.children[0].location); | 88 EXPECT_EQ(inner1.location, output.children[0].location); |
102 EXPECT_EQ(inner2.id, output.children[1].id); | 89 EXPECT_EQ(inner2.id, output.children[1].id); |
103 EXPECT_EQ(inner2.name, output.children[1].name); | 90 EXPECT_EQ(inner2.name, output.children[1].name); |
104 EXPECT_EQ(inner2.role, output.children[1].role); | 91 EXPECT_EQ(inner2.role, output.children[1].role); |
105 EXPECT_EQ(inner2.state, output.children[1].state); | 92 EXPECT_EQ(inner2.state, output.children[1].state); |
106 EXPECT_EQ(inner2.location, output.children[1].location); | 93 EXPECT_EQ(inner2.location, output.children[1].location); |
107 } | 94 } |
OLD | NEW |