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 | |
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
-rw-r--r-- | chrome/browser/custom_handlers/custom_handlers_uitest.cc | 123 | ||||
-rw-r--r-- | chrome/browser/custom_handlers/protocol_handler_registry.cc | 4 | ||||
-rw-r--r-- | chrome/browser/custom_handlers/protocol_handler_registry_browsertest.cc | 20 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 5 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 1 | ||||
-rw-r--r-- | chrome/test/data/custom_handler_foo.html | 4 | ||||
-rw-r--r-- | chrome/test/data/custom_handler_mailto.html | 4 | ||||
-rw-r--r-- | chrome/test/data/custom_handler_webcal.html | 4 | ||||
-rw-r--r-- | chrome/test/data/profiles/custom_handlers/Default/Preferences | 17 |
10 files changed, 22 insertions, 161 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()); +} diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 7beaa2b..fa4f35d 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -790,7 +790,6 @@ # NOTE: DON'T ADD NEW TESTS HERE! # New tests should be browser_tests. browser_tests are sharded and are # less flakier. - 'browser/custom_handlers/custom_handlers_uitest.cc', 'browser/download/save_page_uitest.cc', 'browser/fast_shutdown_uitest.cc', 'browser/history/multipart_uitest.cc', diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index fe4aee7..d92b14c 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -278,11 +278,6 @@ const char kDisableCRLSets[] = "disable-crl-sets"; // Disables the custom JumpList on Windows 7. const char kDisableCustomJumpList[] = "disable-custom-jumplist"; -// Disables checking whether custom protocol handlers are registered with the -// OS and removing those that are not. This is used during automated testing. -const char kDisableCustomProtocolOSCheck[] = - "disable-custom-protocol-os-check"; - // Disables installation of default apps on first run. This is used during // automated testing. const char kDisableDefaultApps[] = "disable-default-apps"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index a531f5d..6e81643 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -83,7 +83,6 @@ extern const char kDisableClientSidePhishingDetection[]; extern const char kDisableConnectBackupJobs[]; extern const char kDisableCRLSets[]; extern const char kDisableCustomJumpList[]; -extern const char kDisableCustomProtocolOSCheck[]; extern const char kDisableDefaultApps[]; extern const char kDisableDhcpWpad[]; extern const char kDisableExtensionsFileAccessCheck[]; diff --git a/chrome/test/data/custom_handler_foo.html b/chrome/test/data/custom_handler_foo.html new file mode 100644 index 0000000..85ef48f --- /dev/null +++ b/chrome/test/data/custom_handler_foo.html @@ -0,0 +1,4 @@ +<html> +<head><title>Custom foo Handler</title></head> +<body>Test page to test custom foo handler.</body> +</html> diff --git a/chrome/test/data/custom_handler_mailto.html b/chrome/test/data/custom_handler_mailto.html deleted file mode 100644 index 891afc8..0000000 --- a/chrome/test/data/custom_handler_mailto.html +++ /dev/null @@ -1,4 +0,0 @@ -<html> -<head><title>Custom mailto Handler</title></head> -<body>Test page to test custom mailto handler.</body> -</html> diff --git a/chrome/test/data/custom_handler_webcal.html b/chrome/test/data/custom_handler_webcal.html deleted file mode 100644 index f39de0c..0000000 --- a/chrome/test/data/custom_handler_webcal.html +++ /dev/null @@ -1,4 +0,0 @@ -<html> -<head><title>Custom webcal Handler</title></head> -<body>Test page to test custom webcal handler.</body> -</html> diff --git a/chrome/test/data/profiles/custom_handlers/Default/Preferences b/chrome/test/data/profiles/custom_handlers/Default/Preferences deleted file mode 100644 index 0284f3a..0000000 --- a/chrome/test/data/profiles/custom_handlers/Default/Preferences +++ /dev/null @@ -1,17 +0,0 @@ -{ - "custom_handlers": { - "enabled": true, - "registered_protocol_handlers": [ { - "default": true, - "protocol": "mailto", - "title": "Test Mail Handler", - "url": "MAILTOHANDLER" - }, { - "default": true, - "protocol": "webcal", - "title": "Test Webcal Handler", - "url": "WEBCALHANDLER" - } ] - } -} - |