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" |
(...skipping 28 matching lines...) Expand all Loading... |
39 params.writing_direction_right_to_left = 0; | 39 params.writing_direction_right_to_left = 0; |
40 #endif // OS_MACOSX | 40 #endif // OS_MACOSX |
41 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( | 41 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( |
42 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), | 42 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), |
43 params); | 43 params); |
44 menu->Init(); | 44 menu->Init(); |
45 return menu; | 45 return menu; |
46 } | 46 } |
47 | 47 |
48 void AddProtocolHandler(const std::string& protocol, | 48 void AddProtocolHandler(const std::string& protocol, |
49 const GURL& url, | 49 const GURL& url) { |
50 const base::string16& title) { | 50 ProtocolHandler handler = ProtocolHandler::CreateProtocolHandler(protocol, |
51 ProtocolHandler handler = ProtocolHandler::CreateProtocolHandler( | 51 url); |
52 protocol, url, title); | |
53 ProtocolHandlerRegistry* registry = | 52 ProtocolHandlerRegistry* registry = |
54 ProtocolHandlerRegistryFactory::GetForProfile(browser()->profile()); | 53 ProtocolHandlerRegistryFactory::GetForProfile(browser()->profile()); |
55 // Fake that this registration is happening on profile startup. Otherwise | 54 // Fake that this registration is happening on profile startup. Otherwise |
56 // it'll try to register with the OS, which causes DCHECKs on Windows when | 55 // it'll try to register with the OS, which causes DCHECKs on Windows when |
57 // running as admin on Windows 7. | 56 // running as admin on Windows 7. |
58 registry->is_loading_ = true; | 57 registry->is_loading_ = true; |
59 registry->OnAcceptRegisterProtocolHandler(handler); | 58 registry->OnAcceptRegisterProtocolHandler(handler); |
60 registry->is_loading_ = false; | 59 registry->is_loading_ = false; |
61 ASSERT_TRUE(registry->IsHandledProtocol(protocol)); | 60 ASSERT_TRUE(registry->IsHandledProtocol(protocol)); |
62 } | 61 } |
63 }; | 62 }; |
64 | 63 |
65 IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest, | 64 IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest, |
66 ContextMenuEntryAppearsForHandledUrls) { | 65 ContextMenuEntryAppearsForHandledUrls) { |
67 scoped_ptr<TestRenderViewContextMenu> menu( | 66 scoped_ptr<TestRenderViewContextMenu> menu( |
68 CreateContextMenu(GURL("http://www.google.com/"))); | 67 CreateContextMenu(GURL("http://www.google.com/"))); |
69 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH)); | 68 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH)); |
70 | 69 |
71 AddProtocolHandler(std::string("web+search"), | 70 AddProtocolHandler(std::string("web+search"), |
72 GURL("http://www.google.com/%s"), | 71 GURL("http://www.google.com/%s")); |
73 base::UTF8ToUTF16(std::string("Test handler"))); | |
74 GURL url("web+search:testing"); | 72 GURL url("web+search:testing"); |
75 ProtocolHandlerRegistry* registry = | 73 ProtocolHandlerRegistry* registry = |
76 ProtocolHandlerRegistryFactory::GetForProfile(browser()->profile()); | 74 ProtocolHandlerRegistryFactory::GetForProfile(browser()->profile()); |
77 ASSERT_EQ(1u, registry->GetHandlersFor(url.scheme()).size()); | 75 ASSERT_EQ(1u, registry->GetHandlersFor(url.scheme()).size()); |
78 menu.reset(CreateContextMenu(url)); | 76 menu.reset(CreateContextMenu(url)); |
79 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH)); | 77 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH)); |
80 } | 78 } |
81 | 79 |
82 IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest, CustomHandler) { | 80 IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest, CustomHandler) { |
83 ASSERT_TRUE(test_server()->Start()); | 81 ASSERT_TRUE(test_server()->Start()); |
84 GURL handler_url = test_server()->GetURL("files/custom_handler_foo.html"); | 82 GURL handler_url = test_server()->GetURL("files/custom_handler_foo.html"); |
85 AddProtocolHandler("foo", handler_url, | 83 AddProtocolHandler("foo", handler_url); |
86 base::UTF8ToUTF16(std::string("Test foo Handler"))); | |
87 | 84 |
88 ui_test_utils::NavigateToURL(browser(), GURL("foo:test")); | 85 ui_test_utils::NavigateToURL(browser(), GURL("foo:test")); |
89 | 86 |
90 ASSERT_EQ(handler_url, | 87 ASSERT_EQ(handler_url, |
91 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); | 88 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); |
92 } | 89 } |
OLD | NEW |