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

Side by Side Diff: chrome/browser/extensions/api/gcd_private/gcd_private_apitest.cc

Issue 411783002: Initial implementation of session APIs, sans WiFi component (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
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/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "chrome/browser/extensions/api/gcd_private/gcd_private_api.h" 9 #include "chrome/browser/extensions/api/gcd_private/gcd_private_api.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/common/extensions/api/mdns.h" 12 #include "chrome/common/extensions/api/mdns.h"
13 #include "extensions/common/switches.h" 13 #include "extensions/common/switches.h"
14 #include "net/url_request/test_url_fetcher_factory.h"
14 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
15 16
16 #if defined(ENABLE_MDNS) 17 #if defined(ENABLE_MDNS)
17 #include "chrome/browser/local_discovery/test_service_discovery_client.h" 18 #include "chrome/browser/local_discovery/test_service_discovery_client.h"
18 #endif // ENABLE_MDNS 19 #endif // ENABLE_MDNS
19 20
20 namespace api = extensions::api; 21 namespace api = extensions::api;
21 22
22 namespace { 23 namespace {
23 24
(...skipping 23 matching lines...) Expand all
47 " \"connectionStatus\": \"offline\"" 48 " \"connectionStatus\": \"offline\""
48 " }" 49 " }"
49 " }," 50 " },"
50 " \"channel\": {" 51 " \"channel\": {"
51 " \"supportedType\": \"xmpp\"" 52 " \"supportedType\": \"xmpp\""
52 " }," 53 " },"
53 " \"personalizedInfo\": {" 54 " \"personalizedInfo\": {"
54 " \"maxRole\": \"owner\"" 55 " \"maxRole\": \"owner\""
55 " }}]}"; 56 " }}]}";
56 57
58 const char kPrivetInfoResponse[] =
59 "{"
60 "\"x-privet-token\": \"sample\""
61 "}";
62
63 const char kPrivetPingResponse[] =
64 "{"
65 "\"response\": \"pong\""
66 "}";
67
57 #if defined(ENABLE_MDNS) 68 #if defined(ENABLE_MDNS)
58 69
59 const uint8 kAnnouncePacket[] = { 70 const uint8 kAnnouncePacket[] = {
60 // Header 71 // Header
61 0x00, 0x00, // ID is zeroed out 72 0x00, 0x00, // ID is zeroed out
62 0x80, 0x00, // Standard query response, no error 73 0x80, 0x00, // Standard query response, no error
63 0x00, 0x00, // No questions (for simplicity) 74 0x00, 0x00, // No questions (for simplicity)
64 0x00, 0x05, // 5 RR (answers) 75 0x00, 0x05, // 5 RR (answers)
65 0x00, 0x00, // 0 authority RRs 76 0x00, 0x00, // 0 authority RRs
66 0x00, 0x00, // 0 additional RRs 77 0x00, 0x00, // 0 additional RRs
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 209
199 private: 210 private:
200 FakeGCDApiFlowFactory* factory_; 211 FakeGCDApiFlowFactory* factory_;
201 }; 212 };
202 213
203 std::map<GURL /*request url*/, std::string /*response json*/> responses_; 214 std::map<GURL /*request url*/, std::string /*response json*/> responses_;
204 }; 215 };
205 216
206 class GcdPrivateAPITest : public ExtensionApiTest { 217 class GcdPrivateAPITest : public ExtensionApiTest {
207 public: 218 public:
208 GcdPrivateAPITest() { 219 GcdPrivateAPITest() : url_fetcher_factory_(NULL) {
209 #if defined(ENABLE_MDNS) 220 #if defined(ENABLE_MDNS)
210 test_service_discovery_client_ = 221 test_service_discovery_client_ =
211 new local_discovery::TestServiceDiscoveryClient(); 222 new local_discovery::TestServiceDiscoveryClient();
212 test_service_discovery_client_->Start(); 223 test_service_discovery_client_->Start();
213 #endif // ENABLE_MDNS 224 #endif // ENABLE_MDNS
214 } 225 }
215 226
216 protected: 227 protected:
217 FakeGCDApiFlowFactory api_flow_factory_; 228 FakeGCDApiFlowFactory api_flow_factory_;
229 net::FakeURLFetcherFactory url_fetcher_factory_;
218 230
219 #if defined(ENABLE_MDNS) 231 #if defined(ENABLE_MDNS)
220 scoped_refptr<local_discovery::TestServiceDiscoveryClient> 232 scoped_refptr<local_discovery::TestServiceDiscoveryClient>
221 test_service_discovery_client_; 233 test_service_discovery_client_;
222 #endif // ENABLE_MDNS 234 #endif // ENABLE_MDNS
223 }; 235 };
224 236
225 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, GetCloudList) { 237 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, GetCloudList) {
226 api_flow_factory_.SetResponse( 238 api_flow_factory_.SetResponse(
227 GURL("https://www.google.com/cloudprint/search"), kCloudPrintResponse); 239 GURL("https://www.google.com/cloudprint/search"), kCloudPrintResponse);
228 240
229 api_flow_factory_.SetResponse( 241 api_flow_factory_.SetResponse(
230 GURL("https://www.googleapis.com/clouddevices/v1/devices"), kGCDResponse); 242 GURL("https://www.googleapis.com/clouddevices/v1/devices"), kGCDResponse);
231 243
232 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "get_cloud_list.html")); 244 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "get_cloud_list.html"));
233 } 245 }
234 246
247 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, Session) {
248 url_fetcher_factory_.SetFakeResponse(GURL("http://1.2.3.4:9090/privet/info"),
249 kPrivetInfoResponse,
250 net::HTTP_OK,
251 net::URLRequestStatus::SUCCESS);
252
253 url_fetcher_factory_.SetFakeResponse(GURL("http://1.2.3.4:9090/privet/ping"),
254 kPrivetPingResponse,
255 net::HTTP_OK,
256 net::URLRequestStatus::SUCCESS);
257
258 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "session.html"));
259 }
260
235 #if defined(ENABLE_MDNS) 261 #if defined(ENABLE_MDNS)
236 262
237 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, AddBefore) { 263 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, AddBefore) {
238 test_service_discovery_client_->SimulateReceive(kAnnouncePacket, 264 test_service_discovery_client_->SimulateReceive(kAnnouncePacket,
239 sizeof(kAnnouncePacket)); 265 sizeof(kAnnouncePacket));
240 266
241 EXPECT_TRUE( 267 EXPECT_TRUE(
242 RunExtensionSubtest("gcd_private/api", "receive_new_device.html")); 268 RunExtensionSubtest("gcd_private/api", "receive_new_device.html"));
243 } 269 }
244 270
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 EXPECT_CALL(*test_service_discovery_client_, 304 EXPECT_CALL(*test_service_discovery_client_,
279 OnSendTo(std::string(reinterpret_cast<const char*>(kQueryPacket), 305 OnSendTo(std::string(reinterpret_cast<const char*>(kQueryPacket),
280 sizeof(kQueryPacket)))).Times(2); 306 sizeof(kQueryPacket)))).Times(2);
281 #endif 307 #endif
282 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "send_query.html")); 308 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "send_query.html"));
283 } 309 }
284 310
285 #endif // ENABLE_MDNS 311 #endif // ENABLE_MDNS
286 312
287 } // namespace 313 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/gcd_private/gcd_private_api.cc ('k') | chrome/common/extensions/api/gcd_private.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698