Index: content/browser/memory/memory_state_notifier_browsertest.cc |
diff --git a/content/browser/memory/memory_state_notifier_browsertest.cc b/content/browser/memory/memory_state_notifier_browsertest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2812663f0a3c3b4371511b6b10b1551f35926bdd |
--- /dev/null |
+++ b/content/browser/memory/memory_state_notifier_browsertest.cc |
@@ -0,0 +1,80 @@ |
+// 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/command_line.h" |
+#include "base/run_loop.h" |
+#include "components/memory_coordinator/browser/memory_state_notifier.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 MemoryStateNotifierTest : public ContentBrowserTest { |
+ public: |
+ MemoryStateNotifierTest() {} |
+ |
+ void SetUpCommandLine(base::CommandLine* command_line) override { |
+ base::CommandLine::ForCurrentProcess()->AppendSwitch( |
+ switches::kEnableMemoryCoordinator); |
+ } |
+ |
+ protected: |
+ memory_coordinator::MemoryStateNotifier* memory_state_notifier() { |
+ return BrowserMainLoop::GetInstance()->memory_state_notifier(); |
+ } |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MemoryStateNotifierTest); |
+}; |
+ |
+class LastStateChecker { |
+ public: |
+ explicit LastStateChecker(memory_coordinator::MemoryStateNotifier* notifier) |
+ : notifier_(notifier) {} |
+ ~LastStateChecker() {} |
+ |
+ void Check(memory_coordinator::mojom::MemoryState expected) { |
+ DCHECK(notifier_); |
+ notifier_->IterateChildren(base::Bind(&LastStateChecker::GetLastState, |
+ base::Unretained(this), expected)); |
+ run_loop_.Run(); |
+ } |
+ |
+ private: |
+ void GetLastState( |
+ memory_coordinator::mojom::MemoryState expected, |
+ memory_coordinator::mojom::ChildMemoryCoordinatorPtr& child) { |
+ ++num_children_; |
+ child->GetLastState(base::Bind(&LastStateChecker::AppendLastState, |
+ base::Unretained(this), expected)); |
+ } |
+ |
+ void AppendLastState(memory_coordinator::mojom::MemoryState expected, |
+ memory_coordinator::mojom::MemoryState actual) { |
+ EXPECT_EQ(expected, actual); |
+ if (--num_children_ == 0) { |
+ run_loop_.QuitWhenIdle(); |
+ } |
+ } |
+ |
+ memory_coordinator::MemoryStateNotifier* notifier_ = nullptr; |
+ base::RunLoop run_loop_; |
+ size_t num_children_ = 0; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(LastStateChecker); |
+}; |
+ |
+ |
+IN_PROC_BROWSER_TEST_F(MemoryStateNotifierTest, Throttled) { |
+ GURL url = GetTestUrl("", "simple_page.html"); |
+ NavigateToURL(shell(), url); |
+ memory_state_notifier()->Notify( |
+ memory_coordinator::mojom::MemoryState::THROTTLED); |
+ |
+ LastStateChecker checker(memory_state_notifier()); |
+ checker.Check(memory_coordinator::mojom::MemoryState::THROTTLED); |
+} |
+ |
+} // namespace content |