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/test/scoped_feature_list.h" |
| 10 #include "base/time/time.h" |
| 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "content/public/browser/memory_coordinator_delegate.h" |
| 13 #include "content/public/browser/render_widget_host_view.h" |
| 14 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/common/content_features.h" |
| 16 #include "content/public/test/memory_coordinator_test_utils.h" |
| 17 #include "content/public/test/test_browser_thread.h" |
| 18 #include "content/public/test/test_web_contents_factory.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 |
| 21 class TabLoaderTest : public testing::Test { |
| 22 public: |
| 23 using RestoredTab = SessionRestoreDelegate::RestoredTab; |
| 24 |
| 25 TabLoaderTest() |
| 26 : ui_thread_(content::BrowserThread::UI, &message_loop_) {} |
| 27 |
| 28 // testing::Test: |
| 29 void SetUp() override { |
| 30 scoped_feature_list_.InitAndEnableFeature(features::kMemoryCoordinator); |
| 31 content::SetUpMemoryCoordinatorProxyForTesting(); |
| 32 |
| 33 test_web_contents_factory_.reset(new content::TestWebContentsFactory); |
| 34 content::WebContents* contents = |
| 35 test_web_contents_factory_->CreateWebContents(&testing_profile_); |
| 36 restored_tabs_.push_back(RestoredTab(contents, false, false, false)); |
| 37 } |
| 38 |
| 39 void TearDown() override { |
| 40 restored_tabs_.clear(); |
| 41 test_web_contents_factory_.reset(); |
| 42 } |
| 43 |
| 44 protected: |
| 45 std::unique_ptr<content::TestWebContentsFactory> test_web_contents_factory_; |
| 46 std::vector<RestoredTab> restored_tabs_; |
| 47 |
| 48 base::MessageLoop message_loop_; |
| 49 TestingProfile testing_profile_; |
| 50 content::TestBrowserThread ui_thread_; |
| 51 base::test::ScopedFeatureList scoped_feature_list_; |
| 52 |
| 53 private: |
| 54 DISALLOW_COPY_AND_ASSIGN(TabLoaderTest); |
| 55 }; |
| 56 |
| 57 // TODO(hajimehoshi): Enable this test on macos when MemoryMonitorMac is |
| 58 // implemented. |
| 59 #if defined(OS_MACOSX) |
| 60 #define MAYBE_OnMemoryStateChange DISABLED_OnMemoryStateChange |
| 61 #else |
| 62 #define MAYBE_OnMemoryStateChange OnMemoryStateChange |
| 63 #endif |
| 64 TEST_F(TabLoaderTest, MAYBE_OnMemoryStateChange) { |
| 65 TabLoader::RestoreTabs(restored_tabs_, base::TimeTicks()); |
| 66 EXPECT_TRUE(TabLoader::shared_tab_loader_->loading_enabled_); |
| 67 base::MemoryCoordinatorProxy::GetInstance()->SetCurrentMemoryStateForTesting( |
| 68 base::MemoryState::THROTTLED); |
| 69 // ObserverListThreadsafe is used to notify the state to clients, so running |
| 70 // the loop is necessary here. |
| 71 base::RunLoop loop; |
| 72 loop.RunUntilIdle(); |
| 73 EXPECT_FALSE(TabLoader::shared_tab_loader_->loading_enabled_); |
| 74 } |
OLD | NEW |