OLD | NEW |
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 "components/autofill/content/browser/content_autofill_driver.h" | 5 #include "components/autofill/content/browser/content_autofill_driver.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 |
8 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> |
9 #include <tuple> | 11 #include <tuple> |
10 #include <utility> | 12 #include <utility> |
11 #include <vector> | 13 #include <vector> |
12 | 14 |
13 #include "base/command_line.h" | 15 #include "base/command_line.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
16 #include "components/autofill/content/common/autofill_messages.h" | 17 #include "components/autofill/content/common/autofill_messages.h" |
17 #include "components/autofill/core/browser/autofill_external_delegate.h" | 18 #include "components/autofill/core/browser/autofill_external_delegate.h" |
18 #include "components/autofill/core/browser/autofill_manager.h" | 19 #include "components/autofill/core/browser/autofill_manager.h" |
19 #include "components/autofill/core/browser/autofill_test_utils.h" | 20 #include "components/autofill/core/browser/autofill_test_utils.h" |
20 #include "components/autofill/core/browser/test_autofill_client.h" | 21 #include "components/autofill/core/browser/test_autofill_client.h" |
21 #include "components/autofill/core/common/autofill_switches.h" | 22 #include "components/autofill/core/common/autofill_switches.h" |
22 #include "components/autofill/core/common/form_data_predictions.h" | 23 #include "components/autofill/core/common/form_data_predictions.h" |
23 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
24 #include "content/public/browser/navigation_details.h" | 25 #include "content/public/browser/navigation_details.h" |
(...skipping 22 matching lines...) Expand all Loading... |
47 virtual ~MockAutofillManager() {} | 48 virtual ~MockAutofillManager() {} |
48 | 49 |
49 MOCK_METHOD0(Reset, void()); | 50 MOCK_METHOD0(Reset, void()); |
50 }; | 51 }; |
51 | 52 |
52 class TestContentAutofillDriver : public ContentAutofillDriver { | 53 class TestContentAutofillDriver : public ContentAutofillDriver { |
53 public: | 54 public: |
54 TestContentAutofillDriver(content::RenderFrameHost* rfh, | 55 TestContentAutofillDriver(content::RenderFrameHost* rfh, |
55 AutofillClient* client) | 56 AutofillClient* client) |
56 : ContentAutofillDriver(rfh, client, kAppLocale, kDownloadState) { | 57 : ContentAutofillDriver(rfh, client, kAppLocale, kDownloadState) { |
57 scoped_ptr<AutofillManager> autofill_manager( | 58 std::unique_ptr<AutofillManager> autofill_manager( |
58 new MockAutofillManager(this, client)); | 59 new MockAutofillManager(this, client)); |
59 SetAutofillManager(std::move(autofill_manager)); | 60 SetAutofillManager(std::move(autofill_manager)); |
60 } | 61 } |
61 ~TestContentAutofillDriver() override {} | 62 ~TestContentAutofillDriver() override {} |
62 | 63 |
63 virtual MockAutofillManager* mock_autofill_manager() { | 64 virtual MockAutofillManager* mock_autofill_manager() { |
64 return static_cast<MockAutofillManager*>(autofill_manager()); | 65 return static_cast<MockAutofillManager*>(autofill_manager()); |
65 } | 66 } |
66 | 67 |
67 using ContentAutofillDriver::DidNavigateFrame; | 68 using ContentAutofillDriver::DidNavigateFrame; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 // of sent messages and returns true. | 189 // of sent messages and returns true. |
189 bool HasMessageMatchingID(uint32_t messageID) { | 190 bool HasMessageMatchingID(uint32_t messageID) { |
190 const IPC::Message* message = | 191 const IPC::Message* message = |
191 process()->sink().GetFirstMessageMatching(messageID); | 192 process()->sink().GetFirstMessageMatching(messageID); |
192 if (!message) | 193 if (!message) |
193 return false; | 194 return false; |
194 process()->sink().ClearMessages(); | 195 process()->sink().ClearMessages(); |
195 return true; | 196 return true; |
196 } | 197 } |
197 | 198 |
198 scoped_ptr<TestAutofillClient> test_autofill_client_; | 199 std::unique_ptr<TestAutofillClient> test_autofill_client_; |
199 scoped_ptr<TestContentAutofillDriver> driver_; | 200 std::unique_ptr<TestContentAutofillDriver> driver_; |
200 }; | 201 }; |
201 | 202 |
202 TEST_F(ContentAutofillDriverTest, GetURLRequestContext) { | 203 TEST_F(ContentAutofillDriverTest, GetURLRequestContext) { |
203 net::URLRequestContextGetter* request_context = | 204 net::URLRequestContextGetter* request_context = |
204 driver_->GetURLRequestContext(); | 205 driver_->GetURLRequestContext(); |
205 net::URLRequestContextGetter* expected_request_context = | 206 net::URLRequestContextGetter* expected_request_context = |
206 web_contents()->GetBrowserContext()->GetRequestContext(); | 207 web_contents()->GetBrowserContext()->GetRequestContext(); |
207 EXPECT_EQ(request_context, expected_request_context); | 208 EXPECT_EQ(request_context, expected_request_context); |
208 } | 209 } |
209 | 210 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 base::string16 input_value(base::ASCIIToUTF16("barqux")); | 319 base::string16 input_value(base::ASCIIToUTF16("barqux")); |
319 base::string16 output_value; | 320 base::string16 output_value; |
320 driver_->RendererShouldPreviewFieldWithValue(input_value); | 321 driver_->RendererShouldPreviewFieldWithValue(input_value); |
321 EXPECT_TRUE(GetString16FromMessageWithID( | 322 EXPECT_TRUE(GetString16FromMessageWithID( |
322 AutofillMsg_PreviewFieldWithValue::ID, | 323 AutofillMsg_PreviewFieldWithValue::ID, |
323 &output_value)); | 324 &output_value)); |
324 EXPECT_EQ(input_value, output_value); | 325 EXPECT_EQ(input_value, output_value); |
325 } | 326 } |
326 | 327 |
327 } // namespace autofill | 328 } // namespace autofill |
OLD | NEW |