Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Unified Diff: content/browser/child_process_security_policy_unittest.cc

Issue 8588039: Remove "open in new tab" items from context menu if the process doesn't (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/child_process_security_policy.cc ('k') | content/browser/mock_content_browser_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/child_process_security_policy_unittest.cc
===================================================================
--- content/browser/child_process_security_policy_unittest.cc (revision 113019)
+++ content/browser/child_process_security_policy_unittest.cc (working copy)
@@ -2,41 +2,76 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <set>
#include <string>
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/platform_file.h"
#include "content/browser/child_process_security_policy.h"
+#include "content/browser/mock_content_browser_client.h"
#include "content/common/test_url_constants.h"
#include "content/public/common/url_constants.h"
-#include "net/url_request/url_request.h"
-#include "net/url_request/url_request_test_job.h"
+#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace {
+
+const int kRendererID = 42;
+const int kWorkerRendererID = kRendererID + 1;
+
+class ChildProcessSecurityPolicyTestBrowserClient :
+ public content::MockContentBrowserClient {
+ public:
+ ChildProcessSecurityPolicyTestBrowserClient() {}
+
+ virtual bool IsHandledURL(const GURL& url) {
+ return schemes_.find(url.scheme()) != schemes_.end();
+ }
+
+ void ClearSchemes() {
+ schemes_.clear();
+ }
+
+ void AddScheme(const std::string& scheme) {
+ schemes_.insert(scheme);
+ }
+
+ private:
+ std::set<std::string> schemes_;
+};
+
+} // namespace
+
class ChildProcessSecurityPolicyTest : public testing::Test {
- protected:
- // testing::Test
+ public:
+ ChildProcessSecurityPolicyTest() : old_browser_client_(NULL) {
+ }
+
virtual void SetUp() {
- // In the real world, "chrome:" is a handled scheme.
- RegisterProtocolFactory(chrome::kChromeUIScheme,
- &net::URLRequestTestJob::Factory);
+ old_browser_client_ = content::GetContentClient()->browser();
+ content::GetContentClient()->set_browser(&test_browser_client_);
+
+ // Claim to always handle chrome:// URLs because the CPSP's notion of
+ // allowing WebUI bindings is hard-wired to this particular scheme.
+ test_browser_client_.AddScheme("chrome");
}
+
virtual void TearDown() {
- RegisterProtocolFactory(chrome::kChromeUIScheme, NULL);
+ test_browser_client_.ClearSchemes();
+ content::GetContentClient()->set_browser(old_browser_client_);
}
- static net::URLRequest::ProtocolFactory* RegisterProtocolFactory(
- const std::string& scheme,
- net::URLRequest::ProtocolFactory* factory) {
- return net::URLRequest::Deprecated::RegisterProtocolFactory(
- scheme, factory);
+ protected:
+ void RegisterTestScheme(const std::string& scheme) {
+ test_browser_client_.AddScheme(scheme);
}
+
+ private:
+ ChildProcessSecurityPolicyTestBrowserClient test_browser_client_;
+ content::ContentBrowserClient* old_browser_client_;
};
-static int kRendererID = 42;
-static int kWorkerRendererID = kRendererID + 1;
-
TEST_F(ChildProcessSecurityPolicyTest, IsWebSafeSchemeTest) {
ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance();
@@ -174,8 +209,8 @@
// Currently, "asdf" is destined for ShellExecute, so it is allowed.
EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("asdf:rockers")));
- // Once we register a ProtocolFactory for "asdf", we default to deny.
- RegisterProtocolFactory("asdf", &net::URLRequestTestJob::Factory);
+ // Once we register "asdf", we default to deny.
+ RegisterTestScheme("asdf");
EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("asdf:rockers")));
// We can allow new schemes by adding them to the whitelist.
@@ -183,9 +218,6 @@
EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("asdf:rockers")));
// Cleanup.
- RegisterProtocolFactory("asdf", NULL);
- EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("asdf:rockers")));
-
p->Remove(kRendererID);
}
« no previous file with comments | « content/browser/child_process_security_policy.cc ('k') | content/browser/mock_content_browser_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698