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