Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 "content/browser/background_fetch/background_fetch_batch_manager.h" | |
| 6 | |
| 7 #include "base/bind_helpers.h" | |
| 8 #include "base/callback_helpers.h" | |
| 9 #include "base/run_loop.h" | |
| 10 #include "content/browser/background_fetch/fetch_request.h" | |
| 11 #include "content/public/browser/browser_thread.h" | |
| 12 #include "content/public/test/mock_download_manager.h" | |
| 13 #include "content/public/test/test_browser_context.h" | |
| 14 #include "content/public/test/test_browser_thread_bundle.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 const char kOrigin[] = "https://example.com/"; | |
| 20 const char kBatchUid[] = "TestRequestUid"; | |
| 21 constexpr int64_t kServiceWorkerRegistrationId = 9001; | |
| 22 const char kTestUrl[] = "http://www.example.com/example.html"; | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 namespace content { | |
| 27 | |
| 28 class BackgroundFetchBatchManagerTest : public ::testing::Test { | |
| 29 public: | |
| 30 BackgroundFetchBatchManagerTest() | |
| 31 : batch_manager_( | |
| 32 &browser_context_, | |
| 33 BrowserContext::GetDefaultStoragePartition(&browser_context_)), | |
| 34 download_manager_(new content::MockDownloadManager()) { | |
|
Peter Beverloo
2017/02/23 12:14:56
nit: drop `content::`
harkness
2017/02/23 17:08:41
Done.
| |
| 35 BrowserContext::SetDownloadManagerForTesting(&browser_context_, | |
| 36 download_manager_); | |
| 37 } | |
| 38 ~BackgroundFetchBatchManagerTest() override {} | |
| 39 | |
| 40 void ProcessBatch(const std::string& batch_uid, | |
| 41 const std::vector<FetchRequest>& requests) { | |
| 42 base::RunLoop run_loop; | |
| 43 BrowserThread::PostTask( | |
| 44 BrowserThread::IO, FROM_HERE, | |
| 45 base::Bind(&BackgroundFetchBatchManagerTest::ProcessBatchOnIO, | |
| 46 base::Unretained(this), batch_uid, requests, | |
| 47 run_loop.QuitClosure())); | |
| 48 run_loop.Run(); | |
| 49 } | |
| 50 | |
| 51 void ProcessBatchOnIO(const std::string& batch_uid, | |
| 52 const std::vector<FetchRequest>& requests, | |
| 53 const base::Closure& closure) { | |
| 54 batch_manager_.ProcessBatch(batch_uid, requests); | |
| 55 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, closure); | |
| 56 } | |
| 57 | |
| 58 BackgroundFetchBatchManager* GetBatchManager() { return &batch_manager_; } | |
|
Peter Beverloo
2017/02/23 12:14:59
nit: batch_manager() const { .. }
harkness
2017/02/23 17:08:41
Done.
| |
| 59 MockDownloadManager* GetDownloadManager() { return download_manager_; } | |
|
Peter Beverloo
2017/02/23 12:14:56
nit: download_manager() const { .. }
harkness
2017/02/23 17:08:41
Done.
| |
| 60 | |
| 61 private: | |
| 62 TestBrowserThreadBundle thread_bundle_; | |
| 63 TestBrowserContext browser_context_; | |
| 64 BackgroundFetchBatchManager batch_manager_; | |
| 65 MockDownloadManager* download_manager_; | |
| 66 }; | |
| 67 | |
| 68 TEST_F(BackgroundFetchBatchManagerTest, StartDownload) { | |
| 69 FetchRequest request(url::Origin(GURL(kOrigin)), GURL(kTestUrl), | |
| 70 kServiceWorkerRegistrationId, kBatchUid); | |
|
Peter Beverloo
2017/02/23 12:14:56
What is a "uid"?
harkness
2017/02/23 17:08:41
An imprecise statement of a guid. I've updated.
| |
| 71 std::vector<FetchRequest> requests; | |
| 72 requests.push_back(request); | |
| 73 | |
| 74 EXPECT_CALL(*(GetDownloadManager()), | |
| 75 DownloadUrlMock(::testing::Pointee(::testing::Property( | |
| 76 &DownloadUrlParameters::url, GURL(kTestUrl))))) | |
| 77 .Times(1); | |
| 78 ProcessBatch(kBatchUid, requests); | |
| 79 } | |
| 80 | |
| 81 } // namespace content | |
| OLD | NEW |