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

Side by Side Diff: components/autofill/browser/autocheckout/whitelist_manager_unittest.cc

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged ToT Created 7 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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" 8 #include "chrome/test/base/testing_profile.h"
9 #include "components/autofill/browser/autocheckout/whitelist_manager.h" 9 #include "components/autofill/browser/autocheckout/whitelist_manager.h"
10 #include "components/autofill/browser/autofill_metrics.h" 10 #include "components/autofill/browser/autofill_metrics.h"
11 #include "components/autofill/common/autofill_switches.h" 11 #include "components/autofill/common/autofill_switches.h"
12 #include "content/public/test/test_browser_thread.h" 12 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 #include "net/http/http_status_code.h" 15 #include "net/http/http_status_code.h"
16 #include "net/url_request/test_url_fetcher_factory.h" 16 #include "net/url_request/test_url_fetcher_factory.h"
17 #include "net/url_request/url_fetcher_delegate.h" 17 #include "net/url_request/url_fetcher_delegate.h"
18 #include "net/url_request/url_request_status.h" 18 #include "net/url_request/url_request_status.h"
19 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 namespace { 22 namespace {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 private: 83 private:
84 bool did_start_download_timer_; 84 bool did_start_download_timer_;
85 85
86 MockAutofillMetrics mock_metrics_logger_; 86 MockAutofillMetrics mock_metrics_logger_;
87 87
88 DISALLOW_COPY_AND_ASSIGN(TestWhitelistManager); 88 DISALLOW_COPY_AND_ASSIGN(TestWhitelistManager);
89 }; 89 };
90 90
91 class WhitelistManagerTest : public testing::Test { 91 class WhitelistManagerTest : public testing::Test {
92 public: 92 public:
93 WhitelistManagerTest() : io_thread_(content::BrowserThread::IO) {} 93 WhitelistManagerTest()
94 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {}
94 95
95 virtual void SetUp() { 96 virtual void SetUp() {
96 io_thread_.StartIOThread();
97 profile_.CreateRequestContext(); 97 profile_.CreateRequestContext();
98 } 98 }
99 99
100 virtual void TearDown() { 100 virtual void TearDown() {
101 profile_.ResetRequestContext(); 101 profile_.ResetRequestContext();
102 io_thread_.Stop();
103 } 102 }
104 103
105 protected: 104 protected:
106 void CreateWhitelistManager() { 105 void CreateWhitelistManager() {
107 if (!whitelist_manager_.get()) { 106 if (!whitelist_manager_.get()) {
108 whitelist_manager_.reset(new TestWhitelistManager()); 107 whitelist_manager_.reset(new TestWhitelistManager());
109 } 108 }
110 } 109 }
111 110
112 void DownloadWhitelist(int response_code, const std::string& response) { 111 void DownloadWhitelist(int response_code, const std::string& response) {
(...skipping 26 matching lines...) Expand all
139 138
140 const std::vector<std::string>& get_url_prefixes() const { 139 const std::vector<std::string>& get_url_prefixes() const {
141 return whitelist_manager_->url_prefixes(); 140 return whitelist_manager_->url_prefixes();
142 } 141 }
143 142
144 protected: 143 protected:
145 TestingProfile profile_; 144 TestingProfile profile_;
146 scoped_ptr<TestWhitelistManager> whitelist_manager_; 145 scoped_ptr<TestWhitelistManager> whitelist_manager_;
147 146
148 private: 147 private:
149 base::MessageLoopForIO message_loop_; 148 content::TestBrowserThreadBundle thread_bundle_;
150 // The profile's request context must be released on the IO thread.
151 content::TestBrowserThread io_thread_;
152 }; 149 };
153 150
154 TEST_F(WhitelistManagerTest, DownloadWhitelist) { 151 TEST_F(WhitelistManagerTest, DownloadWhitelist) {
155 CommandLine::ForCurrentProcess()->AppendSwitch( 152 CommandLine::ForCurrentProcess()->AppendSwitch(
156 switches::kEnableExperimentalFormFilling); 153 switches::kEnableExperimentalFormFilling);
157 DownloadWhitelist(net::HTTP_OK, kDownloadWhitelistResponse); 154 DownloadWhitelist(net::HTTP_OK, kDownloadWhitelistResponse);
158 ASSERT_EQ(2U, get_url_prefixes().size()); 155 ASSERT_EQ(2U, get_url_prefixes().size());
159 EXPECT_EQ("https://www.merchant1.com/checkout/", 156 EXPECT_EQ("https://www.merchant1.com/checkout/",
160 get_url_prefixes()[0]); 157 get_url_prefixes()[0]);
161 EXPECT_EQ("https://cart.merchant2.com/", 158 EXPECT_EQ("https://cart.merchant2.com/",
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 GURL("https://cart.merchant2.com/ShippingInfo?a=b&c=d"))); 282 GURL("https://cart.merchant2.com/ShippingInfo?a=b&c=d")));
286 // Bypass other urls. 283 // Bypass other urls.
287 EXPECT_EQ(std::string("https://bypass.me/"), 284 EXPECT_EQ(std::string("https://bypass.me/"),
288 whitelist_manager_->GetMatchedURLPrefix( 285 whitelist_manager_->GetMatchedURLPrefix(
289 GURL("https://bypass.me/"))); 286 GURL("https://bypass.me/")));
290 } 287 }
291 288
292 } // namespace autocheckout 289 } // namespace autocheckout
293 } // namespace autofill 290 } // namespace autofill
294 291
OLDNEW
« no previous file with comments | « chrome/test/base/chrome_render_view_host_test_harness.cc ('k') | components/autofill/browser/autocheckout_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698