Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 ASSERT_EQ(1u, manager_.MenuItems(item2->extension_id())->size()); | 183 ASSERT_EQ(1u, manager_.MenuItems(item2->extension_id())->size()); |
| 184 ASSERT_EQ(item2, manager_.MenuItems(item2->extension_id())->at(0)); | 184 ASSERT_EQ(item2, manager_.MenuItems(item2->extension_id())->at(0)); |
| 185 | 185 |
| 186 // Remove child2_item. | 186 // Remove child2_item. |
| 187 ASSERT_TRUE(manager_.RemoveContextMenuItem(id2_child)); | 187 ASSERT_TRUE(manager_.RemoveContextMenuItem(id2_child)); |
| 188 ASSERT_EQ(1u, manager_.MenuItems(item2->extension_id())->size()); | 188 ASSERT_EQ(1u, manager_.MenuItems(item2->extension_id())->size()); |
| 189 ASSERT_EQ(item2, manager_.MenuItems(item2->extension_id())->at(0)); | 189 ASSERT_EQ(item2, manager_.MenuItems(item2->extension_id())->at(0)); |
| 190 ASSERT_EQ(0, item2->child_count()); | 190 ASSERT_EQ(0, item2->child_count()); |
| 191 } | 191 } |
| 192 | 192 |
| 193 TEST_F(MenuManagerTest, PopulateFromValue) { | |
| 194 Extension* extension = AddExtension("test"); | |
| 195 | |
| 196 bool incognito = true; | |
| 197 int type = MenuItem::CHECKBOX; | |
| 198 std::string title("TITLE"); | |
| 199 bool checked = true; | |
| 200 bool enabled = true; | |
| 201 MenuItem::ContextList contexts; | |
| 202 contexts.Add(MenuItem::PAGE); | |
| 203 contexts.Add(MenuItem::SELECTION); | |
| 204 int contexts_value = 0; | |
| 205 ASSERT_TRUE(contexts.ToValue()->GetAsInteger(&contexts_value)); | |
| 206 | |
| 207 ListValue* document_url_patterns(new ListValue()); | |
| 208 document_url_patterns->Append( | |
| 209 Value::CreateStringValue("http://www.google.com/*")); | |
| 210 document_url_patterns->Append( | |
| 211 Value::CreateStringValue("http://www.reddit.com/*")); | |
| 212 | |
| 213 ListValue* target_url_patterns(new ListValue()); | |
| 214 target_url_patterns->Append( | |
| 215 Value::CreateStringValue("http://www.yahoo.com/*")); | |
| 216 target_url_patterns->Append( | |
| 217 Value::CreateStringValue("http://www.facebook.com/*")); | |
| 218 | |
| 219 base::DictionaryValue value; | |
| 220 value.SetBoolean("incognito", incognito); | |
| 221 value.SetString("string_uid", std::string()); | |
| 222 value.SetInteger("type", type); | |
| 223 value.SetString("title", title); | |
| 224 value.SetBoolean("checked", checked); | |
| 225 value.SetBoolean("enabled", enabled); | |
| 226 value.SetInteger("contexts", contexts_value); | |
| 227 value.Set("document_url_patterns", document_url_patterns); | |
| 228 value.Set("target_url_patterns", target_url_patterns); | |
| 229 | |
| 230 std::string error; | |
| 231 scoped_ptr<MenuItem> item(MenuItem::Populate(extension->id(), value, &error)); | |
| 232 ASSERT_TRUE(item.get()); | |
| 233 | |
| 234 EXPECT_EQ(extension->id(), item->extension_id()); | |
| 235 EXPECT_EQ(incognito, item->incognito()); | |
| 236 EXPECT_EQ(title, item->title()); | |
| 237 EXPECT_EQ(checked, item->checked()); | |
| 238 EXPECT_EQ(item->checked(), item->checked()); | |
| 239 EXPECT_EQ(enabled, item->enabled()); | |
| 240 EXPECT_EQ(contexts, item->contexts()); | |
| 241 | |
| 242 URLPatternSet document_url_pattern_set; | |
| 243 document_url_pattern_set.Populate(*document_url_patterns, | |
| 244 URLPattern::SCHEME_ALL, | |
| 245 true, | |
| 246 &error); | |
| 247 EXPECT_EQ(document_url_pattern_set, item->document_url_patterns()); | |
| 248 | |
| 249 URLPatternSet target_url_pattern_set; | |
| 250 target_url_pattern_set.Populate(*target_url_patterns, | |
| 251 URLPattern::SCHEME_ALL, | |
| 252 true, | |
| 253 &error); | |
| 254 EXPECT_EQ(target_url_pattern_set, item->target_url_patterns()); | |
| 255 } | |
| 256 | |
| 193 // Tests that deleting a parent properly removes descendants. | 257 // Tests that deleting a parent properly removes descendants. |
| 194 TEST_F(MenuManagerTest, DeleteParent) { | 258 TEST_F(MenuManagerTest, DeleteParent) { |
| 195 Extension* extension = AddExtension("1111"); | 259 Extension* extension = AddExtension("1111"); |
| 196 | 260 |
| 197 // Set up 5 items to add. | 261 // Set up 5 items to add. |
| 198 MenuItem* item1 = CreateTestItem(extension); | 262 MenuItem* item1 = CreateTestItem(extension); |
| 199 MenuItem* item2 = CreateTestItem(extension); | 263 MenuItem* item2 = CreateTestItem(extension); |
| 200 MenuItem* item3 = CreateTestItemWithID(extension, "id3"); | 264 MenuItem* item3 = CreateTestItemWithID(extension, "id3"); |
| 201 MenuItem* item4 = CreateTestItemWithID(extension, "id4"); | 265 MenuItem* item4 = CreateTestItemWithID(extension, "id4"); |
| 202 MenuItem* item5 = CreateTestItem(extension); | 266 MenuItem* item5 = CreateTestItem(extension); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 | 436 |
| 373 // A mock message service for tests of MenuManager::ExecuteCommand. | 437 // A mock message service for tests of MenuManager::ExecuteCommand. |
| 374 class MockEventRouter : public EventRouter { | 438 class MockEventRouter : public EventRouter { |
| 375 public: | 439 public: |
| 376 explicit MockEventRouter(Profile* profile) : | 440 explicit MockEventRouter(Profile* profile) : |
| 377 EventRouter(profile) {} | 441 EventRouter(profile) {} |
| 378 | 442 |
| 379 MOCK_METHOD6(DispatchEventToExtensionMock, | 443 MOCK_METHOD6(DispatchEventToExtensionMock, |
| 380 void(const std::string& extension_id, | 444 void(const std::string& extension_id, |
| 381 const std::string& event_name, | 445 const std::string& event_name, |
| 382 base::ListValue* event_args, | 446 base::ListValue* event_args, |
|
not at google - send to devlin
2012/08/14 05:12:21
I don't know how mocks are supposed to work, but I
chebert
2012/08/14 18:56:53
I think that this is a mock specific thing, since
| |
| 383 Profile* source_profile, | 447 Profile* source_profile, |
| 384 const GURL& event_url, | 448 const GURL& event_url, |
| 385 EventRouter::UserGestureState state)); | 449 EventRouter::UserGestureState state)); |
| 386 | 450 |
| 387 virtual void DispatchEventToExtension(const std::string& extension_id, | 451 virtual void DispatchEventToExtension(const std::string& extension_id, |
| 388 const std::string& event_name, | 452 const std::string& event_name, |
| 389 scoped_ptr<base::ListValue> event_args, | 453 scoped_ptr<base::ListValue> event_args, |
| 390 Profile* source_profile, | 454 Profile* source_profile, |
| 391 const GURL& event_url, | 455 const GURL& event_url, |
| 392 EventRouter::UserGestureState state) { | 456 EventRouter::UserGestureState state) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 ASSERT_EQ(params.page_url.spec(), tmp); | 592 ASSERT_EQ(params.page_url.spec(), tmp); |
| 529 | 593 |
| 530 string16 tmp16; | 594 string16 tmp16; |
| 531 ASSERT_TRUE(info->GetString("selectionText", &tmp16)); | 595 ASSERT_TRUE(info->GetString("selectionText", &tmp16)); |
| 532 ASSERT_EQ(params.selection_text, tmp16); | 596 ASSERT_EQ(params.selection_text, tmp16); |
| 533 | 597 |
| 534 bool bool_tmp = true; | 598 bool bool_tmp = true; |
| 535 ASSERT_TRUE(info->GetBoolean("editable", &bool_tmp)); | 599 ASSERT_TRUE(info->GetBoolean("editable", &bool_tmp)); |
| 536 ASSERT_EQ(params.is_editable, bool_tmp); | 600 ASSERT_EQ(params.is_editable, bool_tmp); |
| 537 | 601 |
| 538 delete list; | 602 delete list; |
|
not at google - send to devlin
2012/08/14 05:12:21
make list a scoped_ptr so that you don't need to c
chebert
2012/08/14 18:56:53
This is another mock specific thing.
The address o
not at google - send to devlin
2012/08/14 22:04:49
You can't do
.WillOnce(SaveArg<2>(list.get())) th
chebert
2012/08/14 22:06:49
it would need to be
.WillOnce(SaveArg<2>(&(list.ge
| |
| 539 } | 603 } |
| 540 | 604 |
| 541 // Test that there is always only one radio item selected. | 605 // Test that there is always only one radio item selected. |
| 542 TEST_F(MenuManagerTest, SanitizeRadioButtons) { | 606 TEST_F(MenuManagerTest, SanitizeRadioButtons) { |
| 543 Extension* extension = AddExtension("test"); | 607 Extension* extension = AddExtension("test"); |
| 544 | 608 |
| 545 // A single unchecked item should get checked | 609 // A single unchecked item should get checked |
| 546 MenuItem* item1 = CreateTestItem(extension); | 610 MenuItem* item1 = CreateTestItem(extension); |
| 547 | 611 |
| 548 item1->set_type(MenuItem::RADIO); | 612 item1->set_type(MenuItem::RADIO); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 ASSERT_TRUE(child1->checked()); | 687 ASSERT_TRUE(child1->checked()); |
| 624 | 688 |
| 625 // Removing |parent| should cause only |child1| to be selected. | 689 // Removing |parent| should cause only |child1| to be selected. |
| 626 manager_.RemoveContextMenuItem(parent->id()); | 690 manager_.RemoveContextMenuItem(parent->id()); |
| 627 parent = NULL; | 691 parent = NULL; |
| 628 ASSERT_FALSE(new_item->checked()); | 692 ASSERT_FALSE(new_item->checked()); |
| 629 ASSERT_TRUE(child1->checked()); | 693 ASSERT_TRUE(child1->checked()); |
| 630 } | 694 } |
| 631 | 695 |
| 632 } // namespace extensions | 696 } // namespace extensions |
| OLD | NEW |