OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 | 244 |
245 const ExtensionMenuItem::List* items = | 245 const ExtensionMenuItem::List* items = |
246 manager_.MenuItems(item1->extension_id()); | 246 manager_.MenuItems(item1->extension_id()); |
247 ASSERT_EQ(2u, items->size()); | 247 ASSERT_EQ(2u, items->size()); |
248 ASSERT_EQ(item1, items->at(0)); | 248 ASSERT_EQ(item1, items->at(0)); |
249 ASSERT_EQ(item2, items->at(1)); | 249 ASSERT_EQ(item2, items->at(1)); |
250 | 250 |
251 // Now create a third item, initially add it as a child of item1, then move | 251 // Now create a third item, initially add it as a child of item1, then move |
252 // it to be a child of item2. | 252 // it to be a child of item2. |
253 ExtensionMenuItem* item3 = CreateTestItem(extension1); | 253 ExtensionMenuItem* item3 = CreateTestItem(extension1); |
254 | |
255 ASSERT_TRUE(manager_.AddChildItem(item1->id(), item3)); | 254 ASSERT_TRUE(manager_.AddChildItem(item1->id(), item3)); |
256 ASSERT_EQ(1, item1->child_count()); | 255 ASSERT_EQ(1, item1->child_count()); |
257 ASSERT_EQ(item3, item1->children()[0]); | 256 ASSERT_EQ(item3, item1->children()[0]); |
258 | 257 |
259 ASSERT_TRUE(manager_.ChangeParent(item3->id(), &item2->id())); | 258 ASSERT_TRUE(manager_.ChangeParent(item3->id(), &item2->id())); |
260 ASSERT_EQ(0, item1->child_count()); | 259 ASSERT_EQ(0, item1->child_count()); |
261 ASSERT_EQ(1, item2->child_count()); | 260 ASSERT_EQ(1, item2->child_count()); |
262 ASSERT_EQ(item3, item2->children()[0]); | 261 ASSERT_EQ(item3, item2->children()[0]); |
263 | 262 |
264 // Move item2 to be a child of item1. | 263 // Move item2 to be a child of item1. |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 ASSERT_EQ(params.page_url.spec(), tmp); | 485 ASSERT_EQ(params.page_url.spec(), tmp); |
487 | 486 |
488 string16 tmp16; | 487 string16 tmp16; |
489 ASSERT_TRUE(info->GetString("selectionText", &tmp16)); | 488 ASSERT_TRUE(info->GetString("selectionText", &tmp16)); |
490 ASSERT_EQ(params.selection_text, tmp16); | 489 ASSERT_EQ(params.selection_text, tmp16); |
491 | 490 |
492 bool bool_tmp = true; | 491 bool bool_tmp = true; |
493 ASSERT_TRUE(info->GetBoolean("editable", &bool_tmp)); | 492 ASSERT_TRUE(info->GetBoolean("editable", &bool_tmp)); |
494 ASSERT_EQ(params.is_editable, bool_tmp); | 493 ASSERT_EQ(params.is_editable, bool_tmp); |
495 } | 494 } |
495 | |
496 // Test that SanitizeRadioButtons will always leave a run of | |
497 // radio buttons with one item selected. | |
498 TEST_F(ExtensionMenuManagerTest, SanitizeRadioButtons) { | |
499 Extension* extension = AddExtension("test"); | |
500 | |
501 // A single unchecked item should get checked | |
502 ExtensionMenuItem* item1 = CreateTestItem(extension); | |
503 | |
504 manager_.AddContextItem(extension, item1); | |
505 item1->set_type(ExtensionMenuItem::RADIO); | |
506 item1->SetChecked(false); | |
507 ASSERT_FALSE(item1->checked()); | |
508 manager_.SanitizeRadioButtons(); | |
509 ASSERT_TRUE(item1->checked()); | |
510 | |
511 // In a run of two unchecked items, the first should get selected. | |
512 item1->SetChecked(false); | |
513 ExtensionMenuItem* item2 = CreateTestItem(extension); | |
514 item2->set_type(ExtensionMenuItem::RADIO); | |
515 item2->SetChecked(false); | |
516 manager_.AddContextItem(extension, item2); | |
517 ASSERT_FALSE(item1->checked()); | |
518 ASSERT_FALSE(item2->checked()); | |
519 manager_.SanitizeRadioButtons(); | |
520 ASSERT_TRUE(item1->checked()); | |
521 ASSERT_FALSE(item2->checked()); | |
522 | |
523 // If multiple items are checked, only the last item should get checked. | |
524 item1->SetChecked(true); | |
525 item2->SetChecked(true); | |
526 ASSERT_TRUE(item1->checked()); | |
527 ASSERT_TRUE(item2->checked()); | |
528 manager_.SanitizeRadioButtons(); | |
529 ASSERT_FALSE(item1->checked()); | |
530 ASSERT_TRUE(item2->checked()); | |
531 | |
532 // If the checked item is removed, the new first item should get checked. | |
533 item1->SetChecked(false); | |
534 item2->SetChecked(true); | |
535 ASSERT_FALSE(item1->checked()); | |
536 ASSERT_TRUE(item2->checked()); | |
537 manager_.RemoveContextMenuItem(item2->id()); | |
538 manager_.SanitizeRadioButtons(); | |
539 ASSERT_TRUE(item1->checked()); | |
540 | |
541 // If a checked item is added to a run that already has a checked item, | |
542 // then the new item should get checked. | |
543 item1->SetChecked(true); | |
544 ExtensionMenuItem* newItem = CreateTestItem(extension); | |
545 newItem->set_type(ExtensionMenuItem::RADIO); | |
546 newItem->SetChecked(true); | |
547 ASSERT_TRUE(item1->checked()); | |
548 ASSERT_TRUE(newItem->checked()); | |
549 manager_.AddContextItem(extension, newItem); | |
550 manager_.SanitizeRadioButtons(); | |
551 ASSERT_FALSE(item1->checked()); | |
552 ASSERT_TRUE(newItem->checked()); | |
553 } | |
554 | |
555 | |
Aaron Boodman
2011/12/15 00:53:55
Remove extra blank lines. There should be exactly
| |
OLD | NEW |