OLD | NEW |
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 "chrome/browser/tab_contents/render_view_context_menu.h" | 5 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
6 | 6 |
| 7 #include "chrome/app/chrome_command_ids.h" |
| 8 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
7 #include "chrome/browser/extensions/extension_prefs.h" | 9 #include "chrome/browser/extensions/extension_prefs.h" |
| 10 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 11 #include "chrome/browser/prefs/pref_service.h" |
| 12 #include "chrome/browser/tab_contents/render_view_context_menu_test_util.h" |
| 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 14 #include "chrome/test/base/testing_profile.h" |
| 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/test/test_browser_thread.h" |
8 #include "extensions/common/url_pattern.h" | 18 #include "extensions/common/url_pattern.h" |
9 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
12 | 22 |
13 using extensions::MenuItem; | 23 using extensions::MenuItem; |
14 using extensions::URLPatternSet; | 24 using extensions::URLPatternSet; |
15 | 25 |
16 class RenderViewContextMenuTest : public testing::Test { | 26 class RenderViewContextMenuTest : public testing::Test { |
17 public: | 27 public: |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 MenuItem::SELECTION | MenuItem::IMAGE); | 240 MenuItem::SELECTION | MenuItem::IMAGE); |
231 | 241 |
232 MenuItem::ContextList contexts; | 242 MenuItem::ContextList contexts; |
233 contexts.Add(MenuItem::SELECTION); | 243 contexts.Add(MenuItem::SELECTION); |
234 contexts.Add(MenuItem::IMAGE); | 244 contexts.Add(MenuItem::IMAGE); |
235 | 245 |
236 URLPatternSet patterns = CreatePatternSet("*://test.none/*"); | 246 URLPatternSet patterns = CreatePatternSet("*://test.none/*"); |
237 | 247 |
238 EXPECT_TRUE(ExtensionContextAndPatternMatch(params, contexts, patterns)); | 248 EXPECT_TRUE(ExtensionContextAndPatternMatch(params, contexts, patterns)); |
239 } | 249 } |
| 250 |
| 251 class RenderViewContextMenuPrefsTest : public ChromeRenderViewHostTestHarness { |
| 252 public: |
| 253 RenderViewContextMenuPrefsTest() |
| 254 : browser_thread_(content::BrowserThread::UI, &message_loop_), |
| 255 registry_(profile(), NULL) {} |
| 256 |
| 257 TestRenderViewContextMenu* CreateContextMenu() { |
| 258 content::ContextMenuParams params = CreateParams(MenuItem::LINK); |
| 259 params.unfiltered_link_url = params.link_url; |
| 260 content::WebContents* wc = web_contents(); |
| 261 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( |
| 262 wc, params); |
| 263 // TestingProfile (returned by profile()) does not provide a protocol |
| 264 // registry. |
| 265 menu->protocol_handler_registry_ = ®istry_; |
| 266 menu->Init(); |
| 267 return menu; |
| 268 } |
| 269 |
| 270 private: |
| 271 content::TestBrowserThread browser_thread_; |
| 272 ProtocolHandlerRegistry registry_; |
| 273 |
| 274 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenuPrefsTest); |
| 275 }; |
| 276 |
| 277 // Verifies when Incognito Mode is not available (disabled by policy), |
| 278 // Open Link in Incognito Window link in the context menu is disabled. |
| 279 TEST_F(RenderViewContextMenuPrefsTest, |
| 280 DisableOpenInIncognitoWindowWhenIncognitoIsDisabled) { |
| 281 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); |
| 282 |
| 283 // Initially the Incognito mode is be enabled. So is the Open Link in |
| 284 // Incognito Window link. |
| 285 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); |
| 286 EXPECT_TRUE( |
| 287 menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); |
| 288 |
| 289 // Disable Incognito mode. |
| 290 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), |
| 291 IncognitoModePrefs::DISABLED); |
| 292 menu.reset(CreateContextMenu()); |
| 293 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); |
| 294 EXPECT_FALSE( |
| 295 menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); |
| 296 } |
OLD | NEW |