|
Lines 2285-2290
Link Here
|
| 2285 |
} |
2285 |
} |
| 2286 |
} |
2286 |
} |
| 2287 |
|
2287 |
|
|
|
2288 |
[Test] |
| 2289 |
public void Bug468271Test () |
| 2290 |
{ |
| 2291 |
// NOTE: This test only exposes bug in Provider side. |
| 2292 |
// ListView_details: "table cell" isn't accessible without "focused" |
| 2293 |
ListView listview = new ListView (); |
| 2294 |
listview.View = View.Details; |
| 2295 |
listview.CheckBoxes = true; |
| 2296 |
listview.GridLines = true; |
| 2297 |
listview.Sorting = SortOrder.Ascending; |
| 2298 |
listview.Dock = DockStyle.Top; |
| 2299 |
listview.Width = 350; |
| 2300 |
listview.Height = 260; |
| 2301 |
|
| 2302 |
listview.Columns.Add ("Column1", 200, HorizontalAlignment.Left); |
| 2303 |
listview.Columns.Add ("Column2", 200, HorizontalAlignment.Left); |
| 2304 |
listview.Columns.Add ("Column3", 200, HorizontalAlignment.Left); |
| 2305 |
|
| 2306 |
for (int index = 0; index < 3; index++) { |
| 2307 |
ListViewItem item = new ListViewItem (string.Format ("Item:{0}", index)); |
| 2308 |
item.SubItems.Add (index.ToString ()); |
| 2309 |
item.SubItems.Add ((index+10).ToString ()); |
| 2310 |
listview.Items.Add (item); |
| 2311 |
} |
| 2312 |
|
| 2313 |
// We have the following table: |
| 2314 |
// "Column1" | "Column2" | "Column3" |
| 2315 |
// ------------------|-----------|---------- |
| 2316 |
// checkbox, "Item0" | "0" | "10" |
| 2317 |
// checkbox, "Item1" | "1" | "11" |
| 2318 |
// checkbox, "Item2" | "2" | "12" |
| 2319 |
|
| 2320 |
// ListViewUIATree: |
| 2321 |
// - Header |
| 2322 |
// - HeaderItem "Column1" |
| 2323 |
// - HeaderItem "Column2" |
| 2324 |
// - HeaderItem "Column3" |
| 2325 |
// - DataItem "Item0" |
| 2326 |
// - CheckBox |
| 2327 |
// - "Item0" |
| 2328 |
// - "0" |
| 2329 |
// - "10" |
| 2330 |
// - DataItem "Item1" |
| 2331 |
// - CheckBox |
| 2332 |
// - "Item1" |
| 2333 |
// - "1" |
| 2334 |
// - "11" |
| 2335 |
// - DataItem "Item2" |
| 2336 |
// - CheckBox |
| 2337 |
// - "Item2" |
| 2338 |
// - "2" |
| 2339 |
// - "12" |
| 2340 |
IRawElementProviderFragmentRoot root |
| 2341 |
= (IRawElementProviderFragmentRoot) GetProviderFromControl (listview); |
| 2342 |
Assert.IsNotNull (root, "Missing ListViewProvider"); |
| 2343 |
IRawElementProviderFragmentRoot []dataItems = new IRawElementProviderFragmentRoot [3]; |
| 2344 |
IRawElementProviderFragment child = root.Navigate (NavigateDirection.FirstChild); |
| 2345 |
Assert.IsNotNull (child, "Missing child"); |
| 2346 |
|
| 2347 |
int dataItem = 0; |
| 2348 |
while (child != null) { |
| 2349 |
if ((int) child.GetPropertyValue (AutomationElementIdentifiers.ControlTypeProperty.Id) |
| 2350 |
== ControlType.DataItem.Id) { |
| 2351 |
dataItems [dataItem] = (IRawElementProviderFragmentRoot) child; |
| 2352 |
dataItem++; |
| 2353 |
} |
| 2354 |
child = child.Navigate (NavigateDirection.NextSibling); |
| 2355 |
} |
| 2356 |
Assert.AreEqual (dataItems.Length, dataItem, "Count != DataItems"); |
| 2357 |
|
| 2358 |
// You *can* only focus 1 item, so, focusing a different item |
| 2359 |
// will unfocus previous item and focus new item. |
| 2360 |
|
| 2361 |
// listview.FullRowSelect = false: first subitem will is selected. |
| 2362 |
bridge.ResetEventLists (); |
| 2363 |
listview.Focus (); |
| 2364 |
listview.Items [0].Focused = true; |
| 2365 |
TestFocusInDataItemChildren (listview, 0, dataItems [0], true); |
| 2366 |
|
| 2367 |
bridge.ResetEventLists (); |
| 2368 |
listview.Items [1].Focused = true; |
| 2369 |
TestFocusInDataItemChildren (listview, 1, dataItems [1], true); |
| 2370 |
TestFocusInDataItemChildren (listview, 0, dataItems [0], false); |
| 2371 |
|
| 2372 |
bridge.ResetEventLists (); |
| 2373 |
listview.Items [2].Focused = true; |
| 2374 |
TestFocusInDataItemChildren (listview, 2, dataItems [2], true); |
| 2375 |
TestFocusInDataItemChildren (listview, 1, dataItems [1], false); |
| 2376 |
} |
| 2377 |
|
| 2378 |
private int GetIndexFromName (ListViewItem item, string name) |
| 2379 |
{ |
| 2380 |
int index = 0; |
| 2381 |
|
| 2382 |
foreach (ListViewItem.ListViewSubItem subItem in item.SubItems) { |
| 2383 |
if (subItem.Text == name) |
| 2384 |
break; |
| 2385 |
index++; |
| 2386 |
} |
| 2387 |
|
| 2388 |
return index; |
| 2389 |
} |
| 2390 |
|
| 2391 |
private void TestFocusInDataItemChildren (ListView listview, |
| 2392 |
int index, |
| 2393 |
IRawElementProviderFragmentRoot dataItemRoot, |
| 2394 |
bool focused) |
| 2395 |
{ |
| 2396 |
AutomationPropertyChangedEventTuple tuple |
| 2397 |
= bridge.GetAutomationPropertyEventFrom (dataItemRoot, |
| 2398 |
AutomationElementIdentifiers.HasKeyboardFocusProperty.Id); |
| 2399 |
Assert.AreEqual (focused, |
| 2400 |
(bool) tuple.e.NewValue, |
| 2401 |
"DataItem Focused value."); |
| 2402 |
|
| 2403 |
IRawElementProviderFragment child = dataItemRoot.Navigate (NavigateDirection.FirstChild); |
| 2404 |
Assert.IsNotNull (child, "Child should not be null"); |
| 2405 |
int subItem = 0; |
| 2406 |
while (child != null) { |
| 2407 |
bool hasfocus |
| 2408 |
= (bool) child.GetPropertyValue (AutomationElementIdentifiers.HasKeyboardFocusProperty.Id); |
| 2409 |
if ((int) child.GetPropertyValue (AutomationElementIdentifiers.ControlTypeProperty.Id) |
| 2410 |
== ControlType.Edit.Id) { |
| 2411 |
string name |
| 2412 |
= (string) child.GetPropertyValue (AutomationElementIdentifiers.NameProperty.Id); |
| 2413 |
if (!focused) |
| 2414 |
Assert.IsFalse (hasfocus, |
| 2415 |
string.Format ("{0}.{1} Name: '{0}'", |
| 2416 |
index, subItem, name)); |
| 2417 |
else { |
| 2418 |
if (listview.FullRowSelect |
| 2419 |
|| GetIndexFromName (listview.Items [index], name) == 0) |
| 2420 |
Assert.AreEqual (focused, |
| 2421 |
hasfocus, |
| 2422 |
string.Format ("{0}.{1} Name: '{0}'", |
| 2423 |
index, subItem, name)); |
| 2424 |
else |
| 2425 |
Assert.AreNotEqual (focused, |
| 2426 |
hasfocus, |
| 2427 |
string.Format ("{0}.{1} Name: '{0}'", |
| 2428 |
index, subItem, name)); |
| 2429 |
} |
| 2430 |
subItem++; |
| 2431 |
} else |
| 2432 |
// CheckBox only selected when is fullrow and is focused |
| 2433 |
// is expected |
| 2434 |
Assert.AreEqual (listview.FullRowSelect && focused, |
| 2435 |
hasfocus, |
| 2436 |
string.Format ("{0}.CheckBox Focus should NOT be set", index)); |
| 2437 |
child = child.Navigate (NavigateDirection.NextSibling); |
| 2438 |
} |
| 2439 |
} |
| 2440 |
|
| 2288 |
#region BaseProviderTest Overrides |
2441 |
#region BaseProviderTest Overrides |
| 2289 |
|
2442 |
|
| 2290 |
protected override Control GetControlInstance () |
2443 |
protected override Control GetControlInstance () |