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

Side by Side Diff: chrome/browser/component_updater/test/component_updater_service_unittest.cc

Issue 508473002: Componentize component_updater: Move URLRequestPrepackagedInterceptor from content/ to net/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: run git cl format Created 6 years, 3 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "chrome/browser/component_updater/test/component_updater_service_unitte st.h" 5 #include "chrome/browser/component_updater/test/component_updater_service_unitte st.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.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/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/component_updater/component_updater_resource_throttle.h " 16 #include "chrome/browser/component_updater/component_updater_resource_throttle.h "
17 #include "chrome/browser/component_updater/test/test_configurator.h"
18 #include "chrome/browser/component_updater/test/test_installer.h"
19 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
20 #include "components/component_updater/component_updater_utils.h" 18 #include "components/component_updater/component_updater_utils.h"
19 #include "components/component_updater/test/test_configurator.h"
20 #include "components/component_updater/test/test_installer.h"
21 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/resource_controller.h" 22 #include "content/public/browser/resource_controller.h"
23 #include "content/public/browser/resource_request_info.h" 23 #include "content/public/browser/resource_request_info.h"
24 #include "content/public/browser/resource_throttle.h" 24 #include "content/public/browser/resource_throttle.h"
25 #include "libxml/globals.h" 25 #include "libxml/globals.h"
26 #include "net/base/upload_bytes_element_reader.h" 26 #include "net/base/upload_bytes_element_reader.h"
27 #include "net/url_request/url_fetcher.h" 27 #include "net/url_request/url_fetcher.h"
28 #include "net/url_request/url_request_test_util.h" 28 #include "net/url_request/url_request_test_util.h"
29 #include "url/gurl.h" 29 #include "url/gurl.h"
30 30
31 using content::BrowserThread; 31 using content::BrowserThread;
32 32
33 using ::testing::_; 33 using ::testing::_;
34 using ::testing::AnyNumber; 34 using ::testing::AnyNumber;
35 using ::testing::InSequence; 35 using ::testing::InSequence;
36 using ::testing::Mock; 36 using ::testing::Mock;
37 37
38 namespace component_updater { 38 namespace component_updater {
39 39
40 MockServiceObserver::MockServiceObserver() { 40 MockServiceObserver::MockServiceObserver() {
41 } 41 }
42 42
43 MockServiceObserver::~MockServiceObserver() { 43 MockServiceObserver::~MockServiceObserver() {
44 } 44 }
45 45
46 bool PartialMatch::Match(const std::string& actual) const {
47 return actual.find(expected_) != std::string::npos;
48 }
49
50 InterceptorFactory::InterceptorFactory()
51 : URLRequestPostInterceptorFactory(POST_INTERCEPT_SCHEME,
52 POST_INTERCEPT_HOSTNAME) {
53 }
54
55 InterceptorFactory::~InterceptorFactory() {
56 }
57
58 URLRequestPostInterceptor* InterceptorFactory::CreateInterceptor() {
59 return URLRequestPostInterceptorFactory::CreateInterceptor(
60 base::FilePath::FromUTF8Unsafe(POST_INTERCEPT_PATH));
61 }
62
63 ComponentUpdaterTest::ComponentUpdaterTest() 46 ComponentUpdaterTest::ComponentUpdaterTest()
64 : test_config_(NULL), 47 : test_config_(NULL),
65 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { 48 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
66 // The component updater instance under test. 49 // The component updater instance under test.
67 test_config_ = new TestConfigurator; 50 test_config_ = new TestConfigurator;
68 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); 51 component_updater_.reset(ComponentUpdateServiceFactory(test_config_));
69 52
70 // The test directory is chrome/test/data/components.
71 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_);
72 test_data_dir_ = test_data_dir_.AppendASCII("components");
73
74 net::URLFetcher::SetEnableInterceptionForTests(true); 53 net::URLFetcher::SetEnableInterceptionForTests(true);
75 } 54 }
76 55
77 ComponentUpdaterTest::~ComponentUpdaterTest() { 56 ComponentUpdaterTest::~ComponentUpdaterTest() {
78 net::URLFetcher::SetEnableInterceptionForTests(false); 57 net::URLFetcher::SetEnableInterceptionForTests(false);
79 } 58 }
80 59
81 void ComponentUpdaterTest::SetUp() { 60 void ComponentUpdaterTest::SetUp() {
82 get_interceptor_.reset(new GetInterceptor); 61 get_interceptor_.reset(new GetInterceptor(
62 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
63 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
64 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
83 interceptor_factory_.reset(new InterceptorFactory); 65 interceptor_factory_.reset(new InterceptorFactory);
84 post_interceptor_ = interceptor_factory_->CreateInterceptor(); 66 post_interceptor_ = interceptor_factory_->CreateInterceptor();
85 EXPECT_TRUE(post_interceptor_); 67 EXPECT_TRUE(post_interceptor_);
86 } 68 }
87 69
88 void ComponentUpdaterTest::TearDown() { 70 void ComponentUpdaterTest::TearDown() {
89 interceptor_factory_.reset(); 71 interceptor_factory_.reset();
90 get_interceptor_.reset(); 72 get_interceptor_.reset();
91 xmlCleanupGlobals(); 73 xmlCleanupGlobals();
92 } 74 }
93 75
94 ComponentUpdateService* ComponentUpdaterTest::component_updater() { 76 ComponentUpdateService* ComponentUpdaterTest::component_updater() {
95 return component_updater_.get(); 77 return component_updater_.get();
96 } 78 }
97 79
98 // Makes the full path to a component updater test file. 80 // Makes the full path to a component updater test file.
99 const base::FilePath ComponentUpdaterTest::test_file(const char* file) { 81 const base::FilePath ComponentUpdaterTest::test_file(const char* file) {
100 return test_data_dir_.AppendASCII(file); 82 base::FilePath path;
83 PathService::Get(base::DIR_SOURCE_ROOT, &path);
84 return path.AppendASCII("components")
85 .AppendASCII("test")
86 .AppendASCII("data")
87 .AppendASCII("component_updater")
88 .AppendASCII(file);
101 } 89 }
102 90
103 TestConfigurator* ComponentUpdaterTest::test_configurator() { 91 TestConfigurator* ComponentUpdaterTest::test_configurator() {
104 return test_config_; 92 return test_config_;
105 } 93 }
106 94
107 ComponentUpdateService::Status ComponentUpdaterTest::RegisterComponent( 95 ComponentUpdateService::Status ComponentUpdaterTest::RegisterComponent(
108 CrxComponent* com, 96 CrxComponent* com,
109 TestComponents component, 97 TestComponents component,
110 const Version& version, 98 const Version& version,
(...skipping 1385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 component_updater()->RemoveObserver(&observer2); 1484 component_updater()->RemoveObserver(&observer2);
1497 1485
1498 test_configurator()->SetLoopCount(1); 1486 test_configurator()->SetLoopCount(1);
1499 component_updater()->Start(); 1487 component_updater()->Start();
1500 RunThreads(); 1488 RunThreads();
1501 1489
1502 component_updater()->Stop(); 1490 component_updater()->Stop();
1503 } 1491 }
1504 1492
1505 } // namespace component_updater 1493 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698