Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 { | |
| 23 public: | |
| 24 WebRTCIdentityStoreTest() | |
| 25 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | |
| 26 sequenced_worker_pool_( | |
| 27 new base::SequencedWorkerPool(3, "ServerBoundCertServiceTest")) { | |
|
Ami GONE FROM CHROMIUM
2013/06/27 20:05:18
"ServerBoundCertServiceTest" is copy/pasta?
jiayl
2013/06/27 21:08:37
Done.
| |
| 28 webrtc_identity_store_.reset( | |
| 29 new WebRTCIdentityStore(sequenced_worker_pool_)); | |
| 30 } | |
| 31 | |
| 32 virtual ~WebRTCIdentityStoreTest() { sequenced_worker_pool_->Shutdown(); } | |
| 33 | |
| 34 protected: | |
| 35 TestBrowserThreadBundle browser_thread_bundle_; | |
| 36 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; | |
| 37 scoped_ptr<WebRTCIdentityStore> webrtc_identity_store_; | |
| 38 }; | |
| 39 | |
| 40 namespace { | |
|
Ami GONE FROM CHROMIUM
2013/06/27 20:05:18
nit: prefer to make ORC below static and the TEST_
jiayl
2013/06/27 21:08:37
Done.
| |
| 41 | |
| 42 void OnRequestCompleted(bool* completed, | |
| 43 int error, | |
| 44 const std::string& certificate, | |
| 45 const std::string& private_key) { | |
| 46 ASSERT_EQ(net::OK, error); | |
| 47 ASSERT_NE("", certificate); | |
| 48 ASSERT_NE("", private_key); | |
| 49 *completed = true; | |
| 50 } | |
| 51 | |
| 52 TEST_F(WebRTCIdentityStoreTest, RequestIdentity) { | |
| 53 scoped_ptr<bool> completed(new bool(false)); | |
|
Ami GONE FROM CHROMIUM
2013/06/27 20:05:18
why not just
bool completed = false;
and pass &com
jiayl
2013/06/27 21:08:37
Done.
| |
| 54 base::Closure cancel_callback; | |
| 55 webrtc_identity_store_->RequestIdentity( | |
|
Ami GONE FROM CHROMIUM
2013/06/27 20:05:18
ASSERT_TRUE?
jiayl
2013/06/27 21:08:37
Done.
| |
| 56 GURL("http://google.com"), | |
| 57 "a", | |
| 58 "b", | |
| 59 base::Bind(&OnRequestCompleted, base::Unretained(completed.get())), | |
| 60 &cancel_callback); | |
| 61 sequenced_worker_pool_->FlushForTesting(); | |
| 62 base::RunLoop().RunUntilIdle(); | |
| 63 EXPECT_EQ(true, *completed); | |
| 64 } | |
| 65 | |
| 66 TEST_F(WebRTCIdentityStoreTest, CancelRequest) { | |
| 67 scoped_ptr<bool> completed(new bool(false)); | |
| 68 base::Closure cancel_callback; | |
| 69 bool success = webrtc_identity_store_->RequestIdentity( | |
| 70 GURL("http://google.com"), | |
| 71 "a", | |
| 72 "b", | |
| 73 base::Bind(&OnRequestCompleted, base::Unretained(completed.get())), | |
| 74 &cancel_callback); | |
| 75 EXPECT_TRUE(success); | |
| 76 cancel_callback.Run(); | |
| 77 sequenced_worker_pool_->FlushForTesting(); | |
| 78 base::RunLoop().RunUntilIdle(); | |
| 79 EXPECT_EQ(false, *completed); | |
| 80 } | |
| 81 | |
| 82 TEST_F(WebRTCIdentityStoreTest, MultipleRequests) { | |
| 83 scoped_ptr<bool> completed_1(new bool(false)); | |
| 84 scoped_ptr<bool> completed_2(new bool(false)); | |
| 85 base::Closure cancel_callback; | |
| 86 webrtc_identity_store_->RequestIdentity( | |
|
Ami GONE FROM CHROMIUM
2013/06/27 20:05:18
ditto ASSERT_TRUE
jiayl
2013/06/27 21:08:37
Done.
| |
| 87 GURL("http://foo.com"), | |
| 88 "a", | |
| 89 "b", | |
| 90 base::Bind(&OnRequestCompleted, base::Unretained(completed_1.get())), | |
| 91 &cancel_callback); | |
| 92 | |
| 93 webrtc_identity_store_->RequestIdentity( | |
|
Ami GONE FROM CHROMIUM
2013/06/27 20:05:18
ditto ASSERT_TRUE
jiayl
2013/06/27 21:08:37
Done.
| |
| 94 GURL("http://bar.com"), | |
| 95 "a", | |
| 96 "b", | |
| 97 base::Bind(&OnRequestCompleted, base::Unretained(completed_2.get())), | |
| 98 &cancel_callback); | |
| 99 | |
| 100 sequenced_worker_pool_->FlushForTesting(); | |
| 101 base::RunLoop().RunUntilIdle(); | |
| 102 EXPECT_EQ(true, *completed_1); | |
| 103 EXPECT_EQ(true, *completed_2); | |
| 104 } | |
| 105 | |
| 106 } // namespace | |
| 107 } // namespace content | |
| OLD | NEW |