Commit e9afac10 authored by Matt Menard's avatar Matt Menard Committed by Commit Bot

Add device policy print servers to ServerPrintersProvider

This complements the existing user policy and adds print servers defined
by device policy. The device policy has its own corresponding whitelist
and if there is existing print servers in user policy also in device
policy, then the user policy print servers take precedence (which is
only for the purpose of the print server names currently).
Also changed to using shared url loader factory since the
SystemNetworkContext is non-unit-testable.

Bug: 1100777
Change-Id: I0e45597437b59b5eb940c4fbf5fb63596b8504dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2293178Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarLuum Habtemariam <luum@chromium.org>
Reviewed-by: default avatarPiotr Pawliczek <pawliczek@chromium.org>
Commit-Queue: Matt Menard <mattme@google.com>
Cr-Commit-Position: refs/heads/master@{#800322}
parent 9742a747
...@@ -3475,6 +3475,7 @@ source_set("unit_tests") { ...@@ -3475,6 +3475,7 @@ source_set("unit_tests") {
"printing/printer_event_tracker_unittest.cc", "printing/printer_event_tracker_unittest.cc",
"printing/printers_map_unittest.cc", "printing/printers_map_unittest.cc",
"printing/printers_sync_bridge_unittest.cc", "printing/printers_sync_bridge_unittest.cc",
"printing/server_printers_provider_unittest.cc",
"printing/specifics_translation_unittest.cc", "printing/specifics_translation_unittest.cc",
"printing/synced_printers_manager_unittest.cc", "printing/synced_printers_manager_unittest.cc",
"printing/test_cups_print_job_manager.cc", "printing/test_cups_print_job_manager.cc",
......
...@@ -52,8 +52,4 @@ specific_include_rules = { ...@@ -52,8 +52,4 @@ specific_include_rules = {
"+chrome/browser/ui/views/extensions/extension_dialog.h", "+chrome/browser/ui/views/extensions/extension_dialog.h",
"+chrome/browser/ui/views/select_file_dialog_extension.h", "+chrome/browser/ui/views/select_file_dialog_extension.h",
], ],
"server_printers_fetcher\.cc": [
# IPP protocol; it is needed for communication with print servers.
"+third_party/libipp/libipp/ipp.h",
],
} }
specific_include_rules = {
"(server_printers_fetcher|server_printers_provider_unittest)\.cc": [
# IPP protocol; it is needed for communication with print servers.
"+third_party/libipp/libipp/ipp.h",
],
}
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "components/device_event_log/device_event_log.h" #include "components/device_event_log/device_event_log.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
#include "services/network/public/cpp/resource_request.h" #include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h" #include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h" #include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
#include "third_party/libipp/libipp/ipp.h" #include "third_party/libipp/libipp/ipp.h"
...@@ -58,9 +59,11 @@ class ServerPrintersFetcher::PrivateImplementation ...@@ -58,9 +59,11 @@ class ServerPrintersFetcher::PrivateImplementation
CHECK(base::SequencedTaskRunnerHandle::IsSet()); CHECK(base::SequencedTaskRunnerHandle::IsSet());
task_runner_for_callback_ = base::SequencedTaskRunnerHandle::Get(); task_runner_for_callback_ = base::SequencedTaskRunnerHandle::Get();
// Post task to execute. // Post task to execute.
task_runner_->PostTask(FROM_HERE, task_runner_->PostTask(
base::BindOnce(&PrivateImplementation::SendQuery, FROM_HERE,
base::Unretained(this))); base::BindOnce(
&PrivateImplementation::SendQuery, base::Unretained(this),
g_browser_process->shared_url_loader_factory()->Clone()));
} }
~PrivateImplementation() override = default; ~PrivateImplementation() override = default;
...@@ -141,7 +144,8 @@ class ServerPrintersFetcher::PrivateImplementation ...@@ -141,7 +144,8 @@ class ServerPrintersFetcher::PrivateImplementation
private: private:
// The main task. It is scheduled in the constructor. // The main task. It is scheduled in the constructor.
void SendQuery() { void SendQuery(std::unique_ptr<network::PendingSharedURLLoaderFactory>
url_loader_factory) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Preparation of the IPP frame. // Preparation of the IPP frame.
...@@ -157,22 +161,18 @@ class ServerPrintersFetcher::PrivateImplementation ...@@ -157,22 +161,18 @@ class ServerPrintersFetcher::PrivateImplementation
auto resource_request = std::make_unique<network::ResourceRequest>(); auto resource_request = std::make_unique<network::ResourceRequest>();
resource_request->url = server_url_; resource_request->url = server_url_;
resource_request->method = "POST"; resource_request->method = "POST";
resource_request->headers.SetHeader(net::HttpRequestHeaders::kContentType,
"application/ipp");
resource_request->load_flags = resource_request->load_flags =
net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE; net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE;
resource_request->request_body =
network::ResourceRequestBody::CreateFromBytes(
reinterpret_cast<char*>(request_frame.data()),
request_frame.size());
resource_request->credentials_mode = network::mojom::CredentialsMode::kOmit; resource_request->credentials_mode = network::mojom::CredentialsMode::kOmit;
// TODO(pawliczek): create a traffic annotation for printing network traffic // TODO(pawliczek): create a traffic annotation for printing network traffic
simple_url_loader_ = network::SimpleURLLoader::Create( simple_url_loader_ = network::SimpleURLLoader::Create(
std::move(resource_request), MISSING_TRAFFIC_ANNOTATION); std::move(resource_request), MISSING_TRAFFIC_ANNOTATION);
network::mojom::URLLoaderFactory* loader_factory = std::string request_body(request_frame.begin(), request_frame.end());
g_browser_process->system_network_context_manager() simple_url_loader_->AttachStringForUpload(request_body, "application/ipp");
->GetURLLoaderFactory(); simple_url_loader_->DownloadAsStream(
simple_url_loader_->DownloadAsStream(loader_factory, this); network::SharedURLLoaderFactory::Create(std::move(url_loader_factory))
.get(),
this);
} }
// Posts a response with a list of printers. // Posts a response with a list of printers.
......
...@@ -11,9 +11,12 @@ ...@@ -11,9 +11,12 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/optional.h"
#include "base/scoped_observer.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/printing/print_server.h" #include "chrome/browser/chromeos/printing/print_server.h"
#include "chrome/browser/chromeos/printing/print_servers_provider.h" #include "chrome/browser/chromeos/printing/print_servers_provider.h"
#include "chrome/browser/chromeos/printing/print_servers_provider_factory.h" #include "chrome/browser/chromeos/printing/print_servers_provider_factory.h"
...@@ -23,6 +26,8 @@ ...@@ -23,6 +26,8 @@
#include "components/device_event_log/device_event_log.h" #include "components/device_event_log/device_event_log.h"
#include "url/gurl.h" #include "url/gurl.h"
class PrefService;
namespace chromeos { namespace chromeos {
namespace { namespace {
...@@ -35,25 +40,72 @@ struct PrintServerWithPrinters { ...@@ -35,25 +40,72 @@ struct PrintServerWithPrinters {
std::vector<PrinterDetector::DetectedPrinter> printers; // queried printers std::vector<PrinterDetector::DetectedPrinter> printers; // queried printers
}; };
class PrintServersPolicyProvider : public PrintServersProvider::Observer {
public:
PrintServersPolicyProvider(base::WeakPtr<PrintServersProvider> provider,
PrefService* prefs,
const std::string& pref_name)
: provider_(provider) {
provider_->SetAllowlistPref(prefs, pref_name);
provider->AddObserver(this);
}
~PrintServersPolicyProvider() override {
if (provider_) {
provider_->RemoveObserver(this);
}
}
base::Optional<std::vector<PrintServer>>& GetPrinterServers() {
return servers_;
}
void SetListener(const base::RepeatingCallback<void()>& callback) {
callback_ = std::make_unique<base::RepeatingCallback<void()>>(callback);
callback_->Run();
}
// PrintServersProvider::Observer implementation.
void OnServersChanged(bool servers_are_complete,
const std::vector<PrintServer>& servers) override {
servers_ =
servers_are_complete ? base::make_optional(servers) : base::nullopt;
if (callback_) {
callback_->Run();
}
}
private:
base::WeakPtr<PrintServersProvider> provider_;
base::Optional<std::vector<PrintServer>> servers_;
std::unique_ptr<base::RepeatingCallback<void()>> callback_;
};
class ServerPrintersProviderImpl class ServerPrintersProviderImpl
: public ServerPrintersProvider, : public ServerPrintersProvider,
public PrintServersProvider::Observer,
public base::SupportsWeakPtr<ServerPrintersProviderImpl> { public base::SupportsWeakPtr<ServerPrintersProviderImpl> {
public: public:
explicit ServerPrintersProviderImpl(Profile* profile) explicit ServerPrintersProviderImpl(Profile* profile)
: servers_provider_( : user_policy_provider_(std::make_unique<PrintServersPolicyProvider>(
PrintServersProviderFactory::Get()->GetForProfile(profile)) { PrintServersProviderFactory::Get()->GetForProfile(profile),
profile->GetPrefs(),
prefs::kExternalPrintServersAllowlist)),
device_policy_provider_(std::make_unique<PrintServersPolicyProvider>(
PrintServersProviderFactory::Get()->GetForDevice(),
g_browser_process->local_state(),
prefs::kDeviceExternalPrintServersAllowlist)) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
servers_provider_->SetAllowlistPref(profile->GetPrefs(),
prefs::kExternalPrintServersAllowlist);
servers_provider_->AddObserver(this);
}
~ServerPrintersProviderImpl() override { user_policy_provider_->SetListener(
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); base::BindRepeating(&ServerPrintersProviderImpl::NotifyPolicyChanged,
servers_provider_->RemoveObserver(this); weak_ptr_factory_.GetWeakPtr()));
device_policy_provider_->SetListener(
base::BindRepeating(&ServerPrintersProviderImpl::NotifyPolicyChanged,
weak_ptr_factory_.GetWeakPtr()));
} }
~ServerPrintersProviderImpl() override = default;
void RegisterPrintersFoundCallback(OnPrintersUpdateCallback cb) override { void RegisterPrintersFoundCallback(OnPrintersUpdateCallback cb) override {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
callback_ = std::move(cb); callback_ = std::move(cb);
...@@ -69,9 +121,8 @@ class ServerPrintersProviderImpl ...@@ -69,9 +121,8 @@ class ServerPrintersProviderImpl
return printers; return printers;
} }
// PrintServersProvider::Observer implementation.
void OnServersChanged(bool servers_are_complete, void OnServersChanged(bool servers_are_complete,
const std::vector<PrintServer>& servers) override { const std::map<GURL, PrintServer>& servers) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Create an entry in the device log. // Create an entry in the device log.
if (servers_are_complete) { if (servers_are_complete) {
...@@ -88,7 +139,8 @@ class ServerPrintersProviderImpl ...@@ -88,7 +139,8 @@ class ServerPrintersProviderImpl
servers_are_complete_ = servers_are_complete; servers_are_complete_ = servers_are_complete;
// Fill new map with new servers and compare with the old map. // Fill new map with new servers and compare with the old map.
std::map<GURL, PrintServerWithPrinters> new_servers; std::map<GURL, PrintServerWithPrinters> new_servers;
for (const auto& server : servers) { for (const auto& server_pair : servers) {
const PrintServer& server = server_pair.second;
const GURL& url = server.GetUrl(); const GURL& url = server.GetUrl();
const std::string& name = server.GetName(); const std::string& name = server.GetName();
auto it_new = new_servers.emplace(url, server).first; auto it_new = new_servers.emplace(url, server).first;
...@@ -158,6 +210,25 @@ class ServerPrintersProviderImpl ...@@ -158,6 +210,25 @@ class ServerPrintersProviderImpl
} }
private: private:
void NotifyPolicyChanged() {
std::map<GURL, PrintServer> all_servers;
auto& device_servers = device_policy_provider_->GetPrinterServers();
if (device_servers.has_value()) {
for (const auto& server : device_servers.value()) {
all_servers.emplace(server.GetUrl(), server);
}
}
auto& user_servers = user_policy_provider_->GetPrinterServers();
if (user_servers.has_value()) {
for (const auto& server : user_servers.value()) {
all_servers.emplace(server.GetUrl(), server);
}
}
bool is_complete = user_servers.has_value() || device_servers.has_value();
OnServersChanged(is_complete, all_servers);
}
// Returns true <=> all policies have been parsed and applied and all servers // Returns true <=> all policies have been parsed and applied and all servers
// have been queried (even when some errors occurred). // have been queried (even when some errors occurred).
bool IsComplete() const { bool IsComplete() const {
...@@ -176,7 +247,9 @@ class ServerPrintersProviderImpl ...@@ -176,7 +247,9 @@ class ServerPrintersProviderImpl
// URLs that are being queried now with corresponding fetcher objects. // URLs that are being queried now with corresponding fetcher objects.
std::map<GURL, std::unique_ptr<ServerPrintersFetcher>> fetchers_; std::map<GURL, std::unique_ptr<ServerPrintersFetcher>> fetchers_;
base::WeakPtr<PrintServersProvider> servers_provider_; std::unique_ptr<PrintServersPolicyProvider> user_policy_provider_;
std::unique_ptr<PrintServersPolicyProvider> device_policy_provider_;
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
base::WeakPtrFactory<ServerPrintersProviderImpl> weak_ptr_factory_{this}; base::WeakPtrFactory<ServerPrintersProviderImpl> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ServerPrintersProviderImpl); DISALLOW_COPY_AND_ASSIGN(ServerPrintersProviderImpl);
......
// Copyright 2020 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 "chrome/browser/chromeos/printing/server_printers_provider.h"
#include <memory>
#include <string>
#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/chromeos/printing/print_server.h"
#include "chrome/browser/chromeos/printing/print_servers_provider.h"
#include "chrome/browser/chromeos/printing/print_servers_provider_factory.h"
#include "chrome/browser/chromeos/printing/printer_detector.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "components/policy/proto/chrome_device_policy.pb.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/user_manager/scoped_user_manager.h"
#include "content/public/test/browser_task_environment.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libipp/libipp/ipp.h"
using ::testing::AllOf;
using ::testing::Property;
using ::testing::ResultOf;
using ::testing::UnorderedElementsAre;
namespace chromeos {
namespace {
const char kAccountName[] = "test";
// An example of configuration file with print servers for user policy.
const char kUserExternalPrintServersContentsJson[] = R"json(
[
{
"id": "id1",
"display_name": "LexaPrint - User",
"url": "ipp://192.168.1.5/user-printer",
}, {
"id": "id2",
"display_name": "Color Laser - User",
"url":"ipps://user-print-server.intranet.example.com:443/ipp/cl2k4",
}, {
"id": "id3",
"display_name": "B&W Printer - User",
"url":"ipps://user-print-server.intranet.example.com:443/bwprinter",
}
])json";
Printer UserPrinter1() {
Printer printer("server-20e91b728d4d04bc68132ced81772ef5");
printer.set_display_name("LexaPrint - User Name");
std::string server("ipp://192.168.1.5");
printer.set_print_server_uri(server);
Uri url("ipp://192.168.1.5:631/printers/LexaPrint - User Name");
printer.SetUri(url);
return printer;
}
Printer UserPrinter2() {
Printer printer("server-5da95e01216b1fe0ee1de25dc8d0a6e8");
printer.set_display_name("Color Laser - User Name");
std::string server("ipps://user-print-server.intranet.example.com");
printer.set_print_server_uri(server);
Uri url(
"ipps://user-print-server.intranet.example.com:443/printers/"
"Color Laser "
"- User Name");
printer.SetUri(url);
return printer;
}
// An example of configuration file with print servers for device policy.
const char kDeviceExternalPrintServersContentsJson[] = R"json(
[
{
"id": "id1",
"display_name": "LexaPrint - Device",
"url": "ipp://192.168.1.5/device-printer",
}, {
"id": "id2",
"display_name": "Color Laser - Device",
"url":"ipps://device-print-server.intranet.example.com:443/ipp/cl2k4",
}, {
"id": "id3",
"display_name": "B&W Printer - Device",
"url":"ipps://device-print-server.intranet.example.com:443/bwprinter",
}
])json";
// An example allowlist for device policy.
const std::vector<std::string> kDevicePrintServersPolicyAllowlist = {
"id3", "idX", "id1"};
Printer DevicePrinter1() {
Printer printer("server-f4a2ce25d8f9e6335d36f8253f8cf047");
printer.set_display_name("LexaPrint - Device Name");
std::string server("ipp://192.168.1.5");
Uri url("ipp://192.168.1.5:631/printers/LexaPrint - Device Name");
printer.set_print_server_uri(server);
printer.SetUri(url);
return printer;
}
Printer DevicePrinter2() {
Printer printer("server-1f88fe69dd2ce98ae6c195f3eb295a6d");
printer.set_display_name("B&W Printer - Device Name");
std::string server("ipps://device-print-server.intranet.example.com");
printer.set_print_server_uri(server);
Uri url(
"ipps://device-print-server.intranet.example.com:443/printers/"
"B&W Printer - Device Name");
printer.SetUri(url);
return printer;
}
} // namespace
auto GetPrinter = [](const PrinterDetector::DetectedPrinter& input) -> Printer {
return input.printer;
};
auto PrinterMatcher(Printer printer) {
return ResultOf(
GetPrinter,
AllOf(Property(&Printer::uri, printer.uri()),
Property(&Printer::print_server_uri, printer.print_server_uri()),
Property(&Printer::display_name, printer.display_name())));
}
class ServerPrintersProviderTest : public ::testing::Test {
public:
ServerPrintersProviderTest()
: local_state_(TestingBrowserProcess::GetGlobal()),
test_shared_loader_factory_(
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&test_url_loader_factory_)) {}
protected:
void SetUp() override {
TestingBrowserProcess::GetGlobal()->SetSharedURLLoaderFactory(
test_shared_loader_factory_);
ASSERT_TRUE(test_server_.Start());
SetupUserProfile();
server_printers_provider_ = ServerPrintersProvider::Create(profile_.get());
}
void SetupUserProfile() {
auto unique_user_manager = std::make_unique<FakeChromeUserManager>();
auto* user_manager = unique_user_manager.get();
user_manager_enabler_ = std::make_unique<user_manager::ScopedUserManager>(
std::move(unique_user_manager));
TestingProfile::Builder profile_builder;
profile_builder.SetProfileName(kAccountName);
profile_ = profile_builder.Build();
user_manager->AddUserWithAffiliationAndTypeAndProfile(
AccountId::FromUserEmail(kAccountName), false,
user_manager::UserType::USER_TYPE_REGULAR, profile_.get());
}
void TearDown() override { PrintServersProviderFactory::Get()->Shutdown(); }
std::string CreateResponse(const std::string& name,
const std::string& description) {
ipp::Response_CUPS_Get_Printers response;
response.printer_attributes[0].printer_name.Set(
ipp::StringWithLanguage(name, "us-EN"));
response.printer_attributes[0].printer_info.Set(
ipp::StringWithLanguage(description, "us-EN"));
ipp::Server server(ipp::Version::_1_1, 1);
server.BuildResponseFrom(&response);
std::vector<uint8_t> bin_data;
EXPECT_TRUE(server.WriteResponseFrameTo(&bin_data));
std::string response_body(bin_data.begin(), bin_data.end());
return response_body;
}
void ApplyDevicePolicy() {
device_print_servers_provider_ =
PrintServersProviderFactory::Get()->GetForDevice();
device_print_servers_provider_->SetData(
std::make_unique<std::string>(kDeviceExternalPrintServersContentsJson));
// Apply device allowlist.
auto device_allowlist =
std::make_unique<base::Value>(base::Value::Type::LIST);
for (const std::string& id : kDevicePrintServersPolicyAllowlist)
device_allowlist->Append(base::Value(id));
local_state_.Get()->SetManagedPref(
prefs::kDeviceExternalPrintServersAllowlist,
std::move(device_allowlist));
}
void ApplyUserPolicy() {
static const std::vector<std::string> kUserPrintServersPolicyAllowlist = {
"idX", "id2", "id1"};
user_print_servers_provider_ =
PrintServersProviderFactory::Get()->GetForProfile(profile_.get());
user_print_servers_provider_->SetData(
std::make_unique<std::string>(kUserExternalPrintServersContentsJson));
// Apply user allowlist.
auto user_allowlist = std::make_unique<base::ListValue>();
for (const std::string& id : kUserPrintServersPolicyAllowlist)
user_allowlist->Append(base::Value(id));
profile_->GetTestingPrefService()->SetManagedPref(
prefs::kExternalPrintServersAllowlist, std::move(user_allowlist));
}
// Everything must be called on Chrome_UIThread.
content::BrowserTaskEnvironment task_environment_;
ScopedTestingLocalState local_state_;
network::TestURLLoaderFactory test_url_loader_factory_;
scoped_refptr<network::WeakWrapperSharedURLLoaderFactory>
test_shared_loader_factory_;
std::unique_ptr<TestingProfile> profile_;
std::unique_ptr<user_manager::ScopedUserManager> user_manager_enabler_;
net::test_server::EmbeddedTestServer test_server_;
base::WeakPtr<PrintServersProvider> user_print_servers_provider_;
base::WeakPtr<PrintServersProvider> device_print_servers_provider_;
std::unique_ptr<ServerPrintersProvider> server_printers_provider_;
};
TEST_F(ServerPrintersProviderTest, GetPrinters_OnlyDevicePolicy) {
test_url_loader_factory_.AddResponse(
"http://192.168.1.5:631/device-printer",
CreateResponse("LexaPrint - Device Name", "LexaPrint Description"));
test_url_loader_factory_.AddResponse(
"https://device-print-server.intranet.example.com:443/bwprinter",
CreateResponse("B&W Printer - Device Name", "B&W Printer Description"));
EXPECT_TRUE(server_printers_provider_->GetPrinters().empty());
ApplyDevicePolicy();
task_environment_.RunUntilIdle();
EXPECT_THAT(server_printers_provider_->GetPrinters(),
UnorderedElementsAre(PrinterMatcher(DevicePrinter1()),
PrinterMatcher(DevicePrinter2())));
}
TEST_F(ServerPrintersProviderTest, GetPrinters_OnlyUserPolicy) {
test_url_loader_factory_.AddResponse(
"http://192.168.1.5:631/user-printer",
CreateResponse("LexaPrint - User Name", "LexaPrint Description"));
test_url_loader_factory_.AddResponse(
"https://user-print-server.intranet.example.com/ipp/cl2k4",
CreateResponse("Color Laser - User Name", "Color Laser Description"));
EXPECT_TRUE(server_printers_provider_->GetPrinters().empty());
ApplyUserPolicy();
task_environment_.RunUntilIdle();
EXPECT_THAT(server_printers_provider_->GetPrinters(),
UnorderedElementsAre(PrinterMatcher(UserPrinter1()),
PrinterMatcher(UserPrinter2())));
}
TEST_F(ServerPrintersProviderTest, GetPrinters_UserAndDevicePolicy) {
test_url_loader_factory_.AddResponse(
"http://192.168.1.5:631/device-printer",
CreateResponse("LexaPrint - Device Name", "LexaPrint Description"));
test_url_loader_factory_.AddResponse(
"https://device-print-server.intranet.example.com:443/bwprinter",
CreateResponse("B&W Printer - Device Name", "B&W Printer Description"));
test_url_loader_factory_.AddResponse(
"http://192.168.1.5:631/user-printer",
CreateResponse("LexaPrint - User Name", "LexaPrint Description"));
test_url_loader_factory_.AddResponse(
"https://user-print-server.intranet.example.com/ipp/cl2k4",
CreateResponse("Color Laser - User Name", "Color Laser Description"));
EXPECT_TRUE(server_printers_provider_->GetPrinters().empty());
ApplyUserPolicy();
ApplyDevicePolicy();
task_environment_.RunUntilIdle();
EXPECT_THAT(server_printers_provider_->GetPrinters(),
UnorderedElementsAre(PrinterMatcher(DevicePrinter1()),
PrinterMatcher(DevicePrinter2()),
PrinterMatcher(UserPrinter1()),
PrinterMatcher(UserPrinter2())));
}
} // namespace chromeos
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment