1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <oleacc.h> 6 7 #include "base/win/scoped_bstr.h" 8 #include "base/win/scoped_comptr.h" 9 #include "base/win/scoped_variant.h" 10 #include "ui/views/controls/textfield/textfield.h" 11 #include "ui/views/test/views_test_base.h" 12 13 namespace views { 14 namespace test { 15 16 typedef ViewsTestBase NativeViewAcccessibilityWinTest; 17 18 TEST_F(NativeViewAcccessibilityWinTest, TextfieldAccessibility) { 19 Widget widget; 20 Widget::InitParams init_params = 21 CreateParams(Widget::InitParams::TYPE_POPUP); 22 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 23 widget.Init(init_params); 24 25 View* content = new View; 26 widget.SetContentsView(content); 27 28 Textfield* textfield = new Textfield; 29 textfield->SetAccessibleName(L"Name"); 30 textfield->SetText(L"Value"); 31 content->AddChildView(textfield); 32 33 base::win::ScopedComPtr<IAccessible> content_accessible( 34 content->GetNativeViewAccessible()); 35 LONG child_count = 0; 36 ASSERT_EQ(S_OK, content_accessible->get_accChildCount(&child_count)); 37 ASSERT_EQ(1L, child_count); 38 39 base::win::ScopedComPtr<IDispatch> textfield_dispatch; 40 base::win::ScopedComPtr<IAccessible> textfield_accessible; 41 base::win::ScopedVariant child_index(1); 42 ASSERT_EQ(S_OK, content_accessible->get_accChild( 43 child_index, textfield_dispatch.Receive())); 44 ASSERT_EQ(S_OK, textfield_dispatch.QueryInterface( 45 textfield_accessible.Receive())); 46 47 base::win::ScopedBstr name; 48 base::win::ScopedVariant childid_self(CHILDID_SELF); 49 ASSERT_EQ(S_OK, textfield_accessible->get_accName( 50 childid_self, name.Receive())); 51 ASSERT_STREQ(L"Name", name); 52 53 base::win::ScopedBstr value; 54 ASSERT_EQ(S_OK, textfield_accessible->get_accValue( 55 childid_self, value.Receive())); 56 ASSERT_STREQ(L"Value", value); 57 58 base::win::ScopedBstr new_value(L"New value"); 59 ASSERT_EQ(S_OK, textfield_accessible->put_accValue(childid_self, new_value)); 60 61 ASSERT_STREQ(L"New value", textfield->text().c_str()); 62 } 63 64 } // namespace test 65 } // namespace views 66