Chromium Code Reviews| Index: chrome/browser/tab_contents/render_view_context_menu_unittest.cc |
| diff --git a/chrome/browser/tab_contents/render_view_context_menu_unittest.cc b/chrome/browser/tab_contents/render_view_context_menu_unittest.cc |
| index 582dd60566b26dff0b303c954aaeafd7efc13dec..29792c6bee245c90c586cd58d78db282dde13cc3 100644 |
| --- a/chrome/browser/tab_contents/render_view_context_menu_unittest.cc |
| +++ b/chrome/browser/tab_contents/render_view_context_menu_unittest.cc |
| @@ -4,7 +4,17 @@ |
| #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| +#include "chrome/app/chrome_command_ids.h" |
| +#include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| #include "chrome/browser/extensions/extension_prefs.h" |
| +#include "chrome/browser/prefs/incognito_mode_prefs.h" |
| +#include "chrome/browser/prefs/pref_service.h" |
| +#include "chrome/browser/tab_contents/render_view_context_menu_test_util.h" |
| +#include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| +#include "chrome/test/base/testing_profile.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/test/test_browser_thread.h" |
| #include "extensions/common/url_pattern.h" |
| #include "googleurl/src/gurl.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -237,3 +247,47 @@ TEST_F(RenderViewContextMenuTest, TargetIgnoredForSelectionOnImage) { |
| EXPECT_TRUE(ExtensionContextAndPatternMatch(params, contexts, patterns)); |
| } |
| + |
| +class RenderViewContextMenuPrefsTest : public ChromeRenderViewHostTestHarness { |
| + public: |
| + RenderViewContextMenuPrefsTest() |
| + : browser_thread_(content::BrowserThread::UI, &message_loop_), |
| + registry_(profile(), NULL) {} |
| + |
| + TestRenderViewContextMenu* CreateContextMenu() { |
| + content::ContextMenuParams params = CreateParams(MenuItem::LINK); |
| + params.unfiltered_link_url = params.link_url; |
| + content::WebContents* wc = web_contents(); |
| + TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( |
| + wc, params); |
| + // TestingProfile (returned by profile()) does not provide a protocol |
| + // registry. |
| + menu->protocol_handler_registry_ = ®istry_; |
| + menu->Init(); |
| + return menu; |
| + } |
| + private: |
|
sky
2013/01/14 16:03:37
nit: newline bewteen 268/269.
rustema
2013/01/15 07:37:40
Done.
|
| + content::TestBrowserThread browser_thread_; |
| + ProtocolHandlerRegistry registry_; |
| +}; |
|
sky
2013/01/14 16:03:37
DISALLOW_...
rustema
2013/01/15 07:37:40
Done.
|
| + |
| +// Verifies when Incognito Mode is not available (disabled by policy), |
| +// Open Link in Incognito Window link in the context menu is disabled. |
| +TEST_F(RenderViewContextMenuPrefsTest, |
| + DisableOpenInIncognitoWindowWhenIncognitoIsDisabled) { |
| + scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); |
| + |
| + // Initially the Incognito mode is be enabled. So is the Open Link in |
| + // Incognito Window link. |
| + ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); |
| + EXPECT_TRUE( |
| + menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); |
| + |
| + // Disable Incognito mode. |
| + IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), |
| + IncognitoModePrefs::DISABLED); |
| + menu.reset(CreateContextMenu()); |
| + ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); |
| + EXPECT_FALSE( |
| + menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); |
| +} |