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

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

Issue 9235072: Adding Mouse Support for new GTK Autofill (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Responding to comments Created 8 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/autofill/autofill_popup_view.h" 5 #include "chrome/browser/autofill/autofill_popup_view.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/autofill/autofill_external_delegate_test.h"
8 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
9 #include "chrome/test/base/ui_test_utils.h" 10 #include "chrome/test/base/ui_test_utils.h"
10 #include "content/public/browser/navigation_controller.h" 11 #include "content/public/browser/navigation_controller.h"
11 #include "content/public/browser/notification_service.h" 12 #include "content/public/browser/notification_service.h"
12 #include "content/public/browser/notification_types.h" 13 #include "content/public/browser/notification_types.h"
13 #include "content/public/browser/page_navigator.h" 14 #include "content/public/browser/page_navigator.h"
14 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/url_constants.h" 16 #include "content/public/common/url_constants.h"
16 #include "content/test/browser_test.h" 17 #include "content/test/browser_test.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 using ::testing::AtLeast; 21 using ::testing::AtLeast;
22 using testing::_;
23
24 namespace {
25
26 class MockAutofillExternalDelegate : public AutofillExternalDelegateTest {
27 public:
28 MockAutofillExternalDelegate(
29 TabContentsWrapper* wrapper, AutofillManager* autofill_manager) :
30 AutofillExternalDelegateTest(wrapper, autofill_manager) {}
31 ~MockAutofillExternalDelegate() {}
32
33 virtual void SelectAutofillSuggestionAtIndex(int unique_id, int list_index)
34 OVERRIDE {}
35 };
21 36
22 class TestAutofillPopupView : public AutofillPopupView { 37 class TestAutofillPopupView : public AutofillPopupView {
23 public: 38 public:
24 explicit TestAutofillPopupView(content::WebContents* web_contents) 39 explicit TestAutofillPopupView(
25 : AutofillPopupView(web_contents) {} 40 content::WebContents* web_contents,
41 AutofillExternalDelegate* autofill_external_delegate)
42 : AutofillPopupView(web_contents, autofill_external_delegate) {}
26 virtual ~TestAutofillPopupView() {} 43 virtual ~TestAutofillPopupView() {}
27 44
28 MOCK_METHOD0(Hide, void()); 45 MOCK_METHOD0(Hide, void());
29 46
47 MOCK_METHOD1(InvalidateRow, void(size_t));
48
49 void SetSelectedLine(size_t selected_line) {
50 AutofillPopupView::SetSelectedLine(selected_line);
51 }
52
53 protected:
30 virtual void ShowInternal() OVERRIDE {} 54 virtual void ShowInternal() OVERRIDE {}
55
56 virtual void HideInternal() OVERRIDE {}
31 }; 57 };
32 58
59 } // namespace
60
33 class AutofillPopupViewBrowserTest : public InProcessBrowserTest { 61 class AutofillPopupViewBrowserTest : public InProcessBrowserTest {
34 public: 62 public:
35 AutofillPopupViewBrowserTest() {} 63 AutofillPopupViewBrowserTest() {}
36 virtual ~AutofillPopupViewBrowserTest() {} 64 virtual ~AutofillPopupViewBrowserTest() {}
37 65
66 virtual void SetUpOnMainThread() OVERRIDE {
67 web_contents_ = browser()->GetSelectedWebContents();
68 ASSERT_TRUE(web_contents_ != NULL);
69
70 autofill_external_delegate_.reset(
71 new MockAutofillExternalDelegate(NULL, NULL));
72
73 autofill_popup_view_.reset(new TestAutofillPopupView(
74 web_contents_,
75 autofill_external_delegate_.get()));
76 }
77
38 protected: 78 protected:
79 content::WebContents* web_contents_;
39 scoped_ptr<TestAutofillPopupView> autofill_popup_view_; 80 scoped_ptr<TestAutofillPopupView> autofill_popup_view_;
81 // Make this just a member
Ilya Sherman 2012/02/07 23:35:55 nit: Is this meant as a TODO?
csharp 2012/02/08 16:11:16 I had make this change before uploading, I must ha
82 scoped_ptr<AutofillExternalDelegateTest> autofill_external_delegate_;
40 }; 83 };
41 84
42 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, SwitchTabAndHideAutofillPopup) { 85 IN_PROC_BROWSER_TEST_F(AutofillPopupViewBrowserTest,
43 content::WebContents* web_contents = browser()->GetSelectedWebContents(); 86 SwitchTabAndHideAutofillPopup) {
44 TestAutofillPopupView autofill_popup_view(web_contents); 87 EXPECT_CALL(*autofill_popup_view_, Hide()).Times(AtLeast(1));
45
46 // Using AtLeast here because current Hide is called once on Linux and Mac,
47 // and three times on Windows and ChromeOS. http://crbug.com/109269
48 EXPECT_CALL(autofill_popup_view, Hide()).Times(AtLeast(1));
49 88
50 ui_test_utils::WindowedNotificationObserver observer( 89 ui_test_utils::WindowedNotificationObserver observer(
51 content::NOTIFICATION_WEB_CONTENTS_HIDDEN, 90 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
52 content::Source<content::WebContents>(web_contents)); 91 content::Source<content::WebContents>(web_contents_));
53 browser()->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL), 92 browser()->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL),
54 content::PAGE_TRANSITION_START_PAGE); 93 content::PAGE_TRANSITION_START_PAGE);
55 observer.Wait(); 94 observer.Wait();
56 95
57 // The mock verifies that the call was made. 96 // The mock verifies that the call was made.
58 } 97 }
59 98
60 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, 99 IN_PROC_BROWSER_TEST_F(AutofillPopupViewBrowserTest,
61 TestPageNavigationHidingAutofillPopup) { 100 TestPageNavigationHidingAutofillPopup) {
62 content::WebContents* web_contents = browser()->GetSelectedWebContents(); 101 EXPECT_CALL(*autofill_popup_view_, Hide()).Times(AtLeast(1));
63 TestAutofillPopupView autofill_popup_view(web_contents);
64 EXPECT_CALL(autofill_popup_view, Hide());
65 102
66 ui_test_utils::WindowedNotificationObserver observer( 103 ui_test_utils::WindowedNotificationObserver observer(
67 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 104 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
68 content::Source<content::NavigationController>( 105 content::Source<content::NavigationController>(
69 &(web_contents->GetController()))); 106 &(web_contents_->GetController())));
70 browser()->OpenURL(content::OpenURLParams( 107 browser()->OpenURL(content::OpenURLParams(
71 GURL(chrome::kAboutBlankURL), content::Referrer(), 108 GURL(chrome::kAboutBlankURL), content::Referrer(),
72 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 109 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
73 browser()->OpenURL(content::OpenURLParams( 110 browser()->OpenURL(content::OpenURLParams(
74 GURL(chrome::kAboutCrashURL), content::Referrer(), 111 GURL(chrome::kAboutCrashURL), content::Referrer(),
75 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 112 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
76 observer.Wait(); 113 observer.Wait();
77 114
78 // The mock verifies that the call was made. 115 // The mock verifies that the call was made.
79 } 116 }
117
118 IN_PROC_BROWSER_TEST_F(AutofillPopupViewBrowserTest,
119 SetSelectedAutofillLineAndCallInvalidate) {
120 std::vector<string16> autofill_values;
121 autofill_values.push_back(string16());
122 std::vector<int> autofill_ids;
123 autofill_ids.push_back(0);
124 autofill_popup_view_->Show(
125 autofill_values, autofill_values, autofill_values, autofill_ids, 0);
126
127 // Make sure that when a new line is selected, it is invalidated so it can
128 // be updated to show it is selected.
129 int selected_line = 0;
130 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(selected_line));
131 autofill_popup_view_->SetSelectedLine(selected_line);
132
133 // Ensure that the row isn't invalidated if it didn't change.
134 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(selected_line)).Times(0);
135 autofill_popup_view_->SetSelectedLine(selected_line);
136
137 // Change back to no selection.
138 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(selected_line));
139 autofill_popup_view_->SetSelectedLine(-1);
140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698