Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: content/browser/memory/memory_coordinator_browsertest.cc

Issue 2094583002: Add MemoryCoordinator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Create handle per child Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "base/run_loop.h"
6 #include "components/memory_coordinator/browser/memory_coordinator.h"
7 #include "components/memory_coordinator/common/memory_coordinator_features.h"
8 #include "content/browser/browser_main_loop.h"
9 #include "content/public/common/content_switches.h"
10 #include "content/public/test/content_browser_test.h"
11 #include "content/public/test/content_browser_test_utils.h"
12
13 namespace content {
14
15 class MemoryCoordinatorTest : public ContentBrowserTest {
16 public:
17 MemoryCoordinatorTest() {}
18
19 void SetUp() override {
20 memory_coordinator::EnableForTesting();
21 ContentBrowserTest::SetUp();
22 }
23
24 void NotifyState(memory_coordinator::mojom::MemoryState state) {
25 memory_coordinator()->IterateChildrenForTesting(
26 base::Bind(&MemoryCoordinatorTest::NotifyStateToChild,
27 base::Unretained(this), state));
28 }
29
30 protected:
31 memory_coordinator::MemoryCoordinator* memory_coordinator() {
32 return BrowserMainLoop::GetInstance()->memory_coordinator();
33 }
34
35 void NotifyStateToChild(
36 memory_coordinator::mojom::MemoryState state,
37 memory_coordinator::mojom::ChildMemoryCoordinator* child) {
38 child->OnStateChange(state);
39 }
40
41 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorTest);
42 };
43
44 class LastStateChecker {
45 public:
46 explicit LastStateChecker(
47 memory_coordinator::MemoryCoordinator* coordinator)
48 : coordinator_(coordinator) {}
49 ~LastStateChecker() {}
50
51 void Check(memory_coordinator::mojom::MemoryState expected) {
52 DCHECK(coordinator_);
53 coordinator_->IterateChildrenForTesting(base::Bind(
54 &LastStateChecker::GetChildState, base::Unretained(this), expected));
55 run_loop_.Run();
56 }
57
58 private:
59 void GetChildState(memory_coordinator::mojom::MemoryState expected,
60 memory_coordinator::mojom::ChildMemoryCoordinator* child) {
61 ++num_children_;
62 child->GetCurrentStateForTesting(
63 base::Bind(&LastStateChecker::CheckLastStateForChild,
64 base::Unretained(this), expected));
65 }
66
67 void CheckLastStateForChild(memory_coordinator::mojom::MemoryState expected,
68 memory_coordinator::mojom::MemoryState actual) {
69 EXPECT_EQ(expected, actual);
70 if (--num_children_ == 0) {
71 run_loop_.QuitWhenIdle();
72 }
73 }
74
75 memory_coordinator::MemoryCoordinator* coordinator_ = nullptr;
76 base::RunLoop run_loop_;
77 size_t num_children_ = 0;
78
79 DISALLOW_COPY_AND_ASSIGN(LastStateChecker);
80 };
81
82 IN_PROC_BROWSER_TEST_F(MemoryCoordinatorTest, Throttled) {
83 GURL url = GetTestUrl("", "simple_page.html");
84 NavigateToURL(shell(), url);
85 NotifyState(memory_coordinator::mojom::MemoryState::THROTTLED);
86
87 LastStateChecker checker(memory_coordinator());
88 checker.Check(memory_coordinator::mojom::MemoryState::THROTTLED);
89 }
90
91 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698