Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: chrome/browser/extensions/extension_menu_manager_unittest.cc

Issue 10454106: Dispatch a new event chrome.contextMenus.onClicked. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: names Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/scoped_temp_dir.h" 11 #include "base/scoped_temp_dir.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/extensions/extension_event_names.h"
14 #include "chrome/browser/extensions/extension_event_router.h" 15 #include "chrome/browser/extensions/extension_event_router.h"
15 #include "chrome/browser/extensions/extension_menu_manager.h" 16 #include "chrome/browser/extensions/extension_menu_manager.h"
16 #include "chrome/browser/extensions/test_extension_prefs.h" 17 #include "chrome/browser/extensions/test_extension_prefs.h"
17 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/chrome_paths.h" 19 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/extensions/extension.h" 20 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/extensions/extension_constants.h" 21 #include "chrome/common/extensions/extension_constants.h"
21 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
22 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
23 #include "content/public/common/context_menu_params.h" 24 #include "content/public/common/context_menu_params.h"
24 #include "content/test/test_browser_thread.h" 25 #include "content/test/test_browser_thread.h"
25 #include "testing/gmock/include/gmock/gmock.h" 26 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
27 28
28 using content::BrowserThread; 29 using content::BrowserThread;
29 using extensions::Extension; 30 using extensions::Extension;
30 using testing::_; 31 using testing::_;
31 using testing::AtLeast; 32 using testing::AtLeast;
33 using testing::InSequence;
32 using testing::Return; 34 using testing::Return;
33 using testing::SaveArg; 35 using testing::SaveArg;
34 36
35 // Base class for tests. 37 // Base class for tests.
36 class ExtensionMenuManagerTest : public testing::Test { 38 class ExtensionMenuManagerTest : public testing::Test {
37 public: 39 public:
38 ExtensionMenuManagerTest() 40 ExtensionMenuManagerTest()
39 : ui_thread_(BrowserThread::UI, &message_loop_), 41 : ui_thread_(BrowserThread::UI, &message_loop_),
40 file_thread_(BrowserThread::FILE, &message_loop_), 42 file_thread_(BrowserThread::FILE, &message_loop_),
41 manager_(&profile_), 43 manager_(&profile_),
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 ExtensionMenuItem::Id id = item->id(); 471 ExtensionMenuItem::Id id = item->id();
470 ASSERT_TRUE(manager_.AddContextItem(extension, item)); 472 ASSERT_TRUE(manager_.AddContextItem(extension, item));
471 473
472 EXPECT_CALL(profile, GetExtensionEventRouter()) 474 EXPECT_CALL(profile, GetExtensionEventRouter())
473 .Times(1) 475 .Times(1)
474 .WillOnce(Return(mock_event_router.get())); 476 .WillOnce(Return(mock_event_router.get()));
475 477
476 // Use the magic of googlemock to save a parameter to our mock's 478 // Use the magic of googlemock to save a parameter to our mock's
477 // DispatchEventToExtension method into event_args. 479 // DispatchEventToExtension method into event_args.
478 std::string event_args; 480 std::string event_args;
479 std::string expected_event_name = "contextMenus"; 481 {
480 EXPECT_CALL(*mock_event_router.get(), 482 InSequence s;
481 DispatchEventToExtension( 483 EXPECT_CALL(*mock_event_router.get(),
482 item->extension_id(), 484 DispatchEventToExtension(
483 expected_event_name, 485 item->extension_id(),
486 extension_event_names::kOnContextMenus,
484 _, 487 _,
485 &profile, 488 &profile,
486 GURL(), 489 GURL(),
487 ExtensionEventRouter::USER_GESTURE_ENABLED)) 490 ExtensionEventRouter::USER_GESTURE_ENABLED))
488 .Times(1) 491 .Times(1)
489 .WillOnce(SaveArg<2>(&event_args)); 492 .WillOnce(SaveArg<2>(&event_args));
490 493 EXPECT_CALL(*mock_event_router.get(),
494 DispatchEventToExtension(
495 item->extension_id(),
496 extension_event_names::kOnContextMenuClicked,
497 _,
498 &profile,
499 GURL(),
500 ExtensionEventRouter::USER_GESTURE_ENABLED))
501 .Times(1);
502 }
491 manager_.ExecuteCommand(&profile, NULL /* tab_contents */, params, id); 503 manager_.ExecuteCommand(&profile, NULL /* tab_contents */, params, id);
492 504
493 // Parse the json event_args, which should turn into a 2-element list where 505 // Parse the json event_args, which should turn into a 2-element list where
494 // the first element is a dictionary we want to inspect for the correct 506 // the first element is a dictionary we want to inspect for the correct
495 // values. 507 // values.
496 scoped_ptr<Value> result( 508 scoped_ptr<Value> result(
497 base::JSONReader::Read(event_args, base::JSON_ALLOW_TRAILING_COMMAS)); 509 base::JSONReader::Read(event_args, base::JSON_ALLOW_TRAILING_COMMAS));
498 Value* value = result.get(); 510 Value* value = result.get();
499 ASSERT_TRUE(result.get() != NULL); 511 ASSERT_TRUE(result.get() != NULL);
500 ASSERT_EQ(Value::TYPE_LIST, value->GetType()); 512 ASSERT_EQ(Value::TYPE_LIST, value->GetType());
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 manager_.ChangeParent(child1->id(), NULL); 620 manager_.ChangeParent(child1->id(), NULL);
609 ASSERT_TRUE(new_item->checked()); 621 ASSERT_TRUE(new_item->checked());
610 ASSERT_TRUE(child1->checked()); 622 ASSERT_TRUE(child1->checked());
611 623
612 // Removing |parent| should cause only |child1| to be selected. 624 // Removing |parent| should cause only |child1| to be selected.
613 manager_.RemoveContextMenuItem(parent->id()); 625 manager_.RemoveContextMenuItem(parent->id());
614 parent = NULL; 626 parent = NULL;
615 ASSERT_FALSE(new_item->checked()); 627 ASSERT_FALSE(new_item->checked());
616 ASSERT_TRUE(child1->checked()); 628 ASSERT_TRUE(child1->checked());
617 } 629 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698