Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / custom_handlers / protocol_handler_registry_browsertest.cc
index cd4f791..9a0f518 100644 (file)
@@ -50,7 +50,8 @@ class RegisterProtocolHandlerBrowserTest : public InProcessBrowserTest {
     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.
@@ -59,6 +60,16 @@ class RegisterProtocolHandlerBrowserTest : public InProcessBrowserTest {
     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,
@@ -71,10 +82,33 @@ 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) {