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

Side by Side Diff: chrome/browser/nacl_host/pnacl_host_unittest.cc

Issue 23458015: Handle cache-control:no-store header in PNaCl translation cache (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix iterator use Created 7 years, 3 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 | « chrome/browser/nacl_host/pnacl_host.cc ('k') | chrome/renderer/pepper/ppb_nacl_private_impl.cc » ('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 "chrome/browser/nacl_host/pnacl_host.h" 5 #include "chrome/browser/nacl_host/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 29 matching lines...) Expand all
40 } 40 }
41 // Flush the blocking pool first, then any tasks it posted to the IO thread. 41 // Flush the blocking pool first, then any tasks it posted to the IO thread.
42 // Do 2 rounds of flushing, because some operations require 2 trips back and 42 // Do 2 rounds of flushing, because some operations require 2 trips back and
43 // forth between the threads. 43 // forth between the threads.
44 void FlushQueues() { 44 void FlushQueues() {
45 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 45 content::BrowserThread::GetBlockingPool()->FlushForTesting();
46 base::RunLoop().RunUntilIdle(); 46 base::RunLoop().RunUntilIdle();
47 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 47 content::BrowserThread::GetBlockingPool()->FlushForTesting();
48 base::RunLoop().RunUntilIdle(); 48 base::RunLoop().RunUntilIdle();
49 } 49 }
50 int GetCacheSize() { 50 int GetCacheSize() { return host_->disk_cache_->Size(); }
51 return host_->disk_cache_->Size();
52 }
53 51
54 public: // Required for derived classes to bind this method 52 public: // Required for derived classes to bind this method
55 // Callbacks used by tests which call GetNexeFd. 53 // Callbacks used by tests which call GetNexeFd.
56 // CallbackExpectMiss checks that the fd is valid and a miss is reported, 54 // CallbackExpectMiss checks that the fd is valid and a miss is reported,
57 // and also writes some data into the file, which is read back by 55 // and also writes some data into the file, which is read back by
58 // CallbackExpectHit 56 // CallbackExpectHit
59 void CallbackExpectMiss(base::PlatformFile fd, bool is_hit) { 57 void CallbackExpectMiss(base::PlatformFile fd, bool is_hit) {
60 EXPECT_FALSE(is_hit); 58 EXPECT_FALSE(is_hit);
61 ASSERT_FALSE(fd == base::kInvalidPlatformFileValue); 59 ASSERT_FALSE(fd == base::kInvalidPlatformFileValue);
62 base::PlatformFileInfo info; 60 base::PlatformFileInfo info;
63 EXPECT_TRUE(base::GetPlatformFileInfo(fd, &info)); 61 EXPECT_TRUE(base::GetPlatformFileInfo(fd, &info));
64 EXPECT_FALSE(info.is_directory); 62 EXPECT_FALSE(info.is_directory);
65 EXPECT_EQ(0LL, info.size); 63 EXPECT_EQ(0LL, info.size);
(...skipping 26 matching lines...) Expand all
92 int write_callback_count_; 90 int write_callback_count_;
93 content::TestBrowserThreadBundle thread_bundle_; 91 content::TestBrowserThreadBundle thread_bundle_;
94 base::ScopedTempDir temp_dir_; 92 base::ScopedTempDir temp_dir_;
95 }; 93 };
96 94
97 static nacl::PnaclCacheInfo GetTestCacheInfo() { 95 static nacl::PnaclCacheInfo GetTestCacheInfo() {
98 nacl::PnaclCacheInfo info; 96 nacl::PnaclCacheInfo info;
99 info.pexe_url = GURL("http://www.google.com"); 97 info.pexe_url = GURL("http://www.google.com");
100 info.abi_version = 0; 98 info.abi_version = 0;
101 info.opt_level = 0; 99 info.opt_level = 0;
100 info.has_no_store_header = false;
102 return info; 101 return info;
103 } 102 }
104 103
105 #define GET_NEXE_FD(renderer, instance, incognito, info, expect_hit)\ 104 #define GET_NEXE_FD(renderer, instance, incognito, info, expect_hit) \
106 do { \ 105 do { \
107 SCOPED_TRACE(""); \ 106 SCOPED_TRACE(""); \
108 host_->GetNexeFd( \ 107 host_->GetNexeFd( \
109 renderer, \ 108 renderer, \
110 0, /* ignore render_view_id for now */ \ 109 0, /* ignore render_view_id for now */ \
111 instance, \ 110 instance, \
112 incognito, \ 111 incognito, \
113 info, \ 112 info, \
114 base::Bind(expect_hit ? &PnaclHostTest::CallbackExpectHit \ 113 base::Bind(expect_hit ? &PnaclHostTest::CallbackExpectHit \
115 : &PnaclHostTest::CallbackExpectMiss, \ 114 : &PnaclHostTest::CallbackExpectMiss, \
116 base::Unretained(this))); \ 115 base::Unretained(this))); \
117 } while (0) 116 } while (0)
118 117
119 TEST_F(PnaclHostTest, BasicMiss) { 118 TEST_F(PnaclHostTest, BasicMiss) {
120 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 119 nacl::PnaclCacheInfo info = GetTestCacheInfo();
121 // Test cold miss. 120 // Test cold miss.
122 GET_NEXE_FD(0, 0, false, info, false); 121 GET_NEXE_FD(0, 0, false, info, false);
123 EXPECT_EQ(1U, host_->pending_translations()); 122 EXPECT_EQ(1U, host_->pending_translations());
124 FlushQueues(); 123 FlushQueues();
125 EXPECT_EQ(1U, host_->pending_translations()); 124 EXPECT_EQ(1U, host_->pending_translations());
126 EXPECT_EQ(1, temp_callback_count_); 125 EXPECT_EQ(1, temp_callback_count_);
(...skipping 30 matching lines...) Expand all
157 host_->TranslationFinished(0, 0, true); 156 host_->TranslationFinished(0, 0, true);
158 FlushQueues(); 157 FlushQueues();
159 GET_NEXE_FD(0, 1, false, info, true); 158 GET_NEXE_FD(0, 1, false, info, true);
160 FlushQueues(); 159 FlushQueues();
161 EXPECT_EQ(2, temp_callback_count_); 160 EXPECT_EQ(2, temp_callback_count_);
162 EXPECT_EQ(0U, host_->pending_translations()); 161 EXPECT_EQ(0U, host_->pending_translations());
163 } 162 }
164 163
165 TEST_F(PnaclHostTest, TranslationErrors) { 164 TEST_F(PnaclHostTest, TranslationErrors) {
166 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 165 nacl::PnaclCacheInfo info = GetTestCacheInfo();
167 info.pexe_url = GURL("http://www.google.com");
168 GET_NEXE_FD(0, 0, false, info, false); 166 GET_NEXE_FD(0, 0, false, info, false);
169 // Early abort, before temp file request returns 167 // Early abort, before temp file request returns
170 host_->TranslationFinished(0, 0, false); 168 host_->TranslationFinished(0, 0, false);
171 FlushQueues(); 169 FlushQueues();
172 EXPECT_EQ(0U, host_->pending_translations()); 170 EXPECT_EQ(0U, host_->pending_translations());
173 EXPECT_EQ(0, temp_callback_count_); 171 EXPECT_EQ(0, temp_callback_count_);
174 // Check that another request for the same info misses successfully. 172 // Check that another request for the same info misses successfully.
175 GET_NEXE_FD(0, 0, false, info, false); 173 GET_NEXE_FD(0, 0, false, info, false);
176 FlushQueues(); 174 FlushQueues();
177 host_->TranslationFinished(0, 0, true); 175 host_->TranslationFinished(0, 0, true);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 EXPECT_EQ(2U, host_->pending_translations()); 338 EXPECT_EQ(2U, host_->pending_translations());
341 FlushQueues(); 339 FlushQueues();
342 EXPECT_EQ(2U, host_->pending_translations()); 340 EXPECT_EQ(2U, host_->pending_translations());
343 EXPECT_EQ(1, temp_callback_count_); 341 EXPECT_EQ(1, temp_callback_count_);
344 host_->TranslationFinished(0, 0, true); 342 host_->TranslationFinished(0, 0, true);
345 FlushQueues(); 343 FlushQueues();
346 EXPECT_EQ(2, temp_callback_count_); 344 EXPECT_EQ(2, temp_callback_count_);
347 EXPECT_EQ(0U, host_->pending_translations()); 345 EXPECT_EQ(0U, host_->pending_translations());
348 } 346 }
349 347
348 // Test that pexes with the no-store header do not get cached.
349 TEST_F(PnaclHostTest, CacheControlNoStore) {
350 nacl::PnaclCacheInfo info = GetTestCacheInfo();
351 info.has_no_store_header = true;
352 GET_NEXE_FD(0, 0, false, info, false);
353 FlushQueues();
354 EXPECT_EQ(1, temp_callback_count_);
355 host_->TranslationFinished(0, 0, true);
356 FlushQueues();
357 EXPECT_EQ(0U, host_->pending_translations());
358 EXPECT_EQ(0, GetCacheSize());
359 }
360
361 // Test that no-store pexes do not wait, but do duplicate translations
362 TEST_F(PnaclHostTest, NoStoreOverlappedMiss) {
363 nacl::PnaclCacheInfo info = GetTestCacheInfo();
364 info.has_no_store_header = true;
365 GET_NEXE_FD(0, 0, false, info, false);
366 GET_NEXE_FD(0, 1, false, info, false);
367 FlushQueues();
368 // Check that both translations have returned misses, (i.e. that the
369 // second one has not blocked on the first one)
370 EXPECT_EQ(2, temp_callback_count_);
371 host_->TranslationFinished(0, 0, true);
372 host_->TranslationFinished(0, 1, true);
373 FlushQueues();
374 EXPECT_EQ(0U, host_->pending_translations());
375
376 // Same test, but issue the 2nd request after the first has returned a miss.
377 info.abi_version = 222;
378 GET_NEXE_FD(0, 0, false, info, false);
379 FlushQueues();
380 EXPECT_EQ(3, temp_callback_count_);
381 GET_NEXE_FD(0, 1, false, info, false);
382 FlushQueues();
383 EXPECT_EQ(4, temp_callback_count_);
384 host_->RendererClosing(0);
385 }
386
350 TEST_F(PnaclHostTest, ClearTranslationCache) { 387 TEST_F(PnaclHostTest, ClearTranslationCache) {
351 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 388 nacl::PnaclCacheInfo info = GetTestCacheInfo();
352 // Add 2 entries in the cache 389 // Add 2 entries in the cache
353 GET_NEXE_FD(0, 0, false, info, false); 390 GET_NEXE_FD(0, 0, false, info, false);
354 info.abi_version = 222; 391 info.abi_version = 222;
355 GET_NEXE_FD(0, 1, false, info, false); 392 GET_NEXE_FD(0, 1, false, info, false);
356 FlushQueues(); 393 FlushQueues();
357 EXPECT_EQ(2, temp_callback_count_); 394 EXPECT_EQ(2, temp_callback_count_);
358 host_->TranslationFinished(0, 0, true); 395 host_->TranslationFinished(0, 0, true);
359 host_->TranslationFinished(0, 1, true); 396 host_->TranslationFinished(0, 1, true);
360 FlushQueues(); 397 FlushQueues();
361 EXPECT_EQ(0U, host_->pending_translations()); 398 EXPECT_EQ(0U, host_->pending_translations());
362 EXPECT_EQ(2, GetCacheSize()); 399 EXPECT_EQ(2, GetCacheSize());
363 net::TestCompletionCallback cb; 400 net::TestCompletionCallback cb;
364 // Since we are using a memory backend, the clear should happen immediately. 401 // Since we are using a memory backend, the clear should happen immediately.
365 host_->ClearTranslationCacheEntriesBetween(base::Time(), base::Time(), 402 host_->ClearTranslationCacheEntriesBetween(
366 base::Bind(cb.callback(), 0)); 403 base::Time(), base::Time(), base::Bind(cb.callback(), 0));
367 EXPECT_EQ(0, cb.GetResult(net::ERR_IO_PENDING)); 404 EXPECT_EQ(0, cb.GetResult(net::ERR_IO_PENDING));
368 // Check that the translation cache has been cleared 405 // Check that the translation cache has been cleared
369 EXPECT_EQ(0, GetCacheSize()); 406 EXPECT_EQ(0, GetCacheSize());
370 host_->RendererClosing(0); 407 host_->RendererClosing(0);
371 } 408 }
372 409
373 } // namespace pnacl 410 } // namespace pnacl
OLDNEW
« no previous file with comments | « chrome/browser/nacl_host/pnacl_host.cc ('k') | chrome/renderer/pepper/ppb_nacl_private_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698