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

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

Issue 10382149: Refactor the various ways to control what users can do to extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 "base/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/app/chrome_command_ids.h" 6 #include "chrome/app/chrome_command_ids.h"
7 #include "chrome/browser/extensions/extension_browsertest.h" 7 #include "chrome/browser/extensions/extension_browsertest.h"
8 #include "chrome/browser/extensions/extension_context_menu_model.h"
8 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_system.h"
9 #include "chrome/browser/extensions/extension_test_message_listener.h" 11 #include "chrome/browser/extensions/extension_test_message_listener.h"
10 #include "chrome/browser/extensions/lazy_background_page_test_util.h" 12 #include "chrome/browser/extensions/lazy_background_page_test_util.h"
13 #include "chrome/browser/extensions/test_management_policy.h"
11 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/tab_contents/render_view_context_menu.h" 15 #include "chrome/browser/tab_contents/render_view_context_menu.h"
13 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_finder.h" 17 #include "chrome/browser/ui/browser_finder.h"
15 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
16 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
17 #include "content/public/common/context_menu_params.h" 20 #include "content/public/common/context_menu_params.h"
18 #include "net/base/mock_host_resolver.h" 21 #include "net/base/mock_host_resolver.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
20 #include "ui/base/models/menu_model.h" 23 #include "ui/base/models/menu_model.h"
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 ASSERT_TRUE(MenuHasItemWithLabel( 508 ASSERT_TRUE(MenuHasItemWithLabel(
506 page_url, GURL(), frame_url, std::string("Frame item"))); 509 page_url, GURL(), frame_url, std::string("Frame item")));
507 } 510 }
508 511
509 // Tests enabling and disabling a context menu item. 512 // Tests enabling and disabling a context menu item.
510 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Enabled) { 513 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Enabled) {
511 TestEnabledContextMenu(true); 514 TestEnabledContextMenu(true);
512 TestEnabledContextMenu(false); 515 TestEnabledContextMenu(false);
513 } 516 }
514 517
518 // Tests that applicable menu items are disabled when a ManagementPolicy
519 // prohibits them.
520 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, PolicyDisablesItems) {
521 ASSERT_TRUE(LoadContextMenuExtension("simple"));
522 ExtensionService* service = browser()->profile()->GetExtensionService();
523 ASSERT_TRUE(service != NULL);
524 ASSERT_FALSE(service->extensions()->is_empty());
525
526 // We need an extension to pass to the menu constructor, but we don't care
527 // which one.
528 ExtensionSet::const_iterator i = service->extensions()->begin();
529 const extensions::Extension* extension = *i;
530 ASSERT_TRUE(extension != NULL);
531
532 scoped_refptr<ExtensionContextMenuModel> menu(
533 new ExtensionContextMenuModel(extension, browser()));
534
535 ExtensionSystem::Get(
536 browser()->profile())->management_policy()->UnregisterAllProviders();
537
538 // Actions should be enabled.
539 ASSERT_TRUE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::DISABLE));
540 ASSERT_TRUE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL));
541
542 extensions::TestManagementPolicyProvider policy_provider(
543 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
544 ExtensionSystem::Get(
545 browser()->profile())->management_policy()->RegisterProvider(
546 &policy_provider);
547
548 // Now the actions are disabled.
549 ASSERT_FALSE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::DISABLE));
550 ASSERT_FALSE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL));
551 }
552
515 class ExtensionContextMenuBrowserLazyTest : 553 class ExtensionContextMenuBrowserLazyTest :
516 public ExtensionContextMenuBrowserTest { 554 public ExtensionContextMenuBrowserTest {
517 void SetUpCommandLine(CommandLine* command_line) { 555 void SetUpCommandLine(CommandLine* command_line) {
518 ExtensionContextMenuBrowserTest::SetUpCommandLine(command_line); 556 ExtensionContextMenuBrowserTest::SetUpCommandLine(command_line);
519 // Set shorter delays to prevent test timeouts. 557 // Set shorter delays to prevent test timeouts.
520 command_line->AppendSwitchASCII(switches::kEventPageIdleTime, "0"); 558 command_line->AppendSwitchASCII(switches::kEventPageIdleTime, "0");
521 command_line->AppendSwitchASCII(switches::kEventPageUnloadingTime, "0"); 559 command_line->AppendSwitchASCII(switches::kEventPageUnloadingTime, "0");
522 } 560 }
523 }; 561 };
524 562
(...skipping 22 matching lines...) Expand all
547 EXPECT_FALSE(menu->IsCommandIdChecked(command_id)); 585 EXPECT_FALSE(menu->IsCommandIdChecked(command_id));
548 586
549 // Executing the checkbox also fires the onClicked event. 587 // Executing the checkbox also fires the onClicked event.
550 ExtensionTestMessageListener listener("onClicked fired for checkbox1", false); 588 ExtensionTestMessageListener listener("onClicked fired for checkbox1", false);
551 menu->ExecuteCommand(command_id); 589 menu->ExecuteCommand(command_id);
552 checkbox_checked.WaitUntilClosed(); 590 checkbox_checked.WaitUntilClosed();
553 591
554 EXPECT_TRUE(menu->IsCommandIdChecked(command_id)); 592 EXPECT_TRUE(menu->IsCommandIdChecked(command_id));
555 ASSERT_TRUE(listener.WaitUntilSatisfied()); 593 ASSERT_TRUE(listener.WaitUntilSatisfied());
556 } 594 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/crx_installer.cc ('k') | chrome/browser/extensions/extension_context_menu_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698