Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2229)

Unified Diff: chrome/browser/sessions/tab_loader_unittest.cc

Issue 2466883002: Add TabLoaderTest (Closed)
Patch Set: Address on sky's review Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..3a09ba230188c2f6631c2fc8061135baf71f5905
--- /dev/null
+++ b/chrome/browser/sessions/tab_loader_unittest.cc
@@ -0,0 +1,61 @@
+// 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/public/browser/memory_coordinator_delegate.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"
+
+class TabLoaderTest : public testing::Test {
+ public:
+ using RestoredTab = SessionRestoreDelegate::RestoredTab;
+
+ TabLoaderTest()
+ : ui_thread_(content::BrowserThread::UI, &message_loop_) {}
+
+ // testing::Test:
+ void SetUp() override {
+ content::EnableFeaturesForTesting();
+ content::SetUpMemoryCoordinatorProxyForTesting();
+
+ 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::TestWebContentsFactory> test_web_contents_factory_;
+ std::vector<RestoredTab> restored_tabs_;
+
+ base::MessageLoop message_loop_;
+ TestingProfile testing_profile_;
+ content::TestBrowserThread ui_thread_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TabLoaderTest);
+};
+
+TEST_F(TabLoaderTest, OnMemoryStateChange) {
+ TabLoader::RestoreTabs(restored_tabs_, base::TimeTicks());
+ EXPECT_TRUE(TabLoader::shared_tab_loader_->loading_enabled_);
+ base::MemoryCoordinatorProxy::GetInstance()->SetCurrentMemoryStateForTesting(
+ base::MemoryState::THROTTLED);
+ base::RunLoop loop;
+ loop.RunUntilIdle();
+ EXPECT_FALSE(TabLoader::shared_tab_loader_->loading_enabled_);
+}

Powered by Google App Engine
This is Rietveld 408576698