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 131 132 133 134 135 136 137 138 139 140 141 142 143
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_WEBAPKS_HELPER_H_
#define CHROME_BROWSER_SYNC_TEST_INTEGRATION_WEBAPKS_HELPER_H_
#include "chrome/browser/android/webapk/webapk_registrar.h"
#include "chrome/browser/sync/test/integration/fake_server_match_status_checker.h"
#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace webapks_helper {
bool AreIconInfosMatching(const sync_pb::WebApkIconInfo& icon_info_1,
const sync_pb::WebApkIconInfo& icon_info_2);
// Matchers for sync_pb::WebApkSpecifics.
MATCHER_P(ServerManifestIdIs, manifest_id, "") {
return arg.manifest_id() == manifest_id;
}
MATCHER_P(ServerStartUrlIs, start_url, "") {
return arg.start_url() == start_url;
}
MATCHER_P(ServerNameIs, name, "") {
return arg.name() == name;
}
MATCHER_P(ServerThemeColorIs, theme_color, "") {
return arg.theme_color() == theme_color;
}
MATCHER_P(ServerScopeIs, scope, "") {
return arg.scope() == scope;
}
MATCHER_P(ServerLastUsedTimeWindowsEpochMicrosIs,
last_used_time_windows_epoch_micros,
"") {
return arg.last_used_time_windows_epoch_micros() ==
last_used_time_windows_epoch_micros;
}
MATCHER_P(ServerIconInfoIs, icon_info, "") {
return arg.icon_infos_size() == 1 &&
AreIconInfosMatching(arg.icon_infos(0), *icon_info);
}
// Matchers for std::pair<const webapps::AppId,
// std::unique_ptr<webapk::WebApkProto>> (ie, a single item from a
// webapk::Registry).
MATCHER_P(LocalAppIdIs, app_id, "") {
return arg.first == app_id;
}
MATCHER_P(LocalIsLocallyInstalledIs, is_locally_installed, "") {
return arg.second->is_locally_installed() == is_locally_installed;
}
MATCHER_P(LocalManifestIdIs, manifest_id, "") {
return arg.second->sync_data().manifest_id() == manifest_id;
}
MATCHER_P(LocalStartUrlIs, start_url, "") {
return arg.second->sync_data().start_url() == start_url;
}
MATCHER_P(LocalNameIs, name, "") {
return arg.second->sync_data().name() == name;
}
MATCHER_P(LocalThemeColorIs, theme_color, "") {
return arg.second->sync_data().theme_color() == theme_color;
}
MATCHER_P(LocalScopeIs, scope, "") {
return arg.second->sync_data().scope() == scope;
}
MATCHER_P(LocalLastUsedTimeWindowsEpochMicrosIs,
last_used_time_windows_epoch_micros,
"") {
return arg.second->sync_data().last_used_time_windows_epoch_micros() ==
last_used_time_windows_epoch_micros;
}
MATCHER_P(LocalIconInfoIs, icon_info, "") {
return arg.second->sync_data().icon_infos_size() == 1 &&
AreIconInfosMatching(arg.second->sync_data().icon_infos(0),
*icon_info);
}
// A helper class that waits for entries in the local webapk DB that match the
// given matchers.
class LocalWebApkMatchChecker : public SingleClientStatusChangeChecker {
public:
using Matcher = testing::Matcher<webapk::Registry>;
explicit LocalWebApkMatchChecker(int profile_index,
syncer::SyncServiceImpl* service,
const Matcher& matcher);
~LocalWebApkMatchChecker() override;
// StatusChangeChecker implementation.
bool IsExitConditionSatisfied(std::ostream* os) override;
// syncer::SyncServiceObserver implementation.
void OnSyncCycleCompleted(syncer::SyncService* sync) override;
private:
const int profile_index_;
const Matcher matcher_;
};
// A helper class that waits for the WEB_APK entities on the FakeServer to match
// a given GMock matcher.
class ServerWebApkMatchChecker
: public fake_server::FakeServerMatchStatusChecker {
public:
using Matcher = testing::Matcher<std::vector<sync_pb::WebApkSpecifics>>;
explicit ServerWebApkMatchChecker(const Matcher& matcher);
~ServerWebApkMatchChecker() override;
ServerWebApkMatchChecker(const ServerWebApkMatchChecker&) = delete;
ServerWebApkMatchChecker& operator=(const ServerWebApkMatchChecker&) = delete;
// FakeServer::Observer overrides.
void OnCommit(syncer::DataTypeSet committed_data_types) override;
// StatusChangeChecker overrides.
bool IsExitConditionSatisfied(std::ostream* os) override;
private:
const Matcher matcher_;
};
} // namespace webapks_helper
#endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_WEBAPKS_HELPER_H_
|