Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1449)

Side by Side Diff: chrome/browser/autofill/autofill_manager_unittest.cc

Issue 8353025: External autofill delegates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Carnitasify Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <vector> 5 #include <vector>
6 6
7 #include "base/command_line.h"
7 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
9 #include "base/string16.h" 10 #include "base/string16.h"
10 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
11 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
12 #include "base/time.h" 13 #include "base/time.h"
13 #include "base/tuple.h" 14 #include "base/tuple.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/autocomplete_history_manager.h" 16 #include "chrome/browser/autocomplete_history_manager.h"
16 #include "chrome/browser/autofill/autofill_common_test.h" 17 #include "chrome/browser/autofill/autofill_common_test.h"
18 #include "chrome/browser/autofill/autofill_external_delegate.h"
17 #include "chrome/browser/autofill/autofill_manager.h" 19 #include "chrome/browser/autofill/autofill_manager.h"
18 #include "chrome/browser/autofill/autofill_profile.h" 20 #include "chrome/browser/autofill/autofill_profile.h"
19 #include "chrome/browser/autofill/credit_card.h" 21 #include "chrome/browser/autofill/credit_card.h"
20 #include "chrome/browser/autofill/personal_data_manager.h" 22 #include "chrome/browser/autofill/personal_data_manager.h"
21 #include "chrome/browser/autofill/personal_data_manager_factory.h" 23 #include "chrome/browser/autofill/personal_data_manager_factory.h"
22 #include "chrome/browser/prefs/pref_service.h" 24 #include "chrome/browser/prefs/pref_service.h"
23 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/ui/browser.h" 26 #include "chrome/browser/ui/browser.h"
25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
26 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" 28 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
27 #include "chrome/common/autofill_messages.h" 29 #include "chrome/common/autofill_messages.h"
30 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
29 #include "chrome/test/base/testing_profile.h" 32 #include "chrome/test/base/testing_profile.h"
30 #include "content/browser/browser_thread.h" 33 #include "content/browser/browser_thread.h"
31 #include "content/browser/tab_contents/test_tab_contents.h" 34 #include "content/browser/tab_contents/test_tab_contents.h"
32 #include "googleurl/src/gurl.h" 35 #include "googleurl/src/gurl.h"
33 #include "grit/generated_resources.h" 36 #include "grit/generated_resources.h"
34 #include "ipc/ipc_test_sink.h" 37 #include "ipc/ipc_test_sink.h"
35 #include "testing/gmock/include/gmock/gmock.h" 38 #include "testing/gmock/include/gmock/gmock.h"
36 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
37 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
38 #include "webkit/glue/form_data.h" 41 #include "webkit/glue/form_data.h"
39 #include "webkit/glue/form_field.h" 42 #include "webkit/glue/form_field.h"
40 43
44 using testing::_;
41 using webkit_glue::FormData; 45 using webkit_glue::FormData;
42 using webkit_glue::FormField; 46 using webkit_glue::FormField;
43 47
44 namespace { 48 namespace {
45 49
46 // The page ID sent to the AutofillManager from the RenderView, used to send 50 // The page ID sent to the AutofillManager from the RenderView, used to send
47 // an IPC message back to the renderer. 51 // an IPC message back to the renderer.
48 const int kDefaultPageID = 137; 52 const int kDefaultPageID = 137;
49 53
50 typedef Tuple5<int, 54 typedef Tuple5<int,
(...skipping 2776 matching lines...) Expand 10 before | Expand all | Expand 10 after
2827 const FieldTypeSet& possible_types1 = 2831 const FieldTypeSet& possible_types1 =
2828 form_structure.field(1)->possible_types(); 2832 form_structure.field(1)->possible_types();
2829 EXPECT_EQ(1U, possible_types1.size()); 2833 EXPECT_EQ(1U, possible_types1.size());
2830 EXPECT_TRUE(possible_types1.find(NAME_FIRST) != possible_types1.end()); 2834 EXPECT_TRUE(possible_types1.find(NAME_FIRST) != possible_types1.end());
2831 const FieldTypeSet& possible_types2 = 2835 const FieldTypeSet& possible_types2 =
2832 form_structure.field(2)->possible_types(); 2836 form_structure.field(2)->possible_types();
2833 EXPECT_EQ(1U, possible_types2.size()); 2837 EXPECT_EQ(1U, possible_types2.size());
2834 EXPECT_TRUE(possible_types2.find(UNKNOWN_TYPE) != 2838 EXPECT_TRUE(possible_types2.find(UNKNOWN_TYPE) !=
2835 possible_types2.end()); 2839 possible_types2.end());
2836 } 2840 }
2841
2842 namespace {
2843
2844 class MockAutofillExternalDelegate : public AutofillExternalDelegate {
2845 public:
2846 MockAutofillExternalDelegate() {}
2847 virtual ~MockAutofillExternalDelegate() {}
2848
2849 MOCK_METHOD3(OnQuery, void(int query_id,
2850 const webkit_glue::FormData& form,
2851 const webkit_glue::FormField& field));
2852 virtual void OnSuggestionsReturned(
2853 int query_id,
2854 const std::vector<string16>& autofill_values,
2855 const std::vector<string16>& autofill_labels,
2856 const std::vector<string16>& autofill_icons,
2857 const std::vector<int>& autofill_unique_ids) {}
2858
2859 private:
2860 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate);
2861 };
2862
2863 } // namespace
2864
2865 // Test our external delegate is called at the right time.
2866 TEST_F(AutofillManagerTest, TestExternalDelegate) {
2867 MockAutofillExternalDelegate external_delegate;
2868 EXPECT_CALL(external_delegate, OnQuery(_, _, _));
Ilya Sherman 2011/10/26 11:09:58 nit: How about moving this line to immediately pre
2869 autofill_manager_->SetExternalDelegate(&external_delegate);
2870
2871 FormData form;
2872 CreateTestAddressFormData(&form);
2873 std::vector<FormData> forms(1, form);
2874 FormsSeen(forms);
2875 const FormField& field = form.fields[0];
2876 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery()
2877
2878 autofill_manager_->SetExternalDelegate(NULL);
Ilya Sherman 2011/10/26 11:09:58 nit: Is this line really necessary for the test?
John Grabowski 2011/10/27 03:05:59 If not, autofill_manager_ will have a pointer to a
Ilya Sherman 2011/10/27 11:01:55 Sure, but it's not like NULL is especially much so
2879 }
2880
2881 #if defined(OS_ANDROID)
2882 // Only OS_ANDROID defines an external delegate, but prerequisites for
2883 // landing autofill_external_delegate_android.cc in the Chromium tree
2884 // have not themselves landed.
2885
2886 // Turn on the external delegate. Recreate a TabContents. Make sure
2887 // an external delegate was set in the proper structures.
2888 TEST_F(AutofillManagerTest, TestTabContents) {
Ilya Sherman 2011/10/26 11:09:58 nit: How about naming this something a bit more ex
2889 CommandLine::ForCurrentProcess()->AppendSwitch(
2890 switches::kExternalAutofillPopup);
2891
2892 // Setting the contents creates a new TabContentsWrapper.
2893 TestTabContents* contents = CreateTestTabContents();
2894 SetContents(contents);
2895
2896 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager();
2897 EXPECT_TRUE(autofill_manager->external_delegate());
Ilya Sherman 2011/10/26 11:09:58 Won't this EXPECT fail on OS_ANDROID until autofil
2898
2899 AutocompleteHistoryManager* autocomplete_history_manager =
2900 contents_wrapper()->autocomplete_history_manager();
2901 EXPECT_TRUE(autocomplete_history_manager->external_delegate());
2902 }
2903
2904 #endif // OS_ANDROID
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698