| Index: content/browser/memory/memory_coordinator_browsertest.cc
|
| diff --git a/content/browser/memory/memory_coordinator_browsertest.cc b/content/browser/memory/memory_coordinator_browsertest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..08331bb28e3e94385c38f85edac80d91acfd1696
|
| --- /dev/null
|
| +++ b/content/browser/memory/memory_coordinator_browsertest.cc
|
| @@ -0,0 +1,91 @@
|
| +// 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 "base/run_loop.h"
|
| +#include "components/memory_coordinator/browser/memory_coordinator.h"
|
| +#include "components/memory_coordinator/common/memory_coordinator_features.h"
|
| +#include "content/browser/browser_main_loop.h"
|
| +#include "content/public/common/content_switches.h"
|
| +#include "content/public/test/content_browser_test.h"
|
| +#include "content/public/test/content_browser_test_utils.h"
|
| +
|
| +namespace content {
|
| +
|
| +class MemoryCoordinatorTest : public ContentBrowserTest {
|
| + public:
|
| + MemoryCoordinatorTest() {}
|
| +
|
| + void SetUp() override {
|
| + memory_coordinator::EnableForTesting();
|
| + ContentBrowserTest::SetUp();
|
| + }
|
| +
|
| + void NotifyState(memory_coordinator::mojom::MemoryState state) {
|
| + memory_coordinator()->IterateChildrenForTesting(
|
| + base::Bind(&MemoryCoordinatorTest::NotifyStateToChild,
|
| + base::Unretained(this), state));
|
| + }
|
| +
|
| + protected:
|
| + memory_coordinator::MemoryCoordinator* memory_coordinator() {
|
| + return BrowserMainLoop::GetInstance()->memory_coordinator();
|
| + }
|
| +
|
| + void NotifyStateToChild(
|
| + memory_coordinator::mojom::MemoryState state,
|
| + memory_coordinator::mojom::ChildMemoryCoordinator* child) {
|
| + child->OnStateChange(state);
|
| + }
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorTest);
|
| +};
|
| +
|
| +class LastStateChecker {
|
| + public:
|
| + explicit LastStateChecker(
|
| + memory_coordinator::MemoryCoordinator* coordinator)
|
| + : coordinator_(coordinator) {}
|
| + ~LastStateChecker() {}
|
| +
|
| + void Check(memory_coordinator::mojom::MemoryState expected) {
|
| + DCHECK(coordinator_);
|
| + coordinator_->IterateChildrenForTesting(base::Bind(
|
| + &LastStateChecker::GetChildState, base::Unretained(this), expected));
|
| + run_loop_.Run();
|
| + }
|
| +
|
| + private:
|
| + void GetChildState(memory_coordinator::mojom::MemoryState expected,
|
| + memory_coordinator::mojom::ChildMemoryCoordinator* child) {
|
| + ++num_children_;
|
| + child->GetCurrentStateForTesting(
|
| + base::Bind(&LastStateChecker::CheckLastStateForChild,
|
| + base::Unretained(this), expected));
|
| + }
|
| +
|
| + void CheckLastStateForChild(memory_coordinator::mojom::MemoryState expected,
|
| + memory_coordinator::mojom::MemoryState actual) {
|
| + EXPECT_EQ(expected, actual);
|
| + if (--num_children_ == 0) {
|
| + run_loop_.QuitWhenIdle();
|
| + }
|
| + }
|
| +
|
| + memory_coordinator::MemoryCoordinator* coordinator_ = nullptr;
|
| + base::RunLoop run_loop_;
|
| + size_t num_children_ = 0;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(LastStateChecker);
|
| +};
|
| +
|
| +IN_PROC_BROWSER_TEST_F(MemoryCoordinatorTest, Throttled) {
|
| + GURL url = GetTestUrl("", "simple_page.html");
|
| + NavigateToURL(shell(), url);
|
| + NotifyState(memory_coordinator::mojom::MemoryState::THROTTLED);
|
| +
|
| + LastStateChecker checker(memory_coordinator());
|
| + checker.Check(memory_coordinator::mojom::MemoryState::THROTTLED);
|
| +}
|
| +
|
| +} // namespace content
|
|
|