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

Unified Diff: mojo/shell/fetcher/about_fetcher_unittest.cc

Issue 1701933004: Remove the old package manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@am2
Patch Set: . Created 4 years, 10 months 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 | « mojo/shell/fetcher/about_fetcher.cc ('k') | mojo/shell/fetcher/data_fetcher.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/fetcher/about_fetcher_unittest.cc
diff --git a/mojo/shell/fetcher/about_fetcher_unittest.cc b/mojo/shell/fetcher/about_fetcher_unittest.cc
deleted file mode 100644
index 09e881f5eeb32828b663cc0fdb434607ad1a4b57..0000000000000000000000000000000000000000
--- a/mojo/shell/fetcher/about_fetcher_unittest.cc
+++ /dev/null
@@ -1,196 +0,0 @@
-// 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 "mojo/shell/fetcher/about_fetcher.h"
-
-#include <stddef.h>
-
-#include <utility>
-
-#include "base/at_exit.h"
-#include "base/command_line.h"
-#include "base/macros.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
-#include "base/path_service.h"
-#include "base/run_loop.h"
-#include "mojo/public/cpp/bindings/weak_binding_set.h"
-#include "mojo/shell/application_loader.h"
-#include "mojo/shell/application_manager.h"
-#include "mojo/shell/package_manager/package_manager_impl.h"
-#include "mojo/shell/public/cpp/interface_factory.h"
-#include "mojo/shell/public/cpp/shell_client.h"
-#include "mojo/shell/public/cpp/shell_connection.h"
-#include "mojo/shell/public/interfaces/content_handler.mojom.h"
-#include "mojo/shell/switches.h"
-#include "mojo/util/filename_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace mojo {
-namespace shell {
-namespace {
-
-class TestContentHandler : public ShellClient,
- public InterfaceFactory<mojom::ContentHandler>,
- public mojom::ContentHandler {
- public:
- TestContentHandler() : response_number_(0) {}
- ~TestContentHandler() override {}
-
- size_t response_number() const { return response_number_; }
- const URLResponse* latest_response() const { return latest_response_.get(); }
-
- private:
- // Overridden from ShellClient:
- void Initialize(Shell* shell, const std::string& url, uint32_t id) override {}
- bool AcceptConnection(Connection* connection) override {
- connection->AddInterface<mojom::ContentHandler>(this);
- return true;
- }
-
- // Overridden from InterfaceFactory<mojom::ContentHandler>:
- void Create(Connection* connection,
- InterfaceRequest<mojom::ContentHandler> request) override {
- bindings_.AddBinding(this, std::move(request));
- }
-
- // Overridden from mojom::ContentHandler:
- void StartApplication(
- InterfaceRequest<mojom::ShellClient> request,
- URLResponsePtr response,
- const Callback<void()>& destruct_callback) override {
- response_number_++;
- latest_response_ = std::move(response);
- destruct_callback.Run();
-
- // Drop |application| request. This results in the application manager
- // dropping the InterfaceProvider interface request provided by the client
- // who made the ConnectToApplication() call. Therefore the client could
- // listen for connection error of the InterfaceProvider interface to learn
- // that StartApplication() has been called.
- }
-
- size_t response_number_;
- URLResponsePtr latest_response_;
- WeakBindingSet<mojom::ContentHandler> bindings_;
-
- DISALLOW_COPY_AND_ASSIGN(TestContentHandler);
-};
-
-class TestLoader : public ApplicationLoader {
- public:
- explicit TestLoader(ShellClient* delegate) : delegate_(delegate) {}
- ~TestLoader() override {}
-
- private:
- // Overridden from ApplicationLoader:
- void Load(const GURL& url,
- InterfaceRequest<mojom::ShellClient> request) override {
- app_.reset(new ShellConnection(delegate_, std::move(request)));
- }
-
- ShellClient* delegate_;
- scoped_ptr<ShellConnection> app_;
-
- DISALLOW_COPY_AND_ASSIGN(TestLoader);
-};
-
-class AboutFetcherTest : public testing::Test {
- public:
- AboutFetcherTest() {}
- ~AboutFetcherTest() override {}
-
- protected:
- const TestContentHandler* html_content_handler() const {
- return &html_content_handler_;
- }
-
- void ConnectAndWait(const std::string& url) {
- base::RunLoop run_loop;
-
- shell::mojom::InterfaceProviderPtr remote_interfaces;
- shell::mojom::InterfaceProviderRequest remote_request =
- GetProxy(&remote_interfaces);
- // This connection error handler will be called when:
- // - TestContentHandler::StartApplication() has been called (please see
- // comments in that method); or
- // - the application manager fails to fetch the requested URL.
- remote_interfaces.set_connection_error_handler(
- [&run_loop]() { run_loop.Quit(); });
-
- scoped_ptr<ConnectToApplicationParams> params(
- new ConnectToApplicationParams);
- params->SetTargetURL(GURL(url));
- params->set_remote_interfaces(std::move(remote_request));
- application_manager_->ConnectToApplication(std::move(params));
-
- run_loop.Run();
- }
-
- // Overridden from testing::Test:
- void SetUp() override {
- if (!ShouldRunTest())
- return;
- base::FilePath shell_dir;
- PathService::Get(base::DIR_MODULE, &shell_dir);
- scoped_ptr<PackageManagerImpl> package_manager(
- new PackageManagerImpl(shell_dir, nullptr, nullptr));
- package_manager->RegisterContentHandler(
- "text/html", GURL("test:html_content_handler"));
- application_manager_.reset(
- new ApplicationManager(std::move(package_manager), true));
- application_manager_->SetLoaderForURL(
- make_scoped_ptr(new TestLoader(&html_content_handler_)),
- GURL("test:html_content_handler"));
- }
-
- void TearDown() override { application_manager_.reset(); }
-
- bool ShouldRunTest() const {
- return base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDontUseRemotePackageManager);
- }
-
- private:
- base::ShadowingAtExitManager at_exit_;
- TestContentHandler html_content_handler_;
- base::MessageLoop loop_;
- scoped_ptr<ApplicationManager> application_manager_;
-
- DISALLOW_COPY_AND_ASSIGN(AboutFetcherTest);
-};
-
-TEST_F(AboutFetcherTest, AboutBlank) {
- if (!ShouldRunTest())
- return;
-
- ConnectAndWait("about:blank");
-
- ASSERT_EQ(1u, html_content_handler()->response_number());
-
- const URLResponse* response = html_content_handler()->latest_response();
- EXPECT_EQ("about:blank", response->url);
- EXPECT_EQ(200u, response->status_code);
- EXPECT_EQ("text/html", response->mime_type);
- EXPECT_FALSE(response->body.is_valid());
-}
-
-TEST_F(AboutFetcherTest, UnrecognizedURL) {
- if (!ShouldRunTest())
- return;
-
- ConnectAndWait("about:some_unrecognized_url");
-
- ASSERT_EQ(1u, html_content_handler()->response_number());
-
- const URLResponse* response = html_content_handler()->latest_response();
- EXPECT_EQ("about:some_unrecognized_url", response->url);
- EXPECT_EQ(404u, response->status_code);
- EXPECT_EQ("text/html", response->mime_type);
- EXPECT_FALSE(response->body.is_valid());
-}
-
-} // namespace
-} // namespace shell
-} // namespace mojo
« no previous file with comments | « mojo/shell/fetcher/about_fetcher.cc ('k') | mojo/shell/fetcher/data_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698