ProtocolHandler handler = ProtocolHandler::CreateProtocolHandler(protocol,
url);
ProtocolHandlerRegistry* registry =
- ProtocolHandlerRegistryFactory::GetForProfile(browser()->profile());
+ ProtocolHandlerRegistryFactory::GetForBrowserContext(
+ browser()->profile());
// Fake that this registration is happening on profile startup. Otherwise
// it'll try to register with the OS, which causes DCHECKs on Windows when
// running as admin on Windows 7.
registry->is_loading_ = false;
ASSERT_TRUE(registry->IsHandledProtocol(protocol));
}
+ void RemoveProtocolHandler(const std::string& protocol,
+ const GURL& url) {
+ ProtocolHandler handler = ProtocolHandler::CreateProtocolHandler(protocol,
+ url);
+ ProtocolHandlerRegistry* registry =
+ ProtocolHandlerRegistryFactory::GetForBrowserContext(
+ browser()->profile());
+ registry->RemoveHandler(handler);
+ ASSERT_FALSE(registry->IsHandledProtocol(protocol));
+ }
};
IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest,
GURL("http://www.google.com/%s"));
GURL url("web+search:testing");
ProtocolHandlerRegistry* registry =
- ProtocolHandlerRegistryFactory::GetForProfile(browser()->profile());
+ ProtocolHandlerRegistryFactory::GetForBrowserContext(
+ browser()->profile());
+ ASSERT_EQ(1u, registry->GetHandlersFor(url.scheme()).size());
+ menu.reset(CreateContextMenu(url));
+ ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH));
+}
+
+IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest,
+ UnregisterProtocolHandler) {
+ scoped_ptr<TestRenderViewContextMenu> menu(
+ CreateContextMenu(GURL("http://www.google.com/")));
+ ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH));
+
+ AddProtocolHandler(std::string("web+search"),
+ GURL("http://www.google.com/%s"));
+ GURL url("web+search:testing");
+ ProtocolHandlerRegistry* registry =
+ ProtocolHandlerRegistryFactory::GetForBrowserContext(
+ browser()->profile());
ASSERT_EQ(1u, registry->GetHandlersFor(url.scheme()).size());
menu.reset(CreateContextMenu(url));
ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH));
+ RemoveProtocolHandler(std::string("web+search"),
+ GURL("http://www.google.com/%s"));
+ ASSERT_EQ(0u, registry->GetHandlersFor(url.scheme()).size());
+ menu.reset(CreateContextMenu(url));
+ ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH));
}
IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest, CustomHandler) {