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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 1956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1967 base::Bind(&DataCallbackFake::Callback), | 1967 base::Bind(&DataCallbackFake::Callback), |
1968 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 1968 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
1969 | 1969 |
1970 RunThreads(); | 1970 RunThreads(); |
1971 | 1971 |
1972 update_client->RemoveObserver(&observer); | 1972 update_client->RemoveObserver(&observer); |
1973 | 1973 |
1974 StopWorkerPool(); | 1974 StopWorkerPool(); |
1975 } | 1975 } |
1976 | 1976 |
| 1977 // Tests that overlapping installs of the same CRX result in an error. |
| 1978 TEST_F(UpdateClientTest, ConcurrentInstallSameCRX) { |
| 1979 class DataCallbackFake { |
| 1980 public: |
| 1981 static void Callback(const std::vector<std::string>& ids, |
| 1982 std::vector<CrxComponent>* components) { |
| 1983 CrxComponent crx; |
| 1984 crx.name = "test_jebg"; |
| 1985 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 1986 crx.version = Version("0.0"); |
| 1987 crx.installer = new TestInstaller; |
| 1988 |
| 1989 components->push_back(crx); |
| 1990 } |
| 1991 }; |
| 1992 |
| 1993 class CompletionCallbackFake { |
| 1994 public: |
| 1995 static void Callback(const base::Closure& quit_closure, int error) { |
| 1996 static int num_call = 0; |
| 1997 ++num_call; |
| 1998 |
| 1999 EXPECT_LE(num_call, 2); |
| 2000 |
| 2001 if (num_call == 1) { |
| 2002 EXPECT_EQ(Error::ERROR_UPDATE_IN_PROGRESS, error); |
| 2003 return; |
| 2004 } |
| 2005 if (num_call == 2) { |
| 2006 EXPECT_EQ(0, error); |
| 2007 quit_closure.Run(); |
| 2008 } |
| 2009 } |
| 2010 }; |
| 2011 |
| 2012 class FakeUpdateChecker : public UpdateChecker { |
| 2013 public: |
| 2014 static scoped_ptr<UpdateChecker> Create(const Configurator& config) { |
| 2015 return scoped_ptr<UpdateChecker>(new FakeUpdateChecker()); |
| 2016 } |
| 2017 |
| 2018 bool CheckForUpdates( |
| 2019 const std::vector<CrxUpdateItem*>& items_to_check, |
| 2020 const std::string& additional_attributes, |
| 2021 const UpdateCheckCallback& update_check_callback) override { |
| 2022 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 2023 FROM_HERE, base::Bind(update_check_callback, GURL(), 0, "", |
| 2024 UpdateResponse::Results())); |
| 2025 return true; |
| 2026 } |
| 2027 }; |
| 2028 |
| 2029 class FakeCrxDownloader : public CrxDownloader { |
| 2030 public: |
| 2031 static scoped_ptr<CrxDownloader> Create( |
| 2032 bool is_background_download, |
| 2033 net::URLRequestContextGetter* context_getter, |
| 2034 const scoped_refptr<base::SequencedTaskRunner>& |
| 2035 url_fetcher_task_runner) { |
| 2036 return scoped_ptr<CrxDownloader>(new FakeCrxDownloader()); |
| 2037 } |
| 2038 |
| 2039 private: |
| 2040 FakeCrxDownloader() : CrxDownloader(scoped_ptr<CrxDownloader>().Pass()) {} |
| 2041 ~FakeCrxDownloader() override {} |
| 2042 |
| 2043 void DoStartDownload(const GURL& url) override { EXPECT_TRUE(false); } |
| 2044 }; |
| 2045 |
| 2046 class FakePingManager : public FakePingManagerImpl { |
| 2047 public: |
| 2048 explicit FakePingManager(const Configurator& config) |
| 2049 : FakePingManagerImpl(config) {} |
| 2050 ~FakePingManager() override { EXPECT_TRUE(items().empty()); } |
| 2051 }; |
| 2052 |
| 2053 scoped_ptr<FakePingManager> ping_manager(new FakePingManager(*config())); |
| 2054 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( |
| 2055 config(), ping_manager.Pass(), &FakeUpdateChecker::Create, |
| 2056 &FakeCrxDownloader::Create)); |
| 2057 |
| 2058 // Verify that calling Install sets ondemand. |
| 2059 OnDemandTester ondemand_tester(update_client, true); |
| 2060 |
| 2061 MockObserver observer; |
| 2062 ON_CALL(observer, OnEvent(_, _)) |
| 2063 .WillByDefault(Invoke(&ondemand_tester, &OnDemandTester::CheckOnDemand)); |
| 2064 |
| 2065 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 2066 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2067 .Times(1); |
| 2068 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, |
| 2069 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2070 .Times(1); |
| 2071 |
| 2072 update_client->AddObserver(&observer); |
| 2073 |
| 2074 update_client->Install( |
| 2075 std::string("jebgalgnebhfojomionfpkfelancnnkf"), |
| 2076 base::Bind(&DataCallbackFake::Callback), |
| 2077 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 2078 |
| 2079 update_client->Install( |
| 2080 std::string("jebgalgnebhfojomionfpkfelancnnkf"), |
| 2081 base::Bind(&DataCallbackFake::Callback), |
| 2082 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 2083 |
| 2084 RunThreads(); |
| 2085 |
| 2086 update_client->RemoveObserver(&observer); |
| 2087 |
| 2088 StopWorkerPool(); |
| 2089 } |
| 2090 |
1977 // Make sure that we don't get any crashes when trying to update an empty list | 2091 // Make sure that we don't get any crashes when trying to update an empty list |
1978 // of ids. | 2092 // of ids. |
1979 TEST_F(UpdateClientTest, EmptyIdList) { | 2093 TEST_F(UpdateClientTest, EmptyIdList) { |
1980 class DataCallbackFake { | 2094 class DataCallbackFake { |
1981 public: | 2095 public: |
1982 static void Callback(const std::vector<std::string>& ids, | 2096 static void Callback(const std::vector<std::string>& ids, |
1983 std::vector<CrxComponent>* components) {} | 2097 std::vector<CrxComponent>* components) {} |
1984 }; | 2098 }; |
1985 | 2099 |
1986 class CompletionCallbackFake { | 2100 class CompletionCallbackFake { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2028 base::RunLoop runloop; | 2142 base::RunLoop runloop; |
2029 update_client->Update( | 2143 update_client->Update( |
2030 empty_id_list, base::Bind(&DataCallbackFake::Callback), | 2144 empty_id_list, base::Bind(&DataCallbackFake::Callback), |
2031 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); | 2145 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); |
2032 runloop.Run(); | 2146 runloop.Run(); |
2033 | 2147 |
2034 StopWorkerPool(); | 2148 StopWorkerPool(); |
2035 } | 2149 } |
2036 | 2150 |
2037 } // namespace update_client | 2151 } // namespace update_client |
OLD | NEW |