Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "chrome/browser/sessions/tab_loader.h" | |
| 6 | |
| 7 #include "base/memory/memory_coordinator_proxy.h" | |
| 8 #include "base/run_loop.h" | |
| 9 #include "base/time/time.h" | |
| 10 #include "chrome/test/base/testing_profile.h" | |
| 11 #include "content/browser/memory/memory_coordinator.h" | |
| 12 #include "content/browser/memory/memory_coordinator_impl.h" | |
| 13 #include "content/browser/memory/memory_monitor.h" | |
| 14 #include "content/public/browser/render_widget_host_view.h" | |
| 15 #include "content/public/browser/web_contents.h" | |
| 16 #include "content/public/test/test_browser_thread.h" | |
| 17 #include "content/public/test/test_web_contents_factory.h" | |
| 18 #include "testing/gtest/include/gtest/gtest.h" | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 class MockMemoryMonitor : public content::MemoryMonitor { | |
| 23 public: | |
| 24 MockMemoryMonitor() {} | |
| 25 ~MockMemoryMonitor() override {} | |
| 26 | |
| 27 // MemoryMonitor: | |
| 28 int GetFreeMemoryUntilCriticalMB() override { return 0; } | |
| 29 | |
| 30 private: | |
| 31 DISALLOW_COPY_AND_ASSIGN(MockMemoryMonitor); | |
| 32 }; | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 class TabLoaderTest : public testing::Test { | |
| 37 public: | |
| 38 using RestoredTab = SessionRestoreDelegate::RestoredTab; | |
| 39 | |
| 40 TabLoaderTest() | |
| 41 : ui_thread_(content::BrowserThread::UI, &message_loop_) {} | |
| 42 | |
| 43 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.
| |
| 44 content::MemoryCoordinator::EnableFeaturesForTesting(); | |
| 45 | |
| 46 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.
| |
| 47 message_loop_.task_runner(), base::WrapUnique(new MockMemoryMonitor))); | |
| 48 | |
| 49 base::MemoryCoordinatorProxy::GetInstance()-> | |
| 50 SetGetCurrentMemoryStateCallback(base::Bind( | |
| 51 &content::MemoryCoordinator::GetCurrentMemoryState, | |
| 52 base::Unretained(coordinator_.get()))); | |
| 53 base::MemoryCoordinatorProxy::GetInstance()-> | |
| 54 SetSetCurrentMemoryStateForTestingCallback(base::Bind( | |
| 55 &content::MemoryCoordinator::SetCurrentMemoryStateForTesting, | |
| 56 base::Unretained(coordinator_.get()))); | |
| 57 | |
| 58 test_web_contents_factory_.reset(new content::TestWebContentsFactory); | |
| 59 content::WebContents* contents = | |
| 60 test_web_contents_factory_->CreateWebContents(&testing_profile_); | |
| 61 restored_tabs_.push_back(RestoredTab(contents, false, false, false)); | |
| 62 } | |
| 63 | |
| 64 void TearDown() override { | |
| 65 restored_tabs_.clear(); | |
| 66 test_web_contents_factory_.reset(); | |
| 67 } | |
| 68 | |
| 69 protected: | |
| 70 std::unique_ptr<content::MemoryCoordinatorImpl> coordinator_; | |
| 71 std::unique_ptr<content::TestWebContentsFactory> test_web_contents_factory_; | |
| 72 std::vector<RestoredTab> restored_tabs_; | |
| 73 | |
| 74 base::MessageLoop message_loop_; | |
| 75 TestingProfile testing_profile_; | |
| 76 content::TestBrowserThread ui_thread_; | |
| 77 }; | |
|
sky
2016/11/01 15:23:14
DISALLOW...
hajimehoshi
2016/11/02 09:34:13
Done.
| |
| 78 | |
| 79 TEST_F(TabLoaderTest, OnMemoryStateChange) { | |
| 80 TabLoader::RestoreTabs(restored_tabs_, base::TimeTicks()); | |
| 81 EXPECT_TRUE(TabLoader::GetLoadingEnabledForTesting()); | |
| 82 base::MemoryCoordinatorProxy::GetInstance()->SetCurrentMemoryStateForTesting( | |
| 83 base::MemoryState::THROTTLED); | |
| 84 base::RunLoop loop; | |
| 85 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
| |
| 86 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
| |
| 87 } | |
| OLD | NEW |