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 "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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 int write_callback_count_; | 92 int write_callback_count_; |
93 content::TestBrowserThreadBundle thread_bundle_; | 93 content::TestBrowserThreadBundle thread_bundle_; |
94 base::ScopedTempDir temp_dir_; | 94 base::ScopedTempDir temp_dir_; |
95 }; | 95 }; |
96 | 96 |
97 static nacl::PnaclCacheInfo GetTestCacheInfo() { | 97 static nacl::PnaclCacheInfo GetTestCacheInfo() { |
98 nacl::PnaclCacheInfo info; | 98 nacl::PnaclCacheInfo info; |
99 info.pexe_url = GURL("http://www.google.com"); | 99 info.pexe_url = GURL("http://www.google.com"); |
100 info.abi_version = 0; | 100 info.abi_version = 0; |
101 info.opt_level = 0; | 101 info.opt_level = 0; |
| 102 info.has_no_store_header = false; |
102 return info; | 103 return info; |
103 } | 104 } |
104 | 105 |
105 #define GET_NEXE_FD(renderer, instance, incognito, info, expect_hit)\ | 106 #define GET_NEXE_FD(renderer, instance, incognito, info, expect_hit)\ |
106 do { \ | 107 do { \ |
107 SCOPED_TRACE(""); \ | 108 SCOPED_TRACE(""); \ |
108 host_->GetNexeFd( \ | 109 host_->GetNexeFd( \ |
109 renderer, \ | 110 renderer, \ |
110 0, /* ignore render_view_id for now */ \ | 111 0, /* ignore render_view_id for now */ \ |
111 instance, \ | 112 instance, \ |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 host_->TranslationFinished(0, 0, true); | 158 host_->TranslationFinished(0, 0, true); |
158 FlushQueues(); | 159 FlushQueues(); |
159 GET_NEXE_FD(0, 1, false, info, true); | 160 GET_NEXE_FD(0, 1, false, info, true); |
160 FlushQueues(); | 161 FlushQueues(); |
161 EXPECT_EQ(2, temp_callback_count_); | 162 EXPECT_EQ(2, temp_callback_count_); |
162 EXPECT_EQ(0U, host_->pending_translations()); | 163 EXPECT_EQ(0U, host_->pending_translations()); |
163 } | 164 } |
164 | 165 |
165 TEST_F(PnaclHostTest, TranslationErrors) { | 166 TEST_F(PnaclHostTest, TranslationErrors) { |
166 nacl::PnaclCacheInfo info = GetTestCacheInfo(); | 167 nacl::PnaclCacheInfo info = GetTestCacheInfo(); |
167 info.pexe_url = GURL("http://www.google.com"); | |
168 GET_NEXE_FD(0, 0, false, info, false); | 168 GET_NEXE_FD(0, 0, false, info, false); |
169 // Early abort, before temp file request returns | 169 // Early abort, before temp file request returns |
170 host_->TranslationFinished(0, 0, false); | 170 host_->TranslationFinished(0, 0, false); |
171 FlushQueues(); | 171 FlushQueues(); |
172 EXPECT_EQ(0U, host_->pending_translations()); | 172 EXPECT_EQ(0U, host_->pending_translations()); |
173 EXPECT_EQ(0, temp_callback_count_); | 173 EXPECT_EQ(0, temp_callback_count_); |
174 // Check that another request for the same info misses successfully. | 174 // Check that another request for the same info misses successfully. |
175 GET_NEXE_FD(0, 0, false, info, false); | 175 GET_NEXE_FD(0, 0, false, info, false); |
176 FlushQueues(); | 176 FlushQueues(); |
177 host_->TranslationFinished(0, 0, true); | 177 host_->TranslationFinished(0, 0, true); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 EXPECT_EQ(2U, host_->pending_translations()); | 340 EXPECT_EQ(2U, host_->pending_translations()); |
341 FlushQueues(); | 341 FlushQueues(); |
342 EXPECT_EQ(2U, host_->pending_translations()); | 342 EXPECT_EQ(2U, host_->pending_translations()); |
343 EXPECT_EQ(1, temp_callback_count_); | 343 EXPECT_EQ(1, temp_callback_count_); |
344 host_->TranslationFinished(0, 0, true); | 344 host_->TranslationFinished(0, 0, true); |
345 FlushQueues(); | 345 FlushQueues(); |
346 EXPECT_EQ(2, temp_callback_count_); | 346 EXPECT_EQ(2, temp_callback_count_); |
347 EXPECT_EQ(0U, host_->pending_translations()); | 347 EXPECT_EQ(0U, host_->pending_translations()); |
348 } | 348 } |
349 | 349 |
| 350 // Test that pexes with the no-store header do not get cached. |
| 351 TEST_F(PnaclHostTest, CacheControlNoStore) { |
| 352 nacl::PnaclCacheInfo info = GetTestCacheInfo(); |
| 353 info.has_no_store_header = true; |
| 354 GET_NEXE_FD(0, 0, false, info, false); |
| 355 FlushQueues(); |
| 356 EXPECT_EQ(1, temp_callback_count_); |
| 357 host_->TranslationFinished(0, 0, true); |
| 358 FlushQueues(); |
| 359 EXPECT_EQ(0U, host_->pending_translations()); |
| 360 EXPECT_EQ(0, GetCacheSize()); |
| 361 } |
| 362 |
| 363 // Test that no-store pexes do not wait, but do duplicate translations |
| 364 TEST_F(PnaclHostTest, NoStoreOverlappedMiss) { |
| 365 nacl::PnaclCacheInfo info = GetTestCacheInfo(); |
| 366 info.has_no_store_header = true; |
| 367 GET_NEXE_FD(0, 0, false, info, false); |
| 368 GET_NEXE_FD(0, 1, false, info, false); |
| 369 FlushQueues(); |
| 370 // Check that both translations have returned misses, (i.e. that the |
| 371 // second one has not blocked on the first one) |
| 372 EXPECT_EQ(2, temp_callback_count_); |
| 373 host_->TranslationFinished(0, 0, true); |
| 374 host_->TranslationFinished(0, 1, true); |
| 375 FlushQueues(); |
| 376 EXPECT_EQ(0U, host_->pending_translations()); |
| 377 |
| 378 // Same test, but issue the 2nd request after the first has returned a miss. |
| 379 info.abi_version = 222; |
| 380 GET_NEXE_FD(0, 0, false, info, false); |
| 381 FlushQueues(); |
| 382 EXPECT_EQ(3, temp_callback_count_); |
| 383 GET_NEXE_FD(0, 1, false, info, false); |
| 384 FlushQueues(); |
| 385 EXPECT_EQ(4, temp_callback_count_); |
| 386 host_->RendererClosing(0); |
| 387 } |
| 388 |
350 TEST_F(PnaclHostTest, ClearTranslationCache) { | 389 TEST_F(PnaclHostTest, ClearTranslationCache) { |
351 nacl::PnaclCacheInfo info = GetTestCacheInfo(); | 390 nacl::PnaclCacheInfo info = GetTestCacheInfo(); |
352 // Add 2 entries in the cache | 391 // Add 2 entries in the cache |
353 GET_NEXE_FD(0, 0, false, info, false); | 392 GET_NEXE_FD(0, 0, false, info, false); |
354 info.abi_version = 222; | 393 info.abi_version = 222; |
355 GET_NEXE_FD(0, 1, false, info, false); | 394 GET_NEXE_FD(0, 1, false, info, false); |
356 FlushQueues(); | 395 FlushQueues(); |
357 EXPECT_EQ(2, temp_callback_count_); | 396 EXPECT_EQ(2, temp_callback_count_); |
358 host_->TranslationFinished(0, 0, true); | 397 host_->TranslationFinished(0, 0, true); |
359 host_->TranslationFinished(0, 1, true); | 398 host_->TranslationFinished(0, 1, true); |
360 FlushQueues(); | 399 FlushQueues(); |
361 EXPECT_EQ(0U, host_->pending_translations()); | 400 EXPECT_EQ(0U, host_->pending_translations()); |
362 EXPECT_EQ(2, GetCacheSize()); | 401 EXPECT_EQ(2, GetCacheSize()); |
363 net::TestCompletionCallback cb; | 402 net::TestCompletionCallback cb; |
364 // Since we are using a memory backend, the clear should happen immediately. | 403 // Since we are using a memory backend, the clear should happen immediately. |
365 host_->ClearTranslationCacheEntriesBetween(base::Time(), base::Time(), | 404 host_->ClearTranslationCacheEntriesBetween(base::Time(), base::Time(), |
366 base::Bind(cb.callback(), 0)); | 405 base::Bind(cb.callback(), 0)); |
367 EXPECT_EQ(0, cb.GetResult(net::ERR_IO_PENDING)); | 406 EXPECT_EQ(0, cb.GetResult(net::ERR_IO_PENDING)); |
368 // Check that the translation cache has been cleared | 407 // Check that the translation cache has been cleared |
369 EXPECT_EQ(0, GetCacheSize()); | 408 EXPECT_EQ(0, GetCacheSize()); |
370 host_->RendererClosing(0); | 409 host_->RendererClosing(0); |
371 } | 410 } |
372 | 411 |
373 } // namespace pnacl | 412 } // namespace pnacl |
OLD | NEW |