Chromium Code Reviews| 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 | |
| 7 #include <string> | |
|
Peter Beverloo
2016/04/08 10:41:11
micro nit: no new line above here
harkness
2016/04/08 14:11:43
Done.
| |
| 8 | |
| 9 #include "base/run_loop.h" | |
| 10 #include "chrome/browser/push_messaging/background_budget_service.h" | |
| 11 #include "chrome/test/base/testing_profile.h" | |
| 12 #include "content/public/test/test_browser_thread_bundle.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 const char kTestOrigin[] = "https://example.com"; | |
| 18 const char kTestData[] = "1111101111"; | |
| 19 | |
| 20 // Implementation of the TestingProfile that provides the Push Messaging | |
| 21 // Service, the Permission Manager, and the Background Budget service, all of | |
| 22 // which are required for the tests. | |
| 23 class BackgroundBudgetTestingProfile : public TestingProfile { | |
|
Peter Beverloo
2016/04/08 10:41:11
What is the benefit of this class today? Can you j
harkness
2016/04/08 14:11:43
My next patch will use it, but I can remove it for
| |
| 24 public: | |
| 25 BackgroundBudgetTestingProfile() {} | |
| 26 ~BackgroundBudgetTestingProfile() override {} | |
| 27 | |
| 28 private: | |
| 29 DISALLOW_COPY_AND_ASSIGN(BackgroundBudgetTestingProfile); | |
| 30 }; | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 34 class BackgroundBudgetServiceTest : public ::testing::Test { | |
| 35 public: | |
| 36 BackgroundBudgetServiceTest() {} | |
| 37 ~BackgroundBudgetServiceTest() override {} | |
| 38 | |
| 39 void DidGetBudget(const std::string& data) { | |
| 40 if (!data.empty()) | |
| 41 success_ = true; | |
| 42 data_ = data; | |
| 43 } | |
| 44 | |
| 45 void DidStoreBudget(bool success) { success_ = success; } | |
| 46 | |
| 47 void IgnoreResult() {} | |
|
Peter Beverloo
2016/04/08 10:41:11
nit: unused.
harkness
2016/04/08 14:11:43
Done.
| |
| 48 | |
| 49 BackgroundBudgetTestingProfile* profile() { return &profile_; } | |
| 50 | |
| 51 bool success_ = false; | |
| 52 std::string data_; | |
| 53 | |
| 54 private: | |
| 55 content::TestBrowserThreadBundle thread_bundle_; | |
| 56 BackgroundBudgetTestingProfile profile_; | |
| 57 }; | |
| 58 | |
| 59 TEST_F(BackgroundBudgetServiceTest, GetBudgetFailure) { | |
| 60 const GURL origin(kTestOrigin); | |
| 61 | |
| 62 chrome::BackgroundBudgetService::GetBudget( | |
| 63 profile(), GURL(kTestOrigin), | |
| 64 base::Bind(&BackgroundBudgetServiceTest::DidGetBudget, | |
| 65 base::Unretained(this))); | |
| 66 | |
| 67 base::RunLoop().RunUntilIdle(); | |
| 68 | |
| 69 EXPECT_EQ(success_, false); | |
| 70 EXPECT_EQ(data_, std::string()); | |
| 71 } | |
| 72 | |
| 73 TEST_F(BackgroundBudgetServiceTest, GetBudgetSuccess) { | |
| 74 const GURL origin(kTestOrigin); | |
| 75 | |
| 76 chrome::BackgroundBudgetService::StoreBudget( | |
| 77 profile(), GURL(kTestOrigin), kTestData, | |
| 78 base::Bind(&BackgroundBudgetServiceTest::DidStoreBudget, | |
| 79 base::Unretained(this))); | |
| 80 | |
| 81 base::RunLoop().RunUntilIdle(); | |
| 82 | |
| 83 chrome::BackgroundBudgetService::GetBudget( | |
| 84 profile(), GURL(kTestOrigin), | |
| 85 base::Bind(&BackgroundBudgetServiceTest::DidGetBudget, | |
| 86 base::Unretained(this))); | |
| 87 | |
| 88 base::RunLoop().RunUntilIdle(); | |
| 89 | |
| 90 EXPECT_EQ(success_, true); | |
| 91 EXPECT_EQ(data_, kTestData); | |
| 92 } | |
| OLD | NEW |