OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/message_loop/message_loop.h" |
6 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
7 #include "base/version.h" | 8 #include "base/version.h" |
8 #include "components/component_updater/component_updater_ping_manager.h" | 9 #include "components/component_updater/component_updater_ping_manager.h" |
9 #include "components/component_updater/crx_update_item.h" | 10 #include "components/component_updater/crx_update_item.h" |
10 #include "components/component_updater/test/test_configurator.h" | 11 #include "components/component_updater/test/test_configurator.h" |
11 #include "components/component_updater/test/url_request_post_interceptor.h" | 12 #include "components/component_updater/test/url_request_post_interceptor.h" |
12 #include "content/public/browser/browser_thread.h" | |
13 #include "content/public/test/test_browser_thread_bundle.h" | |
14 #include "net/url_request/url_request_test_util.h" | 13 #include "net/url_request/url_request_test_util.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 | 15 |
17 using content::BrowserThread; | |
18 | |
19 namespace component_updater { | 16 namespace component_updater { |
20 | 17 |
21 class ComponentUpdaterPingManagerTest : public testing::Test { | 18 class ComponentUpdaterPingManagerTest : public testing::Test { |
22 public: | 19 public: |
23 ComponentUpdaterPingManagerTest(); | 20 ComponentUpdaterPingManagerTest(); |
24 virtual ~ComponentUpdaterPingManagerTest() {} | 21 virtual ~ComponentUpdaterPingManagerTest() {} |
25 | 22 |
26 void RunThreadsUntilIdle(); | 23 void RunThreadsUntilIdle(); |
27 | 24 |
28 // Overrides from testing::Test. | 25 // Overrides from testing::Test. |
29 virtual void SetUp() OVERRIDE; | 26 virtual void SetUp() OVERRIDE; |
30 virtual void TearDown() OVERRIDE; | 27 virtual void TearDown() OVERRIDE; |
31 | 28 |
32 protected: | 29 protected: |
33 scoped_ptr<TestConfigurator> config_; | 30 scoped_ptr<TestConfigurator> config_; |
34 scoped_ptr<PingManager> ping_manager_; | 31 scoped_ptr<PingManager> ping_manager_; |
35 | 32 |
36 private: | 33 private: |
37 content::TestBrowserThreadBundle thread_bundle_; | 34 base::MessageLoopForIO loop_; |
38 }; | 35 }; |
39 | 36 |
40 ComponentUpdaterPingManagerTest::ComponentUpdaterPingManagerTest() | 37 ComponentUpdaterPingManagerTest::ComponentUpdaterPingManagerTest() |
41 : config_(new TestConfigurator), | 38 : config_(new TestConfigurator(base::MessageLoopProxy::current(), |
42 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { | 39 base::MessageLoopProxy::current())) { |
43 } | 40 } |
44 | 41 |
45 void ComponentUpdaterPingManagerTest::SetUp() { | 42 void ComponentUpdaterPingManagerTest::SetUp() { |
46 ping_manager_.reset(new PingManager(*config_)); | 43 ping_manager_.reset(new PingManager(*config_)); |
47 } | 44 } |
48 | 45 |
49 void ComponentUpdaterPingManagerTest::TearDown() { | 46 void ComponentUpdaterPingManagerTest::TearDown() { |
50 ping_manager_.reset(); | 47 ping_manager_.reset(); |
51 config_.reset(); | 48 config_.reset(); |
52 } | 49 } |
53 | 50 |
54 void ComponentUpdaterPingManagerTest::RunThreadsUntilIdle() { | 51 void ComponentUpdaterPingManagerTest::RunThreadsUntilIdle() { |
55 base::RunLoop().RunUntilIdle(); | 52 base::RunLoop().RunUntilIdle(); |
56 } | 53 } |
57 | 54 |
58 // Test is flaky: http://crbug.com/349547 | 55 // Test is flaky: http://crbug.com/349547 |
59 TEST_F(ComponentUpdaterPingManagerTest, DISABLED_PingManagerTest) { | 56 TEST_F(ComponentUpdaterPingManagerTest, DISABLED_PingManagerTest) { |
60 scoped_ptr<InterceptorFactory> interceptor_factory(new InterceptorFactory); | 57 scoped_ptr<InterceptorFactory> interceptor_factory( |
| 58 new InterceptorFactory(base::MessageLoopProxy::current())); |
61 URLRequestPostInterceptor* interceptor = | 59 URLRequestPostInterceptor* interceptor = |
62 interceptor_factory->CreateInterceptor(); | 60 interceptor_factory->CreateInterceptor(); |
63 EXPECT_TRUE(interceptor); | 61 EXPECT_TRUE(interceptor); |
64 | 62 |
65 // Test eventresult="1" is sent for successful updates. | 63 // Test eventresult="1" is sent for successful updates. |
66 CrxUpdateItem item; | 64 CrxUpdateItem item; |
67 item.id = "abc"; | 65 item.id = "abc"; |
68 item.status = CrxUpdateItem::kUpdated; | 66 item.status = CrxUpdateItem::kUpdated; |
69 item.previous_version = base::Version("1.0"); | 67 item.previous_version = base::Version("1.0"); |
70 item.next_version = base::Version("2.0"); | 68 item.next_version = base::Version("2.0"); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 "errorcode=\"-1\" url=\"http://host1/path1\" downloaded=\"123\" " | 166 "errorcode=\"-1\" url=\"http://host1/path1\" downloaded=\"123\" " |
169 "total=\"456\" download_time_ms=\"987\"/>" | 167 "total=\"456\" download_time_ms=\"987\"/>" |
170 "<event eventtype=\"14\" eventresult=\"1\" downloader=\"bits\" " | 168 "<event eventtype=\"14\" eventresult=\"1\" downloader=\"bits\" " |
171 "url=\"http://host2/path2\" downloaded=\"1230\" total=\"4560\" " | 169 "url=\"http://host2/path2\" downloaded=\"1230\" total=\"4560\" " |
172 "download_time_ms=\"9870\"/></app>")) | 170 "download_time_ms=\"9870\"/></app>")) |
173 << interceptor->GetRequestsAsString(); | 171 << interceptor->GetRequestsAsString(); |
174 interceptor->Reset(); | 172 interceptor->Reset(); |
175 } | 173 } |
176 | 174 |
177 } // namespace component_updater | 175 } // namespace component_updater |
OLD | NEW |