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

Side by Side Diff: components/autofill/content/browser/content_autofill_driver_unittest.cc

Issue 306053008: Rename AutofillManagerDelegate to AutofillClient. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "components/autofill/content/browser/content_autofill_driver.h" 11 #include "components/autofill/content/browser/content_autofill_driver.h"
12 #include "components/autofill/content/common/autofill_messages.h" 12 #include "components/autofill/content/common/autofill_messages.h"
13 #include "components/autofill/core/browser/autofill_external_delegate.h" 13 #include "components/autofill/core/browser/autofill_external_delegate.h"
14 #include "components/autofill/core/browser/autofill_manager.h" 14 #include "components/autofill/core/browser/autofill_manager.h"
15 #include "components/autofill/core/browser/autofill_test_utils.h" 15 #include "components/autofill/core/browser/autofill_test_utils.h"
16 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" 16 #include "components/autofill/core/browser/test_autofill_client.h"
17 #include "components/autofill/core/common/autofill_switches.h" 17 #include "components/autofill/core/common/autofill_switches.h"
18 #include "components/autofill/core/common/form_data_predictions.h" 18 #include "components/autofill/core/common/form_data_predictions.h"
19 #include "content/public/browser/browser_context.h" 19 #include "content/public/browser/browser_context.h"
20 #include "content/public/browser/navigation_details.h" 20 #include "content/public/browser/navigation_details.h"
21 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "content/public/common/frame_navigate_params.h" 22 #include "content/public/common/frame_navigate_params.h"
23 #include "content/public/test/mock_render_process_host.h" 23 #include "content/public/test/mock_render_process_host.h"
24 #include "content/public/test/test_renderer_host.h" 24 #include "content/public/test/test_renderer_host.h"
25 #include "ipc/ipc_test_sink.h" 25 #include "ipc/ipc_test_sink.h"
26 #include "testing/gmock/include/gmock/gmock.h" 26 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 28
29 namespace autofill { 29 namespace autofill {
30 30
31 namespace { 31 namespace {
32 32
33 const std::string kAppLocale = "en-US"; 33 const std::string kAppLocale = "en-US";
34 const AutofillManager::AutofillDownloadManagerState kDownloadState = 34 const AutofillManager::AutofillDownloadManagerState kDownloadState =
35 AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER; 35 AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER;
36 36
37 } // namespace 37 } // namespace
38 38
39 class MockAutofillManager : public AutofillManager { 39 class MockAutofillManager : public AutofillManager {
40 public: 40 public:
41 MockAutofillManager(AutofillDriver* driver, AutofillManagerDelegate* delegate) 41 MockAutofillManager(AutofillDriver* driver, AutofillClient* client)
42 : AutofillManager(driver, delegate, kAppLocale, kDownloadState) {} 42 : AutofillManager(driver, client, kAppLocale, kDownloadState) {}
43 virtual ~MockAutofillManager() {} 43 virtual ~MockAutofillManager() {}
44 44
45 MOCK_METHOD0(Reset, void()); 45 MOCK_METHOD0(Reset, void());
46 }; 46 };
47 47
48 class TestContentAutofillDriver : public ContentAutofillDriver { 48 class TestContentAutofillDriver : public ContentAutofillDriver {
49 public: 49 public:
50 TestContentAutofillDriver(content::WebContents* contents, 50 TestContentAutofillDriver(content::WebContents* contents,
51 AutofillManagerDelegate* delegate) 51 AutofillClient* client)
52 : ContentAutofillDriver(contents, delegate, kAppLocale, kDownloadState) { 52 : ContentAutofillDriver(contents, client, kAppLocale, kDownloadState) {
53 scoped_ptr<AutofillManager> autofill_manager( 53 scoped_ptr<AutofillManager> autofill_manager(
54 new MockAutofillManager(this, delegate)); 54 new MockAutofillManager(this, client));
55 SetAutofillManager(autofill_manager.Pass()); 55 SetAutofillManager(autofill_manager.Pass());
56 } 56 }
57 virtual ~TestContentAutofillDriver() {} 57 virtual ~TestContentAutofillDriver() {}
58 58
59 virtual MockAutofillManager* mock_autofill_manager() { 59 virtual MockAutofillManager* mock_autofill_manager() {
60 return static_cast<MockAutofillManager*>(autofill_manager()); 60 return static_cast<MockAutofillManager*>(autofill_manager());
61 } 61 }
62 62
63 using ContentAutofillDriver::DidNavigateMainFrame; 63 using ContentAutofillDriver::DidNavigateMainFrame;
64 }; 64 };
65 65
66 class ContentAutofillDriverTest : public content::RenderViewHostTestHarness { 66 class ContentAutofillDriverTest : public content::RenderViewHostTestHarness {
67 public: 67 public:
68 virtual void SetUp() OVERRIDE { 68 virtual void SetUp() OVERRIDE {
69 content::RenderViewHostTestHarness::SetUp(); 69 content::RenderViewHostTestHarness::SetUp();
70 70
71 test_manager_delegate_.reset(new TestAutofillManagerDelegate()); 71 test_autofill_client_.reset(new TestAutofillClient());
72 driver_.reset(new TestContentAutofillDriver(web_contents(), 72 driver_.reset(new TestContentAutofillDriver(web_contents(),
73 test_manager_delegate_.get())); 73 test_autofill_client_.get()));
74 } 74 }
75 75
76 virtual void TearDown() OVERRIDE { 76 virtual void TearDown() OVERRIDE {
77 // Reset the driver now to cause all pref observers to be removed and avoid 77 // Reset the driver now to cause all pref observers to be removed and avoid
78 // crashes that otherwise occur in the destructor. 78 // crashes that otherwise occur in the destructor.
79 driver_.reset(); 79 driver_.reset();
80 content::RenderViewHostTestHarness::TearDown(); 80 content::RenderViewHostTestHarness::TearDown();
81 } 81 }
82 82
83 protected: 83 protected:
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // of sent messages and returns true. 184 // of sent messages and returns true.
185 bool HasMessageMatchingID(uint32 messageID) { 185 bool HasMessageMatchingID(uint32 messageID) {
186 const IPC::Message* message = 186 const IPC::Message* message =
187 process()->sink().GetFirstMessageMatching(messageID); 187 process()->sink().GetFirstMessageMatching(messageID);
188 if (!message) 188 if (!message)
189 return false; 189 return false;
190 process()->sink().ClearMessages(); 190 process()->sink().ClearMessages();
191 return true; 191 return true;
192 } 192 }
193 193
194 scoped_ptr<TestAutofillManagerDelegate> test_manager_delegate_; 194 scoped_ptr<TestAutofillClient> test_autofill_client_;
195 scoped_ptr<TestContentAutofillDriver> driver_; 195 scoped_ptr<TestContentAutofillDriver> driver_;
196 }; 196 };
197 197
198 TEST_F(ContentAutofillDriverTest, GetURLRequestContext) { 198 TEST_F(ContentAutofillDriverTest, GetURLRequestContext) {
199 net::URLRequestContextGetter* request_context = 199 net::URLRequestContextGetter* request_context =
200 driver_->GetURLRequestContext(); 200 driver_->GetURLRequestContext();
201 net::URLRequestContextGetter* expected_request_context = 201 net::URLRequestContextGetter* expected_request_context =
202 web_contents()->GetBrowserContext()->GetRequestContext(); 202 web_contents()->GetBrowserContext()->GetRequestContext();
203 EXPECT_EQ(request_context, expected_request_context); 203 EXPECT_EQ(request_context, expected_request_context);
204 } 204 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 base::string16 input_value(base::ASCIIToUTF16("barqux")); 314 base::string16 input_value(base::ASCIIToUTF16("barqux"));
315 base::string16 output_value; 315 base::string16 output_value;
316 driver_->RendererShouldPreviewFieldWithValue(input_value); 316 driver_->RendererShouldPreviewFieldWithValue(input_value);
317 EXPECT_TRUE(GetString16FromMessageWithID( 317 EXPECT_TRUE(GetString16FromMessageWithID(
318 AutofillMsg_PreviewFieldWithValue::ID, 318 AutofillMsg_PreviewFieldWithValue::ID,
319 &output_value)); 319 &output_value));
320 EXPECT_EQ(input_value, output_value); 320 EXPECT_EQ(input_value, output_value);
321 } 321 }
322 322
323 } // namespace autofill 323 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698