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

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

Issue 307173002: Remove PlatformFile from components/nacl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update NexeFdCallback definition Created 6 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 | Annotate | Revision Log
« no previous file with comments | « components/nacl/browser/pnacl_host.cc ('k') | components/nacl/renderer/file_downloader.h » ('j') | 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 <stdio.h> 7 #include <stdio.h>
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 host_->InitForTest(temp_dir_.path(), true); 60 host_->InitForTest(temp_dir_.path(), true);
61 base::RunLoop().RunUntilIdle(); 61 base::RunLoop().RunUntilIdle();
62 EXPECT_EQ(PnaclHost::CacheReady, host_->cache_state_); 62 EXPECT_EQ(PnaclHost::CacheReady, host_->cache_state_);
63 } 63 }
64 64
65 public: // Required for derived classes to bind this method 65 public: // Required for derived classes to bind this method
66 // Callbacks used by tests which call GetNexeFd. 66 // Callbacks used by tests which call GetNexeFd.
67 // CallbackExpectMiss checks that the fd is valid and a miss is reported, 67 // CallbackExpectMiss checks that the fd is valid and a miss is reported,
68 // and also writes some data into the file, which is read back by 68 // and also writes some data into the file, which is read back by
69 // CallbackExpectHit 69 // CallbackExpectHit
70 void CallbackExpectMiss(base::PlatformFile fd, bool is_hit) { 70 void CallbackExpectMiss(const base::File& file, bool is_hit) {
71 EXPECT_FALSE(is_hit); 71 EXPECT_FALSE(is_hit);
72 ASSERT_FALSE(fd == base::kInvalidPlatformFileValue); 72 ASSERT_TRUE(file.IsValid());
73 base::PlatformFileInfo info; 73 base::File::Info info;
74 EXPECT_TRUE(base::GetPlatformFileInfo(fd, &info)); 74 base::File* mutable_file = const_cast<base::File*>(&file);
75 EXPECT_TRUE(mutable_file->GetInfo(&info));
75 EXPECT_FALSE(info.is_directory); 76 EXPECT_FALSE(info.is_directory);
76 EXPECT_EQ(0LL, info.size); 77 EXPECT_EQ(0LL, info.size);
77 char str[16]; 78 char str[16];
78 memset(str, 0x0, 16); 79 memset(str, 0x0, 16);
79 snprintf(str, 16, "testdata%d", ++write_callback_count_); 80 snprintf(str, 16, "testdata%d", ++write_callback_count_);
80 EXPECT_EQ(16, base::WritePlatformFile(fd, 0, str, 16)); 81 EXPECT_EQ(16, mutable_file->Write(0, str, 16));
81 temp_callback_count_++; 82 temp_callback_count_++;
82 } 83 }
83 void CallbackExpectHit(base::PlatformFile fd, bool is_hit) { 84 void CallbackExpectHit(const base::File& file, bool is_hit) {
84 EXPECT_TRUE(is_hit); 85 EXPECT_TRUE(is_hit);
85 ASSERT_FALSE(fd == base::kInvalidPlatformFileValue); 86 ASSERT_TRUE(file.IsValid());
86 base::PlatformFileInfo info; 87 base::File::Info info;
87 EXPECT_TRUE(base::GetPlatformFileInfo(fd, &info)); 88 base::File* mutable_file = const_cast<base::File*>(&file);
89 EXPECT_TRUE(mutable_file->GetInfo(&info));
88 EXPECT_FALSE(info.is_directory); 90 EXPECT_FALSE(info.is_directory);
89 EXPECT_EQ(16LL, info.size); 91 EXPECT_EQ(16LL, info.size);
90 char data[16]; 92 char data[16];
91 memset(data, 0x0, 16); 93 memset(data, 0x0, 16);
92 char str[16]; 94 char str[16];
93 memset(str, 0x0, 16); 95 memset(str, 0x0, 16);
94 snprintf(str, 16, "testdata%d", write_callback_count_); 96 snprintf(str, 16, "testdata%d", write_callback_count_);
95 EXPECT_EQ(16, base::ReadPlatformFile(fd, 0, data, 16)); 97 EXPECT_EQ(16, mutable_file->Read(0, data, 16));
96 EXPECT_STREQ(str, data); 98 EXPECT_STREQ(str, data);
97 temp_callback_count_++; 99 temp_callback_count_++;
98 } 100 }
99 101
100 protected: 102 protected:
101 PnaclHost* host_; 103 PnaclHost* host_;
102 int temp_callback_count_; 104 int temp_callback_count_;
103 int write_callback_count_; 105 int write_callback_count_;
104 content::TestBrowserThreadBundle thread_bundle_; 106 content::TestBrowserThreadBundle thread_bundle_;
105 base::ScopedTempDir temp_dir_; 107 base::ScopedTempDir temp_dir_;
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 // Since there's no easy way to pump message queues one message at a time, we 448 // Since there's no easy way to pump message queues one message at a time, we
447 // have to simulate what would happen if 1 DeInitIfsafe task gets queued, then 449 // have to simulate what would happen if 1 DeInitIfsafe task gets queued, then
448 // a GetNexeFd gets queued, and then another DeInitIfSafe gets queued before 450 // a GetNexeFd gets queued, and then another DeInitIfSafe gets queued before
449 // the first one runs. We can just shortcut and call DeInitIfSafe while the 451 // the first one runs. We can just shortcut and call DeInitIfSafe while the
450 // cache is still initializing. 452 // cache is still initializing.
451 DeInit(); 453 DeInit();
452 base::RunLoop().RunUntilIdle(); 454 base::RunLoop().RunUntilIdle();
453 } 455 }
454 456
455 } // namespace pnacl 457 } // namespace pnacl
OLDNEW
« no previous file with comments | « components/nacl/browser/pnacl_host.cc ('k') | components/nacl/renderer/file_downloader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698