Chromium Code Reviews| 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 private: | |
|
sky
2013/01/14 16:03:37
nit: newline bewteen 268/269.
rustema
2013/01/15 07:37:40
Done.
| |
| 270 content::TestBrowserThread browser_thread_; | |
| 271 ProtocolHandlerRegistry registry_; | |
| 272 }; | |
|
sky
2013/01/14 16:03:37
DISALLOW_...
rustema
2013/01/15 07:37:40
Done.
| |
| 273 | |
| 274 // Verifies when Incognito Mode is not available (disabled by policy), | |
| 275 // Open Link in Incognito Window link in the context menu is disabled. | |
| 276 TEST_F(RenderViewContextMenuPrefsTest, | |
| 277 DisableOpenInIncognitoWindowWhenIncognitoIsDisabled) { | |
| 278 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); | |
| 279 | |
| 280 // Initially the Incognito mode is be enabled. So is the Open Link in | |
| 281 // Incognito Window link. | |
| 282 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); | |
| 283 EXPECT_TRUE( | |
| 284 menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); | |
| 285 | |
| 286 // Disable Incognito mode. | |
| 287 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), | |
| 288 IncognitoModePrefs::DISABLED); | |
| 289 menu.reset(CreateContextMenu()); | |
| 290 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); | |
| 291 EXPECT_FALSE( | |
| 292 menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); | |
| 293 } | |
| OLD | NEW |