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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 ASSERT_TRUE(manager_.GetItemById(id1) == NULL); | 345 ASSERT_TRUE(manager_.GetItemById(id1) == NULL); |
346 ASSERT_TRUE(manager_.GetItemById(item2->id()) != NULL); | 346 ASSERT_TRUE(manager_.GetItemById(item2->id()) != NULL); |
347 } | 347 } |
348 | 348 |
349 // A mock message service for tests of ExtensionMenuManager::ExecuteCommand. | 349 // A mock message service for tests of ExtensionMenuManager::ExecuteCommand. |
350 class MockExtensionEventRouter : public ExtensionEventRouter { | 350 class MockExtensionEventRouter : public ExtensionEventRouter { |
351 public: | 351 public: |
352 explicit MockExtensionEventRouter(Profile* profile) : | 352 explicit MockExtensionEventRouter(Profile* profile) : |
353 ExtensionEventRouter(profile) {} | 353 ExtensionEventRouter(profile) {} |
354 | 354 |
355 MOCK_METHOD5(DispatchEventToExtension, void(const std::string& extension_id, | 355 MOCK_METHOD6(DispatchEventToExtension, |
356 const std::string& event_name, | 356 void(const std::string& extension_id, |
357 const std::string& event_args, | 357 const std::string& event_name, |
358 Profile* source_profile, | 358 const std::string& event_args, |
359 const GURL& event_url)); | 359 Profile* source_profile, |
| 360 const GURL& event_url, |
| 361 ExtensionEventRouter::UserGestureState state)); |
360 | 362 |
361 | 363 |
362 private: | 364 private: |
363 DISALLOW_COPY_AND_ASSIGN(MockExtensionEventRouter); | 365 DISALLOW_COPY_AND_ASSIGN(MockExtensionEventRouter); |
364 }; | 366 }; |
365 | 367 |
366 // A mock profile for tests of ExtensionMenuManager::ExecuteCommand. | 368 // A mock profile for tests of ExtensionMenuManager::ExecuteCommand. |
367 class MockTestingProfile : public TestingProfile { | 369 class MockTestingProfile : public TestingProfile { |
368 public: | 370 public: |
369 MockTestingProfile() {} | 371 MockTestingProfile() {} |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 445 |
444 EXPECT_CALL(profile, GetExtensionEventRouter()) | 446 EXPECT_CALL(profile, GetExtensionEventRouter()) |
445 .Times(1) | 447 .Times(1) |
446 .WillOnce(Return(mock_event_router.get())); | 448 .WillOnce(Return(mock_event_router.get())); |
447 | 449 |
448 // Use the magic of googlemock to save a parameter to our mock's | 450 // Use the magic of googlemock to save a parameter to our mock's |
449 // DispatchEventToExtension method into event_args. | 451 // DispatchEventToExtension method into event_args. |
450 std::string event_args; | 452 std::string event_args; |
451 std::string expected_event_name = "contextMenus"; | 453 std::string expected_event_name = "contextMenus"; |
452 EXPECT_CALL(*mock_event_router.get(), | 454 EXPECT_CALL(*mock_event_router.get(), |
453 DispatchEventToExtension(item->extension_id(), | 455 DispatchEventToExtension( |
454 expected_event_name, | 456 item->extension_id(), |
455 _, | 457 expected_event_name, |
456 &profile, | 458 _, |
457 GURL())) | 459 &profile, |
| 460 GURL(), |
| 461 ExtensionEventRouter::USER_GESTURE_ENABLED)) |
458 .Times(1) | 462 .Times(1) |
459 .WillOnce(SaveArg<2>(&event_args)); | 463 .WillOnce(SaveArg<2>(&event_args)); |
460 | 464 |
461 manager_.ExecuteCommand(&profile, NULL /* tab_contents */, params, id); | 465 manager_.ExecuteCommand(&profile, NULL /* tab_contents */, params, id); |
462 | 466 |
463 // Parse the json event_args, which should turn into a 2-element list where | 467 // Parse the json event_args, which should turn into a 2-element list where |
464 // the first element is a dictionary we want to inspect for the correct | 468 // the first element is a dictionary we want to inspect for the correct |
465 // values. | 469 // values. |
466 scoped_ptr<Value> result(base::JSONReader::Read(event_args, true)); | 470 scoped_ptr<Value> result(base::JSONReader::Read(event_args, true)); |
467 Value* value = result.get(); | 471 Value* value = result.get(); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 manager_.ChangeParent(child1->id(), NULL); | 581 manager_.ChangeParent(child1->id(), NULL); |
578 ASSERT_TRUE(new_item->checked()); | 582 ASSERT_TRUE(new_item->checked()); |
579 ASSERT_TRUE(child1->checked()); | 583 ASSERT_TRUE(child1->checked()); |
580 | 584 |
581 // Removing |parent| should cause only |child1| to be selected. | 585 // Removing |parent| should cause only |child1| to be selected. |
582 manager_.RemoveContextMenuItem(parent->id()); | 586 manager_.RemoveContextMenuItem(parent->id()); |
583 parent = NULL; | 587 parent = NULL; |
584 ASSERT_FALSE(new_item->checked()); | 588 ASSERT_FALSE(new_item->checked()); |
585 ASSERT_TRUE(child1->checked()); | 589 ASSERT_TRUE(child1->checked()); |
586 } | 590 } |
587 | |
OLD | NEW |