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

Side by Side Diff: content/browser/media/webrtc_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, 5 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/synchronization/waitable_event.h"
10 #include "base/threading/sequenced_worker_pool.h"
11 #include "content/browser/media/webrtc_identity_store.h"
12 #include "content/browser/renderer_host/media/webrtc_identity_service_host.h"
13 #include "content/common/media/webrtc_identity_messages.h"
14 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "content/public/test/test_utils.h"
16 #include "googleurl/src/gurl.h"
17 #include "net/base/net_errors.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 namespace content {
21
22 class WebRTCIdentityStoreTest : public testing::Test {
Ryan Sleevi 2013/06/27 18:05:24 Place these tests in an unnamed namespace.
jiayl 2013/06/27 18:29:36 Class WebRTCIdentityStoreTest needs to be forward
23 public:
24 WebRTCIdentityStoreTest()
25 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
26 sequenced_worker_pool_(
27 new base::SequencedWorkerPool(3, "ServerBoundCertServiceTest")) {
28 webrtc_identity_store_.reset(
29 new WebRTCIdentityStore(sequenced_worker_pool_));
30 }
31
32 virtual ~WebRTCIdentityStoreTest() { sequenced_worker_pool_->Shutdown(); }
33
34 virtual void SignalWaitableEvent(const base::Closure& quit_task) {
35 quit_task.Run();
36 }
Ryan Sleevi 2013/06/27 18:05:24 Unneeded
jiayl 2013/06/27 18:29:36 Done.
37
38 protected:
39 TestBrowserThreadBundle browser_thread_bundle_;
40 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_;
41 scoped_ptr<WebRTCIdentityStore> webrtc_identity_store_;
42 };
43
44 void OnRequestCompleted(bool* completed,
45 int error,
46 const std::string& certificate,
47 const std::string& private_key) {
48 ASSERT_EQ(net::OK, error);
49 ASSERT_NE("", certificate);
50 ASSERT_NE("", private_key);
51 *completed = true;
52 }
53
54 TEST_F(WebRTCIdentityStoreTest, RequestIdentity) {
55 scoped_ptr<bool> completed(new bool(false));
56 base::Closure cancel_callback;
57 webrtc_identity_store_->RequestIdentity(
58 GURL("http://google.com"),
59 "a",
60 "b",
61 base::Bind(&OnRequestCompleted, base::Unretained(completed.get())),
62 &cancel_callback);
63 sequenced_worker_pool_->FlushForTesting();
64 base::RunLoop().RunUntilIdle();
65 EXPECT_EQ(true, *completed);
66 }
67
68 TEST_F(WebRTCIdentityStoreTest, CancelRequest) {
69 scoped_ptr<bool> completed(new bool(false));
70 base::Closure cancel_callback;
71 bool success = webrtc_identity_store_->RequestIdentity(
72 GURL("http://google.com"),
73 "a",
74 "b",
75 base::Bind(&OnRequestCompleted, base::Unretained(completed.get())),
76 &cancel_callback);
77 EXPECT_TRUE(success);
78 cancel_callback.Run();
79 sequenced_worker_pool_->FlushForTesting();
80 base::RunLoop().RunUntilIdle();
81 EXPECT_EQ(false, *completed);
82 }
83
84 TEST_F(WebRTCIdentityStoreTest, MultipleRequests) {
85 scoped_ptr<bool> completed_1(new bool(false));
86 scoped_ptr<bool> completed_2(new bool(false));
87 base::Closure cancel_callback;
88 webrtc_identity_store_->RequestIdentity(
89 GURL("http://foo.com"),
90 "a",
91 "b",
92 base::Bind(&OnRequestCompleted, base::Unretained(completed_1.get())),
93 &cancel_callback);
94
95 webrtc_identity_store_->RequestIdentity(
96 GURL("http://bar.com"),
97 "a",
98 "b",
99 base::Bind(&OnRequestCompleted, base::Unretained(completed_2.get())),
100 &cancel_callback);
101
102 sequenced_worker_pool_->FlushForTesting();
103 base::RunLoop().RunUntilIdle();
104 EXPECT_EQ(true, *completed_1);
105 EXPECT_EQ(true, *completed_2);
106 }
107
108 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698