| 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/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 ASSERT_TRUE(manager_.GetItemById(id1) == NULL); | 340 ASSERT_TRUE(manager_.GetItemById(id1) == NULL); |
| 341 ASSERT_TRUE(manager_.GetItemById(item2->id()) != NULL); | 341 ASSERT_TRUE(manager_.GetItemById(item2->id()) != NULL); |
| 342 } | 342 } |
| 343 | 343 |
| 344 // A mock message service for tests of ExtensionMenuManager::ExecuteCommand. | 344 // A mock message service for tests of ExtensionMenuManager::ExecuteCommand. |
| 345 class MockExtensionEventRouter : public ExtensionEventRouter { | 345 class MockExtensionEventRouter : public ExtensionEventRouter { |
| 346 public: | 346 public: |
| 347 explicit MockExtensionEventRouter(Profile* profile) : | 347 explicit MockExtensionEventRouter(Profile* profile) : |
| 348 ExtensionEventRouter(profile) {} | 348 ExtensionEventRouter(profile) {} |
| 349 | 349 |
| 350 MOCK_METHOD6(DispatchEventImpl, void(const std::string& extension_id, | 350 MOCK_METHOD5(DispatchEventToExtension, void(const std::string& extension_id, |
| 351 const std::string& event_name, | 351 const std::string& event_name, |
| 352 const std::string& event_args, | 352 const std::string& event_args, |
| 353 Profile* source_profile, | 353 Profile* source_profile, |
| 354 const std::string& cross_incognito_args, | 354 const GURL& event_url)); |
| 355 const GURL& event_url)); | 355 |
| 356 | 356 |
| 357 private: | 357 private: |
| 358 DISALLOW_COPY_AND_ASSIGN(MockExtensionEventRouter); | 358 DISALLOW_COPY_AND_ASSIGN(MockExtensionEventRouter); |
| 359 }; | 359 }; |
| 360 | 360 |
| 361 // A mock profile for tests of ExtensionMenuManager::ExecuteCommand. | 361 // A mock profile for tests of ExtensionMenuManager::ExecuteCommand. |
| 362 class MockTestingProfile : public TestingProfile { | 362 class MockTestingProfile : public TestingProfile { |
| 363 public: | 363 public: |
| 364 MockTestingProfile() {} | 364 MockTestingProfile() {} |
| 365 MOCK_METHOD0(GetExtensionEventRouter, ExtensionEventRouter*()); | 365 MOCK_METHOD0(GetExtensionEventRouter, ExtensionEventRouter*()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 | 438 |
| 439 EXPECT_CALL(profile, GetExtensionEventRouter()) | 439 EXPECT_CALL(profile, GetExtensionEventRouter()) |
| 440 .Times(1) | 440 .Times(1) |
| 441 .WillOnce(Return(mock_event_router.get())); | 441 .WillOnce(Return(mock_event_router.get())); |
| 442 | 442 |
| 443 // Use the magic of googlemock to save a parameter to our mock's | 443 // Use the magic of googlemock to save a parameter to our mock's |
| 444 // DispatchEventToExtension method into event_args. | 444 // DispatchEventToExtension method into event_args. |
| 445 std::string event_args; | 445 std::string event_args; |
| 446 std::string expected_event_name = "contextMenus"; | 446 std::string expected_event_name = "contextMenus"; |
| 447 EXPECT_CALL(*mock_event_router.get(), | 447 EXPECT_CALL(*mock_event_router.get(), |
| 448 DispatchEventImpl(item->extension_id(), | 448 DispatchEventToExtension(item->extension_id(), |
| 449 expected_event_name, | 449 expected_event_name, |
| 450 _, | 450 _, |
| 451 &profile, | 451 &profile, |
| 452 "", | 452 GURL())) |
| 453 GURL())) | |
| 454 .Times(1) | 453 .Times(1) |
| 455 .WillOnce(SaveArg<2>(&event_args)); | 454 .WillOnce(SaveArg<2>(&event_args)); |
| 456 | 455 |
| 457 manager_.ExecuteCommand(&profile, NULL /* tab_contents */, params, id); | 456 manager_.ExecuteCommand(&profile, NULL /* tab_contents */, params, id); |
| 458 | 457 |
| 459 // Parse the json event_args, which should turn into a 2-element list where | 458 // Parse the json event_args, which should turn into a 2-element list where |
| 460 // the first element is a dictionary we want to inspect for the correct | 459 // the first element is a dictionary we want to inspect for the correct |
| 461 // values. | 460 // values. |
| 462 scoped_ptr<Value> result(base::JSONReader::Read(event_args, true)); | 461 scoped_ptr<Value> result(base::JSONReader::Read(event_args, true)); |
| 463 Value* value = result.get(); | 462 Value* value = result.get(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 482 ASSERT_EQ(params.page_url.spec(), tmp); | 481 ASSERT_EQ(params.page_url.spec(), tmp); |
| 483 | 482 |
| 484 string16 tmp16; | 483 string16 tmp16; |
| 485 ASSERT_TRUE(info->GetString("selectionText", &tmp16)); | 484 ASSERT_TRUE(info->GetString("selectionText", &tmp16)); |
| 486 ASSERT_EQ(params.selection_text, tmp16); | 485 ASSERT_EQ(params.selection_text, tmp16); |
| 487 | 486 |
| 488 bool bool_tmp = true; | 487 bool bool_tmp = true; |
| 489 ASSERT_TRUE(info->GetBoolean("editable", &bool_tmp)); | 488 ASSERT_TRUE(info->GetBoolean("editable", &bool_tmp)); |
| 490 ASSERT_EQ(params.is_editable, bool_tmp); | 489 ASSERT_EQ(params.is_editable, bool_tmp); |
| 491 } | 490 } |
| OLD | NEW |