Chromium Code Reviews| Index: chrome/browser/sessions/tab_loader_unittest.cc |
| diff --git a/chrome/browser/sessions/tab_loader_unittest.cc b/chrome/browser/sessions/tab_loader_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8b682cf82e1c4fac25c63f0669dac0bdbec9bc91 |
| --- /dev/null |
| +++ b/chrome/browser/sessions/tab_loader_unittest.cc |
| @@ -0,0 +1,87 @@ |
| +// 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 "chrome/browser/sessions/tab_loader.h" |
| + |
| +#include "base/memory/memory_coordinator_proxy.h" |
| +#include "base/run_loop.h" |
| +#include "base/time/time.h" |
| +#include "chrome/test/base/testing_profile.h" |
| +#include "content/browser/memory/memory_coordinator.h" |
| +#include "content/browser/memory/memory_coordinator_impl.h" |
| +#include "content/browser/memory/memory_monitor.h" |
| +#include "content/public/browser/render_widget_host_view.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/test/test_browser_thread.h" |
| +#include "content/public/test/test_web_contents_factory.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace { |
| + |
| +class MockMemoryMonitor : public content::MemoryMonitor { |
| + public: |
| + MockMemoryMonitor() {} |
| + ~MockMemoryMonitor() override {} |
| + |
| + // MemoryMonitor: |
| + int GetFreeMemoryUntilCriticalMB() override { return 0; } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(MockMemoryMonitor); |
| +}; |
| + |
| +} // namespace |
| + |
| +class TabLoaderTest : public testing::Test { |
| + public: |
| + using RestoredTab = SessionRestoreDelegate::RestoredTab; |
| + |
| + TabLoaderTest() |
| + : ui_thread_(content::BrowserThread::UI, &message_loop_) {} |
| + |
| + void SetUp() override { |
|
sky
2016/11/01 15:23:14
Prefix section with where overriding from (like yo
hajimehoshi
2016/11/02 09:34:13
Done.
|
| + content::MemoryCoordinator::EnableFeaturesForTesting(); |
| + |
| + coordinator_.reset(new content::MemoryCoordinatorImpl( |
|
sky
2016/11/01 15:23:14
MakeUnique where possible (see threads on chromium
hajimehoshi
2016/11/02 09:34:13
Done.
|
| + message_loop_.task_runner(), base::WrapUnique(new MockMemoryMonitor))); |
| + |
| + base::MemoryCoordinatorProxy::GetInstance()-> |
| + SetGetCurrentMemoryStateCallback(base::Bind( |
| + &content::MemoryCoordinator::GetCurrentMemoryState, |
| + base::Unretained(coordinator_.get()))); |
| + base::MemoryCoordinatorProxy::GetInstance()-> |
| + SetSetCurrentMemoryStateForTestingCallback(base::Bind( |
| + &content::MemoryCoordinator::SetCurrentMemoryStateForTesting, |
| + base::Unretained(coordinator_.get()))); |
| + |
| + test_web_contents_factory_.reset(new content::TestWebContentsFactory); |
| + content::WebContents* contents = |
| + test_web_contents_factory_->CreateWebContents(&testing_profile_); |
| + restored_tabs_.push_back(RestoredTab(contents, false, false, false)); |
| + } |
| + |
| + void TearDown() override { |
| + restored_tabs_.clear(); |
| + test_web_contents_factory_.reset(); |
| + } |
| + |
| + protected: |
| + std::unique_ptr<content::MemoryCoordinatorImpl> coordinator_; |
| + std::unique_ptr<content::TestWebContentsFactory> test_web_contents_factory_; |
| + std::vector<RestoredTab> restored_tabs_; |
| + |
| + base::MessageLoop message_loop_; |
| + TestingProfile testing_profile_; |
| + content::TestBrowserThread ui_thread_; |
| +}; |
|
sky
2016/11/01 15:23:14
DISALLOW...
hajimehoshi
2016/11/02 09:34:13
Done.
|
| + |
| +TEST_F(TabLoaderTest, OnMemoryStateChange) { |
| + TabLoader::RestoreTabs(restored_tabs_, base::TimeTicks()); |
| + EXPECT_TRUE(TabLoader::GetLoadingEnabledForTesting()); |
| + base::MemoryCoordinatorProxy::GetInstance()->SetCurrentMemoryStateForTesting( |
| + base::MemoryState::THROTTLED); |
| + base::RunLoop loop; |
| + loop.RunUntilIdle(); |
|
sky
2016/11/01 15:23:14
Why do you need the RunUntilIdle?
hajimehoshi
2016/11/02 09:34:13
This is needed to ensure TabLoader::OnMemoryStateC
sky
2016/11/02 15:40:26
Doesn't the line above this, SetCurrentMemoryState
|
| + EXPECT_FALSE(TabLoader::GetLoadingEnabledForTesting()); |
|
sky
2016/11/01 15:23:14
It would also be good to verify TabLoader deletes
hajimehoshi
2016/11/02 09:34:13
IIUC TabLoader::~TabLoader is not called until the
|
| +} |