OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/nacl/browser/pnacl_host.h" | 5 #include "components/nacl/browser/pnacl_host.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 class PnaclHostTest : public testing::Test { | 33 class PnaclHostTest : public testing::Test { |
34 protected: | 34 protected: |
35 PnaclHostTest() | 35 PnaclHostTest() |
36 : host_(NULL), | 36 : host_(NULL), |
37 temp_callback_count_(0), | 37 temp_callback_count_(0), |
38 write_callback_count_(0), | 38 write_callback_count_(0), |
39 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} | 39 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} |
40 virtual void SetUp() { | 40 void SetUp() override { |
41 host_ = new PnaclHost(); | 41 host_ = new PnaclHost(); |
42 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 42 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
43 host_->InitForTest(temp_dir_.path(), true); | 43 host_->InitForTest(temp_dir_.path(), true); |
44 base::RunLoop().RunUntilIdle(); | 44 base::RunLoop().RunUntilIdle(); |
45 EXPECT_EQ(PnaclHost::CacheReady, host_->cache_state_); | 45 EXPECT_EQ(PnaclHost::CacheReady, host_->cache_state_); |
46 } | 46 } |
47 virtual void TearDown() { | 47 void TearDown() override { |
48 EXPECT_EQ(0U, host_->pending_translations()); | 48 EXPECT_EQ(0U, host_->pending_translations()); |
49 // Give the host a chance to de-init the backend, and then delete it. | 49 // Give the host a chance to de-init the backend, and then delete it. |
50 host_->RendererClosing(0); | 50 host_->RendererClosing(0); |
51 content::RunAllBlockingPoolTasksUntilIdle(); | 51 content::RunAllBlockingPoolTasksUntilIdle(); |
52 EXPECT_EQ(PnaclHost::CacheUninitialized, host_->cache_state_); | 52 EXPECT_EQ(PnaclHost::CacheUninitialized, host_->cache_state_); |
53 delete host_; | 53 delete host_; |
54 } | 54 } |
55 int GetCacheSize() { return host_->disk_cache_->Size(); } | 55 int GetCacheSize() { return host_->disk_cache_->Size(); } |
56 int CacheIsInitialized() { | 56 int CacheIsInitialized() { |
57 return host_->cache_state_ == PnaclHost::CacheReady; | 57 return host_->cache_state_ == PnaclHost::CacheReady; |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 // queues, because the backend will be freed once it is. | 429 // queues, because the backend will be freed once it is. |
430 EXPECT_EQ(0, GetCacheSize()); | 430 EXPECT_EQ(0, GetCacheSize()); |
431 EXPECT_EQ(0, cb.GetResult(net::ERR_IO_PENDING)); | 431 EXPECT_EQ(0, cb.GetResult(net::ERR_IO_PENDING)); |
432 // Now check that the backend has been freed. | 432 // Now check that the backend has been freed. |
433 EXPECT_FALSE(CacheIsInitialized()); | 433 EXPECT_FALSE(CacheIsInitialized()); |
434 } | 434 } |
435 | 435 |
436 // A version of PnaclHostTest that initializes cache on disk. | 436 // A version of PnaclHostTest that initializes cache on disk. |
437 class PnaclHostTestDisk : public PnaclHostTest { | 437 class PnaclHostTestDisk : public PnaclHostTest { |
438 protected: | 438 protected: |
439 virtual void SetUp() { | 439 void SetUp() override { |
440 host_ = new PnaclHost(); | 440 host_ = new PnaclHost(); |
441 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 441 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
442 host_->InitForTest(temp_dir_.path(), false); | 442 host_->InitForTest(temp_dir_.path(), false); |
443 EXPECT_EQ(PnaclHost::CacheInitializing, host_->cache_state_); | 443 EXPECT_EQ(PnaclHost::CacheInitializing, host_->cache_state_); |
444 } | 444 } |
445 void DeInit() { | 445 void DeInit() { |
446 host_->DeInitIfSafe(); | 446 host_->DeInitIfSafe(); |
447 } | 447 } |
448 }; | 448 }; |
449 TEST_F(PnaclHostTestDisk, DeInitWhileInitializing) { | 449 TEST_F(PnaclHostTestDisk, DeInitWhileInitializing) { |
450 // Since there's no easy way to pump message queues one message at a time, we | 450 // Since there's no easy way to pump message queues one message at a time, we |
451 // have to simulate what would happen if 1 DeInitIfsafe task gets queued, then | 451 // have to simulate what would happen if 1 DeInitIfsafe task gets queued, then |
452 // a GetNexeFd gets queued, and then another DeInitIfSafe gets queued before | 452 // a GetNexeFd gets queued, and then another DeInitIfSafe gets queued before |
453 // the first one runs. We can just shortcut and call DeInitIfSafe while the | 453 // the first one runs. We can just shortcut and call DeInitIfSafe while the |
454 // cache is still initializing. | 454 // cache is still initializing. |
455 DeInit(); | 455 DeInit(); |
456 base::RunLoop().RunUntilIdle(); | 456 base::RunLoop().RunUntilIdle(); |
457 } | 457 } |
458 | 458 |
459 } // namespace pnacl | 459 } // namespace pnacl |
OLD | NEW |