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

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

Issue 2094583002: Add MemoryCoordinator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gn 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_impl.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 MemoryCoordinatorImplTest : public ContentBrowserTest {
16 public:
17 MemoryCoordinatorImplTest() {}
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()->IterateChildren(
26 [&state](memory_coordinator::mojom::ChildMemoryCoordinator* child) {
chrisha 2016/07/07 02:53:44 Capturing state by ref here, and by value below? B
bashi 2016/07/07 03:25:22 (seems forgot to remove &) Changed to by value.
27 child->OnStateChange(state);
28 });
29 }
30
31 protected:
32 memory_coordinator::MemoryCoordinatorImpl* memory_coordinator() {
33 return BrowserMainLoop::GetInstance()->memory_coordinator();
34 }
35
36 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorImplTest);
37 };
38
39 class LastStateChecker {
40 public:
41 explicit LastStateChecker(
42 memory_coordinator::MemoryCoordinatorImpl* coordinator)
43 : coordinator_(coordinator) {}
44 ~LastStateChecker() {}
45
46 void Check(memory_coordinator::mojom::MemoryState expected) {
47 DCHECK(coordinator_);
48 coordinator_->IterateChildren([this, expected](
49 memory_coordinator::mojom::ChildMemoryCoordinator* child) {
50 ++num_children_;
51 child->GetCurrentState(
chrisha 2016/07/07 02:53:44 GetCurrentState is only used for testing, no? Mayb
bashi 2016/07/07 03:25:22 Renamed.
52 base::Bind(&LastStateChecker::CheckLastStateForChild,
53 base::Unretained(this), expected));
54 });
55 run_loop_.Run();
56 }
57
58 private:
59 void CheckLastStateForChild(memory_coordinator::mojom::MemoryState expected,
60 memory_coordinator::mojom::MemoryState actual) {
61 EXPECT_EQ(expected, actual);
62 if (--num_children_ == 0) {
63 run_loop_.QuitWhenIdle();
64 }
65 }
66
67 memory_coordinator::MemoryCoordinatorImpl* coordinator_ = nullptr;
68 base::RunLoop run_loop_;
69 size_t num_children_ = 0;
70
71 DISALLOW_COPY_AND_ASSIGN(LastStateChecker);
72 };
73
74
75 IN_PROC_BROWSER_TEST_F(MemoryCoordinatorImplTest, Throttled) {
76 GURL url = GetTestUrl("", "simple_page.html");
77 NavigateToURL(shell(), url);
78 NotifyState(memory_coordinator::mojom::MemoryState::THROTTLED);
79
80 LastStateChecker checker(memory_coordinator());
81 checker.Check(memory_coordinator::mojom::MemoryState::THROTTLED);
82 }
83
84 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698