| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "chrome/browser/webdata/web_intents_table.h" | 26 #include "chrome/browser/webdata/web_intents_table.h" |
| 27 #include "chrome/common/chrome_notification_types.h" | 27 #include "chrome/common/chrome_notification_types.h" |
| 28 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
| 29 #include "chrome/common/guid.h" | 29 #include "chrome/common/guid.h" |
| 30 #include "chrome/test/base/thread_observer_helper.h" | 30 #include "chrome/test/base/thread_observer_helper.h" |
| 31 #include "content/public/browser/notification_details.h" | 31 #include "content/public/browser/notification_details.h" |
| 32 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
| 33 #include "content/test/test_browser_thread.h" | 33 #include "content/test/test_browser_thread.h" |
| 34 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 36 #include "webkit/glue/form_field.h" | 36 #include "webkit/forms/form_field.h" |
| 37 | 37 |
| 38 using base::Time; | 38 using base::Time; |
| 39 using base::TimeDelta; | 39 using base::TimeDelta; |
| 40 using base::WaitableEvent; | 40 using base::WaitableEvent; |
| 41 using content::BrowserThread; | 41 using content::BrowserThread; |
| 42 using testing::_; | 42 using testing::_; |
| 43 using testing::DoDefault; | 43 using testing::DoDefault; |
| 44 using testing::ElementsAreArray; | 44 using testing::ElementsAreArray; |
| 45 using testing::Pointee; | 45 using testing::Pointee; |
| 46 using testing::Property; | 46 using testing::Property; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 122 } |
| 123 | 123 |
| 124 virtual void TearDown() { | 124 virtual void TearDown() { |
| 125 // Release this first so it can get destructed on the db thread. | 125 // Release this first so it can get destructed on the db thread. |
| 126 observer_helper_ = NULL; | 126 observer_helper_ = NULL; |
| 127 WebDataServiceTest::TearDown(); | 127 WebDataServiceTest::TearDown(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void AppendFormField(const string16& name, | 130 void AppendFormField(const string16& name, |
| 131 const string16& value, | 131 const string16& value, |
| 132 std::vector<webkit_glue::FormField>* form_fields) { | 132 std::vector<webkit::forms::FormField>* form_fields) { |
| 133 webkit_glue::FormField field; | 133 webkit::forms::FormField field; |
| 134 field.name = name; | 134 field.name = name; |
| 135 field.value = value; | 135 field.value = value; |
| 136 form_fields->push_back(field); | 136 form_fields->push_back(field); |
| 137 } | 137 } |
| 138 | 138 |
| 139 string16 name1_; | 139 string16 name1_; |
| 140 string16 name2_; | 140 string16 name2_; |
| 141 string16 value1_; | 141 string16 value1_; |
| 142 string16 value2_; | 142 string16 value2_; |
| 143 int unique_id1_, unique_id2_; | 143 int unique_id1_, unique_id2_; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 // This will verify that the correct notification is triggered, | 217 // This will verify that the correct notification is triggered, |
| 218 // passing the correct list of autofill keys in the details. | 218 // passing the correct list of autofill keys in the details. |
| 219 EXPECT_CALL( | 219 EXPECT_CALL( |
| 220 *observer_helper_->observer(), | 220 *observer_helper_->observer(), |
| 221 Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED), | 221 Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED), |
| 222 content::Source<WebDataService>(wds_.get()), | 222 content::Source<WebDataService>(wds_.get()), |
| 223 Property(&content::Details<const AutofillChangeList>::ptr, | 223 Property(&content::Details<const AutofillChangeList>::ptr, |
| 224 Pointee(ElementsAreArray(expected_changes))))). | 224 Pointee(ElementsAreArray(expected_changes))))). |
| 225 WillOnce(SignalEvent(&done_event_)); | 225 WillOnce(SignalEvent(&done_event_)); |
| 226 | 226 |
| 227 std::vector<webkit_glue::FormField> form_fields; | 227 std::vector<webkit::forms::FormField> form_fields; |
| 228 AppendFormField(name1_, value1_, &form_fields); | 228 AppendFormField(name1_, value1_, &form_fields); |
| 229 AppendFormField(name2_, value2_, &form_fields); | 229 AppendFormField(name2_, value2_, &form_fields); |
| 230 wds_->AddFormFields(form_fields); | 230 wds_->AddFormFields(form_fields); |
| 231 | 231 |
| 232 // The event will be signaled when the mock observer is notified. | 232 // The event will be signaled when the mock observer is notified. |
| 233 done_event_.TimedWait(test_timeout_); | 233 done_event_.TimedWait(test_timeout_); |
| 234 | 234 |
| 235 AutofillWebDataServiceConsumer<std::vector<string16> > consumer; | 235 AutofillWebDataServiceConsumer<std::vector<string16> > consumer; |
| 236 WebDataService::Handle handle; | 236 WebDataService::Handle handle; |
| 237 static const int limit = 10; | 237 static const int limit = 10; |
| 238 handle = wds_->GetFormValuesForElementName( | 238 handle = wds_->GetFormValuesForElementName( |
| 239 name1_, string16(), limit, &consumer); | 239 name1_, string16(), limit, &consumer); |
| 240 | 240 |
| 241 // The message loop will exit when the consumer is called. | 241 // The message loop will exit when the consumer is called. |
| 242 MessageLoop::current()->Run(); | 242 MessageLoop::current()->Run(); |
| 243 | 243 |
| 244 EXPECT_EQ(handle, consumer.handle()); | 244 EXPECT_EQ(handle, consumer.handle()); |
| 245 ASSERT_EQ(1U, consumer.result().size()); | 245 ASSERT_EQ(1U, consumer.result().size()); |
| 246 EXPECT_EQ(value1_, consumer.result()[0]); | 246 EXPECT_EQ(value1_, consumer.result()[0]); |
| 247 } | 247 } |
| 248 | 248 |
| 249 TEST_F(WebDataServiceAutofillTest, FormFillRemoveOne) { | 249 TEST_F(WebDataServiceAutofillTest, FormFillRemoveOne) { |
| 250 // First add some values to autofill. | 250 // First add some values to autofill. |
| 251 EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). | 251 EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). |
| 252 WillOnce(SignalEvent(&done_event_)); | 252 WillOnce(SignalEvent(&done_event_)); |
| 253 std::vector<webkit_glue::FormField> form_fields; | 253 std::vector<webkit::forms::FormField> form_fields; |
| 254 AppendFormField(name1_, value1_, &form_fields); | 254 AppendFormField(name1_, value1_, &form_fields); |
| 255 wds_->AddFormFields(form_fields); | 255 wds_->AddFormFields(form_fields); |
| 256 | 256 |
| 257 // The event will be signaled when the mock observer is notified. | 257 // The event will be signaled when the mock observer is notified. |
| 258 done_event_.TimedWait(test_timeout_); | 258 done_event_.TimedWait(test_timeout_); |
| 259 | 259 |
| 260 // This will verify that the correct notification is triggered, | 260 // This will verify that the correct notification is triggered, |
| 261 // passing the correct list of autofill keys in the details. | 261 // passing the correct list of autofill keys in the details. |
| 262 const AutofillChange expected_changes[] = { | 262 const AutofillChange expected_changes[] = { |
| 263 AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)) | 263 AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 274 // The event will be signaled when the mock observer is notified. | 274 // The event will be signaled when the mock observer is notified. |
| 275 done_event_.TimedWait(test_timeout_); | 275 done_event_.TimedWait(test_timeout_); |
| 276 } | 276 } |
| 277 | 277 |
| 278 TEST_F(WebDataServiceAutofillTest, FormFillRemoveMany) { | 278 TEST_F(WebDataServiceAutofillTest, FormFillRemoveMany) { |
| 279 TimeDelta one_day(TimeDelta::FromDays(1)); | 279 TimeDelta one_day(TimeDelta::FromDays(1)); |
| 280 Time t = Time::Now(); | 280 Time t = Time::Now(); |
| 281 | 281 |
| 282 EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). | 282 EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). |
| 283 WillOnce(SignalEvent(&done_event_)); | 283 WillOnce(SignalEvent(&done_event_)); |
| 284 std::vector<webkit_glue::FormField> form_fields; | 284 std::vector<webkit::forms::FormField> form_fields; |
| 285 AppendFormField(name1_, value1_, &form_fields); | 285 AppendFormField(name1_, value1_, &form_fields); |
| 286 AppendFormField(name2_, value2_, &form_fields); | 286 AppendFormField(name2_, value2_, &form_fields); |
| 287 wds_->AddFormFields(form_fields); | 287 wds_->AddFormFields(form_fields); |
| 288 | 288 |
| 289 // The event will be signaled when the mock observer is notified. | 289 // The event will be signaled when the mock observer is notified. |
| 290 done_event_.TimedWait(test_timeout_); | 290 done_event_.TimedWait(test_timeout_); |
| 291 | 291 |
| 292 // This will verify that the correct notification is triggered, | 292 // This will verify that the correct notification is triggered, |
| 293 // passing the correct list of autofill keys in the details. | 293 // passing the correct list of autofill keys in the details. |
| 294 const AutofillChange expected_changes[] = { | 294 const AutofillChange expected_changes[] = { |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 } | 726 } |
| 727 | 727 |
| 728 TEST_F(WebDataServiceTest, DidDefaultSearchProviderChangeOnNewProfile) { | 728 TEST_F(WebDataServiceTest, DidDefaultSearchProviderChangeOnNewProfile) { |
| 729 KeywordsConsumer consumer; | 729 KeywordsConsumer consumer; |
| 730 wds_->GetKeywords(&consumer); | 730 wds_->GetKeywords(&consumer); |
| 731 KeywordsConsumer::WaitUntilCalled(); | 731 KeywordsConsumer::WaitUntilCalled(); |
| 732 ASSERT_TRUE(consumer.load_succeeded); | 732 ASSERT_TRUE(consumer.load_succeeded); |
| 733 EXPECT_FALSE(consumer.keywords_result.did_default_search_provider_change); | 733 EXPECT_FALSE(consumer.keywords_result.did_default_search_provider_change); |
| 734 EXPECT_EQ(0, consumer.keywords_result.default_search_provider_id_backup); | 734 EXPECT_EQ(0, consumer.keywords_result.default_search_provider_id_backup); |
| 735 } | 735 } |
| OLD | NEW |