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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 ProtocolHandlerRegistry* registry = | 52 ProtocolHandlerRegistry* registry = |
53 ProtocolHandlerRegistryFactory::GetForProfile(browser()->profile()); | 53 ProtocolHandlerRegistryFactory::GetForProfile(browser()->profile()); |
54 // Fake that this registration is happening on profile startup. Otherwise | 54 // Fake that this registration is happening on profile startup. Otherwise |
55 // 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 |
56 // running as admin on Windows 7. | 56 // running as admin on Windows 7. |
57 registry->is_loading_ = true; | 57 registry->is_loading_ = true; |
58 registry->OnAcceptRegisterProtocolHandler(handler); | 58 registry->OnAcceptRegisterProtocolHandler(handler); |
59 registry->is_loading_ = false; | 59 registry->is_loading_ = false; |
60 ASSERT_TRUE(registry->IsHandledProtocol(protocol)); | 60 ASSERT_TRUE(registry->IsHandledProtocol(protocol)); |
61 } | 61 } |
| 62 void RemoveProtocolHandler(const std::string& protocol, |
| 63 const GURL& url) { |
| 64 ProtocolHandler handler = ProtocolHandler::CreateProtocolHandler(protocol, |
| 65 url); |
| 66 ProtocolHandlerRegistry* registry = |
| 67 ProtocolHandlerRegistryFactory::GetForProfile(browser()->profile()); |
| 68 registry->RemoveHandler(handler); |
| 69 ASSERT_FALSE(registry->IsHandledProtocol(protocol)); |
| 70 } |
62 }; | 71 }; |
63 | 72 |
64 IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest, | 73 IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest, |
65 ContextMenuEntryAppearsForHandledUrls) { | 74 ContextMenuEntryAppearsForHandledUrls) { |
66 scoped_ptr<TestRenderViewContextMenu> menu( | 75 scoped_ptr<TestRenderViewContextMenu> menu( |
67 CreateContextMenu(GURL("http://www.google.com/"))); | 76 CreateContextMenu(GURL("http://www.google.com/"))); |
68 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH)); | 77 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH)); |
69 | 78 |
70 AddProtocolHandler(std::string("web+search"), | 79 AddProtocolHandler(std::string("web+search"), |
71 GURL("http://www.google.com/%s")); | 80 GURL("http://www.google.com/%s")); |
72 GURL url("web+search:testing"); | 81 GURL url("web+search:testing"); |
73 ProtocolHandlerRegistry* registry = | 82 ProtocolHandlerRegistry* registry = |
74 ProtocolHandlerRegistryFactory::GetForProfile(browser()->profile()); | 83 ProtocolHandlerRegistryFactory::GetForProfile(browser()->profile()); |
75 ASSERT_EQ(1u, registry->GetHandlersFor(url.scheme()).size()); | 84 ASSERT_EQ(1u, registry->GetHandlersFor(url.scheme()).size()); |
76 menu.reset(CreateContextMenu(url)); | 85 menu.reset(CreateContextMenu(url)); |
77 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH)); | 86 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH)); |
78 } | 87 } |
79 | 88 |
| 89 IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest, |
| 90 UnregisterProtocolHandler) { |
| 91 scoped_ptr<TestRenderViewContextMenu> menu( |
| 92 CreateContextMenu(GURL("http://www.google.com/"))); |
| 93 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH)); |
| 94 |
| 95 AddProtocolHandler(std::string("web+search"), |
| 96 GURL("http://www.google.com/%s")); |
| 97 GURL url("web+search:testing"); |
| 98 ProtocolHandlerRegistry* registry = |
| 99 ProtocolHandlerRegistryFactory::GetForProfile(browser()->profile()); |
| 100 ASSERT_EQ(1u, registry->GetHandlersFor(url.scheme()).size()); |
| 101 menu.reset(CreateContextMenu(url)); |
| 102 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH)); |
| 103 RemoveProtocolHandler(std::string("web+search"), |
| 104 GURL("http://www.google.com/%s")); |
| 105 ASSERT_EQ(0u, registry->GetHandlersFor(url.scheme()).size()); |
| 106 menu.reset(CreateContextMenu(url)); |
| 107 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH)); |
| 108 } |
| 109 |
80 IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest, CustomHandler) { | 110 IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest, CustomHandler) { |
81 ASSERT_TRUE(test_server()->Start()); | 111 ASSERT_TRUE(test_server()->Start()); |
82 GURL handler_url = test_server()->GetURL("files/custom_handler_foo.html"); | 112 GURL handler_url = test_server()->GetURL("files/custom_handler_foo.html"); |
83 AddProtocolHandler("foo", handler_url); | 113 AddProtocolHandler("foo", handler_url); |
84 | 114 |
85 ui_test_utils::NavigateToURL(browser(), GURL("foo:test")); | 115 ui_test_utils::NavigateToURL(browser(), GURL("foo:test")); |
86 | 116 |
87 ASSERT_EQ(handler_url, | 117 ASSERT_EQ(handler_url, |
88 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); | 118 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); |
89 } | 119 } |
OLD | NEW |