1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stddef.h>
#include "chrome/browser/ash/printing/printers_sync_bridge.h"
#include "chrome/browser/sync/test/integration/printers_helper.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/sync/test/integration/updated_progress_marker_checker.h"
#include "chromeos/printing/printer_configuration.h"
#include "content/public/test/browser_test.h"
using printers_helper::AddPrinter;
using printers_helper::CreateTestPrinterSpecifics;
using printers_helper::EditPrinterDescription;
using printers_helper::GetPrinterCount;
using printers_helper::GetPrinterStore;
using printers_helper::GetVerifierPrinterCount;
using printers_helper::GetVerifierPrinterStore;
using printers_helper::ProfileContainsSamePrintersAsVerifier;
using printers_helper::RemovePrinter;
namespace {
class SingleClientPrintersSyncTest : public SyncTest {
public:
SingleClientPrintersSyncTest() : SyncTest(SINGLE_CLIENT) {}
~SingleClientPrintersSyncTest() override = default;
bool SetupClients() override {
if (!SyncTest::SetupClients()) {
return false;
}
CHECK(UseVerifier());
printers_helper::WaitForPrinterStoreToLoad(verifier());
printers_helper::WaitForPrinterStoreToLoad(GetProfile(0));
return true;
}
bool UseVerifier() override {
// TODO(crbug.com/40724972): rewrite tests to not use verifier.
return true;
}
};
// Verify that printers aren't added with a sync call.
IN_PROC_BROWSER_TEST_F(SingleClientPrintersSyncTest, NoPrinters) {
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait());
EXPECT_TRUE(ProfileContainsSamePrintersAsVerifier(0));
}
// Verify syncing doesn't randomly remove a printer.
IN_PROC_BROWSER_TEST_F(SingleClientPrintersSyncTest, SingleNewPrinter) {
ASSERT_TRUE(SetupSync());
ASSERT_EQ(0, GetVerifierPrinterCount());
AddPrinter(GetPrinterStore(0), printers_helper::CreateTestPrinter(0));
AddPrinter(GetVerifierPrinterStore(), printers_helper::CreateTestPrinter(0));
ASSERT_EQ(1, GetPrinterCount(0));
ASSERT_EQ(1, GetVerifierPrinterCount());
ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait());
EXPECT_EQ(1, GetVerifierPrinterCount());
EXPECT_TRUE(ProfileContainsSamePrintersAsVerifier(0));
}
// Verify editing a printer doesn't add it.
IN_PROC_BROWSER_TEST_F(SingleClientPrintersSyncTest, EditPrinter) {
ASSERT_TRUE(SetupSync());
AddPrinter(GetPrinterStore(0), printers_helper::CreateTestPrinter(0));
AddPrinter(GetVerifierPrinterStore(), printers_helper::CreateTestPrinter(0));
ASSERT_TRUE(
EditPrinterDescription(GetPrinterStore(0), 0, "Updated description"));
EXPECT_EQ(1, GetPrinterCount(0));
EXPECT_EQ(1, GetVerifierPrinterCount());
EXPECT_FALSE(ProfileContainsSamePrintersAsVerifier(0));
}
// Verify that removing a printer works.
IN_PROC_BROWSER_TEST_F(SingleClientPrintersSyncTest, RemovePrinter) {
ASSERT_TRUE(SetupSync());
AddPrinter(GetPrinterStore(0), printers_helper::CreateTestPrinter(0));
EXPECT_EQ(1, GetPrinterCount(0));
RemovePrinter(GetPrinterStore(0), 0);
EXPECT_EQ(0, GetPrinterCount(0));
}
// Verify that merging data added before sync works.
IN_PROC_BROWSER_TEST_F(SingleClientPrintersSyncTest, AddBeforeSetup) {
ASSERT_TRUE(SetupClients());
AddPrinter(GetPrinterStore(0), printers_helper::CreateTestPrinter(0));
EXPECT_EQ(1, GetPrinterCount(0));
EXPECT_TRUE(SetupSync());
}
// Verify that adding a print server printer retains the print server URI.
IN_PROC_BROWSER_TEST_F(SingleClientPrintersSyncTest, AddPrintServerPrinter) {
ASSERT_TRUE(SetupClients());
const char kServerAddress[] = "ipp://192.168.1.1:631";
// Initialize sync bridge with test printer.
std::unique_ptr<sync_pb::PrinterSpecifics> printer =
CreateTestPrinterSpecifics(0);
const std::string spec_printer_id = printer->id();
printer->set_print_server_uri(kServerAddress);
ash::PrintersSyncBridge* bridge = GetPrinterStore(0)->GetSyncBridge();
bridge->AddPrinter(std::move(printer));
// Start the sync.
ASSERT_TRUE(SetupSync());
std::optional<sync_pb::PrinterSpecifics> spec_printer =
bridge->GetPrinter(spec_printer_id);
ASSERT_TRUE(spec_printer);
// Verify that the print server address was saved correctly.
EXPECT_EQ(kServerAddress, spec_printer->print_server_uri());
}
} // namespace
|