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

Side by Side Diff: components/nacl/browser/pnacl_host_unittest.cc

Issue 2207683002: Use a raw pointer instead of Singleton for PnaclHost and leak it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b6_sequenced_worker_pool_redirection
Patch Set: typo Created 4 years, 4 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 | « components/nacl/browser/pnacl_host.cc ('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 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <string.h> 9 #include <string.h>
10 #include <string> 10 #include <string>
(...skipping 23 matching lines...) Expand all
34 } // namespace 34 } // namespace
35 35
36 class PnaclHostTest : public testing::Test { 36 class PnaclHostTest : public testing::Test {
37 protected: 37 protected:
38 PnaclHostTest() 38 PnaclHostTest()
39 : host_(NULL), 39 : host_(NULL),
40 temp_callback_count_(0), 40 temp_callback_count_(0),
41 write_callback_count_(0), 41 write_callback_count_(0),
42 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} 42 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {}
43 void SetUp() override { 43 void SetUp() override {
44 host_ = new PnaclHost(); 44 host_ = PnaclHost::GetInstance();
45 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 45 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
46 host_->InitForTest(temp_dir_.path(), true); 46 host_->InitForTest(temp_dir_.path(), true);
47 base::RunLoop().RunUntilIdle(); 47 base::RunLoop().RunUntilIdle();
48 EXPECT_EQ(PnaclHost::CacheReady, host_->cache_state_); 48 EXPECT_EQ(PnaclHost::CacheReady, host_->cache_state_);
49 } 49 }
50 void TearDown() override { 50 void TearDown() override {
51 EXPECT_EQ(0U, host_->pending_translations()); 51 EXPECT_EQ(0U, host_->pending_translations());
52 // Give the host a chance to de-init the backend, and then delete it. 52 // Give the host a chance to de-init the backend, and then delete it.
53 host_->RendererClosing(0); 53 host_->RendererClosing(0);
54 content::RunAllBlockingPoolTasksUntilIdle(); 54 content::RunAllBlockingPoolTasksUntilIdle();
55 EXPECT_EQ(PnaclHost::CacheUninitialized, host_->cache_state_); 55 EXPECT_EQ(PnaclHost::CacheUninitialized, host_->cache_state_);
56 delete host_;
57 } 56 }
58 int GetCacheSize() { return host_->disk_cache_->Size(); } 57 int GetCacheSize() { return host_->disk_cache_->Size(); }
59 int CacheIsInitialized() { 58 int CacheIsInitialized() {
60 return host_->cache_state_ == PnaclHost::CacheReady; 59 return host_->cache_state_ == PnaclHost::CacheReady;
61 } 60 }
62 void ReInitBackend() { 61 void ReInitBackend() {
63 host_->InitForTest(temp_dir_.path(), true); 62 host_->InitForTest(temp_dir_.path(), true);
64 base::RunLoop().RunUntilIdle(); 63 base::RunLoop().RunUntilIdle();
65 EXPECT_EQ(PnaclHost::CacheReady, host_->cache_state_); 64 EXPECT_EQ(PnaclHost::CacheReady, host_->cache_state_);
66 } 65 }
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 EXPECT_EQ(0, GetCacheSize()); 433 EXPECT_EQ(0, GetCacheSize());
435 EXPECT_EQ(0, cb.GetResult(net::ERR_IO_PENDING)); 434 EXPECT_EQ(0, cb.GetResult(net::ERR_IO_PENDING));
436 // Now check that the backend has been freed. 435 // Now check that the backend has been freed.
437 EXPECT_FALSE(CacheIsInitialized()); 436 EXPECT_FALSE(CacheIsInitialized());
438 } 437 }
439 438
440 // A version of PnaclHostTest that initializes cache on disk. 439 // A version of PnaclHostTest that initializes cache on disk.
441 class PnaclHostTestDisk : public PnaclHostTest { 440 class PnaclHostTestDisk : public PnaclHostTest {
442 protected: 441 protected:
443 void SetUp() override { 442 void SetUp() override {
444 host_ = new PnaclHost(); 443 host_ = PnaclHost::GetInstance();
445 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 444 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
446 host_->InitForTest(temp_dir_.path(), false); 445 host_->InitForTest(temp_dir_.path(), false);
447 EXPECT_EQ(PnaclHost::CacheInitializing, host_->cache_state_); 446 EXPECT_EQ(PnaclHost::CacheInitializing, host_->cache_state_);
448 } 447 }
449 void DeInit() { 448 void DeInit() {
450 host_->DeInitIfSafe(); 449 host_->DeInitIfSafe();
451 } 450 }
452 }; 451 };
453 TEST_F(PnaclHostTestDisk, DeInitWhileInitializing) { 452 TEST_F(PnaclHostTestDisk, DeInitWhileInitializing) {
454 // Since there's no easy way to pump message queues one message at a time, we 453 // Since there's no easy way to pump message queues one message at a time, we
455 // have to simulate what would happen if 1 DeInitIfsafe task gets queued, then 454 // have to simulate what would happen if 1 DeInitIfsafe task gets queued, then
456 // a GetNexeFd gets queued, and then another DeInitIfSafe gets queued before 455 // a GetNexeFd gets queued, and then another DeInitIfSafe gets queued before
457 // the first one runs. We can just shortcut and call DeInitIfSafe while the 456 // the first one runs. We can just shortcut and call DeInitIfSafe while the
458 // cache is still initializing. 457 // cache is still initializing.
459 DeInit(); 458 DeInit();
460 base::RunLoop().RunUntilIdle(); 459 base::RunLoop().RunUntilIdle();
461 } 460 }
462 461
463 } // namespace pnacl 462 } // namespace pnacl
OLDNEW
« no previous file with comments | « components/nacl/browser/pnacl_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698