forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move more of ContentHandler handling into PackageManager.
Dependency/#include rules required that I restructure the unit tests as part of this, moving all the content handler tests into package_manager also. R=yzshen@chromium.org http://crbug.com/533085 Review URL: https://codereview.chromium.org/1358533004 Cr-Commit-Position: refs/heads/master@{#350572}
- Loading branch information
ben
authored and
Commit bot
committed
Sep 24, 2015
1 parent
277f231
commit 885517f
Showing
24 changed files
with
1,252 additions
and
1,055 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
mojo/package_manager/capability_filter_content_handler_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
// Copyright 2015 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/path_service.h" | ||
#include "mojo/application/public/cpp/application_connection.h" | ||
#include "mojo/application/public/cpp/application_delegate.h" | ||
#include "mojo/application/public/cpp/application_impl.h" | ||
#include "mojo/application/public/cpp/interface_factory.h" | ||
#include "mojo/application/public/interfaces/content_handler.mojom.h" | ||
#include "mojo/common/weak_binding_set.h" | ||
#include "mojo/package_manager/package_manager_impl.h" | ||
#include "mojo/shell/capability_filter_test.h" | ||
#include "mojo/shell/fetcher.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
namespace mojo { | ||
namespace package_manager { | ||
namespace test { | ||
namespace { | ||
|
||
const char kTestMimeType[] = "test/mime-type"; | ||
|
||
// A custom Fetcher used to trigger a content handler for kTestMimeType for a | ||
// specific test. | ||
class TestFetcher : public shell::Fetcher { | ||
public: | ||
TestFetcher(const GURL& url, const FetchCallback& callback) | ||
: shell::Fetcher(callback), | ||
url_(url) { | ||
loader_callback_.Run(make_scoped_ptr(this)); | ||
} | ||
~TestFetcher() override {} | ||
|
||
private: | ||
// Overridden from Fetcher: | ||
const GURL& GetURL() const override { return url_; } | ||
GURL GetRedirectURL() const override { return GURL(); } | ||
GURL GetRedirectReferer() const override { return GURL(); } | ||
URLResponsePtr AsURLResponse(base::TaskRunner* task_runner, | ||
uint32_t skip) override { | ||
URLResponsePtr response(URLResponse::New()); | ||
response->url = url_.spec(); | ||
return response.Pass(); | ||
} | ||
void AsPath( | ||
base::TaskRunner* task_runner, | ||
base::Callback<void(const base::FilePath&, bool)> callback) override {} | ||
std::string MimeType() override { return kTestMimeType; } | ||
bool HasMojoMagic() override { return false; } | ||
bool PeekFirstLine(std::string* line) override { return false; } | ||
|
||
const GURL url_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(TestFetcher); | ||
}; | ||
|
||
class TestPackageManager : public PackageManagerImpl { | ||
public: | ||
TestPackageManager(const base::FilePath& package_path) | ||
: PackageManagerImpl(package_path, nullptr) {} | ||
~TestPackageManager() override {} | ||
|
||
private: | ||
// Overridden from PackageManagerImpl: | ||
void FetchRequest( | ||
URLRequestPtr request, | ||
const shell::Fetcher::FetchCallback& loader_callback) override { | ||
new TestFetcher(GURL(request->url), loader_callback); | ||
} | ||
|
||
DISALLOW_COPY_AND_ASSIGN(TestPackageManager); | ||
}; | ||
|
||
class TestContentHandler : public ApplicationDelegate, | ||
public InterfaceFactory<ContentHandler>, | ||
public ContentHandler { | ||
public: | ||
TestContentHandler() : app_(nullptr) {} | ||
~TestContentHandler() override {} | ||
|
||
private: | ||
// Overridden from ApplicationDelegate: | ||
void Initialize(ApplicationImpl* app) override { | ||
app_ = app; | ||
} | ||
bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | ||
connection->AddService<ContentHandler>(this); | ||
return true; | ||
} | ||
|
||
// Overridden from InterfaceFactory<ContentHandler>: | ||
void Create(ApplicationConnection* connection, | ||
InterfaceRequest<ContentHandler> request) override { | ||
bindings_.AddBinding(this, request.Pass()); | ||
} | ||
|
||
// Overridden from ContentHandler: | ||
void StartApplication(InterfaceRequest<Application> application, | ||
URLResponsePtr response) override { | ||
scoped_ptr<ApplicationDelegate> delegate(new shell::test::TestApplication); | ||
embedded_apps_.push_back( | ||
new ApplicationImpl(delegate.get(), application.Pass())); | ||
embedded_app_delegates_.push_back(delegate.Pass()); | ||
} | ||
|
||
ApplicationImpl* app_; | ||
WeakBindingSet<ContentHandler> bindings_; | ||
ScopedVector<ApplicationDelegate> embedded_app_delegates_; | ||
ScopedVector<ApplicationImpl> embedded_apps_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(TestContentHandler); | ||
}; | ||
|
||
} // namespace | ||
|
||
class CapabilityFilterContentHandlerTest | ||
: public shell::test::CapabilityFilterTest { | ||
public: | ||
CapabilityFilterContentHandlerTest() | ||
: package_manager_(nullptr) { | ||
base::FilePath shell_dir; | ||
PathService::Get(base::DIR_MODULE, &shell_dir); | ||
package_manager_ = new TestPackageManager(shell_dir); | ||
} | ||
~CapabilityFilterContentHandlerTest() override {} | ||
|
||
private: | ||
// Overridden from CapabilityFilterTest: | ||
shell::PackageManager* CreatePackageManager() override { | ||
return package_manager_; | ||
} | ||
void SetUp() override { | ||
shell::test::CapabilityFilterTest::SetUp(); | ||
|
||
GURL content_handler_url("test:content_handler"); | ||
package_manager_->RegisterContentHandler(kTestMimeType, | ||
content_handler_url); | ||
CreateLoader<TestContentHandler>(content_handler_url.spec()); | ||
} | ||
|
||
// Owned by ApplicationManager in base class. | ||
PackageManagerImpl* package_manager_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(CapabilityFilterContentHandlerTest); | ||
}; | ||
|
||
TEST_F(CapabilityFilterContentHandlerTest, Blocking) { | ||
RunBlockingTest(); | ||
} | ||
|
||
TEST_F(CapabilityFilterContentHandlerTest, Wildcards) { | ||
RunWildcardTest(); | ||
} | ||
|
||
} // namespace test | ||
} // namespace package_manager | ||
} // namespace mojo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.