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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/memory/tab_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/tab_manager.h" 5 #include "chrome/browser/memory/tab_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map>
8 #include <vector> 9 #include <vector>
9 10
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/test/mock_entropy_provider.h"
13 #include "base/test/simple_test_tick_clock.h" 15 #include "base/test/simple_test_tick_clock.h"
14 #include "base/time/time.h" 16 #include "base/time/time.h"
15 #include "build/build_config.h" 17 #include "build/build_config.h"
16 #include "chrome/browser/memory/tab_manager_web_contents_data.h" 18 #include "chrome/browser/memory/tab_manager_web_contents_data.h"
17 #include "chrome/browser/memory/tab_stats.h" 19 #include "chrome/browser/memory/tab_stats.h"
18 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h" 22 #include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h"
23 #include "chrome/common/chrome_features.h"
21 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 25 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
23 #include "chrome/test/base/testing_profile.h" 26 #include "chrome/test/base/testing_profile.h"
27 #include "components/variations/variations_associated_data.h"
24 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
25 #include "content/public/test/web_contents_tester.h" 29 #include "content/public/test/web_contents_tester.h"
26 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
28 #include "url/gurl.h" 32 #include "url/gurl.h"
29 33
30 using content::WebContents; 34 using content::WebContents;
31 using content::WebContentsTester; 35 using content::WebContentsTester;
32 36
33 namespace memory { 37 namespace memory {
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 test_contents->SetLastActiveTime(new_last_active_time); 430 test_contents->SetLastActiveTime(new_last_active_time);
427 EXPECT_EQ(new_last_active_time, test_contents->GetLastActiveTime()); 431 EXPECT_EQ(new_last_active_time, test_contents->GetLastActiveTime());
428 432
429 WebContents* null_contents = tab_manager.DiscardWebContentsAt(1, &tabstrip); 433 WebContents* null_contents = tab_manager.DiscardWebContentsAt(1, &tabstrip);
430 EXPECT_EQ(new_last_active_time, null_contents->GetLastActiveTime()); 434 EXPECT_EQ(new_last_active_time, null_contents->GetLastActiveTime());
431 435
432 tabstrip.CloseAllTabs(); 436 tabstrip.CloseAllTabs();
433 EXPECT_TRUE(tabstrip.empty()); 437 EXPECT_TRUE(tabstrip.empty());
434 } 438 }
435 439
440 // Test to see if a tab can only be discarded once. On Windows and Mac, this
441 // defaults to true unless overridden through a variation parameter. On other
442 // platforms, it's always false
443 #if defined(OS_WIN) || defined(OS_MACOSX)
444 TEST_F(TabManagerTest, CanOnlyDiscardOnce) {
445 TabManager tab_manager;
446 const std::string kTrialName = features::kAutomaticTabDiscarding.name;
447
448 // Not setting the variation parameter.
449 {
450 bool discard_once_value = tab_manager.CanOnlyDiscardOnce();
451 EXPECT_TRUE(discard_once_value);
452 }
453
454 // Setting the variation parameter to true.
455 {
456 std::unique_ptr<base::FieldTrialList> field_trial_list_;
457 field_trial_list_.reset(
458 new base::FieldTrialList(new base::MockEntropyProvider()));
459 variations::testing::ClearAllVariationParams();
460
461 std::map<std::string, std::string> params;
462 params["AllowMultipleDiscards"] = "true";
463 ASSERT_TRUE(variations::AssociateVariationParams(kTrialName, "A", params));
464 base::FieldTrialList::CreateFieldTrial(kTrialName, "A");
465
466 bool discard_once_value = tab_manager.CanOnlyDiscardOnce();
467 EXPECT_FALSE(discard_once_value);
468 }
469
470 // Setting the variation parameter to something else.
471 {
472 std::unique_ptr<base::FieldTrialList> field_trial_list_;
473 field_trial_list_.reset(
474 new base::FieldTrialList(new base::MockEntropyProvider()));
475 variations::testing::ClearAllVariationParams();
476
477 std::map<std::string, std::string> params;
478 params["AllowMultipleDiscards"] = "somethingElse";
479 ASSERT_TRUE(variations::AssociateVariationParams(kTrialName, "B", params));
480 base::FieldTrialList::CreateFieldTrial(kTrialName, "B");
481
482 bool discard_once_value = tab_manager.CanOnlyDiscardOnce();
483 EXPECT_TRUE(discard_once_value);
484 }
485 }
486 #else
487 TEST_F(TabManagerTest, CanOnlyDiscardOnce) {
488 TabManager tab_manager;
489
490 bool discard_once_value = tab_manager.CanOnlyDiscardOnce();
491 EXPECT_FALSE(discard_once_value);
492 }
493 #endif // defined(OS_WIN) || defined(OS_MACOSX)
494
436 namespace { 495 namespace {
437 496
438 using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel; 497 using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel;
439 498
440 // Function that always indicates the absence of memory pressure. 499 // Function that always indicates the absence of memory pressure.
441 MemoryPressureLevel ReturnNoPressure() { 500 MemoryPressureLevel ReturnNoPressure() {
442 return base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE; 501 return base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE;
443 } 502 }
444 503
445 // Function that simply parrots back an externally specified memory pressure 504 // Function that simply parrots back an externally specified memory pressure
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 EXPECT_EQ(0u, task_runner->size()); 651 EXPECT_EQ(0u, task_runner->size());
593 EXPECT_EQ(0u, tm.notified_renderers_.size()); 652 EXPECT_EQ(0u, tm.notified_renderers_.size());
594 653
595 654
596 // Clean up the tabstrip. 655 // Clean up the tabstrip.
597 tabstrip.CloseAllTabs(); 656 tabstrip.CloseAllTabs();
598 ASSERT_TRUE(tabstrip.empty()); 657 ASSERT_TRUE(tabstrip.empty());
599 } 658 }
600 659
601 } // namespace memory 660 } // namespace memory
OLDNEW
« 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