| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 <stdint.h> |
| 6 #include <string> |
| 7 |
| 8 #include "base/run_loop.h" |
| 9 #include "chrome/browser/push_messaging/background_budget_service.h" |
| 10 #include "chrome/test/base/testing_profile.h" |
| 11 #include "content/public/test/test_browser_thread_bundle.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 const char kTestOrigin[] = "https://example.com"; |
| 17 const char kTestData[] = "1111101111"; |
| 18 |
| 19 } // namespace |
| 20 |
| 21 class BackgroundBudgetServiceTest : public ::testing::Test { |
| 22 public: |
| 23 BackgroundBudgetServiceTest() {} |
| 24 ~BackgroundBudgetServiceTest() override {} |
| 25 |
| 26 void DidGetBudget(const std::string& data) { |
| 27 if (!data.empty()) |
| 28 success_ = true; |
| 29 data_ = data; |
| 30 } |
| 31 |
| 32 void DidStoreBudget(bool success) { success_ = success; } |
| 33 |
| 34 TestingProfile* profile() { return &profile_; } |
| 35 |
| 36 bool success_ = false; |
| 37 std::string data_; |
| 38 |
| 39 private: |
| 40 content::TestBrowserThreadBundle thread_bundle_; |
| 41 TestingProfile profile_; |
| 42 }; |
| 43 |
| 44 TEST_F(BackgroundBudgetServiceTest, GetBudgetFailure) { |
| 45 const GURL origin(kTestOrigin); |
| 46 |
| 47 chrome::BackgroundBudgetService::GetBudget( |
| 48 profile(), GURL(kTestOrigin), |
| 49 base::Bind(&BackgroundBudgetServiceTest::DidGetBudget, |
| 50 base::Unretained(this))); |
| 51 |
| 52 base::RunLoop().RunUntilIdle(); |
| 53 |
| 54 EXPECT_EQ(success_, false); |
| 55 EXPECT_EQ(data_, std::string()); |
| 56 } |
| 57 |
| 58 TEST_F(BackgroundBudgetServiceTest, GetBudgetSuccess) { |
| 59 const GURL origin(kTestOrigin); |
| 60 |
| 61 chrome::BackgroundBudgetService::StoreBudget(profile(), GURL(kTestOrigin), |
| 62 kTestData); |
| 63 |
| 64 base::RunLoop().RunUntilIdle(); |
| 65 |
| 66 chrome::BackgroundBudgetService::GetBudget( |
| 67 profile(), GURL(kTestOrigin), |
| 68 base::Bind(&BackgroundBudgetServiceTest::DidGetBudget, |
| 69 base::Unretained(this))); |
| 70 |
| 71 base::RunLoop().RunUntilIdle(); |
| 72 |
| 73 EXPECT_EQ(success_, true); |
| 74 EXPECT_EQ(data_, kTestData); |
| 75 } |
| OLD | NEW |