Chromium Code Reviews| 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "base/time.h" | |
| 7 #include "content/browser/gpu/gpu_data_manager_impl.h" | 8 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 8 #include "content/public/browser/gpu_data_manager_observer.h" | 9 #include "content/public/browser/gpu_data_manager_observer.h" |
| 9 #include "content/public/common/gpu_info.h" | 10 #include "content/public/common/gpu_info.h" |
| 11 #include "googleurl/src/gurl.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 13 |
| 12 namespace content { | 14 namespace content { |
| 13 namespace { | 15 namespace { |
| 14 | 16 |
| 15 class TestObserver : public GpuDataManagerObserver { | 17 class TestObserver : public GpuDataManagerObserver { |
| 16 public: | 18 public: |
| 17 TestObserver() | 19 TestObserver() |
| 18 : gpu_info_updated_(false), | 20 : gpu_info_updated_(false), |
| 19 video_memory_usage_stats_updated_(false) { | 21 video_memory_usage_stats_updated_(false) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 32 virtual void OnVideoMemoryUsageStatsUpdate( | 34 virtual void OnVideoMemoryUsageStatsUpdate( |
| 33 const GPUVideoMemoryUsageStats& stats) OVERRIDE { | 35 const GPUVideoMemoryUsageStats& stats) OVERRIDE { |
| 34 video_memory_usage_stats_updated_ = true; | 36 video_memory_usage_stats_updated_ = true; |
| 35 } | 37 } |
| 36 | 38 |
| 37 private: | 39 private: |
| 38 bool gpu_info_updated_; | 40 bool gpu_info_updated_; |
| 39 bool video_memory_usage_stats_updated_; | 41 bool video_memory_usage_stats_updated_; |
| 40 }; | 42 }; |
| 41 | 43 |
| 44 static base::Time GetTimeForTesting() { | |
| 45 return base::Time::FromDoubleT(1000); | |
| 46 } | |
| 47 | |
| 48 static GURL GetDomain1ForTesting() { | |
| 49 return GURL("http://foo.com/"); | |
| 50 } | |
| 51 | |
| 52 static GURL GetDomain2ForTesting() { | |
| 53 return GURL("http://bar.com/"); | |
| 54 } | |
| 55 | |
| 42 } // namespace anonymous | 56 } // namespace anonymous |
| 43 | 57 |
| 44 class GpuDataManagerImplTest : public testing::Test { | 58 class GpuDataManagerImplTest : public testing::Test { |
| 45 public: | 59 public: |
| 46 GpuDataManagerImplTest() { } | 60 GpuDataManagerImplTest() { } |
| 47 | 61 |
| 48 virtual ~GpuDataManagerImplTest() { } | 62 virtual ~GpuDataManagerImplTest() { } |
| 49 | 63 |
| 50 protected: | 64 protected: |
| 51 void SetUp() { | 65 void SetUp() { |
| 52 } | 66 } |
| 53 | 67 |
| 54 void TearDown() { | 68 void TearDown() { |
| 55 } | 69 } |
| 56 | 70 |
| 71 base::Time JustBeforeExpiration(GpuDataManagerImpl* manager); | |
| 72 base::Time JustAfterExpiration(GpuDataManagerImpl* manager); | |
| 73 void TestBlockingDomainFrom3DAPIs( | |
| 74 GpuDataManager::DomainGuilt guilt_level); | |
| 75 void TestUnblockingDomainFrom3DAPIs( | |
| 76 GpuDataManager::DomainGuilt guilt_level); | |
| 77 | |
| 57 MessageLoop message_loop_; | 78 MessageLoop message_loop_; |
| 58 }; | 79 }; |
| 59 | 80 |
| 60 // We use new method instead of GetInstance() method because we want | 81 // We use new method instead of GetInstance() method because we want |
| 61 // each test to be independent of each other. | 82 // each test to be independent of each other. |
| 62 | 83 |
| 63 TEST_F(GpuDataManagerImplTest, GpuSideBlacklisting) { | 84 TEST_F(GpuDataManagerImplTest, GpuSideBlacklisting) { |
| 64 // If a feature is allowed in preliminary step (browser side), but | 85 // If a feature is allowed in preliminary step (browser side), but |
| 65 // disabled when GPU process launches and collects full GPU info, | 86 // disabled when GPU process launches and collects full GPU info, |
| 66 // it's too late to let renderer know, so we basically block all GPU | 87 // it's too late to let renderer know, so we basically block all GPU |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 manager->UpdateVideoMemoryUsageStats(vram_stats); | 313 manager->UpdateVideoMemoryUsageStats(vram_stats); |
| 293 { | 314 { |
| 294 base::RunLoop run_loop; | 315 base::RunLoop run_loop; |
| 295 run_loop.RunUntilIdle(); | 316 run_loop.RunUntilIdle(); |
| 296 } | 317 } |
| 297 EXPECT_TRUE(observer.video_memory_usage_stats_updated()); | 318 EXPECT_TRUE(observer.video_memory_usage_stats_updated()); |
| 298 | 319 |
| 299 delete manager; | 320 delete manager; |
| 300 } | 321 } |
| 301 | 322 |
| 323 base::Time GpuDataManagerImplTest::JustBeforeExpiration( | |
| 324 GpuDataManagerImpl* manager) { | |
| 325 return GetTimeForTesting() + base::TimeDelta::FromMilliseconds( | |
| 326 manager->GetBlockAllDomainsDurationInMs()) - | |
| 327 base::TimeDelta::FromMilliseconds(3); | |
| 328 } | |
| 329 | |
| 330 base::Time GpuDataManagerImplTest::JustAfterExpiration( | |
| 331 GpuDataManagerImpl* manager) { | |
| 332 return GetTimeForTesting() + base::TimeDelta::FromMilliseconds( | |
| 333 manager->GetBlockAllDomainsDurationInMs()) + | |
| 334 base::TimeDelta::FromMilliseconds(3); | |
| 335 } | |
| 336 | |
| 337 void GpuDataManagerImplTest::TestBlockingDomainFrom3DAPIs( | |
| 338 GpuDataManager::DomainGuilt guilt_level) { | |
| 339 GpuDataManagerImpl* manager = new GpuDataManagerImpl(); | |
|
Zhenyao Mo
2012/11/14 16:35:58
You need to manually delete this manager to avoid
Ken Russell (switch to Gerrit)
2012/11/14 19:09:14
I see. I don't think this is maintainable so I've
| |
| 340 ASSERT_TRUE(manager); | |
| 341 | |
| 342 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(), | |
| 343 guilt_level, | |
| 344 GetTimeForTesting()); | |
| 345 | |
| 346 // This domain should be blocked no matter what. | |
| 347 EXPECT_EQ(GpuDataManager::kDomainBlocked, manager->Are3DAPIsBlockedAtTime( | |
| 348 GetDomain1ForTesting(), | |
| 349 GetTimeForTesting())); | |
| 350 EXPECT_EQ(GpuDataManager::kDomainBlocked, manager->Are3DAPIsBlockedAtTime( | |
| 351 GetDomain1ForTesting(), | |
| 352 JustBeforeExpiration(manager))); | |
| 353 EXPECT_EQ(GpuDataManager::kDomainBlocked, manager->Are3DAPIsBlockedAtTime( | |
| 354 GetDomain1ForTesting(), | |
| 355 JustAfterExpiration(manager))); | |
| 356 } | |
| 357 | |
| 358 void GpuDataManagerImplTest::TestUnblockingDomainFrom3DAPIs( | |
| 359 GpuDataManager::DomainGuilt guilt_level) { | |
| 360 GpuDataManagerImpl* manager = new GpuDataManagerImpl(); | |
|
Zhenyao Mo
2012/11/14 16:35:58
delete manager in the end
| |
| 361 ASSERT_TRUE(manager); | |
| 362 | |
| 363 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(), | |
| 364 guilt_level, | |
| 365 GetTimeForTesting()); | |
| 366 | |
| 367 // Unblocking the domain should work. | |
| 368 manager->UnblockDomainFrom3DAPIs(GetDomain1ForTesting()); | |
| 369 EXPECT_EQ(GpuDataManager::kNotBlocked, manager->Are3DAPIsBlockedAtTime( | |
| 370 GetDomain1ForTesting(), | |
| 371 GetTimeForTesting())); | |
| 372 EXPECT_EQ(GpuDataManager::kNotBlocked, manager->Are3DAPIsBlockedAtTime( | |
| 373 GetDomain1ForTesting(), | |
| 374 JustBeforeExpiration(manager))); | |
| 375 EXPECT_EQ(GpuDataManager::kNotBlocked, manager->Are3DAPIsBlockedAtTime( | |
| 376 GetDomain1ForTesting(), | |
| 377 JustAfterExpiration(manager))); | |
| 378 } | |
| 379 | |
| 380 TEST_F(GpuDataManagerImplTest, BlockGuiltyDomainFrom3DAPIs) { | |
| 381 TestBlockingDomainFrom3DAPIs(GpuDataManager::kKnownGuilty); | |
| 382 } | |
| 383 | |
| 384 TEST_F(GpuDataManagerImplTest, BlockDomainOfUnknownGuiltFrom3DAPIs) { | |
| 385 TestBlockingDomainFrom3DAPIs(GpuDataManager::kUnknownGuilt); | |
| 386 } | |
| 387 | |
| 388 TEST_F(GpuDataManagerImplTest, BlockAllDomainsFrom3DAPIs) { | |
| 389 GpuDataManagerImpl* manager = new GpuDataManagerImpl(); | |
|
Zhenyao Mo
2012/11/14 16:35:58
delete manager in the end
| |
| 390 ASSERT_TRUE(manager); | |
| 391 | |
| 392 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(), | |
| 393 GpuDataManager::kUnknownGuilt, | |
| 394 GetTimeForTesting()); | |
| 395 | |
| 396 // Blocking of other domains should expire. | |
| 397 EXPECT_EQ(GpuDataManager::kAllDomainsBlocked, manager->Are3DAPIsBlockedAtTime( | |
| 398 GetDomain2ForTesting(), | |
| 399 JustBeforeExpiration(manager))); | |
| 400 EXPECT_EQ(GpuDataManager::kNotBlocked, manager->Are3DAPIsBlockedAtTime( | |
| 401 GetDomain2ForTesting(), | |
| 402 JustAfterExpiration(manager))); | |
| 403 } | |
| 404 | |
| 405 TEST_F(GpuDataManagerImplTest, UnblockGuiltyDomainFrom3DAPIs) { | |
| 406 TestUnblockingDomainFrom3DAPIs(GpuDataManager::kKnownGuilty); | |
| 407 } | |
| 408 | |
| 409 TEST_F(GpuDataManagerImplTest, UnblockDomainOfUnknownGuiltFrom3DAPIs) { | |
| 410 TestUnblockingDomainFrom3DAPIs(GpuDataManager::kUnknownGuilt); | |
| 411 } | |
| 412 | |
| 413 TEST_F(GpuDataManagerImplTest, UnblockOtherDomainFrom3DAPIs) { | |
| 414 GpuDataManagerImpl* manager = new GpuDataManagerImpl(); | |
|
Zhenyao Mo
2012/11/14 16:35:58
delete manager in the end
| |
| 415 ASSERT_TRUE(manager); | |
| 416 | |
| 417 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(), | |
| 418 GpuDataManager::kUnknownGuilt, | |
| 419 GetTimeForTesting()); | |
| 420 | |
| 421 manager->UnblockDomainFrom3DAPIs(GetDomain2ForTesting()); | |
| 422 | |
| 423 EXPECT_EQ(GpuDataManager::kNotBlocked, manager->Are3DAPIsBlockedAtTime( | |
| 424 GetDomain2ForTesting(), | |
| 425 JustBeforeExpiration(manager))); | |
| 426 | |
| 427 // The original domain should still be blocked. | |
| 428 EXPECT_EQ(GpuDataManager::kDomainBlocked, manager->Are3DAPIsBlockedAtTime( | |
| 429 GetDomain1ForTesting(), | |
| 430 JustBeforeExpiration(manager))); | |
| 431 } | |
| 432 | |
| 433 TEST_F(GpuDataManagerImplTest, UnblockThisDomainFrom3DAPIs) { | |
| 434 GpuDataManagerImpl* manager = new GpuDataManagerImpl(); | |
| 435 ASSERT_TRUE(manager); | |
| 436 | |
| 437 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(), | |
| 438 GpuDataManager::kUnknownGuilt, | |
| 439 GetTimeForTesting()); | |
| 440 | |
| 441 manager->UnblockDomainFrom3DAPIs(GetDomain1ForTesting()); | |
| 442 | |
| 443 // This behavior is debatable. Perhaps the GPU reset caused by | |
| 444 // domain 1 should still cause other domains to be blocked. | |
| 445 EXPECT_EQ(GpuDataManager::kNotBlocked, manager->Are3DAPIsBlockedAtTime( | |
| 446 GetDomain2ForTesting(), | |
| 447 JustBeforeExpiration(manager))); | |
| 448 } | |
| 449 | |
| 302 } // namespace content | 450 } // namespace content |
| OLD | NEW |