| 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"))); |
| 26 | 30 |
| 27 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 31 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 28 IPC::WriteParam(&msg, input); | 32 IPC::WriteParam(&msg, input); |
| 29 | 33 |
| 30 webkit_glue::WebAccessibility output; | 34 webkit_glue::WebAccessibility output; |
| 31 void* iter = NULL; | 35 void* iter = NULL; |
| 32 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); | 36 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); |
| 33 EXPECT_EQ(input.id, output.id); | 37 EXPECT_EQ(input.id, output.id); |
| 34 EXPECT_EQ(input.name, output.name); | 38 EXPECT_EQ(input.name, output.name); |
| 35 EXPECT_EQ(input.value, output.value); | 39 EXPECT_EQ(input.value, output.value); |
| 36 EXPECT_EQ(static_cast<size_t>(1), input.attributes.size()); | 40 EXPECT_EQ(static_cast<size_t>(1), input.attributes.size()); |
| 37 EXPECT_EQ(help, input.attributes[webkit_glue::WebAccessibility::ATTR_HELP]); | 41 EXPECT_EQ(help, input.attributes[webkit_glue::WebAccessibility::ATTR_HELP]); |
| 38 EXPECT_EQ(input.role, output.role); | 42 EXPECT_EQ(input.role, output.role); |
| 39 EXPECT_EQ(input.state, output.state); | 43 EXPECT_EQ(input.state, output.state); |
| 40 EXPECT_EQ(input.location, output.location); | 44 EXPECT_EQ(input.location, output.location); |
| 41 EXPECT_EQ(input.children.size(), output.children.size()); | 45 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); |
| 42 | 55 |
| 43 // Test a corrupt case. | 56 // Test a corrupt case. |
| 44 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 57 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 45 bad_msg.WriteInt(99); | 58 bad_msg.WriteInt(99); |
| 46 iter = NULL; | 59 iter = NULL; |
| 47 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); | 60 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); |
| 48 | 61 |
| 49 // Test a recursive case. | 62 // Test a recursive case. |
| 50 webkit_glue::WebAccessibility outer; | 63 webkit_glue::WebAccessibility outer; |
| 51 outer.id = 1000; | 64 outer.id = 1000; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 EXPECT_EQ(inner1.name, output.children[0].name); | 98 EXPECT_EQ(inner1.name, output.children[0].name); |
| 86 EXPECT_EQ(inner1.role, output.children[0].role); | 99 EXPECT_EQ(inner1.role, output.children[0].role); |
| 87 EXPECT_EQ(inner1.state, output.children[0].state); | 100 EXPECT_EQ(inner1.state, output.children[0].state); |
| 88 EXPECT_EQ(inner1.location, output.children[0].location); | 101 EXPECT_EQ(inner1.location, output.children[0].location); |
| 89 EXPECT_EQ(inner2.id, output.children[1].id); | 102 EXPECT_EQ(inner2.id, output.children[1].id); |
| 90 EXPECT_EQ(inner2.name, output.children[1].name); | 103 EXPECT_EQ(inner2.name, output.children[1].name); |
| 91 EXPECT_EQ(inner2.role, output.children[1].role); | 104 EXPECT_EQ(inner2.role, output.children[1].role); |
| 92 EXPECT_EQ(inner2.state, output.children[1].state); | 105 EXPECT_EQ(inner2.state, output.children[1].state); |
| 93 EXPECT_EQ(inner2.location, output.children[1].location); | 106 EXPECT_EQ(inner2.location, output.children[1].location); |
| 94 } | 107 } |
| OLD | NEW |