| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "chrome/test/base/testing_profile.h" | |
| 9 #include "components/autofill/content/browser/autocheckout/whitelist_manager.h" | 8 #include "components/autofill/content/browser/autocheckout/whitelist_manager.h" |
| 10 #include "components/autofill/core/browser/autofill_metrics.h" | 9 #include "components/autofill/core/browser/autofill_metrics.h" |
| 11 #include "components/autofill/core/common/autofill_switches.h" | 10 #include "components/autofill/core/common/autofill_switches.h" |
| 12 #include "content/public/test/test_browser_thread_bundle.h" | 11 #include "content/public/test/test_browser_thread_bundle.h" |
| 13 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 14 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 15 #include "net/http/http_status_code.h" | 14 #include "net/http/http_status_code.h" |
| 16 #include "net/url_request/test_url_fetcher_factory.h" | 15 #include "net/url_request/test_url_fetcher_factory.h" |
| 17 #include "net/url_request/url_fetcher_delegate.h" | 16 #include "net/url_request/url_fetcher_delegate.h" |
| 18 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 MockAutofillMetrics mock_metrics_logger_; | 85 MockAutofillMetrics mock_metrics_logger_; |
| 87 | 86 |
| 88 DISALLOW_COPY_AND_ASSIGN(TestWhitelistManager); | 87 DISALLOW_COPY_AND_ASSIGN(TestWhitelistManager); |
| 89 }; | 88 }; |
| 90 | 89 |
| 91 class WhitelistManagerTest : public testing::Test { | 90 class WhitelistManagerTest : public testing::Test { |
| 92 public: | 91 public: |
| 93 WhitelistManagerTest() | 92 WhitelistManagerTest() |
| 94 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} | 93 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} |
| 95 | 94 |
| 96 virtual void SetUp() { | |
| 97 profile_.CreateRequestContext(); | |
| 98 } | |
| 99 | |
| 100 virtual void TearDown() { | |
| 101 profile_.ResetRequestContext(); | |
| 102 } | |
| 103 | |
| 104 protected: | 95 protected: |
| 105 void CreateWhitelistManager() { | 96 void CreateWhitelistManager() { |
| 106 if (!whitelist_manager_.get()) { | 97 if (!whitelist_manager_.get()) { |
| 107 whitelist_manager_.reset(new TestWhitelistManager()); | 98 whitelist_manager_.reset(new TestWhitelistManager()); |
| 108 } | 99 } |
| 109 } | 100 } |
| 110 | 101 |
| 111 void DownloadWhitelist(int response_code, const std::string& response) { | 102 void DownloadWhitelist(int response_code, const std::string& response) { |
| 112 // Create and register factory. | 103 // Create and register factory. |
| 113 net::TestURLFetcherFactory factory; | 104 net::TestURLFetcherFactory factory; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 134 | 125 |
| 135 void ResetBackOff() { | 126 void ResetBackOff() { |
| 136 whitelist_manager_->StopDownloadTimer(); | 127 whitelist_manager_->StopDownloadTimer(); |
| 137 } | 128 } |
| 138 | 129 |
| 139 const std::vector<std::string>& get_url_prefixes() const { | 130 const std::vector<std::string>& get_url_prefixes() const { |
| 140 return whitelist_manager_->url_prefixes(); | 131 return whitelist_manager_->url_prefixes(); |
| 141 } | 132 } |
| 142 | 133 |
| 143 protected: | 134 protected: |
| 144 TestingProfile profile_; | |
| 145 scoped_ptr<TestWhitelistManager> whitelist_manager_; | 135 scoped_ptr<TestWhitelistManager> whitelist_manager_; |
| 146 | 136 |
| 147 private: | 137 private: |
| 148 content::TestBrowserThreadBundle thread_bundle_; | 138 content::TestBrowserThreadBundle thread_bundle_; |
| 149 }; | 139 }; |
| 150 | 140 |
| 151 TEST_F(WhitelistManagerTest, DownloadWhitelist) { | 141 TEST_F(WhitelistManagerTest, DownloadWhitelist) { |
| 152 CommandLine::ForCurrentProcess()->AppendSwitch( | 142 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 153 switches::kEnableExperimentalFormFilling); | 143 switches::kEnableExperimentalFormFilling); |
| 154 DownloadWhitelist(net::HTTP_OK, kDownloadWhitelistResponse); | 144 DownloadWhitelist(net::HTTP_OK, kDownloadWhitelistResponse); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 GURL("https://cart.merchant2.com/ShippingInfo?a=b&c=d"))); | 272 GURL("https://cart.merchant2.com/ShippingInfo?a=b&c=d"))); |
| 283 // Bypass other urls. | 273 // Bypass other urls. |
| 284 EXPECT_EQ(std::string("https://bypass.me/"), | 274 EXPECT_EQ(std::string("https://bypass.me/"), |
| 285 whitelist_manager_->GetMatchedURLPrefix( | 275 whitelist_manager_->GetMatchedURLPrefix( |
| 286 GURL("https://bypass.me/"))); | 276 GURL("https://bypass.me/"))); |
| 287 } | 277 } |
| 288 | 278 |
| 289 } // namespace autocheckout | 279 } // namespace autocheckout |
| 290 } // namespace autofill | 280 } // namespace autofill |
| 291 | 281 |
| OLD | NEW |