diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-04 22:39:52 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-04 22:39:52 +0000 |
commit | d0381510f773c5b4105f8f470a8847353f3bc682 (patch) | |
tree | 9deaa04ecd8b919359a9eec97f7f3abe4d76e702 /chrome/browser/custom_handlers | |
parent | 668d965bc7684af43781743e13496521ca11d0b9 (diff) | |
download | chromium_src-d0381510f773c5b4105f8f470a8847353f3bc682.zip chromium_src-d0381510f773c5b4105f8f470a8847353f3bc682.tar.gz chromium_src-d0381510f773c5b4105f8f470a8847353f3bc682.tar.bz2 |
Convert the CustomHandler ui_test to a browser_test. There were two cases for the same thing, I just reduced it to one.
BUG=121574
Review URL: https://chromiumcodereview.appspot.com/9979018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130751 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/custom_handlers')
3 files changed, 18 insertions, 129 deletions
diff --git a/chrome/browser/custom_handlers/custom_handlers_uitest.cc b/chrome/browser/custom_handlers/custom_handlers_uitest.cc deleted file mode 100644 index a94f9b1..0000000 --- a/chrome/browser/custom_handlers/custom_handlers_uitest.cc +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/file_util.h" -#include "base/path_service.h" -#include "base/scoped_temp_dir.h" -#include "base/test/test_file_util.h" -#include "build/build_config.h" -#include "chrome/common/chrome_constants.h" -#include "chrome/common/chrome_paths.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/test/automation/automation_proxy.h" -#include "chrome/test/automation/browser_proxy.h" -#include "chrome/test/automation/tab_proxy.h" -#include "chrome/test/ui/ui_test.h" -#include "net/test/test_server.h" - -namespace { - -class CustomHandlerTest : public UITest { - public: - CustomHandlerTest() - : test_server_(net::TestServer::TYPE_HTTP, - net::TestServer::kLocalhost, - FilePath(FILE_PATH_LITERAL("chrome/test/data"))) { - // Stop Chrome from removing custom protocol handlers for protocols that - // Chrome is not registered with the OS as the default application. - // In the test environment Chrome will not be registered with the OS as the - // default application to handle any protocols. - launch_arguments_.AppendSwitch(switches::kDisableCustomProtocolOSCheck); - - FilePath template_dir; - EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &template_dir)); - template_dir = template_dir.AppendASCII("profiles"). - AppendASCII("custom_handlers"); - set_template_user_data(template_dir); - } - - virtual void SetUpProfile() { - UITest::SetUpProfile(); - FilePath preferences_path = user_data_dir().AppendASCII("Default"). - Append(chrome::kPreferencesFilename); - - std::string preferences; - ASSERT_TRUE(file_util::ReadFileToString(preferences_path, &preferences)); - - // Update the placeholders for our mailto and webcal handlers with - // their proper URLs. - preferences = ReplacePlaceholderHandler(preferences, - "MAILTOHANDLER", - "files/custom_handler_mailto.html"); - preferences = ReplacePlaceholderHandler(preferences, - "WEBCALHANDLER", - "files/custom_handler_webcal.html"); - - // Write the updated preference file to our temporary profile. - ASSERT_TRUE(file_util::WriteFile(preferences_path, - preferences.c_str(), - preferences.size())); - } - - virtual void SetUp() { - UITest::SetUp(); - - window_ = automation()->GetBrowserWindow(0); - ASSERT_TRUE(window_.get()); - - tab_ = window_->GetActiveTab(); - ASSERT_TRUE(tab_.get()); - } - - protected: - net::TestServer test_server_; - - GURL GetTabURL() { - GURL url; - EXPECT_TRUE(tab_->GetCurrentURL(&url)); - return url; - } - - private: - std::string ReplacePlaceholderHandler(const std::string& preferences, - const std::string& placeholder, - const std::string& handler_path) { - GURL handler_url = test_server_.GetURL(handler_path); - std::string result = preferences; - size_t found = result.find(placeholder); - EXPECT_FALSE(found == std::string::npos); - if (found != std::string::npos) - result.replace(found, placeholder.length(), handler_url.spec()); - return result; - } - - scoped_refptr<BrowserProxy> window_; - scoped_refptr<TabProxy> tab_; -}; - -class CustomHandlerMailStartupTest : public CustomHandlerTest { - public: - CustomHandlerMailStartupTest() { - launch_arguments_.AppendArg("mailto:test"); - } -}; - -class CustomHandlerWebcalStartupTest : public CustomHandlerTest { - public: - CustomHandlerWebcalStartupTest() { - launch_arguments_.AppendArg("webcal:test"); - } -}; - -TEST_F(CustomHandlerMailStartupTest, CustomHandlerMailStartup) { - ASSERT_EQ(test_server_.GetURL("files/custom_handler_mailto.html"), - GetTabURL()); -} - -TEST_F(CustomHandlerWebcalStartupTest, CustomHandlerWebcalStartup) { - ASSERT_EQ(test_server_.GetURL("files/custom_handler_webcal.html"), - GetTabURL()); -} - -} // namespace diff --git a/chrome/browser/custom_handlers/protocol_handler_registry.cc b/chrome/browser/custom_handlers/protocol_handler_registry.cc index 500da2b..d81af98 100644 --- a/chrome/browser/custom_handlers/protocol_handler_registry.cc +++ b/chrome/browser/custom_handlers/protocol_handler_registry.cc @@ -188,9 +188,7 @@ bool ShouldRemoveHandlersNotInOS() { // difference (http://crbug.com/88255). return false; #else - const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); - return ShellIntegration::CanSetAsDefaultProtocolClient() && - !cmd_line.HasSwitch(switches::kDisableCustomProtocolOSCheck); + return ShellIntegration::CanSetAsDefaultProtocolClient(); #endif } diff --git a/chrome/browser/custom_handlers/protocol_handler_registry_browsertest.cc b/chrome/browser/custom_handlers/protocol_handler_registry_browsertest.cc index 6cb7d11..2c7265a 100644 --- a/chrome/browser/custom_handlers/protocol_handler_registry_browsertest.cc +++ b/chrome/browser/custom_handlers/protocol_handler_registry_browsertest.cc @@ -39,6 +39,8 @@ class TestRenderViewContextMenu : public RenderViewContextMenu { } }; +} // namespace + class RegisterProtocolHandlerBrowserTest : public InProcessBrowserTest { public: RegisterProtocolHandlerBrowserTest() { } @@ -74,13 +76,25 @@ IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest, UTF8ToUTF16(std::string("Test handler"))); ProtocolHandlerRegistry* registry = browser()->profile()->GetProtocolHandlerRegistry(); - - GURL url("web+search:testing"); registry->OnAcceptRegisterProtocolHandler(handler); ASSERT_TRUE(registry->IsHandledProtocol("web+search")); + + GURL url("web+search:testing"); ASSERT_EQ(registry->GetHandlersFor(url.scheme()).size(), (size_t) 1); menu.reset(CreateContextMenu(url)); ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKWITH)); } -} // namespace +IN_PROC_BROWSER_TEST_F(RegisterProtocolHandlerBrowserTest, CustomHandler) { + ASSERT_TRUE(test_server()->Start()); + GURL handler_url = test_server()->GetURL("files/custom_handler_foo.html"); + ProtocolHandler handler = ProtocolHandler::CreateProtocolHandler( + std::string("foo"), handler_url, + UTF8ToUTF16(std::string("Test foo Handler"))); + browser()->profile()->GetProtocolHandlerRegistry()-> + OnAcceptRegisterProtocolHandler(handler); + + ui_test_utils::NavigateToURL(browser(), GURL("foo:test")); + + ASSERT_EQ(handler_url, browser()->GetSelectedWebContents()->GetURL()); +} |