Commit 1e2ba090 authored by tby's avatar tby Committed by Commit Bot

[Hashed logging] Add some more tests.

Bug: 951287
Change-Id: I4b4a9ff809908b7804e1111b07d41279d8e66039
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1640797Reviewed-by: default avatarCharles . <charleszhao@chromium.org>
Commit-Queue: Tony Yeoman <tby@chromium.org>
Cr-Commit-Position: refs/heads/master@{#669562}
parent deaace8f
......@@ -4,6 +4,7 @@
#include "chrome/browser/ui/app_list/search/search_result_ranker/app_list_launch_metrics_provider.h"
#include <set>
#include <string>
#include "base/base64.h"
......@@ -141,6 +142,22 @@ class AppListLaunchMetricsProviderTest : public testing::Test {
return proto->secret();
}
uint64_t ReadUserId() {
std::string proto_str;
{
base::ScopedBlockingCall scoped_blocking_call(
FROM_HERE, base::BlockingType::MAY_BLOCK);
base::FilePath path = temp_dir_.GetPath().AppendASCII(
AppListLaunchMetricsProvider::kStateProtoFilename);
CHECK(base::ReadFileToString(path, &proto_str));
}
auto proto = std::make_unique<AppListLaunchRecorderStateProto>();
CHECK(proto->ParseFromString(proto_str));
return proto->recurrence_ranker_user_id();
}
void WriteStateProto(const std::string& secret) {
AppListLaunchRecorderStateProto proto;
proto.set_recurrence_ranker_user_id(kUserId);
......@@ -160,6 +177,12 @@ class AppListLaunchMetricsProviderTest : public testing::Test {
Wait();
}
void DeleteStateProto() {
DeleteFile(temp_dir_.GetPath().AppendASCII(
AppListLaunchMetricsProvider::kStateProtoFilename),
false);
}
void AddLog(
const std::string& target,
const std::string& query,
......@@ -225,6 +248,17 @@ TEST_F(AppListLaunchMetricsProviderTest, SucceedsLoadingExistingSecret) {
ExpectNoErrors();
}
TEST_F(AppListLaunchMetricsProviderTest, DisableOnInvalidSecret) {
WriteStateProto("wrong length");
MakeProvider();
InitProvider();
ExpectDisabled();
histogram_tester_.ExpectUniqueSample("Apps.AppListLaunchRecorderError",
MetricsProviderError::kInvalidSecret, 1);
}
// Tests that a call to ProvideCurrentSessionData populates protos for each log,
// and that those protos contain the right values.
TEST_F(AppListLaunchMetricsProviderTest, CorrectHashedValues) {
......@@ -326,4 +360,24 @@ TEST_F(AppListLaunchMetricsProviderTest,
ExpectNoErrors();
}
// Without an existing saved state, instantiating a metrics provider should save
// an almost certainly unique user ID and secret. Test this by creating a few
// blank-slate metrics providers.
TEST_F(AppListLaunchMetricsProviderTest, UserIDsAndSecretsAreUnique) {
const int num_runs = 10;
std::set<uint64_t> user_ids;
std::set<std::string> secrets;
for (int i = 0; i < num_runs; ++i) {
DeleteStateProto();
MakeProvider();
InitProvider();
secrets.insert(ReadSecret());
user_ids.insert(ReadUserId());
}
EXPECT_EQ(static_cast<size_t>(num_runs), secrets.size());
EXPECT_EQ(static_cast<size_t>(num_runs), user_ids.size());
}
} // namespace app_list
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