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

Unified Diff: chrome/browser/memory/tab_manager_unittest.cc

Issue 2000833002: [TabManager] Unit tests to make sure of the number of times tabs can be discarded. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bug605533
Patch Set: Fixing final NIT Created 4 years, 7 months 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
« no previous file with comments | « chrome/browser/memory/tab_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/memory/tab_manager_unittest.cc
diff --git a/chrome/browser/memory/tab_manager_unittest.cc b/chrome/browser/memory/tab_manager_unittest.cc
index eb885061207bd482904453878873114f8462172a..794f62bf083bf184e52337e4f6b23547475deea9 100644
--- a/chrome/browser/memory/tab_manager_unittest.cc
+++ b/chrome/browser/memory/tab_manager_unittest.cc
@@ -5,11 +5,13 @@
#include "chrome/browser/memory/tab_manager.h"
#include <algorithm>
+#include <map>
#include <vector>
#include "base/logging.h"
#include "base/macros.h"
#include "base/strings/string16.h"
+#include "base/test/mock_entropy_provider.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/time/time.h"
#include "build/build_config.h"
@@ -18,9 +20,11 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h"
+#include "chrome/common/chrome_features.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
+#include "components/variations/variations_associated_data.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/web_contents_tester.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -433,6 +437,61 @@ TEST_F(TabManagerTest, DiscardedTabKeepsLastActiveTime) {
EXPECT_TRUE(tabstrip.empty());
}
+// Test to see if a tab can only be discarded once. On Windows and Mac, this
+// defaults to true unless overridden through a variation parameter. On other
+// platforms, it's always false
+#if defined(OS_WIN) || defined(OS_MACOSX)
+TEST_F(TabManagerTest, CanOnlyDiscardOnce) {
+ TabManager tab_manager;
+ const std::string kTrialName = features::kAutomaticTabDiscarding.name;
+
+ // Not setting the variation parameter.
+ {
+ bool discard_once_value = tab_manager.CanOnlyDiscardOnce();
+ EXPECT_TRUE(discard_once_value);
+ }
+
+ // Setting the variation parameter to true.
+ {
+ std::unique_ptr<base::FieldTrialList> field_trial_list_;
+ field_trial_list_.reset(
+ new base::FieldTrialList(new base::MockEntropyProvider()));
+ variations::testing::ClearAllVariationParams();
+
+ std::map<std::string, std::string> params;
+ params["AllowMultipleDiscards"] = "true";
+ ASSERT_TRUE(variations::AssociateVariationParams(kTrialName, "A", params));
+ base::FieldTrialList::CreateFieldTrial(kTrialName, "A");
+
+ bool discard_once_value = tab_manager.CanOnlyDiscardOnce();
+ EXPECT_FALSE(discard_once_value);
+ }
+
+ // Setting the variation parameter to something else.
+ {
+ std::unique_ptr<base::FieldTrialList> field_trial_list_;
+ field_trial_list_.reset(
+ new base::FieldTrialList(new base::MockEntropyProvider()));
+ variations::testing::ClearAllVariationParams();
+
+ std::map<std::string, std::string> params;
+ params["AllowMultipleDiscards"] = "somethingElse";
+ ASSERT_TRUE(variations::AssociateVariationParams(kTrialName, "B", params));
+ base::FieldTrialList::CreateFieldTrial(kTrialName, "B");
+
+ bool discard_once_value = tab_manager.CanOnlyDiscardOnce();
+ EXPECT_TRUE(discard_once_value);
+ }
+}
+#else
+TEST_F(TabManagerTest, CanOnlyDiscardOnce) {
+ TabManager tab_manager;
+
+ bool discard_once_value = tab_manager.CanOnlyDiscardOnce();
+ EXPECT_FALSE(discard_once_value);
+}
+#endif // defined(OS_WIN) || defined(OS_MACOSX)
+
namespace {
using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel;
« no previous file with comments | « chrome/browser/memory/tab_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698