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

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 namespace {
18
19 class DTLSIdentityStoreForTest : public DTLSIdentityStore {
20 public:
21 DTLSIdentityStoreForTest(const scoped_refptr<base::TaskRunner>& task_runner)
22 : DTLSIdentityStore(task_runner) {}
23
24 virtual ~DTLSIdentityStoreForTest() {}
25 };
26
27 class DTLSIdentityStoreTest : public testing::Test {
28 public:
29 DTLSIdentityStoreTest()
30 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
31 sequenced_worker_pool_(
32 new base::SequencedWorkerPool(3, "ServerBoundCertServiceTest")) {
33 dtls_identity_store_.reset(
34 new DTLSIdentityStoreForTest(sequenced_worker_pool_));
35 }
36
37 virtual ~DTLSIdentityStoreTest() { sequenced_worker_pool_->Shutdown(); }
38
39 protected:
40 TestBrowserThreadBundle browser_thread_bundle_;
41 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_;
42 scoped_ptr<DTLSIdentityStoreForTest> dtls_identity_store_;
43 };
44
45 void OnRequestCompleted(bool* completed,
46 int error,
47 const std::string& certificate,
48 const std::string& private_key) {
49 ASSERT_EQ(net::OK, error);
50 ASSERT_NE("", certificate);
51 ASSERT_NE("", private_key);
52 *completed = true;
53 }
54
55 TEST_F(DTLSIdentityStoreTest, RequestIdentity) {
56 scoped_ptr<bool> completed(new bool(false));
57 dtls_identity_store_->RequestIdentity(
58 GURL("http://google.com"),
59 "a",
60 "b",
61 base::Bind(&OnRequestCompleted, base::Unretained(completed.get())));
62 sequenced_worker_pool_->FlushForTesting();
63 base::RunLoop().RunUntilIdle();
64 EXPECT_EQ(true, *completed);
65 }
66
67 TEST_F(DTLSIdentityStoreTest, CancelRequest) {
68 scoped_ptr<bool> completed(new bool(false));
69 base::Closure cancel_closure =
70 dtls_identity_store_->RequestIdentity(
71 GURL("http://google.com"),
72 "a",
73 "b",
74 base::Bind(&OnRequestCompleted, base::Unretained(completed.get())));
75 cancel_closure.Run();
76 sequenced_worker_pool_->FlushForTesting();
77 base::RunLoop().RunUntilIdle();
78 EXPECT_EQ(false, *completed);
79 }
80
81 TEST_F(DTLSIdentityStoreTest, MultipleRequests) {
82 scoped_ptr<bool> completed_1(new bool(false));
83 scoped_ptr<bool> completed_2(new bool(false));
84
85 dtls_identity_store_->RequestIdentity(
86 GURL("http://foo.com"),
87 "a",
88 "b",
89 base::Bind(&OnRequestCompleted, base::Unretained(completed_1.get())));
90
91 dtls_identity_store_->RequestIdentity(
92 GURL("http://bar.com"),
93 "a",
94 "b",
95 base::Bind(&OnRequestCompleted, base::Unretained(completed_2.get())));
96
97 sequenced_worker_pool_->FlushForTesting();
98 base::RunLoop().RunUntilIdle();
99 EXPECT_EQ(true, *completed_1);
100 EXPECT_EQ(true, *completed_2);
101 }
102
103 } // namespace
104 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698