Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(522)

Side by Side Diff: ui/views/focus/focus_traversal_unittest.cc

Issue 2368283002: views: add focus to TabbedPane (Closed)
Patch Set: sed tr sed Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 15 matching lines...) Expand all
26 #include "ui/views/test/focus_manager_test.h" 26 #include "ui/views/test/focus_manager_test.h"
27 #include "ui/views/widget/root_view.h" 27 #include "ui/views/widget/root_view.h"
28 #include "ui/views/widget/widget.h" 28 #include "ui/views/widget/widget.h"
29 29
30 using base::ASCIIToUTF16; 30 using base::ASCIIToUTF16;
31 31
32 namespace views { 32 namespace views {
33 33
34 namespace { 34 namespace {
35 35
36 int count = 1; 36 enum {
37 TOP_CHECK_BOX_ID = 1, // 1
38 LEFT_CONTAINER_ID,
39 APPLE_LABEL_ID,
40 APPLE_TEXTFIELD_ID,
41 ORANGE_LABEL_ID, // 5
42 ORANGE_TEXTFIELD_ID,
43 BANANA_LABEL_ID,
44 BANANA_TEXTFIELD_ID,
45 KIWI_LABEL_ID,
46 KIWI_TEXTFIELD_ID, // 10
47 FRUIT_BUTTON_ID,
48 FRUIT_CHECK_BOX_ID,
49 COMBOBOX_ID,
37 50
38 const int kTopCheckBoxID = count++; // 1 51 RIGHT_CONTAINER_ID,
39 const int kLeftContainerID = count++; 52 ASPARAGUS_BUTTON_ID, // 15
40 const int kAppleLabelID = count++; 53 BROCCOLI_BUTTON_ID,
41 const int kAppleTextfieldID = count++; 54 CAULIFLOWER_BUTTON_ID,
42 const int kOrangeLabelID = count++; // 5
43 const int kOrangeTextfieldID = count++;
44 const int kBananaLabelID = count++;
45 const int kBananaTextfieldID = count++;
46 const int kKiwiLabelID = count++;
47 const int kKiwiTextfieldID = count++; // 10
48 const int kFruitButtonID = count++;
49 const int kFruitCheckBoxID = count++;
50 const int kComboboxID = count++;
51 55
52 const int kRightContainerID = count++; 56 INNER_CONTAINER_ID,
53 const int kAsparagusButtonID = count++; // 15 57 SCROLL_VIEW_ID,
54 const int kBroccoliButtonID = count++; 58 ROSETTA_LINK_ID, // 20
55 const int kCauliflowerButtonID = count++; 59 STUPEUR_ET_TREMBLEMENT_LINK_ID,
60 DINER_GAME_LINK_ID,
61 RIDICULE_LINK_ID,
62 CLOSET_LINK_ID,
63 VISITING_LINK_ID, // 25
64 AMELIE_LINK_ID,
65 JOYEUX_NOEL_LINK_ID,
66 CAMPING_LINK_ID,
67 BRICE_DE_NICE_LINK_ID,
68 TAXI_LINK_ID, // 30
69 ASTERIX_LINK_ID,
56 70
57 const int kInnerContainerID = count++; 71 O_K_BUTTON_ID,
Evan Stade 2016/10/06 21:18:44 heh^
Elly Fong-Jones 2016/10/07 17:18:24 Fixed. I'm still feeling clever that I automated
58 const int kScrollViewID = count++; 72 CANCEL_BUTTON_ID,
59 const int kRosettaLinkID = count++; // 20 73 HELP_BUTTON_ID,
60 const int kStupeurEtTremblementLinkID = count++;
61 const int kDinerGameLinkID = count++;
62 const int kRidiculeLinkID = count++;
63 const int kClosetLinkID = count++;
64 const int kVisitingLinkID = count++; // 25
65 const int kAmelieLinkID = count++;
66 const int kJoyeuxNoelLinkID = count++;
67 const int kCampingLinkID = count++;
68 const int kBriceDeNiceLinkID = count++;
69 const int kTaxiLinkID = count++; // 30
70 const int kAsterixLinkID = count++;
71 74
72 const int kOKButtonID = count++; 75 STYLE_CONTAINER_ID, // 35
73 const int kCancelButtonID = count++; 76 BOLD_CHECK_BOX_ID,
74 const int kHelpButtonID = count++; 77 ITALIC_CHECK_BOX_ID,
Evan Stade 2016/10/06 21:18:44 s/CHECK_BOX/CHECKBOX here and everywhere
Elly Fong-Jones 2016/10/07 17:18:24 Done.
78 UNDERLINED_CHECK_BOX_ID,
79 STYLE_HELP_LINK_ID,
80 STYLE_TEXT_EDIT_ID, // 40
75 81
76 const int kStyleContainerID = count++; // 35 82 SEARCH_CONTAINER_ID,
77 const int kBoldCheckBoxID = count++; 83 SEARCH_TEXTFIELD_ID,
78 const int kItalicCheckBoxID = count++; 84 SEARCH_BUTTON_ID,
79 const int kUnderlinedCheckBoxID = count++; 85 HELP_LINK_ID,
80 const int kStyleHelpLinkID = count++;
81 const int kStyleTextEditID = count++; // 40
82 86
83 const int kSearchContainerID = count++; 87 THUMBNAIL_CONTAINER_ID, // 45
84 const int kSearchTextfieldID = count++; 88 THUMBNAIL_STAR_ID,
85 const int kSearchButtonID = count++; 89 THUMBNAIL_SUPER_STAR_ID,
86 const int kHelpLinkID = count++; 90 };
87
88 const int kThumbnailContainerID = count++; // 45
89 const int kThumbnailStarID = count++;
90 const int kThumbnailSuperStarID = count++;
91 91
92 class DummyComboboxModel : public ui::ComboboxModel { 92 class DummyComboboxModel : public ui::ComboboxModel {
93 public: 93 public:
94 // Overridden from ui::ComboboxModel: 94 // Overridden from ui::ComboboxModel:
95 int GetItemCount() const override { return 10; } 95 int GetItemCount() const override { return 10; }
96 base::string16 GetItemAt(int index) override { 96 base::string16 GetItemAt(int index) override {
97 return ASCIIToUTF16("Item ") + base::IntToString16(index); 97 return ASCIIToUTF16("Item ") + base::IntToString16(index);
98 } 98 }
99 }; 99 };
100 100
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 void InitContentView() override; 185 void InitContentView() override;
186 186
187 protected: 187 protected:
188 FocusTraversalTest(); 188 FocusTraversalTest();
189 189
190 View* FindViewByID(int id) { 190 View* FindViewByID(int id) {
191 View* view = GetContentsView()->GetViewByID(id); 191 View* view = GetContentsView()->GetViewByID(id);
192 if (view) 192 if (view)
193 return view; 193 return view;
194 if (style_tab_) 194 if (style_tab_)
195 view = style_tab_->GetSelectedTab()->GetViewByID(id); 195 view = style_tab_->GetSelectedTabContentView()->GetViewByID(id);
196 if (view) 196 if (view)
197 return view; 197 return view;
198 view = search_border_view_->GetContentsRootView()->GetViewByID(id); 198 view = search_border_view_->GetContentsRootView()->GetViewByID(id);
199 if (view) 199 if (view)
200 return view; 200 return view;
201 return NULL; 201 return NULL;
202 } 202 }
203 203
204 protected: 204 protected:
205 // Helper function to advance focus multiple times in a loop. |traversal_ids| 205 // Helper function to advance focus multiple times in a loop. |traversal_ids|
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 FocusTraversalTest::~FocusTraversalTest() { 237 FocusTraversalTest::~FocusTraversalTest() {
238 } 238 }
239 239
240 void FocusTraversalTest::InitContentView() { 240 void FocusTraversalTest::InitContentView() {
241 // Create a complicated view hierarchy with lots of control types for 241 // Create a complicated view hierarchy with lots of control types for
242 // use by all of the focus traversal tests. 242 // use by all of the focus traversal tests.
243 // 243 //
244 // Class name, ID, and asterisk next to focusable views: 244 // Class name, ID, and asterisk next to focusable views:
245 // 245 //
246 // View 246 // View
247 // Checkbox * kTopCheckBoxID 247 // Checkbox * TOP_CHECK_BOX_ID
248 // PaneView kLeftContainerID 248 // PaneView LEFT_CONTAINER_ID
249 // Label kAppleLabelID 249 // Label APPLE_LABEL_ID
250 // Textfield * kAppleTextfieldID 250 // Textfield * APPLE_TEXTFIELD_ID
251 // Label kOrangeLabelID 251 // Label ORANGE_LABEL_ID
252 // Textfield * kOrangeTextfieldID 252 // Textfield * ORANGE_TEXTFIELD_ID
253 // Label kBananaLabelID 253 // Label BANANA_LABEL_ID
254 // Textfield * kBananaTextfieldID 254 // Textfield * BANANA_TEXTFIELD_ID
255 // Label kKiwiLabelID 255 // Label KIWI_LABEL_ID
256 // Textfield * kKiwiTextfieldID 256 // Textfield * KIWI_TEXTFIELD_ID
257 // NativeButton * kFruitButtonID 257 // NativeButton * FRUIT_BUTTON_ID
258 // Checkbox * kFruitCheckBoxID 258 // Checkbox * FRUIT_CHECK_BOX_ID
259 // Combobox * kComboboxID 259 // Combobox * COMBOBOX_ID
260 // PaneView kRightContainerID 260 // PaneView RIGHT_CONTAINER_ID
261 // RadioButton * kAsparagusButtonID 261 // RadioButton * ASPARAGUS_BUTTON_ID
262 // RadioButton * kBroccoliButtonID 262 // RadioButton * BROCCOLI_BUTTON_ID
263 // RadioButton * kCauliflowerButtonID 263 // RadioButton * CAULIFLOWER_BUTTON_ID
264 // View kInnerContainerID 264 // View INNER_CONTAINER_ID
265 // ScrollView kScrollViewID 265 // ScrollView SCROLL_VIEW_ID
266 // View 266 // View
267 // Link * kRosettaLinkID 267 // Link * ROSETTA_LINK_ID
268 // Link * kStupeurEtTremblementLinkID 268 // Link * STUPEUR_ET_TREMBLEMENT_LINK_ID
269 // Link * kDinerGameLinkID 269 // Link * DINER_GAME_LINK_ID
270 // Link * kRidiculeLinkID 270 // Link * RIDICULE_LINK_ID
271 // Link * kClosetLinkID 271 // Link * CLOSET_LINK_ID
272 // Link * kVisitingLinkID 272 // Link * VISITING_LINK_ID
273 // Link * kAmelieLinkID 273 // Link * AMELIE_LINK_ID
274 // Link * kJoyeuxNoelLinkID 274 // Link * JOYEUX_NOEL_LINK_ID
275 // Link * kCampingLinkID 275 // Link * CAMPING_LINK_ID
276 // Link * kBriceDeNiceLinkID 276 // Link * BRICE_DE_NICE_LINK_ID
277 // Link * kTaxiLinkID 277 // Link * TAXI_LINK_ID
278 // Link * kAsterixLinkID 278 // Link * ASTERIX_LINK_ID
279 // NativeButton * kOKButtonID 279 // NativeButton * O_K_BUTTON_ID
280 // NativeButton * kCancelButtonID 280 // NativeButton * CANCEL_BUTTON_ID
281 // NativeButton * kHelpButtonID 281 // NativeButton * HELP_BUTTON_ID
282 // TabbedPane * kStyleContainerID 282 // TabbedPane * STYLE_CONTAINER_ID
283 // TabStrip 283 // TabStrip
284 // Tab ("Style") 284 // Tab ("Style")
285 // Tab ("Other") 285 // Tab ("Other")
286 // View 286 // View
287 // View 287 // View
288 // Checkbox * kBoldCheckBoxID 288 // Checkbox * BOLD_CHECK_BOX_ID
289 // Checkbox * kItalicCheckBoxID 289 // Checkbox * ITALIC_CHECK_BOX_ID
290 // Checkbox * kUnderlinedCheckBoxID 290 // Checkbox * UNDERLINED_CHECK_BOX_ID
291 // Link * kStyleHelpLinkID 291 // Link * STYLE_HELP_LINK_ID
292 // Textfield * kStyleTextEditID 292 // Textfield * STYLE_TEXT_EDIT_ID
293 // View 293 // View
294 // BorderView kSearchContainerID 294 // BorderView SEARCH_CONTAINER_ID
295 // View 295 // View
296 // Textfield * kSearchTextfieldID 296 // Textfield * SEARCH_TEXTFIELD_ID
297 // NativeButton * kSearchButtonID 297 // NativeButton * SEARCH_BUTTON_ID
298 // Link * kHelpLinkID 298 // Link * HELP_LINK_ID
299 // View * kThumbnailContainerID 299 // View * THUMBNAIL_CONTAINER_ID
300 // NativeButton * kThumbnailStarID 300 // NativeButton * THUMBNAIL_STAR_ID
301 // NativeButton * kThumbnailSuperStarID 301 // NativeButton * THUMBNAIL_SUPER_STAR_ID
302 302
303 GetContentsView()->set_background( 303 GetContentsView()->set_background(
304 Background::CreateSolidBackground(SK_ColorWHITE)); 304 Background::CreateSolidBackground(SK_ColorWHITE));
305 305
306 Checkbox* cb = new Checkbox(ASCIIToUTF16("This is a checkbox")); 306 Checkbox* cb = new Checkbox(ASCIIToUTF16("This is a checkbox"));
307 GetContentsView()->AddChildView(cb); 307 GetContentsView()->AddChildView(cb);
308 // In this fast paced world, who really has time for non hard-coded layout? 308 // In this fast paced world, who really has time for non hard-coded layout?
309 cb->SetBounds(10, 10, 200, 20); 309 cb->SetBounds(10, 10, 200, 20);
310 cb->set_id(kTopCheckBoxID); 310 cb->set_id(TOP_CHECK_BOX_ID);
311 311
312 left_container_ = new PaneView(); 312 left_container_ = new PaneView();
313 left_container_->SetBorder(Border::CreateSolidBorder(1, SK_ColorBLACK)); 313 left_container_->SetBorder(Border::CreateSolidBorder(1, SK_ColorBLACK));
314 left_container_->set_background( 314 left_container_->set_background(
315 Background::CreateSolidBackground(240, 240, 240)); 315 Background::CreateSolidBackground(240, 240, 240));
316 left_container_->set_id(kLeftContainerID); 316 left_container_->set_id(LEFT_CONTAINER_ID);
317 GetContentsView()->AddChildView(left_container_); 317 GetContentsView()->AddChildView(left_container_);
318 left_container_->SetBounds(10, 35, 250, 200); 318 left_container_->SetBounds(10, 35, 250, 200);
319 319
320 int label_x = 5; 320 int label_x = 5;
321 int label_width = 50; 321 int label_width = 50;
322 int label_height = 15; 322 int label_height = 15;
323 int text_field_width = 150; 323 int text_field_width = 150;
324 int y = 10; 324 int y = 10;
325 int gap_between_labels = 10; 325 int gap_between_labels = 10;
326 326
327 Label* label = new Label(ASCIIToUTF16("Apple:")); 327 Label* label = new Label(ASCIIToUTF16("Apple:"));
328 label->set_id(kAppleLabelID); 328 label->set_id(APPLE_LABEL_ID);
329 left_container_->AddChildView(label); 329 left_container_->AddChildView(label);
330 label->SetBounds(label_x, y, label_width, label_height); 330 label->SetBounds(label_x, y, label_width, label_height);
331 331
332 Textfield* text_field = new Textfield(); 332 Textfield* text_field = new Textfield();
333 text_field->set_id(kAppleTextfieldID); 333 text_field->set_id(APPLE_TEXTFIELD_ID);
334 left_container_->AddChildView(text_field); 334 left_container_->AddChildView(text_field);
335 text_field->SetBounds(label_x + label_width + 5, y, 335 text_field->SetBounds(label_x + label_width + 5, y,
336 text_field_width, label_height); 336 text_field_width, label_height);
337 337
338 y += label_height + gap_between_labels; 338 y += label_height + gap_between_labels;
339 339
340 label = new Label(ASCIIToUTF16("Orange:")); 340 label = new Label(ASCIIToUTF16("Orange:"));
341 label->set_id(kOrangeLabelID); 341 label->set_id(ORANGE_LABEL_ID);
342 left_container_->AddChildView(label); 342 left_container_->AddChildView(label);
343 label->SetBounds(label_x, y, label_width, label_height); 343 label->SetBounds(label_x, y, label_width, label_height);
344 344
345 text_field = new Textfield(); 345 text_field = new Textfield();
346 text_field->set_id(kOrangeTextfieldID); 346 text_field->set_id(ORANGE_TEXTFIELD_ID);
347 left_container_->AddChildView(text_field); 347 left_container_->AddChildView(text_field);
348 text_field->SetBounds(label_x + label_width + 5, y, 348 text_field->SetBounds(label_x + label_width + 5, y,
349 text_field_width, label_height); 349 text_field_width, label_height);
350 350
351 y += label_height + gap_between_labels; 351 y += label_height + gap_between_labels;
352 352
353 label = new Label(ASCIIToUTF16("Banana:")); 353 label = new Label(ASCIIToUTF16("Banana:"));
354 label->set_id(kBananaLabelID); 354 label->set_id(BANANA_LABEL_ID);
355 left_container_->AddChildView(label); 355 left_container_->AddChildView(label);
356 label->SetBounds(label_x, y, label_width, label_height); 356 label->SetBounds(label_x, y, label_width, label_height);
357 357
358 text_field = new Textfield(); 358 text_field = new Textfield();
359 text_field->set_id(kBananaTextfieldID); 359 text_field->set_id(BANANA_TEXTFIELD_ID);
360 left_container_->AddChildView(text_field); 360 left_container_->AddChildView(text_field);
361 text_field->SetBounds(label_x + label_width + 5, y, 361 text_field->SetBounds(label_x + label_width + 5, y,
362 text_field_width, label_height); 362 text_field_width, label_height);
363 363
364 y += label_height + gap_between_labels; 364 y += label_height + gap_between_labels;
365 365
366 label = new Label(ASCIIToUTF16("Kiwi:")); 366 label = new Label(ASCIIToUTF16("Kiwi:"));
367 label->set_id(kKiwiLabelID); 367 label->set_id(KIWI_LABEL_ID);
368 left_container_->AddChildView(label); 368 left_container_->AddChildView(label);
369 label->SetBounds(label_x, y, label_width, label_height); 369 label->SetBounds(label_x, y, label_width, label_height);
370 370
371 text_field = new Textfield(); 371 text_field = new Textfield();
372 text_field->set_id(kKiwiTextfieldID); 372 text_field->set_id(KIWI_TEXTFIELD_ID);
373 left_container_->AddChildView(text_field); 373 left_container_->AddChildView(text_field);
374 text_field->SetBounds(label_x + label_width + 5, y, 374 text_field->SetBounds(label_x + label_width + 5, y,
375 text_field_width, label_height); 375 text_field_width, label_height);
376 376
377 y += label_height + gap_between_labels; 377 y += label_height + gap_between_labels;
378 378
379 LabelButton* button = MdTextButton::Create(NULL, ASCIIToUTF16("Click me")); 379 LabelButton* button = MdTextButton::Create(NULL, ASCIIToUTF16("Click me"));
380 button->SetBounds(label_x, y + 10, 80, 30); 380 button->SetBounds(label_x, y + 10, 80, 30);
381 button->set_id(kFruitButtonID); 381 button->set_id(FRUIT_BUTTON_ID);
382 left_container_->AddChildView(button); 382 left_container_->AddChildView(button);
383 y += 40; 383 y += 40;
384 384
385 cb = new Checkbox(ASCIIToUTF16("This is another check box")); 385 cb = new Checkbox(ASCIIToUTF16("This is another check box"));
386 cb->SetBounds(label_x + label_width + 5, y, 180, 20); 386 cb->SetBounds(label_x + label_width + 5, y, 180, 20);
387 cb->set_id(kFruitCheckBoxID); 387 cb->set_id(FRUIT_CHECK_BOX_ID);
388 left_container_->AddChildView(cb); 388 left_container_->AddChildView(cb);
389 y += 20; 389 y += 20;
390 390
391 Combobox* combobox = new Combobox(&combobox_model_); 391 Combobox* combobox = new Combobox(&combobox_model_);
392 combobox->SetBounds(label_x + label_width + 5, y, 150, 30); 392 combobox->SetBounds(label_x + label_width + 5, y, 150, 30);
393 combobox->set_id(kComboboxID); 393 combobox->set_id(COMBOBOX_ID);
394 left_container_->AddChildView(combobox); 394 left_container_->AddChildView(combobox);
395 395
396 right_container_ = new PaneView(); 396 right_container_ = new PaneView();
397 right_container_->SetBorder(Border::CreateSolidBorder(1, SK_ColorBLACK)); 397 right_container_->SetBorder(Border::CreateSolidBorder(1, SK_ColorBLACK));
398 right_container_->set_background( 398 right_container_->set_background(
399 Background::CreateSolidBackground(240, 240, 240)); 399 Background::CreateSolidBackground(240, 240, 240));
400 right_container_->set_id(kRightContainerID); 400 right_container_->set_id(RIGHT_CONTAINER_ID);
401 GetContentsView()->AddChildView(right_container_); 401 GetContentsView()->AddChildView(right_container_);
402 right_container_->SetBounds(270, 35, 300, 200); 402 right_container_->SetBounds(270, 35, 300, 200);
403 403
404 y = 10; 404 y = 10;
405 int radio_button_height = 18; 405 int radio_button_height = 18;
406 int gap_between_radio_buttons = 10; 406 int gap_between_radio_buttons = 10;
407 RadioButton* radio_button = new RadioButton(ASCIIToUTF16("Asparagus"), 1); 407 RadioButton* radio_button = new RadioButton(ASCIIToUTF16("Asparagus"), 1);
408 radio_button->set_id(kAsparagusButtonID); 408 radio_button->set_id(ASPARAGUS_BUTTON_ID);
409 right_container_->AddChildView(radio_button); 409 right_container_->AddChildView(radio_button);
410 radio_button->SetBounds(5, y, 70, radio_button_height); 410 radio_button->SetBounds(5, y, 70, radio_button_height);
411 radio_button->SetGroup(1); 411 radio_button->SetGroup(1);
412 y += radio_button_height + gap_between_radio_buttons; 412 y += radio_button_height + gap_between_radio_buttons;
413 radio_button = new RadioButton(ASCIIToUTF16("Broccoli"), 1); 413 radio_button = new RadioButton(ASCIIToUTF16("Broccoli"), 1);
414 radio_button->set_id(kBroccoliButtonID); 414 radio_button->set_id(BROCCOLI_BUTTON_ID);
415 right_container_->AddChildView(radio_button); 415 right_container_->AddChildView(radio_button);
416 radio_button->SetBounds(5, y, 70, radio_button_height); 416 radio_button->SetBounds(5, y, 70, radio_button_height);
417 radio_button->SetGroup(1); 417 radio_button->SetGroup(1);
418 RadioButton* radio_button_to_check = radio_button; 418 RadioButton* radio_button_to_check = radio_button;
419 y += radio_button_height + gap_between_radio_buttons; 419 y += radio_button_height + gap_between_radio_buttons;
420 radio_button = new RadioButton(ASCIIToUTF16("Cauliflower"), 1); 420 radio_button = new RadioButton(ASCIIToUTF16("Cauliflower"), 1);
421 radio_button->set_id(kCauliflowerButtonID); 421 radio_button->set_id(CAULIFLOWER_BUTTON_ID);
422 right_container_->AddChildView(radio_button); 422 right_container_->AddChildView(radio_button);
423 radio_button->SetBounds(5, y, 70, radio_button_height); 423 radio_button->SetBounds(5, y, 70, radio_button_height);
424 radio_button->SetGroup(1); 424 radio_button->SetGroup(1);
425 y += radio_button_height + gap_between_radio_buttons; 425 y += radio_button_height + gap_between_radio_buttons;
426 426
427 View* inner_container = new View(); 427 View* inner_container = new View();
428 inner_container->SetBorder(Border::CreateSolidBorder(1, SK_ColorBLACK)); 428 inner_container->SetBorder(Border::CreateSolidBorder(1, SK_ColorBLACK));
429 inner_container->set_background( 429 inner_container->set_background(
430 Background::CreateSolidBackground(230, 230, 230)); 430 Background::CreateSolidBackground(230, 230, 230));
431 inner_container->set_id(kInnerContainerID); 431 inner_container->set_id(INNER_CONTAINER_ID);
432 right_container_->AddChildView(inner_container); 432 right_container_->AddChildView(inner_container);
433 inner_container->SetBounds(100, 10, 150, 180); 433 inner_container->SetBounds(100, 10, 150, 180);
434 434
435 ScrollView* scroll_view = new ScrollView(); 435 ScrollView* scroll_view = new ScrollView();
436 scroll_view->set_id(kScrollViewID); 436 scroll_view->set_id(SCROLL_VIEW_ID);
437 inner_container->AddChildView(scroll_view); 437 inner_container->AddChildView(scroll_view);
438 scroll_view->SetBounds(1, 1, 148, 178); 438 scroll_view->SetBounds(1, 1, 148, 178);
439 439
440 View* scroll_content = new View(); 440 View* scroll_content = new View();
441 scroll_content->SetBounds(0, 0, 200, 200); 441 scroll_content->SetBounds(0, 0, 200, 200);
442 scroll_content->set_background( 442 scroll_content->set_background(
443 Background::CreateSolidBackground(200, 200, 200)); 443 Background::CreateSolidBackground(200, 200, 200));
444 scroll_view->SetContents(scroll_content); 444 scroll_view->SetContents(scroll_content);
445 445
446 static const char* const kTitles[] = { 446 static const char* const kTitles[] = {
447 "Rosetta", "Stupeur et tremblement", "The diner game", 447 "Rosetta", "Stupeur et tremblement", "The diner game",
448 "Ridicule", "Le placard", "Les Visiteurs", "Amelie", 448 "Ridicule", "Le placard", "Les Visiteurs", "Amelie",
449 "Joyeux Noel", "Camping", "Brice de Nice", 449 "Joyeux Noel", "Camping", "Brice de Nice",
450 "Taxi", "Asterix" 450 "Taxi", "Asterix"
451 }; 451 };
452 452
453 static const int kIDs[] = { 453 static const int kIDs[] = {ROSETTA_LINK_ID, STUPEUR_ET_TREMBLEMENT_LINK_ID,
454 kRosettaLinkID, kStupeurEtTremblementLinkID, kDinerGameLinkID, 454 DINER_GAME_LINK_ID, RIDICULE_LINK_ID,
455 kRidiculeLinkID, kClosetLinkID, kVisitingLinkID, kAmelieLinkID, 455 CLOSET_LINK_ID, VISITING_LINK_ID,
456 kJoyeuxNoelLinkID, kCampingLinkID, kBriceDeNiceLinkID, 456 AMELIE_LINK_ID, JOYEUX_NOEL_LINK_ID,
457 kTaxiLinkID, kAsterixLinkID 457 CAMPING_LINK_ID, BRICE_DE_NICE_LINK_ID,
458 }; 458 TAXI_LINK_ID, ASTERIX_LINK_ID};
459 459
460 DCHECK(arraysize(kTitles) == arraysize(kIDs)); 460 DCHECK(arraysize(kTitles) == arraysize(kIDs));
461 461
462 y = 5; 462 y = 5;
463 for (size_t i = 0; i < arraysize(kTitles); ++i) { 463 for (size_t i = 0; i < arraysize(kTitles); ++i) {
464 Link* link = new Link(ASCIIToUTF16(kTitles[i])); 464 Link* link = new Link(ASCIIToUTF16(kTitles[i]));
465 link->SetHorizontalAlignment(gfx::ALIGN_LEFT); 465 link->SetHorizontalAlignment(gfx::ALIGN_LEFT);
466 link->set_id(kIDs[i]); 466 link->set_id(kIDs[i]);
467 scroll_content->AddChildView(link); 467 scroll_content->AddChildView(link);
468 link->SetBounds(5, y, 300, 15); 468 link->SetBounds(5, y, 300, 15);
469 y += 15; 469 y += 15;
470 } 470 }
471 471
472 y = 250; 472 y = 250;
473 int width = 60; 473 int width = 60;
474 button = MdTextButton::Create(NULL, ASCIIToUTF16("OK")); 474 button = MdTextButton::Create(NULL, ASCIIToUTF16("OK"));
475 button->set_id(kOKButtonID); 475 button->set_id(O_K_BUTTON_ID);
476 button->SetIsDefault(true); 476 button->SetIsDefault(true);
477 477
478 GetContentsView()->AddChildView(button); 478 GetContentsView()->AddChildView(button);
479 button->SetBounds(150, y, width, 30); 479 button->SetBounds(150, y, width, 30);
480 480
481 button = MdTextButton::Create(NULL, ASCIIToUTF16("Cancel")); 481 button = MdTextButton::Create(NULL, ASCIIToUTF16("Cancel"));
482 button->set_id(kCancelButtonID); 482 button->set_id(CANCEL_BUTTON_ID);
483 GetContentsView()->AddChildView(button); 483 GetContentsView()->AddChildView(button);
484 button->SetBounds(220, y, width, 30); 484 button->SetBounds(220, y, width, 30);
485 485
486 button = MdTextButton::Create(NULL, ASCIIToUTF16("Help")); 486 button = MdTextButton::Create(NULL, ASCIIToUTF16("Help"));
487 button->set_id(kHelpButtonID); 487 button->set_id(HELP_BUTTON_ID);
488 GetContentsView()->AddChildView(button); 488 GetContentsView()->AddChildView(button);
489 button->SetBounds(290, y, width, 30); 489 button->SetBounds(290, y, width, 30);
490 490
491 y += 40; 491 y += 40;
492 492
493 View* contents = NULL; 493 View* contents = NULL;
494 Link* link = NULL; 494 Link* link = NULL;
495 495
496 // Left bottom box with style checkboxes. 496 // Left bottom box with style checkboxes.
497 contents = new View(); 497 contents = new View();
498 contents->set_background(Background::CreateSolidBackground(SK_ColorWHITE)); 498 contents->set_background(Background::CreateSolidBackground(SK_ColorWHITE));
499 cb = new Checkbox(ASCIIToUTF16("Bold")); 499 cb = new Checkbox(ASCIIToUTF16("Bold"));
500 contents->AddChildView(cb); 500 contents->AddChildView(cb);
501 cb->SetBounds(10, 10, 50, 20); 501 cb->SetBounds(10, 10, 50, 20);
502 cb->set_id(kBoldCheckBoxID); 502 cb->set_id(BOLD_CHECK_BOX_ID);
503 503
504 cb = new Checkbox(ASCIIToUTF16("Italic")); 504 cb = new Checkbox(ASCIIToUTF16("Italic"));
505 contents->AddChildView(cb); 505 contents->AddChildView(cb);
506 cb->SetBounds(70, 10, 50, 20); 506 cb->SetBounds(70, 10, 50, 20);
507 cb->set_id(kItalicCheckBoxID); 507 cb->set_id(ITALIC_CHECK_BOX_ID);
508 508
509 cb = new Checkbox(ASCIIToUTF16("Underlined")); 509 cb = new Checkbox(ASCIIToUTF16("Underlined"));
510 contents->AddChildView(cb); 510 contents->AddChildView(cb);
511 cb->SetBounds(130, 10, 70, 20); 511 cb->SetBounds(130, 10, 70, 20);
512 cb->set_id(kUnderlinedCheckBoxID); 512 cb->set_id(UNDERLINED_CHECK_BOX_ID);
513 513
514 link = new Link(ASCIIToUTF16("Help")); 514 link = new Link(ASCIIToUTF16("Help"));
515 contents->AddChildView(link); 515 contents->AddChildView(link);
516 link->SetBounds(10, 35, 70, 10); 516 link->SetBounds(10, 35, 70, 10);
517 link->set_id(kStyleHelpLinkID); 517 link->set_id(STYLE_HELP_LINK_ID);
518 518
519 text_field = new Textfield(); 519 text_field = new Textfield();
520 contents->AddChildView(text_field); 520 contents->AddChildView(text_field);
521 text_field->SetBounds(10, 50, 100, 20); 521 text_field->SetBounds(10, 50, 100, 20);
522 text_field->set_id(kStyleTextEditID); 522 text_field->set_id(STYLE_TEXT_EDIT_ID);
523 523
524 style_tab_ = new TabbedPane(); 524 style_tab_ = new TabbedPane();
525 style_tab_->set_id(kStyleContainerID);
526 GetContentsView()->AddChildView(style_tab_); 525 GetContentsView()->AddChildView(style_tab_);
527 style_tab_->SetBounds(10, y, 210, 100); 526 style_tab_->SetBounds(10, y, 210, 100);
528 style_tab_->AddTab(ASCIIToUTF16("Style"), contents); 527 style_tab_->AddTab(ASCIIToUTF16("Style"), contents);
528 style_tab_->GetSelectedTabAsView()->set_id(STYLE_CONTAINER_ID);
529 style_tab_->AddTab(ASCIIToUTF16("Other"), new View()); 529 style_tab_->AddTab(ASCIIToUTF16("Other"), new View());
530 530
531 // Right bottom box with search. 531 // Right bottom box with search.
532 contents = new View(); 532 contents = new View();
533 contents->set_background(Background::CreateSolidBackground(SK_ColorWHITE)); 533 contents->set_background(Background::CreateSolidBackground(SK_ColorWHITE));
534 text_field = new Textfield(); 534 text_field = new Textfield();
535 contents->AddChildView(text_field); 535 contents->AddChildView(text_field);
536 text_field->SetBounds(10, 10, 100, 20); 536 text_field->SetBounds(10, 10, 100, 20);
537 text_field->set_id(kSearchTextfieldID); 537 text_field->set_id(SEARCH_TEXTFIELD_ID);
538 538
539 button = MdTextButton::Create(NULL, ASCIIToUTF16("Search")); 539 button = MdTextButton::Create(NULL, ASCIIToUTF16("Search"));
540 contents->AddChildView(button); 540 contents->AddChildView(button);
541 button->SetBounds(112, 5, 60, 30); 541 button->SetBounds(112, 5, 60, 30);
542 button->set_id(kSearchButtonID); 542 button->set_id(SEARCH_BUTTON_ID);
543 543
544 link = new Link(ASCIIToUTF16("Help")); 544 link = new Link(ASCIIToUTF16("Help"));
545 link->SetHorizontalAlignment(gfx::ALIGN_LEFT); 545 link->SetHorizontalAlignment(gfx::ALIGN_LEFT);
546 link->set_id(kHelpLinkID); 546 link->set_id(HELP_LINK_ID);
547 contents->AddChildView(link); 547 contents->AddChildView(link);
548 link->SetBounds(175, 10, 30, 20); 548 link->SetBounds(175, 10, 30, 20);
549 549
550 search_border_view_ = new BorderView(contents); 550 search_border_view_ = new BorderView(contents);
551 search_border_view_->set_id(kSearchContainerID); 551 search_border_view_->set_id(SEARCH_CONTAINER_ID);
552 552
553 GetContentsView()->AddChildView(search_border_view_); 553 GetContentsView()->AddChildView(search_border_view_);
554 search_border_view_->SetBounds(300, y, 240, 50); 554 search_border_view_->SetBounds(300, y, 240, 50);
555 555
556 y += 60; 556 y += 60;
557 557
558 contents = new View(); 558 contents = new View();
559 contents->SetFocusBehavior(View::FocusBehavior::ALWAYS); 559 contents->SetFocusBehavior(View::FocusBehavior::ALWAYS);
560 contents->set_background(Background::CreateSolidBackground(SK_ColorBLUE)); 560 contents->set_background(Background::CreateSolidBackground(SK_ColorBLUE));
561 contents->set_id(kThumbnailContainerID); 561 contents->set_id(THUMBNAIL_CONTAINER_ID);
562 button = MdTextButton::Create(NULL, ASCIIToUTF16("Star")); 562 button = MdTextButton::Create(NULL, ASCIIToUTF16("Star"));
563 contents->AddChildView(button); 563 contents->AddChildView(button);
564 button->SetBounds(5, 5, 50, 30); 564 button->SetBounds(5, 5, 50, 30);
565 button->set_id(kThumbnailStarID); 565 button->set_id(THUMBNAIL_STAR_ID);
566 button = MdTextButton::Create(NULL, ASCIIToUTF16("SuperStar")); 566 button = MdTextButton::Create(NULL, ASCIIToUTF16("SuperStar"));
567 contents->AddChildView(button); 567 contents->AddChildView(button);
568 button->SetBounds(60, 5, 100, 30); 568 button->SetBounds(60, 5, 100, 30);
569 button->set_id(kThumbnailSuperStarID); 569 button->set_id(THUMBNAIL_SUPER_STAR_ID);
570 570
571 GetContentsView()->AddChildView(contents); 571 GetContentsView()->AddChildView(contents);
572 contents->SetBounds(250, y, 200, 50); 572 contents->SetBounds(250, y, 200, 50);
573 // We can only call RadioButton::SetChecked() on the radio-button is part of 573 // We can only call RadioButton::SetChecked() on the radio-button is part of
574 // the view hierarchy. 574 // the view hierarchy.
575 radio_button_to_check->SetChecked(true); 575 radio_button_to_check->SetChecked(true);
576 } 576 }
577 577
578 TEST_F(FocusTraversalTest, NormalTraversal) { 578 TEST_F(FocusTraversalTest, NormalTraversal) {
579 const int kTraversalIDs[] = { kTopCheckBoxID, kAppleTextfieldID, 579 const int kTraversalIDs[] = {TOP_CHECK_BOX_ID,
580 kOrangeTextfieldID, kBananaTextfieldID, kKiwiTextfieldID, 580 APPLE_TEXTFIELD_ID,
581 kFruitButtonID, kFruitCheckBoxID, kComboboxID, kBroccoliButtonID, 581 ORANGE_TEXTFIELD_ID,
582 kRosettaLinkID, kStupeurEtTremblementLinkID, 582 BANANA_TEXTFIELD_ID,
583 kDinerGameLinkID, kRidiculeLinkID, kClosetLinkID, kVisitingLinkID, 583 KIWI_TEXTFIELD_ID,
584 kAmelieLinkID, kJoyeuxNoelLinkID, kCampingLinkID, kBriceDeNiceLinkID, 584 FRUIT_BUTTON_ID,
585 kTaxiLinkID, kAsterixLinkID, kOKButtonID, kCancelButtonID, kHelpButtonID, 585 FRUIT_CHECK_BOX_ID,
586 kStyleContainerID, kBoldCheckBoxID, kItalicCheckBoxID, 586 COMBOBOX_ID,
587 kUnderlinedCheckBoxID, kStyleHelpLinkID, kStyleTextEditID, 587 BROCCOLI_BUTTON_ID,
588 kSearchTextfieldID, kSearchButtonID, kHelpLinkID, 588 ROSETTA_LINK_ID,
589 kThumbnailContainerID, kThumbnailStarID, kThumbnailSuperStarID }; 589 STUPEUR_ET_TREMBLEMENT_LINK_ID,
590 DINER_GAME_LINK_ID,
591 RIDICULE_LINK_ID,
592 CLOSET_LINK_ID,
593 VISITING_LINK_ID,
594 AMELIE_LINK_ID,
595 JOYEUX_NOEL_LINK_ID,
596 CAMPING_LINK_ID,
597 BRICE_DE_NICE_LINK_ID,
598 TAXI_LINK_ID,
599 ASTERIX_LINK_ID,
600 O_K_BUTTON_ID,
601 CANCEL_BUTTON_ID,
602 HELP_BUTTON_ID,
603 STYLE_CONTAINER_ID,
604 BOLD_CHECK_BOX_ID,
605 ITALIC_CHECK_BOX_ID,
606 UNDERLINED_CHECK_BOX_ID,
607 STYLE_HELP_LINK_ID,
608 STYLE_TEXT_EDIT_ID,
609 SEARCH_TEXTFIELD_ID,
610 SEARCH_BUTTON_ID,
611 HELP_LINK_ID,
612 THUMBNAIL_CONTAINER_ID,
613 THUMBNAIL_STAR_ID,
614 THUMBNAIL_SUPER_STAR_ID};
590 615
591 SCOPED_TRACE("NormalTraversal"); 616 SCOPED_TRACE("NormalTraversal");
592 617
593 // Let's traverse the whole focus hierarchy (several times, to make sure it 618 // Let's traverse the whole focus hierarchy (several times, to make sure it
594 // loops OK). 619 // loops OK).
595 GetFocusManager()->ClearFocus(); 620 GetFocusManager()->ClearFocus();
596 AdvanceEntireFocusLoop(kTraversalIDs, false); 621 AdvanceEntireFocusLoop(kTraversalIDs, false);
597 622
598 // Let's traverse in reverse order. 623 // Let's traverse in reverse order.
599 GetFocusManager()->ClearFocus(); 624 GetFocusManager()->ClearFocus();
600 AdvanceEntireFocusLoop(kTraversalIDs, true); 625 AdvanceEntireFocusLoop(kTraversalIDs, true);
601 } 626 }
602 627
603 #if defined(OS_MACOSX) 628 #if defined(OS_MACOSX)
604 // Test focus traversal with full keyboard access off on Mac. 629 // Test focus traversal with full keyboard access off on Mac.
605 TEST_F(FocusTraversalTest, NormalTraversalMac) { 630 TEST_F(FocusTraversalTest, NormalTraversalMac) {
606 GetFocusManager()->SetKeyboardAccessible(false); 631 GetFocusManager()->SetKeyboardAccessible(false);
607 632
608 // Now only views with FocusBehavior of ALWAYS will be focusable. 633 // Now only views with FocusBehavior of ALWAYS will be focusable.
609 const int kTraversalIDs[] = {kAppleTextfieldID, kOrangeTextfieldID, 634 const int kTraversalIDs[] = {APPLE_TEXTFIELD_ID, ORANGE_TEXTFIELD_ID,
610 kBananaTextfieldID, kKiwiTextfieldID, 635 BANANA_TEXTFIELD_ID, KIWI_TEXTFIELD_ID,
611 kStyleTextEditID, kSearchTextfieldID, 636 STYLE_TEXT_EDIT_ID, SEARCH_TEXTFIELD_ID,
612 kThumbnailContainerID}; 637 THUMBNAIL_CONTAINER_ID};
613 638
614 SCOPED_TRACE("NormalTraversalMac"); 639 SCOPED_TRACE("NormalTraversalMac");
615 640
616 // Let's traverse the whole focus hierarchy (several times, to make sure it 641 // Let's traverse the whole focus hierarchy (several times, to make sure it
617 // loops OK). 642 // loops OK).
618 GetFocusManager()->ClearFocus(); 643 GetFocusManager()->ClearFocus();
619 AdvanceEntireFocusLoop(kTraversalIDs, false); 644 AdvanceEntireFocusLoop(kTraversalIDs, false);
620 645
621 // Let's traverse in reverse order. 646 // Let's traverse in reverse order.
622 GetFocusManager()->ClearFocus(); 647 GetFocusManager()->ClearFocus();
623 AdvanceEntireFocusLoop(kTraversalIDs, true); 648 AdvanceEntireFocusLoop(kTraversalIDs, true);
624 } 649 }
625 650
626 // Test toggling full keyboard access correctly changes the focused view on Mac. 651 // Test toggling full keyboard access correctly changes the focused view on Mac.
627 TEST_F(FocusTraversalTest, FullKeyboardToggle) { 652 TEST_F(FocusTraversalTest, FullKeyboardToggle) {
628 // Give focus to kTopCheckBoxID . 653 // Give focus to TOP_CHECK_BOX_ID .
629 FindViewByID(kTopCheckBoxID)->RequestFocus(); 654 FindViewByID(TOP_CHECK_BOX_ID)->RequestFocus();
630 EXPECT_EQ(kTopCheckBoxID, GetFocusManager()->GetFocusedView()->id()); 655 EXPECT_EQ(TOP_CHECK_BOX_ID, GetFocusManager()->GetFocusedView()->id());
631 656
632 // Turn off full keyboard access. Focus should move to next view with ALWAYS 657 // Turn off full keyboard access. Focus should move to next view with ALWAYS
633 // focus behavior. 658 // focus behavior.
634 GetFocusManager()->SetKeyboardAccessible(false); 659 GetFocusManager()->SetKeyboardAccessible(false);
635 EXPECT_EQ(kAppleTextfieldID, GetFocusManager()->GetFocusedView()->id()); 660 EXPECT_EQ(APPLE_TEXTFIELD_ID, GetFocusManager()->GetFocusedView()->id());
636 661
637 // Turning on full keyboard access should not change the focused view. 662 // Turning on full keyboard access should not change the focused view.
638 GetFocusManager()->SetKeyboardAccessible(true); 663 GetFocusManager()->SetKeyboardAccessible(true);
639 EXPECT_EQ(kAppleTextfieldID, GetFocusManager()->GetFocusedView()->id()); 664 EXPECT_EQ(APPLE_TEXTFIELD_ID, GetFocusManager()->GetFocusedView()->id());
640 665
641 // Give focus to kSearchButtonID. 666 // Give focus to SEARCH_BUTTON_ID.
642 FindViewByID(kSearchButtonID)->RequestFocus(); 667 FindViewByID(SEARCH_BUTTON_ID)->RequestFocus();
643 EXPECT_EQ(kSearchButtonID, GetFocusManager()->GetFocusedView()->id()); 668 EXPECT_EQ(SEARCH_BUTTON_ID, GetFocusManager()->GetFocusedView()->id());
644 669
645 // Turn off full keyboard access. Focus should move to next view with ALWAYS 670 // Turn off full keyboard access. Focus should move to next view with ALWAYS
646 // focus behavior. 671 // focus behavior.
647 GetFocusManager()->SetKeyboardAccessible(false); 672 GetFocusManager()->SetKeyboardAccessible(false);
648 EXPECT_EQ(kThumbnailContainerID, GetFocusManager()->GetFocusedView()->id()); 673 EXPECT_EQ(THUMBNAIL_CONTAINER_ID, GetFocusManager()->GetFocusedView()->id());
649 674
650 // See focus advances correctly in both directions. 675 // See focus advances correctly in both directions.
651 GetFocusManager()->AdvanceFocus(false); 676 GetFocusManager()->AdvanceFocus(false);
652 EXPECT_EQ(kAppleTextfieldID, GetFocusManager()->GetFocusedView()->id()); 677 EXPECT_EQ(APPLE_TEXTFIELD_ID, GetFocusManager()->GetFocusedView()->id());
653 678
654 GetFocusManager()->AdvanceFocus(true); 679 GetFocusManager()->AdvanceFocus(true);
655 EXPECT_EQ(kThumbnailContainerID, GetFocusManager()->GetFocusedView()->id()); 680 EXPECT_EQ(THUMBNAIL_CONTAINER_ID, GetFocusManager()->GetFocusedView()->id());
656 } 681 }
657 #endif // OS_MACOSX 682 #endif // OS_MACOSX
658 683
659 TEST_F(FocusTraversalTest, TraversalWithNonEnabledViews) { 684 TEST_F(FocusTraversalTest, TraversalWithNonEnabledViews) {
660 const int kDisabledIDs[] = { 685 const int kDisabledIDs[] = {
661 kBananaTextfieldID, kFruitCheckBoxID, kComboboxID, kAsparagusButtonID, 686 BANANA_TEXTFIELD_ID, FRUIT_CHECK_BOX_ID, COMBOBOX_ID,
662 kCauliflowerButtonID, kClosetLinkID, kVisitingLinkID, kBriceDeNiceLinkID, 687 ASPARAGUS_BUTTON_ID, CAULIFLOWER_BUTTON_ID, CLOSET_LINK_ID,
663 kTaxiLinkID, kAsterixLinkID, kHelpButtonID, kBoldCheckBoxID, 688 VISITING_LINK_ID, BRICE_DE_NICE_LINK_ID, TAXI_LINK_ID,
664 kSearchTextfieldID, kHelpLinkID }; 689 ASTERIX_LINK_ID, HELP_BUTTON_ID, BOLD_CHECK_BOX_ID,
690 SEARCH_TEXTFIELD_ID, HELP_LINK_ID};
665 691
666 const int kTraversalIDs[] = { kTopCheckBoxID, kAppleTextfieldID, 692 const int kTraversalIDs[] = {
667 kOrangeTextfieldID, kKiwiTextfieldID, kFruitButtonID, kBroccoliButtonID, 693 TOP_CHECK_BOX_ID, APPLE_TEXTFIELD_ID,
668 kRosettaLinkID, kStupeurEtTremblementLinkID, kDinerGameLinkID, 694 ORANGE_TEXTFIELD_ID, KIWI_TEXTFIELD_ID,
669 kRidiculeLinkID, kAmelieLinkID, kJoyeuxNoelLinkID, kCampingLinkID, 695 FRUIT_BUTTON_ID, BROCCOLI_BUTTON_ID,
670 kOKButtonID, kCancelButtonID, kStyleContainerID, kItalicCheckBoxID, 696 ROSETTA_LINK_ID, STUPEUR_ET_TREMBLEMENT_LINK_ID,
671 kUnderlinedCheckBoxID, kStyleHelpLinkID, kStyleTextEditID, 697 DINER_GAME_LINK_ID, RIDICULE_LINK_ID,
672 kSearchButtonID, kThumbnailContainerID, kThumbnailStarID, 698 AMELIE_LINK_ID, JOYEUX_NOEL_LINK_ID,
673 kThumbnailSuperStarID }; 699 CAMPING_LINK_ID, O_K_BUTTON_ID,
700 CANCEL_BUTTON_ID, STYLE_CONTAINER_ID,
701 ITALIC_CHECK_BOX_ID, UNDERLINED_CHECK_BOX_ID,
702 STYLE_HELP_LINK_ID, STYLE_TEXT_EDIT_ID,
703 SEARCH_BUTTON_ID, THUMBNAIL_CONTAINER_ID,
704 THUMBNAIL_STAR_ID, THUMBNAIL_SUPER_STAR_ID};
674 705
675 SCOPED_TRACE("TraversalWithNonEnabledViews"); 706 SCOPED_TRACE("TraversalWithNonEnabledViews");
676 707
677 // Let's disable some views. 708 // Let's disable some views.
678 for (size_t i = 0; i < arraysize(kDisabledIDs); i++) { 709 for (size_t i = 0; i < arraysize(kDisabledIDs); i++) {
679 View* v = FindViewByID(kDisabledIDs[i]); 710 View* v = FindViewByID(kDisabledIDs[i]);
680 ASSERT_TRUE(v != NULL); 711 ASSERT_TRUE(v != NULL);
681 v->SetEnabled(false); 712 v->SetEnabled(false);
682 } 713 }
683 714
684 // Let's do one traversal (several times, to make sure it loops ok). 715 // Let's do one traversal (several times, to make sure it loops ok).
685 GetFocusManager()->ClearFocus(); 716 GetFocusManager()->ClearFocus();
686 AdvanceEntireFocusLoop(kTraversalIDs, false); 717 AdvanceEntireFocusLoop(kTraversalIDs, false);
687 718
688 // Same thing in reverse. 719 // Same thing in reverse.
689 GetFocusManager()->ClearFocus(); 720 GetFocusManager()->ClearFocus();
690 AdvanceEntireFocusLoop(kTraversalIDs, true); 721 AdvanceEntireFocusLoop(kTraversalIDs, true);
691 } 722 }
692 723
693 TEST_F(FocusTraversalTest, TraversalWithInvisibleViews) { 724 TEST_F(FocusTraversalTest, TraversalWithInvisibleViews) {
694 const int kInvisibleIDs[] = { kTopCheckBoxID, kOKButtonID, 725 const int kInvisibleIDs[] = {TOP_CHECK_BOX_ID, O_K_BUTTON_ID,
695 kThumbnailContainerID }; 726 THUMBNAIL_CONTAINER_ID};
696 727
697 const int kTraversalIDs[] = { kAppleTextfieldID, kOrangeTextfieldID, 728 const int kTraversalIDs[] = {
698 kBananaTextfieldID, kKiwiTextfieldID, kFruitButtonID, kFruitCheckBoxID, 729 APPLE_TEXTFIELD_ID, ORANGE_TEXTFIELD_ID,
699 kComboboxID, kBroccoliButtonID, kRosettaLinkID, 730 BANANA_TEXTFIELD_ID, KIWI_TEXTFIELD_ID,
700 kStupeurEtTremblementLinkID, kDinerGameLinkID, kRidiculeLinkID, 731 FRUIT_BUTTON_ID, FRUIT_CHECK_BOX_ID,
701 kClosetLinkID, kVisitingLinkID, kAmelieLinkID, kJoyeuxNoelLinkID, 732 COMBOBOX_ID, BROCCOLI_BUTTON_ID,
702 kCampingLinkID, kBriceDeNiceLinkID, kTaxiLinkID, kAsterixLinkID, 733 ROSETTA_LINK_ID, STUPEUR_ET_TREMBLEMENT_LINK_ID,
703 kCancelButtonID, kHelpButtonID, kStyleContainerID, kBoldCheckBoxID, 734 DINER_GAME_LINK_ID, RIDICULE_LINK_ID,
704 kItalicCheckBoxID, kUnderlinedCheckBoxID, kStyleHelpLinkID, 735 CLOSET_LINK_ID, VISITING_LINK_ID,
705 kStyleTextEditID, kSearchTextfieldID, kSearchButtonID, kHelpLinkID }; 736 AMELIE_LINK_ID, JOYEUX_NOEL_LINK_ID,
737 CAMPING_LINK_ID, BRICE_DE_NICE_LINK_ID,
738 TAXI_LINK_ID, ASTERIX_LINK_ID,
739 CANCEL_BUTTON_ID, HELP_BUTTON_ID,
740 STYLE_CONTAINER_ID, BOLD_CHECK_BOX_ID,
741 ITALIC_CHECK_BOX_ID, UNDERLINED_CHECK_BOX_ID,
742 STYLE_HELP_LINK_ID, STYLE_TEXT_EDIT_ID,
743 SEARCH_TEXTFIELD_ID, SEARCH_BUTTON_ID,
744 HELP_LINK_ID};
706 745
707 SCOPED_TRACE("TraversalWithInvisibleViews"); 746 SCOPED_TRACE("TraversalWithInvisibleViews");
708 747
709 // Let's make some views invisible. 748 // Let's make some views invisible.
710 for (size_t i = 0; i < arraysize(kInvisibleIDs); i++) { 749 for (size_t i = 0; i < arraysize(kInvisibleIDs); i++) {
711 View* v = FindViewByID(kInvisibleIDs[i]); 750 View* v = FindViewByID(kInvisibleIDs[i]);
712 ASSERT_TRUE(v != NULL); 751 ASSERT_TRUE(v != NULL);
713 v->SetVisible(false); 752 v->SetVisible(false);
714 } 753 }
715 754
716 // Let's do one traversal (several times, to make sure it loops ok). 755 // Let's do one traversal (several times, to make sure it loops ok).
717 GetFocusManager()->ClearFocus(); 756 GetFocusManager()->ClearFocus();
718 AdvanceEntireFocusLoop(kTraversalIDs, false); 757 AdvanceEntireFocusLoop(kTraversalIDs, false);
719 758
720 // Same thing in reverse. 759 // Same thing in reverse.
721 GetFocusManager()->ClearFocus(); 760 GetFocusManager()->ClearFocus();
722 AdvanceEntireFocusLoop(kTraversalIDs, true); 761 AdvanceEntireFocusLoop(kTraversalIDs, true);
723 } 762 }
724 763
725 TEST_F(FocusTraversalTest, PaneTraversal) { 764 TEST_F(FocusTraversalTest, PaneTraversal) {
726 // Tests trapping the traversal within a pane - useful for full 765 // Tests trapping the traversal within a pane - useful for full
727 // keyboard accessibility for toolbars. 766 // keyboard accessibility for toolbars.
728 767
729 // First test the left container. 768 // First test the left container.
730 const int kLeftTraversalIDs[] = { 769 const int kLeftTraversalIDs[] = {APPLE_TEXTFIELD_ID, ORANGE_TEXTFIELD_ID,
731 kAppleTextfieldID, 770 BANANA_TEXTFIELD_ID, KIWI_TEXTFIELD_ID,
732 kOrangeTextfieldID, kBananaTextfieldID, kKiwiTextfieldID, 771 FRUIT_BUTTON_ID, FRUIT_CHECK_BOX_ID,
733 kFruitButtonID, kFruitCheckBoxID, kComboboxID }; 772 COMBOBOX_ID};
734 773
735 SCOPED_TRACE("PaneTraversal"); 774 SCOPED_TRACE("PaneTraversal");
736 775
737 FocusSearch focus_search_left(left_container_, true, false); 776 FocusSearch focus_search_left(left_container_, true, false);
738 left_container_->EnablePaneFocus(&focus_search_left); 777 left_container_->EnablePaneFocus(&focus_search_left);
739 FindViewByID(kComboboxID)->RequestFocus(); 778 FindViewByID(COMBOBOX_ID)->RequestFocus();
740 779
741 // Traverse the focus hierarchy within the pane several times. 780 // Traverse the focus hierarchy within the pane several times.
742 AdvanceEntireFocusLoop(kLeftTraversalIDs, false); 781 AdvanceEntireFocusLoop(kLeftTraversalIDs, false);
743 782
744 // Traverse in reverse order. 783 // Traverse in reverse order.
745 FindViewByID(kAppleTextfieldID)->RequestFocus(); 784 FindViewByID(APPLE_TEXTFIELD_ID)->RequestFocus();
746 AdvanceEntireFocusLoop(kLeftTraversalIDs, true); 785 AdvanceEntireFocusLoop(kLeftTraversalIDs, true);
747 786
748 // Now test the right container, but this time with accessibility mode. 787 // Now test the right container, but this time with accessibility mode.
749 // Make some links not focusable, but mark one of them as 788 // Make some links not focusable, but mark one of them as
750 // "accessibility focusable", so it should show up in the traversal. 789 // "accessibility focusable", so it should show up in the traversal.
751 const int kRightTraversalIDs[] = { 790 const int kRightTraversalIDs[] = {
752 kBroccoliButtonID, kDinerGameLinkID, kRidiculeLinkID, 791 BROCCOLI_BUTTON_ID, DINER_GAME_LINK_ID, RIDICULE_LINK_ID,
753 kClosetLinkID, kVisitingLinkID, kAmelieLinkID, kJoyeuxNoelLinkID, 792 CLOSET_LINK_ID, VISITING_LINK_ID, AMELIE_LINK_ID,
754 kCampingLinkID, kBriceDeNiceLinkID, kTaxiLinkID, kAsterixLinkID }; 793 JOYEUX_NOEL_LINK_ID, CAMPING_LINK_ID, BRICE_DE_NICE_LINK_ID,
794 TAXI_LINK_ID, ASTERIX_LINK_ID};
755 795
756 FocusSearch focus_search_right(right_container_, true, true); 796 FocusSearch focus_search_right(right_container_, true, true);
757 right_container_->EnablePaneFocus(&focus_search_right); 797 right_container_->EnablePaneFocus(&focus_search_right);
758 FindViewByID(kRosettaLinkID)->SetFocusBehavior(View::FocusBehavior::NEVER); 798 FindViewByID(ROSETTA_LINK_ID)->SetFocusBehavior(View::FocusBehavior::NEVER);
759 FindViewByID(kStupeurEtTremblementLinkID) 799 FindViewByID(STUPEUR_ET_TREMBLEMENT_LINK_ID)
760 ->SetFocusBehavior(View::FocusBehavior::NEVER); 800 ->SetFocusBehavior(View::FocusBehavior::NEVER);
761 FindViewByID(kDinerGameLinkID) 801 FindViewByID(DINER_GAME_LINK_ID)
762 ->SetFocusBehavior(View::FocusBehavior::ACCESSIBLE_ONLY); 802 ->SetFocusBehavior(View::FocusBehavior::ACCESSIBLE_ONLY);
763 FindViewByID(kAsterixLinkID)->RequestFocus(); 803 FindViewByID(ASTERIX_LINK_ID)->RequestFocus();
764 804
765 // Traverse the focus hierarchy within the pane several times. 805 // Traverse the focus hierarchy within the pane several times.
766 AdvanceEntireFocusLoop(kRightTraversalIDs, false); 806 AdvanceEntireFocusLoop(kRightTraversalIDs, false);
767 807
768 // Traverse in reverse order. 808 // Traverse in reverse order.
769 FindViewByID(kBroccoliButtonID)->RequestFocus(); 809 FindViewByID(BROCCOLI_BUTTON_ID)->RequestFocus();
770 AdvanceEntireFocusLoop(kRightTraversalIDs, true); 810 AdvanceEntireFocusLoop(kRightTraversalIDs, true);
771 } 811 }
772 812
773 class FocusTraversalNonFocusableTest : public FocusManagerTest { 813 class FocusTraversalNonFocusableTest : public FocusManagerTest {
774 public: 814 public:
775 ~FocusTraversalNonFocusableTest() override {} 815 ~FocusTraversalNonFocusableTest() override {}
776 816
777 void InitContentView() override; 817 void InitContentView() override;
778 818
779 protected: 819 protected:
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 GetFocusManager()->AdvanceFocus(false); 879 GetFocusManager()->AdvanceFocus(false);
840 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); 880 EXPECT_FALSE(GetFocusManager()->GetFocusedView());
841 881
842 // Advance backwards from the root node. 882 // Advance backwards from the root node.
843 GetFocusManager()->ClearFocus(); 883 GetFocusManager()->ClearFocus();
844 GetFocusManager()->AdvanceFocus(true); 884 GetFocusManager()->AdvanceFocus(true);
845 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); 885 EXPECT_FALSE(GetFocusManager()->GetFocusedView());
846 } 886 }
847 887
848 } // namespace views 888 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698