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

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

Issue 10694085: Refactor extension event distribution to use Values instead of JSON strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Build fix. Created 8 years, 5 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"
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 374
375 // A mock message service for tests of ExtensionMenuManager::ExecuteCommand. 375 // A mock message service for tests of ExtensionMenuManager::ExecuteCommand.
376 class MockExtensionEventRouter : public ExtensionEventRouter { 376 class MockExtensionEventRouter : public ExtensionEventRouter {
377 public: 377 public:
378 explicit MockExtensionEventRouter(Profile* profile) : 378 explicit MockExtensionEventRouter(Profile* profile) :
379 ExtensionEventRouter(profile) {} 379 ExtensionEventRouter(profile) {}
380 380
381 MOCK_METHOD6(DispatchEventToExtension, 381 MOCK_METHOD6(DispatchEventToExtension,
382 void(const std::string& extension_id, 382 void(const std::string& extension_id,
383 const std::string& event_name, 383 const std::string& event_name,
384 const std::string& event_args, 384 base::ListValue* event_args,
385 Profile* source_profile, 385 Profile* source_profile,
386 const GURL& event_url, 386 const GURL& event_url,
387 ExtensionEventRouter::UserGestureState state)); 387 ExtensionEventRouter::UserGestureState state));
388 388
389 389
390 private: 390 private:
391 DISALLOW_COPY_AND_ASSIGN(MockExtensionEventRouter); 391 DISALLOW_COPY_AND_ASSIGN(MockExtensionEventRouter);
392 }; 392 };
393 393
394 // A mock profile for tests of ExtensionMenuManager::ExecuteCommand. 394 // A mock profile for tests of ExtensionMenuManager::ExecuteCommand.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 ExtensionMenuItem* item = CreateTestItem(extension); 470 ExtensionMenuItem* item = CreateTestItem(extension);
471 ExtensionMenuItem::Id id = item->id(); 471 ExtensionMenuItem::Id id = item->id();
472 ASSERT_TRUE(manager_.AddContextItem(extension, item)); 472 ASSERT_TRUE(manager_.AddContextItem(extension, item));
473 473
474 EXPECT_CALL(profile, GetExtensionEventRouter()) 474 EXPECT_CALL(profile, GetExtensionEventRouter())
475 .Times(1) 475 .Times(1)
476 .WillOnce(Return(mock_event_router.get())); 476 .WillOnce(Return(mock_event_router.get()));
477 477
478 // 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
479 // DispatchEventToExtension method into event_args. 479 // DispatchEventToExtension method into event_args.
480 std::string event_args; 480 base::ListValue* list = NULL;
481 { 481 {
482 InSequence s; 482 InSequence s;
483 EXPECT_CALL(*mock_event_router.get(), 483 EXPECT_CALL(*mock_event_router.get(),
484 DispatchEventToExtension( 484 DispatchEventToExtension(
485 item->extension_id(), 485 item->extension_id(),
486 extension_event_names::kOnContextMenus, 486 extension_event_names::kOnContextMenus,
487 _, 487 _,
488 &profile, 488 &profile,
489 GURL(), 489 GURL(),
490 ExtensionEventRouter::USER_GESTURE_ENABLED)) 490 ExtensionEventRouter::USER_GESTURE_ENABLED))
491 .Times(1) 491 .Times(1)
492 .WillOnce(SaveArg<2>(&event_args)); 492 .WillOnce(SaveArg<2>(&list));
493 EXPECT_CALL(*mock_event_router.get(), 493 EXPECT_CALL(*mock_event_router.get(),
494 DispatchEventToExtension( 494 DispatchEventToExtension(
495 item->extension_id(), 495 item->extension_id(),
496 extension_event_names::kOnContextMenuClicked, 496 extension_event_names::kOnContextMenuClicked,
497 _, 497 _,
498 &profile, 498 &profile,
499 GURL(), 499 GURL(),
500 ExtensionEventRouter::USER_GESTURE_ENABLED)) 500 ExtensionEventRouter::USER_GESTURE_ENABLED))
501 .Times(1); 501 .Times(1);
502 } 502 }
503 manager_.ExecuteCommand(&profile, NULL /* tab_contents */, params, id); 503 manager_.ExecuteCommand(&profile, NULL /* tab_contents */, params, id);
504 504
505 // Parse the json event_args, which should turn into a 2-element list where
506 // the first element is a dictionary we want to inspect for the correct
507 // values.
508 scoped_ptr<Value> result(
509 base::JSONReader::Read(event_args, base::JSON_ALLOW_TRAILING_COMMAS));
510 Value* value = result.get();
511 ASSERT_TRUE(result.get() != NULL);
512 ASSERT_EQ(Value::TYPE_LIST, value->GetType());
513 ListValue* list = static_cast<ListValue*>(value);
514 ASSERT_EQ(2u, list->GetSize()); 505 ASSERT_EQ(2u, list->GetSize());
515 506
516 DictionaryValue* info; 507 DictionaryValue* info;
517 ASSERT_TRUE(list->GetDictionary(0, &info)); 508 ASSERT_TRUE(list->GetDictionary(0, &info));
518 509
519 int tmp_id = 0; 510 int tmp_id = 0;
520 ASSERT_TRUE(info->GetInteger("menuItemId", &tmp_id)); 511 ASSERT_TRUE(info->GetInteger("menuItemId", &tmp_id));
521 ASSERT_EQ(id.uid, tmp_id); 512 ASSERT_EQ(id.uid, tmp_id);
522 513
523 std::string tmp; 514 std::string tmp;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 manager_.ChangeParent(child1->id(), NULL); 611 manager_.ChangeParent(child1->id(), NULL);
621 ASSERT_TRUE(new_item->checked()); 612 ASSERT_TRUE(new_item->checked());
622 ASSERT_TRUE(child1->checked()); 613 ASSERT_TRUE(child1->checked());
623 614
624 // Removing |parent| should cause only |child1| to be selected. 615 // Removing |parent| should cause only |child1| to be selected.
625 manager_.RemoveContextMenuItem(parent->id()); 616 manager_.RemoveContextMenuItem(parent->id());
626 parent = NULL; 617 parent = NULL;
627 ASSERT_FALSE(new_item->checked()); 618 ASSERT_FALSE(new_item->checked());
628 ASSERT_TRUE(child1->checked()); 619 ASSERT_TRUE(child1->checked());
629 } 620 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698