OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 EXPECT_TRUE(update_client_->GetCrxUpdateState(id, &update_item)); | 90 EXPECT_TRUE(update_client_->GetCrxUpdateState(id, &update_item)); |
91 EXPECT_EQ(update_item.on_demand, expected_value_); | 91 EXPECT_EQ(update_item.on_demand, expected_value_); |
92 } | 92 } |
93 } | 93 } |
94 | 94 |
95 class FakePingManagerImpl : public PingManager { | 95 class FakePingManagerImpl : public PingManager { |
96 public: | 96 public: |
97 explicit FakePingManagerImpl(const scoped_refptr<Configurator>& config); | 97 explicit FakePingManagerImpl(const scoped_refptr<Configurator>& config); |
98 ~FakePingManagerImpl() override; | 98 ~FakePingManagerImpl() override; |
99 | 99 |
100 void OnUpdateComplete(const CrxUpdateItem* item) override; | 100 void SendPing(const CrxUpdateItem* item) override; |
101 | 101 |
102 const std::vector<CrxUpdateItem>& items() const; | 102 const std::vector<CrxUpdateItem>& items() const; |
103 | 103 |
104 private: | 104 private: |
105 std::vector<CrxUpdateItem> items_; | 105 std::vector<CrxUpdateItem> items_; |
106 DISALLOW_COPY_AND_ASSIGN(FakePingManagerImpl); | 106 DISALLOW_COPY_AND_ASSIGN(FakePingManagerImpl); |
107 }; | 107 }; |
108 | 108 |
109 FakePingManagerImpl::FakePingManagerImpl( | 109 FakePingManagerImpl::FakePingManagerImpl( |
110 const scoped_refptr<Configurator>& config) | 110 const scoped_refptr<Configurator>& config) |
111 : PingManager(config) {} | 111 : PingManager(config) {} |
112 | 112 |
113 FakePingManagerImpl::~FakePingManagerImpl() { | 113 FakePingManagerImpl::~FakePingManagerImpl() { |
114 } | 114 } |
115 | 115 |
116 void FakePingManagerImpl::OnUpdateComplete(const CrxUpdateItem* item) { | 116 void FakePingManagerImpl::SendPing(const CrxUpdateItem* item) { |
117 items_.push_back(*item); | 117 items_.push_back(*item); |
118 } | 118 } |
119 | 119 |
120 const std::vector<CrxUpdateItem>& FakePingManagerImpl::items() const { | 120 const std::vector<CrxUpdateItem>& FakePingManagerImpl::items() const { |
121 return items_; | 121 return items_; |
122 } | 122 } |
123 | 123 |
124 } // namespace | 124 } // namespace |
125 | 125 |
126 using ::testing::_; | 126 using ::testing::_; |
(...skipping 2001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2128 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create)); | 2128 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create)); |
2129 | 2129 |
2130 std::vector<std::string> empty_id_list; | 2130 std::vector<std::string> empty_id_list; |
2131 base::RunLoop runloop; | 2131 base::RunLoop runloop; |
2132 update_client->Update( | 2132 update_client->Update( |
2133 empty_id_list, base::Bind(&DataCallbackFake::Callback), | 2133 empty_id_list, base::Bind(&DataCallbackFake::Callback), |
2134 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); | 2134 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); |
2135 runloop.Run(); | 2135 runloop.Run(); |
2136 } | 2136 } |
2137 | 2137 |
| 2138 TEST_F(UpdateClientTest, SendUninstallPing) { |
| 2139 class FakeUpdateChecker : public UpdateChecker { |
| 2140 public: |
| 2141 static scoped_ptr<UpdateChecker> Create( |
| 2142 const scoped_refptr<Configurator>& config) { |
| 2143 return nullptr; |
| 2144 } |
| 2145 |
| 2146 bool CheckForUpdates( |
| 2147 const std::vector<CrxUpdateItem*>& items_to_check, |
| 2148 const std::string& additional_attributes, |
| 2149 const UpdateCheckCallback& update_check_callback) override { |
| 2150 return false; |
| 2151 } |
| 2152 }; |
| 2153 |
| 2154 class FakeCrxDownloader : public CrxDownloader { |
| 2155 public: |
| 2156 static scoped_ptr<CrxDownloader> Create( |
| 2157 bool is_background_download, |
| 2158 net::URLRequestContextGetter* context_getter, |
| 2159 const scoped_refptr<base::SequencedTaskRunner>& |
| 2160 url_fetcher_task_runner) { |
| 2161 return nullptr; |
| 2162 } |
| 2163 |
| 2164 private: |
| 2165 FakeCrxDownloader() : CrxDownloader(scoped_ptr<CrxDownloader>()) {} |
| 2166 ~FakeCrxDownloader() override {} |
| 2167 |
| 2168 void DoStartDownload(const GURL& url) override {} |
| 2169 }; |
| 2170 |
| 2171 class FakePingManager : public FakePingManagerImpl { |
| 2172 public: |
| 2173 explicit FakePingManager(const scoped_refptr<Configurator>& config) |
| 2174 : FakePingManagerImpl(config) {} |
| 2175 ~FakePingManager() override { |
| 2176 const auto& ping_items = items(); |
| 2177 EXPECT_EQ(1U, ping_items.size()); |
| 2178 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_items[0].id); |
| 2179 EXPECT_TRUE(base::Version("1.0").Equals(ping_items[0].previous_version)); |
| 2180 EXPECT_TRUE(base::Version("0.0").Equals(ping_items[0].next_version)); |
| 2181 EXPECT_EQ(10, ping_items[0].extra_code1); |
| 2182 } |
| 2183 }; |
| 2184 |
| 2185 scoped_ptr<PingManager> ping_manager(new FakePingManager(config())); |
| 2186 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( |
| 2187 config(), std::move(ping_manager), &FakeUpdateChecker::Create, |
| 2188 &FakeCrxDownloader::Create)); |
| 2189 |
| 2190 update_client->SendUninstallPing("jebgalgnebhfojomionfpkfelancnnkf", |
| 2191 base::Version("1.0"), 10); |
| 2192 } |
| 2193 |
2138 } // namespace update_client | 2194 } // namespace update_client |
OLD | NEW |