OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/net/keygen_handler.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/barrier_closure.h" |
| 10 #include "base/base64.h" |
| 11 #include "base/bind.h" |
| 12 #include "base/run_loop.h" |
| 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/test/base/in_process_browser_test.h" |
| 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "net/base/keygen_handler_test_util.h" |
| 18 |
| 19 namespace { |
| 20 |
| 21 void KeygenComplete(std::string* output_result, |
| 22 const base::Closure& callback, |
| 23 const std::string* input_result) { |
| 24 if (input_result) |
| 25 *output_result = *input_result; |
| 26 callback.Run(); |
| 27 } |
| 28 |
| 29 void RunConcurrencyTest(content::ResourceContext* context, |
| 30 int num_handlers, |
| 31 std::string results[], |
| 32 const base::Closure& callback) { |
| 33 for (int i = 0; i < num_handlers; i++) { |
| 34 chrome_browser_net::GenerateKey( |
| 35 context, |
| 36 768, |
| 37 "some challenge", |
| 38 GURL("http://www.example.com"), |
| 39 false, |
| 40 base::Bind(&KeygenComplete, &results[i], callback)); |
| 41 } |
| 42 } |
| 43 |
| 44 class ChromeKeygenHandlerTest : public InProcessBrowserTest { |
| 45 public: |
| 46 ChromeKeygenHandlerTest() {} |
| 47 |
| 48 private: |
| 49 DISALLOW_COPY_AND_ASSIGN(ChromeKeygenHandlerTest); |
| 50 }; |
| 51 |
| 52 } // namespace |
| 53 |
| 54 IN_PROC_BROWSER_TEST_F(ChromeKeygenHandlerTest, ConcurrencyTest) { |
| 55 base::RunLoop run_loop; |
| 56 const int NUM_HANDLERS = 5; |
| 57 std::string results[NUM_HANDLERS]; |
| 58 content::BrowserThread::PostTask( |
| 59 content::BrowserThread::IO, |
| 60 FROM_HERE, |
| 61 base::Bind( |
| 62 RunConcurrencyTest, |
| 63 browser()->profile()->GetResourceContext(), |
| 64 NUM_HANDLERS, |
| 65 &results[0], |
| 66 base::BarrierClosure( |
| 67 NUM_HANDLERS, |
| 68 base::Bind(base::IgnoreResult(&content::BrowserThread::PostTask), |
| 69 content::BrowserThread::UI, |
| 70 FROM_HERE, |
| 71 run_loop.QuitClosure())))); |
| 72 |
| 73 run_loop.Run(); |
| 74 |
| 75 for (int i = 0; i < NUM_HANDLERS; i++) { |
| 76 VLOG(1) << "GenerateKey " << i << " produced: " << results[i]; |
| 77 net::AssertValidSignedPublicKeyAndChallenge( |
| 78 results[i], 768, "some challenge"); |
| 79 } |
| 80 } |
OLD | NEW |