OLD | NEW |
(Empty) | |
| 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 |
| 5 #include <vector> |
| 6 |
| 7 #include "android_webview/browser/aw_form_database_service.h" |
| 8 #include "base/android/jni_android.h" |
| 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop.h" |
| 12 #include "base/utf_string_conversions.h" |
| 13 #include "components/autofill/browser/webdata/autofill_webdata_service.h" |
| 14 #include "components/autofill/common/form_field_data.h" |
| 15 #include "content/public/test/test_browser_thread.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/base/l10n/l10n_util_android.h" |
| 18 |
| 19 using autofill::AutofillWebDataService; |
| 20 using autofill::FormFieldData; |
| 21 using base::android::AttachCurrentThread; |
| 22 using content::BrowserThread; |
| 23 using testing::Test; |
| 24 |
| 25 namespace android_webview { |
| 26 |
| 27 class AwFormDatabaseServiceTest : public Test { |
| 28 public: |
| 29 AwFormDatabaseServiceTest() |
| 30 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 31 db_thread_(BrowserThread::DB) { |
| 32 db_thread_.Start(); |
| 33 } |
| 34 |
| 35 protected: |
| 36 virtual void SetUp() { |
| 37 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 38 env_ = AttachCurrentThread(); |
| 39 ASSERT_TRUE(env_ != NULL); |
| 40 ASSERT_TRUE(l10n_util::RegisterLocalizationUtil(env_)); |
| 41 |
| 42 service_.reset(new AwFormDatabaseService(temp_dir_.path())); |
| 43 } |
| 44 |
| 45 virtual void TearDown() { |
| 46 service_->Shutdown(); |
| 47 } |
| 48 |
| 49 // The path to the temporary directory used for the test operations. |
| 50 base::ScopedTempDir temp_dir_; |
| 51 // A message loop for UI thread. |
| 52 MessageLoop message_loop_; |
| 53 content::TestBrowserThread ui_thread_; |
| 54 content::TestBrowserThread db_thread_; |
| 55 JNIEnv* env_; |
| 56 |
| 57 scoped_ptr<AwFormDatabaseService> service_; |
| 58 }; |
| 59 |
| 60 TEST_F(AwFormDatabaseServiceTest, HasAndClearFormElements) { |
| 61 EXPECT_FALSE(service_->HasFormElements()); |
| 62 std::vector<FormFieldData> fields; |
| 63 FormFieldData field; |
| 64 field.name = ASCIIToUTF16("foo"); |
| 65 field.value = ASCIIToUTF16("bar"); |
| 66 fields.push_back(field); |
| 67 service_->get_autofill_webdata_service()->AddFormFields(fields); |
| 68 EXPECT_TRUE(service_->HasFormElements()); |
| 69 service_->ClearFormElements(); |
| 70 EXPECT_FALSE(service_->HasFormElements()); |
| 71 } |
| 72 |
| 73 } // namespace android_webview |
OLD | NEW |