OLD | NEW |
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/resource_coordinator/tab_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "base/test/mock_entropy_provider.h" | 16 #include "base/test/mock_entropy_provider.h" |
17 #include "base/test/simple_test_tick_clock.h" | 17 #include "base/test/simple_test_tick_clock.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "chrome/browser/memory/tab_manager_web_contents_data.h" | |
21 #include "chrome/browser/memory/tab_stats.h" | |
22 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/resource_coordinator/tab_manager_web_contents_data.h" |
| 22 #include "chrome/browser/resource_coordinator/tab_stats.h" |
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
24 #include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h" | 24 #include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h" |
25 #include "chrome/common/chrome_features.h" | 25 #include "chrome/common/chrome_features.h" |
26 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
27 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 27 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
28 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" |
29 #include "components/variations/variations_associated_data.h" | 29 #include "components/variations/variations_associated_data.h" |
30 #include "content/public/browser/render_process_host.h" | 30 #include "content/public/browser/render_process_host.h" |
31 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
32 #include "content/public/test/mock_render_process_host.h" | 32 #include "content/public/test/mock_render_process_host.h" |
33 #include "content/public/test/web_contents_tester.h" | 33 #include "content/public/test/web_contents_tester.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
35 #include "url/gurl.h" | 35 #include "url/gurl.h" |
36 | 36 |
37 using content::WebContents; | 37 using content::WebContents; |
38 using content::WebContentsTester; | 38 using content::WebContentsTester; |
39 | 39 |
40 namespace memory { | 40 namespace resource_coordinator { |
41 namespace { | 41 namespace { |
42 | 42 |
43 class TabStripDummyDelegate : public TestTabStripModelDelegate { | 43 class TabStripDummyDelegate : public TestTabStripModelDelegate { |
44 public: | 44 public: |
45 TabStripDummyDelegate() {} | 45 TabStripDummyDelegate() {} |
46 | 46 |
47 bool RunUnloadListenerBeforeClosing(WebContents* contents) override { | 47 bool RunUnloadListenerBeforeClosing(WebContents* contents) override { |
48 return false; | 48 return false; |
49 } | 49 } |
50 | 50 |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 | 367 |
368 // Not setting the variation parameter. | 368 // Not setting the variation parameter. |
369 { | 369 { |
370 bool discard_once_value = tab_manager.CanOnlyDiscardOnce(); | 370 bool discard_once_value = tab_manager.CanOnlyDiscardOnce(); |
371 EXPECT_TRUE(discard_once_value); | 371 EXPECT_TRUE(discard_once_value); |
372 } | 372 } |
373 | 373 |
374 // Setting the variation parameter to true. | 374 // Setting the variation parameter to true. |
375 { | 375 { |
376 std::unique_ptr<base::FieldTrialList> field_trial_list_; | 376 std::unique_ptr<base::FieldTrialList> field_trial_list_; |
377 field_trial_list_.reset( | 377 field_trial_list_.reset(new base::FieldTrialList( |
378 new base::FieldTrialList( | 378 base::MakeUnique<base::MockEntropyProvider>())); |
379 base::MakeUnique<base::MockEntropyProvider>())); | |
380 variations::testing::ClearAllVariationParams(); | 379 variations::testing::ClearAllVariationParams(); |
381 | 380 |
382 std::map<std::string, std::string> params; | 381 std::map<std::string, std::string> params; |
383 params["AllowMultipleDiscards"] = "true"; | 382 params["AllowMultipleDiscards"] = "true"; |
384 ASSERT_TRUE(variations::AssociateVariationParams(kTrialName, "A", params)); | 383 ASSERT_TRUE(variations::AssociateVariationParams(kTrialName, "A", params)); |
385 base::FieldTrialList::CreateFieldTrial(kTrialName, "A"); | 384 base::FieldTrialList::CreateFieldTrial(kTrialName, "A"); |
386 | 385 |
387 bool discard_once_value = tab_manager.CanOnlyDiscardOnce(); | 386 bool discard_once_value = tab_manager.CanOnlyDiscardOnce(); |
388 EXPECT_FALSE(discard_once_value); | 387 EXPECT_FALSE(discard_once_value); |
389 } | 388 } |
390 | 389 |
391 // Setting the variation parameter to something else. | 390 // Setting the variation parameter to something else. |
392 { | 391 { |
393 std::unique_ptr<base::FieldTrialList> field_trial_list_; | 392 std::unique_ptr<base::FieldTrialList> field_trial_list_; |
394 field_trial_list_.reset( | 393 field_trial_list_.reset(new base::FieldTrialList( |
395 new base::FieldTrialList( | 394 base::MakeUnique<base::MockEntropyProvider>())); |
396 base::MakeUnique<base::MockEntropyProvider>())); | |
397 variations::testing::ClearAllVariationParams(); | 395 variations::testing::ClearAllVariationParams(); |
398 | 396 |
399 std::map<std::string, std::string> params; | 397 std::map<std::string, std::string> params; |
400 params["AllowMultipleDiscards"] = "somethingElse"; | 398 params["AllowMultipleDiscards"] = "somethingElse"; |
401 ASSERT_TRUE(variations::AssociateVariationParams(kTrialName, "B", params)); | 399 ASSERT_TRUE(variations::AssociateVariationParams(kTrialName, "B", params)); |
402 base::FieldTrialList::CreateFieldTrial(kTrialName, "B"); | 400 base::FieldTrialList::CreateFieldTrial(kTrialName, "B"); |
403 | 401 |
404 bool discard_once_value = tab_manager.CanOnlyDiscardOnce(); | 402 bool discard_once_value = tab_manager.CanOnlyDiscardOnce(); |
405 EXPECT_TRUE(discard_once_value); | 403 EXPECT_TRUE(discard_once_value); |
406 } | 404 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 tab_manager.PurgeBackgroundedTabsIfNeeded(); | 485 tab_manager.PurgeBackgroundedTabsIfNeeded(); |
488 // Since tab2 is kept inactive and background for more than time-to-purge, | 486 // Since tab2 is kept inactive and background for more than time-to-purge, |
489 // tab2 should be purged. | 487 // tab2 should be purged. |
490 EXPECT_TRUE(tab_manager.GetWebContentsData(tab2)->is_purged()); | 488 EXPECT_TRUE(tab_manager.GetWebContentsData(tab2)->is_purged()); |
491 | 489 |
492 // Activate tab2. Tab2's PurgeAndSuspend state should be NOT_PURGED. | 490 // Activate tab2. Tab2's PurgeAndSuspend state should be NOT_PURGED. |
493 tabstrip.ActivateTabAt(1, true /* user_gesture */); | 491 tabstrip.ActivateTabAt(1, true /* user_gesture */); |
494 EXPECT_FALSE(tab_manager.GetWebContentsData(tab2)->is_purged()); | 492 EXPECT_FALSE(tab_manager.GetWebContentsData(tab2)->is_purged()); |
495 } | 493 } |
496 | 494 |
497 } // namespace memory | 495 } // namespace resource_coordinator |
OLD | NEW |