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