OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/version.h" | 12 #include "base/version.h" |
13 #include "chrome/browser/component_updater/test/component_updater_service_unitte
st.h" | |
14 #include "chrome/browser/component_updater/test/url_request_post_interceptor.h" | |
15 #include "chrome/common/chrome_paths.h" | |
16 #include "components/component_updater/crx_update_item.h" | 13 #include "components/component_updater/crx_update_item.h" |
| 14 #include "components/component_updater/test/test_configurator.h" |
| 15 #include "components/component_updater/test/url_request_post_interceptor.h" |
17 #include "components/component_updater/update_checker.h" | 16 #include "components/component_updater/update_checker.h" |
18 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
20 #include "net/url_request/url_fetcher.h" | 19 #include "net/url_request/url_fetcher.h" |
21 #include "net/url_request/url_request_test_util.h" | 20 #include "net/url_request/url_request_test_util.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
23 | 22 |
24 using content::BrowserThread; | 23 using content::BrowserThread; |
25 | 24 |
26 namespace component_updater { | 25 namespace component_updater { |
27 | 26 |
28 namespace { | 27 namespace { |
29 | 28 |
30 base::FilePath test_file(const char* file) { | 29 base::FilePath test_file(const char* file) { |
31 base::FilePath path; | 30 base::FilePath path; |
32 PathService::Get(chrome::DIR_TEST_DATA, &path); | 31 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
33 return path.AppendASCII("components").AppendASCII(file); | 32 return path.AppendASCII("components").AppendASCII("test").AppendASCII("data") |
| 33 .AppendASCII("component_updater").AppendASCII(file); |
34 } | 34 } |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 class UpdateCheckerTest : public testing::Test { | 38 class UpdateCheckerTest : public testing::Test { |
39 public: | 39 public: |
40 UpdateCheckerTest(); | 40 UpdateCheckerTest(); |
41 virtual ~UpdateCheckerTest(); | 41 virtual ~UpdateCheckerTest(); |
42 | 42 |
43 // Overrides from testing::Test. | 43 // Overrides from testing::Test. |
(...skipping 17 matching lines...) Expand all Loading... |
61 | 61 |
62 scoped_ptr<InterceptorFactory> interceptor_factory_; | 62 scoped_ptr<InterceptorFactory> interceptor_factory_; |
63 URLRequestPostInterceptor* post_interceptor_; // Owned by the factory. | 63 URLRequestPostInterceptor* post_interceptor_; // Owned by the factory. |
64 | 64 |
65 int error_; | 65 int error_; |
66 std::string error_message_; | 66 std::string error_message_; |
67 UpdateResponse::Results results_; | 67 UpdateResponse::Results results_; |
68 | 68 |
69 private: | 69 private: |
70 content::TestBrowserThreadBundle thread_bundle_; | 70 content::TestBrowserThreadBundle thread_bundle_; |
71 base::FilePath test_data_dir_; | |
72 base::Closure quit_closure_; | 71 base::Closure quit_closure_; |
73 | 72 |
74 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerTest); | 73 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerTest); |
75 }; | 74 }; |
76 | 75 |
77 UpdateCheckerTest::UpdateCheckerTest() | 76 UpdateCheckerTest::UpdateCheckerTest() |
78 : config_(new TestConfigurator), | 77 : config_(new TestConfigurator), |
79 error_(0), | 78 error_(0), |
80 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { | 79 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
81 // The test directory is chrome/test/data/components. | |
82 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); | |
83 test_data_dir_ = test_data_dir_.AppendASCII("components"); | |
84 | |
85 net::URLFetcher::SetEnableInterceptionForTests(true); | 80 net::URLFetcher::SetEnableInterceptionForTests(true); |
86 } | 81 } |
87 | 82 |
88 UpdateCheckerTest::~UpdateCheckerTest() { | 83 UpdateCheckerTest::~UpdateCheckerTest() { |
89 net::URLFetcher::SetEnableInterceptionForTests(false); | 84 net::URLFetcher::SetEnableInterceptionForTests(false); |
90 } | 85 } |
91 | 86 |
92 void UpdateCheckerTest::SetUp() { | 87 void UpdateCheckerTest::SetUp() { |
93 interceptor_factory_.reset(new InterceptorFactory); | 88 interceptor_factory_.reset(new InterceptorFactory); |
94 post_interceptor_ = interceptor_factory_->CreateInterceptor(); | 89 post_interceptor_ = interceptor_factory_->CreateInterceptor(); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 << post_interceptor_->GetRequestsAsString(); | 222 << post_interceptor_->GetRequestsAsString(); |
228 EXPECT_EQ(1, post_interceptor_->GetCount()) | 223 EXPECT_EQ(1, post_interceptor_->GetCount()) |
229 << post_interceptor_->GetRequestsAsString(); | 224 << post_interceptor_->GetRequestsAsString(); |
230 | 225 |
231 EXPECT_NE(0, error_); | 226 EXPECT_NE(0, error_); |
232 EXPECT_STREQ("network error", error_message_.c_str()); | 227 EXPECT_STREQ("network error", error_message_.c_str()); |
233 EXPECT_EQ(0ul, results_.list.size()); | 228 EXPECT_EQ(0ul, results_.list.size()); |
234 } | 229 } |
235 | 230 |
236 } // namespace component_updater | 231 } // namespace component_updater |
OLD | NEW |