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

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 NULL);
63 sequenced_worker_pool_->FlushForTesting();
64 base::RunLoop().RunUntilIdle();
65 EXPECT_EQ(true, *completed);
66 }
67
68 TEST_F(DTLSIdentityStoreTest, CancelRequest) {
69 scoped_ptr<bool> completed(new bool(false));
70 base::Closure canceller;
71 bool success =
72 dtls_identity_store_->RequestIdentity(
73 GURL("http://google.com"),
74 "a",
75 "b",
76 base::Bind(&OnRequestCompleted, base::Unretained(completed.get())),
77 &canceller);
78 EXPECT_TRUE(success);
79 canceller.Run();
80 sequenced_worker_pool_->FlushForTesting();
81 base::RunLoop().RunUntilIdle();
82 EXPECT_EQ(false, *completed);
83 }
84
85 TEST_F(DTLSIdentityStoreTest, MultipleRequests) {
86 scoped_ptr<bool> completed_1(new bool(false));
87 scoped_ptr<bool> completed_2(new bool(false));
88
89 dtls_identity_store_->RequestIdentity(
90 GURL("http://foo.com"),
91 "a",
92 "b",
93 base::Bind(&OnRequestCompleted, base::Unretained(completed_1.get())),
94 NULL);
95
96 dtls_identity_store_->RequestIdentity(
97 GURL("http://bar.com"),
98 "a",
99 "b",
100 base::Bind(&OnRequestCompleted, base::Unretained(completed_2.get())),
101 NULL);
102
103 sequenced_worker_pool_->FlushForTesting();
104 base::RunLoop().RunUntilIdle();
105 EXPECT_EQ(true, *completed_1);
106 EXPECT_EQ(true, *completed_2);
107 }
108
109 } // namespace
110 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698