Index: chrome/browser/net/keygen_handler_browsertest.cc |
diff --git a/chrome/browser/net/keygen_handler_browsertest.cc b/chrome/browser/net/keygen_handler_browsertest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..520511e124301d63bc7d08c1cbccab4f87d2ca9a |
--- /dev/null |
+++ b/chrome/browser/net/keygen_handler_browsertest.cc |
@@ -0,0 +1,80 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/net/keygen_handler.h" |
+ |
+#include <string> |
+ |
+#include "base/barrier_closure.h" |
+#include "base/base64.h" |
+#include "base/bind.h" |
+#include "base/run_loop.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/test/base/in_process_browser_test.h" |
+#include "content/public/browser/browser_thread.h" |
+#include "net/base/keygen_handler_test_util.h" |
+ |
+namespace { |
+ |
+void KeygenComplete(std::string* output_result, |
+ const base::Closure& callback, |
+ const std::string* input_result) { |
+ if (input_result) |
+ *output_result = *input_result; |
+ callback.Run(); |
+} |
+ |
+void RunConcurrencyTest(content::ResourceContext* context, |
+ int num_handlers, |
+ std::string results[], |
+ const base::Closure& callback) { |
+ for (int i = 0; i < num_handlers; i++) { |
+ chrome_browser_net::GenerateKey( |
+ context, |
+ 768, |
+ "some challenge", |
+ GURL("http://www.example.com"), |
+ false, |
+ base::Bind(&KeygenComplete, &results[i], callback)); |
+ } |
+} |
+ |
+class ChromeKeygenHandlerTest : public InProcessBrowserTest { |
+ public: |
+ ChromeKeygenHandlerTest() {} |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(ChromeKeygenHandlerTest); |
+}; |
+ |
+} // namespace |
+ |
+IN_PROC_BROWSER_TEST_F(ChromeKeygenHandlerTest, ConcurrencyTest) { |
+ base::RunLoop run_loop; |
+ const int NUM_HANDLERS = 5; |
+ std::string results[NUM_HANDLERS]; |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind( |
+ RunConcurrencyTest, |
+ browser()->profile()->GetResourceContext(), |
+ NUM_HANDLERS, |
+ &results[0], |
+ base::BarrierClosure( |
+ NUM_HANDLERS, |
+ base::Bind(base::IgnoreResult(&content::BrowserThread::PostTask), |
+ content::BrowserThread::UI, |
+ FROM_HERE, |
+ run_loop.QuitClosure())))); |
+ |
+ run_loop.Run(); |
+ |
+ for (int i = 0; i < NUM_HANDLERS; i++) { |
+ VLOG(1) << "GenerateKey " << i << " produced: " << results[i]; |
+ net::AssertValidSignedPublicKeyAndChallenge( |
+ results[i], 768, "some challenge"); |
+ } |
+} |