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

Side by Side Diff: chrome/browser/profile_resetter/profile_resetter_unittest.cc

Issue 48713008: [sync] Allow FakeURLFetcher to return arbitrary HTTP response codes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 1 month 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 "chrome/browser/profile_resetter/profile_resetter.h" 5 #include "chrome/browser/profile_resetter/profile_resetter.h"
6 6
7 #include "base/json/json_string_value_serializer.h" 7 #include "base/json/json_string_value_serializer.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/content_settings/host_content_settings_map.h" 10 #include "chrome/browser/content_settings/host_content_settings_map.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/themes/theme_service.h" 21 #include "chrome/browser/themes/theme_service.h"
22 #include "chrome/browser/themes/theme_service_factory.h" 22 #include "chrome/browser/themes/theme_service_factory.h"
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" 23 #include "chrome/browser/ui/tabs/tab_strip_model.h"
24 #include "chrome/common/extensions/extension.h" 24 #include "chrome/common/extensions/extension.h"
25 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
26 #include "chrome/test/base/browser_with_test_window_test.h" 26 #include "chrome/test/base/browser_with_test_window_test.h"
27 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 #include "content/public/test/test_browser_thread.h" 28 #include "content/public/test/test_browser_thread.h"
29 #include "extensions/common/manifest_constants.h" 29 #include "extensions/common/manifest_constants.h"
30 #include "net/http/http_response_headers.h" 30 #include "net/http/http_response_headers.h"
31 #include "net/http/http_status_code.h"
31 #include "net/url_request/test_url_fetcher_factory.h" 32 #include "net/url_request/test_url_fetcher_factory.h"
32 #include "url/gurl.h" 33 #include "url/gurl.h"
33 34
34 35
35 namespace { 36 namespace {
36 37
37 const char kDistributionConfig[] = "{" 38 const char kDistributionConfig[] = "{"
38 " \"homepage\" : \"http://www.foo.com\"," 39 " \"homepage\" : \"http://www.foo.com\","
39 " \"homepage_is_newtabpage\" : false," 40 " \"homepage_is_newtabpage\" : false,"
40 " \"browser\" : {" 41 " \"browser\" : {"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 167
167 scoped_ptr<BrandcodeConfigFetcher> WaitForRequest(const GURL& url); 168 scoped_ptr<BrandcodeConfigFetcher> WaitForRequest(const GURL& url);
168 169
169 net::FakeURLFetcherFactory& factory() { return factory_; } 170 net::FakeURLFetcherFactory& factory() { return factory_; }
170 171
171 private: 172 private:
172 scoped_ptr<net::FakeURLFetcher> CreateFakeURLFetcher( 173 scoped_ptr<net::FakeURLFetcher> CreateFakeURLFetcher(
173 const GURL& url, 174 const GURL& url,
174 net::URLFetcherDelegate* fetcher_delegate, 175 net::URLFetcherDelegate* fetcher_delegate,
175 const std::string& response_data, 176 const std::string& response_data,
176 bool success); 177 net::HttpStatusCode response_code);
177 178
178 MOCK_METHOD0(Callback, void(void)); 179 MOCK_METHOD0(Callback, void(void));
179 180
180 base::MessageLoop loop_; 181 base::MessageLoop loop_;
181 content::TestBrowserThread ui_thread_; 182 content::TestBrowserThread ui_thread_;
182 content::TestBrowserThread io_thread_; 183 content::TestBrowserThread io_thread_;
183 URLFetcherRequestListener request_listener_; 184 URLFetcherRequestListener request_listener_;
184 net::FakeURLFetcherFactory factory_; 185 net::FakeURLFetcherFactory factory_;
185 }; 186 };
186 187
(...skipping 19 matching lines...) Expand all
206 EXPECT_FALSE(fetcher->IsActive()); 207 EXPECT_FALSE(fetcher->IsActive());
207 // Look for the brand code in the request. 208 // Look for the brand code in the request.
208 EXPECT_NE(std::string::npos, request_listener_.upload_data.find("ABCD")); 209 EXPECT_NE(std::string::npos, request_listener_.upload_data.find("ABCD"));
209 return fetcher.Pass(); 210 return fetcher.Pass();
210 } 211 }
211 212
212 scoped_ptr<net::FakeURLFetcher> ConfigParserTest::CreateFakeURLFetcher( 213 scoped_ptr<net::FakeURLFetcher> ConfigParserTest::CreateFakeURLFetcher(
213 const GURL& url, 214 const GURL& url,
214 net::URLFetcherDelegate* fetcher_delegate, 215 net::URLFetcherDelegate* fetcher_delegate,
215 const std::string& response_data, 216 const std::string& response_data,
216 bool success) { 217 net::HttpStatusCode response_code) {
217 request_listener_.real_delegate = fetcher_delegate; 218 request_listener_.real_delegate = fetcher_delegate;
218 scoped_ptr<net::FakeURLFetcher> fetcher( 219 scoped_ptr<net::FakeURLFetcher> fetcher(
219 new net::FakeURLFetcher(url, &request_listener_, response_data, success)); 220 new net::FakeURLFetcher(url,
221 &request_listener_,
222 response_data,
223 response_code));
220 scoped_refptr<net::HttpResponseHeaders> download_headers = 224 scoped_refptr<net::HttpResponseHeaders> download_headers =
221 new net::HttpResponseHeaders(""); 225 new net::HttpResponseHeaders("");
222 download_headers->AddHeader("Content-Type: text/xml"); 226 download_headers->AddHeader("Content-Type: text/xml");
223 fetcher->set_response_headers(download_headers); 227 fetcher->set_response_headers(download_headers);
224 return fetcher.Pass(); 228 return fetcher.Pass();
225 } 229 }
226 230
227 231
228 // helper functions ----------------------------------------------------------- 232 // helper functions -----------------------------------------------------------
229 233
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 TEST_F(ProfileResetterTest, ResetFewFlags) { 646 TEST_F(ProfileResetterTest, ResetFewFlags) {
643 // mock_object_ is a StrictMock, so we verify that it is called only once. 647 // mock_object_ is a StrictMock, so we verify that it is called only once.
644 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE | 648 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE |
645 ProfileResetter::HOMEPAGE | 649 ProfileResetter::HOMEPAGE |
646 ProfileResetter::CONTENT_SETTINGS); 650 ProfileResetter::CONTENT_SETTINGS);
647 } 651 }
648 652
649 // Tries to load unavailable config file. 653 // Tries to load unavailable config file.
650 TEST_F(ConfigParserTest, NoConnectivity) { 654 TEST_F(ConfigParserTest, NoConnectivity) {
651 const GURL url("http://test"); 655 const GURL url("http://test");
652 factory().SetFakeResponse(url, "", false); 656 factory().SetFakeResponse(url, "", net::HTTP_INTERNAL_SERVER_ERROR);
653 657
654 scoped_ptr<BrandcodeConfigFetcher> fetcher = WaitForRequest(GURL(url)); 658 scoped_ptr<BrandcodeConfigFetcher> fetcher = WaitForRequest(GURL(url));
655 EXPECT_FALSE(fetcher->GetSettings()); 659 EXPECT_FALSE(fetcher->GetSettings());
656 } 660 }
657 661
658 // Tries to load available config file. 662 // Tries to load available config file.
659 TEST_F(ConfigParserTest, ParseConfig) { 663 TEST_F(ConfigParserTest, ParseConfig) {
660 const GURL url("http://test"); 664 const GURL url("http://test");
661 std::string xml_config(kXmlConfig); 665 std::string xml_config(kXmlConfig);
662 ReplaceString(&xml_config, "placeholder_for_data", kDistributionConfig); 666 ReplaceString(&xml_config, "placeholder_for_data", kDistributionConfig);
663 ReplaceString(&xml_config, 667 ReplaceString(&xml_config,
664 "placeholder_for_id", 668 "placeholder_for_id",
665 "abbaabbaabbaabbaabbaabbaabbaabba"); 669 "abbaabbaabbaabbaabbaabbaabbaabba");
666 factory().SetFakeResponse(url, xml_config, true); 670 factory().SetFakeResponse(url, xml_config, net::HTTP_OK);
667 671
668 scoped_ptr<BrandcodeConfigFetcher> fetcher = WaitForRequest(GURL(url)); 672 scoped_ptr<BrandcodeConfigFetcher> fetcher = WaitForRequest(GURL(url));
669 scoped_ptr<BrandcodedDefaultSettings> settings = fetcher->GetSettings(); 673 scoped_ptr<BrandcodedDefaultSettings> settings = fetcher->GetSettings();
670 ASSERT_TRUE(settings); 674 ASSERT_TRUE(settings);
671 675
672 std::vector<std::string> extension_ids; 676 std::vector<std::string> extension_ids;
673 EXPECT_TRUE(settings->GetExtensions(&extension_ids)); 677 EXPECT_TRUE(settings->GetExtensions(&extension_ids));
674 EXPECT_EQ(1u, extension_ids.size()); 678 EXPECT_EQ(1u, extension_ids.size());
675 EXPECT_EQ("abbaabbaabbaabbaabbaabbaabbaabba", extension_ids[0]); 679 EXPECT_EQ("abbaabbaabbaabbaabbaabbaabbaabba", extension_ids[0]);
676 680
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 ASSERT_TRUE(dict->GetString("key", &value)); 843 ASSERT_TRUE(dict->GetString("key", &value));
840 if (value == "Extensions") { 844 if (value == "Extensions") {
841 string16 extensions; 845 string16 extensions;
842 EXPECT_TRUE(dict->GetString("value", &extensions)); 846 EXPECT_TRUE(dict->GetString("value", &extensions));
843 EXPECT_EQ(WideToUTF16(L"Tiësto"), extensions); 847 EXPECT_EQ(WideToUTF16(L"Tiësto"), extensions);
844 } 848 }
845 } 849 }
846 } 850 }
847 851
848 } // namespace 852 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698