1a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// found in the LICENSE file.
4a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
5a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/bind.h"
61320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/bind_helpers.h"
7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/files/file_path.h"
81320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/files/file_util.h"
9a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/memory/ref_counted.h"
10a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/message_loop/message_loop.h"
12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/path_service.h"
13a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/run_loop.h"
1403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "components/component_updater/crx_downloader.h"
15a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "net/base/net_errors.h"
161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "net/url_request/test_url_request_interceptor.h"
17a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "net/url_request/url_request_test_util.h"
18a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuusing base::ContentsEqual;
21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)namespace component_updater {
23a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
24a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)namespace {
25a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
26a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Intercepts HTTP GET requests sent to "localhost".
271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccitypedef net::LocalHostTestURLRequestInterceptor GetInterceptor;
28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
295c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuconst char kTestFileName[] = "jebgalgnebhfojomionfpkfelancnnkf.crx";
305c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liubase::FilePath MakeTestFilePath(const char* file) {
32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::FilePath path;
331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  PathService::Get(base::DIR_SOURCE_ROOT, &path);
341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return path.AppendASCII("components").AppendASCII("test").AppendASCII("data")
351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      .AppendASCII("component_updater").AppendASCII(file);
36a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}  // namespace
39a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
40a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class CrxDownloaderTest : public testing::Test {
41a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public:
42a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  CrxDownloaderTest();
43a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual ~CrxDownloaderTest();
44a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
45a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Overrides from testing::Test.
46a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void SetUp() OVERRIDE;
47a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void TearDown() OVERRIDE;
48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
49a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void Quit();
50a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void RunThreads();
51a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void RunThreadsUntilIdle();
52a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
53a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void DownloadComplete(int crx_context, const CrxDownloader::Result& result);
54a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
55010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void DownloadProgress(int crx_context, const CrxDownloader::Result& result);
56010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
57a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) protected:
58a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  scoped_ptr<CrxDownloader> crx_downloader_;
59a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  scoped_ptr<GetInterceptor> get_interceptor_;
611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
625c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  CrxDownloader::DownloadCallback callback_;
63010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  CrxDownloader::ProgressCallback progress_callback_;
645c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
65a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  int crx_context_;
66a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
675c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  int num_download_complete_calls_;
685c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  CrxDownloader::Result download_complete_result_;
69a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
70010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // These members are updated by DownloadProgress.
71010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  int num_progress_calls_;
72010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  CrxDownloader::Result download_progress_result_;
73010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
74a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // A magic value for the context to be used in the tests.
75a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  static const int kExpectedContext = 0xaabb;
76a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
77a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) private:
781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  base::MessageLoopForIO loop_;
79a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  scoped_refptr<net::TestURLRequestContextGetter> context_;
80a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::Closure quit_closure_;
81a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)};
82a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
83a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)const int CrxDownloaderTest::kExpectedContext;
84a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
85a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)CrxDownloaderTest::CrxDownloaderTest()
865c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    : callback_(base::Bind(&CrxDownloaderTest::DownloadComplete,
875c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                           base::Unretained(this),
885c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                           kExpectedContext)),
89010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      progress_callback_(base::Bind(&CrxDownloaderTest::DownloadProgress,
90010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                                    base::Unretained(this),
91010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                                    kExpectedContext)),
925c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      crx_context_(0),
935c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      num_download_complete_calls_(0),
94010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      num_progress_calls_(0),
95a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      context_(new net::TestURLRequestContextGetter(
961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci          base::MessageLoopProxy::current())) {
97a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
98a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
99a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)CrxDownloaderTest::~CrxDownloaderTest() {
1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  context_ = NULL;
1011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // The GetInterceptor requires the message loop to run to destruct correctly.
1031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  get_interceptor_.reset();
1041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  RunThreadsUntilIdle();
105a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
106a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
107a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void CrxDownloaderTest::SetUp() {
1085c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  num_download_complete_calls_ = 0;
1095c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  download_complete_result_ = CrxDownloader::Result();
110010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  num_progress_calls_ = 0;
111010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  download_progress_result_ = CrxDownloader::Result();
1121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
113a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  crx_downloader_.reset(CrxDownloader::Create(
114010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      false,  // Do not use the background downloader in these tests.
115a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      context_.get(),
1161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      base::MessageLoopProxy::current(),
1171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      NULL));  // No |background_task_runner| because no background downloader.
118010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  crx_downloader_->set_progress_callback(progress_callback_);
1191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  get_interceptor_.reset(new GetInterceptor(base::MessageLoopProxy::current(),
1211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                            base::MessageLoopProxy::current()));
122a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
123a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
124a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void CrxDownloaderTest::TearDown() {
125010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  crx_downloader_.reset();
126a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
127a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
128a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void CrxDownloaderTest::Quit() {
1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!quit_closure_.is_null())
1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    quit_closure_.Run();
131a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
132a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1335c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuvoid CrxDownloaderTest::DownloadComplete(int crx_context,
1345c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                                         const CrxDownloader::Result& result) {
1355c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  ++num_download_complete_calls_;
136a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  crx_context_ = crx_context;
1375c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  download_complete_result_ = result;
138a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Quit();
139a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
140a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
141010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void CrxDownloaderTest::DownloadProgress(int crx_context,
142010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                                         const CrxDownloader::Result& result) {
143010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  ++num_progress_calls_;
144010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  download_progress_result_ = result;
145010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
146010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
147a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void CrxDownloaderTest::RunThreads() {
148a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::RunLoop runloop;
149a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  quit_closure_ = runloop.QuitClosure();
150a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  runloop.Run();
151a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
152a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Since some tests need to drain currently enqueued tasks such as network
153a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // intercepts on the IO thread, run the threads until they are
154a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // idle. The component updater service won't loop again until the loop count
155a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // is set and the service is started.
156a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  RunThreadsUntilIdle();
157a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
158a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
159a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void CrxDownloaderTest::RunThreadsUntilIdle() {
160a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::RunLoop().RunUntilIdle();
161a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
162a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Tests that starting a download without a url results in an error.
1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(CrxDownloaderTest, NoUrl) {
1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::vector<GURL> urls;
1665c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  crx_downloader_->StartDownload(urls, callback_);
1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  RunThreadsUntilIdle();
1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1695c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(1, num_download_complete_calls_);
1705c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(kExpectedContext, crx_context_);
1715c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(-1, download_complete_result_.error);
1725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_TRUE(download_complete_result_.response.empty());
173010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(-1, download_complete_result_.downloaded_bytes);
174010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(-1, download_complete_result_.total_bytes);
175010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(0, num_progress_calls_);
1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
178a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Tests that downloading from one url is successful.
179a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)TEST_F(CrxDownloaderTest, OneUrl) {
180a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  const GURL expected_crx_url =
181010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
182a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1835c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  const base::FilePath test_file(MakeTestFilePath(kTestFileName));
1841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  get_interceptor_->SetResponse(expected_crx_url, test_file);
185a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1865c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  crx_downloader_->StartDownloadFromUrl(expected_crx_url, callback_);
187a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  RunThreads();
1885c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(1, get_interceptor_->GetHitCount());
1905c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1915c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(1, num_download_complete_calls_);
192a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(kExpectedContext, crx_context_);
1935c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(0, download_complete_result_.error);
194010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
195010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(1843, download_complete_result_.total_bytes);
1965c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file));
197a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1985c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false));
199010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
200010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_LE(1, num_progress_calls_);
201010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
202010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(1843, download_progress_result_.total_bytes);
203a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
204a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
205a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Tests that specifying from two urls has no side effects. Expect a successful
206a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// download, and only one download request be made.
2070529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// This test is flaky on Android. crbug.com/329883
2080529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#if defined(OS_ANDROID)
2090529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#define MAYBE_TwoUrls DISABLED_TwoUrls
2100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#else
2110529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#define MAYBE_TwoUrls TwoUrls
2120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#endif
2130529e5d033099cbfc42635f6f6183833b09dff6eBen MurdochTEST_F(CrxDownloaderTest, MAYBE_TwoUrls) {
214a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  const GURL expected_crx_url =
215010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
216a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  const base::FilePath test_file(MakeTestFilePath(kTestFileName));
2181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  get_interceptor_->SetResponse(expected_crx_url, test_file);
219a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
220a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  std::vector<GURL> urls;
221a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  urls.push_back(expected_crx_url);
222a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  urls.push_back(expected_crx_url);
223a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  crx_downloader_->StartDownload(urls, callback_);
225a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  RunThreads();
2265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
2271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(1, get_interceptor_->GetHitCount());
2285c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
2295c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(1, num_download_complete_calls_);
230a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(kExpectedContext, crx_context_);
2315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(0, download_complete_result_.error);
232010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
233010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(1843, download_complete_result_.total_bytes);
2345c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file));
235a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2365c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false));
237010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
238010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_LE(1, num_progress_calls_);
239010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
240010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(1843, download_progress_result_.total_bytes);
241a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
242a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
243a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Tests that an invalid host results in a download error.
244a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)TEST_F(CrxDownloaderTest, OneUrl_InvalidHost) {
245a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  const GURL expected_crx_url =
246010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
247a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  const base::FilePath test_file(MakeTestFilePath(kTestFileName));
2491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  get_interceptor_->SetResponse(expected_crx_url, test_file);
250a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
251a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  crx_downloader_->StartDownloadFromUrl(
252a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      GURL("http://no.such.host"
2535c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu           "/download/jebgalgnebhfojomionfpkfelancnnkf.crx"),
2545c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      callback_);
255a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  RunThreads();
2565c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
2571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(0, get_interceptor_->GetHitCount());
258a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2595c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(1, num_download_complete_calls_);
2605c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(kExpectedContext, crx_context_);
2615c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_NE(0, download_complete_result_.error);
2625c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_TRUE(download_complete_result_.response.empty());
263a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
264a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
265a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Tests that an invalid path results in a download error.
266a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)TEST_F(CrxDownloaderTest, OneUrl_InvalidPath) {
267a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  const GURL expected_crx_url =
268010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
269a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2705c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  const base::FilePath test_file(MakeTestFilePath(kTestFileName));
2711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  get_interceptor_->SetResponse(expected_crx_url, test_file);
272a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
273010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  crx_downloader_->StartDownloadFromUrl(GURL("http://localhost/no/such/file"),
274010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                                        callback_);
275a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  RunThreads();
2765c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
2771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(0, get_interceptor_->GetHitCount());
278a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2795c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(1, num_download_complete_calls_);
2805c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(kExpectedContext, crx_context_);
2815c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_NE(0, download_complete_result_.error);
2825c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_TRUE(download_complete_result_.response.empty());
283a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
284a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
285a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Tests that the fallback to a valid url is successful.
2860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// This test is flaky on Android. crbug.com/329883
2870529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#if defined(OS_ANDROID)
2880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#define MAYBE_TwoUrls_FirstInvalid DISABLED_TwoUrls_FirstInvalid
2890529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#else
2900529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#define MAYBE_TwoUrls_FirstInvalid TwoUrls_FirstInvalid
2910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#endif
2920529e5d033099cbfc42635f6f6183833b09dff6eBen MurdochTEST_F(CrxDownloaderTest, MAYBE_TwoUrls_FirstInvalid) {
293a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  const GURL expected_crx_url =
294010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
295a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2965c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  const base::FilePath test_file(MakeTestFilePath(kTestFileName));
2971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  get_interceptor_->SetResponse(expected_crx_url, test_file);
298a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
299a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  std::vector<GURL> urls;
300a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  urls.push_back(GURL("http://localhost/no/such/file"));
301a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  urls.push_back(expected_crx_url);
302a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
3035c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  crx_downloader_->StartDownload(urls, callback_);
304a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  RunThreads();
3055c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
3061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(1, get_interceptor_->GetHitCount());
3075c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
3085c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(1, num_download_complete_calls_);
309a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(kExpectedContext, crx_context_);
3105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(0, download_complete_result_.error);
311010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
312010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(1843, download_complete_result_.total_bytes);
3135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file));
314a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
3155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false));
316010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
317010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_LE(1, num_progress_calls_);
318010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
319010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(1843, download_progress_result_.total_bytes);
320a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
321a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
322a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Tests that the download succeeds if the first url is correct and the
323a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// second bad url does not have a side-effect.
324a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)TEST_F(CrxDownloaderTest, TwoUrls_SecondInvalid) {
325a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  const GURL expected_crx_url =
326010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
327a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
3285c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  const base::FilePath test_file(MakeTestFilePath(kTestFileName));
3291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  get_interceptor_->SetResponse(expected_crx_url, test_file);
330a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
331a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  std::vector<GURL> urls;
332a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  urls.push_back(expected_crx_url);
333a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  urls.push_back(GURL("http://localhost/no/such/file"));
334a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
3355c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  crx_downloader_->StartDownload(urls, callback_);
336a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  RunThreads();
3375c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
3381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(1, get_interceptor_->GetHitCount());
3395c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
3405c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(1, num_download_complete_calls_);
341a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(kExpectedContext, crx_context_);
3425c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(0, download_complete_result_.error);
343010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
344010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(1843, download_complete_result_.total_bytes);
3455c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file));
346a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
3475c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false));
348010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
349010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_LE(1, num_progress_calls_);
350010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
351010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(1843, download_progress_result_.total_bytes);
352a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
353a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
354a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Tests that the download fails if both urls are bad.
355a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)TEST_F(CrxDownloaderTest, TwoUrls_BothInvalid) {
356a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  const GURL expected_crx_url =
357010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
358a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
3595c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  const base::FilePath test_file(MakeTestFilePath(kTestFileName));
3601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  get_interceptor_->SetResponse(expected_crx_url, test_file);
361a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
362a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  std::vector<GURL> urls;
363a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  urls.push_back(GURL("http://localhost/no/such/file"));
364a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  urls.push_back(GURL("http://no.such.host/"
365a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                      "/download/jebgalgnebhfojomionfpkfelancnnkf.crx"));
366a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
3675c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  crx_downloader_->StartDownload(urls, callback_);
368a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  RunThreads();
3695c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
3701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(0, get_interceptor_->GetHitCount());
371a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
3725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(1, num_download_complete_calls_);
3735c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(kExpectedContext, crx_context_);
3745c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_NE(0, download_complete_result_.error);
3755c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_TRUE(download_complete_result_.response.empty());
376a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
377a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
378a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}  // namespace component_updater
379