OLD | NEW |
---|---|
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 "base/callback_helpers.h" | 5 #include "base/callback_helpers.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/search_engines/template_url_service_test_util.h" | 11 #include "chrome/browser/search_engines/template_url_service_test_util.h" |
12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
14 #include "components/search_engines/template_url.h" | 14 #include "components/search_engines/template_url.h" |
15 #include "components/search_engines/template_url_fetcher.h" | 15 #include "components/search_engines/template_url_fetcher.h" |
16 #include "components/search_engines/template_url_service.h" | 16 #include "components/search_engines/template_url_service.h" |
17 #include "content/public/test/test_browser_thread_bundle.h" | |
17 #include "net/test/embedded_test_server/embedded_test_server.h" | 18 #include "net/test/embedded_test_server/embedded_test_server.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
20 | 21 |
21 using base::ASCIIToUTF16; | 22 using base::ASCIIToUTF16; |
22 | 23 |
23 // Basic set-up for TemplateURLFetcher tests. | 24 // Basic set-up for TemplateURLFetcher tests. |
24 class TemplateURLFetcherTest : public testing::Test { | 25 class TemplateURLFetcherTest : public testing::Test { |
25 public: | 26 public: |
26 TemplateURLFetcherTest(); | 27 TemplateURLFetcherTest(); |
(...skipping 23 matching lines...) Expand all Loading... | |
50 protected: | 51 protected: |
51 // Schedules the download of the url. | 52 // Schedules the download of the url. |
52 void StartDownload(const base::string16& keyword, | 53 void StartDownload(const base::string16& keyword, |
53 const std::string& osdd_file_name, | 54 const std::string& osdd_file_name, |
54 TemplateURLFetcher::ProviderType provider_type, | 55 TemplateURLFetcher::ProviderType provider_type, |
55 bool check_that_file_exists); | 56 bool check_that_file_exists); |
56 | 57 |
57 // Waits for any downloads to finish. | 58 // Waits for any downloads to finish. |
58 void WaitForDownloadToFinish(); | 59 void WaitForDownloadToFinish(); |
59 | 60 |
61 content::TestBrowserThreadBundle thread_bundle_; | |
Peter Kasting
2014/08/28 19:06:20
Nit: Add comments about why we need this.
While h
hashimoto
2014/08/29 08:06:26
Added comments and made all data members private.
| |
60 TemplateURLServiceTestUtil test_util_; | 62 TemplateURLServiceTestUtil test_util_; |
61 scoped_ptr<TemplateURLFetcher> template_url_fetcher_; | 63 scoped_ptr<TemplateURLFetcher> template_url_fetcher_; |
62 net::test_server::EmbeddedTestServer test_server_; | 64 net::test_server::EmbeddedTestServer test_server_; |
63 | 65 |
64 // The last TemplateURL to come from a callback. | 66 // The last TemplateURL to come from a callback. |
65 scoped_ptr<TemplateURL> last_callback_template_url_; | 67 scoped_ptr<TemplateURL> last_callback_template_url_; |
66 | 68 |
67 // How many TemplateURLFetcherTestCallbacks have been destructed. | 69 // How many TemplateURLFetcherTestCallbacks have been destructed. |
68 int callbacks_destroyed_; | 70 int callbacks_destroyed_; |
69 | 71 |
70 // How many times ConfirmAddSearchProvider has been called. | 72 // How many times ConfirmAddSearchProvider has been called. |
71 int add_provider_called_; | 73 int add_provider_called_; |
72 | 74 |
73 // Is the code in WaitForDownloadToFinish in a message loop waiting for a | 75 // Is the code in WaitForDownloadToFinish in a message loop waiting for a |
74 // callback to finish? | 76 // callback to finish? |
75 bool waiting_for_download_; | 77 bool waiting_for_download_; |
76 | 78 |
77 private: | 79 private: |
78 DISALLOW_COPY_AND_ASSIGN(TemplateURLFetcherTest); | 80 DISALLOW_COPY_AND_ASSIGN(TemplateURLFetcherTest); |
79 }; | 81 }; |
80 | 82 |
81 TemplateURLFetcherTest::TemplateURLFetcherTest() | 83 TemplateURLFetcherTest::TemplateURLFetcherTest() |
82 : callbacks_destroyed_(0), | 84 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
85 callbacks_destroyed_(0), | |
83 add_provider_called_(0), | 86 add_provider_called_(0), |
84 waiting_for_download_(false) { | 87 waiting_for_download_(false) { |
85 base::FilePath src_dir; | 88 base::FilePath src_dir; |
86 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)); | 89 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)); |
87 test_server_.ServeFilesFromDirectory( | 90 test_server_.ServeFilesFromDirectory( |
88 src_dir.AppendASCII("chrome/test/data")); | 91 src_dir.AppendASCII("chrome/test/data")); |
89 } | 92 } |
90 | 93 |
91 void TemplateURLFetcherTest::DestroyedCallback() { | 94 void TemplateURLFetcherTest::DestroyedCallback() { |
92 callbacks_destroyed_++; | 95 callbacks_destroyed_++; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 StartDownload(keyword, osdd_file_name, | 299 StartDownload(keyword, osdd_file_name, |
297 TemplateURLFetcher::EXPLICIT_PROVIDER, true); | 300 TemplateURLFetcher::EXPLICIT_PROVIDER, true); |
298 ASSERT_EQ(0, add_provider_called_); | 301 ASSERT_EQ(0, add_provider_called_); |
299 ASSERT_EQ(1, callbacks_destroyed_); | 302 ASSERT_EQ(1, callbacks_destroyed_); |
300 | 303 |
301 WaitForDownloadToFinish(); | 304 WaitForDownloadToFinish(); |
302 ASSERT_EQ(1, add_provider_called_); | 305 ASSERT_EQ(1, add_provider_called_); |
303 ASSERT_EQ(2, callbacks_destroyed_); | 306 ASSERT_EQ(2, callbacks_destroyed_); |
304 ASSERT_TRUE(last_callback_template_url_.get()); | 307 ASSERT_TRUE(last_callback_template_url_.get()); |
305 } | 308 } |
OLD | NEW |