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
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ash/input_method/editor_consent_store.h"
#include <optional>
#include "ash/constants/ash_pref_names.h"
#include "chrome/browser/ash/input_method/editor_consent_enums.h"
#include "chrome/browser/ash/input_method/editor_context.h"
#include "chrome/browser/ash/input_method/editor_geolocation_mock_provider.h"
#include "chrome/browser/ash/input_method/editor_metrics_recorder.h"
#include "chrome/test/base/testing_profile.h"
#include "chromeos/ash/components/editor_menu/public/cpp/editor_consent_status.h"
#include "content/public/test/browser_task_environment.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace ash::input_method {
namespace {
constexpr std::string_view kAllowedCountryCode = "au";
class FakeContextObserver : public EditorContext::Observer {
public:
FakeContextObserver() = default;
~FakeContextObserver() override = default;
// EditorContext::Observer overrides
void OnContextUpdated() override {}
void OnImeChange(std::string_view engine_id) override {}
};
class FakeSystem : public EditorContext::System {
public:
FakeSystem() = default;
~FakeSystem() override = default;
// EditorContext::System overrides
std::optional<ukm::SourceId> GetUkmSourceId() override {
return std::nullopt;
}
};
class EditorConsentStoreTest : public ::testing::Test {
public:
EditorConsentStoreTest() = default;
~EditorConsentStoreTest() override = default;
private:
content::BrowserTaskEnvironment task_environment_;
};
TEST_F(EditorConsentStoreTest,
ReceivingDeclineResponseWillLeadToConsentDecline) {
TestingProfile profile_;
FakeSystem system;
FakeContextObserver observer;
EditorGeolocationMockProvider geolocation_provider(kAllowedCountryCode);
EditorContext context(&observer, &system, &geolocation_provider);
EditorMetricsRecorder metrics_recorder(&context,
EditorOpportunityMode::kInvalidInput);
EditorConsentStore store(profile_.GetPrefs(), &metrics_recorder);
store.ProcessConsentAction(ConsentAction::kDecline);
EXPECT_EQ(store.GetConsentStatus(),
chromeos::editor_menu::EditorConsentStatus::kDeclined);
}
TEST_F(EditorConsentStoreTest,
ReceivingApprovalResponseWillLeadToConsentApproval) {
TestingProfile profile_;
FakeSystem system;
FakeContextObserver observer;
EditorGeolocationMockProvider geolocation_provider(kAllowedCountryCode);
EditorContext context(&observer, &system, &geolocation_provider);
EditorMetricsRecorder metrics_recorder(&context,
EditorOpportunityMode::kInvalidInput);
EditorConsentStore store(profile_.GetPrefs(), &metrics_recorder);
store.ProcessConsentAction(ConsentAction::kApprove);
EXPECT_EQ(store.GetConsentStatus(),
chromeos::editor_menu::EditorConsentStatus::kApproved);
}
TEST_F(EditorConsentStoreTest,
SwitchingOnSettingToggleWillResetConsentWhichWasPreviouslyDeclined) {
TestingProfile profile_;
FakeSystem system;
FakeContextObserver observer;
EditorGeolocationMockProvider geolocation_provider(kAllowedCountryCode);
EditorContext context(&observer, &system, &geolocation_provider);
EditorMetricsRecorder metrics_recorder(&context,
EditorOpportunityMode::kInvalidInput);
EditorConsentStore store(profile_.GetPrefs(), &metrics_recorder);
store.ProcessConsentAction(ConsentAction::kDecline);
// Simulate a user action to switch on the orca toggle.
profile_.GetPrefs()->SetBoolean(prefs::kOrcaEnabled, true);
EXPECT_EQ(store.GetConsentStatus(),
chromeos::editor_menu::EditorConsentStatus::kUnset);
}
TEST_F(EditorConsentStoreTest,
DecliningThePromoCardWillSwitchOffFeatureToggle) {
TestingProfile profile_;
FakeSystem system;
FakeContextObserver observer;
EditorGeolocationMockProvider geolocation_provider(kAllowedCountryCode);
EditorContext context(&observer, &system, &geolocation_provider);
EditorMetricsRecorder metrics_recorder(&context,
EditorOpportunityMode::kInvalidInput);
EditorConsentStore store(profile_.GetPrefs(), &metrics_recorder);
// Switch on the orca toggle in the setting page.
profile_.GetPrefs()->SetBoolean(prefs::kOrcaEnabled, true);
// Simulate a user action to explicitly decline the promo card.
store.ProcessPromoCardAction(PromoCardAction::kDecline);
EXPECT_FALSE(profile_.GetPrefs()->GetBoolean(prefs::kOrcaEnabled));
}
} // namespace
} // namespace ash::input_method
|