| OLD | NEW |
| 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 12 matching lines...) Expand all Loading... |
| 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/http/http_status_code.h" |
| 32 #include "net/url_request/test_url_fetcher_factory.h" | 32 #include "net/url_request/test_url_fetcher_factory.h" |
| 33 #include "net/url_request/url_request_status.h" |
| 33 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 34 | 35 |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 const char kDistributionConfig[] = "{" | 39 const char kDistributionConfig[] = "{" |
| 39 " \"homepage\" : \"http://www.foo.com\"," | 40 " \"homepage\" : \"http://www.foo.com\"," |
| 40 " \"homepage_is_newtabpage\" : false," | 41 " \"homepage_is_newtabpage\" : false," |
| 41 " \"browser\" : {" | 42 " \"browser\" : {" |
| 42 " \"show_home_button\" : true" | 43 " \"show_home_button\" : true" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 168 |
| 168 scoped_ptr<BrandcodeConfigFetcher> WaitForRequest(const GURL& url); | 169 scoped_ptr<BrandcodeConfigFetcher> WaitForRequest(const GURL& url); |
| 169 | 170 |
| 170 net::FakeURLFetcherFactory& factory() { return factory_; } | 171 net::FakeURLFetcherFactory& factory() { return factory_; } |
| 171 | 172 |
| 172 private: | 173 private: |
| 173 scoped_ptr<net::FakeURLFetcher> CreateFakeURLFetcher( | 174 scoped_ptr<net::FakeURLFetcher> CreateFakeURLFetcher( |
| 174 const GURL& url, | 175 const GURL& url, |
| 175 net::URLFetcherDelegate* fetcher_delegate, | 176 net::URLFetcherDelegate* fetcher_delegate, |
| 176 const std::string& response_data, | 177 const std::string& response_data, |
| 177 net::HttpStatusCode response_code); | 178 net::HttpStatusCode response_code, |
| 179 net::URLRequestStatus::Status status); |
| 178 | 180 |
| 179 MOCK_METHOD0(Callback, void(void)); | 181 MOCK_METHOD0(Callback, void(void)); |
| 180 | 182 |
| 181 base::MessageLoop loop_; | 183 base::MessageLoop loop_; |
| 182 content::TestBrowserThread ui_thread_; | 184 content::TestBrowserThread ui_thread_; |
| 183 content::TestBrowserThread io_thread_; | 185 content::TestBrowserThread io_thread_; |
| 184 URLFetcherRequestListener request_listener_; | 186 URLFetcherRequestListener request_listener_; |
| 185 net::FakeURLFetcherFactory factory_; | 187 net::FakeURLFetcherFactory factory_; |
| 186 }; | 188 }; |
| 187 | 189 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 207 EXPECT_FALSE(fetcher->IsActive()); | 209 EXPECT_FALSE(fetcher->IsActive()); |
| 208 // Look for the brand code in the request. | 210 // Look for the brand code in the request. |
| 209 EXPECT_NE(std::string::npos, request_listener_.upload_data.find("ABCD")); | 211 EXPECT_NE(std::string::npos, request_listener_.upload_data.find("ABCD")); |
| 210 return fetcher.Pass(); | 212 return fetcher.Pass(); |
| 211 } | 213 } |
| 212 | 214 |
| 213 scoped_ptr<net::FakeURLFetcher> ConfigParserTest::CreateFakeURLFetcher( | 215 scoped_ptr<net::FakeURLFetcher> ConfigParserTest::CreateFakeURLFetcher( |
| 214 const GURL& url, | 216 const GURL& url, |
| 215 net::URLFetcherDelegate* fetcher_delegate, | 217 net::URLFetcherDelegate* fetcher_delegate, |
| 216 const std::string& response_data, | 218 const std::string& response_data, |
| 217 net::HttpStatusCode response_code) { | 219 net::HttpStatusCode response_code, |
| 220 net::URLRequestStatus::Status status) { |
| 218 request_listener_.real_delegate = fetcher_delegate; | 221 request_listener_.real_delegate = fetcher_delegate; |
| 219 scoped_ptr<net::FakeURLFetcher> fetcher( | 222 scoped_ptr<net::FakeURLFetcher> fetcher( |
| 220 new net::FakeURLFetcher(url, | 223 new net::FakeURLFetcher( |
| 221 &request_listener_, | 224 url, &request_listener_, response_data, response_code, status)); |
| 222 response_data, | |
| 223 response_code)); | |
| 224 scoped_refptr<net::HttpResponseHeaders> download_headers = | 225 scoped_refptr<net::HttpResponseHeaders> download_headers = |
| 225 new net::HttpResponseHeaders(""); | 226 new net::HttpResponseHeaders(""); |
| 226 download_headers->AddHeader("Content-Type: text/xml"); | 227 download_headers->AddHeader("Content-Type: text/xml"); |
| 227 fetcher->set_response_headers(download_headers); | 228 fetcher->set_response_headers(download_headers); |
| 228 return fetcher.Pass(); | 229 return fetcher.Pass(); |
| 229 } | 230 } |
| 230 | 231 |
| 231 | 232 |
| 232 // helper functions ----------------------------------------------------------- | 233 // helper functions ----------------------------------------------------------- |
| 233 | 234 |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 TEST_F(ProfileResetterTest, ResetFewFlags) { | 647 TEST_F(ProfileResetterTest, ResetFewFlags) { |
| 647 // mock_object_ is a StrictMock, so we verify that it is called only once. | 648 // mock_object_ is a StrictMock, so we verify that it is called only once. |
| 648 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE | | 649 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE | |
| 649 ProfileResetter::HOMEPAGE | | 650 ProfileResetter::HOMEPAGE | |
| 650 ProfileResetter::CONTENT_SETTINGS); | 651 ProfileResetter::CONTENT_SETTINGS); |
| 651 } | 652 } |
| 652 | 653 |
| 653 // Tries to load unavailable config file. | 654 // Tries to load unavailable config file. |
| 654 TEST_F(ConfigParserTest, NoConnectivity) { | 655 TEST_F(ConfigParserTest, NoConnectivity) { |
| 655 const GURL url("http://test"); | 656 const GURL url("http://test"); |
| 656 factory().SetFakeResponse(url, "", net::HTTP_INTERNAL_SERVER_ERROR); | 657 factory().SetFakeResponse(url, "", net::HTTP_INTERNAL_SERVER_ERROR, |
| 658 net::URLRequestStatus::FAILED); |
| 657 | 659 |
| 658 scoped_ptr<BrandcodeConfigFetcher> fetcher = WaitForRequest(GURL(url)); | 660 scoped_ptr<BrandcodeConfigFetcher> fetcher = WaitForRequest(GURL(url)); |
| 659 EXPECT_FALSE(fetcher->GetSettings()); | 661 EXPECT_FALSE(fetcher->GetSettings()); |
| 660 } | 662 } |
| 661 | 663 |
| 662 // Tries to load available config file. | 664 // Tries to load available config file. |
| 663 TEST_F(ConfigParserTest, ParseConfig) { | 665 TEST_F(ConfigParserTest, ParseConfig) { |
| 664 const GURL url("http://test"); | 666 const GURL url("http://test"); |
| 665 std::string xml_config(kXmlConfig); | 667 std::string xml_config(kXmlConfig); |
| 666 ReplaceString(&xml_config, "placeholder_for_data", kDistributionConfig); | 668 ReplaceString(&xml_config, "placeholder_for_data", kDistributionConfig); |
| 667 ReplaceString(&xml_config, | 669 ReplaceString(&xml_config, |
| 668 "placeholder_for_id", | 670 "placeholder_for_id", |
| 669 "abbaabbaabbaabbaabbaabbaabbaabba"); | 671 "abbaabbaabbaabbaabbaabbaabbaabba"); |
| 670 factory().SetFakeResponse(url, xml_config, net::HTTP_OK); | 672 factory().SetFakeResponse(url, xml_config, net::HTTP_OK, |
| 673 net::URLRequestStatus::SUCCESS); |
| 671 | 674 |
| 672 scoped_ptr<BrandcodeConfigFetcher> fetcher = WaitForRequest(GURL(url)); | 675 scoped_ptr<BrandcodeConfigFetcher> fetcher = WaitForRequest(GURL(url)); |
| 673 scoped_ptr<BrandcodedDefaultSettings> settings = fetcher->GetSettings(); | 676 scoped_ptr<BrandcodedDefaultSettings> settings = fetcher->GetSettings(); |
| 674 ASSERT_TRUE(settings); | 677 ASSERT_TRUE(settings); |
| 675 | 678 |
| 676 std::vector<std::string> extension_ids; | 679 std::vector<std::string> extension_ids; |
| 677 EXPECT_TRUE(settings->GetExtensions(&extension_ids)); | 680 EXPECT_TRUE(settings->GetExtensions(&extension_ids)); |
| 678 EXPECT_EQ(1u, extension_ids.size()); | 681 EXPECT_EQ(1u, extension_ids.size()); |
| 679 EXPECT_EQ("abbaabbaabbaabbaabbaabbaabbaabba", extension_ids[0]); | 682 EXPECT_EQ("abbaabbaabbaabbaabbaabbaabbaabba", extension_ids[0]); |
| 680 | 683 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 ASSERT_TRUE(dict->GetString("key", &value)); | 846 ASSERT_TRUE(dict->GetString("key", &value)); |
| 844 if (value == "Extensions") { | 847 if (value == "Extensions") { |
| 845 string16 extensions; | 848 string16 extensions; |
| 846 EXPECT_TRUE(dict->GetString("value", &extensions)); | 849 EXPECT_TRUE(dict->GetString("value", &extensions)); |
| 847 EXPECT_EQ(WideToUTF16(L"Tiësto"), extensions); | 850 EXPECT_EQ(WideToUTF16(L"Tiësto"), extensions); |
| 848 } | 851 } |
| 849 } | 852 } |
| 850 } | 853 } |
| 851 | 854 |
| 852 } // namespace | 855 } // namespace |
| OLD | NEW |