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

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: [TabManager Created 4 years, 6 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 #if defined(OS_WIN) || defined(OS_MACOSX)
441 // Make sure of the number of times a tab is discarded.
442 // Tests related to platforms that fully supports TabManager.
Georges Khalil 2016/05/25 17:15:09 nit: Reword this comment and put it above the #ifd
443 TEST_F(TabManagerTest, CanOnlyDiscardOnce) {
444 TabManager tab_manager;
445 const std::string kTrialName = features::kAutomaticTabDiscarding.name;
446
447 // Not setting the variation parameter.
448 {
449 bool discard_once_value = tab_manager.CanOnlyDiscardOnce();
450 EXPECT_TRUE(discard_once_value);
451 }
452
453 // Setting the variation parameter to true.
454 {
455 std::unique_ptr<base::FieldTrialList> field_trial_list_;
456 field_trial_list_.reset(
457 new base::FieldTrialList(new base::MockEntropyProvider()));
458 variations::testing::ClearAllVariationParams();
459
460 std::map<std::string, std::string> params;
461 params["AllowMultipleDiscards"] = "true";
462 ASSERT_TRUE(variations::AssociateVariationParams(kTrialName, "A", params));
463 base::FieldTrialList::CreateFieldTrial(kTrialName, "A");
464
465 bool discard_once_value = tab_manager.CanOnlyDiscardOnce();
466 EXPECT_FALSE(discard_once_value);
467 }
468
469 // Setting the variation parameter to something else.
470 {
471 std::unique_ptr<base::FieldTrialList> field_trial_list_;
472 field_trial_list_.reset(
473 new base::FieldTrialList(new base::MockEntropyProvider()));
474 variations::testing::ClearAllVariationParams();
475
476 std::map<std::string, std::string> params;
477 params["AllowMultipleDiscards"] = "somethingElse";
478 ASSERT_TRUE(variations::AssociateVariationParams(kTrialName, "B", params));
479 base::FieldTrialList::CreateFieldTrial(kTrialName, "B");
480
481 bool discard_once_value = tab_manager.CanOnlyDiscardOnce();
482 EXPECT_TRUE(discard_once_value);
483 }
484 }
485 #else
486 // Make sure of the number of times a tab is discarded.
487 // Tests for platforms that doesn't fully support TabManager.
Georges Khalil 2016/05/25 17:15:09 nit: remove this comment as the above one will tak
488 TEST_F(TabManagerTest, CanOnlyDiscardOnce) {
489 TabManager tab_manager;
490
491 bool discard_once_value = tab_manager.CanOnlyDiscardOnce();
492 EXPECT_FALSE(discard_once_value);
493 }
494 #endif
495
Georges Khalil 2016/05/25 17:15:09 nit: add " // defined(OS_WIN) || defined(OS_MACOS
436 namespace { 496 namespace {
437 497
438 using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel; 498 using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel;
439 499
440 // Function that always indicates the absence of memory pressure. 500 // Function that always indicates the absence of memory pressure.
441 MemoryPressureLevel ReturnNoPressure() { 501 MemoryPressureLevel ReturnNoPressure() {
442 return base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE; 502 return base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE;
443 } 503 }
444 504
445 // Function that simply parrots back an externally specified memory pressure 505 // 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()); 652 EXPECT_EQ(0u, task_runner->size());
593 EXPECT_EQ(0u, tm.notified_renderers_.size()); 653 EXPECT_EQ(0u, tm.notified_renderers_.size());
594 654
595 655
596 // Clean up the tabstrip. 656 // Clean up the tabstrip.
597 tabstrip.CloseAllTabs(); 657 tabstrip.CloseAllTabs();
598 ASSERT_TRUE(tabstrip.empty()); 658 ASSERT_TRUE(tabstrip.empty());
599 } 659 }
600 660
601 } // namespace memory 661 } // 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