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

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

Issue 11230060: Adding commandline switch and user pref for autofill server url. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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) 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 <list> 5 #include <list>
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/test/test_timeouts.h" 9 #include "base/test/test_timeouts.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/autofill/autofill_download.h" 11 #include "chrome/browser/autofill/autofill_download.h"
12 #include "chrome/browser/autofill/autofill_field.h" 12 #include "chrome/browser/autofill/autofill_field.h"
13 #include "chrome/browser/autofill/autofill_metrics.h" 13 #include "chrome/browser/autofill/autofill_metrics.h"
14 #include "chrome/browser/autofill/autofill_type.h" 14 #include "chrome/browser/autofill/autofill_type.h"
15 #include "chrome/browser/autofill/form_structure.h" 15 #include "chrome/browser/autofill/form_structure.h"
16 #include "chrome/common/form_data.h" 16 #include "chrome/common/form_data.h"
17 #include "chrome/test/base/testing_browser_process.h" 17 #include "chrome/test/base/testing_browser_process.h"
18 #include "chrome/test/base/testing_profile.h" 18 #include "chrome/test/base/testing_profile.h"
19 #include "chrome/test/base/testing_pref_service.h"
Albert Bodenhamer 2012/10/23 23:34:17 Alphabetize
ahutter 2012/10/24 17:33:45 Reverting all changes to this file.
19 #include "content/public/test/test_browser_thread.h" 20 #include "content/public/test/test_browser_thread.h"
20 #include "net/url_request/test_url_fetcher_factory.h" 21 #include "net/url_request/test_url_fetcher_factory.h"
21 #include "net/url_request/url_request_status.h" 22 #include "net/url_request/url_request_status.h"
22 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
25 26
26 using content::BrowserThread; 27 using content::BrowserThread;
27 using WebKit::WebInputElement; 28 using WebKit::WebInputElement;
29 using testing::HasSubstr;
30 using testing::Not;
28 31
29 namespace { 32 namespace {
30 33
31 class MockAutofillMetrics : public AutofillMetrics { 34 class MockAutofillMetrics : public AutofillMetrics {
32 public: 35 public:
33 MockAutofillMetrics() {} 36 MockAutofillMetrics() {}
34 MOCK_CONST_METHOD1(LogServerQueryMetric, void(ServerQueryMetric metric)); 37 MOCK_CONST_METHOD1(LogServerQueryMetric, void(ServerQueryMetric metric));
35 38
36 private: 39 private:
37 DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics); 40 DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics);
38 }; 41 };
39 42
40 // Call |fetcher->OnURLFetchComplete()| as the URLFetcher would when 43 // Call |fetcher->OnURLFetchComplete()| as the URLFetcher would when
41 // a response is received. Params allow caller to set fake status. 44 // a response is received. Params allow caller to set fake status.
42 void FakeOnURLFetchComplete(net::TestURLFetcher* fetcher, 45 void FakeOnURLFetchComplete(net::TestURLFetcher* fetcher,
43 int response_code, 46 int response_code,
44 const std::string& response_body) { 47 const std::string& response_body) {
45 fetcher->set_url(GURL()); 48 fetcher->set_url(GURL());
46 fetcher->set_status(net::URLRequestStatus()); 49 fetcher->set_status(net::URLRequestStatus());
47 fetcher->set_response_code(response_code); 50 fetcher->set_response_code(response_code);
48 fetcher->SetResponseString(response_body); 51 fetcher->SetResponseString(response_body);
49 52
50 fetcher->delegate()->OnURLFetchComplete(fetcher); 53 fetcher->delegate()->OnURLFetchComplete(fetcher);
51 } 54 }
52 55
53 } // namespace 56 } // namespace
54 57
58 class AutofillDownloadUrlTest : public testing::Test {
59 public:
60 AutofillDownloadUrlTest() {}
61
62 protected:
63 virtual void SetUp() {
64 pref_service_.reset(new TestingPrefService());
65 }
66
67 scoped_ptr<TestingPrefService> pref_service_;
68 };
69
70 TEST_F(AutofillDownloadUrlTest, CheckDefaultUrls) {
71 std::string request_url =
72 AutofillDownloadUrl(pref_service_.get()).
73 GetAutofillRequestUrl().spec();
74 EXPECT_THAT(request_url, HasSubstr("clients1.google.com"));
75 EXPECT_THAT(request_url, HasSubstr("/tbproxy/"));
76 EXPECT_THAT(request_url, HasSubstr("/af/"));
77 EXPECT_THAT(request_url, HasSubstr("/query"));
78 EXPECT_THAT(request_url, Not(HasSubstr("/upload")));
79 EXPECT_THAT(request_url, HasSubstr("?client="));
80
81
82 std::string upload_url =
83 AutofillDownloadUrl(pref_service_.get()).
84 GetAutofillUploadUrl().spec();
85 EXPECT_THAT(upload_url, HasSubstr("clients1.google.com"));
86 EXPECT_THAT(upload_url, HasSubstr("/tbproxy/"));
87 EXPECT_THAT(upload_url, HasSubstr("/af/"));
88 EXPECT_THAT(upload_url, HasSubstr("/upload"));
89 EXPECT_THAT(upload_url, Not(HasSubstr("/query")));
90 EXPECT_THAT(upload_url, HasSubstr("?client="));
91 }
Ilya Sherman 2012/10/23 23:45:13 nit: Since this code is testing the AutofillDownlo
ahutter 2012/10/24 17:33:45 Reverting all changes to this file.
92
93
55 // This tests AutofillDownloadManager. AutofillDownloadTest implements 94 // This tests AutofillDownloadManager. AutofillDownloadTest implements
56 // AutofillDownloadManager::Observer and creates an instance of 95 // AutofillDownloadManager::Observer and creates an instance of
57 // AutofillDownloadManager. Then it records responses to different initiated 96 // AutofillDownloadManager. Then it records responses to different initiated
58 // requests, which are verified later. To mock network requests 97 // requests, which are verified later. To mock network requests
59 // TestURLFetcherFactory is used, which creates URLFetchers that do not 98 // TestURLFetcherFactory is used, which creates URLFetchers that do not
60 // go over the wire, but allow calling back HTTP responses directly. 99 // go over the wire, but allow calling back HTTP responses directly.
61 // The responses in test are out of order and verify: successful query request, 100 // The responses in test are out of order and verify: successful query request,
62 // successful upload request, failed upload request. 101 // successful upload request, failed upload request.
63 class AutofillDownloadTest : public AutofillDownloadManager::Observer, 102 class AutofillDownloadTest : public AutofillDownloadManager::Observer,
64 public testing::Test { 103 public testing::Test {
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 mock_metric_logger)); 535 mock_metric_logger));
497 // No responses yet 536 // No responses yet
498 EXPECT_EQ(static_cast<size_t>(0), responses_.size()); 537 EXPECT_EQ(static_cast<size_t>(0), responses_.size());
499 538
500 fetcher = factory.GetFetcherByID(3); 539 fetcher = factory.GetFetcherByID(3);
501 ASSERT_TRUE(fetcher); 540 ASSERT_TRUE(fetcher);
502 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[0])); 541 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[0]));
503 ASSERT_EQ(static_cast<size_t>(1), responses_.size()); 542 ASSERT_EQ(static_cast<size_t>(1), responses_.size());
504 EXPECT_EQ(responses[0], responses_.front().response); 543 EXPECT_EQ(responses[0], responses_.front().response);
505 } 544 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698