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/public/browser/memory_coordinator_delegate.h" |
| 12 #include "content/public/browser/render_widget_host_view.h" |
| 13 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/test/memory_coordinator_test_utils.h" |
| 15 #include "content/public/test/test_browser_thread.h" |
| 16 #include "content/public/test/test_web_contents_factory.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 |
| 19 class TabLoaderTest : public testing::Test { |
| 20 public: |
| 21 using RestoredTab = SessionRestoreDelegate::RestoredTab; |
| 22 |
| 23 TabLoaderTest() |
| 24 : ui_thread_(content::BrowserThread::UI, &message_loop_) {} |
| 25 |
| 26 // testing::Test: |
| 27 void SetUp() override { |
| 28 content::EnableMemoryCoordinatorFeaturesForTesting(); |
| 29 content::SetUpMemoryCoordinatorProxyForTesting(); |
| 30 |
| 31 test_web_contents_factory_.reset(new content::TestWebContentsFactory); |
| 32 content::WebContents* contents = |
| 33 test_web_contents_factory_->CreateWebContents(&testing_profile_); |
| 34 restored_tabs_.push_back(RestoredTab(contents, false, false, false)); |
| 35 } |
| 36 |
| 37 void TearDown() override { |
| 38 restored_tabs_.clear(); |
| 39 test_web_contents_factory_.reset(); |
| 40 } |
| 41 |
| 42 protected: |
| 43 std::unique_ptr<content::TestWebContentsFactory> test_web_contents_factory_; |
| 44 std::vector<RestoredTab> restored_tabs_; |
| 45 |
| 46 base::MessageLoop message_loop_; |
| 47 TestingProfile testing_profile_; |
| 48 content::TestBrowserThread ui_thread_; |
| 49 |
| 50 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(TabLoaderTest); |
| 52 }; |
| 53 |
| 54 TEST_F(TabLoaderTest, OnMemoryStateChange) { |
| 55 TabLoader::RestoreTabs(restored_tabs_, base::TimeTicks()); |
| 56 EXPECT_TRUE(TabLoader::shared_tab_loader_->loading_enabled_); |
| 57 base::MemoryCoordinatorProxy::GetInstance()->SetCurrentMemoryStateForTesting( |
| 58 base::MemoryState::THROTTLED); |
| 59 // ObserverListThreadsafe is used to notify the state to clients, so running |
| 60 // the loop is necessary here. |
| 61 base::RunLoop loop; |
| 62 loop.RunUntilIdle(); |
| 63 EXPECT_FALSE(TabLoader::shared_tab_loader_->loading_enabled_); |
| 64 } |
OLD | NEW |