Chromium Code Reviews| Index: chrome/browser/push_messaging/background_budget_service_unittest.cc |
| diff --git a/chrome/browser/push_messaging/background_budget_service_unittest.cc b/chrome/browser/push_messaging/background_budget_service_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..066f8b6542cd40a7cf19317a605329f782fe9ae3 |
| --- /dev/null |
| +++ b/chrome/browser/push_messaging/background_budget_service_unittest.cc |
| @@ -0,0 +1,92 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <stdint.h> |
| + |
| +#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.
|
| + |
| +#include "base/run_loop.h" |
| +#include "chrome/browser/push_messaging/background_budget_service.h" |
| +#include "chrome/test/base/testing_profile.h" |
| +#include "content/public/test/test_browser_thread_bundle.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace { |
| + |
| +const char kTestOrigin[] = "https://example.com"; |
| +const char kTestData[] = "1111101111"; |
| + |
| +// Implementation of the TestingProfile that provides the Push Messaging |
| +// Service, the Permission Manager, and the Background Budget service, all of |
| +// which are required for the tests. |
| +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
|
| + public: |
| + BackgroundBudgetTestingProfile() {} |
| + ~BackgroundBudgetTestingProfile() override {} |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(BackgroundBudgetTestingProfile); |
| +}; |
| + |
| +} // namespace |
| + |
| +class BackgroundBudgetServiceTest : public ::testing::Test { |
| + public: |
| + BackgroundBudgetServiceTest() {} |
| + ~BackgroundBudgetServiceTest() override {} |
| + |
| + void DidGetBudget(const std::string& data) { |
| + if (!data.empty()) |
| + success_ = true; |
| + data_ = data; |
| + } |
| + |
| + void DidStoreBudget(bool success) { success_ = success; } |
| + |
| + void IgnoreResult() {} |
|
Peter Beverloo
2016/04/08 10:41:11
nit: unused.
harkness
2016/04/08 14:11:43
Done.
|
| + |
| + BackgroundBudgetTestingProfile* profile() { return &profile_; } |
| + |
| + bool success_ = false; |
| + std::string data_; |
| + |
| + private: |
| + content::TestBrowserThreadBundle thread_bundle_; |
| + BackgroundBudgetTestingProfile profile_; |
| +}; |
| + |
| +TEST_F(BackgroundBudgetServiceTest, GetBudgetFailure) { |
| + const GURL origin(kTestOrigin); |
| + |
| + chrome::BackgroundBudgetService::GetBudget( |
| + profile(), GURL(kTestOrigin), |
| + base::Bind(&BackgroundBudgetServiceTest::DidGetBudget, |
| + base::Unretained(this))); |
| + |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + EXPECT_EQ(success_, false); |
| + EXPECT_EQ(data_, std::string()); |
| +} |
| + |
| +TEST_F(BackgroundBudgetServiceTest, GetBudgetSuccess) { |
| + const GURL origin(kTestOrigin); |
| + |
| + chrome::BackgroundBudgetService::StoreBudget( |
| + profile(), GURL(kTestOrigin), kTestData, |
| + base::Bind(&BackgroundBudgetServiceTest::DidStoreBudget, |
| + base::Unretained(this))); |
| + |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + chrome::BackgroundBudgetService::GetBudget( |
| + profile(), GURL(kTestOrigin), |
| + base::Bind(&BackgroundBudgetServiceTest::DidGetBudget, |
| + base::Unretained(this))); |
| + |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + EXPECT_EQ(success_, true); |
| + EXPECT_EQ(data_, kTestData); |
| +} |