OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/memory/scoped_ptr.h" | |
6 #include "base/message_loop/message_loop.h" | |
7 #include "base/run_loop.h" | |
8 #include "base/version.h" | |
9 #include "components/component_updater/component_updater_ping_manager.h" | |
10 #include "components/component_updater/crx_update_item.h" | |
11 #include "components/component_updater/test/test_configurator.h" | |
12 #include "components/component_updater/test/url_request_post_interceptor.h" | |
13 #include "net/url_request/url_request_test_util.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 | |
16 using std::string; | |
17 | |
18 namespace component_updater { | |
19 | |
20 class ComponentUpdaterPingManagerTest : public testing::Test { | |
21 public: | |
22 ComponentUpdaterPingManagerTest(); | |
23 ~ComponentUpdaterPingManagerTest() override {} | |
24 | |
25 void RunThreadsUntilIdle(); | |
26 | |
27 // Overrides from testing::Test. | |
28 void SetUp() override; | |
29 void TearDown() override; | |
30 | |
31 protected: | |
32 scoped_ptr<TestConfigurator> config_; | |
33 scoped_ptr<PingManager> ping_manager_; | |
34 | |
35 private: | |
36 base::MessageLoopForIO loop_; | |
37 }; | |
38 | |
39 ComponentUpdaterPingManagerTest::ComponentUpdaterPingManagerTest() | |
40 : config_(new TestConfigurator(base::MessageLoopProxy::current(), | |
41 base::MessageLoopProxy::current())) { | |
42 } | |
43 | |
44 void ComponentUpdaterPingManagerTest::SetUp() { | |
45 ping_manager_.reset(new PingManager(*config_)); | |
46 } | |
47 | |
48 void ComponentUpdaterPingManagerTest::TearDown() { | |
49 ping_manager_.reset(); | |
50 config_.reset(); | |
51 } | |
52 | |
53 void ComponentUpdaterPingManagerTest::RunThreadsUntilIdle() { | |
54 base::RunLoop().RunUntilIdle(); | |
55 } | |
56 | |
57 // Test is flaky: http://crbug.com/349547 | |
58 TEST_F(ComponentUpdaterPingManagerTest, DISABLED_PingManagerTest) { | |
59 scoped_ptr<InterceptorFactory> interceptor_factory( | |
60 new InterceptorFactory(base::MessageLoopProxy::current())); | |
61 URLRequestPostInterceptor* interceptor = | |
62 interceptor_factory->CreateInterceptor(); | |
63 EXPECT_TRUE(interceptor); | |
64 | |
65 // Test eventresult="1" is sent for successful updates. | |
66 CrxUpdateItem item; | |
67 item.id = "abc"; | |
68 item.status = CrxUpdateItem::kUpdated; | |
69 item.previous_version = base::Version("1.0"); | |
70 item.next_version = base::Version("2.0"); | |
71 | |
72 ping_manager_->OnUpdateComplete(&item); | |
73 base::RunLoop().RunUntilIdle(); | |
74 | |
75 EXPECT_EQ(1, interceptor->GetCount()) << interceptor->GetRequestsAsString(); | |
76 EXPECT_NE(string::npos, | |
77 interceptor->GetRequests()[0].find( | |
78 "<app appid=\"abc\" version=\"1.0\" nextversion=\"2.0\">" | |
79 "<event eventtype=\"3\" eventresult=\"1\"/></app>")) | |
80 << interceptor->GetRequestsAsString(); | |
81 interceptor->Reset(); | |
82 | |
83 // Test eventresult="0" is sent for failed updates. | |
84 item = CrxUpdateItem(); | |
85 item.id = "abc"; | |
86 item.status = CrxUpdateItem::kNoUpdate; | |
87 item.previous_version = base::Version("1.0"); | |
88 item.next_version = base::Version("2.0"); | |
89 | |
90 ping_manager_->OnUpdateComplete(&item); | |
91 base::RunLoop().RunUntilIdle(); | |
92 | |
93 EXPECT_EQ(1, interceptor->GetCount()) << interceptor->GetRequestsAsString(); | |
94 EXPECT_NE(string::npos, | |
95 interceptor->GetRequests()[0].find( | |
96 "<app appid=\"abc\" version=\"1.0\" nextversion=\"2.0\">" | |
97 "<event eventtype=\"3\" eventresult=\"0\"/></app>")) | |
98 << interceptor->GetRequestsAsString(); | |
99 interceptor->Reset(); | |
100 | |
101 // Test the error values and the fingerprints. | |
102 item = CrxUpdateItem(); | |
103 item.id = "abc"; | |
104 item.status = CrxUpdateItem::kNoUpdate; | |
105 item.previous_version = base::Version("1.0"); | |
106 item.next_version = base::Version("2.0"); | |
107 item.previous_fp = "prev fp"; | |
108 item.next_fp = "next fp"; | |
109 item.error_category = 1; | |
110 item.error_code = 2; | |
111 item.extra_code1 = -1; | |
112 item.diff_error_category = 10; | |
113 item.diff_error_code = 20; | |
114 item.diff_extra_code1 = -10; | |
115 item.diff_update_failed = true; | |
116 item.crx_diffurls.push_back(GURL("http://host/path")); | |
117 | |
118 ping_manager_->OnUpdateComplete(&item); | |
119 base::RunLoop().RunUntilIdle(); | |
120 | |
121 EXPECT_EQ(1, interceptor->GetCount()) << interceptor->GetRequestsAsString(); | |
122 EXPECT_NE(string::npos, | |
123 interceptor->GetRequests()[0].find( | |
124 "<app appid=\"abc\" version=\"1.0\" nextversion=\"2.0\">" | |
125 "<event eventtype=\"3\" eventresult=\"0\" errorcat=\"1\" " | |
126 "errorcode=\"2\" extracode1=\"-1\" diffresult=\"0\" " | |
127 "differrorcat=\"10\" " | |
128 "differrorcode=\"20\" diffextracode1=\"-10\" " | |
129 "previousfp=\"prev fp\" nextfp=\"next fp\"/></app>")) | |
130 << interceptor->GetRequestsAsString(); | |
131 interceptor->Reset(); | |
132 | |
133 // Test the download metrics. | |
134 item = CrxUpdateItem(); | |
135 item.id = "abc"; | |
136 item.status = CrxUpdateItem::kUpdated; | |
137 item.previous_version = base::Version("1.0"); | |
138 item.next_version = base::Version("2.0"); | |
139 | |
140 CrxDownloader::DownloadMetrics download_metrics; | |
141 download_metrics.url = GURL("http://host1/path1"); | |
142 download_metrics.downloader = CrxDownloader::DownloadMetrics::kUrlFetcher; | |
143 download_metrics.error = -1; | |
144 download_metrics.downloaded_bytes = 123; | |
145 download_metrics.total_bytes = 456; | |
146 download_metrics.download_time_ms = 987; | |
147 item.download_metrics.push_back(download_metrics); | |
148 | |
149 download_metrics = CrxDownloader::DownloadMetrics(); | |
150 download_metrics.url = GURL("http://host2/path2"); | |
151 download_metrics.downloader = CrxDownloader::DownloadMetrics::kBits; | |
152 download_metrics.error = 0; | |
153 download_metrics.downloaded_bytes = 1230; | |
154 download_metrics.total_bytes = 4560; | |
155 download_metrics.download_time_ms = 9870; | |
156 item.download_metrics.push_back(download_metrics); | |
157 | |
158 ping_manager_->OnUpdateComplete(&item); | |
159 base::RunLoop().RunUntilIdle(); | |
160 | |
161 EXPECT_EQ(1, interceptor->GetCount()) << interceptor->GetRequestsAsString(); | |
162 EXPECT_NE( | |
163 string::npos, | |
164 interceptor->GetRequests()[0].find( | |
165 "<app appid=\"abc\" version=\"1.0\" nextversion=\"2.0\">" | |
166 "<event eventtype=\"3\" eventresult=\"1\"/>" | |
167 "<event eventtype=\"14\" eventresult=\"0\" downloader=\"direct\" " | |
168 "errorcode=\"-1\" url=\"http://host1/path1\" downloaded=\"123\" " | |
169 "total=\"456\" download_time_ms=\"987\"/>" | |
170 "<event eventtype=\"14\" eventresult=\"1\" downloader=\"bits\" " | |
171 "url=\"http://host2/path2\" downloaded=\"1230\" total=\"4560\" " | |
172 "download_time_ms=\"9870\"/></app>")) | |
173 << interceptor->GetRequestsAsString(); | |
174 interceptor->Reset(); | |
175 } | |
176 | |
177 } // namespace component_updater | |
OLD | NEW |