aw_form_database_service_unittest.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "android_webview/browser/aw_form_database_service.h"
  5. #include <memory>
  6. #include <vector>
  7. #include "base/android/jni_android.h"
  8. #include "base/files/scoped_temp_dir.h"
  9. #include "base/memory/raw_ptr.h"
  10. #include "base/strings/utf_string_conversions.h"
  11. #include "base/test/task_environment.h"
  12. #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
  13. #include "components/autofill/core/common/form_field_data.h"
  14. #include "testing/gtest/include/gtest/gtest.h"
  15. using autofill::AutofillWebDataService;
  16. using autofill::FormFieldData;
  17. using base::android::AttachCurrentThread;
  18. using testing::Test;
  19. namespace android_webview {
  20. class AwFormDatabaseServiceTest : public Test {
  21. public:
  22. AwFormDatabaseServiceTest() {}
  23. protected:
  24. void SetUp() override {
  25. ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
  26. env_ = AttachCurrentThread();
  27. ASSERT_TRUE(env_);
  28. service_ = std::make_unique<AwFormDatabaseService>(temp_dir_.GetPath());
  29. }
  30. void TearDown() override {
  31. service_->Shutdown();
  32. task_environment_.RunUntilIdle();
  33. }
  34. // The path to the temporary directory used for the test operations.
  35. base::test::TaskEnvironment task_environment_;
  36. base::ScopedTempDir temp_dir_;
  37. raw_ptr<JNIEnv> env_;
  38. std::unique_ptr<AwFormDatabaseService> service_;
  39. };
  40. TEST_F(AwFormDatabaseServiceTest, HasAndClearFormData) {
  41. EXPECT_FALSE(service_->HasFormData());
  42. std::vector<FormFieldData> fields;
  43. FormFieldData field;
  44. field.name = u"foo";
  45. field.value = u"bar";
  46. fields.push_back(field);
  47. service_->get_autofill_webdata_service()->AddFormFields(fields);
  48. EXPECT_TRUE(service_->HasFormData());
  49. service_->ClearFormData();
  50. EXPECT_FALSE(service_->HasFormData());
  51. }
  52. } // namespace android_webview