| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| 11 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 11 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "content/browser/tab_contents/tab_contents.h" | 15 #include "content/browser/tab_contents/tab_contents.h" |
| 16 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
| 18 | 18 |
| 19 using content::WebContents; |
| 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 class TestRenderViewContextMenu : public RenderViewContextMenu { | 23 class TestRenderViewContextMenu : public RenderViewContextMenu { |
| 22 public: | 24 public: |
| 23 TestRenderViewContextMenu(TabContents* tab_contents, ContextMenuParams params) | 25 TestRenderViewContextMenu(TabContents* tab_contents, ContextMenuParams params) |
| 24 : RenderViewContextMenu(tab_contents, params) { } | 26 : RenderViewContextMenu(tab_contents, params) { } |
| 25 | 27 |
| 26 virtual void PlatformInit() { } | 28 virtual void PlatformInit() { } |
| 27 virtual bool GetAcceleratorForCommandId( | 29 virtual bool GetAcceleratorForCommandId( |
| 28 int command_id, | 30 int command_id, |
| 29 ui::Accelerator* accelerator) { | 31 ui::Accelerator* accelerator) { |
| 30 return false; | 32 return false; |
| 31 } | 33 } |
| 32 | 34 |
| 33 bool IsItemPresent(int command_id) { | 35 bool IsItemPresent(int command_id) { |
| 34 return menu_model_.GetIndexOfCommandId(command_id) != -1; | 36 return menu_model_.GetIndexOfCommandId(command_id) != -1; |
| 35 } | 37 } |
| 36 }; | 38 }; |
| 37 | 39 |
| 38 class ContextMenuBrowserTest : public InProcessBrowserTest { | 40 class ContextMenuBrowserTest : public InProcessBrowserTest { |
| 39 public: | 41 public: |
| 40 ContextMenuBrowserTest() { } | 42 ContextMenuBrowserTest() { } |
| 41 | 43 |
| 42 TestRenderViewContextMenu* CreateContextMenu(GURL unfiltered_url, GURL url) { | 44 TestRenderViewContextMenu* CreateContextMenu(GURL unfiltered_url, GURL url) { |
| 43 ContextMenuParams params; | 45 ContextMenuParams params; |
| 44 params.media_type = WebKit::WebContextMenuData::MediaTypeNone; | 46 params.media_type = WebKit::WebContextMenuData::MediaTypeNone; |
| 45 params.unfiltered_link_url = unfiltered_url; | 47 params.unfiltered_link_url = unfiltered_url; |
| 46 params.link_url = url; | 48 params.link_url = url; |
| 47 TabContents* tab_contents = browser()->GetSelectedTabContents(); | 49 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 48 params.page_url = tab_contents->GetController().GetActiveEntry()->GetURL(); | 50 params.page_url = web_contents->GetController().GetActiveEntry()->GetURL(); |
| 49 #if defined(OS_MACOSX) | 51 #if defined(OS_MACOSX) |
| 50 params.writing_direction_default = 0; | 52 params.writing_direction_default = 0; |
| 51 params.writing_direction_left_to_right = 0; | 53 params.writing_direction_left_to_right = 0; |
| 52 params.writing_direction_right_to_left = 0; | 54 params.writing_direction_right_to_left = 0; |
| 53 #endif // OS_MACOSX | 55 #endif // OS_MACOSX |
| 54 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( | 56 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( |
| 55 browser()->GetSelectedTabContents(), params); | 57 browser()->GetSelectedTabContents(), params); |
| 56 menu->Init(); | 58 menu->Init(); |
| 57 return menu; | 59 return menu; |
| 58 } | 60 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 74 scoped_ptr<TestRenderViewContextMenu> menu( | 76 scoped_ptr<TestRenderViewContextMenu> menu( |
| 75 CreateContextMenu(GURL("chrome://history"), | 77 CreateContextMenu(GURL("chrome://history"), |
| 76 GURL())); | 78 GURL())); |
| 77 | 79 |
| 78 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); | 80 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); |
| 79 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); | 81 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); |
| 80 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); | 82 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); |
| 81 } | 83 } |
| 82 | 84 |
| 83 } // namespace | 85 } // namespace |
| OLD | NEW |