Chromium Code Reviews| Index: content/browser/accessibility/accessibility_win_browsertest.cc |
| diff --git a/content/browser/accessibility/accessibility_win_browsertest.cc b/content/browser/accessibility/accessibility_win_browsertest.cc |
| index e70b82f776838e43bc38e2a49b913862a1de0ad8..a759e62b5fb0617b9e47fb40b19aae6e29ac7411 100644 |
| --- a/content/browser/accessibility/accessibility_win_browsertest.cc |
| +++ b/content/browser/accessibility/accessibility_win_browsertest.cc |
| @@ -63,6 +63,8 @@ class AccessibilityWinBrowserTest : public ContentBrowserTest { |
| base::win::ScopedComPtr<IAccessibleText>* input_text); |
| void SetUpTextareaField( |
| base::win::ScopedComPtr<IAccessibleText>* textarea_text); |
| + void SetUpSampleParagraph( |
| + base::win::ScopedComPtr<IAccessibleText>* paragraph_text); |
| static base::win::ScopedComPtr<IAccessible> GetAccessibleFromVariant( |
| IAccessible* parent, |
| @@ -75,7 +77,7 @@ class AccessibilityWinBrowserTest : public ContentBrowserTest { |
| int32_t depth, |
| bool* found); |
| static void CheckTextAtOffset( |
| - base::win::ScopedComPtr<IAccessibleText>& element, |
| + base::win::ScopedComPtr<IAccessibleText>& object, |
| LONG offset, |
| IA2TextBoundaryType boundary_type, |
| LONG expected_start_offset, |
| @@ -133,26 +135,25 @@ void AccessibilityWinBrowserTest::SetUpInputField( |
| ASSERT_EQ(1u, document_children.size()); |
| base::win::ScopedComPtr<IAccessible2> form; |
| - HRESULT hr = QueryIAccessible2(GetAccessibleFromVariant( |
| - document.get(), document_children[0].AsInput()).get(), form.Receive()); |
| - ASSERT_EQ(S_OK, hr); |
| + ASSERT_HRESULT_SUCCEEDED(QueryIAccessible2( |
| + GetAccessibleFromVariant(document.get(), document_children[0].AsInput()) |
| + .get(), |
| + form.Receive())); |
| std::vector<base::win::ScopedVariant> form_children = |
| GetAllAccessibleChildren(form.get()); |
| ASSERT_EQ(2u, form_children.size()); |
| // Find the input text field. |
| base::win::ScopedComPtr<IAccessible2> input; |
| - hr = QueryIAccessible2(GetAccessibleFromVariant( |
| - form.get(), form_children[1].AsInput()).get(), input.Receive()); |
| - ASSERT_EQ(S_OK, hr); |
| + ASSERT_HRESULT_SUCCEEDED(QueryIAccessible2( |
| + GetAccessibleFromVariant(form.get(), form_children[1].AsInput()).get(), |
| + input.Receive())); |
| LONG input_role = 0; |
| - hr = input->role(&input_role); |
| - ASSERT_EQ(S_OK, hr); |
| + ASSERT_HRESULT_SUCCEEDED(input->role(&input_role)); |
| ASSERT_EQ(ROLE_SYSTEM_TEXT, input_role); |
| // Retrieve the IAccessibleText interface for the field. |
| - hr = input.QueryInterface(input_text->Receive()); |
| - ASSERT_EQ(S_OK, hr); |
| + ASSERT_HRESULT_SUCCEEDED(input.QueryInterface(input_text->Receive())); |
| // Set the caret on the last character. |
| AccessibilityNotificationWaiter waiter( |
| @@ -185,26 +186,26 @@ void AccessibilityWinBrowserTest::SetUpTextareaField( |
| ASSERT_EQ(1u, document_children.size()); |
| base::win::ScopedComPtr<IAccessible2> section; |
| - HRESULT hr = QueryIAccessible2(GetAccessibleFromVariant( |
| - document.get(), document_children[0].AsInput()).get(), section.Receive()); |
| - ASSERT_EQ(S_OK, hr); |
| + ASSERT_HRESULT_SUCCEEDED(QueryIAccessible2( |
| + GetAccessibleFromVariant(document.get(), document_children[0].AsInput()) |
| + .get(), |
| + section.Receive())); |
| std::vector<base::win::ScopedVariant> section_children = |
| GetAllAccessibleChildren(section.get()); |
| ASSERT_EQ(1u, section_children.size()); |
| // Find the textarea text field. |
| base::win::ScopedComPtr<IAccessible2> textarea; |
| - hr = QueryIAccessible2(GetAccessibleFromVariant( |
| - section.get(), section_children[0].AsInput()).get(), textarea.Receive()); |
| - ASSERT_EQ(S_OK, hr); |
| + ASSERT_HRESULT_SUCCEEDED(QueryIAccessible2( |
| + GetAccessibleFromVariant(section.get(), section_children[0].AsInput()) |
| + .get(), |
| + textarea.Receive())); |
| LONG textarea_role = 0; |
| - hr = textarea->role(&textarea_role); |
| - ASSERT_EQ(S_OK, hr); |
| + ASSERT_HRESULT_SUCCEEDED(textarea->role(&textarea_role)); |
| ASSERT_EQ(ROLE_SYSTEM_TEXT, textarea_role); |
| // Retrieve the IAccessibleText interface for the field. |
| - hr = textarea.QueryInterface(textarea_text->Receive()); |
| - ASSERT_EQ(S_OK, hr); |
| + ASSERT_HRESULT_SUCCEEDED(textarea.QueryInterface(textarea_text->Receive())); |
| // Set the caret on the last character. |
| AccessibilityNotificationWaiter waiter( |
| @@ -220,6 +221,35 @@ void AccessibilityWinBrowserTest::SetUpTextareaField( |
| waiter.WaitForNotification(); |
| } |
| +// Loads a page with a paragraph of sample text. |
| +// (This is an actual test case provided by Freedom Scientific as part of a bug |
| +// report.) |
| +void AccessibilityWinBrowserTest::SetUpSampleParagraph( |
| + base::win::ScopedComPtr<IAccessibleText>* paragraph_text) { |
| + ASSERT_NE(nullptr, paragraph_text); |
| + LoadInitialAccessibilityTreeFromHtml(std::string( |
| + "<!DOCTYPE html><html><body>" |
| + "<p><b>Game theory</b> is \"the study of " |
| + "<a href=\"#\" title=\"Mathematical model\">mathematical models</a> " |
| + "of conflict and<br>cooperation between intelligent rational " |
| + "decision-makers.\"</p></body></html>")); |
| + |
| + // Retrieve the IAccessible interface for the web page. |
| + base::win::ScopedComPtr<IAccessible> document(GetRendererAccessible()); |
| + std::vector<base::win::ScopedVariant> document_children = |
| + GetAllAccessibleChildren(document.get()); |
| + ASSERT_EQ(1u, document_children.size()); |
| + |
| + base::win::ScopedComPtr<IAccessible2> paragraph; |
| + ASSERT_HRESULT_SUCCEEDED(QueryIAccessible2( |
| + GetAccessibleFromVariant(document.get(), document_children[0].AsInput()) |
| + .get(), |
| + paragraph.Receive())); |
| + LONG paragraph_role = 0; |
| + ASSERT_HRESULT_SUCCEEDED(paragraph->role(¶graph_role)); |
| + ASSERT_EQ(IA2_ROLE_PARAGRAPH, paragraph_role); |
| + ASSERT_HRESULT_SUCCEEDED(paragraph.QueryInterface(paragraph_text->Receive())); |
| +} |
| // Static helpers ------------------------------------------------ |
| @@ -307,7 +337,7 @@ void AccessibilityWinBrowserTest::FindNodeInAccessibilityTree( |
| // Ensures that the text and the start and end offsets retrieved using |
| // get_textAtOffset match the expected values. |
| void AccessibilityWinBrowserTest::CheckTextAtOffset( |
| - base::win::ScopedComPtr<IAccessibleText>& element, |
| + base::win::ScopedComPtr<IAccessibleText>& object, |
| LONG offset, |
| IA2TextBoundaryType boundary_type, |
| LONG expected_start_offset, |
| @@ -321,9 +351,8 @@ void AccessibilityWinBrowserTest::CheckTextAtOffset( |
| LONG start_offset = 0; |
| LONG end_offset = 0; |
| base::win::ScopedBstr text; |
| - HRESULT hr = element->get_textAtOffset( |
| - offset, boundary_type, |
| - &start_offset, &end_offset, text.Receive()); |
| + HRESULT hr = object->get_textAtOffset(offset, boundary_type, &start_offset, |
| + &end_offset, text.Receive()); |
| EXPECT_EQ(S_OK, hr); |
| EXPECT_EQ(expected_start_offset, start_offset); |
| EXPECT_EQ(expected_end_offset, end_offset); |
| @@ -954,7 +983,107 @@ IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, TestRoleGroup) { |
| } |
| IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
| - TestSetCaretOffset) { |
| + TestCharacterExtentsWithInvalidArguments) { |
| + base::win::ScopedComPtr<IAccessibleText> paragraph_text; |
| + SetUpSampleParagraph(¶graph_text); |
| + |
| + LONG invalid_offset = -3; |
| + LONG x = -1, y = -1; |
| + LONG width = -1, height = -1; |
| + |
| + HRESULT hr = paragraph_text->get_characterExtents( |
| + invalid_offset, IA2_COORDTYPE_SCREEN_RELATIVE, &x, &y, &width, &height); |
| + EXPECT_EQ(E_INVALIDARG, hr); |
| + EXPECT_EQ(-1, x); |
| + EXPECT_EQ(-1, y); |
| + EXPECT_EQ(-1, width); |
| + EXPECT_EQ(-1, height); |
| + hr = paragraph_text->get_characterExtents( |
| + invalid_offset, IA2_COORDTYPE_PARENT_RELATIVE, &x, &y, &width, &height); |
| + EXPECT_EQ(E_INVALIDARG, hr); |
| + EXPECT_EQ(-1, x); |
| + EXPECT_EQ(-1, y); |
| + EXPECT_EQ(-1, width); |
| + EXPECT_EQ(-1, height); |
| + |
| + LONG n_characters; |
| + ASSERT_HRESULT_SUCCEEDED(paragraph_text->get_nCharacters(&n_characters)); |
| + ASSERT_LT(0, n_characters); |
| + |
| + invalid_offset = n_characters + 1; |
| + hr = paragraph_text->get_characterExtents( |
| + invalid_offset, IA2_COORDTYPE_SCREEN_RELATIVE, &x, &y, &width, &height); |
| + EXPECT_EQ(E_INVALIDARG, hr); |
| + EXPECT_EQ(-1, x); |
| + EXPECT_EQ(-1, y); |
| + EXPECT_EQ(-1, width); |
| + EXPECT_EQ(-1, height); |
| + hr = paragraph_text->get_characterExtents( |
| + invalid_offset, IA2_COORDTYPE_PARENT_RELATIVE, &x, &y, &width, &height); |
| + EXPECT_EQ(E_INVALIDARG, hr); |
| + EXPECT_EQ(-1, x); |
| + EXPECT_EQ(-1, y); |
| + EXPECT_EQ(-1, width); |
| + EXPECT_EQ(-1, height); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, TestCharacterExtents) { |
| + base::win::ScopedComPtr<IAccessibleText> paragraph_text; |
| + SetUpSampleParagraph(¶graph_text); |
| + |
| + const LONG newline_offset = 46; |
| + LONG n_characters; |
| + ASSERT_HRESULT_SUCCEEDED(paragraph_text->get_nCharacters(&n_characters)); |
| + ASSERT_LT(0, n_characters); |
| + |
| + IA2CoordinateType coordinate_type = IA2_COORDTYPE_SCREEN_RELATIVE; |
| + LONG x, y, width, height; |
| + LONG previous_x, previous_y; |
| + |
| + for (int test_case = 0; test_case < 1; ++test_case) { |
|
dmazzoni
2016/01/20 01:10:43
Delete this loop since there's only 1 test case no
|
| + EXPECT_HRESULT_SUCCEEDED(paragraph_text->get_characterExtents( |
| + 0, coordinate_type, &x, &y, &width, &height)); |
| + EXPECT_LT(0, x) << "at offset 0"; |
| + EXPECT_LT(0, y) << "at offset 0"; |
| + EXPECT_LT(0, width) << "at offset 0"; |
| + EXPECT_LT(0, height) << "at offset 0"; |
| + |
| + for (LONG offset = 1; offset < newline_offset; ++offset) { |
| + previous_x = x; |
| + previous_y = y; |
| + |
| + EXPECT_HRESULT_SUCCEEDED(paragraph_text->get_characterExtents( |
| + offset, coordinate_type, &x, &y, &width, &height)); |
| + EXPECT_LT(previous_x, x) << "at offset " << offset; |
| + EXPECT_EQ(previous_y, y) << "at offset " << offset; |
| + EXPECT_LT(0, width) << "at offset " << offset; |
| + EXPECT_LT(0, height) << "at offset " << offset; |
| + } |
| + |
| + EXPECT_HRESULT_SUCCEEDED(paragraph_text->get_characterExtents( |
| + newline_offset + 1, coordinate_type, &x, &y, &width, &height)); |
| + EXPECT_LT(0, x) << "at offset 0"; |
|
dmazzoni
2016/01/20 01:10:43
Do you also want to assert that this is actually o
|
| + EXPECT_LT(0, y) << "at offset 0"; |
| + EXPECT_LT(0, width) << "at offset 0"; |
| + EXPECT_LT(0, height) << "at offset 0"; |
| + |
| + for (LONG offset = newline_offset + 2; offset < n_characters; ++offset) { |
| + previous_x = x; |
| + previous_y = y; |
| + |
| + EXPECT_HRESULT_SUCCEEDED(paragraph_text->get_characterExtents( |
| + offset, coordinate_type, &x, &y, &width, &height)); |
| + EXPECT_LT(previous_x, x) << "at offset " << offset; |
| + EXPECT_EQ(previous_y, y) << "at offset " << offset; |
| + EXPECT_LT(0, width) << "at offset " << offset; |
| + EXPECT_LT(0, height) << "at offset " << offset; |
| + } |
| + |
| + coordinate_type = IA2_COORDTYPE_PARENT_RELATIVE; |
| + } |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, TestSetCaretOffset) { |
| base::win::ScopedComPtr<IAccessibleText> input_text; |
| SetUpInputField(&input_text); |
| @@ -1000,7 +1129,7 @@ IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
| } |
| IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
| - TestTextAtOffsetWithInvalidArgs) { |
| + TestTextAtOffsetWithInvalidArguments) { |
| base::win::ScopedComPtr<IAccessibleText> input_text; |
| SetUpInputField(&input_text); |
| HRESULT hr = input_text->get_textAtOffset( |
| @@ -1093,7 +1222,7 @@ IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
| } |
| IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
| - TestMultiLineTextAtOffsetWithInvalidArgs) { |
| + TestMultiLineTextAtOffsetWithInvalidArguments) { |
| base::win::ScopedComPtr<IAccessibleText> textarea_text; |
| SetUpTextareaField(&textarea_text); |
| HRESULT hr = textarea_text->get_textAtOffset( |
| @@ -1378,6 +1507,28 @@ IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
| } |
| IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
| + TestStaticTextAtOffsetWithBoundaryWord) { |
| + base::win::ScopedComPtr<IAccessibleText> paragraph_text; |
| + SetUpSampleParagraph(¶graph_text); |
| + const std::vector<std::wstring> words{ |
| + L"Game ", L"theory ", L"is \"", L"the ", |
| + L"study ", L"of \xfffc ", L"of ", L"conflict ", |
| + L"and\n", L"cooperation ", L"between ", L"intelligent ", |
| + L"rational ", L"decision-makers.\""}; |
| + |
| + // Try to retrieve one word after another. |
| + // (This is an actual test case provided by Freedom Scientific as part of a |
| + // bug report.) |
| + LONG word_start_offset = 0; |
| + for (auto& word : words) { |
| + LONG word_end_offset = word_start_offset + word.size(); |
| + CheckTextAtOffset(paragraph_text, word_start_offset, IA2_TEXT_BOUNDARY_WORD, |
| + word_start_offset, word_end_offset, word); |
| + word_start_offset = word_end_offset; |
| + } |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
| TestTextAtOffsetWithBoundarySentence) { |
| base::win::ScopedComPtr<IAccessibleText> input_text; |
| SetUpInputField(&input_text); |