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

Side by Side Diff: content/browser/media/dtls_identity_store_unittest.cc

Issue 15969025: Generates the DTLS identity in browser process and returns it to render process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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
OLDNEW
(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 "base/bind.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop.h"
8 #include "base/run_loop.h"
9 #include "base/threading/sequenced_worker_pool.h"
10 #include "content/browser/media/dtls_identity_store.h"
11 #include "content/public/test/test_browser_thread_bundle.h"
12 #include "googleurl/src/gurl.h"
13 #include "net/base/net_errors.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace content {
17
18 class DTLSIdentityStoreTest : public testing::Test {
19 public:
20 DTLSIdentityStoreTest()
21 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
22 sequenced_worker_pool_(
23 new base::SequencedWorkerPool(3, "ServerBoundCertServiceTest")) {
24 dtls_identity_store_.reset(new DTLSIdentityStore(sequenced_worker_pool_));
25 }
26
27 virtual ~DTLSIdentityStoreTest() { sequenced_worker_pool_->Shutdown(); }
28
29 protected:
30 TestBrowserThreadBundle browser_thread_bundle_;
31 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_;
32 scoped_ptr<DTLSIdentityStore> dtls_identity_store_;
33 };
34
35 void OnRequestCompleted(bool* completed,
36 int error,
37 const std::string& certificate,
38 const std::string& private_key) {
39 ASSERT_EQ(net::OK, error);
40 ASSERT_NE("", certificate);
41 ASSERT_NE("", private_key);
42 *completed = true;
43 }
44
45 TEST_F(DTLSIdentityStoreTest, RequestIdentity) {
46 scoped_ptr<bool> completed(new bool(false));
47 base::Closure cancel_callback;
48 dtls_identity_store_->RequestIdentity(
49 GURL("http://google.com"),
50 "a",
51 "b",
52 base::Bind(&OnRequestCompleted, base::Unretained(completed.get())),
53 &cancel_callback);
54 sequenced_worker_pool_->FlushForTesting();
55 base::RunLoop().RunUntilIdle();
56 EXPECT_EQ(true, *completed);
57 }
58
59 TEST_F(DTLSIdentityStoreTest, CancelRequest) {
60 scoped_ptr<bool> completed(new bool(false));
61 base::Closure cancel_callback;
62 bool success = dtls_identity_store_->RequestIdentity(
63 GURL("http://google.com"),
64 "a",
65 "b",
66 base::Bind(&OnRequestCompleted, base::Unretained(completed.get())),
67 &cancel_callback);
68 EXPECT_TRUE(success);
69 cancel_callback.Run();
70 sequenced_worker_pool_->FlushForTesting();
71 base::RunLoop().RunUntilIdle();
72 EXPECT_EQ(false, *completed);
73 }
74
75 TEST_F(DTLSIdentityStoreTest, MultipleRequests) {
76 scoped_ptr<bool> completed_1(new bool(false));
77 scoped_ptr<bool> completed_2(new bool(false));
78 base::Closure cancel_callback;
79 dtls_identity_store_->RequestIdentity(
80 GURL("http://foo.com"),
81 "a",
82 "b",
83 base::Bind(&OnRequestCompleted, base::Unretained(completed_1.get())),
84 &cancel_callback);
85
86 dtls_identity_store_->RequestIdentity(
87 GURL("http://bar.com"),
88 "a",
89 "b",
90 base::Bind(&OnRequestCompleted, base::Unretained(completed_2.get())),
91 &cancel_callback);
92
93 sequenced_worker_pool_->FlushForTesting();
94 base::RunLoop().RunUntilIdle();
95 EXPECT_EQ(true, *completed_1);
96 EXPECT_EQ(true, *completed_2);
97 }
98
99 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698