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

Side by Side Diff: extensions/browser/api/cast_channel/cast_channel_apitest.cc

Issue 2913033003: [cast_channel] Move cast_channel related files from //extensions to //components (Closed)
Patch Set: fix buildbot compile errors Created 3 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/timer/mock_timer.h" 9 #include "base/timer/mock_timer.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/extensions/extension_apitest.h" 11 #include "chrome/browser/extensions/extension_apitest.h"
12 #include "chrome/browser/extensions/extension_function_test_utils.h" 12 #include "chrome/browser/extensions/extension_function_test_utils.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "components/cast_channel/cast_socket.h"
16 #include "components/cast_channel/cast_test_util.h"
17 #include "components/cast_channel/logger.h"
18 #include "components/cast_channel/proto/cast_channel.pb.h"
15 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
16 #include "extensions/browser/api/cast_channel/cast_channel_api.h" 20 #include "extensions/browser/api/cast_channel/cast_channel_api.h"
17 #include "extensions/browser/api/cast_channel/cast_socket.h"
18 #include "extensions/browser/api/cast_channel/cast_test_util.h"
19 #include "extensions/browser/api/cast_channel/logger.h"
20 #include "extensions/common/api/cast_channel.h" 21 #include "extensions/common/api/cast_channel.h"
21 #include "extensions/common/api/cast_channel/cast_channel.pb.h"
22 #include "extensions/common/switches.h" 22 #include "extensions/common/switches.h"
23 #include "extensions/common/test_util.h" 23 #include "extensions/common/test_util.h"
24 #include "extensions/test/extension_test_message_listener.h" 24 #include "extensions/test/extension_test_message_listener.h"
25 #include "extensions/test/result_catcher.h" 25 #include "extensions/test/result_catcher.h"
26 #include "net/base/completion_callback.h" 26 #include "net/base/completion_callback.h"
27 #include "net/base/ip_address.h" 27 #include "net/base/ip_address.h"
28 #include "net/base/net_errors.h" 28 #include "net/base/net_errors.h"
29 #include "net/log/test_net_log.h" 29 #include "net/log/test_net_log.h"
30 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gmock_mutant.h" 31 #include "testing/gmock_mutant.h"
32 32
33 // TODO(mfoltz): Mock out the ApiResourceManager to resolve threading issues 33 using ::cast_channel::CastMessage;
34 // (crbug.com/398242) and simulate unloading of the extension. 34 using ::cast_channel::CastSocket;
35 35 using ::cast_channel::CastTransport;
36 using ::cast_channel::ChannelAuthType; 36 using ::cast_channel::ChannelAuthType;
37 using ::cast_channel::ChannelError; 37 using ::cast_channel::ChannelError;
38 using ::cast_channel::CreateIPEndPointForTest;
39 using ::cast_channel::LastErrors;
40 using ::cast_channel::Logger;
41 using ::cast_channel::MockCastSocket;
42 using ::cast_channel::MockCastTransport;
38 using ::cast_channel::ReadyState; 43 using ::cast_channel::ReadyState;
39
40 using extensions::api::cast_channel::CastMessage;
41 using extensions::api::cast_channel::CastSocket;
42 using extensions::api::cast_channel::CastTransport;
43 using extensions::api::cast_channel::CreateIPEndPointForTest;
44 using extensions::api::cast_channel::ErrorInfo; 44 using extensions::api::cast_channel::ErrorInfo;
45 using extensions::api::cast_channel::LastErrors;
46 using extensions::api::cast_channel::Logger;
47 using extensions::api::cast_channel::MessageInfo; 45 using extensions::api::cast_channel::MessageInfo;
48 using extensions::api::cast_channel::MockCastSocket;
49 using extensions::api::cast_channel::MockCastTransport;
50 using extensions::Extension; 46 using extensions::Extension;
51 47
52 namespace utils = extension_function_test_utils; 48 namespace utils = extension_function_test_utils;
53 49
54 using ::testing::_; 50 using ::testing::_;
55 using ::testing::A; 51 using ::testing::A;
56 using ::testing::DoAll; 52 using ::testing::DoAll;
57 using ::testing::Invoke; 53 using ::testing::Invoke;
58 using ::testing::InSequence; 54 using ::testing::InSequence;
59 using ::testing::NotNull; 55 using ::testing::NotNull;
60 using ::testing::Return; 56 using ::testing::Return;
61 using ::testing::ReturnRef; 57 using ::testing::ReturnRef;
62 using ::testing::ReturnPointee; 58 using ::testing::ReturnPointee;
63 using ::testing::SaveArg; 59 using ::testing::SaveArg;
64 60
65 namespace { 61 namespace {
66 62
63 const char kTestExtensionId[] = "ddchlicdkolnonkihahngkmmmjnjlkkf";
64
67 static void FillCastMessage(const std::string& message, 65 static void FillCastMessage(const std::string& message,
68 CastMessage* cast_message) { 66 CastMessage* cast_message) {
69 cast_message->set_namespace_("foo"); 67 cast_message->set_namespace_("foo");
70 cast_message->set_source_id("src"); 68 cast_message->set_source_id("src");
71 cast_message->set_destination_id("dest"); 69 cast_message->set_destination_id("dest");
72 cast_message->set_payload_utf8(message); 70 cast_message->set_payload_utf8(message);
73 cast_message->set_payload_type(CastMessage::STRING); 71 cast_message->set_payload_type(CastMessage::STRING);
74 } 72 }
75 73
76 ACTION_TEMPLATE(InvokeCompletionCallback, 74 ACTION_TEMPLATE(InvokeCompletionCallback,
77 HAS_1_TEMPLATE_PARAMS(int, k), 75 HAS_1_TEMPLATE_PARAMS(int, k),
78 AND_1_VALUE_PARAMS(result)) { 76 AND_1_VALUE_PARAMS(result)) {
79 ::std::tr1::get<k>(args).Run(result); 77 ::std::tr1::get<k>(args).Run(result);
80 } 78 }
81 79
82 } // namespace 80 } // namespace
83 81
84 class CastChannelAPITest : public ExtensionApiTest { 82 class CastChannelAPITest : public ExtensionApiTest {
85 public: 83 public:
86 CastChannelAPITest() : ip_endpoint_(CreateIPEndPointForTest()) {} 84 CastChannelAPITest() : ip_endpoint_(CreateIPEndPointForTest()) {}
87 85
88 void SetUpCommandLine(base::CommandLine* command_line) override { 86 void SetUpCommandLine(base::CommandLine* command_line) override {
89 ExtensionApiTest::SetUpCommandLine(command_line); 87 ExtensionApiTest::SetUpCommandLine(command_line);
90 command_line->AppendSwitchASCII( 88 command_line->AppendSwitchASCII(
91 extensions::switches::kWhitelistedExtensionID, 89 extensions::switches::kWhitelistedExtensionID, kTestExtensionId);
92 extensions::api::cast_channel::kTestExtensionId);
93 } 90 }
94 91
95 void SetUpMockCastSocket() { 92 void SetUpMockCastSocket() {
96 extensions::CastChannelAPI* api = GetApi(); 93 extensions::CastChannelAPI* api = GetApi();
97 timeout_timer_ = new base::MockTimer(true, false); 94 timeout_timer_ = new base::MockTimer(true, false);
98 api->SetPingTimeoutTimerForTest(base::WrapUnique(timeout_timer_)); 95 api->SetPingTimeoutTimerForTest(base::WrapUnique(timeout_timer_));
99 96
100 net::IPEndPoint ip_endpoint(net::IPAddress(192, 168, 1, 1), 8009); 97 net::IPEndPoint ip_endpoint(net::IPAddress(192, 168, 1, 1), 8009);
101 mock_cast_socket_ = new MockCastSocket; 98 mock_cast_socket_ = new MockCastSocket;
102 // Transfers ownership of the socket. 99 // Transfers ownership of the socket.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 .WillOnce(Return(ReadyState::CLOSED)); 148 .WillOnce(Return(ReadyState::CLOSED));
152 } 149 }
153 } 150 }
154 151
155 extensions::CastChannelAPI* GetApi() { 152 extensions::CastChannelAPI* GetApi() {
156 return extensions::CastChannelAPI::Get(profile()); 153 return extensions::CastChannelAPI::Get(profile());
157 } 154 }
158 155
159 // Logs some bogus error details and calls the OnError handler. 156 // Logs some bogus error details and calls the OnError handler.
160 void DoCallOnError(extensions::CastChannelAPI* api) { 157 void DoCallOnError(extensions::CastChannelAPI* api) {
161 api->GetLogger()->LogSocketEventWithRv( 158 api->GetLogger()->LogSocketEventWithRv(mock_cast_socket_->id(),
162 mock_cast_socket_->id(), 159 ::cast_channel::proto::SOCKET_WRITE,
163 extensions::api::cast_channel::proto::SOCKET_WRITE, net::ERR_FAILED); 160 net::ERR_FAILED);
164 message_delegate_->OnError(ChannelError::CONNECT_ERROR); 161 message_delegate_->OnError(ChannelError::CONNECT_ERROR);
165 } 162 }
166 163
167 protected: 164 protected:
168 void CallOnMessage(const std::string& message) { 165 void CallOnMessage(const std::string& message) {
169 content::BrowserThread::PostTask( 166 content::BrowserThread::PostTask(
170 content::BrowserThread::IO, FROM_HERE, 167 content::BrowserThread::IO, FROM_HERE,
171 base::Bind(&CastChannelAPITest::DoCallOnMessage, base::Unretained(this), 168 base::Bind(&CastChannelAPITest::DoCallOnMessage, base::Unretained(this),
172 GetApi(), mock_cast_socket_, message)); 169 GetApi(), mock_cast_socket_, message));
173 } 170 }
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 "\"keepAlive\": true, " 431 "\"keepAlive\": true, "
435 "\"audioOnly\": false, " 432 "\"audioOnly\": false, "
436 "\"connectInfo\": " 433 "\"connectInfo\": "
437 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, " 434 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
438 "\"auth\": \"ssl_verified\"}, \"readyState\": \"open\"}, " 435 "\"auth\": \"ssl_verified\"}, \"readyState\": \"open\"}, "
439 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", " 436 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", "
440 "\"destinationId\": \"\", \"data\": \"data\"}]", 437 "\"destinationId\": \"\", \"data\": \"data\"}]",
441 browser()); 438 browser());
442 EXPECT_EQ(error, "message_info.destination_id is required"); 439 EXPECT_EQ(error, "message_info.destination_id is required");
443 } 440 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698