chromium/components/autofill/core/browser/autocomplete_history_manager_unittest.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/autofill/core/browser/autocomplete_history_manager.h"

#include <string>
#include <vector>

#include "base/functional/callback_helpers.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/test_autofill_client.h"
#include "components/autofill/core/browser/test_autofill_clock.h"
#include "components/autofill/core/browser/webdata/autocomplete/autocomplete_entry.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/browser/webdata/mock_autofill_webdata_service.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/autofill/core/common/autofill_test_utils.h"
#include "components/autofill/core/common/form_data.h"
#include "components/prefs/testing_pref_service.h"
#include "components/version_info/version_info.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/rect.h"

namespace autofill {

namespace {

MockSuggestionsReturnedCallback;
CreateTestFormField;
_;
Eq;
Field;
Return;
UnorderedElementsAre;

}  // namespace

class AutocompleteHistoryManagerTest : public testing::Test {};

// Tests that credit card numbers are not sent to the WebDatabase to be saved.
TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) {}

// Contrary test to AutocompleteHistoryManagerTest.CreditCardNumberValue.  The
// value being submitted is not a valid credit card number, so it will be sent
// to the WebDatabase to be saved.
TEST_F(AutocompleteHistoryManagerTest, NonCreditCardNumberValue) {}

// Tests that SSNs are not sent to the WebDatabase to be saved.
TEST_F(AutocompleteHistoryManagerTest, SSNValue) {}

// Verify that autocomplete text is saved for search fields.
TEST_F(AutocompleteHistoryManagerTest, SearchField) {}

TEST_F(AutocompleteHistoryManagerTest, AutocompleteFeatureOff) {}

// Verify that we don't save invalid values in Autocomplete.
TEST_F(AutocompleteHistoryManagerTest, InvalidValues) {}

// Tests that text entered into fields specifying autocomplete="off" is not sent
// to the WebDatabase to be saved. Note this is also important as the mechanism
// for preventing CVCs from being saved.
// See BrowserAutofillManagerTest.DontSaveCvcInAutocompleteHistory
TEST_F(AutocompleteHistoryManagerTest, FieldWithAutocompleteOff) {}

// Shouldn't save entries when in Incognito mode.
TEST_F(AutocompleteHistoryManagerTest, Incognito) {}

#if !BUILDFLAG(IS_IOS)
// Tests that fields that are no longer focusable but still have user typed
// input are sent to the WebDatabase to be saved. Will not work for iOS
// because |properties_mask| is not set on iOS.
TEST_F(AutocompleteHistoryManagerTest, UserInputNotFocusable) {}
#endif

// Tests that text entered into presentation fields is not sent to the
// WebDatabase to be saved.
TEST_F(AutocompleteHistoryManagerTest, PresentationField) {}

// Tests that the Init function will trigger the Autocomplete Retention Policy
// cleanup if the flag is enabled, we're not in OTR and it hadn't run in the
// current major version.
TEST_F(AutocompleteHistoryManagerTest, Init_TriggersCleanup) {}

// Tests that the Init function will not trigger the Autocomplete Retention
// Policy when running in OTR.
TEST_F(AutocompleteHistoryManagerTest, Init_OTR_Not_TriggersCleanup) {}

// Tests that the Init function will not crash even if we don't have a DB.
TEST_F(AutocompleteHistoryManagerTest, Init_NullDB_NoCrash) {}

// Tests that the Init function will not trigger the Autocomplete Retention
// Policy when running in a major version that was already cleaned.
TEST_F(AutocompleteHistoryManagerTest,
       Init_SameMajorVersion_Not_TriggersCleanup) {}

// Make sure suggestions are not returned if the field should not autocomplete.
TEST_F(AutocompleteHistoryManagerTest,
       OnGetSingleFieldSuggestions_FieldShouldNotAutocomplete) {}

// Make sure our handler is called at the right time.
TEST_F(AutocompleteHistoryManagerTest,
       SuggestionsReturned_InvokeHandler_Empty) {}

// Tests that no suggestions are queried if the field name is filtered because
// it has a meaningless sub string that is allowed for sub string matches.
TEST_F(AutocompleteHistoryManagerTest,
       DoQuerySuggestionsForMeaninglessFieldNames_FilterSubStringName) {}

// Tests that no suggestions are queried if the field name is filtered because
// it has a meaningless name.
TEST_F(AutocompleteHistoryManagerTest,
       DoQuerySuggestionsForMeaninglessFieldNames_FilterName) {}

// Tests that the suggestions are queried if the field has meaningless substring
// which is not allowed for substring matches.
TEST_F(AutocompleteHistoryManagerTest,
       DoQuerySuggestionsForMeaninglessFieldNames_PassNameWithSubstring) {}
// Tests that the suggestions are queried if the field name is not filtered
// because the field's name is meaningful.
TEST_F(AutocompleteHistoryManagerTest,
       DoQuerySuggestionsForMeaninglessFieldNames_PassName) {}

// Tests that we are correctly returning a suggestion back to the handler.
TEST_F(AutocompleteHistoryManagerTest,
       SuggestionsReturned_InvokeHandler_SingleValue) {}

// Tests that we don't return any suggestion if we only have one suggestion that
// is case-sensitive equal to the given prefix.
TEST_F(AutocompleteHistoryManagerTest,
       SuggestionsReturned_InvokeHandler_SingleValue_EqualsPrefix) {}

// Tests the case sensitivity of the unique suggestion equal to the prefix
// filter.
TEST_F(AutocompleteHistoryManagerTest,
       SuggestionsReturned_InvokeHandler_SingleValue_EqualsPrefix_DiffCase) {}

TEST_F(AutocompleteHistoryManagerTest,
       OnSingleFieldSuggestionSelected_Found_ShouldLogDays) {}

TEST_F(AutocompleteHistoryManagerTest,
       SuggestionsReturned_InvokeHandler_TwoRequests_OneHandler_Cancels) {}

TEST_F(AutocompleteHistoryManagerTest,
       SuggestionsReturned_CancelPendingQueries) {}

// Verify that no autocomplete suggestion is returned for a textarea.
TEST_F(AutocompleteHistoryManagerTest, NoAutocompleteSuggestionsForTextarea) {}

TEST_F(AutocompleteHistoryManagerTest, DestructorCancelsRequests) {}

// Tests that a successful Autocomplete Retention Policy cleanup will
// overwrite the last cleaned major version preference.
TEST_F(AutocompleteHistoryManagerTest, EntriesCleanup_Success) {}

// Tests that AutocompleteHistoryManager::OnWebDataServiceRequestDone does not
// crash on empty results.
TEST_F(AutocompleteHistoryManagerTest, EmptyResult_DoesNotCrash) {}

}  // namespace autofill