| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| 11 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 11 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| 12 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 12 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 20 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
| 21 | 21 |
| 22 using content::WebContents; | 22 using content::WebContents; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 class TestRenderViewContextMenu : public RenderViewContextMenu { | 26 class TestRenderViewContextMenu : public RenderViewContextMenu { |
| 27 public: | 27 public: |
| 28 TestRenderViewContextMenu(WebContents* web_contents, | 28 TestRenderViewContextMenu(content::RenderFrameHost* render_frame_host, |
| 29 content::ContextMenuParams params) | 29 content::ContextMenuParams params) |
| 30 : RenderViewContextMenu(web_contents, params) { } | 30 : RenderViewContextMenu(render_frame_host, params) { } |
| 31 | 31 |
| 32 virtual void PlatformInit() OVERRIDE { } | 32 virtual void PlatformInit() OVERRIDE { } |
| 33 virtual void PlatformCancel() OVERRIDE { } | 33 virtual void PlatformCancel() OVERRIDE { } |
| 34 virtual bool GetAcceleratorForCommandId( | 34 virtual bool GetAcceleratorForCommandId( |
| 35 int command_id, | 35 int command_id, |
| 36 ui::Accelerator* accelerator) OVERRIDE { | 36 ui::Accelerator* accelerator) OVERRIDE { |
| 37 return false; | 37 return false; |
| 38 } | 38 } |
| 39 | 39 |
| 40 bool IsItemPresent(int command_id) { | 40 bool IsItemPresent(int command_id) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 55 params.unfiltered_link_url = url; | 55 params.unfiltered_link_url = url; |
| 56 WebContents* web_contents = | 56 WebContents* web_contents = |
| 57 browser()->tab_strip_model()->GetActiveWebContents(); | 57 browser()->tab_strip_model()->GetActiveWebContents(); |
| 58 params.page_url = web_contents->GetController().GetActiveEntry()->GetURL(); | 58 params.page_url = web_contents->GetController().GetActiveEntry()->GetURL(); |
| 59 #if defined(OS_MACOSX) | 59 #if defined(OS_MACOSX) |
| 60 params.writing_direction_default = 0; | 60 params.writing_direction_default = 0; |
| 61 params.writing_direction_left_to_right = 0; | 61 params.writing_direction_left_to_right = 0; |
| 62 params.writing_direction_right_to_left = 0; | 62 params.writing_direction_right_to_left = 0; |
| 63 #endif // OS_MACOSX | 63 #endif // OS_MACOSX |
| 64 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( | 64 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( |
| 65 browser()->tab_strip_model()->GetActiveWebContents(), params); | 65 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), |
| 66 params); |
| 66 menu->Init(); | 67 menu->Init(); |
| 67 return menu; | 68 return menu; |
| 68 } | 69 } |
| 69 | 70 |
| 70 void AddProtocolHandler(const std::string& protocol, | 71 void AddProtocolHandler(const std::string& protocol, |
| 71 const GURL& url, | 72 const GURL& url, |
| 72 const base::string16& title) { | 73 const base::string16& title) { |
| 73 ProtocolHandler handler = ProtocolHandler::CreateProtocolHandler( | 74 ProtocolHandler handler = ProtocolHandler::CreateProtocolHandler( |
| 74 protocol, url, title); | 75 protocol, url, title); |
| 75 ProtocolHandlerRegistry* registry = | 76 ProtocolHandlerRegistry* registry = |
| (...skipping 29 matching lines...) Expand all Loading... |
| 105 ASSERT_TRUE(test_server()->Start()); | 106 ASSERT_TRUE(test_server()->Start()); |
| 106 GURL handler_url = test_server()->GetURL("files/custom_handler_foo.html"); | 107 GURL handler_url = test_server()->GetURL("files/custom_handler_foo.html"); |
| 107 AddProtocolHandler("foo", handler_url, | 108 AddProtocolHandler("foo", handler_url, |
| 108 base::UTF8ToUTF16(std::string("Test foo Handler"))); | 109 base::UTF8ToUTF16(std::string("Test foo Handler"))); |
| 109 | 110 |
| 110 ui_test_utils::NavigateToURL(browser(), GURL("foo:test")); | 111 ui_test_utils::NavigateToURL(browser(), GURL("foo:test")); |
| 111 | 112 |
| 112 ASSERT_EQ(handler_url, | 113 ASSERT_EQ(handler_url, |
| 113 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); | 114 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); |
| 114 } | 115 } |
| OLD | NEW |