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

#import "components/autofill/ios/browser/form_suggestion_provider_query.h"

#import "testing/gtest/include/gtest/gtest.h"
#import "testing/platform_test.h"

using autofill::FieldRendererId;
using autofill::FormRendererId;

namespace {
NSString* const kTestFormName = @"login_form";
FormRendererId const kTestFormRendererID = FormRendererId(0);
NSString* const kTestUsernameFieldIdentifier = @"username";
NSString* const kTestPasswordFieldIdentifier = @"pw";
FieldRendererId const kTestFieldRendererID = FieldRendererId(1);
NSString* const kTestTypedValue = @"smth";
NSString* const kTestFrameID = @"someframe";
}  // namespace

using FormSuggestionProviderQueryTest = PlatformTest;

// Tests that a query caused by focusing an obfuscated field is processed
// correctly.
TEST_F(FormSuggestionProviderQueryTest, PasswordFieldFocused) {
  FormSuggestionProviderQuery* formQuery = [[FormSuggestionProviderQuery alloc]
      initWithFormName:kTestFormName
        formRendererID:kTestFormRendererID
       fieldIdentifier:kTestPasswordFieldIdentifier
       fieldRendererID:kTestFieldRendererID
             fieldType:FieldType::kObfuscated
                  type:ActivityType::kFocus
            typedValue:kTestTypedValue
               frameID:kTestFrameID
          onlyPassword:NO];

  EXPECT_TRUE([formQuery hasFocusType]);
}

// Tests that a query caused by input in a non-obfuscated field id processed
// correctly.
TEST_F(FormSuggestionProviderQueryTest, InputInTextField) {
  FormSuggestionProviderQuery* formQuery = [[FormSuggestionProviderQuery alloc]
      initWithFormName:kTestFormName
        formRendererID:kTestFormRendererID
       fieldIdentifier:kTestUsernameFieldIdentifier
       fieldRendererID:kTestFieldRendererID
             fieldType:FieldType::kText
                  type:ActivityType::kInput
            typedValue:kTestTypedValue
               frameID:kTestFrameID
          onlyPassword:NO];

  EXPECT_FALSE([formQuery hasFocusType]);
}
